[PATCH] D44666: [XRay] Lazily compute MachineLoopInfo instead of requiring it.

Michael Zolotukhin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 20 10:05:11 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL327999: [XRay] Lazily compute MachineLoopInfo instead of requiring it. (authored by mzolotukhin, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44666?vs=139060&id=139152#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44666

Files:
  llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp
  llvm/trunk/test/CodeGen/X86/O0-pipeline.ll


Index: llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp
+++ llvm/trunk/lib/CodeGen/XRayInstrumentation.cpp
@@ -52,7 +52,6 @@
 
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.setPreservesCFG();
-    AU.addRequired<MachineLoopInfo>();
     AU.addPreserved<MachineLoopInfo>();
     AU.addPreserved<MachineDominatorTree>();
     MachineFunctionPass::getAnalysisUsage(AU);
@@ -160,11 +159,26 @@
     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;
+    }
+
+    // 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?
-    MachineLoopInfo &MLI = getAnalysis<MachineLoopInfo>();
-    if (MLI.empty() && MICount < XRayThreshold)
+    if (MLI->empty() && MICount < XRayThreshold)
       return false; // Function is too small and has no loops.
   }
 
Index: llvm/trunk/test/CodeGen/X86/O0-pipeline.ll
===================================================================
--- llvm/trunk/test/CodeGen/X86/O0-pipeline.ll
+++ llvm/trunk/test/CodeGen/X86/O0-pipeline.ll
@@ -55,8 +55,6 @@
 ; CHECK-NEXT:       StackMap Liveness Analysis
 ; CHECK-NEXT:       Live DEBUG_VALUE analysis
 ; CHECK-NEXT:       Insert fentry calls
-; CHECK-NEXT:       MachineDominator Tree Construction
-; CHECK-NEXT:       Machine Natural Loop Construction
 ; CHECK-NEXT:       Insert XRay ops
 ; CHECK-NEXT:       Implement the 'patchable-function' attribute
 ; CHECK-NEXT:       X86 Retpoline Thunks


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44666.139152.patch
Type: text/x-patch
Size: 2148 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180320/9363bb8e/attachment.bin>


More information about the llvm-commits mailing list