[llvm] 7628e47 - [xray] Add xray-ignore-loops option
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 17 13:32:54 PST 2020
Author: Ian Levesque
Date: 2020-01-17T13:32:17-08:00
New Revision: 7628e474a5916ed8a43c015248443f4c03077509
URL: https://github.com/llvm/llvm-project/commit/7628e474a5916ed8a43c015248443f4c03077509
DIFF: https://github.com/llvm/llvm-project/commit/7628e474a5916ed8a43c015248443f4c03077509.diff
LOG: [xray] Add xray-ignore-loops option
XRay allows tuning by minimum function size, but also always instruments
functions with loops in them. If the minimum function size is set to a
large value the loop instrumention ends up causing most functions to be
instrumented anyway. This adds a new flag, xray-ignore-loops, to disable
the loop detection logic.
Differential Revision: https://reviews.llvm.org/D72659
Added:
llvm/test/CodeGen/X86/xray-ignore-loop-detection.ll
Modified:
llvm/lib/CodeGen/XRayInstrumentation.cpp
llvm/test/CodeGen/X86/xray-loop-detection.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/XRayInstrumentation.cpp b/llvm/lib/CodeGen/XRayInstrumentation.cpp
index 4847a0c3e842..a7ccfba1a2fc 100644
--- a/llvm/lib/CodeGen/XRayInstrumentation.cpp
+++ b/llvm/lib/CodeGen/XRayInstrumentation.cpp
@@ -148,40 +148,51 @@ bool XRayInstrumentation::runOnMachineFunction(MachineFunction &MF) {
bool AlwaysInstrument = !InstrAttr.hasAttribute(Attribute::None) &&
InstrAttr.isStringAttribute() &&
InstrAttr.getValueAsString() == "xray-always";
- Attribute Attr = F.getFnAttribute("xray-instruction-threshold");
- unsigned XRayThreshold = 0;
+ auto ThresholdAttr = F.getFnAttribute("xray-instruction-threshold");
+ auto IgnoreLoopsAttr = F.getFnAttribute("xray-ignore-loops");
+ unsigned int XRayThreshold = 0;
if (!AlwaysInstrument) {
- if (Attr.hasAttribute(Attribute::None) || !Attr.isStringAttribute())
+ if (ThresholdAttr.hasAttribute(Attribute::None) ||
+ !ThresholdAttr.isStringAttribute())
return false; // XRay threshold attribute not found.
- if (Attr.getValueAsString().getAsInteger(10, XRayThreshold))
+ if (ThresholdAttr.getValueAsString().getAsInteger(10, XRayThreshold))
return false; // Invalid value for threshold.
+ bool IgnoreLoops = !IgnoreLoopsAttr.hasAttribute(Attribute::None);
+
// Count the number of MachineInstr`s in MachineFunction
int64_t MICount = 0;
for (const auto &MBB : MF)
MICount += MBB.size();
- // Get MachineDominatorTree or compute it on the fly if it's unavailable
- auto *MDT = getAnalysisIfAvailable<MachineDominatorTree>();
- MachineDominatorTree ComputedMDT;
- if (!MDT) {
- ComputedMDT.getBase().recalculate(MF);
- MDT = &ComputedMDT;
- }
+ bool TooFewInstrs = MICount < XRayThreshold;
- // Get MachineLoopInfo or compute it on the fly if it's unavailable
- auto *MLI = getAnalysisIfAvailable<MachineLoopInfo>();
- MachineLoopInfo ComputedMLI;
- if (!MLI) {
- ComputedMLI.getBase().analyze(MDT->getBase());
- MLI = &ComputedMLI;
- }
+ if (!IgnoreLoops) {
+ // Get MachineDominatorTree or compute it on the fly if it's unavailable
+ auto *MDT = getAnalysisIfAvailable<MachineDominatorTree>();
+ MachineDominatorTree ComputedMDT;
+ if (!MDT) {
+ ComputedMDT.getBase().recalculate(MF);
+ MDT = &ComputedMDT;
+ }
- // Check if we have a loop.
- // FIXME: Maybe make this smarter, and see whether the loops are dependent
- // on inputs or side-effects?
- if (MLI->empty() && MICount < XRayThreshold)
- return false; // Function is too small and has no loops.
+ // Get MachineLoopInfo or compute it on the fly if it's unavailable
+ auto *MLI = getAnalysisIfAvailable<MachineLoopInfo>();
+ MachineLoopInfo ComputedMLI;
+ if (!MLI) {
+ ComputedMLI.getBase().analyze(MDT->getBase());
+ MLI = &ComputedMLI;
+ }
+
+ // Check if we have a loop.
+ // FIXME: Maybe make this smarter, and see whether the loops are dependent
+ // on inputs or side-effects?
+ if (MLI->empty() && TooFewInstrs)
+ return false; // Function is too small and has no loops.
+ } else if (TooFewInstrs) {
+ // Function is too small
+ return false;
+ }
}
// We look for the first non-empty MachineBasicBlock, so that we can insert
diff --git a/llvm/test/CodeGen/X86/xray-ignore-loop-detection.ll b/llvm/test/CodeGen/X86/xray-ignore-loop-detection.ll
new file mode 100644
index 000000000000..2450d991e3aa
--- /dev/null
+++ b/llvm/test/CodeGen/X86/xray-ignore-loop-detection.ll
@@ -0,0 +1,19 @@
+; RUN: llc -verify-machineinstrs -filetype=asm -o - -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -filetype=asm -o - -mtriple=x86_64-darwin-unknown < %s | FileCheck %s
+
+define i32 @foo(i32 %i) nounwind noinline uwtable "xray-instruction-threshold"="10" "xray-ignore-loops" {
+entry:
+ br label %Test
+Test:
+ %indvar = phi i32 [0, %entry], [%nextindvar, %Inc]
+ %cond = icmp eq i32 %indvar, %i
+ br i1 %cond, label %Exit, label %Inc
+Inc:
+ %nextindvar = add i32 %indvar, 1
+ br label %Test
+Exit:
+ %retval = phi i32 [%indvar, %Test]
+ ret i32 %retval
+}
+
+; CHECK-NOT: xray_sled_0:
diff --git a/llvm/test/CodeGen/X86/xray-loop-detection.ll b/llvm/test/CodeGen/X86/xray-loop-detection.ll
index c47592eef021..4acb22983be3 100644
--- a/llvm/test/CodeGen/X86/xray-loop-detection.ll
+++ b/llvm/test/CodeGen/X86/xray-loop-detection.ll
@@ -1,7 +1,7 @@
; RUN: llc -verify-machineinstrs -filetype=asm -o - -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
; RUN: llc -verify-machineinstrs -filetype=asm -o - -mtriple=x86_64-darwin-unknown < %s | FileCheck %s
-define i32 @foo(i32 %i) nounwind noinline uwtable "xray-instruction-threshold"="1" {
+define i32 @foo(i32 %i) nounwind noinline uwtable "xray-instruction-threshold"="10" {
entry:
br label %Test
Test:
More information about the llvm-commits
mailing list