unsigned Align, AtomicOrdering Order,
SynchronizationScope SynchScope,
BasicBlock *InsertAtEnd);
-
+
/// isVolatile - Return true if this is a store to a volatile memory
/// location.
Value *getCompareOperand() { return getOperand(1); }
const Value *getCompareOperand() const { return getOperand(1); }
-
+
Value *getNewValOperand() { return getOperand(2); }
const Value *getNewValOperand() const { return getOperand(2); }
-
+
/// \brief Returns the address space of the pointer operand.
unsigned getPointerAddressSpace() const {
return getPointerOperand()->getType()->getPointerAddressSpace();
}
-
+
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Instruction *I) {
return I->getOpcode() == Instruction::AtomicCmpXchg;
Constant *getMask() const {
return cast<Constant>(getOperand(2));
}
-
+
/// getMaskValue - Return the index from the shuffle mask for the specified
/// output result. This is either -1 if the element is undef or a number less
/// than 2*numelements.
int getMaskValue(unsigned i) const {
return getMaskValue(getMask(), i);
}
-
+
/// getShuffleMask - Return the full mask for this instruction, where each
/// element is the element number and undef's are returned as -1.
static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
Instruction *InsertBefore = 0) {
return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
}
- static PHINode *Create(Type *Ty, unsigned NumReservedValues,
+ static PHINode *Create(Type *Ty, unsigned NumReservedValues,
const Twine &NameStr, BasicBlock *InsertAtEnd) {
return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
}
// Operand[1] = Default basic block destination
// Operand[2n ] = Value to match
// Operand[2n+1] = BasicBlock to go to on match
-
+
// Store case values separately from operands list. We needn't User-Use
// concept here, since it is just a case value, it will always constant,
// and case value couldn't reused with another instructions/values.
typedef std::list<IntegersSubset> Subsets;
typedef Subsets::iterator SubsetsIt;
typedef Subsets::const_iterator SubsetsConstIt;
-
+
Subsets TheSubsets;
-
+
SwitchInst(const SwitchInst &SI);
void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
void growOperands();
protected:
virtual SwitchInst *clone_impl() const;
public:
-
+
// FIXME: Currently there are a lot of unclean template parameters,
// we need to make refactoring in future.
// All these parameters are used to implement both iterator and const_iterator
// SubsetsItTy may be SubsetsConstIt or SubsetsIt
// BasicBlockTy may be "const BasicBlock" or "BasicBlock"
template <class SwitchInstTy, class ConstantIntTy,
- class SubsetsItTy, class BasicBlockTy>
+ class SubsetsItTy, class BasicBlockTy>
class CaseIteratorT;
typedef CaseIteratorT<const SwitchInst, const ConstantInt,
SubsetsConstIt, const BasicBlock> ConstCaseIt;
class CaseIt;
-
+
// -2
static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
-
+
static SwitchInst *Create(Value *Value, BasicBlock *Default,
unsigned NumCases, Instruction *InsertBefore = 0) {
return new SwitchInst(Value, Default, NumCases, InsertBefore);
unsigned NumCases, BasicBlock *InsertAtEnd) {
return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
}
-
+
~SwitchInst();
/// Provide fast operand accessors
ConstCaseIt case_begin() const {
return ConstCaseIt(this, 0, TheSubsets.begin());
}
-
+
/// Returns a read/write iterator that points one past the last
/// in the SwitchInst.
CaseIt case_end() {
/// Note: this iterator allows to resolve successor only. Attempt
/// to resolve case value causes an assertion.
/// Also note, that increment and decrement also causes an assertion and
- /// makes iterator invalid.
+ /// makes iterator invalid.
CaseIt case_default() {
return CaseIt(this, DefaultPseudoIndex, TheSubsets.end());
}
ConstCaseIt case_default() const {
return ConstCaseIt(this, DefaultPseudoIndex, TheSubsets.end());
}
-
+
/// findCaseValue - Search all of the case values for the specified constant.
/// If it is explicitly handled, return the case iterator of it, otherwise
/// return default case iterator to indicate
if (i.getCaseValueEx().isSatisfies(IntItem::fromConstantInt(C)))
return i;
return case_default();
- }
-
+ }
+
/// findCaseDest - Finds the unique case value for a given successor. Returns
/// null if the successor is not found, not unique, or is the default case.
ConstantInt *findCaseDest(BasicBlock *BB) {
/// This action invalidates case_end(). Old case_end() iterator will
/// point to the added case.
void addCase(ConstantInt *OnVal, BasicBlock *Dest);
-
+
/// addCase - Add an entry to the switch instruction.
/// Note:
/// This action invalidates case_end(). Old case_end() iterator will
assert(idx < getNumSuccessors() && "Successor # out of range for switch!");
setOperand(idx*2+1, (Value*)NewSucc);
}
-
+
uint16_t hash() const {
uint32_t NumberOfCases = (uint32_t)getNumCases();
uint16_t Hash = (0xFFFF & NumberOfCases) ^ (NumberOfCases >> 16);
for (ConstCaseIt i = case_begin(), e = case_end();
i != e; ++i) {
- uint32_t NumItems = (uint32_t)i.getCaseValueEx().getNumItems();
+ uint32_t NumItems = (uint32_t)i.getCaseValueEx().getNumItems();
Hash = (Hash << 1) ^ (0xFFFF & NumItems) ^ (NumItems >> 16);
}
return Hash;
- }
-
+ }
+
// Case iterators definition.
template <class SwitchInstTy, class ConstantIntTy,
- class SubsetsItTy, class BasicBlockTy>
+ class SubsetsItTy, class BasicBlockTy>
class CaseIteratorT {
protected:
-
+
SwitchInstTy *SI;
unsigned long Index;
SubsetsItTy SubsetIt;
-
+
/// Initializes case iterator for given SwitchInst and for given
- /// case number.
+ /// case number.
friend class SwitchInst;
CaseIteratorT(SwitchInstTy *SI, unsigned SuccessorIndex,
SubsetsItTy CaseValueIt) {
Index = SuccessorIndex;
this->SubsetIt = CaseValueIt;
}
-
+
public:
typedef typename SubsetsItTy::reference IntegersSubsetRef;
typedef CaseIteratorT<SwitchInstTy, ConstantIntTy,
SubsetsItTy, BasicBlockTy> Self;
-
+
CaseIteratorT(SwitchInstTy *SI, unsigned CaseNum) {
this->SI = SI;
Index = CaseNum;
SubsetIt = SI->TheSubsets.begin();
std::advance(SubsetIt, CaseNum);
}
-
-
+
+
/// Initializes case iterator for given SwitchInst and for given
/// TerminatorInst's successor index.
static Self fromSuccessorIndex(SwitchInstTy *SI, unsigned SuccessorIndex) {
assert(SuccessorIndex < SI->getNumSuccessors() &&
- "Successor index # out of range!");
- return SuccessorIndex != 0 ?
+ "Successor index # out of range!");
+ return SuccessorIndex != 0 ?
Self(SI, SuccessorIndex - 1) :
- Self(SI, DefaultPseudoIndex);
+ Self(SI, DefaultPseudoIndex);
}
-
+
/// Resolves case value for current case.
/// @deprecated
ConstantIntTy *getCaseValue() {
assert(Index < SI->getNumCases() && "Index out the number of cases.");
IntegersSubsetRef CaseRanges = *SubsetIt;
-
+
// FIXME: Currently we work with ConstantInt based cases.
// So return CaseValue as ConstantInt.
return CaseRanges.getSingleNumber(0).toConstantInt();
assert(Index < SI->getNumCases() && "Index out the number of cases.");
return *SubsetIt;
}
-
+
/// Resolves successor for current case.
BasicBlockTy *getCaseSuccessor() {
assert((Index < SI->getNumCases() ||
Index == DefaultPseudoIndex) &&
"Index out the number of cases.");
- return SI->getSuccessor(getSuccessorIndex());
+ return SI->getSuccessor(getSuccessorIndex());
}
-
+
/// Returns number of current case.
unsigned getCaseIndex() const { return Index; }
-
+
/// Returns TerminatorInst's successor index for current case successor.
unsigned getSuccessorIndex() const {
assert((Index == DefaultPseudoIndex || Index < SI->getNumCases()) &&
"Index out the number of cases.");
return Index != DefaultPseudoIndex ? Index + 1 : 0;
}
-
+
Self operator++() {
// Check index correctness after increment.
// Note: Index == getNumCases() means end().
++(*this);
return tmp;
}
- Self operator--() {
+ Self operator--() {
// Check index correctness after decrement.
// Note: Index == getNumCases() means end().
// Also allow "-1" iterator here. That will became valid after ++.
SubsetIt = SI->TheSubsets.end();
return *this;
}
-
+
if (Index != -1UL)
--SubsetIt;
-
+
return *this;
}
Self operator--(int) {
SubsetsIt, BasicBlock> {
typedef CaseIteratorT<SwitchInst, ConstantInt, SubsetsIt, BasicBlock>
ParentTy;
-
+
protected:
friend class SwitchInst;
CaseIt(SwitchInst *SI, unsigned CaseNum, SubsetsIt SubsetIt) :
ParentTy(SI, CaseNum, SubsetIt) {}
-
+
void updateCaseValueOperand(IntegersSubset& V) {
- SI->setOperand(2 + Index*2, reinterpret_cast<Value*>((Constant*)V));
+ SI->setOperand(2 + Index*2, reinterpret_cast<Value*>((Constant*)V));
}
-
+
public:
- CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
-
+ CaseIt(SwitchInst *SI, unsigned CaseNum) : ParentTy(SI, CaseNum) {}
+
CaseIt(const ParentTy& Src) : ParentTy(Src) {}
- /// Sets the new value for current case.
+ /// Sets the new value for current case.
/// @deprecated.
void setValue(ConstantInt *V) {
assert(Index < SI->getNumCases() && "Index out the number of cases.");
*SubsetIt = Mapping.getCase();
updateCaseValueOperand(*SubsetIt);
}
-
+
/// Sets the new value for current case.
void setValueEx(IntegersSubset& V) {
assert(Index < SI->getNumCases() && "Index out the number of cases.");
*SubsetIt = V;
- updateCaseValueOperand(*SubsetIt);
+ updateCaseValueOperand(*SubsetIt);
}
-
+
/// Sets the new successor for current case.
void setSuccessor(BasicBlock *S) {
- SI->setSuccessor(getSuccessorIndex(), S);
+ SI->setSuccessor(getSuccessorIndex(), S);
}
};