[PM] Port the Sample FDO to new PM (part-1)

llvm-svn: 271062
This commit is contained in:
Xinliang David Li 2016-05-27 22:30:44 +00:00
parent 852c55491b
commit e897edbd36
3 changed files with 39 additions and 21 deletions

View File

@ -70,7 +70,7 @@ void initializeAliasSetPrinterPass(PassRegistry&);
void initializeAlwaysInlinerPass(PassRegistry&);
void initializeArgPromotionPass(PassRegistry&);
void initializeAtomicExpandPass(PassRegistry&);
void initializeSampleProfileLoaderPass(PassRegistry&);
void initializeSampleProfileLoaderLegacyPassPass(PassRegistry&);
void initializeAlignmentFromAssumptionsPass(PassRegistry&);
void initializeBarrierNoopPass(PassRegistry&);
void initializeBasicAAWrapperPassPass(PassRegistry&);

View File

@ -52,7 +52,7 @@ void llvm::initializeIPO(PassRegistry &Registry) {
initializeStripNonDebugSymbolsPass(Registry);
initializeBarrierNoopPass(Registry);
initializeEliminateAvailableExternallyLegacyPassPass(Registry);
initializeSampleProfileLoaderPass(Registry);
initializeSampleProfileLoaderLegacyPassPass(Registry);
initializeFunctionImportPassPass(Registry);
initializeWholeProgramDevirtPass(Registry);
}

View File

@ -101,26 +101,17 @@ typedef DenseMap<const BasicBlock *, SmallVector<const BasicBlock *, 8>>
/// 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 ModulePass {
class SampleProfileLoader {
public:
// Class identification, replacement for typeinfo
static char ID;
SampleProfileLoader(StringRef Name = SampleProfileFile)
: ModulePass(ID), DT(nullptr), PDT(nullptr), LI(nullptr), Reader(),
Samples(nullptr), Filename(Name), ProfileIsValid(false),
TotalCollectedSamples(0) {
initializeSampleProfileLoaderPass(*PassRegistry::getPassRegistry());
}
: DT(nullptr), PDT(nullptr), LI(nullptr), Reader(), Samples(nullptr),
Filename(Name), ProfileIsValid(false), TotalCollectedSamples(0) {}
bool doInitialization(Module &M) override;
bool doInitialization(Module &M);
bool runOnModule(Module &M);
void dump() { Reader->dump(); }
const char *getPassName() const override { return "Sample profile pass"; }
bool runOnModule(Module &M) override;
protected:
bool runOnFunction(Function &F);
unsigned getFunctionLoc(Function &F);
@ -202,6 +193,29 @@ protected:
uint64_t TotalCollectedSamples;
};
class SampleProfileLoaderLegacyPass : public ModulePass {
public:
// Class identification, replacement for typeinfo
static char ID;
SampleProfileLoaderLegacyPass(StringRef Name = SampleProfileFile)
: ModulePass(ID), SampleLoader(Name) {
initializeSampleProfileLoaderLegacyPassPass(
*PassRegistry::getPassRegistry());
}
void dump() { SampleLoader.dump(); }
bool doInitialization(Module &M) override {
return SampleLoader.doInitialization(M);
}
const char *getPassName() const override { return "Sample profile pass"; }
bool runOnModule(Module &M) override;
private:
SampleProfileLoader SampleLoader;
};
class SampleCoverageTracker {
public:
SampleCoverageTracker() : SampleCoverage(), TotalUsedSamples(0) {}
@ -1210,10 +1224,10 @@ bool SampleProfileLoader::emitAnnotations(Function &F) {
return Changed;
}
char SampleProfileLoader::ID = 0;
INITIALIZE_PASS_BEGIN(SampleProfileLoader, "sample-profile",
char SampleProfileLoaderLegacyPass::ID = 0;
INITIALIZE_PASS_BEGIN(SampleProfileLoaderLegacyPass, "sample-profile",
"Sample Profile loader", false, false)
INITIALIZE_PASS_END(SampleProfileLoader, "sample-profile",
INITIALIZE_PASS_END(SampleProfileLoaderLegacyPass, "sample-profile",
"Sample Profile loader", false, false)
bool SampleProfileLoader::doInitialization(Module &M) {
@ -1230,11 +1244,11 @@ bool SampleProfileLoader::doInitialization(Module &M) {
}
ModulePass *llvm::createSampleProfileLoaderPass() {
return new SampleProfileLoader(SampleProfileFile);
return new SampleProfileLoaderLegacyPass(SampleProfileFile);
}
ModulePass *llvm::createSampleProfileLoaderPass(StringRef Name) {
return new SampleProfileLoader(Name);
return new SampleProfileLoaderLegacyPass(Name);
}
bool SampleProfileLoader::runOnModule(Module &M) {
@ -1254,6 +1268,10 @@ bool SampleProfileLoader::runOnModule(Module &M) {
return retval;
}
bool SampleProfileLoaderLegacyPass::runOnModule(Module &M) {
return SampleLoader.runOnModule(M);
}
bool SampleProfileLoader::runOnFunction(Function &F) {
F.setEntryCount(0);
Samples = Reader->getSamplesFor(F);