mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
[TI removal] Remove TerminatorInst
from BasicBlockUtils.h
This requires updating a number of .cpp files to adapt to the new API. I've just systematically updated all uses of `TerminatorInst` within these files te `Instruction` so thta I won't have to touch them again in the future. llvm-svn: 344498
This commit is contained in:
parent
30c1b2684f
commit
84522b83d5
@ -148,7 +148,7 @@ inline bool SplitCriticalEdge(BasicBlock *Succ, pred_iterator PI,
|
||||
const CriticalEdgeSplittingOptions &Options =
|
||||
CriticalEdgeSplittingOptions()) {
|
||||
bool MadeChange = false;
|
||||
TerminatorInst *TI = (*PI)->getTerminator();
|
||||
Instruction *TI = (*PI)->getTerminator();
|
||||
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
|
||||
if (TI->getSuccessor(i) == Succ)
|
||||
MadeChange |= !!SplitCriticalEdge(TI, i, Options);
|
||||
@ -162,7 +162,7 @@ inline BasicBlock *
|
||||
SplitCriticalEdge(BasicBlock *Src, BasicBlock *Dst,
|
||||
const CriticalEdgeSplittingOptions &Options =
|
||||
CriticalEdgeSplittingOptions()) {
|
||||
TerminatorInst *TI = Src->getTerminator();
|
||||
Instruction *TI = Src->getTerminator();
|
||||
unsigned i = 0;
|
||||
while (true) {
|
||||
assert(i != TI->getNumSuccessors() && "Edge doesn't exist!");
|
||||
@ -257,11 +257,11 @@ ReturnInst *FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
|
||||
/// Returns the NewBasicBlock's terminator.
|
||||
///
|
||||
/// Updates DT and LI if given.
|
||||
TerminatorInst *SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore,
|
||||
bool Unreachable,
|
||||
MDNode *BranchWeights = nullptr,
|
||||
DominatorTree *DT = nullptr,
|
||||
LoopInfo *LI = nullptr);
|
||||
Instruction *SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore,
|
||||
bool Unreachable,
|
||||
MDNode *BranchWeights = nullptr,
|
||||
DominatorTree *DT = nullptr,
|
||||
LoopInfo *LI = nullptr);
|
||||
|
||||
/// SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen,
|
||||
/// but also creates the ElseBlock.
|
||||
@ -278,8 +278,8 @@ TerminatorInst *SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore,
|
||||
/// SplitBefore
|
||||
/// Tail
|
||||
void SplitBlockAndInsertIfThenElse(Value *Cond, Instruction *SplitBefore,
|
||||
TerminatorInst **ThenTerm,
|
||||
TerminatorInst **ElseTerm,
|
||||
Instruction **ThenTerm,
|
||||
Instruction **ElseTerm,
|
||||
MDNode *BranchWeights = nullptr);
|
||||
|
||||
/// Check whether BB is the merge point of a if-region.
|
||||
|
@ -1443,7 +1443,7 @@ static void instrumentMaskedLoadOrStore(AddressSanitizer *Pass,
|
||||
} else {
|
||||
IRBuilder<> IRB(I);
|
||||
Value *MaskElem = IRB.CreateExtractElement(Mask, Idx);
|
||||
TerminatorInst *ThenTerm = SplitBlockAndInsertIfThen(MaskElem, I, false);
|
||||
Instruction *ThenTerm = SplitBlockAndInsertIfThen(MaskElem, I, false);
|
||||
InsertBefore = ThenTerm;
|
||||
}
|
||||
|
||||
@ -1596,8 +1596,9 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns,
|
||||
Value *TagCheck =
|
||||
IRB.CreateICmpEQ(Tag, ConstantInt::get(IntptrTy, kMyriadDDRTag));
|
||||
|
||||
TerminatorInst *TagCheckTerm = SplitBlockAndInsertIfThen(
|
||||
TagCheck, InsertBefore, false, MDBuilder(*C).createBranchWeights(1, 100000));
|
||||
Instruction *TagCheckTerm =
|
||||
SplitBlockAndInsertIfThen(TagCheck, InsertBefore, false,
|
||||
MDBuilder(*C).createBranchWeights(1, 100000));
|
||||
assert(cast<BranchInst>(TagCheckTerm)->isUnconditional());
|
||||
IRB.SetInsertPoint(TagCheckTerm);
|
||||
InsertBefore = TagCheckTerm;
|
||||
@ -1613,12 +1614,12 @@ void AddressSanitizer::instrumentAddress(Instruction *OrigIns,
|
||||
|
||||
Value *Cmp = IRB.CreateICmpNE(ShadowValue, CmpVal);
|
||||
size_t Granularity = 1ULL << Mapping.Scale;
|
||||
TerminatorInst *CrashTerm = nullptr;
|
||||
Instruction *CrashTerm = nullptr;
|
||||
|
||||
if (ClAlwaysSlowPath || (TypeSize < 8 * Granularity)) {
|
||||
// We use branch weights for the slow path check, to indicate that the slow
|
||||
// path is rarely taken. This seems to be the case for SPEC benchmarks.
|
||||
TerminatorInst *CheckTerm = SplitBlockAndInsertIfThen(
|
||||
Instruction *CheckTerm = SplitBlockAndInsertIfThen(
|
||||
Cmp, InsertBefore, false, MDBuilder(*C).createBranchWeights(1, 100000));
|
||||
assert(cast<BranchInst>(CheckTerm)->isUnconditional());
|
||||
BasicBlock *NextBB = CheckTerm->getSuccessor(0);
|
||||
@ -3116,7 +3117,7 @@ void FunctionStackPoisoner::processStaticAllocas() {
|
||||
// <This is not a fake stack; unpoison the redzones>
|
||||
Value *Cmp =
|
||||
IRBRet.CreateICmpNE(FakeStack, Constant::getNullValue(IntptrTy));
|
||||
TerminatorInst *ThenTerm, *ElseTerm;
|
||||
Instruction *ThenTerm, *ElseTerm;
|
||||
SplitBlockAndInsertIfThenElse(Cmp, Ret, &ThenTerm, &ElseTerm);
|
||||
|
||||
IRBuilder<> IRBPoison(ThenTerm);
|
||||
|
@ -887,7 +887,7 @@ bool EfficiencySanitizer::instrumentFastpathWorkingSet(
|
||||
Value *OldValue = IRB.CreateLoad(IRB.CreateIntToPtr(ShadowPtr, ShadowPtrTy));
|
||||
// The AND and CMP will be turned into a TEST instruction by the compiler.
|
||||
Value *Cmp = IRB.CreateICmpNE(IRB.CreateAnd(OldValue, ValueMask), ValueMask);
|
||||
TerminatorInst *CmpTerm = SplitBlockAndInsertIfThen(Cmp, I, false);
|
||||
Instruction *CmpTerm = SplitBlockAndInsertIfThen(Cmp, I, false);
|
||||
// FIXME: do I need to call SetCurrentDebugLocation?
|
||||
IRB.SetInsertPoint(CmpTerm);
|
||||
// We use OR to set the shadow bits to avoid corrupting the middle 6 bits,
|
||||
|
@ -467,7 +467,7 @@ void HWAddressSanitizer::instrumentMemAccessInline(Value *PtrLong, bool IsWrite,
|
||||
TagMismatch = IRB.CreateAnd(TagMismatch, TagNotIgnored);
|
||||
}
|
||||
|
||||
TerminatorInst *CheckTerm =
|
||||
Instruction *CheckTerm =
|
||||
SplitBlockAndInsertIfThen(TagMismatch, InsertBefore, !Recover,
|
||||
MDBuilder(*C).createBranchWeights(1, 100000));
|
||||
|
||||
|
@ -947,7 +947,7 @@ bool JumpThreadingPass::ComputeValueKnownInPredecessors(
|
||||
/// Since we can pick an arbitrary destination, we pick the successor with the
|
||||
/// fewest predecessors. This should reduce the in-degree of the others.
|
||||
static unsigned GetBestDestForJumpOnUndef(BasicBlock *BB) {
|
||||
TerminatorInst *BBTerm = BB->getTerminator();
|
||||
Instruction *BBTerm = BB->getTerminator();
|
||||
unsigned MinSucc = 0;
|
||||
BasicBlock *TestBB = BBTerm->getSuccessor(MinSucc);
|
||||
// Compute the successor with the minimum number of predecessors.
|
||||
@ -988,7 +988,7 @@ bool JumpThreadingPass::ProcessBlock(BasicBlock *BB) {
|
||||
// because now the condition in this block can be threaded through
|
||||
// predecessors of our predecessor block.
|
||||
if (BasicBlock *SinglePred = BB->getSinglePredecessor()) {
|
||||
const TerminatorInst *TI = SinglePred->getTerminator();
|
||||
const Instruction *TI = SinglePred->getTerminator();
|
||||
if (!TI->isExceptionalTerminator() && TI->getNumSuccessors() == 1 &&
|
||||
SinglePred != BB && !hasAddressTakenAndUsed(BB)) {
|
||||
// If SinglePred was a loop header, BB becomes one.
|
||||
@ -1080,7 +1080,7 @@ bool JumpThreadingPass::ProcessBlock(BasicBlock *BB) {
|
||||
std::vector<DominatorTree::UpdateType> Updates;
|
||||
|
||||
// Fold the branch/switch.
|
||||
TerminatorInst *BBTerm = BB->getTerminator();
|
||||
Instruction *BBTerm = BB->getTerminator();
|
||||
Updates.reserve(BBTerm->getNumSuccessors());
|
||||
for (unsigned i = 0, e = BBTerm->getNumSuccessors(); i != e; ++i) {
|
||||
if (i == BestSucc) continue;
|
||||
@ -1549,7 +1549,7 @@ FindMostPopularDest(BasicBlock *BB,
|
||||
// successor list.
|
||||
if (!SamePopularity.empty()) {
|
||||
SamePopularity.push_back(MostPopularDest);
|
||||
TerminatorInst *TI = BB->getTerminator();
|
||||
Instruction *TI = BB->getTerminator();
|
||||
for (unsigned i = 0; ; ++i) {
|
||||
assert(i != TI->getNumSuccessors() && "Didn't find any successor!");
|
||||
|
||||
@ -1669,7 +1669,7 @@ bool JumpThreadingPass::ProcessThreadableEdges(Value *Cond, BasicBlock *BB,
|
||||
}
|
||||
|
||||
// Finally update the terminator.
|
||||
TerminatorInst *Term = BB->getTerminator();
|
||||
Instruction *Term = BB->getTerminator();
|
||||
BranchInst::Create(OnlyDest, Term);
|
||||
Term->eraseFromParent();
|
||||
DTU->applyUpdates(Updates);
|
||||
@ -2006,7 +2006,7 @@ bool JumpThreadingPass::ThreadEdge(BasicBlock *BB,
|
||||
// Update the terminator of PredBB to jump to NewBB instead of BB. This
|
||||
// eliminates predecessors from BB, which requires us to simplify any PHI
|
||||
// nodes in BB.
|
||||
TerminatorInst *PredTerm = PredBB->getTerminator();
|
||||
Instruction *PredTerm = PredBB->getTerminator();
|
||||
for (unsigned i = 0, e = PredTerm->getNumSuccessors(); i != e; ++i)
|
||||
if (PredTerm->getSuccessor(i) == BB) {
|
||||
BB->removePredecessor(PredBB, true);
|
||||
@ -2115,7 +2115,7 @@ BasicBlock *JumpThreadingPass::SplitBlockPreds(BasicBlock *BB,
|
||||
}
|
||||
|
||||
bool JumpThreadingPass::doesBlockHaveProfileData(BasicBlock *BB) {
|
||||
const TerminatorInst *TI = BB->getTerminator();
|
||||
const Instruction *TI = BB->getTerminator();
|
||||
assert(TI->getNumSuccessors() > 1 && "not a split");
|
||||
|
||||
MDNode *WeightsNode = TI->getMetadata(LLVMContext::MD_prof);
|
||||
@ -2538,7 +2538,7 @@ bool JumpThreadingPass::TryToUnfoldSelectInCurrBB(BasicBlock *BB) {
|
||||
if (!SI)
|
||||
continue;
|
||||
// Expand the select.
|
||||
TerminatorInst *Term =
|
||||
Instruction *Term =
|
||||
SplitBlockAndInsertIfThen(SI->getCondition(), SI, false);
|
||||
BasicBlock *SplitBB = SI->getParent();
|
||||
BasicBlock *NewBB = Term->getParent();
|
||||
|
@ -52,7 +52,7 @@ void llvm::DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU) {
|
||||
assert((pred_begin(BB) == pred_end(BB) ||
|
||||
// Can delete self loop.
|
||||
BB->getSinglePredecessor() == BB) && "Block is not dead!");
|
||||
TerminatorInst *BBTerm = BB->getTerminator();
|
||||
Instruction *BBTerm = BB->getTerminator();
|
||||
std::vector<DominatorTree::UpdateType> Updates;
|
||||
|
||||
// Loop through all of our successors and make sure they know that one
|
||||
@ -270,7 +270,7 @@ BasicBlock *llvm::SplitEdge(BasicBlock *BB, BasicBlock *Succ, DominatorTree *DT,
|
||||
unsigned SuccNum = GetSuccessorNumber(BB, Succ);
|
||||
|
||||
// If this is a critical edge, let SplitCriticalEdge do it.
|
||||
TerminatorInst *LatchTerm = BB->getTerminator();
|
||||
Instruction *LatchTerm = BB->getTerminator();
|
||||
if (SplitCriticalEdge(
|
||||
LatchTerm, SuccNum,
|
||||
CriticalEdgeSplittingOptions(DT, LI, MSSAU).setPreserveLCSSA()))
|
||||
@ -298,7 +298,7 @@ llvm::SplitAllCriticalEdges(Function &F,
|
||||
const CriticalEdgeSplittingOptions &Options) {
|
||||
unsigned NumBroken = 0;
|
||||
for (BasicBlock &BB : F) {
|
||||
TerminatorInst *TI = BB.getTerminator();
|
||||
Instruction *TI = BB.getTerminator();
|
||||
if (TI->getNumSuccessors() > 1 && !isa<IndirectBrInst>(TI))
|
||||
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
|
||||
if (SplitCriticalEdge(TI, i, Options))
|
||||
@ -705,16 +705,17 @@ ReturnInst *llvm::FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
|
||||
return cast<ReturnInst>(NewRet);
|
||||
}
|
||||
|
||||
TerminatorInst *
|
||||
llvm::SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore,
|
||||
bool Unreachable, MDNode *BranchWeights,
|
||||
DominatorTree *DT, LoopInfo *LI) {
|
||||
Instruction *llvm::SplitBlockAndInsertIfThen(Value *Cond,
|
||||
Instruction *SplitBefore,
|
||||
bool Unreachable,
|
||||
MDNode *BranchWeights,
|
||||
DominatorTree *DT, LoopInfo *LI) {
|
||||
BasicBlock *Head = SplitBefore->getParent();
|
||||
BasicBlock *Tail = Head->splitBasicBlock(SplitBefore->getIterator());
|
||||
TerminatorInst *HeadOldTerm = Head->getTerminator();
|
||||
Instruction *HeadOldTerm = Head->getTerminator();
|
||||
LLVMContext &C = Head->getContext();
|
||||
BasicBlock *ThenBlock = BasicBlock::Create(C, "", Head->getParent(), Tail);
|
||||
TerminatorInst *CheckTerm;
|
||||
Instruction *CheckTerm;
|
||||
if (Unreachable)
|
||||
CheckTerm = new UnreachableInst(C, ThenBlock);
|
||||
else
|
||||
@ -749,12 +750,12 @@ llvm::SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore,
|
||||
}
|
||||
|
||||
void llvm::SplitBlockAndInsertIfThenElse(Value *Cond, Instruction *SplitBefore,
|
||||
TerminatorInst **ThenTerm,
|
||||
TerminatorInst **ElseTerm,
|
||||
Instruction **ThenTerm,
|
||||
Instruction **ElseTerm,
|
||||
MDNode *BranchWeights) {
|
||||
BasicBlock *Head = SplitBefore->getParent();
|
||||
BasicBlock *Tail = Head->splitBasicBlock(SplitBefore->getIterator());
|
||||
TerminatorInst *HeadOldTerm = Head->getTerminator();
|
||||
Instruction *HeadOldTerm = Head->getTerminator();
|
||||
LLVMContext &C = Head->getContext();
|
||||
BasicBlock *ThenBlock = BasicBlock::Create(C, "", Head->getParent(), Tail);
|
||||
BasicBlock *ElseBlock = BasicBlock::Create(C, "", Head->getParent(), Tail);
|
||||
|
@ -270,8 +270,8 @@ static Instruction *versionCallSite(CallSite CS, Value *Callee,
|
||||
// Create an if-then-else structure. The original instruction is moved into
|
||||
// the "else" block, and a clone of the original instruction is placed in the
|
||||
// "then" block.
|
||||
TerminatorInst *ThenTerm = nullptr;
|
||||
TerminatorInst *ElseTerm = nullptr;
|
||||
Instruction *ThenTerm = nullptr;
|
||||
Instruction *ElseTerm = nullptr;
|
||||
SplitBlockAndInsertIfThenElse(Cond, CS.getInstruction(), &ThenTerm, &ElseTerm,
|
||||
BranchWeights);
|
||||
BasicBlock *ThenBlock = ThenTerm->getParent();
|
||||
|
@ -487,7 +487,7 @@ void LibCallsShrinkWrap::shrinkWrapCI(CallInst *CI, Value *Cond) {
|
||||
MDNode *BranchWeights =
|
||||
MDBuilder(CI->getContext()).createBranchWeights(1, 2000);
|
||||
|
||||
TerminatorInst *NewInst =
|
||||
Instruction *NewInst =
|
||||
SplitBlockAndInsertIfThen(Cond, CI, false, BranchWeights, DT);
|
||||
BasicBlock *CallBB = NewInst->getParent();
|
||||
CallBB->setName("cdce.call");
|
||||
|
@ -301,7 +301,7 @@ static void createMemMoveLoop(Instruction *InsertBefore,
|
||||
// the appropriate conditional branches when the loop is built.
|
||||
ICmpInst *PtrCompare = new ICmpInst(InsertBefore, ICmpInst::ICMP_ULT,
|
||||
SrcAddr, DstAddr, "compare_src_dst");
|
||||
TerminatorInst *ThenTerm, *ElseTerm;
|
||||
Instruction *ThenTerm, *ElseTerm;
|
||||
SplitBlockAndInsertIfThenElse(PtrCompare, InsertBefore, &ThenTerm,
|
||||
&ElseTerm);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user