Summary:
Currently XRay compares its threshold against `Function::size()` . However, `Function::size()` returns the number of basic blocks (as I understand, such as cycle bodies, if/else bodies, switch-case bodies, etc.), rather than the number of instructions.
The name of the parameter `-fxray-instruction-threshold=N`, as well as XRay documentation at http://llvm.org/docs/XRay.html , suggests that instructions should be counted, rather than the number of basic blocks.
I see two options:
1. Count the number of MachineInstr`s in MachineFunction : this gives better estimate for the number of assembly instructions on the target. So a user can check in disassembly that the threshold works more or less correctly.
2. Count the number of Instruction`s in a Function : AFAIK, this gives correct number of IR instructions, which the user can check in IR listing. However, this number may be far (several times for small functions) from the number of assembly instructions finally emitted.
Option 1 is implemented in this patch because I think that having the closer estimate for the number of assembly instructions emitted is more important than to have a clear definition of the metric.
Reviewers: dberris, rengolin
Reviewed By: dberris
Subscribers: llvm-commits, iid_iunknown
Differential Revision: https://reviews.llvm.org/D34027
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@305072
91177308-0d34-0410-b5e6-
96231b3b80d8
if (Attr.getValueAsString().getAsInteger(10, XRayThreshold))
return false; // Invalid value for threshold.
+ // Count the number of MachineInstr`s in MachineFunction
+ int64_t MICount = 0;\r
+ for (const auto& MBB : MF)\r
+ MICount += MBB.size();\r
+
// Check if we have a loop.
// FIXME: Maybe make this smarter, and see whether the loops are dependent
// on inputs or side-effects?
MachineLoopInfo &MLI = getAnalysis<MachineLoopInfo>();
- if (MLI.empty() && F.size() < XRayThreshold)
+ if (MLI.empty() && MICount < XRayThreshold)
return false; // Function is too small and has no loops.
}