From: Dehao Chen Date: Mon, 20 Jun 2016 20:53:40 +0000 (+0000) Subject: Pass AssumptionCacheTracker from SampleProfileLoader to Inliner X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8122c25a1aed4022a746b91879b52dba2f6afe47;p=llvm Pass AssumptionCacheTracker from SampleProfileLoader to Inliner Summary: Inliner needs ACT when calling InlineFunction. Instead of nullptr, we need to pass it in from SampleProfileLoader Reviewers: davidxl Subscribers: eraman, vsk, danielcdh, llvm-commits Differential Revision: http://reviews.llvm.org/D21205 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273199 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/SampleProfile.cpp b/lib/Transforms/IPO/SampleProfile.cpp index 68310687f82..d25d9d4be1e 100644 --- a/lib/Transforms/IPO/SampleProfile.cpp +++ b/lib/Transforms/IPO/SampleProfile.cpp @@ -27,6 +27,7 @@ #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/PostDominators.h" #include "llvm/IR/Constants.h" @@ -105,11 +106,13 @@ typedef DenseMap> class SampleProfileLoader { public: SampleProfileLoader(StringRef Name = SampleProfileFile) - : DT(nullptr), PDT(nullptr), LI(nullptr), Reader(), Samples(nullptr), - Filename(Name), ProfileIsValid(false), TotalCollectedSamples(0) {} + : DT(nullptr), PDT(nullptr), LI(nullptr), ACT(nullptr), Reader(), + Samples(nullptr), Filename(Name), ProfileIsValid(false), + TotalCollectedSamples(0) {} bool doInitialization(Module &M); bool runOnModule(Module &M); + void setACT(AssumptionCacheTracker *A) { ACT = A; } void dump() { Reader->dump(); } @@ -169,6 +172,8 @@ protected: std::unique_ptr> PDT; std::unique_ptr LI; + AssumptionCacheTracker *ACT; + /// \brief Predecessors for each basic block in the CFG. BlockEdgeMap Predecessors; @@ -213,6 +218,9 @@ public: const char *getPassName() const override { return "Sample profile pass"; } bool runOnModule(Module &M) override; + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addRequired(); + } private: SampleProfileLoader SampleLoader; }; @@ -698,7 +706,7 @@ bool SampleProfileLoader::inlineHotFunctions(Function &F) { } } for (auto CI : CIS) { - InlineFunctionInfo IFI; + InlineFunctionInfo IFI(nullptr, ACT); Function *CalledFunction = CI->getCalledFunction(); DebugLoc DLoc = CI->getDebugLoc(); uint64_t NumSamples = findCalleeFunctionSamples(*CI)->getTotalSamples(); @@ -1226,7 +1234,10 @@ bool SampleProfileLoader::emitAnnotations(Function &F) { } char SampleProfileLoaderLegacyPass::ID = 0; -INITIALIZE_PASS(SampleProfileLoaderLegacyPass, "sample-profile", +INITIALIZE_PASS_BEGIN(SampleProfileLoaderLegacyPass, "sample-profile", + "Sample Profile loader", false, false) +INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker) +INITIALIZE_PASS_END(SampleProfileLoaderLegacyPass, "sample-profile", "Sample Profile loader", false, false) bool SampleProfileLoader::doInitialization(Module &M) { @@ -1268,6 +1279,8 @@ bool SampleProfileLoader::runOnModule(Module &M) { } bool SampleProfileLoaderLegacyPass::runOnModule(Module &M) { + // FIXME: pass in AssumptionCache correctly for the new pass manager. + SampleLoader.setACT(&getAnalysis()); return SampleLoader.runOnModule(M); } diff --git a/test/Transforms/SampleProfile/Inputs/inline-act.prof b/test/Transforms/SampleProfile/Inputs/inline-act.prof new file mode 100644 index 00000000000..655739f3788 --- /dev/null +++ b/test/Transforms/SampleProfile/Inputs/inline-act.prof @@ -0,0 +1,3 @@ +_Z3bari:100:0 + 1: _Z3fooi:100 + 2: 100 diff --git a/test/Transforms/SampleProfile/inline-act.ll b/test/Transforms/SampleProfile/inline-act.ll new file mode 100644 index 00000000000..6383dfbddf9 --- /dev/null +++ b/test/Transforms/SampleProfile/inline-act.ll @@ -0,0 +1,72 @@ +; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/inline-act.prof + +; Sample profile should have non-empty ACT passed to inliner + +; int t; +; bool foo(int value) { +; switch(value) { +; case 0: +; case 1: +; case 3: +; return true; +; default: +; return false; +; } +; } +; void bar(int i) { +; if (foo(i)) +; t *= 2; +; } + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@t = global i32 0, align 4 + +; Function Attrs: nounwind uwtable +define zeroext i1 @_Z3fooi(i32) #0 { + %switch.tableidx = sub i32 %0, 0 + %2 = icmp ult i32 %switch.tableidx, 4 + br i1 %2, label %switch.lookup, label %3 + +switch.lookup: ; preds = %1 + %switch.cast = trunc i32 %switch.tableidx to i4 + %switch.shiftamt = mul i4 %switch.cast, 1 + %switch.downshift = lshr i4 -5, %switch.shiftamt + %switch.masked = trunc i4 %switch.downshift to i1 + ret i1 %switch.masked + +;