summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/XRayInstrumentation.cpp
diff options
context:
space:
mode:
authorSerge Rogatch <srogatch@accesssoftek.com>2017-06-09 13:23:23 +0000
committerSerge Rogatch <srogatch@accesssoftek.com>2017-06-09 13:23:23 +0000
commit85427c0da7282cfc6722a835451888510e154219 (patch)
tree7fe69af3ef69f6acfc7fb974bf1848908f2ee250 /llvm/lib/CodeGen/XRayInstrumentation.cpp
parentaf845f26e66603b927a14f74f9e54e776af6e0c7 (diff)
downloadbcm5719-llvm-85427c0da7282cfc6722a835451888510e154219.tar.gz
bcm5719-llvm-85427c0da7282cfc6722a835451888510e154219.zip
[XRay] Fix computation of function size subject to XRay threshold
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 llvm-svn: 305072
Diffstat (limited to 'llvm/lib/CodeGen/XRayInstrumentation.cpp')
-rw-r--r--llvm/lib/CodeGen/XRayInstrumentation.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/XRayInstrumentation.cpp b/llvm/lib/CodeGen/XRayInstrumentation.cpp
index 0ca11c0992d..1a8d5a4f45d 100644
--- a/llvm/lib/CodeGen/XRayInstrumentation.cpp
+++ b/llvm/lib/CodeGen/XRayInstrumentation.cpp
@@ -141,11 +141,16 @@ bool XRayInstrumentation::runOnMachineFunction(MachineFunction &MF) {
if (Attr.getValueAsString().getAsInteger(10, XRayThreshold))
return false; // Invalid value for threshold.
+ // Count the number of MachineInstr`s in MachineFunction
+ int64_t MICount = 0;
+ for (const auto& MBB : MF)
+ MICount += MBB.size();
+
// 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.
}
OpenPOWER on IntegriCloud