mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 21:24:00 +00:00
Refactor to share code to find the position of a basic block successor in the
terminator's list of successors. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96377 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -274,24 +274,30 @@ void llvm::RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum) {
|
||||
ReplaceInstWithInst(TI, NewTI);
|
||||
}
|
||||
|
||||
/// SplitEdge - Split the edge connecting specified block. Pass P must
|
||||
/// not be NULL.
|
||||
BasicBlock *llvm::SplitEdge(BasicBlock *BB, BasicBlock *Succ, Pass *P) {
|
||||
TerminatorInst *LatchTerm = BB->getTerminator();
|
||||
unsigned SuccNum = 0;
|
||||
/// SuccessorNumber - Search for the specified successor of basic block BB and
|
||||
/// return its position in the terminator instruction's list of successors.
|
||||
/// It is an error to call this with a block that is not a successor.
|
||||
unsigned llvm::SuccessorNumber(BasicBlock *BB, BasicBlock *Succ) {
|
||||
TerminatorInst *Term = BB->getTerminator();
|
||||
#ifndef NDEBUG
|
||||
unsigned e = LatchTerm->getNumSuccessors();
|
||||
unsigned e = Term->getNumSuccessors();
|
||||
#endif
|
||||
for (unsigned i = 0; ; ++i) {
|
||||
assert(i != e && "Didn't find edge?");
|
||||
if (LatchTerm->getSuccessor(i) == Succ) {
|
||||
SuccNum = i;
|
||||
break;
|
||||
}
|
||||
if (Term->getSuccessor(i) == Succ)
|
||||
return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// SplitEdge - Split the edge connecting specified block. Pass P must
|
||||
/// not be NULL.
|
||||
BasicBlock *llvm::SplitEdge(BasicBlock *BB, BasicBlock *Succ, Pass *P) {
|
||||
unsigned SuccNum = SuccessorNumber(BB, Succ);
|
||||
|
||||
// If this is a critical edge, let SplitCriticalEdge do it.
|
||||
if (SplitCriticalEdge(BB->getTerminator(), SuccNum, P))
|
||||
TerminatorInst *LatchTerm = BB->getTerminator();
|
||||
if (SplitCriticalEdge(LatchTerm, SuccNum, P))
|
||||
return LatchTerm->getSuccessor(SuccNum);
|
||||
|
||||
// If the edge isn't critical, then BB has a single successor or Succ has a
|
||||
|
Reference in New Issue
Block a user