summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2017-12-08 19:38:07 +0000
committerXinliang David Li <davidxl@google.com>2017-12-08 19:38:07 +0000
commit45f64ad571f683fcc8cbebc1cbad30182ed0cd87 (patch)
tree8f0d27d18a83dfd9c0d4d084146c6439d72332b4
parent0f18499689b498723e476e9b1eab7854050111a7 (diff)
Revert r320104: infinite loop profiling bug fix
Causes unexpected memory issue with New PM this time. The new PM invalidates BPI but not BFI, leaving the reference to BPI from BFI invalid. Abandon this patch. There is a more general solution which also handles runtime infinite loop (but not statically). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320180 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Analysis/BlockFrequencyInfo.h1
-rw-r--r--include/llvm/Analysis/BlockFrequencyInfoImpl.h1
-rw-r--r--lib/Analysis/BlockFrequencyInfo.cpp4
-rw-r--r--lib/Transforms/Instrumentation/CFGMST.h24
-rw-r--r--lib/Transforms/Instrumentation/PGOInstrumentation.cpp46
-rw-r--r--test/Transforms/PGOProfile/infinite_loop_gen.ll18
6 files changed, 38 insertions, 56 deletions
diff --git a/include/llvm/Analysis/BlockFrequencyInfo.h b/include/llvm/Analysis/BlockFrequencyInfo.h
index 86ae00825a7..89370cbeeea 100644
--- a/include/llvm/Analysis/BlockFrequencyInfo.h
+++ b/include/llvm/Analysis/BlockFrequencyInfo.h
@@ -56,7 +56,6 @@ public:
const Function *getFunction() const;
const BranchProbabilityInfo *getBPI() const;
- const LoopInfo *getLoopInfo() const;
void view() const;
/// getblockFreq - Return block frequency. Return 0 if we don't have the
diff --git a/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/include/llvm/Analysis/BlockFrequencyInfoImpl.h
index 1ec0510c928..228934cb301 100644
--- a/include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ b/include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -993,7 +993,6 @@ public:
}
const BranchProbabilityInfoT &getBPI() const { return *BPI; }
- const LoopInfoT &getLoopInfo() const { return *LI; }
/// \brief Print the frequencies for the current function.
///
diff --git a/lib/Analysis/BlockFrequencyInfo.cpp b/lib/Analysis/BlockFrequencyInfo.cpp
index f5fe2d84f8b..41c29589521 100644
--- a/lib/Analysis/BlockFrequencyInfo.cpp
+++ b/lib/Analysis/BlockFrequencyInfo.cpp
@@ -264,10 +264,6 @@ const BranchProbabilityInfo *BlockFrequencyInfo::getBPI() const {
return BFI ? &BFI->getBPI() : nullptr;
}
-const LoopInfo *BlockFrequencyInfo::getLoopInfo() const {
- return BFI ? &BFI->getLoopInfo() : nullptr;
-}
-
raw_ostream &BlockFrequencyInfo::
printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const {
return BFI ? BFI->printBlockFreq(OS, Freq) : OS;
diff --git a/lib/Transforms/Instrumentation/CFGMST.h b/lib/Transforms/Instrumentation/CFGMST.h
index 2cfa5ccb0a3..16e2e6b4e73 100644
--- a/lib/Transforms/Instrumentation/CFGMST.h
+++ b/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.
@@ -226,13 +210,13 @@ public:
return *AllEdges.back();
}
- const BranchProbabilityInfo *BPI;
+ BranchProbabilityInfo *BPI;
BlockFrequencyInfo *BFI;
- const LoopInfo *LI;
public:
- CFGMST(Function &Func, BlockFrequencyInfo *BFI_ = nullptr)
- : F(Func), BPI(BFI_->getBPI()), BFI(BFI_), LI(BFI_->getLoopInfo()) {
+ CFGMST(Function &Func, BranchProbabilityInfo *BPI_ = nullptr,
+ BlockFrequencyInfo *BFI_ = nullptr)
+ : F(Func), BPI(BPI_), BFI(BFI_) {
buildEdges();
sortEdgesByWeight();
computeMinimumSpanningTree();
diff --git a/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index 86080295122..47278e19283 100644
--- a/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -425,6 +425,7 @@ char PGOInstrumentationGenLegacyPass::ID = 0;
INITIALIZE_PASS_BEGIN(PGOInstrumentationGenLegacyPass, "pgo-instr-gen",
"PGO instrumentation.", false, false)
INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass)
INITIALIZE_PASS_END(PGOInstrumentationGenLegacyPass, "pgo-instr-gen",
"PGO instrumentation.", false, false)
@@ -437,6 +438,7 @@ char PGOInstrumentationUseLegacyPass::ID = 0;
INITIALIZE_PASS_BEGIN(PGOInstrumentationUseLegacyPass, "pgo-instr-use",
"Read PGO instrumentation profile.", false, false)
INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass)
INITIALIZE_PASS_END(PGOInstrumentationUseLegacyPass, "pgo-instr-use",
"Read PGO instrumentation profile.", false, false)
@@ -527,9 +529,10 @@ public:
FuncPGOInstrumentation(
Function &Func,
std::unordered_multimap<Comdat *, GlobalValue *> &ComdatMembers,
- bool CreateGlobalVar = false, BlockFrequencyInfo *BFI = nullptr)
+ bool CreateGlobalVar = false, BranchProbabilityInfo *BPI = nullptr,
+ BlockFrequencyInfo *BFI = nullptr)
: F(Func), ComdatMembers(ComdatMembers), ValueSites(IPVK_Last + 1),
- SIVisitor(Func), MIVisitor(Func), MST(F, BFI) {
+ SIVisitor(Func), MIVisitor(Func), MST(F, BPI, BFI) {
// This should be done before CFG hash computation.
SIVisitor.countSelects(Func);
MIVisitor.countMemIntrinsics(Func);
@@ -711,9 +714,10 @@ BasicBlock *FuncPGOInstrumentation<Edge, BBInfo>::getInstrBB(Edge *E) {
// Visit all edge and instrument the edges not in MST, and do value profiling.
// Critical edges will be split.
static void instrumentOneFunc(
- Function &F, Module *M, BlockFrequencyInfo *BFI,
+ Function &F, Module *M, BranchProbabilityInfo *BPI, BlockFrequencyInfo *BFI,
std::unordered_multimap<Comdat *, GlobalValue *> &ComdatMembers) {
- FuncPGOInstrumentation<PGOEdge, BBInfo> FuncInfo(F, ComdatMembers, true, BFI);
+ FuncPGOInstrumentation<PGOEdge, BBInfo> FuncInfo(F, ComdatMembers, true, BPI,
+ BFI);
unsigned NumCounters = FuncInfo.getNumCounters();
uint32_t I = 0;
@@ -839,9 +843,11 @@ class PGOUseFunc {
public:
PGOUseFunc(Function &Func, Module *Modu,
std::unordered_multimap<Comdat *, GlobalValue *> &ComdatMembers,
+ BranchProbabilityInfo *BPI = nullptr,
BlockFrequencyInfo *BFIin = nullptr)
: F(Func), M(Modu), BFI(BFIin),
- FuncInfo(Func, ComdatMembers, false, BFIin), FreqAttr(FFA_Normal) {}
+ FuncInfo(Func, ComdatMembers, false, BPI, BFIin),
+ FreqAttr(FFA_Normal) {}
// Read counts for the instrumented BB from profile.
bool readCounters(IndexedInstrProfReader *PGOReader);
@@ -1372,7 +1378,8 @@ static void collectComdatMembers(
}
static bool InstrumentAllFunctions(
- Module &M, function_ref<BlockFrequencyInfo *(Function &)> LookupBFI) {
+ Module &M, function_ref<BranchProbabilityInfo *(Function &)> LookupBPI,
+ function_ref<BlockFrequencyInfo *(Function &)> LookupBFI) {
createIRLevelProfileFlagVariable(M);
std::unordered_multimap<Comdat *, GlobalValue *> ComdatMembers;
collectComdatMembers(M, ComdatMembers);
@@ -1380,8 +1387,9 @@ static bool InstrumentAllFunctions(
for (auto &F : M) {
if (F.isDeclaration())
continue;
+ auto *BPI = LookupBPI(F);
auto *BFI = LookupBFI(F);
- instrumentOneFunc(F, &M, BFI, ComdatMembers);
+ instrumentOneFunc(F, &M, BPI, BFI, ComdatMembers);
}
return true;
}
@@ -1390,21 +1398,27 @@ bool PGOInstrumentationGenLegacyPass::runOnModule(Module &M) {
if (skipModule(M))
return false;
+ auto LookupBPI = [this](Function &F) {
+ return &this->getAnalysis<BranchProbabilityInfoWrapperPass>(F).getBPI();
+ };
auto LookupBFI = [this](Function &F) {
return &this->getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI();
};
- return InstrumentAllFunctions(M, LookupBFI);
+ return InstrumentAllFunctions(M, LookupBPI, LookupBFI);
}
PreservedAnalyses PGOInstrumentationGen::run(Module &M,
ModuleAnalysisManager &AM) {
auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
+ auto LookupBPI = [&FAM](Function &F) {
+ return &FAM.getResult<BranchProbabilityAnalysis>(F);
+ };
auto LookupBFI = [&FAM](Function &F) {
return &FAM.getResult<BlockFrequencyAnalysis>(F);
};
- if (!InstrumentAllFunctions(M, LookupBFI))
+ if (!InstrumentAllFunctions(M, LookupBPI, LookupBFI))
return PreservedAnalyses::all();
return PreservedAnalyses::none();
@@ -1412,6 +1426,7 @@ PreservedAnalyses PGOInstrumentationGen::run(Module &M,
static bool annotateAllFunctions(
Module &M, StringRef ProfileFileName,
+ function_ref<BranchProbabilityInfo *(Function &)> LookupBPI,
function_ref<BlockFrequencyInfo *(Function &)> LookupBFI) {
DEBUG(dbgs() << "Read in profile counters: ");
auto &Ctx = M.getContext();
@@ -1446,8 +1461,9 @@ static bool annotateAllFunctions(
for (auto &F : M) {
if (F.isDeclaration())
continue;
+ auto *BPI = LookupBPI(F);
auto *BFI = LookupBFI(F);
- PGOUseFunc Func(F, &M, ComdatMembers, BFI);
+ PGOUseFunc Func(F, &M, ComdatMembers, BPI, BFI);
if (!Func.readCounters(PGOReader.get()))
continue;
Func.populateCounters();
@@ -1515,12 +1531,15 @@ PreservedAnalyses PGOInstrumentationUse::run(Module &M,
ModuleAnalysisManager &AM) {
auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
+ auto LookupBPI = [&FAM](Function &F) {
+ return &FAM.getResult<BranchProbabilityAnalysis>(F);
+ };
auto LookupBFI = [&FAM](Function &F) {
return &FAM.getResult<BlockFrequencyAnalysis>(F);
};
- if (!annotateAllFunctions(M, ProfileFileName, LookupBFI))
+ if (!annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI))
return PreservedAnalyses::all();
return PreservedAnalyses::none();
@@ -1530,11 +1549,14 @@ bool PGOInstrumentationUseLegacyPass::runOnModule(Module &M) {
if (skipModule(M))
return false;
+ auto LookupBPI = [this](Function &F) {
+ return &this->getAnalysis<BranchProbabilityInfoWrapperPass>(F).getBPI();
+ };
auto LookupBFI = [this](Function &F) {
return &this->getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI();
};
- return annotateAllFunctions(M, ProfileFileName, LookupBFI);
+ return annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI);
}
static std::string getSimpleNodeName(const BasicBlock *Node) {
diff --git a/test/Transforms/PGOProfile/infinite_loop_gen.ll b/test/Transforms/PGOProfile/infinite_loop_gen.ll
deleted file mode 100644
index f200fc3857a..00000000000
--- a/test/Transforms/PGOProfile/infinite_loop_gen.ll
+++ /dev/null
@@ -1,18 +0,0 @@
-; RUN: opt < %s -pgo-instr-gen -S -o - | FileCheck %s
-
-define void @foo() {
-entry:
- br label %while.body
-; CHECK: llvm.instrprof.increment
-
- while.body: ; preds = %entry, %while.body
-; CHECK: llvm.instrprof.increment
- call void (...) @bar() #2
- br label %while.body
-}
-
-declare void @bar(...)
-
-
-attributes #0 = { nounwind }
-