diff options
author | Michael Zolotukhin <mzolotukhin@apple.com> | 2018-03-20 17:02:29 +0000 |
---|---|---|
committer | Michael Zolotukhin <mzolotukhin@apple.com> | 2018-03-20 17:02:29 +0000 |
commit | fb3f509e01b8365e090fd727119125872d0ad85b (patch) | |
tree | fae90ca79bd7d71a706cd315ac841cb924156f37 /llvm/lib/CodeGen/XRayInstrumentation.cpp | |
parent | 54b161e47f51428763a8e4cd4d952d9e58301a89 (diff) | |
download | bcm5719-llvm-fb3f509e01b8365e090fd727119125872d0ad85b.tar.gz bcm5719-llvm-fb3f509e01b8365e090fd727119125872d0ad85b.zip |
[XRay] Lazily compute MachineLoopInfo instead of requiring it.
Summary:
Currently X-Ray Instrumentation pass has a dependency on MachineLoopInfo
(and thus on MachineDominatorTree as well) and we have to compute them
even if X-Ray is not used. This patch changes it to a lazy computation
to save compile time by avoiding these redundant computations.
Reviewers: dberris, kubamracek
Subscribers: llvm-commits, hiraditya
Differential Revision: https://reviews.llvm.org/D44666
llvm-svn: 327999
Diffstat (limited to 'llvm/lib/CodeGen/XRayInstrumentation.cpp')
-rw-r--r-- | llvm/lib/CodeGen/XRayInstrumentation.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/XRayInstrumentation.cpp b/llvm/lib/CodeGen/XRayInstrumentation.cpp index 3d83afcf1fc..32a7457c206 100644 --- a/llvm/lib/CodeGen/XRayInstrumentation.cpp +++ b/llvm/lib/CodeGen/XRayInstrumentation.cpp @@ -52,7 +52,6 @@ struct XRayInstrumentation : public MachineFunctionPass { void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesCFG(); - AU.addRequired<MachineLoopInfo>(); AU.addPreserved<MachineLoopInfo>(); AU.addPreserved<MachineDominatorTree>(); MachineFunctionPass::getAnalysisUsage(AU); @@ -160,11 +159,26 @@ bool XRayInstrumentation::runOnMachineFunction(MachineFunction &MF) { 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. } |