mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-20 19:25:05 +00:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245940 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
39e2b39af7
commit
eb6eb153d9
@ -16,6 +16,7 @@
|
||||
#define LLVM_TRANSFORMS_IPO_H
|
||||
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
@ -209,6 +210,12 @@ ModulePass *createBarrierNoopPass();
|
||||
/// to bitsets.
|
||||
ModulePass *createLowerBitSetsPass();
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// SampleProfilePass - Loads sample profile data from disk and generates
|
||||
// IR metadata to reflect the profile.
|
||||
ModulePass *createSampleProfileLoaderPass();
|
||||
ModulePass *createSampleProfileLoaderPass(StringRef Name);
|
||||
|
||||
} // End llvm namespace
|
||||
|
||||
#endif
|
||||
|
@ -406,13 +406,6 @@ FunctionPass *createLowerExpectIntrinsicPass();
|
||||
//
|
||||
FunctionPass *createPartiallyInlineLibCallsPass();
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// SampleProfilePass - Loads sample profile data from disk and generates
|
||||
// IR metadata to reflect the profile.
|
||||
FunctionPass *createSampleProfileLoaderPass();
|
||||
FunctionPass *createSampleProfileLoaderPass(StringRef Name);
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// ScalarizerPass - Converts vector operations into scalar operations
|
||||
|
@ -20,6 +20,7 @@ add_llvm_library(LLVMipo
|
||||
PartialInlining.cpp
|
||||
PassManagerBuilder.cpp
|
||||
PruneEH.cpp
|
||||
SampleProfile.cpp
|
||||
StripDeadPrototypes.cpp
|
||||
StripSymbols.cpp
|
||||
|
||||
|
@ -47,6 +47,7 @@ void llvm::initializeIPO(PassRegistry &Registry) {
|
||||
initializeStripNonDebugSymbolsPass(Registry);
|
||||
initializeBarrierNoopPass(Registry);
|
||||
initializeEliminateAvailableExternallyPass(Registry);
|
||||
initializeSampleProfileLoaderPass(Registry);
|
||||
}
|
||||
|
||||
void LLVMInitializeIPO(LLVMPassRegistryRef R) {
|
||||
|
@ -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())
|
@ -38,7 +38,6 @@ add_llvm_library(LLVMScalarOpts
|
||||
RewriteStatepointsForGC.cpp
|
||||
SCCP.cpp
|
||||
SROA.cpp
|
||||
SampleProfile.cpp
|
||||
Scalar.cpp
|
||||
ScalarReplAggregates.cpp
|
||||
Scalarizer.cpp
|
||||
|
@ -33,7 +33,6 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) {
|
||||
initializeADCEPass(Registry);
|
||||
initializeBDCEPass(Registry);
|
||||
initializeAlignmentFromAssumptionsPass(Registry);
|
||||
initializeSampleProfileLoaderPass(Registry);
|
||||
initializeConstantHoistingPass(Registry);
|
||||
initializeConstantPropagationPass(Registry);
|
||||
initializeCorrelatedValuePropagationPass(Registry);
|
||||
|
Loading…
x
Reference in New Issue
Block a user