summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2017-12-05 21:54:01 +0000
committerXinliang David Li <davidxl@google.com>2017-12-05 21:54:01 +0000
commit45c819063adcbb9bde51b51de8eecda995392026 (patch)
tree0c10a70af6323ae6a4032f62b2e6881c76605543 /llvm/lib/Transforms
parentd806af3499c5fcc6df0e014a9739bd99ac01cf7d (diff)
downloadbcm5719-llvm-45c819063adcbb9bde51b51de8eecda995392026.tar.gz
bcm5719-llvm-45c819063adcbb9bde51b51de8eecda995392026.zip
Revert r319794: [PGO] detect infinite loop and form MST properly: memory leak problem
llvm-svn: 319841
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Instrumentation/CFGMST.h22
-rw-r--r--llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp50
2 files changed, 15 insertions, 57 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/CFGMST.h b/llvm/lib/Transforms/Instrumentation/CFGMST.h
index a1c2670c659..16e2e6b4e73 100644
--- a/llvm/lib/Transforms/Instrumentation/CFGMST.h
+++ b/llvm/lib/Transforms/Instrumentation/CFGMST.h
@@ -20,7 +20,6 @@
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/Analysis/CFG.h"
-#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
@@ -137,21 +136,6 @@ public:
<< " w = " << BBWeight << "\n");
}
}
- // check if there is any infinite loop. If yes, add a fake edge from
- // the header block to the fake node:
- for (auto *L : *LI) {
- SmallVector<BasicBlock *, 2> ExitingBlocks;
- L->getExitingBlocks(ExitingBlocks);
- if (!ExitingBlocks.empty())
- continue;
- auto *HB = L->getHeader();
- if (!HB)
- continue;
- addEdge(HB, nullptr, UINT64_MAX);
- DEBUG(dbgs() << " Edge: from infinite loop header "
- << HB->getName() << " to exit"
- << " w = " << UINT64_MAX << "\n");
- }
}
// Sort CFG edges based on its weight.
@@ -228,13 +212,11 @@ public:
BranchProbabilityInfo *BPI;
BlockFrequencyInfo *BFI;
- LoopInfo *LI;
public:
CFGMST(Function &Func, BranchProbabilityInfo *BPI_ = nullptr,
- BlockFrequencyInfo *BFI_ = nullptr,
- LoopInfo *LI_ = nullptr)
- : F(Func), BPI(BPI_), BFI(BFI_), LI(LI_) {
+ BlockFrequencyInfo *BFI_ = nullptr)
+ : F(Func), BPI(BPI_), BFI(BFI_) {
buildEdges();
sortEdgesByWeight();
computeMinimumSpanningTree();
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index 16ecb4a2415..47278e19283 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -390,7 +390,6 @@ private:
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<BlockFrequencyInfoWrapperPass>();
- AU.addRequired<LoopInfoWrapperPass>();
}
};
@@ -416,7 +415,6 @@ private:
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<BlockFrequencyInfoWrapperPass>();
- AU.addRequired<LoopInfoWrapperPass>();
}
};
@@ -428,7 +426,6 @@ INITIALIZE_PASS_BEGIN(PGOInstrumentationGenLegacyPass, "pgo-instr-gen",
"PGO instrumentation.", false, false)
INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
INITIALIZE_PASS_END(PGOInstrumentationGenLegacyPass, "pgo-instr-gen",
"PGO instrumentation.", false, false)
@@ -442,7 +439,6 @@ INITIALIZE_PASS_BEGIN(PGOInstrumentationUseLegacyPass, "pgo-instr-use",
"Read PGO instrumentation profile.", false, false)
INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass)
INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
INITIALIZE_PASS_END(PGOInstrumentationUseLegacyPass, "pgo-instr-use",
"Read PGO instrumentation profile.", false, false)
@@ -534,9 +530,9 @@ public:
Function &Func,
std::unordered_multimap<Comdat *, GlobalValue *> &ComdatMembers,
bool CreateGlobalVar = false, BranchProbabilityInfo *BPI = nullptr,
- BlockFrequencyInfo *BFI = nullptr, LoopInfo *LI = nullptr)
+ BlockFrequencyInfo *BFI = nullptr)
: F(Func), ComdatMembers(ComdatMembers), ValueSites(IPVK_Last + 1),
- SIVisitor(Func), MIVisitor(Func), MST(F, BPI, BFI, LI) {
+ SIVisitor(Func), MIVisitor(Func), MST(F, BPI, BFI) {
// This should be done before CFG hash computation.
SIVisitor.countSelects(Func);
MIVisitor.countMemIntrinsics(Func);
@@ -719,10 +715,9 @@ BasicBlock *FuncPGOInstrumentation<Edge, BBInfo>::getInstrBB(Edge *E) {
// Critical edges will be split.
static void instrumentOneFunc(
Function &F, Module *M, BranchProbabilityInfo *BPI, BlockFrequencyInfo *BFI,
- LoopInfo *LI,
std::unordered_multimap<Comdat *, GlobalValue *> &ComdatMembers) {
FuncPGOInstrumentation<PGOEdge, BBInfo> FuncInfo(F, ComdatMembers, true, BPI,
- BFI, LI);
+ BFI);
unsigned NumCounters = FuncInfo.getNumCounters();
uint32_t I = 0;
@@ -849,10 +844,9 @@ public:
PGOUseFunc(Function &Func, Module *Modu,
std::unordered_multimap<Comdat *, GlobalValue *> &ComdatMembers,
BranchProbabilityInfo *BPI = nullptr,
- BlockFrequencyInfo *BFIin = nullptr,
- LoopInfo *LI = nullptr)
+ BlockFrequencyInfo *BFIin = nullptr)
: F(Func), M(Modu), BFI(BFIin),
- FuncInfo(Func, ComdatMembers, false, BPI, BFIin, LI),
+ FuncInfo(Func, ComdatMembers, false, BPI, BFIin),
FreqAttr(FFA_Normal) {}
// Read counts for the instrumented BB from profile.
@@ -1385,8 +1379,7 @@ static void collectComdatMembers(
static bool InstrumentAllFunctions(
Module &M, function_ref<BranchProbabilityInfo *(Function &)> LookupBPI,
- function_ref<BlockFrequencyInfo *(Function &)> LookupBFI,
- function_ref<LoopInfo *(Function &)> LookupLI) {
+ function_ref<BlockFrequencyInfo *(Function &)> LookupBFI) {
createIRLevelProfileFlagVariable(M);
std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers;
collectComdatMembers(M, ComdatMembers);
@@ -1396,8 +1389,7 @@ static bool InstrumentAllFunctions(
continue;
auto *BPI = LookupBPI(F);
auto *BFI = LookupBFI(F);
- auto *LI = LookupLI(F);
- instrumentOneFunc(F, &M, BPI, BFI, LI, ComdatMembers);
+ instrumentOneFunc(F, &M, BPI, BFI, ComdatMembers);
}
return true;
}
@@ -1412,10 +1404,7 @@ bool PGOInstrumentationGenLegacyPass::runOnModule(Module &M) {
auto LookupBFI = [this](Function &F) {
return &this->getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI();
};
- auto LookupLI = [this](Function &F) {
- return &this->getAnalysis<LoopInfoWrapperPass>(F).getLoopInfo();
- };
- return InstrumentAllFunctions(M, LookupBPI, LookupBFI, LookupLI);
+ return InstrumentAllFunctions(M, LookupBPI, LookupBFI);
}
PreservedAnalyses PGOInstrumentationGen::run(Module &M,
@@ -1429,11 +1418,7 @@ PreservedAnalyses PGOInstrumentationGen::run(Module &M,
return &FAM.getResult<BlockFrequencyAnalysis>(F);
};
- auto LookupLI = [&FAM](Function &F) {
- return &FAM.getResult<LoopAnalysis>(F);
- };
-
- if (!InstrumentAllFunctions(M, LookupBPI, LookupBFI, LookupLI))
+ if (!InstrumentAllFunctions(M, LookupBPI, LookupBFI))
return PreservedAnalyses::all();
return PreservedAnalyses::none();
@@ -1442,8 +1427,7 @@ PreservedAnalyses PGOInstrumentationGen::run(Module &M,
static bool annotateAllFunctions(
Module &M, StringRef ProfileFileName,
function_ref<BranchProbabilityInfo *(Function &)> LookupBPI,
- function_ref<BlockFrequencyInfo *(Function &)> LookupBFI,
- function_ref<LoopInfo *(Function &)> LookupLI) {
+ function_ref<BlockFrequencyInfo *(Function &)> LookupBFI) {
DEBUG(dbgs() << "Read in profile counters: ");
auto &Ctx = M.getContext();
// Read the counter array from file.
@@ -1479,8 +1463,7 @@ static bool annotateAllFunctions(
continue;
auto *BPI = LookupBPI(F);
auto *BFI = LookupBFI(F);
- auto *LI = LookupLI(F);
- PGOUseFunc Func(F, &M, ComdatMembers, BPI, BFI, LI);
+ PGOUseFunc Func(F, &M, ComdatMembers, BPI, BFI);
if (!Func.readCounters(PGOReader.get()))
continue;
Func.populateCounters();
@@ -1556,11 +1539,7 @@ PreservedAnalyses PGOInstrumentationUse::run(Module &M,
return &FAM.getResult<BlockFrequencyAnalysis>(F);
};
- auto LookupLI = [&FAM](Function &F) {
- return &FAM.getResult<LoopAnalysis>(F);
- };
-
- if (!annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI, LookupLI))
+ if (!annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI))
return PreservedAnalyses::all();
return PreservedAnalyses::none();
@@ -1576,11 +1555,8 @@ bool PGOInstrumentationUseLegacyPass::runOnModule(Module &M) {
auto LookupBFI = [this](Function &F) {
return &this->getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI();
};
- auto LookupLI = [this](Function &F) {
- return &this->getAnalysis<LoopInfoWrapperPass>(F).getLoopInfo();
- };
- return annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI, LookupLI);
+ return annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI);
}
static std::string getSimpleNodeName(const BasicBlock *Node) {
OpenPOWER on IntegriCloud