2003-04-24 00:23:59 +08:00
|
|
|
//===- LowerSwitch.cpp - Eliminate Switch instructions --------------------===//
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-04-24 00:23:59 +08:00
|
|
|
//
|
2007-11-05 00:15:04 +08:00
|
|
|
// The LowerSwitch transformation rewrites switch instructions with a sequence
|
|
|
|
// of branches, which allows targets to get away with not implementing the
|
|
|
|
// switch instruction until it is convenient.
|
2003-04-24 00:23:59 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2015-03-24 03:32:43 +08:00
|
|
|
#include "llvm/IR/CFG.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
2003-04-24 00:23:59 +08:00
|
|
|
#include "llvm/Pass.h"
|
2006-08-27 20:54:02 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2009-10-25 14:57:41 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2008-08-24 06:23:09 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2015-03-24 03:32:43 +08:00
|
|
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
|
2004-09-04 02:19:51 +08:00
|
|
|
#include <algorithm>
|
2004-01-09 14:02:20 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2014-04-22 06:55:11 +08:00
|
|
|
#define DEBUG_TYPE "lower-switch"
|
|
|
|
|
2003-04-24 00:23:59 +08:00
|
|
|
namespace {
|
2015-01-24 04:43:51 +08:00
|
|
|
struct IntRange {
|
|
|
|
int64_t Low, High;
|
|
|
|
};
|
|
|
|
// Return true iff R is covered by Ranges.
|
|
|
|
static bool IsInRanges(const IntRange &R,
|
|
|
|
const std::vector<IntRange> &Ranges) {
|
|
|
|
// Note: Ranges must be sorted, non-overlapping and non-adjacent.
|
|
|
|
|
|
|
|
// Find the first range whose High field is >= R.High,
|
|
|
|
// then check if the Low field is <= R.Low. If so, we
|
|
|
|
// have a Range that covers R.
|
|
|
|
auto I = std::lower_bound(
|
|
|
|
Ranges.begin(), Ranges.end(), R,
|
|
|
|
[](const IntRange &A, const IntRange &B) { return A.High < B.High; });
|
|
|
|
return I != Ranges.end() && I->Low <= R.Low;
|
|
|
|
}
|
|
|
|
|
2015-09-17 00:21:08 +08:00
|
|
|
/// Replace all SwitchInst instructions with chained branch instructions.
|
2009-10-25 14:33:48 +08:00
|
|
|
class LowerSwitch : public FunctionPass {
|
2003-10-08 02:46:23 +08:00
|
|
|
public:
|
2007-05-06 21:37:16 +08:00
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2010-10-20 01:21:58 +08:00
|
|
|
LowerSwitch() : FunctionPass(ID) {
|
|
|
|
initializeLowerSwitchPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2007-05-02 05:15:47 +08:00
|
|
|
|
2014-03-05 17:10:37 +08:00
|
|
|
bool runOnFunction(Function &F) override;
|
|
|
|
|
2007-03-11 00:46:28 +08:00
|
|
|
struct CaseRange {
|
2015-02-06 00:58:10 +08:00
|
|
|
ConstantInt* Low;
|
|
|
|
ConstantInt* High;
|
2007-03-11 00:46:28 +08:00
|
|
|
BasicBlock* BB;
|
|
|
|
|
2015-02-06 00:58:10 +08:00
|
|
|
CaseRange(ConstantInt *low, ConstantInt *high, BasicBlock *bb)
|
2015-02-06 00:50:27 +08:00
|
|
|
: Low(low), High(high), BB(bb) {}
|
2007-03-11 00:46:28 +08:00
|
|
|
};
|
|
|
|
|
2014-06-17 00:55:20 +08:00
|
|
|
typedef std::vector<CaseRange> CaseVector;
|
2007-03-11 00:46:28 +08:00
|
|
|
typedef std::vector<CaseRange>::iterator CaseItr;
|
2003-10-08 02:46:23 +08:00
|
|
|
private:
|
2015-08-12 04:16:17 +08:00
|
|
|
void processSwitchInst(SwitchInst *SI, SmallPtrSetImpl<BasicBlock*> &DeleteList);
|
2003-10-08 02:46:23 +08:00
|
|
|
|
2014-06-17 00:55:20 +08:00
|
|
|
BasicBlock *switchConvert(CaseItr Begin, CaseItr End,
|
|
|
|
ConstantInt *LowerBound, ConstantInt *UpperBound,
|
2014-07-11 18:34:36 +08:00
|
|
|
Value *Val, BasicBlock *Predecessor,
|
2015-01-24 04:43:51 +08:00
|
|
|
BasicBlock *OrigBlock, BasicBlock *Default,
|
|
|
|
const std::vector<IntRange> &UnreachableRanges);
|
2014-06-17 00:55:20 +08:00
|
|
|
BasicBlock *newLeafBlock(CaseRange &Leaf, Value *Val, BasicBlock *OrigBlock,
|
|
|
|
BasicBlock *Default);
|
|
|
|
unsigned Clusterify(CaseVector &Cases, SwitchInst *SI);
|
2003-10-08 02:46:23 +08:00
|
|
|
};
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
llvm-svn: 190328
2013-09-10 03:14:35 +08:00
|
|
|
|
|
|
|
/// The comparison function for sorting the switch case values in the vector.
|
|
|
|
/// WARNING: Case ranges should be disjoint!
|
|
|
|
struct CaseCmp {
|
|
|
|
bool operator () (const LowerSwitch::CaseRange& C1,
|
|
|
|
const LowerSwitch::CaseRange& C2) {
|
|
|
|
|
|
|
|
const ConstantInt* CI1 = cast<const ConstantInt>(C1.Low);
|
|
|
|
const ConstantInt* CI2 = cast<const ConstantInt>(C2.High);
|
|
|
|
return CI1->getValue().slt(CI2->getValue());
|
|
|
|
}
|
|
|
|
};
|
2015-06-23 17:49:53 +08:00
|
|
|
}
|
2003-04-24 00:23:59 +08:00
|
|
|
|
2008-05-13 08:00:25 +08:00
|
|
|
char LowerSwitch::ID = 0;
|
2010-08-24 01:52:01 +08:00
|
|
|
INITIALIZE_PASS(LowerSwitch, "lowerswitch",
|
2010-10-08 06:25:06 +08:00
|
|
|
"Lower SwitchInst's to branches", false, false)
|
2008-05-13 08:00:25 +08:00
|
|
|
|
2011-04-15 13:18:47 +08:00
|
|
|
// Publicly exposed interface to pass...
|
2010-08-07 02:33:48 +08:00
|
|
|
char &llvm::LowerSwitchID = LowerSwitch::ID;
|
2003-04-24 00:23:59 +08:00
|
|
|
// createLowerSwitchPass - Interface to this file...
|
2004-01-09 14:02:20 +08:00
|
|
|
FunctionPass *llvm::createLowerSwitchPass() {
|
2003-04-24 00:23:59 +08:00
|
|
|
return new LowerSwitch();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LowerSwitch::runOnFunction(Function &F) {
|
|
|
|
bool Changed = false;
|
2015-08-12 04:16:17 +08:00
|
|
|
SmallPtrSet<BasicBlock*, 8> DeleteList;
|
2003-04-24 00:23:59 +08:00
|
|
|
|
|
|
|
for (Function::iterator I = F.begin(), E = F.end(); I != E; ) {
|
2015-10-13 10:39:05 +08:00
|
|
|
BasicBlock *Cur = &*I++; // Advance over block so we don't traverse new blocks
|
2003-04-24 00:23:59 +08:00
|
|
|
|
2015-08-12 04:16:17 +08:00
|
|
|
// If the block is a dead Default block that will be deleted later, don't
|
|
|
|
// waste time processing it.
|
|
|
|
if (DeleteList.count(Cur))
|
|
|
|
continue;
|
|
|
|
|
2003-04-24 00:23:59 +08:00
|
|
|
if (SwitchInst *SI = dyn_cast<SwitchInst>(Cur->getTerminator())) {
|
|
|
|
Changed = true;
|
2015-08-12 02:12:26 +08:00
|
|
|
processSwitchInst(SI, DeleteList);
|
2003-04-24 00:23:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 02:12:26 +08:00
|
|
|
for (BasicBlock* BB: DeleteList) {
|
|
|
|
DeleteDeadBlock(BB);
|
|
|
|
}
|
|
|
|
|
2003-04-24 00:23:59 +08:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2015-09-17 00:21:08 +08:00
|
|
|
/// Used for debugging purposes.
|
2009-07-28 07:33:34 +08:00
|
|
|
static raw_ostream& operator<<(raw_ostream &O,
|
2010-10-23 16:10:43 +08:00
|
|
|
const LowerSwitch::CaseVector &C)
|
|
|
|
LLVM_ATTRIBUTE_USED;
|
2009-07-24 18:36:58 +08:00
|
|
|
static raw_ostream& operator<<(raw_ostream &O,
|
|
|
|
const LowerSwitch::CaseVector &C) {
|
2003-10-08 02:46:23 +08:00
|
|
|
O << "[";
|
|
|
|
|
2007-03-11 00:46:28 +08:00
|
|
|
for (LowerSwitch::CaseVector::const_iterator B = C.begin(),
|
2004-01-09 14:02:20 +08:00
|
|
|
E = C.end(); B != E; ) {
|
2007-03-11 00:46:28 +08:00
|
|
|
O << *B->Low << " -" << *B->High;
|
2003-10-08 02:46:23 +08:00
|
|
|
if (++B != E) O << ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
return O << "]";
|
|
|
|
}
|
2007-03-11 00:46:28 +08:00
|
|
|
|
2015-09-17 00:21:08 +08:00
|
|
|
/// \brief Update the first occurrence of the "switch statement" BB in the PHI
|
|
|
|
/// node with the "new" BB. The other occurrences will:
|
|
|
|
///
|
|
|
|
/// 1) Be updated by subsequent calls to this function. Switch statements may
|
|
|
|
/// have more than one outcoming edge into the same BB if they all have the same
|
|
|
|
/// value. When the switch statement is converted these incoming edges are now
|
|
|
|
/// coming from multiple BBs.
|
|
|
|
/// 2) Removed if subsequent incoming values now share the same case, i.e.,
|
|
|
|
/// multiple outcome edges are condensed into one. This is necessary to keep the
|
|
|
|
/// number of phi values equal to the number of branches to SuccBB.
|
2014-11-29 03:47:33 +08:00
|
|
|
static void fixPhis(BasicBlock *SuccBB, BasicBlock *OrigBB, BasicBlock *NewBB,
|
|
|
|
unsigned NumMergedCases) {
|
2015-10-13 10:39:05 +08:00
|
|
|
for (BasicBlock::iterator I = SuccBB->begin(),
|
|
|
|
IE = SuccBB->getFirstNonPHI()->getIterator();
|
2014-11-29 03:47:33 +08:00
|
|
|
I != IE; ++I) {
|
2014-07-11 18:34:36 +08:00
|
|
|
PHINode *PN = cast<PHINode>(I);
|
|
|
|
|
2015-08-09 02:27:36 +08:00
|
|
|
// Only update the first occurrence.
|
2014-11-29 03:47:33 +08:00
|
|
|
unsigned Idx = 0, E = PN->getNumIncomingValues();
|
2014-12-03 02:31:53 +08:00
|
|
|
unsigned LocalNumMergedCases = NumMergedCases;
|
2014-11-29 03:47:33 +08:00
|
|
|
for (; Idx != E; ++Idx) {
|
2014-11-11 05:05:27 +08:00
|
|
|
if (PN->getIncomingBlock(Idx) == OrigBB) {
|
|
|
|
PN->setIncomingBlock(Idx, NewBB);
|
|
|
|
break;
|
|
|
|
}
|
2014-07-11 18:34:36 +08:00
|
|
|
}
|
2014-11-29 03:47:33 +08:00
|
|
|
|
2015-08-09 02:27:36 +08:00
|
|
|
// Remove additional occurrences coming from condensed cases and keep the
|
2014-11-29 03:47:33 +08:00
|
|
|
// number of incoming values equal to the number of branches to SuccBB.
|
2015-03-18 02:03:10 +08:00
|
|
|
SmallVector<unsigned, 8> Indices;
|
2014-12-03 02:31:53 +08:00
|
|
|
for (++Idx; LocalNumMergedCases > 0 && Idx < E; ++Idx)
|
2014-11-29 03:47:33 +08:00
|
|
|
if (PN->getIncomingBlock(Idx) == OrigBB) {
|
2015-03-18 02:03:10 +08:00
|
|
|
Indices.push_back(Idx);
|
2014-12-03 02:31:53 +08:00
|
|
|
LocalNumMergedCases--;
|
2014-11-29 03:47:33 +08:00
|
|
|
}
|
2015-03-18 02:03:10 +08:00
|
|
|
// Remove incoming values in the reverse order to prevent invalidating
|
|
|
|
// *successive* index.
|
2016-06-24 12:05:21 +08:00
|
|
|
for (unsigned III : reverse(Indices))
|
|
|
|
PN->removeIncomingValue(III);
|
2014-07-11 18:34:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-17 00:21:08 +08:00
|
|
|
/// Convert the switch statement into a binary lookup of the case values.
|
|
|
|
/// The function recursively builds this tree. LowerBound and UpperBound are
|
|
|
|
/// used to keep track of the bounds for Val that have already been checked by
|
|
|
|
/// a block emitted by one of the previous calls to switchConvert in the call
|
|
|
|
/// stack.
|
2015-01-24 04:43:51 +08:00
|
|
|
BasicBlock *
|
|
|
|
LowerSwitch::switchConvert(CaseItr Begin, CaseItr End, ConstantInt *LowerBound,
|
|
|
|
ConstantInt *UpperBound, Value *Val,
|
|
|
|
BasicBlock *Predecessor, BasicBlock *OrigBlock,
|
|
|
|
BasicBlock *Default,
|
|
|
|
const std::vector<IntRange> &UnreachableRanges) {
|
2003-10-08 02:46:23 +08:00
|
|
|
unsigned Size = End - Begin;
|
|
|
|
|
2014-06-17 00:55:20 +08:00
|
|
|
if (Size == 1) {
|
|
|
|
// Check if the Case Range is perfectly squeezed in between
|
|
|
|
// already checked Upper and Lower bounds. If it is then we can avoid
|
|
|
|
// emitting the code that checks if the value actually falls in the range
|
|
|
|
// because the bounds already tell us so.
|
|
|
|
if (Begin->Low == LowerBound && Begin->High == UpperBound) {
|
2014-11-29 03:47:33 +08:00
|
|
|
unsigned NumMergedCases = 0;
|
|
|
|
if (LowerBound && UpperBound)
|
|
|
|
NumMergedCases =
|
|
|
|
UpperBound->getSExtValue() - LowerBound->getSExtValue();
|
|
|
|
fixPhis(Begin->BB, OrigBlock, Predecessor, NumMergedCases);
|
2014-06-17 00:55:20 +08:00
|
|
|
return Begin->BB;
|
|
|
|
}
|
2003-10-08 02:46:23 +08:00
|
|
|
return newLeafBlock(*Begin, Val, OrigBlock, Default);
|
2014-06-17 00:55:20 +08:00
|
|
|
}
|
2003-10-08 02:46:23 +08:00
|
|
|
|
|
|
|
unsigned Mid = Size / 2;
|
2007-03-11 00:46:28 +08:00
|
|
|
std::vector<CaseRange> LHS(Begin, Begin + Mid);
|
2010-01-05 09:26:45 +08:00
|
|
|
DEBUG(dbgs() << "LHS: " << LHS << "\n");
|
2007-03-11 00:46:28 +08:00
|
|
|
std::vector<CaseRange> RHS(Begin + Mid, End);
|
2010-01-05 09:26:45 +08:00
|
|
|
DEBUG(dbgs() << "RHS: " << RHS << "\n");
|
2003-10-08 02:46:23 +08:00
|
|
|
|
2014-06-17 00:55:20 +08:00
|
|
|
CaseRange &Pivot = *(Begin + Mid);
|
|
|
|
DEBUG(dbgs() << "Pivot ==> "
|
2015-02-06 00:58:10 +08:00
|
|
|
<< Pivot.Low->getValue()
|
|
|
|
<< " -" << Pivot.High->getValue() << "\n");
|
2014-06-17 00:55:20 +08:00
|
|
|
|
|
|
|
// NewLowerBound here should never be the integer minimal value.
|
|
|
|
// This is because it is computed from a case range that is never
|
|
|
|
// the smallest, so there is always a case range that has at least
|
|
|
|
// a smaller value.
|
2015-02-06 00:58:10 +08:00
|
|
|
ConstantInt *NewLowerBound = Pivot.Low;
|
2015-01-24 04:43:51 +08:00
|
|
|
|
|
|
|
// Because NewLowerBound is never the smallest representable integer
|
|
|
|
// it is safe here to subtract one.
|
|
|
|
ConstantInt *NewUpperBound = ConstantInt::get(NewLowerBound->getContext(),
|
|
|
|
NewLowerBound->getValue() - 1);
|
|
|
|
|
|
|
|
if (!UnreachableRanges.empty()) {
|
|
|
|
// Check if the gap between LHS's highest and NewLowerBound is unreachable.
|
2015-02-06 00:58:10 +08:00
|
|
|
int64_t GapLow = LHS.back().High->getSExtValue() + 1;
|
2015-01-24 04:43:51 +08:00
|
|
|
int64_t GapHigh = NewLowerBound->getSExtValue() - 1;
|
|
|
|
IntRange Gap = { GapLow, GapHigh };
|
|
|
|
if (GapHigh >= GapLow && IsInRanges(Gap, UnreachableRanges))
|
2015-02-06 00:58:10 +08:00
|
|
|
NewUpperBound = LHS.back().High;
|
2014-06-17 00:55:20 +08:00
|
|
|
}
|
2003-10-08 02:46:23 +08:00
|
|
|
|
2014-06-17 00:55:20 +08:00
|
|
|
DEBUG(dbgs() << "LHS Bounds ==> ";
|
|
|
|
if (LowerBound) {
|
2015-02-06 00:58:10 +08:00
|
|
|
dbgs() << LowerBound->getSExtValue();
|
2014-06-17 00:55:20 +08:00
|
|
|
} else {
|
|
|
|
dbgs() << "NONE";
|
|
|
|
}
|
|
|
|
dbgs() << " - " << NewUpperBound->getSExtValue() << "\n";
|
|
|
|
dbgs() << "RHS Bounds ==> ";
|
|
|
|
dbgs() << NewLowerBound->getSExtValue() << " - ";
|
|
|
|
if (UpperBound) {
|
2015-02-06 00:58:10 +08:00
|
|
|
dbgs() << UpperBound->getSExtValue() << "\n";
|
2014-06-17 00:55:20 +08:00
|
|
|
} else {
|
|
|
|
dbgs() << "NONE\n";
|
|
|
|
});
|
|
|
|
|
2003-10-08 02:46:23 +08:00
|
|
|
// Create a new node that checks if the value is < pivot. Go to the
|
|
|
|
// left branch if it is and right branch if not.
|
|
|
|
Function* F = OrigBlock->getParent();
|
2009-08-14 05:58:54 +08:00
|
|
|
BasicBlock* NewNode = BasicBlock::Create(Val->getContext(), "NodeBlock");
|
2003-10-08 02:46:23 +08:00
|
|
|
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
llvm-svn: 190328
2013-09-10 03:14:35 +08:00
|
|
|
ICmpInst* Comp = new ICmpInst(ICmpInst::ICMP_SLT,
|
2009-07-10 07:48:35 +08:00
|
|
|
Val, Pivot.Low, "Pivot");
|
2014-07-11 18:34:36 +08:00
|
|
|
|
|
|
|
BasicBlock *LBranch = switchConvert(LHS.begin(), LHS.end(), LowerBound,
|
|
|
|
NewUpperBound, Val, NewNode, OrigBlock,
|
2015-01-24 04:43:51 +08:00
|
|
|
Default, UnreachableRanges);
|
2014-07-11 18:34:36 +08:00
|
|
|
BasicBlock *RBranch = switchConvert(RHS.begin(), RHS.end(), NewLowerBound,
|
|
|
|
UpperBound, Val, NewNode, OrigBlock,
|
2015-01-24 04:43:51 +08:00
|
|
|
Default, UnreachableRanges);
|
2014-07-11 18:34:36 +08:00
|
|
|
|
2015-10-13 10:39:05 +08:00
|
|
|
F->getBasicBlockList().insert(++OrigBlock->getIterator(), NewNode);
|
2003-10-08 02:46:23 +08:00
|
|
|
NewNode->getInstList().push_back(Comp);
|
2014-07-11 18:34:36 +08:00
|
|
|
|
2008-04-07 04:25:17 +08:00
|
|
|
BranchInst::Create(LBranch, RBranch, Comp, NewNode);
|
2003-10-08 02:46:23 +08:00
|
|
|
return NewNode;
|
|
|
|
}
|
|
|
|
|
2015-09-17 00:21:08 +08:00
|
|
|
/// Create a new leaf block for the binary lookup tree. It checks if the
|
|
|
|
/// switch's value == the case's value. If not, then it jumps to the default
|
|
|
|
/// branch. At this point in the tree, the value can't be another valid case
|
|
|
|
/// value, so the jump to the "default" branch is warranted.
|
2007-03-11 00:46:28 +08:00
|
|
|
BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val,
|
2003-10-08 02:46:23 +08:00
|
|
|
BasicBlock* OrigBlock,
|
|
|
|
BasicBlock* Default)
|
|
|
|
{
|
|
|
|
Function* F = OrigBlock->getParent();
|
2009-08-14 05:58:54 +08:00
|
|
|
BasicBlock* NewLeaf = BasicBlock::Create(Val->getContext(), "LeafBlock");
|
2015-10-13 10:39:05 +08:00
|
|
|
F->getBasicBlockList().insert(++OrigBlock->getIterator(), NewLeaf);
|
2003-10-08 02:46:23 +08:00
|
|
|
|
2007-03-11 00:46:28 +08:00
|
|
|
// Emit comparison
|
2014-04-25 13:29:35 +08:00
|
|
|
ICmpInst* Comp = nullptr;
|
2007-03-11 00:46:28 +08:00
|
|
|
if (Leaf.Low == Leaf.High) {
|
|
|
|
// Make the seteq instruction...
|
2009-07-10 07:48:35 +08:00
|
|
|
Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_EQ, Val,
|
|
|
|
Leaf.Low, "SwitchLeaf");
|
2007-03-11 00:46:28 +08:00
|
|
|
} else {
|
|
|
|
// Make range comparison
|
2015-02-06 00:58:10 +08:00
|
|
|
if (Leaf.Low->isMinValue(true /*isSigned*/)) {
|
2007-03-11 00:46:28 +08:00
|
|
|
// Val >= Min && Val <= Hi --> Val <= Hi
|
2009-07-10 07:48:35 +08:00
|
|
|
Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_SLE, Val, Leaf.High,
|
|
|
|
"SwitchLeaf");
|
2015-02-06 00:58:10 +08:00
|
|
|
} else if (Leaf.Low->isZero()) {
|
2007-03-11 00:46:28 +08:00
|
|
|
// Val >= 0 && Val <= Hi --> Val <=u Hi
|
2009-07-10 07:48:35 +08:00
|
|
|
Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_ULE, Val, Leaf.High,
|
|
|
|
"SwitchLeaf");
|
2007-03-11 00:46:28 +08:00
|
|
|
} else {
|
|
|
|
// Emit V-Lo <=u Hi-Lo
|
2009-07-30 02:55:55 +08:00
|
|
|
Constant* NegLo = ConstantExpr::getNeg(Leaf.Low);
|
2008-05-17 03:29:10 +08:00
|
|
|
Instruction* Add = BinaryOperator::CreateAdd(Val, NegLo,
|
2007-03-11 00:46:28 +08:00
|
|
|
Val->getName()+".off",
|
|
|
|
NewLeaf);
|
2009-07-30 02:55:55 +08:00
|
|
|
Constant *UpperBound = ConstantExpr::getAdd(NegLo, Leaf.High);
|
2009-07-10 07:48:35 +08:00
|
|
|
Comp = new ICmpInst(*NewLeaf, ICmpInst::ICMP_ULE, Add, UpperBound,
|
|
|
|
"SwitchLeaf");
|
2007-03-11 00:46:28 +08:00
|
|
|
}
|
|
|
|
}
|
2003-10-08 02:46:23 +08:00
|
|
|
|
|
|
|
// Make the conditional branch...
|
2007-03-11 00:46:28 +08:00
|
|
|
BasicBlock* Succ = Leaf.BB;
|
2008-04-07 04:25:17 +08:00
|
|
|
BranchInst::Create(Succ, Default, Comp, NewLeaf);
|
2003-10-08 02:46:23 +08:00
|
|
|
|
|
|
|
// If there were any PHI nodes in this successor, rewrite one entry
|
|
|
|
// from OrigBlock to come from NewLeaf.
|
2004-09-16 01:06:42 +08:00
|
|
|
for (BasicBlock::iterator I = Succ->begin(); isa<PHINode>(I); ++I) {
|
|
|
|
PHINode* PN = cast<PHINode>(I);
|
2007-03-11 00:46:28 +08:00
|
|
|
// Remove all but one incoming entries from the cluster
|
2015-02-06 00:58:10 +08:00
|
|
|
uint64_t Range = Leaf.High->getSExtValue() -
|
|
|
|
Leaf.Low->getSExtValue();
|
2007-03-11 00:46:28 +08:00
|
|
|
for (uint64_t j = 0; j < Range; ++j) {
|
|
|
|
PN->removeIncomingValue(OrigBlock);
|
|
|
|
}
|
|
|
|
|
2003-10-08 02:46:23 +08:00
|
|
|
int BlockIdx = PN->getBasicBlockIndex(OrigBlock);
|
|
|
|
assert(BlockIdx != -1 && "Switch didn't go to this successor??");
|
|
|
|
PN->setIncomingBlock((unsigned)BlockIdx, NewLeaf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewLeaf;
|
|
|
|
}
|
|
|
|
|
2015-09-17 00:21:08 +08:00
|
|
|
/// Transform simple list of Cases into list of CaseRange's.
|
2007-03-11 00:46:28 +08:00
|
|
|
unsigned LowerSwitch::Clusterify(CaseVector& Cases, SwitchInst *SI) {
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
llvm-svn: 190328
2013-09-10 03:14:35 +08:00
|
|
|
unsigned numCmps = 0;
|
2007-03-11 00:46:28 +08:00
|
|
|
|
|
|
|
// Start with "simple" cases
|
2017-04-12 15:27:28 +08:00
|
|
|
for (auto Case : SI->cases())
|
|
|
|
Cases.push_back(CaseRange(Case.getCaseValue(), Case.getCaseValue(),
|
|
|
|
Case.getCaseSuccessor()));
|
|
|
|
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
llvm-svn: 190328
2013-09-10 03:14:35 +08:00
|
|
|
std::sort(Cases.begin(), Cases.end(), CaseCmp());
|
|
|
|
|
|
|
|
// Merge case into clusters
|
2015-06-20 23:59:34 +08:00
|
|
|
if (Cases.size() >= 2) {
|
|
|
|
CaseItr I = Cases.begin();
|
|
|
|
for (CaseItr J = std::next(I), E = Cases.end(); J != E; ++J) {
|
2015-02-06 00:58:10 +08:00
|
|
|
int64_t nextValue = J->Low->getSExtValue();
|
|
|
|
int64_t currentValue = I->High->getSExtValue();
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
llvm-svn: 190328
2013-09-10 03:14:35 +08:00
|
|
|
BasicBlock* nextBB = J->BB;
|
|
|
|
BasicBlock* currentBB = I->BB;
|
|
|
|
|
|
|
|
// If the two neighboring cases go to the same destination, merge them
|
|
|
|
// into a single case.
|
2015-06-20 08:28:25 +08:00
|
|
|
assert(nextValue > currentValue && "Cases should be strictly ascending");
|
|
|
|
if ((nextValue == currentValue + 1) && (currentBB == nextBB)) {
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
llvm-svn: 190328
2013-09-10 03:14:35 +08:00
|
|
|
I->High = J->High;
|
2015-06-20 23:59:34 +08:00
|
|
|
// FIXME: Combine branch weights.
|
|
|
|
} else if (++I != J) {
|
|
|
|
*I = *J;
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
llvm-svn: 190328
2013-09-10 03:14:35 +08:00
|
|
|
}
|
|
|
|
}
|
2015-06-20 23:59:34 +08:00
|
|
|
Cases.erase(std::next(I), Cases.end());
|
|
|
|
}
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
llvm-svn: 190328
2013-09-10 03:14:35 +08:00
|
|
|
|
|
|
|
for (CaseItr I=Cases.begin(), E=Cases.end(); I!=E; ++I, ++numCmps) {
|
|
|
|
if (I->Low != I->High)
|
2007-03-11 00:46:28 +08:00
|
|
|
// A range counts double, since it requires two compares.
|
|
|
|
++numCmps;
|
|
|
|
}
|
|
|
|
|
Revert patches to add case-range support for PR1255.
The work on this project was left in an unfinished and inconsistent state.
Hopefully someone will eventually get a chance to implement this feature, but
in the meantime, it is better to put things back the way the were. I have
left support in the bitcode reader to handle the case-range bitcode format,
so that we do not lose bitcode compatibility with the llvm 3.3 release.
This reverts the following commits: 155464, 156374, 156377, 156613, 156704,
156757, 156804 156808, 156985, 157046, 157112, 157183, 157315, 157384, 157575,
157576, 157586, 157612, 157810, 157814, 157815, 157880, 157881, 157882, 157884,
157887, 157901, 158979, 157987, 157989, 158986, 158997, 159076, 159101, 159100,
159200, 159201, 159207, 159527, 159532, 159540, 159583, 159618, 159658, 159659,
159660, 159661, 159703, 159704, 160076, 167356, 172025, 186736
llvm-svn: 190328
2013-09-10 03:14:35 +08:00
|
|
|
return numCmps;
|
2007-03-11 00:46:28 +08:00
|
|
|
}
|
|
|
|
|
2015-09-17 00:21:08 +08:00
|
|
|
/// Replace the specified switch instruction with a sequence of chained if-then
|
|
|
|
/// insts in a balanced binary search.
|
2015-08-12 04:16:17 +08:00
|
|
|
void LowerSwitch::processSwitchInst(SwitchInst *SI,
|
|
|
|
SmallPtrSetImpl<BasicBlock*> &DeleteList) {
|
2003-04-24 00:23:59 +08:00
|
|
|
BasicBlock *CurBlock = SI->getParent();
|
|
|
|
BasicBlock *OrigBlock = CurBlock;
|
|
|
|
Function *F = CurBlock->getParent();
|
2011-09-30 04:21:17 +08:00
|
|
|
Value *Val = SI->getCondition(); // The value we are switching on...
|
2003-10-08 02:46:23 +08:00
|
|
|
BasicBlock* Default = SI->getDefaultDest();
|
2003-04-24 00:23:59 +08:00
|
|
|
|
2017-04-22 07:54:12 +08:00
|
|
|
// Don't handle unreachable blocks. If there are successors with phis, this
|
|
|
|
// would leave them behind with missing predecessors.
|
|
|
|
if ((CurBlock != &F->getEntryBlock() && pred_empty(CurBlock)) ||
|
|
|
|
CurBlock->getSinglePredecessor() == CurBlock) {
|
|
|
|
DeleteList.insert(CurBlock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-24 04:43:51 +08:00
|
|
|
// If there is only the default destination, just branch.
|
SwitchInst refactoring.
The purpose of refactoring is to hide operand roles from SwitchInst user (programmer). If you want to play with operands directly, probably you will need lower level methods than SwitchInst ones (TerminatorInst or may be User). After this patch we can reorganize SwitchInst operands and successors as we want.
What was done:
1. Changed semantics of index inside the getCaseValue method:
getCaseValue(0) means "get first case", not a condition. Use getCondition() if you want to resolve the condition. I propose don't mix SwitchInst case indexing with low level indexing (TI successors indexing, User's operands indexing), since it may be dangerous.
2. By the same reason findCaseValue(ConstantInt*) returns actual number of case value. 0 means first case, not default. If there is no case with given value, ErrorIndex will returned.
3. Added getCaseSuccessor method. I propose to avoid usage of TerminatorInst::getSuccessor if you want to resolve case successor BB. Use getCaseSuccessor instead, since internal SwitchInst organization of operands/successors is hidden and may be changed in any moment.
4. Added resolveSuccessorIndex and resolveCaseIndex. The main purpose of these methods is to see how case successors are really mapped in TerminatorInst.
4.1 "resolveSuccessorIndex" was created if you need to level down from SwitchInst to TerminatorInst. It returns TerminatorInst's successor index for given case successor.
4.2 "resolveCaseIndex" converts low level successors index to case index that curresponds to the given successor.
Note: There are also related compatability fix patches for dragonegg, klee, llvm-gcc-4.0, llvm-gcc-4.2, safecode, clang.
llvm-svn: 149481
2012-02-01 15:49:51 +08:00
|
|
|
if (!SI->getNumCases()) {
|
2015-01-24 04:43:51 +08:00
|
|
|
BranchInst::Create(Default, CurBlock);
|
|
|
|
SI->eraseFromParent();
|
2003-08-24 06:54:34 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-24 04:43:51 +08:00
|
|
|
// Prepare cases vector.
|
|
|
|
CaseVector Cases;
|
|
|
|
unsigned numCmps = Clusterify(Cases, SI);
|
|
|
|
DEBUG(dbgs() << "Clusterify finished. Total clusters: " << Cases.size()
|
|
|
|
<< ". Total compares: " << numCmps << "\n");
|
|
|
|
DEBUG(dbgs() << "Cases: " << Cases << "\n");
|
|
|
|
(void)numCmps;
|
|
|
|
|
|
|
|
ConstantInt *LowerBound = nullptr;
|
|
|
|
ConstantInt *UpperBound = nullptr;
|
|
|
|
std::vector<IntRange> UnreachableRanges;
|
|
|
|
|
|
|
|
if (isa<UnreachableInst>(Default->getFirstNonPHIOrDbg())) {
|
2015-08-09 02:27:36 +08:00
|
|
|
// Make the bounds tightly fitted around the case value range, because we
|
2015-01-24 04:43:51 +08:00
|
|
|
// know that the value passed to the switch must be exactly one of the case
|
|
|
|
// values.
|
|
|
|
assert(!Cases.empty());
|
2015-02-06 00:58:10 +08:00
|
|
|
LowerBound = Cases.front().Low;
|
|
|
|
UpperBound = Cases.back().High;
|
2015-01-24 04:43:51 +08:00
|
|
|
|
|
|
|
DenseMap<BasicBlock *, unsigned> Popularity;
|
|
|
|
unsigned MaxPop = 0;
|
|
|
|
BasicBlock *PopSucc = nullptr;
|
|
|
|
|
|
|
|
IntRange R = { INT64_MIN, INT64_MAX };
|
|
|
|
UnreachableRanges.push_back(R);
|
|
|
|
for (const auto &I : Cases) {
|
2015-02-06 00:58:10 +08:00
|
|
|
int64_t Low = I.Low->getSExtValue();
|
|
|
|
int64_t High = I.High->getSExtValue();
|
2015-01-24 04:43:51 +08:00
|
|
|
|
|
|
|
IntRange &LastRange = UnreachableRanges.back();
|
|
|
|
if (LastRange.Low == Low) {
|
|
|
|
// There is nothing left of the previous range.
|
|
|
|
UnreachableRanges.pop_back();
|
|
|
|
} else {
|
|
|
|
// Terminate the previous range.
|
|
|
|
assert(Low > LastRange.Low);
|
|
|
|
LastRange.High = Low - 1;
|
|
|
|
}
|
|
|
|
if (High != INT64_MAX) {
|
|
|
|
IntRange R = { High + 1, INT64_MAX };
|
|
|
|
UnreachableRanges.push_back(R);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count popularity.
|
|
|
|
int64_t N = High - Low + 1;
|
|
|
|
unsigned &Pop = Popularity[I.BB];
|
|
|
|
if ((Pop += N) > MaxPop) {
|
|
|
|
MaxPop = Pop;
|
|
|
|
PopSucc = I.BB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifndef NDEBUG
|
|
|
|
/* UnreachableRanges should be sorted and the ranges non-adjacent. */
|
|
|
|
for (auto I = UnreachableRanges.begin(), E = UnreachableRanges.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
assert(I->Low <= I->High);
|
|
|
|
auto Next = I + 1;
|
|
|
|
if (Next != E) {
|
|
|
|
assert(Next->Low > I->High);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Use the most popular block as the new default, reducing the number of
|
|
|
|
// cases.
|
|
|
|
assert(MaxPop > 0 && PopSucc);
|
|
|
|
Default = PopSucc;
|
2016-08-12 12:32:37 +08:00
|
|
|
Cases.erase(
|
|
|
|
remove_if(Cases,
|
|
|
|
[PopSucc](const CaseRange &R) { return R.BB == PopSucc; }),
|
|
|
|
Cases.end());
|
2015-01-24 04:43:51 +08:00
|
|
|
|
|
|
|
// If there are no cases left, just branch.
|
|
|
|
if (Cases.empty()) {
|
|
|
|
BranchInst::Create(Default, CurBlock);
|
|
|
|
SI->eraseFromParent();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-08 02:46:23 +08:00
|
|
|
// Create a new, empty default block so that the new hierarchy of
|
|
|
|
// if-then statements go to this and the PHI nodes are happy.
|
2015-01-24 04:43:51 +08:00
|
|
|
BasicBlock *NewDefault = BasicBlock::Create(SI->getContext(), "NewDefault");
|
2015-10-13 10:39:05 +08:00
|
|
|
F->getBasicBlockList().insert(Default->getIterator(), NewDefault);
|
2015-01-24 04:43:51 +08:00
|
|
|
BranchInst::Create(Default, NewDefault);
|
|
|
|
|
2003-10-08 02:46:23 +08:00
|
|
|
// If there is an entry in any PHI nodes for the default edge, make sure
|
|
|
|
// to update them as well.
|
2004-09-16 01:06:42 +08:00
|
|
|
for (BasicBlock::iterator I = Default->begin(); isa<PHINode>(I); ++I) {
|
|
|
|
PHINode *PN = cast<PHINode>(I);
|
2003-10-08 02:46:23 +08:00
|
|
|
int BlockIdx = PN->getBasicBlockIndex(OrigBlock);
|
|
|
|
assert(BlockIdx != -1 && "Switch didn't go to this successor??");
|
|
|
|
PN->setIncomingBlock((unsigned)BlockIdx, NewDefault);
|
2003-04-24 00:23:59 +08:00
|
|
|
}
|
|
|
|
|
2014-06-17 00:55:20 +08:00
|
|
|
BasicBlock *SwitchBlock =
|
|
|
|
switchConvert(Cases.begin(), Cases.end(), LowerBound, UpperBound, Val,
|
2015-01-24 04:43:51 +08:00
|
|
|
OrigBlock, OrigBlock, NewDefault, UnreachableRanges);
|
2003-10-08 02:46:23 +08:00
|
|
|
|
|
|
|
// Branch to our shiny new if-then stuff...
|
2008-04-07 04:25:17 +08:00
|
|
|
BranchInst::Create(SwitchBlock, OrigBlock);
|
2003-10-08 02:46:23 +08:00
|
|
|
|
2003-04-24 00:23:59 +08:00
|
|
|
// We are now done with the switch instruction, delete it.
|
2015-01-24 04:43:51 +08:00
|
|
|
BasicBlock *OldDefault = SI->getDefaultDest();
|
2004-03-14 12:14:31 +08:00
|
|
|
CurBlock->getInstList().erase(SI);
|
2014-06-17 00:55:20 +08:00
|
|
|
|
2015-08-12 02:12:26 +08:00
|
|
|
// If the Default block has no more predecessors just add it to DeleteList.
|
2015-01-24 04:43:51 +08:00
|
|
|
if (pred_begin(OldDefault) == pred_end(OldDefault))
|
2015-08-12 04:16:17 +08:00
|
|
|
DeleteList.insert(OldDefault);
|
2003-04-24 00:23:59 +08:00
|
|
|
}
|