Skip to content

Commit 87f0d0e

Browse files
committed
Revert r272891 "[JumpThreading] Prevent dangling pointer problems in BranchProbabilityInfo"
It was causing failures in Profile-i386 and Profile-x86_64 tests. llvm-svn: 272912
1 parent 0166a71 commit 87f0d0e

File tree

8 files changed

+7
-64
lines changed

8 files changed

+7
-64
lines changed

llvm/include/llvm/Analysis/BranchProbabilityInfo.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/ADT/SmallPtrSet.h"
1919
#include "llvm/IR/CFG.h"
2020
#include "llvm/IR/PassManager.h"
21-
#include "llvm/IR/ValueHandle.h"
2221
#include "llvm/InitializePasses.h"
2322
#include "llvm/Pass.h"
2423
#include "llvm/Support/BranchProbability.h"
@@ -117,16 +116,13 @@ class BranchProbabilityInfo {
117116

118117
void calculate(const Function &F, const LoopInfo &LI);
119118

120-
/// Forget analysis results for the given basic block.
121-
void eraseBlock(const BasicBlock *BB);
122-
123119
private:
124120
void operator=(const BranchProbabilityInfo &) = delete;
125121
BranchProbabilityInfo(const BranchProbabilityInfo &) = delete;
126122

127123
// Since we allow duplicate edges from one basic block to another, we use
128124
// a pair (PredBlock and an index in the successors) to specify an edge.
129-
typedef std::pair<AssertingVH<const BasicBlock>, unsigned> Edge;
125+
typedef std::pair<const BasicBlock *, unsigned> Edge;
130126

131127
// Default weight value. Used when we don't have information about the edge.
132128
// TODO: DEFAULT_WEIGHT makes sense during static predication, when none of

llvm/include/llvm/Transforms/Scalar/JumpThreading.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
134134
const char *Suffix);
135135
void UpdateBlockFreqAndEdgeWeight(BasicBlock *PredBB, BasicBlock *BB,
136136
BasicBlock *NewBB, BasicBlock *SuccBB);
137-
138-
void dropBlockAnalysisResults(BasicBlock *BB);
139137
};
140138

141139
} // end namespace llvm

llvm/include/llvm/Transforms/Utils/Local.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class TargetTransformInfo;
4444
class DIBuilder;
4545
class DominatorTree;
4646
class LazyValueInfo;
47-
class BranchProbabilityInfo;
4847

4948
template<typename T> class SmallVectorImpl;
5049

@@ -301,11 +300,7 @@ void removeUnwindEdge(BasicBlock *BB);
301300
/// Remove all blocks that can not be reached from the function's entry.
302301
///
303302
/// Returns true if any basic block was removed.
304-
/// \param F Target function
305-
/// \param LVI Will update this analysis if non null
306-
/// \param BPI Will update this analysis if non null
307-
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI = nullptr,
308-
BranchProbabilityInfo *BPI = nullptr);
303+
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI = nullptr);
309304

310305
/// Combine the metadata of two instructions so that K can replace J
311306
///

llvm/lib/Analysis/BranchProbabilityInfo.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -639,14 +639,6 @@ BranchProbabilityInfo::printEdgeProbability(raw_ostream &OS,
639639
return OS;
640640
}
641641

