From: Ahmed Bougacha Date: Wed, 10 May 2017 00:39:25 +0000 (+0000) Subject: [CodeGen] Compute DT/LI lazily in SafeStackLegacyPass. NFC. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=294ef0b8d64e2b1e109a5bf94a2eff1e3becf064;p=llvm [CodeGen] Compute DT/LI lazily in SafeStackLegacyPass. NFC. We currently require SCEV, which requires DT/LI. Those are expensive to compute, but the pass only runs for functions that have the safestack attribute. Compute DT/LI to build SCEV lazily, only when the pass is actually going to transform the function. Differential Revision: https://reviews.llvm.org/D31302 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302610 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SafeStack.cpp b/lib/CodeGen/SafeStack.cpp index f0663ebde82..08b3d345f68 100644 --- a/lib/CodeGen/SafeStack.cpp +++ b/lib/CodeGen/SafeStack.cpp @@ -774,7 +774,8 @@ public: SafeStackLegacyPass() : SafeStackLegacyPass(nullptr) {} void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addRequired(); + AU.addRequired(); + AU.addRequired(); } bool runOnFunction(Function &F) override { @@ -799,7 +800,19 @@ public: report_fatal_error("TargetLowering instance is required"); auto *DL = &F.getParent()->getDataLayout(); - auto &SE = getAnalysis().getSE(); + auto &TLI = getAnalysis().getTLI(); + auto &ACT = getAnalysis().getAssumptionCache(F); + + // Compute DT and LI only for functions that have the attribute. + // This is only useful because the legacy pass manager doesn't let us + // compute analyzes lazily. + // In the backend pipeline, nothing preserves DT before SafeStack, so we + // would otherwise always compute it wastefully, even if there is no + // function with the safestack attribute. + DominatorTree DT(F); + LoopInfo LI(DT); + + ScalarEvolution SE(F, TLI, ACT, DT, LI); return SafeStack(F, *TL, *DL, SE).run(); } diff --git a/test/CodeGen/X86/O0-pipeline.ll b/test/CodeGen/X86/O0-pipeline.ll index ba95eba13fd..753861a01e8 100644 --- a/test/CodeGen/X86/O0-pipeline.ll +++ b/test/CodeGen/X86/O0-pipeline.ll @@ -27,9 +27,6 @@ ; CHECK-NEXT: FunctionPass Manager ; CHECK-NEXT: Dominator Tree Construction ; CHECK-NEXT: Exception handling preparation -; CHECK-NEXT: Dominator Tree Construction -; CHECK-NEXT: Natural Loop Information -; CHECK-NEXT: Scalar Evolution Analysis ; CHECK-NEXT: Safe Stack instrumentation pass ; CHECK-NEXT: Insert stack protectors ; CHECK-NEXT: Module Verifier