// Exploit the fact that phi nodes always have at least one entry.
Value *ConstantValue = getIncomingValue(0);
for (unsigned i = 1, e = getNumIncomingValues(); i != e; ++i)
- if (getIncomingValue(i) != ConstantValue)
- return 0; // Incoming values not all the same.
+ if (getIncomingValue(i) != ConstantValue && getIncomingValue(i) != this) {
+ if (ConstantValue != this)
+ return 0; // Incoming values not all the same.
+ // The case where the first value is this PHI.
+ ConstantValue = getIncomingValue(i);
+ }
+ if (ConstantValue == this)
+ return UndefValue::get(getType());
return ConstantValue;
}
setAttributes(PAL);
}
-bool CallInst::paramHasAttr(unsigned i, Attributes attr) const {
- if (AttributeList.paramHasAttr(i, attr))
+bool CallInst::fnHasNoAliasAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasNoAliasAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasNoAliasAttr();
+ return false;
+}
+bool CallInst::fnHasNoInlineAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasNoInlineAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasNoInlineAttr();
+ return false;
+}
+bool CallInst::fnHasNoReturnAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasNoReturnAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasNoReturnAttr();
+ return false;
+}
+bool CallInst::fnHasNoUnwindAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasNoUnwindAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasNoUnwindAttr();
+ return false;
+}
+bool CallInst::fnHasReadNoneAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasReadNoneAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasReadNoneAttr();
+ return false;
+}
+bool CallInst::fnHasReadOnlyAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasReadOnlyAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasReadOnlyAttr();
+ return false;
+}
+bool CallInst::fnHasReturnsTwiceAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasReturnsTwiceAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasReturnsTwiceAttr();
+ return false;
+}
+
+bool CallInst::paramHasSExtAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasSExtAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasSExtAttr();
+ return false;
+}
+
+bool CallInst::paramHasZExtAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasZExtAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasZExtAttr();
+ return false;
+}
+
+bool CallInst::paramHasInRegAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasInRegAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasInRegAttr();
+ return false;
+}
+
+bool CallInst::paramHasStructRetAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasStructRetAttr())
return true;
if (const Function *F = getCalledFunction())
- return F->paramHasAttr(i, attr);
+ return F->getParamAttributes(i).hasStructRetAttr();
+ return false;
+}
+
+bool CallInst::paramHasNestAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasNestAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasNestAttr();
+ return false;
+}
+
+bool CallInst::paramHasByValAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasByValAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasByValAttr();
+ return false;
+}
+
+bool CallInst::paramHasNoAliasAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasNoAliasAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasNoAliasAttr();
+ return false;
+}
+
+bool CallInst::paramHasNoCaptureAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasNoCaptureAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasNoCaptureAttr();
return false;
}
return setSuccessor(idx, B);
}
-bool InvokeInst::paramHasAttr(unsigned i, Attributes attr) const {
- if (AttributeList.paramHasAttr(i, attr))
+bool InvokeInst::fnHasNoAliasAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasNoAliasAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasNoAliasAttr();
+ return false;
+}
+bool InvokeInst::fnHasNoInlineAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasNoInlineAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasNoInlineAttr();
+ return false;
+}
+bool InvokeInst::fnHasNoReturnAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasNoReturnAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasNoReturnAttr();
+ return false;
+}
+bool InvokeInst::fnHasNoUnwindAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasNoUnwindAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasNoUnwindAttr();
+ return false;
+}
+bool InvokeInst::fnHasReadNoneAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasReadNoneAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasReadNoneAttr();
+ return false;
+}
+bool InvokeInst::fnHasReadOnlyAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasReadOnlyAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasReadOnlyAttr();
+ return false;
+}
+bool InvokeInst::fnHasReturnsTwiceAttr() const {
+ if (AttributeList.getParamAttributes(~0U).hasReturnsTwiceAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(~0U).hasReturnsTwiceAttr();
+ return false;
+}
+
+bool InvokeInst::paramHasSExtAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasSExtAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasSExtAttr();
+ return false;
+}
+
+bool InvokeInst::paramHasZExtAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasZExtAttr())
return true;
if (const Function *F = getCalledFunction())
- return F->paramHasAttr(i, attr);
+ return F->getParamAttributes(i).hasZExtAttr();
+ return false;
+}
+
+bool InvokeInst::paramHasInRegAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasInRegAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasInRegAttr();
+ return false;
+}
+
+bool InvokeInst::paramHasStructRetAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasStructRetAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasStructRetAttr();
+ return false;
+}
+
+bool InvokeInst::paramHasNestAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasNestAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasNestAttr();
+ return false;
+}
+
+bool InvokeInst::paramHasByValAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasByValAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasByValAttr();
+ return false;
+}
+
+bool InvokeInst::paramHasNoAliasAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasNoAliasAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasNoAliasAttr();
+ return false;
+}
+
+bool InvokeInst::paramHasNoCaptureAttr(unsigned i) const {
+ if (AttributeList.getParamAttributes(i).hasNoCaptureAttr())
+ return true;
+ if (const Function *F = getCalledFunction())
+ return F->getParamAttributes(i).hasNoCaptureAttr();
return false;
}
ReturnInst::~ReturnInst() {
}
-//===----------------------------------------------------------------------===//
-// UnwindInst Implementation
-//===----------------------------------------------------------------------===//
-
-UnwindInst::UnwindInst(LLVMContext &Context, Instruction *InsertBefore)
- : TerminatorInst(Type::getVoidTy(Context), Instruction::Unwind,
- 0, 0, InsertBefore) {
-}
-UnwindInst::UnwindInst(LLVMContext &Context, BasicBlock *InsertAtEnd)
- : TerminatorInst(Type::getVoidTy(Context), Instruction::Unwind,
- 0, 0, InsertAtEnd) {
-}
-
-
-unsigned UnwindInst::getNumSuccessorsV() const {
- return getNumSuccessors();
-}
-
-void UnwindInst::setSuccessorV(unsigned idx, BasicBlock *NewSucc) {
- llvm_unreachable("UnwindInst has no successors!");
-}
-
-BasicBlock *UnwindInst::getSuccessorV(unsigned idx) const {
- llvm_unreachable("UnwindInst has no successors!");
-}
-
//===----------------------------------------------------------------------===//
// ResumeInst Implementation
//===----------------------------------------------------------------------===//
}
void UnreachableInst::setSuccessorV(unsigned idx, BasicBlock *NewSucc) {
- llvm_unreachable("UnwindInst has no successors!");
+ llvm_unreachable("UnreachableInst has no successors!");
}
BasicBlock *UnreachableInst::getSuccessorV(unsigned idx) const {
- llvm_unreachable("UnwindInst has no successors!");
+ llvm_unreachable("UnreachableInst has no successors!");
}
//===----------------------------------------------------------------------===//
if (PointerType *PTy = dyn_cast<PointerType>(Ty))
return PTy->getAddressSpace();
- assert(false && "Invalid GEP pointer type");
- return 0;
+ llvm_unreachable("Invalid GEP pointer type");
}
/// hasAllZeroIndices - Return true if all of the indices of this GEP are
/// 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 ShuffleVectorInst::getMaskValue(unsigned i) const {
- assert(i < getType()->getNumElements() && "Index out of range");
- if (ConstantDataSequential *CDS =dyn_cast<ConstantDataSequential>(getMask()))
+int ShuffleVectorInst::getMaskValue(Constant *Mask, unsigned i) {
+ assert(i < Mask->getType()->getVectorNumElements() && "Index out of range");
+ if (ConstantDataSequential *CDS =dyn_cast<ConstantDataSequential>(Mask))
return CDS->getElementAsInteger(i);
- Constant *C = getMask()->getAggregateElement(i);
+ Constant *C = Mask->getAggregateElement(i);
if (isa<UndefValue>(C))
return -1;
return cast<ConstantInt>(C)->getZExtValue();
/// getShuffleMask - Return the full mask for this instruction, where each
/// element is the element number and undef's are returned as -1.
-void ShuffleVectorInst::getShuffleMask(SmallVectorImpl<int> &Result) const {
- unsigned NumElts = getType()->getNumElements();
+void ShuffleVectorInst::getShuffleMask(Constant *Mask,
+ SmallVectorImpl<int> &Result) {
+ unsigned NumElts = Mask->getType()->getVectorNumElements();
- if (ConstantDataSequential *CDS=dyn_cast<ConstantDataSequential>(getMask())) {
+ if (ConstantDataSequential *CDS=dyn_cast<ConstantDataSequential>(Mask)) {
for (unsigned i = 0; i != NumElts; ++i)
Result.push_back(CDS->getElementAsInteger(i));
return;
}
- Constant *Mask = getMask();
for (unsigned i = 0; i != NumElts; ++i) {
Constant *C = Mask->getAggregateElement(i);
Result.push_back(isa<UndefValue>(C) ? -1 :
// isConstantAllOnes - Helper function for several functions below
static inline bool isConstantAllOnes(const Value *V) {
- if (const ConstantInt *CI = dyn_cast<ConstantInt>(V))
- return CI->isAllOnesValue();
- if (const ConstantVector *CV = dyn_cast<ConstantVector>(V))
- return CV->isAllOnesValue();
+ if (const Constant *C = dyn_cast<Constant>(V))
+ return C->isAllOnesValue();
return false;
}
return cast<PossiblyExactOperator>(this)->isExact();
}
+//===----------------------------------------------------------------------===//
+// FPMathOperator Class
+//===----------------------------------------------------------------------===//
+
+/// getFPAccuracy - Get the maximum error permitted by this operation in ULPs.
+/// An accuracy of 0.0 means that the operation should be performed with the
+/// default precision.
+float FPMathOperator::getFPAccuracy() const {
+ const MDNode *MD =
+ cast<Instruction>(this)->getMetadata(LLVMContext::MD_fpmath);
+ if (!MD)
+ return 0.0;
+ ConstantFP *Accuracy = cast<ConstantFP>(MD->getOperand(0));
+ return Accuracy->getValueAPF().convertToFloat();
+}
+
+
//===----------------------------------------------------------------------===//
// CastInst Class
//===----------------------------------------------------------------------===//
Type *DestTy,
Type *IntPtrTy) {
switch (Opcode) {
- default:
- assert(0 && "Invalid CastOp");
+ default: llvm_unreachable("Invalid CastOp");
case Instruction::Trunc:
case Instruction::ZExt:
case Instruction::SExt:
case 99:
// cast combination can't happen (error in input). This is for all cases
// where the MidTy is not the same for the two cast instructions.
- assert(0 && "Invalid Cast Combination");
- return 0;
+ llvm_unreachable("Invalid Cast Combination");
default:
- assert(0 && "Error in CastResults table!!!");
- return 0;
+ llvm_unreachable("Error in CastResults table!!!");
}
}
case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertBefore);
case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertBefore);
case BitCast: return new BitCastInst (S, Ty, Name, InsertBefore);
- default:
- assert(0 && "Invalid opcode provided");
- return 0;
+ default: llvm_unreachable("Invalid opcode provided");
}
}
case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertAtEnd);
case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertAtEnd);
case BitCast: return new BitCastInst (S, Ty, Name, InsertAtEnd);
- default:
- assert(0 && "Invalid opcode provided");
- return 0;
+ default: llvm_unreachable("Invalid opcode provided");
}
}
assert(DestBits == SrcBits &&
"Casting vector to floating point of different width");
return BitCast; // same size, no-op cast
- } else {
- llvm_unreachable("Casting pointer or non-first class to float");
}
+ llvm_unreachable("Casting pointer or non-first class to float");
} else if (DestTy->isVectorTy()) {
assert(DestBits == SrcBits &&
"Illegal cast to vector (wrong type or size)");
return BitCast; // ptr -> ptr
} else if (SrcTy->isIntegerTy()) {
return IntToPtr; // int -> ptr
- } else {
- assert(0 && "Casting pointer to other than pointer or int");
}
+ llvm_unreachable("Casting pointer to other than pointer or int");
} else if (DestTy->isX86_MMXTy()) {
if (SrcTy->isVectorTy()) {
assert(DestBits == SrcBits && "Casting vector of wrong width to X86_MMX");
return BitCast; // 64-bit vector to MMX
- } else {
- assert(0 && "Illegal cast to X86_MMX");
}
- } else {
- assert(0 && "Casting to type that is not first-class");
+ llvm_unreachable("Illegal cast to X86_MMX");
}
-
- // If we fall through to here we probably hit an assertion cast above
- // and assertions are not turned on. Anything we return is an error, so
- // BitCast is as good a choice as any.
- return BitCast;
+ llvm_unreachable("Casting to type that is not first-class");
}
//===----------------------------------------------------------------------===//
// CmpInst Classes
//===----------------------------------------------------------------------===//
-void CmpInst::Anchor() const {}
+void CmpInst::anchor() {}
CmpInst::CmpInst(Type *ty, OtherOps op, unsigned short predicate,
Value *LHS, Value *RHS, const Twine &Name,
CmpInst::Predicate CmpInst::getInversePredicate(Predicate pred) {
switch (pred) {
- default: assert(0 && "Unknown cmp predicate!");
+ default: llvm_unreachable("Unknown cmp predicate!");
case ICMP_EQ: return ICMP_NE;
case ICMP_NE: return ICMP_EQ;
case ICMP_UGT: return ICMP_ULE;
ICmpInst::Predicate ICmpInst::getSignedPredicate(Predicate pred) {
switch (pred) {
- default: assert(0 && "Unknown icmp predicate!");
+ default: llvm_unreachable("Unknown icmp predicate!");
case ICMP_EQ: case ICMP_NE:
case ICMP_SGT: case ICMP_SLT: case ICMP_SGE: case ICMP_SLE:
return pred;
ICmpInst::Predicate ICmpInst::getUnsignedPredicate(Predicate pred) {
switch (pred) {
- default: assert(0 && "Unknown icmp predicate!");
+ default: llvm_unreachable("Unknown icmp predicate!");
case ICMP_EQ: case ICMP_NE:
case ICMP_UGT: case ICMP_ULT: case ICMP_UGE: case ICMP_ULE:
return pred;
CmpInst::Predicate CmpInst::getSwappedPredicate(Predicate pred) {
switch (pred) {
- default: assert(0 && "Unknown cmp predicate!");
+ default: llvm_unreachable("Unknown cmp predicate!");
case ICMP_EQ: case ICMP_NE:
return pred;
case ICMP_SGT: return ICMP_SLT;
OL[i] = InOL[i];
OL[i+1] = InOL[i+1];
}
+ TheSubsets = SI.TheSubsets;
SubclassOptionalData = SI.SubclassOptionalData;
}
/// addCase - Add an entry to the switch instruction...
///
void SwitchInst::addCase(ConstantInt *OnVal, BasicBlock *Dest) {
+ IntegersSubsetToBB Mapping;
+
+ // FIXME: Currently we work with ConstantInt based cases.
+ // So inititalize IntItem container directly from ConstantInt.
+ Mapping.add(IntItem::fromConstantInt(OnVal));
+ IntegersSubset CaseRanges = Mapping.getCase();
+ addCase(CaseRanges, Dest);
+}
+
+void SwitchInst::addCase(IntegersSubset& OnVal, BasicBlock *Dest) {
+ unsigned NewCaseIdx = getNumCases();
unsigned OpNo = NumOperands;
if (OpNo+2 > ReservedSpace)
growOperands(); // Get more space!
// Initialize some new operands.
assert(OpNo+1 < ReservedSpace && "Growing didn't work!");
NumOperands = OpNo+2;
- OperandList[OpNo] = OnVal;
- OperandList[OpNo+1] = Dest;
+
+ SubsetsIt TheSubsetsIt = TheSubsets.insert(TheSubsets.end(), OnVal);
+
+ CaseIt Case(this, NewCaseIdx, TheSubsetsIt);
+ Case.updateCaseValueOperand(OnVal);
+ Case.setSuccessor(Dest);
}
-/// removeCase - This method removes the specified successor from the switch
-/// instruction. Note that this cannot be used to remove the default
-/// destination (successor #0).
-///
-void SwitchInst::removeCase(unsigned idx) {
- assert(idx != 0 && "Cannot remove the default case!");
- assert(idx*2 < getNumOperands() && "Successor index out of range!!!");
+/// removeCase - This method removes the specified case and its successor
+/// from the switch instruction.
+void SwitchInst::removeCase(CaseIt& i) {
+ unsigned idx = i.getCaseIndex();
+
+ assert(2 + idx*2 < getNumOperands() && "Case index out of range!!!");
unsigned NumOps = getNumOperands();
Use *OL = OperandList;
// Overwrite this case with the end of the list.
- if ((idx + 1) * 2 != NumOps) {
- OL[idx * 2] = OL[NumOps - 2];
- OL[idx * 2 + 1] = OL[NumOps - 1];
+ if (2 + (idx + 1) * 2 != NumOps) {
+ OL[2 + idx * 2] = OL[NumOps - 2];
+ OL[2 + idx * 2 + 1] = OL[NumOps - 1];
}
// Nuke the last value.
OL[NumOps-2].set(0);
OL[NumOps-2+1].set(0);
+
+ // Do the same with TheCases collection:
+ if (i.SubsetIt != --TheSubsets.end()) {
+ *i.SubsetIt = TheSubsets.back();
+ TheSubsets.pop_back();
+ } else {
+ TheSubsets.pop_back();
+ i.SubsetIt = TheSubsets.end();
+ }
+
NumOperands = NumOps-2;
}
return new(1) ResumeInst(*this);
}
-UnwindInst *UnwindInst::clone_impl() const {
- LLVMContext &Context = getContext();
- return new UnwindInst(Context);
-}
-
UnreachableInst *UnreachableInst::clone_impl() const {
LLVMContext &Context = getContext();
return new UnreachableInst(Context);