#include "llvm/Support/CallSite.h"
#include "llvm/Support/ConstantRange.h"
#include "llvm/Support/MathExtras.h"
-#include "llvm/Target/TargetData.h"
-
using namespace llvm;
//===----------------------------------------------------------------------===//
OperandTraits<CallInst>::op_end(this) - CI.getNumOperands(),
CI.getNumOperands()) {
setAttributes(CI.getAttributes());
- SubclassData = CI.SubclassData;
+ setTailCall(CI.isTailCall());
+ setCallingConv(CI.getCallingConv());
+
Use *OL = OperandList;
Use *InOL = CI.OperandList;
for (unsigned i = 0, e = CI.getNumOperands(); i != e; ++i)
BasicBlock* BB = InsertBefore ? InsertBefore->getParent() : InsertAtEnd;
Module* M = BB->getParent()->getParent();
const Type *BPTy = Type::getInt8PtrTy(BB->getContext());
- if (!MallocF)
+ Value *MallocFunc = MallocF;
+ if (!MallocFunc)
// prototype malloc as "void *malloc(size_t)"
- MallocF = cast<Function>(M->getOrInsertFunction("malloc", BPTy,
- IntPtrTy, NULL));
- if (!MallocF->doesNotAlias(0)) MallocF->setDoesNotAlias(0);
+ MallocFunc = M->getOrInsertFunction("malloc", BPTy, IntPtrTy, NULL);
const PointerType *AllocPtrType = PointerType::getUnqual(AllocTy);
CallInst *MCall = NULL;
Instruction *Result = NULL;
if (InsertBefore) {
- MCall = CallInst::Create(MallocF, AllocSize, "malloccall", InsertBefore);
+ MCall = CallInst::Create(MallocFunc, AllocSize, "malloccall", InsertBefore);
Result = MCall;
if (Result->getType() != AllocPtrType)
// Create a cast instruction to convert to the right type...
Result = new BitCastInst(MCall, AllocPtrType, Name, InsertBefore);
} else {
- MCall = CallInst::Create(MallocF, AllocSize, "malloccall");
+ MCall = CallInst::Create(MallocFunc, AllocSize, "malloccall");
Result = MCall;
if (Result->getType() != AllocPtrType) {
InsertAtEnd->getInstList().push_back(MCall);
}
}
MCall->setTailCall();
- MCall->setCallingConv(MallocF->getCallingConv());
- assert(MCall->getType() != Type::getVoidTy(BB->getContext()) &&
- "Malloc has void return type");
+ if (Function *F = dyn_cast<Function>(MallocFunc)) {
+ MCall->setCallingConv(F->getCallingConv());
+ if (!F->doesNotAlias(0)) F->setDoesNotAlias(0);
+ }
+ assert(!MCall->getType()->isVoidTy() && "Malloc has void return type");
return Result;
}
const Type *VoidTy = Type::getVoidTy(M->getContext());
const Type *IntPtrTy = Type::getInt8PtrTy(M->getContext());
// prototype free as "void free(void*)"
- Function *FreeFunc = cast<Function>(M->getOrInsertFunction("free", VoidTy,
- IntPtrTy, NULL));
+ Value *FreeFunc = M->getOrInsertFunction("free", VoidTy, IntPtrTy, NULL);
CallInst* Result = NULL;
Value *PtrCast = Source;
if (InsertBefore) {
Result = CallInst::Create(FreeFunc, PtrCast, "");
}
Result->setTailCall();
- Result->setCallingConv(FreeFunc->getCallingConv());
+ if (Function *F = dyn_cast<Function>(FreeFunc))
+ Result->setCallingConv(F->getCallingConv());
return Result;
}
- II.getNumOperands(),
II.getNumOperands()) {
setAttributes(II.getAttributes());
- SubclassData = II.SubclassData;
+ setCallingConv(II.getCallingConv());
Use *OL = OperandList, *InOL = II.OperandList;
for (unsigned i = 0, e = II.getNumOperands(); i != e; ++i)
OL[i] = InOL[i];
void BranchInst::AssertOK() {
if (isConditional())
- assert(getCondition()->getType() == Type::getInt1Ty(getContext()) &&
+ assert(getCondition()->getType()->isInteger(1) &&
"May only branch on boolean predicates!");
}
else {
assert(!isa<BasicBlock>(Amt) &&
"Passed basic block into allocation size parameter! Use other ctor");
- assert(Amt->getType() == Type::getInt32Ty(Context) &&
+ assert(Amt->getType()->isInteger(32) &&
"Allocation array size is not a 32-bit integer!");
}
return Amt;
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertBefore) {
setAlignment(0);
- assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
+ assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertAtEnd) {
setAlignment(0);
- assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
+ assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), 0), InsertBefore) {
setAlignment(0);
- assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
+ assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), 0), InsertAtEnd) {
setAlignment(0);
- assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
+ assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertBefore) {
setAlignment(Align);
- assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
+ assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
: UnaryInstruction(PointerType::getUnqual(Ty), Alloca,
getAISize(Ty->getContext(), ArraySize), InsertAtEnd) {
setAlignment(Align);
- assert(Ty != Type::getVoidTy(Ty->getContext()) && "Cannot allocate void!");
+ assert(!Ty->isVoidTy() && "Cannot allocate void!");
setName(Name);
}
void AllocaInst::setAlignment(unsigned Align) {
assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
- SubclassData = Log2_32(Align) + 1;
+ setInstructionSubclassData(Log2_32(Align) + 1);
assert(getAlignment() == Align && "Alignment representation error!");
}
void LoadInst::setAlignment(unsigned Align) {
assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
- SubclassData = (SubclassData & 1) | ((Log2_32(Align)+1)<<1);
+ setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
+ ((Log2_32(Align)+1)<<1));
}
//===----------------------------------------------------------------------===//
void StoreInst::setAlignment(unsigned Align) {
assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
- SubclassData = (SubclassData & 1) | ((Log2_32(Align)+1)<<1);
+ setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
+ ((Log2_32(Align)+1) << 1));
}
//===----------------------------------------------------------------------===//
bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
- if (!isa<VectorType>(Val->getType()) ||
- Index->getType() != Type::getInt32Ty(Val->getContext()))
+ if (!isa<VectorType>(Val->getType()) || !Index->getType()->isInteger(32))
return false;
return true;
}
if (Elt->getType() != cast<VectorType>(Vec->getType())->getElementType())
return false;// Second operand of insertelement must be vector element type.
- if (Index->getType() != Type::getInt32Ty(Vec->getContext()))
+ if (!Index->getType()->isInteger(32))
return false; // Third operand of insertelement must be i32.
return true;
}
const VectorType *MaskTy = dyn_cast<VectorType>(Mask->getType());
if (!isa<Constant>(Mask) || MaskTy == 0 ||
- MaskTy->getElementType() != Type::getInt32Ty(V1->getContext()))
+ !MaskTy->getElementType()->isInteger(32))
return false;
return true;
}
Op->getType(), Name, InsertAtEnd);
}
+BinaryOperator *BinaryOperator::CreateNSWNeg(Value *Op, const Twine &Name,
+ Instruction *InsertBefore) {
+ Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
+ return BinaryOperator::CreateNSWSub(zero, Op, Name, InsertBefore);
+}
+
+BinaryOperator *BinaryOperator::CreateNSWNeg(Value *Op, const Twine &Name,
+ BasicBlock *InsertAtEnd) {
+ Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
+ return BinaryOperator::CreateNSWSub(zero, Op, Name, InsertAtEnd);
+}
+
BinaryOperator *BinaryOperator::CreateFNeg(Value *Op, const Twine &Name,
Instruction *InsertBefore) {
Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
return secondOp;
case 3:
// no-op cast in second op implies firstOp as long as the DestTy
- // is integer
- if (DstTy->isInteger())
+ // is integer and we are not converting between a vector and a
+ // non vector type.
+ if (!isa<VectorType>(SrcTy) && DstTy->isInteger())
return firstOp;
return 0;
case 4:
// no-op cast in second op implies firstOp as long as the DestTy
- // is floating point
+ // is floating point.
if (DstTy->isFloatingPoint())
return firstOp;
return 0;
case 5:
// no-op cast in first op implies secondOp as long as the SrcTy
- // is an integer
+ // is an integer.
if (SrcTy->isInteger())
return secondOp;
return 0;
case 6:
// no-op cast in first op implies secondOp as long as the SrcTy
- // is a floating point
+ // is a floating point.
if (SrcTy->isFloatingPoint())
return secondOp;
return 0;
CastInst *CastInst::CreateIntegerCast(Value *C, const Type *Ty,
bool isSigned, const Twine &Name,
Instruction *InsertBefore) {
- assert(C->getType()->isInteger() && Ty->isInteger() && "Invalid cast");
+ assert(C->getType()->isIntOrIntVector() && Ty->isIntOrIntVector() &&
+ "Invalid integer cast");
unsigned SrcBits = C->getType()->getScalarSizeInBits();
unsigned DstBits = Ty->getScalarSizeInBits();
Instruction::CastOps opcode =
// Check for type sanity on the arguments
const Type *SrcTy = S->getType();
- if (!SrcTy->isFirstClassType() || !DstTy->isFirstClassType())
+ if (!SrcTy->isFirstClassType() || !DstTy->isFirstClassType() ||
+ SrcTy->isAggregateType() || DstTy->isAggregateType())
return false;
// Get the size of the types in bits, we'll need this later
// CmpInst Classes
//===----------------------------------------------------------------------===//
+void CmpInst::Anchor() const {}
+
CmpInst::CmpInst(const Type *ty, OtherOps op, unsigned short predicate,
Value *LHS, Value *RHS, const Twine &Name,
Instruction *InsertBefore)
InsertBefore) {
Op<0>() = LHS;
Op<1>() = RHS;
- SubclassData = predicate;
+ setPredicate((Predicate)predicate);
setName(Name);
}
InsertAtEnd) {
Op<0>() = LHS;
Op<1>() = RHS;
- SubclassData = predicate;
+ setPredicate((Predicate)predicate);
setName(Name);
}
default: llvm_unreachable("Invalid ICmp opcode to ConstantRange ctor!");
case ICmpInst::ICMP_EQ: Upper++; break;
case ICmpInst::ICMP_NE: Lower++; break;
- case ICmpInst::ICMP_ULT: Lower = APInt::getMinValue(BitWidth); break;
- case ICmpInst::ICMP_SLT: Lower = APInt::getSignedMinValue(BitWidth); break;
+ case ICmpInst::ICMP_ULT:
+ Lower = APInt::getMinValue(BitWidth);
+ // Check for an empty-set condition.
+ if (Lower == Upper)
+ return ConstantRange(BitWidth, /*isFullSet=*/false);
+ break;
+ case ICmpInst::ICMP_SLT:
+ Lower = APInt::getSignedMinValue(BitWidth);
+ // Check for an empty-set condition.
+ if (Lower == Upper)
+ return ConstantRange(BitWidth, /*isFullSet=*/false);
+ break;
case ICmpInst::ICMP_UGT:
Lower++; Upper = APInt::getMinValue(BitWidth); // Min = Next(Max)
+ // Check for an empty-set condition.
+ if (Lower == Upper)
+ return ConstantRange(BitWidth, /*isFullSet=*/false);
break;
case ICmpInst::ICMP_SGT:
Lower++; Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max)
+ // Check for an empty-set condition.
+ if (Lower == Upper)
+ return ConstantRange(BitWidth, /*isFullSet=*/false);
break;
case ICmpInst::ICMP_ULE:
Lower = APInt::getMinValue(BitWidth); Upper++;
+ // Check for a full-set condition.
+ if (Lower == Upper)
+ return ConstantRange(BitWidth, /*isFullSet=*/true);
break;
case ICmpInst::ICMP_SLE:
Lower = APInt::getSignedMinValue(BitWidth); Upper++;
+ // Check for a full-set condition.
+ if (Lower == Upper)
+ return ConstantRange(BitWidth, /*isFullSet=*/true);
break;
case ICmpInst::ICMP_UGE:
Upper = APInt::getMinValue(BitWidth); // Min = Next(Max)
+ // Check for a full-set condition.
+ if (Lower == Upper)
+ return ConstantRange(BitWidth, /*isFullSet=*/true);
break;
case ICmpInst::ICMP_SGE:
Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max)
+ // Check for a full-set condition.
+ if (Lower == Upper)
+ return ConstantRange(BitWidth, /*isFullSet=*/true);
break;
}
return ConstantRange(Lower, Upper);