aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/SampleProfile.cpp
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-05-27 22:30:44 +0000
committerXinliang David Li <davidxl@google.com>2016-05-27 22:30:44 +0000
commite897edbd3631d5df50b2d193cb1abf7aaf64a004 (patch)
tree04030b7c7b87aade2be47eda8d8bd5fdd25bb7af /llvm/lib/Transforms/IPO/SampleProfile.cpp
parent852c55491b22a06bbf9403a0e4bc96883f3d2897 (diff)
downloadllvm-e897edbd3631d5df50b2d193cb1abf7aaf64a004.zip
llvm-e897edbd3631d5df50b2d193cb1abf7aaf64a004.tar.gz
llvm-e897edbd3631d5df50b2d193cb1abf7aaf64a004.tar.bz2
[PM] Port the Sample FDO to new PM (part-1)
llvm-svn: 271062
Diffstat (limited to 'llvm/lib/Transforms/IPO/SampleProfile.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/SampleProfile.cpp56
1 files changed, 37 insertions, 19 deletions
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 5cf490a..6c0ce76 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -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);