diff options
author | Diego Novillo <dnovillo@google.com> | 2015-08-25 15:25:11 +0000 |
---|---|---|
committer | Diego Novillo <dnovillo@google.com> | 2015-08-25 15:25:11 +0000 |
commit | 4d71113cdb81af02305f643c9176ba3bfb1be5db (patch) | |
tree | cc460f74c14bb639a4f11a3a1bb02aa6ca411852 /llvm/lib/Transforms | |
parent | 627cbd31d18207192fa7970d16c63a7d5ab3beae (diff) | |
download | bcm5719-llvm-4d71113cdb81af02305f643c9176ba3bfb1be5db.tar.gz bcm5719-llvm-4d71113cdb81af02305f643c9176ba3bfb1be5db.zip |
Convert SampleProfile pass into a Module pass.
Eventually, we will need sample profiles to be incorporated into the
inliner's cost models. To do this, we need the sample profile pass to
be a module pass.
This patch makes no functional changes beyond the mechanical adjustments
needed to run SampleProfile as a module pass.
llvm-svn: 245940
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/IPO/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/IPO.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/SampleProfile.cpp (renamed from llvm/lib/Transforms/Scalar/SampleProfile.cpp) | 41 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/Scalar.cpp | 1 |
5 files changed, 31 insertions, 14 deletions
diff --git a/llvm/lib/Transforms/IPO/CMakeLists.txt b/llvm/lib/Transforms/IPO/CMakeLists.txt index 336dac45e13..8c777548137 100644 --- a/llvm/lib/Transforms/IPO/CMakeLists.txt +++ b/llvm/lib/Transforms/IPO/CMakeLists.txt @@ -20,6 +20,7 @@ add_llvm_library(LLVMipo PartialInlining.cpp PassManagerBuilder.cpp PruneEH.cpp + SampleProfile.cpp StripDeadPrototypes.cpp StripSymbols.cpp diff --git a/llvm/lib/Transforms/IPO/IPO.cpp b/llvm/lib/Transforms/IPO/IPO.cpp index 50f56b0f2af..6efa1193dc0 100644 --- a/llvm/lib/Transforms/IPO/IPO.cpp +++ b/llvm/lib/Transforms/IPO/IPO.cpp @@ -47,6 +47,7 @@ void llvm::initializeIPO(PassRegistry &Registry) { initializeStripNonDebugSymbolsPass(Registry); initializeBarrierNoopPass(Registry); initializeEliminateAvailableExternallyPass(Registry); + initializeSampleProfileLoaderPass(Registry); } void LLVMInitializeIPO(LLVMPassRegistryRef R) { diff --git a/llvm/lib/Transforms/Scalar/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp index c8dfa54a4aa..f6602fda430 100644 --- a/llvm/lib/Transforms/Scalar/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -22,7 +22,6 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Transforms/Scalar.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallSet.h" @@ -45,6 +44,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Transforms/IPO.h" #include <cctype> using namespace llvm; @@ -74,14 +74,15 @@ typedef DenseMap<BasicBlock *, SmallVector<BasicBlock *, 8>> BlockEdgeMap; /// This pass reads profile data from the file specified by /// -sample-profile-file and annotates every affected function with the /// profile information found in that file. -class SampleProfileLoader : public FunctionPass { +class SampleProfileLoader : public ModulePass { public: // Class identification, replacement for typeinfo static char ID; SampleProfileLoader(StringRef Name = SampleProfileFile) - : FunctionPass(ID), DT(nullptr), PDT(nullptr), LI(nullptr), Ctx(nullptr), - Reader(), Samples(nullptr), Filename(Name), ProfileIsValid(false) { + : ModulePass(ID), DT(nullptr), PDT(nullptr), LI(nullptr), + Ctx(nullptr), Reader(), Samples(nullptr), Filename(Name), + ProfileIsValid(false) { initializeSampleProfileLoaderPass(*PassRegistry::getPassRegistry()); } @@ -91,16 +92,23 @@ public: const char *getPassName() const override { return "Sample profile pass"; } - bool runOnFunction(Function &F) override; + bool runOnModule(Module &M) override; void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesCFG(); + AU.addRequired<LoopInfoWrapperPass>(); + AU.addPreserved<LoopInfoWrapperPass>(); + AU.addRequired<DominatorTreeWrapperPass>(); + AU.addPreserved<DominatorTreeWrapperPass>(); + AU.addRequired<PostDominatorTree>(); + AU.addPreserved<PostDominatorTree>(); } protected: + bool runOnFunction(Function &F); unsigned getFunctionLoc(Function &F); bool emitAnnotations(Function &F); unsigned getInstWeight(Instruction &I); @@ -743,10 +751,11 @@ INITIALIZE_PASS_END(SampleProfileLoader, "sample-profile", "Sample Profile loader", false, false) bool SampleProfileLoader::doInitialization(Module &M) { - auto ReaderOrErr = SampleProfileReader::create(Filename, M.getContext()); + auto& Ctx = M.getContext(); + auto ReaderOrErr = SampleProfileReader::create(Filename, Ctx); if (std::error_code EC = ReaderOrErr.getError()) { std::string Msg = "Could not open profile: " + EC.message(); - M.getContext().diagnose(DiagnosticInfoSampleProfile(Filename.data(), Msg)); + Ctx.diagnose(DiagnosticInfoSampleProfile(Filename.data(), Msg)); return false; } Reader = std::move(ReaderOrErr.get()); @@ -754,21 +763,29 @@ bool SampleProfileLoader::doInitialization(Module &M) { return true; } -FunctionPass *llvm::createSampleProfileLoaderPass() { +ModulePass *llvm::createSampleProfileLoaderPass() { return new SampleProfileLoader(SampleProfileFile); } -FunctionPass *llvm::createSampleProfileLoaderPass(StringRef Name) { +ModulePass *llvm::createSampleProfileLoaderPass(StringRef Name) { return new SampleProfileLoader(Name); } +bool SampleProfileLoader::runOnModule(Module &M) { + bool retval = false; + for (auto &F : M) + if (!F.isDeclaration()) + retval |= runOnFunction(F); + return retval; +} + bool SampleProfileLoader::runOnFunction(Function &F) { if (!ProfileIsValid) return false; - DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); - PDT = &getAnalysis<PostDominatorTree>(); - LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); + DT = &getAnalysis<DominatorTreeWrapperPass>(F).getDomTree(); + PDT = &getAnalysis<PostDominatorTree>(F); + LI = &getAnalysis<LoopInfoWrapperPass>(F).getLoopInfo(); Ctx = &F.getParent()->getContext(); Samples = Reader->getSamplesFor(F); if (!Samples->empty()) diff --git a/llvm/lib/Transforms/Scalar/CMakeLists.txt b/llvm/lib/Transforms/Scalar/CMakeLists.txt index 7ee279a5660..1bbbb0317de 100644 --- a/llvm/lib/Transforms/Scalar/CMakeLists.txt +++ b/llvm/lib/Transforms/Scalar/CMakeLists.txt @@ -38,7 +38,6 @@ add_llvm_library(LLVMScalarOpts RewriteStatepointsForGC.cpp SCCP.cpp SROA.cpp - SampleProfile.cpp Scalar.cpp ScalarReplAggregates.cpp Scalarizer.cpp diff --git a/llvm/lib/Transforms/Scalar/Scalar.cpp b/llvm/lib/Transforms/Scalar/Scalar.cpp index a0180f13c1d..54b78e36965 100644 --- a/llvm/lib/Transforms/Scalar/Scalar.cpp +++ b/llvm/lib/Transforms/Scalar/Scalar.cpp @@ -33,7 +33,6 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) { initializeADCEPass(Registry); initializeBDCEPass(Registry); initializeAlignmentFromAssumptionsPass(Registry); - initializeSampleProfileLoaderPass(Registry); initializeConstantHoistingPass(Registry); initializeConstantPropagationPass(Registry); initializeCorrelatedValuePropagationPass(Registry); |