Subzero: Add rudimentary statistics on generated code.
The following are collected:
- Number of machine instructions emitted
- Number of registers saved/restored in prolog/epilog
- Number of stack frame bytes (non-alloca) allocated
- Number of "spills", or stores to stack slots
- Number of "fills", or loads/operations from stack slots
- Fill+Spill count (sum of above two)
These are somewhat reasonable approximations of code quality, and the primary intention is to compare before-and-after when trying out an optimization.
The statistics are dumped after translating each function. Per-function and cumulative statistics are collected. The output lines have a prefix that is easy to filter.
BUG= none
R=jvoung@chromium.org
Review URL: https://codereview.chromium.org/580633002
diff --git a/src/IceCfgNode.cpp b/src/IceCfgNode.cpp
index f6b4a98..4de2f57 100644
--- a/src/IceCfgNode.cpp
+++ b/src/IceCfgNode.cpp
@@ -483,6 +483,21 @@
if (Inst->isRedundantAssign())
continue;
(*I)->emit(Func);
+ // Update emitted instruction count, plus fill/spill count for
+ // Variable operands without a physical register.
+ if (uint32_t Count = (*I)->getEmitInstCount()) {
+ Func->getContext()->statsUpdateEmitted(Count);
+ if (Variable *Dest = (*I)->getDest()) {
+ if (!Dest->hasReg())
+ Func->getContext()->statsUpdateFills();
+ }
+ for (SizeT S = 0; S < (*I)->getSrcSize(); ++S) {
+ if (Variable *Src = llvm::dyn_cast<Variable>((*I)->getSrc(S))) {
+ if (!Src->hasReg())
+ Func->getContext()->statsUpdateSpills();
+ }
+ }
+ }
}
}