642-
void BranchProbabilityInfo::eraseBlock(const BasicBlock *BB) {
643-
for (auto I = Probs.begin(), E = Probs.end(); I != E; ++I) {
644-
auto Key = I->first;
645-
if (Key.first == BB)
646-
Probs.erase(Key);
647-
}
648-
}
649-
650642
void BranchProbabilityInfo::calculate(const Function &F, const LoopInfo &LI) {
651643
DEBUG(dbgs() << "---- Branch Probability Info : " << F.getName()
652644
<< " ----\n\n");

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ bool JumpThreadingPass::runImpl(Function &F, TargetLibraryInfo *TLI_,
182182
// back edges. This works for normal cases but not for unreachable blocks as
183183
// they may have cycle with no back edge.
184184
bool EverChanged = false;
185-
EverChanged |= removeUnreachableBlocks(F, LVI, BPI.get());
185+
EverChanged |= removeUnreachableBlocks(F, LVI);
186186

187187
FindLoopHeaders(F);
188188

@@ -204,7 +204,7 @@ bool JumpThreadingPass::runImpl(Function &F, TargetLibraryInfo *TLI_,
204204
DEBUG(dbgs() << " JT: Deleting dead block '" << BB->getName()
205205
<< "' with terminator: " << *BB->getTerminator() << '\n');
206206
LoopHeaders.erase(BB);
207-
dropBlockAnalysisResults(BB);
207+
LVI->eraseBlock(BB);
208208
DeleteDeadBlock(BB);
209209
Changed = true;
210210
continue;
@@ -232,7 +232,7 @@ bool JumpThreadingPass::runImpl(Function &F, TargetLibraryInfo *TLI_,
232232
// for a block even if it doesn't get erased. This isn't totally
233233
// awesome, but it allows us to use AssertingVH to prevent nasty
234234
// dangling pointer issues within LazyValueInfo.
235-
dropBlockAnalysisResults(BB);
235+
LVI->eraseBlock(BB);
236236
if (TryToSimplifyUncondBranchFromEmptyBlock(BB)) {
237237
Changed = true;
238238
// If we deleted BB and BB was the header of a loop, then the
@@ -715,7 +715,7 @@ bool JumpThreadingPass::ProcessBlock(BasicBlock *BB) {
715715
if (LoopHeaders.erase(SinglePred))
716716
LoopHeaders.insert(BB);
717717

718-
dropBlockAnalysisResults(SinglePred);
718+
LVI->eraseBlock(SinglePred);
719719
MergeBasicBlockIntoOnlyPred(BB);
720720

721721
return true;
@@ -1949,11 +1949,3 @@ bool JumpThreadingPass::TryToUnfoldSelectInCurrBB(BasicBlock *BB) {
19491949

19501950
return false;
19511951
}
1952-
1953-
/// dropBlockAnalysisResults - Inform relevant analyzes that BB is going to
1954-
/// be removed. This is important in order to prevent dangling pointer problems.
1955-
void JumpThreadingPass::dropBlockAnalysisResults(BasicBlock *BB) {
1956-
LVI->eraseBlock(BB);
1957-
if (BPI)
1958-
BPI->eraseBlock(BB);
1959-
}

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "llvm/ADT/SetVector.h"
2121
#include "llvm/ADT/SmallPtrSet.h"
2222
#include "llvm/ADT/Statistic.h"
23-
#include "llvm/Analysis/BranchProbabilityInfo.h"
2423
#include "llvm/Analysis/EHPersonalities.h"
2524
#include "llvm/Analysis/InstructionSimplify.h"
2625
#include "llvm/Analysis/MemoryBuiltins.h"
@@ -1487,8 +1486,7 @@ void llvm::removeUnwindEdge(BasicBlock *BB) {
14871486
/// removeUnreachableBlocksFromFn - Remove blocks that are not reachable, even
14881487
/// if they are in a dead cycle. Return true if a change was made, false
14891488
/// otherwise.
1490-
bool llvm::removeUnreachableBlocks(Function &F, LazyValueInfo *LVI,
1491-
BranchProbabilityInfo *BPI) {
1489+
bool llvm::removeUnreachableBlocks(Function &F, LazyValueInfo *LVI) {
14921490
SmallPtrSet<BasicBlock*, 16> Reachable;
14931491
bool Changed = markAliveBlocks(F, Reachable);
14941492

@@ -1511,8 +1509,6 @@ bool llvm::removeUnreachableBlocks(Function &F, LazyValueInfo *LVI,
15111509
(*SI)->removePredecessor(&*BB);
15121510
if (LVI)
15131511
LVI->eraseBlock(&*BB);
1514-
if (BPI)
1515-
BPI->eraseBlock(&*BB);
15161512
BB->dropAllReferences();
15171513
}
15181514

llvm/test/Transforms/JumpThreading/dangling-pointers-in-bpi.ll

Lines changed: 0 additions & 19 deletions
This file was deleted.

llvm/unittests/Analysis/BlockFrequencyInfoTest.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ class BlockFrequencyInfoTest : public testing::Test {
5454
SMDiagnostic Err;
5555
return parseAssemblyString(ModuleStrig, Err, C);
5656
}
57-
58-
void destroyBFI() {
59-
// Prevent AssertingVH from failing.
60-
BPI->releaseMemory();
61-
}
6257
};
6358

6459
TEST_F(BlockFrequencyInfoTest, Basic) {
@@ -85,8 +80,6 @@ TEST_F(BlockFrequencyInfoTest, Basic) {
8580
EXPECT_EQ(BFI.getBlockProfileCount(BB3).getValue(), UINT64_C(100));
8681
EXPECT_EQ(BFI.getBlockProfileCount(BB1).getValue(), 100 * BB1Freq / BB0Freq);
8782
EXPECT_EQ(BFI.getBlockProfileCount(BB2).getValue(), 100 * BB2Freq / BB0Freq);
88-
89-
destroyBFI();
9083
}
9184

9285
} // end anonymous namespace

0 commit comments

Comments
 (0)