17 #include <boost/foreach.hpp>
23 using namespace impala;
39 counters_.insert(make_pair(TOTAL_INSTS, 0));
40 counters_.insert(make_pair(TOTAL_BLOCKS, 0));
41 counters_.insert(make_pair(TOTAL_FUNCTIONS, 0));
46 counters_.insert(make_pair(TERMINATOR_INSTS, 0));
47 counters_.insert(make_pair(BINARY_INSTS, 0));
48 counters_.insert(make_pair(MEMORY_INSTS, 0));
49 counters_.insert(make_pair(CAST_INSTS, 0));
50 counters_.insert(make_pair(OTHER_INSTS, 0));
54 visit(M.begin(), M.end());
58 IncrementCount(TOTAL_FUNCTIONS);
59 visit(F.begin(), F.end());
63 IncrementCount(TOTAL_BLOCKS);
64 visit(BB.begin(), BB.end());
68 CounterMap::const_iterator counter = counters_.find(name);
69 DCHECK(counter != counters_.end());
70 return counter->second;
74 IncrementCount(TOTAL_INSTS);
75 switch (I.getOpcode()) {
76 case llvm::Instruction::Ret:
77 case llvm::Instruction::Br:
78 case llvm::Instruction::Switch:
79 case llvm::Instruction::IndirectBr:
80 case llvm::Instruction::Invoke:
81 case llvm::Instruction::Resume:
82 case llvm::Instruction::Unreachable:
83 IncrementCount(TERMINATOR_INSTS);
85 case llvm::Instruction::Add:
86 case llvm::Instruction::FAdd:
87 case llvm::Instruction::Sub:
88 case llvm::Instruction::FSub:
89 case llvm::Instruction::Mul:
90 case llvm::Instruction::FMul:
91 case llvm::Instruction::UDiv:
92 case llvm::Instruction::SDiv:
93 case llvm::Instruction::FDiv:
94 case llvm::Instruction::URem:
95 case llvm::Instruction::SRem:
96 case llvm::Instruction::FRem:
97 case llvm::Instruction::Shl:
98 case llvm::Instruction::LShr:
99 case llvm::Instruction::AShr:
100 case llvm::Instruction::And:
101 case llvm::Instruction::Or:
102 case llvm::Instruction::Xor:
103 IncrementCount(BINARY_INSTS);
105 case llvm::Instruction::Alloca:
106 case llvm::Instruction::Load:
107 case llvm::Instruction::Store:
108 case llvm::Instruction::Fence:
109 case llvm::Instruction::AtomicCmpXchg:
110 case llvm::Instruction::AtomicRMW:
111 IncrementCount(MEMORY_INSTS);
113 case llvm::Instruction::Trunc:
114 case llvm::Instruction::ZExt:
115 case llvm::Instruction::SExt:
116 case llvm::Instruction::FPToUI:
117 case llvm::Instruction::FPToSI:
118 case llvm::Instruction::UIToFP:
119 case llvm::Instruction::SIToFP:
120 case llvm::Instruction::FPTrunc:
121 case llvm::Instruction::FPExt:
122 case llvm::Instruction::PtrToInt:
123 case llvm::Instruction::IntToPtr:
124 case llvm::Instruction::BitCast:
125 IncrementCount(CAST_INSTS);
127 case llvm::Instruction::ICmp:
128 case llvm::Instruction::FCmp:
129 case llvm::Instruction::PHI:
130 case llvm::Instruction::Call:
131 case llvm::Instruction::Select:
132 case llvm::Instruction::UserOp1:
133 case llvm::Instruction::UserOp2:
134 case llvm::Instruction::VAArg:
135 case llvm::Instruction::ExtractElement:
136 case llvm::Instruction::InsertElement:
137 case llvm::Instruction::ShuffleVector:
138 case llvm::Instruction::ExtractValue:
139 case llvm::Instruction::InsertValue:
140 case llvm::Instruction::LandingPad:
141 case llvm::Instruction::GetElementPtr:
142 IncrementCount(OTHER_INSTS);
150 BOOST_FOREACH(CounterMap::value_type& counter, counters_) {
156 stringstream* stream)
const {
158 *stream << left << setw(max_count_len + 1) << setfill(
' ') << count << setw(35)
159 << setfill(
' ') << name << left << setw(10 - max_count_len) << setfill(
' ')
160 <<
"Number of " << name << endl;
166 int max_count_len = 0;
167 stringstream count_stream;
168 BOOST_FOREACH(
const CounterMap::value_type& counter, counters_) {
169 count_stream << counter.second;
171 max(max_count_len, static_cast<int>(strlen(count_stream.str().c_str())));
172 count_stream.str(
"");
176 stream <<
"\n===" << string(73,
'-') <<
"===\n\n"
177 <<
" ... Instruction Counts ...\n\n"
178 <<
"===" << string(73,
'-') <<
"===\n\n";
180 BOOST_FOREACH(
const CounterMap::value_type& counter, counters_) {
183 if (strcmp(counter.first.c_str(), TOTAL_BLOCKS) == 0) {
184 stream <<
"\n===" << string(73,
'-') <<
"===\n"
185 <<
" ... Totals ...\n"
186 <<
"===" << string(73,
'-') <<
"===\n\n";
188 PrintCounter(counter.first.c_str(), counter.second, max_count_len, &stream);
195 CounterMap::iterator iter = counters_.find(name);
196 DCHECK(iter != counters_.end());
static const char * TOTAL_INSTS
String constants for instruction count names.
int GetCount(const char *name)
Return count of counter described by name.
void ResetCount()
Set all counts to 0.
static const char * OTHER_INSTS
static const char * CAST_INSTS
static const char * TOTAL_BLOCKS
void PrintCounter(const char *name, int count, int max_count_len, std::stringstream *stream) const
Prints a single counter described by name and count.
static const char * TERMINATOR_INSTS
std::string PrintCounters() const
Prints all counters.
void visit(const llvm::Module &M)
Visits each Function in Module M.
static const char * TOTAL_FUNCTIONS
static const char * BINARY_INSTS
void IncrementCount(const char *name)
Increment InstructionCount with name_ equal to name argument.
static const char * MEMORY_INSTS