mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
Revert the ConstantInt constructors back to their 2.5 forms where possible, thanks to contexts-on-types. More to come.
llvm-svn: 77011
This commit is contained in:
parent
06b94defcb
commit
cc33e89571
@ -77,16 +77,16 @@ void BrainF::header(LLVMContext& C) {
|
||||
builder = new IRBuilder<>(BasicBlock::Create(label, brainf_func));
|
||||
|
||||
//%arr = malloc i8, i32 %d
|
||||
ConstantInt *val_mem = C.getConstantInt(APInt(32, memtotal));
|
||||
ConstantInt *val_mem = ConstantInt::get(C, APInt(32, memtotal));
|
||||
ptr_arr = builder->CreateMalloc(IntegerType::Int8Ty, val_mem, "arr");
|
||||
|
||||
//call void @llvm.memset.i32(i8 *%arr, i8 0, i32 %d, i32 1)
|
||||
{
|
||||
Value *memset_params[] = {
|
||||
ptr_arr,
|
||||
C.getConstantInt(APInt(8, 0)),
|
||||
ConstantInt::get(C, APInt(8, 0)),
|
||||
val_mem,
|
||||
C.getConstantInt(APInt(32, 1))
|
||||
ConstantInt::get(C, APInt(32, 1))
|
||||
};
|
||||
|
||||
CallInst *memset_call = builder->
|
||||
@ -97,12 +97,12 @@ void BrainF::header(LLVMContext& C) {
|
||||
//%arrmax = getelementptr i8 *%arr, i32 %d
|
||||
if (comflag & flag_arraybounds) {
|
||||
ptr_arrmax = builder->
|
||||
CreateGEP(ptr_arr, C.getConstantInt(APInt(32, memtotal)), "arrmax");
|
||||
CreateGEP(ptr_arr, ConstantInt::get(C, APInt(32, memtotal)), "arrmax");
|
||||
}
|
||||
|
||||
//%head.%d = getelementptr i8 *%arr, i32 %d
|
||||
curhead = builder->CreateGEP(ptr_arr,
|
||||
C.getConstantInt(APInt(32, memtotal/2)),
|
||||
ConstantInt::get(C, APInt(32, memtotal/2)),
|
||||
headreg);
|
||||
|
||||
|
||||
@ -229,7 +229,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
|
||||
{
|
||||
//%head.%d = getelementptr i8 *%head.%d, i32 %d
|
||||
curhead = builder->
|
||||
CreateGEP(curhead, C.getConstantInt(APInt(32, curvalue)),
|
||||
CreateGEP(curhead, ConstantInt::get(C, APInt(32, curvalue)),
|
||||
headreg);
|
||||
|
||||
//Error block for array out of bounds
|
||||
@ -264,7 +264,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
|
||||
|
||||
//%tape.%d = add i8 %tape.%d, %d
|
||||
Value *tape_1 = builder->
|
||||
CreateAdd(tape_0, C.getConstantInt(APInt(8, curvalue)), tapereg);
|
||||
CreateAdd(tape_0, ConstantInt::get(C, APInt(8, curvalue)), tapereg);
|
||||
|
||||
//store i8 %tape.%d, i8 *%head.%d\n"
|
||||
builder->CreateStore(tape_1, curhead);
|
||||
@ -429,7 +429,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb,
|
||||
|
||||
//%test.%d = icmp eq i8 %tape.%d, 0
|
||||
ICmpInst *test_0 = new ICmpInst(*testbb, ICmpInst::ICMP_EQ, tape_0,
|
||||
C.getConstantInt(APInt(8, 0)), testreg);
|
||||
ConstantInt::get(C, APInt(8, 0)), testreg);
|
||||
|
||||
//br i1 %test.%d, label %main.%d, label %main.%d
|
||||
BasicBlock *bb_0 = BasicBlock::Create(label, brainf_func);
|
||||
|
@ -80,7 +80,7 @@ void addMainFunction(Module *mod) {
|
||||
}
|
||||
|
||||
//ret i32 0
|
||||
ReturnInst::Create(getGlobalContext().getConstantInt(APInt(32, 0)), bb);
|
||||
ReturnInst::Create(ConstantInt::get(getGlobalContext(), APInt(32, 0)), bb);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
@ -47,8 +47,8 @@ static Function *CreateFibFunction(Module *M, LLVMContext &Context) {
|
||||
BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF);
|
||||
|
||||
// Get pointers to the constants.
|
||||
Value *One = Context.getConstantInt(Type::Int32Ty, 1);
|
||||
Value *Two = Context.getConstantInt(Type::Int32Ty, 2);
|
||||
Value *One = ConstantInt::get(Type::Int32Ty, 1);
|
||||
Value *Two = ConstantInt::get(Type::Int32Ty, 2);
|
||||
|
||||
// Get pointer to the integer argument of the add1 function...
|
||||
Argument *ArgX = FibF->arg_begin(); // Get the arg.
|
||||
|
@ -69,7 +69,7 @@ int main() {
|
||||
BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F);
|
||||
|
||||
// Get pointers to the constant `1'.
|
||||
Value *One = Context.getConstantInt(Type::Int32Ty, 1);
|
||||
Value *One = ConstantInt::get(Type::Int32Ty, 1);
|
||||
|
||||
// Get pointers to the integer argument of the add1 function...
|
||||
assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg
|
||||
@ -94,7 +94,7 @@ int main() {
|
||||
BB = BasicBlock::Create("EntryBlock", FooF);
|
||||
|
||||
// Get pointers to the constant `10'.
|
||||
Value *Ten = Context.getConstantInt(Type::Int32Ty, 10);
|
||||
Value *Ten = ConstantInt::get(Type::Int32Ty, 10);
|
||||
|
||||
// Pass Ten to the call call:
|
||||
CallInst *Add1CallRes = CallInst::Create(Add1F, Ten, "add1", BB);
|
||||
|
@ -42,8 +42,8 @@ int main() {
|
||||
BasicBlock *BB = BasicBlock::Create("EntryBlock", F);
|
||||
|
||||
// Get pointers to the constant integers...
|
||||
Value *Two = Context.getConstantInt(Type::Int32Ty, 2);
|
||||
Value *Three = Context.getConstantInt(Type::Int32Ty, 3);
|
||||
Value *Two = ConstantInt::get(Type::Int32Ty, 2);
|
||||
Value *Three = ConstantInt::get(Type::Int32Ty, 3);
|
||||
|
||||
// Create the add instruction... does not insert...
|
||||
Instruction *Add = BinaryOperator::Create(Instruction::Add, Two, Three,
|
||||
|
@ -44,7 +44,7 @@ static Function* createAdd1(Module *M) {
|
||||
BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F);
|
||||
|
||||
// Get pointers to the constant `1'.
|
||||
Value *One = M->getContext().getConstantInt(Type::Int32Ty, 1);
|
||||
Value *One = ConstantInt::get(Type::Int32Ty, 1);
|
||||
|
||||
// Get pointers to the integer argument of the add1 function...
|
||||
assert(Add1F->arg_begin() != Add1F->arg_end()); // Make sure there's an arg
|
||||
@ -72,8 +72,8 @@ static Function *CreateFibFunction(Module *M) {
|
||||
BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF);
|
||||
|
||||
// Get pointers to the constants.
|
||||
Value *One = M->getContext().getConstantInt(Type::Int32Ty, 1);
|
||||
Value *Two = M->getContext().getConstantInt(Type::Int32Ty, 2);
|
||||
Value *One = ConstantInt::get(Type::Int32Ty, 1);
|
||||
Value *Two = ConstantInt::get(Type::Int32Ty, 2);
|
||||
|
||||
// Get pointer to the integer argument of the add1 function...
|
||||
Argument *ArgX = FibF->arg_begin(); // Get the arg.
|
||||
|
@ -57,6 +57,35 @@ protected:
|
||||
return User::operator new(s, 0);
|
||||
}
|
||||
public:
|
||||
/// If Ty is a vector type, return a Constant with a splat of the given
|
||||
/// value. Otherwise return a ConstantInt for the given value.
|
||||
static Constant* get(const Type* Ty, uint64_t V, bool isSigned = false);
|
||||
|
||||
/// Return a ConstantInt with the specified integer value for the specified
|
||||
/// type. If the type is wider than 64 bits, the value will be zero-extended
|
||||
/// to fit the type, unless isSigned is true, in which case the value will
|
||||
/// be interpreted as a 64-bit signed integer and sign-extended to fit
|
||||
/// the type.
|
||||
/// @brief Get a ConstantInt for a specific value.
|
||||
static ConstantInt* get(const IntegerType* Ty, uint64_t V,
|
||||
bool isSigned = false);
|
||||
|
||||
/// Return a ConstantInt with the specified value for the specified type. The
|
||||
/// value V will be canonicalized to a an unsigned APInt. Accessing it with
|
||||
/// either getSExtValue() or getZExtValue() will yield a correctly sized and
|
||||
/// signed value for the type Ty.
|
||||
/// @brief Get a ConstantInt for a specific signed value.
|
||||
static ConstantInt* getSigned(const IntegerType* Ty, int64_t V);
|
||||
static Constant *getSigned(const Type *Ty, int64_t V);
|
||||
|
||||
/// Return a ConstantInt with the specified value and an implied Type. The
|
||||
/// type is the integer type that corresponds to the bit width of the value.
|
||||
static ConstantInt* get(LLVMContext &Context, const APInt& V);
|
||||
|
||||
/// If Ty is a vector type, return a Constant with a splat of the given
|
||||
/// value. Otherwise return a ConstantInt for the given value.
|
||||
static Constant* get(const Type* Ty, const APInt& V);
|
||||
|
||||
/// Return the constant as an APInt value reference. This allows clients to
|
||||
/// obtain a copy of the value, with all its precision in tact.
|
||||
/// @brief Return the constant's value.
|
||||
|
@ -53,6 +53,8 @@ class Use;
|
||||
/// to have one context per thread.
|
||||
class LLVMContext {
|
||||
LLVMContextImpl* pImpl;
|
||||
|
||||
friend class ConstantInt;
|
||||
public:
|
||||
LLVMContext();
|
||||
~LLVMContext();
|
||||
@ -72,36 +74,6 @@ public:
|
||||
ConstantInt* getTrue();
|
||||
ConstantInt* getFalse();
|
||||
|
||||
/// If Ty is a vector type, return a Constant with a splat of the given
|
||||
/// value. Otherwise return a ConstantInt for the given value.
|
||||
Constant* getConstantInt(const Type* Ty, uint64_t V,
|
||||
bool isSigned = false);
|
||||
|
||||
/// Return a ConstantInt with the specified integer value for the specified
|
||||
/// type. If the type is wider than 64 bits, the value will be zero-extended
|
||||
/// to fit the type, unless isSigned is true, in which case the value will
|
||||
/// be interpreted as a 64-bit signed integer and sign-extended to fit
|
||||
/// the type.
|
||||
/// @brief Get a ConstantInt for a specific value.
|
||||
ConstantInt* getConstantInt(const IntegerType* Ty, uint64_t V,
|
||||
bool isSigned = false);
|
||||
|
||||
/// Return a ConstantInt with the specified value for the specified type. The
|
||||
/// value V will be canonicalized to a an unsigned APInt. Accessing it with
|
||||
/// either getSExtValue() or getZExtValue() will yield a correctly sized and
|
||||
/// signed value for the type Ty.
|
||||
/// @brief Get a ConstantInt for a specific signed value.
|
||||
ConstantInt* getConstantIntSigned(const IntegerType* Ty, int64_t V);
|
||||
Constant *getConstantIntSigned(const Type *Ty, int64_t V);
|
||||
|
||||
/// Return a ConstantInt with the specified value and an implied Type. The
|
||||
/// type is the integer type that corresponds to the bit width of the value.
|
||||
ConstantInt* getConstantInt(const APInt& V);
|
||||
|
||||
/// If Ty is a vector type, return a Constant with a splat of the given
|
||||
/// value. Otherwise return a ConstantInt for the given value.
|
||||
Constant* getConstantInt(const Type* Ty, const APInt& V);
|
||||
|
||||
// ConstantPointerNull accessors
|
||||
ConstantPointerNull* getConstantPointerNull(const PointerType* T);
|
||||
|
||||
|
@ -370,7 +370,7 @@ public:
|
||||
return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
|
||||
}
|
||||
Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const char *Name = "") {
|
||||
Value *Idx = Context.getConstantInt(Type::Int32Ty, Idx0);
|
||||
Value *Idx = ConstantInt::get(Type::Int32Ty, Idx0);
|
||||
|
||||
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
||||
return Folder.CreateGetElementPtr(PC, &Idx, 1);
|
||||
@ -380,8 +380,8 @@ public:
|
||||
Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
|
||||
const char *Name = "") {
|
||||
Value *Idxs[] = {
|
||||
Context.getConstantInt(Type::Int32Ty, Idx0),
|
||||
Context.getConstantInt(Type::Int32Ty, Idx1)
|
||||
ConstantInt::get(Type::Int32Ty, Idx0),
|
||||
ConstantInt::get(Type::Int32Ty, Idx1)
|
||||
};
|
||||
|
||||
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
||||
@ -390,7 +390,7 @@ public:
|
||||
return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
|
||||
}
|
||||
Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const char *Name = "") {
|
||||
Value *Idx = Context.getConstantInt(Type::Int64Ty, Idx0);
|
||||
Value *Idx = ConstantInt::get(Type::Int64Ty, Idx0);
|
||||
|
||||
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
||||
return Folder.CreateGetElementPtr(PC, &Idx, 1);
|
||||
@ -400,8 +400,8 @@ public:
|
||||
Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
|
||||
const char *Name = "") {
|
||||
Value *Idxs[] = {
|
||||
Context.getConstantInt(Type::Int64Ty, Idx0),
|
||||
Context.getConstantInt(Type::Int64Ty, Idx1)
|
||||
ConstantInt::get(Type::Int64Ty, Idx0),
|
||||
ConstantInt::get(Type::Int64Ty, Idx1)
|
||||
};
|
||||
|
||||
if (Constant *PC = dyn_cast<Constant>(Ptr))
|
||||
@ -428,7 +428,7 @@ public:
|
||||
}
|
||||
Value *CreateGlobalStringPtr(const char *Str = "", const char *Name = "") {
|
||||
Value *gv = CreateGlobalString(Str, Name);
|
||||
Value *zero = Context.getConstantInt(Type::Int32Ty, 0);
|
||||
Value *zero = ConstantInt::get(Type::Int32Ty, 0);
|
||||
Value *Args[] = { zero, zero };
|
||||
return CreateGEP(gv, Args, Args+2, Name);
|
||||
}
|
||||
|
@ -780,10 +780,10 @@ BasicAliasAnalysis::CheckGEPInstructions(
|
||||
//
|
||||
if (const ArrayType *AT = dyn_cast<ArrayType>(BasePtr1Ty))
|
||||
GEP1Ops[i] =
|
||||
Context.getConstantInt(Type::Int64Ty,AT->getNumElements()-1);
|
||||
ConstantInt::get(Type::Int64Ty,AT->getNumElements()-1);
|
||||
else if (const VectorType *VT = dyn_cast<VectorType>(BasePtr1Ty))
|
||||
GEP1Ops[i] =
|
||||
Context.getConstantInt(Type::Int64Ty,VT->getNumElements()-1);
|
||||
ConstantInt::get(Type::Int64Ty,VT->getNumElements()-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ static Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0,
|
||||
if (IsConstantOffsetFromGlobal(Op1, GV2, Offs2, *TD) &&
|
||||
GV1 == GV2) {
|
||||
// (&GV+C1) - (&GV+C2) -> C1-C2, pointer arithmetic cannot overflow.
|
||||
return Context.getConstantInt(Op0->getType(), Offs1-Offs2);
|
||||
return ConstantInt::get(Op0->getType(), Offs1-Offs2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ static Constant *SymbolicallyEvaluateGEP(Constant* const* Ops, unsigned NumOps,
|
||||
|
||||
uint64_t Offset = TD->getIndexedOffset(Ptr->getType(),
|
||||
(Value**)Ops+1, NumOps-1);
|
||||
Constant *C = Context.getConstantInt(TD->getIntPtrType(), Offset+BasePtr);
|
||||
Constant *C = ConstantInt::get(TD->getIntPtrType(), Offset+BasePtr);
|
||||
return Context.getConstantExprIntToPtr(C, ResultTy);
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ static Constant *FoldBitCast(Constant *C, const Type *DestTy,
|
||||
|
||||
// Shift it to the right place, depending on endianness.
|
||||
Src = Context.getConstantExprShl(Src,
|
||||
Context.getConstantInt(Src->getType(), ShiftAmt));
|
||||
ConstantInt::get(Src->getType(), ShiftAmt));
|
||||
ShiftAmt += isLittleEndian ? SrcBitSize : -SrcBitSize;
|
||||
|
||||
// Mix it in.
|
||||
@ -255,7 +255,7 @@ static Constant *FoldBitCast(Constant *C, const Type *DestTy,
|
||||
// Shift the piece of the value into the right place, depending on
|
||||
// endianness.
|
||||
Constant *Elt = Context.getConstantExprLShr(Src,
|
||||
Context.getConstantInt(Src->getType(), ShiftAmt));
|
||||
ConstantInt::get(Src->getType(), ShiftAmt));
|
||||
ShiftAmt += isLittleEndian ? DstBitSize : -DstBitSize;
|
||||
|
||||
// Truncate and remember this piece.
|
||||
@ -376,7 +376,7 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
|
||||
unsigned InWidth = Input->getType()->getScalarSizeInBits();
|
||||
if (TD->getPointerSizeInBits() < InWidth) {
|
||||
Constant *Mask =
|
||||
Context.getConstantInt(APInt::getLowBitsSet(InWidth,
|
||||
ConstantInt::get(Context, APInt::getLowBitsSet(InWidth,
|
||||
TD->getPointerSizeInBits()));
|
||||
Input = Context.getConstantExprAnd(Input, Mask);
|
||||
}
|
||||
@ -420,7 +420,7 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
|
||||
AT->getNumElements()))) {
|
||||
Constant *Index[] = {
|
||||
Context.getNullValue(CE->getType()),
|
||||
Context.getConstantInt(ElemIdx)
|
||||
ConstantInt::get(Context, ElemIdx)
|
||||
};
|
||||
return
|
||||
Context.getConstantExprGetElementPtr(GV, &Index[0], 2);
|
||||
@ -801,13 +801,13 @@ llvm::ConstantFoldCall(Function *F,
|
||||
}
|
||||
} else if (ConstantInt *Op = dyn_cast<ConstantInt>(Operands[0])) {
|
||||
if (Len > 11 && !memcmp(Str, "llvm.bswap", 10))
|
||||
return Context.getConstantInt(Op->getValue().byteSwap());
|
||||
return ConstantInt::get(Context, Op->getValue().byteSwap());
|
||||
else if (Len > 11 && !memcmp(Str, "llvm.ctpop", 10))
|
||||
return Context.getConstantInt(Ty, Op->getValue().countPopulation());
|
||||
return ConstantInt::get(Ty, Op->getValue().countPopulation());
|
||||
else if (Len > 10 && !memcmp(Str, "llvm.cttz", 9))
|
||||
return Context.getConstantInt(Ty, Op->getValue().countTrailingZeros());
|
||||
return ConstantInt::get(Ty, Op->getValue().countTrailingZeros());
|
||||
else if (Len > 10 && !memcmp(Str, "llvm.ctlz", 9))
|
||||
return Context.getConstantInt(Ty, Op->getValue().countLeadingZeros());
|
||||
return ConstantInt::get(Ty, Op->getValue().countLeadingZeros());
|
||||
}
|
||||
} else if (NumOperands == 2) {
|
||||
if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
|
||||
|
@ -482,7 +482,7 @@ Constant *DIFactory::getCastToEmpty(DIDescriptor D) {
|
||||
Constant *DIFactory::GetTagConstant(unsigned TAG) {
|
||||
assert((TAG & LLVMDebugVersionMask) == 0 &&
|
||||
"Tag too large for debug encoding!");
|
||||
return VMContext.getConstantInt(Type::Int32Ty, TAG | LLVMDebugVersion);
|
||||
return ConstantInt::get(Type::Int32Ty, TAG | LLVMDebugVersion);
|
||||
}
|
||||
|
||||
Constant *DIFactory::GetStringConstant(const std::string &String) {
|
||||
@ -541,8 +541,8 @@ DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
|
||||
DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
|
||||
Constant *Elts[] = {
|
||||
GetTagConstant(dwarf::DW_TAG_subrange_type),
|
||||
VMContext.getConstantInt(Type::Int64Ty, Lo),
|
||||
VMContext.getConstantInt(Type::Int64Ty, Hi)
|
||||
ConstantInt::get(Type::Int64Ty, Lo),
|
||||
ConstantInt::get(Type::Int64Ty, Hi)
|
||||
};
|
||||
|
||||
Constant *Init = VMContext.getConstantStruct(Elts,
|
||||
@ -577,14 +577,14 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
|
||||
Constant *Elts[] = {
|
||||
GetTagConstant(dwarf::DW_TAG_compile_unit),
|
||||
VMContext.getNullValue(EmptyStructPtr),
|
||||
VMContext.getConstantInt(Type::Int32Ty, LangID),
|
||||
ConstantInt::get(Type::Int32Ty, LangID),
|
||||
GetStringConstant(Filename),
|
||||
GetStringConstant(Directory),
|
||||
GetStringConstant(Producer),
|
||||
VMContext.getConstantInt(Type::Int1Ty, isMain),
|
||||
VMContext.getConstantInt(Type::Int1Ty, isOptimized),
|
||||
ConstantInt::get(Type::Int1Ty, isMain),
|
||||
ConstantInt::get(Type::Int1Ty, isOptimized),
|
||||
GetStringConstant(Flags),
|
||||
VMContext.getConstantInt(Type::Int32Ty, RunTimeVer)
|
||||
ConstantInt::get(Type::Int32Ty, RunTimeVer)
|
||||
};
|
||||
|
||||
Constant *Init = VMContext.getConstantStruct(Elts,
|
||||
@ -603,7 +603,7 @@ DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
|
||||
Constant *Elts[] = {
|
||||
GetTagConstant(dwarf::DW_TAG_enumerator),
|
||||
GetStringConstant(Name),
|
||||
VMContext.getConstantInt(Type::Int64Ty, Val)
|
||||
ConstantInt::get(Type::Int64Ty, Val)
|
||||
};
|
||||
|
||||
Constant *Init = VMContext.getConstantStruct(Elts,
|
||||
@ -632,12 +632,12 @@ DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
|
||||
getCastToEmpty(Context),
|
||||
GetStringConstant(Name),
|
||||
getCastToEmpty(CompileUnit),
|
||||
VMContext.getConstantInt(Type::Int32Ty, LineNumber),
|
||||
VMContext.getConstantInt(Type::Int64Ty, SizeInBits),
|
||||
VMContext.getConstantInt(Type::Int64Ty, AlignInBits),
|
||||
VMContext.getConstantInt(Type::Int64Ty, OffsetInBits),
|
||||
VMContext.getConstantInt(Type::Int32Ty, Flags),
|
||||
VMContext.getConstantInt(Type::Int32Ty, Encoding)
|
||||
ConstantInt::get(Type::Int32Ty, LineNumber),
|
||||
ConstantInt::get(Type::Int64Ty, SizeInBits),
|
||||
ConstantInt::get(Type::Int64Ty, AlignInBits),
|
||||
ConstantInt::get(Type::Int64Ty, OffsetInBits),
|
||||
ConstantInt::get(Type::Int32Ty, Flags),
|
||||
ConstantInt::get(Type::Int32Ty, Encoding)
|
||||
};
|
||||
|
||||
Constant *Init = VMContext.getConstantStruct(Elts,
|
||||
@ -668,11 +668,11 @@ DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
|
||||
getCastToEmpty(Context),
|
||||
GetStringConstant(Name),
|
||||
getCastToEmpty(CompileUnit),
|
||||
VMContext.getConstantInt(Type::Int32Ty, LineNumber),
|
||||
VMContext.getConstantInt(Type::Int64Ty, SizeInBits),
|
||||
VMContext.getConstantInt(Type::Int64Ty, AlignInBits),
|
||||
VMContext.getConstantInt(Type::Int64Ty, OffsetInBits),
|
||||
VMContext.getConstantInt(Type::Int32Ty, Flags),
|
||||
ConstantInt::get(Type::Int32Ty, LineNumber),
|
||||
ConstantInt::get(Type::Int64Ty, SizeInBits),
|
||||
ConstantInt::get(Type::Int64Ty, AlignInBits),
|
||||
ConstantInt::get(Type::Int64Ty, OffsetInBits),
|
||||
ConstantInt::get(Type::Int32Ty, Flags),
|
||||
getCastToEmpty(DerivedFrom)
|
||||
};
|
||||
|
||||
@ -706,14 +706,14 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
|
||||
getCastToEmpty(Context),
|
||||
GetStringConstant(Name),
|
||||
getCastToEmpty(CompileUnit),
|
||||
VMContext.getConstantInt(Type::Int32Ty, LineNumber),
|
||||
VMContext.getConstantInt(Type::Int64Ty, SizeInBits),
|
||||
VMContext.getConstantInt(Type::Int64Ty, AlignInBits),
|
||||
VMContext.getConstantInt(Type::Int64Ty, OffsetInBits),
|
||||
VMContext.getConstantInt(Type::Int32Ty, Flags),
|
||||
ConstantInt::get(Type::Int32Ty, LineNumber),
|
||||
ConstantInt::get(Type::Int64Ty, SizeInBits),
|
||||
ConstantInt::get(Type::Int64Ty, AlignInBits),
|
||||
ConstantInt::get(Type::Int64Ty, OffsetInBits),
|
||||
ConstantInt::get(Type::Int32Ty, Flags),
|
||||
getCastToEmpty(DerivedFrom),
|
||||
getCastToEmpty(Elements),
|
||||
VMContext.getConstantInt(Type::Int32Ty, RuntimeLang)
|
||||
ConstantInt::get(Type::Int32Ty, RuntimeLang)
|
||||
};
|
||||
|
||||
Constant *Init = VMContext.getConstantStruct(Elts,
|
||||
@ -748,10 +748,10 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
|
||||
GetStringConstant(DisplayName),
|
||||
GetStringConstant(LinkageName),
|
||||
getCastToEmpty(CompileUnit),
|
||||
VMContext.getConstantInt(Type::Int32Ty, LineNo),
|
||||
ConstantInt::get(Type::Int32Ty, LineNo),
|
||||
getCastToEmpty(Type),
|
||||
VMContext.getConstantInt(Type::Int1Ty, isLocalToUnit),
|
||||
VMContext.getConstantInt(Type::Int1Ty, isDefinition)
|
||||
ConstantInt::get(Type::Int1Ty, isLocalToUnit),
|
||||
ConstantInt::get(Type::Int1Ty, isDefinition)
|
||||
};
|
||||
|
||||
Constant *Init = VMContext.getConstantStruct(Elts,
|
||||
@ -781,10 +781,10 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
|
||||
GetStringConstant(DisplayName),
|
||||
GetStringConstant(LinkageName),
|
||||
getCastToEmpty(CompileUnit),
|
||||
VMContext.getConstantInt(Type::Int32Ty, LineNo),
|
||||
ConstantInt::get(Type::Int32Ty, LineNo),
|
||||
getCastToEmpty(Type),
|
||||
VMContext.getConstantInt(Type::Int1Ty, isLocalToUnit),
|
||||
VMContext.getConstantInt(Type::Int1Ty, isDefinition),
|
||||
ConstantInt::get(Type::Int1Ty, isLocalToUnit),
|
||||
ConstantInt::get(Type::Int1Ty, isDefinition),
|
||||
VMContext.getConstantExprBitCast(Val, EmptyStructPtr)
|
||||
};
|
||||
|
||||
@ -810,7 +810,7 @@ DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
|
||||
getCastToEmpty(Context),
|
||||
GetStringConstant(Name),
|
||||
getCastToEmpty(CompileUnit),
|
||||
VMContext.getConstantInt(Type::Int32Ty, LineNo),
|
||||
ConstantInt::get(Type::Int32Ty, LineNo),
|
||||
getCastToEmpty(Type)
|
||||
};
|
||||
|
||||
@ -862,8 +862,8 @@ void DIFactory::InsertStopPoint(DICompileUnit CU, unsigned LineNo,
|
||||
|
||||
// Invoke llvm.dbg.stoppoint
|
||||
Value *Args[] = {
|
||||
VMContext.getConstantInt(llvm::Type::Int32Ty, LineNo),
|
||||
VMContext.getConstantInt(llvm::Type::Int32Ty, ColNo),
|
||||
ConstantInt::get(llvm::Type::Int32Ty, LineNo),
|
||||
ConstantInt::get(llvm::Type::Int32Ty, ColNo),
|
||||
getCastToEmpty(CU)
|
||||
};
|
||||
CallInst::Create(StopPointFn, Args, Args+3, "", BB);
|
||||
|
@ -192,13 +192,13 @@ const SCEV *ScalarEvolution::getConstant(ConstantInt *V) {
|
||||
}
|
||||
|
||||
const SCEV *ScalarEvolution::getConstant(const APInt& Val) {
|
||||
return getConstant(getContext().getConstantInt(Val));
|
||||
return getConstant(ConstantInt::get(getContext(), Val));
|
||||
}
|
||||
|
||||
const SCEV *
|
||||
ScalarEvolution::getConstant(const Type *Ty, uint64_t V, bool isSigned) {
|
||||
return getConstant(
|
||||
getContext().getConstantInt(cast<IntegerType>(Ty), V, isSigned));
|
||||
ConstantInt::get(cast<IntegerType>(Ty), V, isSigned));
|
||||
}
|
||||
|
||||
const Type *SCEVConstant::getType() const { return V->getType(); }
|
||||
@ -1518,7 +1518,8 @@ const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl<const SCEV *> &Ops) {
|
||||
++Idx;
|
||||
while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
|
||||
// We found two constants, fold them together!
|
||||
ConstantInt *Fold = getContext().getConstantInt(LHSC->getValue()->getValue() *
|
||||
ConstantInt *Fold = ConstantInt::get(getContext(),
|
||||
LHSC->getValue()->getValue() *
|
||||
RHSC->getValue()->getValue());
|
||||
Ops[0] = getConstant(Fold);
|
||||
Ops.erase(Ops.begin()+1); // Erase the folded element
|
||||
@ -1869,7 +1870,7 @@ ScalarEvolution::getSMaxExpr(SmallVectorImpl<const SCEV *> &Ops) {
|
||||
assert(Idx < Ops.size());
|
||||
while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
|
||||
// We found two constants, fold them together!
|
||||
ConstantInt *Fold = getContext().getConstantInt(
|
||||
ConstantInt *Fold = ConstantInt::get(getContext(),
|
||||
APIntOps::smax(LHSC->getValue()->getValue(),
|
||||
RHSC->getValue()->getValue()));
|
||||
Ops[0] = getConstant(Fold);
|
||||
@ -1966,7 +1967,7 @@ ScalarEvolution::getUMaxExpr(SmallVectorImpl<const SCEV *> &Ops) {
|
||||
assert(Idx < Ops.size());
|
||||
while (const SCEVConstant *RHSC = dyn_cast<SCEVConstant>(Ops[Idx])) {
|
||||
// We found two constants, fold them together!
|
||||
ConstantInt *Fold = getContext().getConstantInt(
|
||||
ConstantInt *Fold = ConstantInt::get(getContext(),
|
||||
APIntOps::umax(LHSC->getValue()->getValue(),
|
||||
RHSC->getValue()->getValue()));
|
||||
Ops[0] = getConstant(Fold);
|
||||
@ -2133,7 +2134,7 @@ const SCEV *ScalarEvolution::getSCEV(Value *V) {
|
||||
/// specified signed integer value and return a SCEV for the constant.
|
||||
const SCEV *ScalarEvolution::getIntegerSCEV(int Val, const Type *Ty) {
|
||||
const IntegerType *ITy = cast<IntegerType>(getEffectiveSCEVType(Ty));
|
||||
return getConstant(getContext().getConstantInt(ITy, Val));
|
||||
return getConstant(ConstantInt::get(ITy, Val));
|
||||
}
|
||||
|
||||
/// getNegativeSCEV - Return a SCEV corresponding to -V = -1*V
|
||||
@ -2896,7 +2897,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
|
||||
// Turn shift left of a constant amount into a multiply.
|
||||
if (ConstantInt *SA = dyn_cast<ConstantInt>(U->getOperand(1))) {
|
||||
uint32_t BitWidth = cast<IntegerType>(V->getType())->getBitWidth();
|
||||
Constant *X = getContext().getConstantInt(
|
||||
Constant *X = ConstantInt::get(getContext(),
|
||||
APInt(BitWidth, 1).shl(SA->getLimitedValue(BitWidth)));
|
||||
return getMulExpr(getSCEV(U->getOperand(0)), getSCEV(X));
|
||||
}
|
||||
@ -2906,7 +2907,7 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
|
||||
// Turn logical shift right of a constant into a unsigned divide.
|
||||
if (ConstantInt *SA = dyn_cast<ConstantInt>(U->getOperand(1))) {
|
||||
uint32_t BitWidth = cast<IntegerType>(V->getType())->getBitWidth();
|
||||
Constant *X = getContext().getConstantInt(
|
||||
Constant *X = ConstantInt::get(getContext(),
|
||||
APInt(BitWidth, 1).shl(SA->getLimitedValue(BitWidth)));
|
||||
return getUDivExpr(getSCEV(U->getOperand(0)), getSCEV(X));
|
||||
}
|
||||
@ -3558,7 +3559,7 @@ ScalarEvolution::ComputeLoadConstantCompareBackedgeTakenCount(
|
||||
|
||||
unsigned MaxSteps = MaxBruteForceIterations;
|
||||
for (unsigned IterationNum = 0; IterationNum != MaxSteps; ++IterationNum) {
|
||||
ConstantInt *ItCst = getContext().getConstantInt(
|
||||
ConstantInt *ItCst = ConstantInt::get(
|
||||
cast<IntegerType>(IdxExpr->getType()), IterationNum);
|
||||
ConstantInt *Val = EvaluateConstantChrecAtConstant(IdxExpr, ItCst, *this);
|
||||
|
||||
@ -4072,9 +4073,9 @@ SolveQuadraticEquation(const SCEVAddRecExpr *AddRec, ScalarEvolution &SE) {
|
||||
LLVMContext &Context = SE.getContext();
|
||||
|
||||
ConstantInt *Solution1 =
|
||||
Context.getConstantInt((NegB + SqrtVal).sdiv(TwoA));
|
||||
ConstantInt::get(Context, (NegB + SqrtVal).sdiv(TwoA));
|
||||
ConstantInt *Solution2 =
|
||||
Context.getConstantInt((NegB - SqrtVal).sdiv(TwoA));
|
||||
ConstantInt::get(Context, (NegB - SqrtVal).sdiv(TwoA));
|
||||
|
||||
return std::make_pair(SE.getConstant(Solution1),
|
||||
SE.getConstant(Solution2));
|
||||
@ -4836,7 +4837,7 @@ const SCEV *SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
|
||||
|
||||
// The exit value should be (End+A)/A.
|
||||
APInt ExitVal = (End + A).udiv(A);
|
||||
ConstantInt *ExitValue = SE.getContext().getConstantInt(ExitVal);
|
||||
ConstantInt *ExitValue = ConstantInt::get(SE.getContext(), ExitVal);
|
||||
|
||||
// Evaluate at the exit value. If we really did fall out of the valid
|
||||
// range, then we computed our trip count, otherwise wrap around or other
|
||||
@ -4848,7 +4849,7 @@ const SCEV *SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
|
||||
// Ensure that the previous value is in the range. This is a sanity check.
|
||||
assert(Range.contains(
|
||||
EvaluateConstantChrecAtConstant(this,
|
||||
SE.getContext().getConstantInt(ExitVal - One), SE)->getValue()) &&
|
||||
ConstantInt::get(SE.getContext(), ExitVal - One), SE)->getValue()) &&
|
||||
"Linear scev computation is off in a bad way!");
|
||||
return SE.getConstant(ExitValue);
|
||||
} else if (isQuadratic()) {
|
||||
@ -4883,7 +4884,7 @@ const SCEV *SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
|
||||
if (Range.contains(R1Val->getValue())) {
|
||||
// The next iteration must be out of the range...
|
||||
ConstantInt *NextVal =
|
||||
SE.getContext().getConstantInt(R1->getValue()->getValue()+1);
|
||||
ConstantInt::get(SE.getContext(), R1->getValue()->getValue()+1);
|
||||
|
||||
R1Val = EvaluateConstantChrecAtConstant(this, NextVal, SE);
|
||||
if (!Range.contains(R1Val->getValue()))
|
||||
@ -4894,7 +4895,7 @@ const SCEV *SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
|
||||
// If R1 was not in the range, then it is a good return value. Make
|
||||
// sure that R1-1 WAS in the range though, just in case.
|
||||
ConstantInt *NextVal =
|
||||
SE.getContext().getConstantInt(R1->getValue()->getValue()-1);
|
||||
ConstantInt::get(SE.getContext(), R1->getValue()->getValue()-1);
|
||||
R1Val = EvaluateConstantChrecAtConstant(this, NextVal, SE);
|
||||
if (Range.contains(R1Val->getValue()))
|
||||
return R1;
|
||||
|
@ -167,7 +167,7 @@ static bool FactorOutConstant(const SCEV *&S,
|
||||
// For a Constant, check for a multiple of the given factor.
|
||||
if (const SCEVConstant *C = dyn_cast<SCEVConstant>(S)) {
|
||||
ConstantInt *CI =
|
||||
SE.getContext().getConstantInt(C->getValue()->getValue().sdiv(Factor));
|
||||
ConstantInt::get(SE.getContext(), C->getValue()->getValue().sdiv(Factor));
|
||||
// If the quotient is zero and the remainder is non-zero, reject
|
||||
// the value at this scale. It will be considered for subsequent
|
||||
// smaller scales.
|
||||
@ -298,8 +298,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin,
|
||||
uint64_t FullOffset = C->getValue()->getZExtValue();
|
||||
if (FullOffset < SL.getSizeInBytes()) {
|
||||
unsigned ElIdx = SL.getElementContainingOffset(FullOffset);
|
||||
GepIndices.push_back(
|
||||
getContext().getConstantInt(Type::Int32Ty, ElIdx));
|
||||
GepIndices.push_back(ConstantInt::get(Type::Int32Ty, ElIdx));
|
||||
ElTy = STy->getTypeAtIndex(ElIdx);
|
||||
Ops[0] =
|
||||
SE.getConstant(Ty, FullOffset - SL.getElementOffset(ElIdx));
|
||||
@ -412,7 +411,7 @@ Value *SCEVExpander::visitUDivExpr(const SCEVUDivExpr *S) {
|
||||
const APInt &RHS = SC->getValue()->getValue();
|
||||
if (RHS.isPowerOf2())
|
||||
return InsertBinop(Instruction::LShr, LHS,
|
||||
getContext().getConstantInt(Ty, RHS.logBase2()));
|
||||
ConstantInt::get(Ty, RHS.logBase2()));
|
||||
}
|
||||
|
||||
Value *RHS = expandCodeFor(S->getRHS(), Ty);
|
||||
@ -532,7 +531,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
|
||||
|
||||
// Insert a unit add instruction right before the terminator corresponding
|
||||
// to the back-edge.
|
||||
Constant *One = getContext().getConstantInt(Ty, 1);
|
||||
Constant *One = ConstantInt::get(Ty, 1);
|
||||
Instruction *Add = BinaryOperator::CreateAdd(PN, One, "indvar.next",
|
||||
(*HPI)->getTerminator());
|
||||
InsertedValues.insert(Add);
|
||||
|
@ -2138,7 +2138,7 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID,
|
||||
if (!isa<IntegerType>(Ty))
|
||||
return Error(ID.Loc, "integer constant must have integer type");
|
||||
ID.APSIntVal.extOrTrunc(Ty->getPrimitiveSizeInBits());
|
||||
V = Context.getConstantInt(ID.APSIntVal);
|
||||
V = ConstantInt::get(Context, ID.APSIntVal);
|
||||
return false;
|
||||
case ValID::t_APFloat:
|
||||
if (!Ty->isFloatingPoint() ||
|
||||
|
@ -877,7 +877,7 @@ bool BitcodeReader::ParseConstants() {
|
||||
case bitc::CST_CODE_INTEGER: // INTEGER: [intval]
|
||||
if (!isa<IntegerType>(CurTy) || Record.empty())
|
||||
return Error("Invalid CST_INTEGER record");
|
||||
V = Context.getConstantInt(CurTy, DecodeSignRotatedValue(Record[0]));
|
||||
V = ConstantInt::get(CurTy, DecodeSignRotatedValue(Record[0]));
|
||||
break;
|
||||
case bitc::CST_CODE_WIDE_INTEGER: {// WIDE_INTEGER: [n x intval]
|
||||
if (!isa<IntegerType>(CurTy) || Record.empty())
|
||||
@ -888,8 +888,9 @@ bool BitcodeReader::ParseConstants() {
|
||||
Words.resize(NumWords);
|
||||
for (unsigned i = 0; i != NumWords; ++i)
|
||||
Words[i] = DecodeSignRotatedValue(Record[i]);
|
||||
V = Context.getConstantInt(APInt(cast<IntegerType>(CurTy)->getBitWidth(),
|
||||
NumWords, &Words[0]));
|
||||
V = ConstantInt::get(Context,
|
||||
APInt(cast<IntegerType>(CurTy)->getBitWidth(),
|
||||
NumWords, &Words[0]));
|
||||
break;
|
||||
}
|
||||
case bitc::CST_CODE_FLOAT: { // FLOAT: [fpval]
|
||||
@ -951,7 +952,7 @@ bool BitcodeReader::ParseConstants() {
|
||||
unsigned Size = Record.size();
|
||||
std::vector<Constant*> Elts;
|
||||
for (unsigned i = 0; i != Size; ++i)
|
||||
Elts.push_back(Context.getConstantInt(EltTy, Record[i]));
|
||||
Elts.push_back(ConstantInt::get(EltTy, Record[i]));
|
||||
V = Context.getConstantArray(ATy, Elts);
|
||||
break;
|
||||
}
|
||||
@ -965,7 +966,7 @@ bool BitcodeReader::ParseConstants() {
|
||||
unsigned Size = Record.size();
|
||||
std::vector<Constant*> Elts;
|
||||
for (unsigned i = 0; i != Size; ++i)
|
||||
Elts.push_back(Context.getConstantInt(EltTy, Record[i]));
|
||||
Elts.push_back(ConstantInt::get(EltTy, Record[i]));
|
||||
Elts.push_back(Context.getNullValue(EltTy));
|
||||
V = Context.getConstantArray(ATy, Elts);
|
||||
break;
|
||||
|
@ -159,27 +159,27 @@ static Value *LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP) {
|
||||
switch(BitSize) {
|
||||
default: llvm_unreachable("Unhandled type size of value to byteswap!");
|
||||
case 16: {
|
||||
Value *Tmp1 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 8),
|
||||
Value *Tmp1 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
|
||||
"bswap.2");
|
||||
Value *Tmp2 = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 8),
|
||||
Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
|
||||
"bswap.1");
|
||||
V = Builder.CreateOr(Tmp1, Tmp2, "bswap.i16");
|
||||
break;
|
||||
}
|
||||
case 32: {
|
||||
Value *Tmp4 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 24),
|
||||
Value *Tmp4 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24),
|
||||
"bswap.4");
|
||||
Value *Tmp3 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 8),
|
||||
Value *Tmp3 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
|
||||
"bswap.3");
|
||||
Value *Tmp2 = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 8),
|
||||
Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
|
||||
"bswap.2");
|
||||
Value *Tmp1 = Builder.CreateLShr(V,Context.getConstantInt(V->getType(), 24),
|
||||
Value *Tmp1 = Builder.CreateLShr(V,ConstantInt::get(V->getType(), 24),
|
||||
"bswap.1");
|
||||
Tmp3 = Builder.CreateAnd(Tmp3,
|
||||
Context.getConstantInt(Type::Int32Ty, 0xFF0000),
|
||||
ConstantInt::get(Type::Int32Ty, 0xFF0000),
|
||||
"bswap.and3");
|
||||
Tmp2 = Builder.CreateAnd(Tmp2,
|
||||
Context.getConstantInt(Type::Int32Ty, 0xFF00),
|
||||
ConstantInt::get(Type::Int32Ty, 0xFF00),
|
||||
"bswap.and2");
|
||||
Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or1");
|
||||
Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or2");
|
||||
@ -187,44 +187,44 @@ static Value *LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP) {
|
||||
break;
|
||||
}
|
||||
case 64: {
|
||||
Value *Tmp8 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 56),
|
||||
Value *Tmp8 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 56),
|
||||
"bswap.8");
|
||||
Value *Tmp7 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 40),
|
||||
Value *Tmp7 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 40),
|
||||
"bswap.7");
|
||||
Value *Tmp6 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 24),
|
||||
Value *Tmp6 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24),
|
||||
"bswap.6");
|
||||
Value *Tmp5 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 8),
|
||||
Value *Tmp5 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8),
|
||||
"bswap.5");
|
||||
Value* Tmp4 = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 8),
|
||||
Value* Tmp4 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8),
|
||||
"bswap.4");
|
||||
Value* Tmp3 = Builder.CreateLShr(V,
|
||||
Context.getConstantInt(V->getType(), 24),
|
||||
ConstantInt::get(V->getType(), 24),
|
||||
"bswap.3");
|
||||
Value* Tmp2 = Builder.CreateLShr(V,
|
||||
Context.getConstantInt(V->getType(), 40),
|
||||
ConstantInt::get(V->getType(), 40),
|
||||
"bswap.2");
|
||||
Value* Tmp1 = Builder.CreateLShr(V,
|
||||
Context.getConstantInt(V->getType(), 56),
|
||||
ConstantInt::get(V->getType(), 56),
|
||||
"bswap.1");
|
||||
Tmp7 = Builder.CreateAnd(Tmp7,
|
||||
Context.getConstantInt(Type::Int64Ty,
|
||||
ConstantInt::get(Type::Int64Ty,
|
||||
0xFF000000000000ULL),
|
||||
"bswap.and7");
|
||||
Tmp6 = Builder.CreateAnd(Tmp6,
|
||||
Context.getConstantInt(Type::Int64Ty,
|
||||
ConstantInt::get(Type::Int64Ty,
|
||||
0xFF0000000000ULL),
|
||||
"bswap.and6");
|
||||
Tmp5 = Builder.CreateAnd(Tmp5,
|
||||
Context.getConstantInt(Type::Int64Ty, 0xFF00000000ULL),
|
||||
ConstantInt::get(Type::Int64Ty, 0xFF00000000ULL),
|
||||
"bswap.and5");
|
||||
Tmp4 = Builder.CreateAnd(Tmp4,
|
||||
Context.getConstantInt(Type::Int64Ty, 0xFF000000ULL),
|
||||
ConstantInt::get(Type::Int64Ty, 0xFF000000ULL),
|
||||
"bswap.and4");
|
||||
Tmp3 = Builder.CreateAnd(Tmp3,
|
||||
Context.getConstantInt(Type::Int64Ty, 0xFF0000ULL),
|
||||
ConstantInt::get(Type::Int64Ty, 0xFF0000ULL),
|
||||
"bswap.and3");
|
||||
Tmp2 = Builder.CreateAnd(Tmp2,
|
||||
Context.getConstantInt(Type::Int64Ty, 0xFF00ULL),
|
||||
ConstantInt::get(Type::Int64Ty, 0xFF00ULL),
|
||||
"bswap.and2");
|
||||
Tmp8 = Builder.CreateOr(Tmp8, Tmp7, "bswap.or1");
|
||||
Tmp6 = Builder.CreateOr(Tmp6, Tmp5, "bswap.or2");
|
||||
@ -254,23 +254,23 @@ static Value *LowerCTPOP(LLVMContext &Context, Value *V, Instruction *IP) {
|
||||
|
||||
unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
|
||||
unsigned WordSize = (BitSize + 63) / 64;
|
||||
Value *Count = Context.getConstantInt(V->getType(), 0);
|
||||
Value *Count = ConstantInt::get(V->getType(), 0);
|
||||
|
||||
for (unsigned n = 0; n < WordSize; ++n) {
|
||||
Value *PartValue = V;
|
||||
for (unsigned i = 1, ct = 0; i < (BitSize>64 ? 64 : BitSize);
|
||||
i <<= 1, ++ct) {
|
||||
Value *MaskCst = Context.getConstantInt(V->getType(), MaskValues[ct]);
|
||||
Value *MaskCst = ConstantInt::get(V->getType(), MaskValues[ct]);
|
||||
Value *LHS = Builder.CreateAnd(PartValue, MaskCst, "cppop.and1");
|
||||
Value *VShift = Builder.CreateLShr(PartValue,
|
||||
Context.getConstantInt(V->getType(), i),
|
||||
ConstantInt::get(V->getType(), i),
|
||||
"ctpop.sh");
|
||||
Value *RHS = Builder.CreateAnd(VShift, MaskCst, "cppop.and2");
|
||||
PartValue = Builder.CreateAdd(LHS, RHS, "ctpop.step");
|
||||
}
|
||||
Count = Builder.CreateAdd(PartValue, Count, "ctpop.part");
|
||||
if (BitSize > 64) {
|
||||
V = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 64),
|
||||
V = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 64),
|
||||
"ctpop.part.sh");
|
||||
BitSize -= 64;
|
||||
}
|
||||
@ -287,7 +287,7 @@ static Value *LowerCTLZ(LLVMContext &Context, Value *V, Instruction *IP) {
|
||||
|
||||
unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
|
||||
for (unsigned i = 1; i < BitSize; i <<= 1) {
|
||||
Value *ShVal = Context.getConstantInt(V->getType(), i);
|
||||
Value *ShVal = ConstantInt::get(V->getType(), i);
|
||||
ShVal = Builder.CreateLShr(V, ShVal, "ctlz.sh");
|
||||
V = Builder.CreateOr(V, ShVal, "ctlz.step");
|
||||
}
|
||||
@ -378,7 +378,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
|
||||
Value *Src = CI->getOperand(1);
|
||||
Value *NotSrc = Builder.CreateNot(Src);
|
||||
NotSrc->setName(Src->getName() + ".not");
|
||||
Value *SrcM1 = Context.getConstantInt(Src->getType(), 1);
|
||||
Value *SrcM1 = ConstantInt::get(Src->getType(), 1);
|
||||
SrcM1 = Builder.CreateSub(Src, SrcM1);
|
||||
Src = LowerCTPOP(Context, Builder.CreateAnd(NotSrc, SrcM1), CI);
|
||||
CI->replaceAllUsesWith(Src);
|
||||
@ -414,7 +414,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
|
||||
case Intrinsic::readcyclecounter: {
|
||||
cerr << "WARNING: this target does not support the llvm.readcyclecoun"
|
||||
<< "ter intrinsic. It is being lowered to a constant 0\n";
|
||||
CI->replaceAllUsesWith(Context.getConstantInt(Type::Int64Ty, 0));
|
||||
CI->replaceAllUsesWith(ConstantInt::get(Type::Int64Ty, 0));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -434,7 +434,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
|
||||
case Intrinsic::eh_typeid_for_i32:
|
||||
case Intrinsic::eh_typeid_for_i64:
|
||||
// Return something different to eh_selector.
|
||||
CI->replaceAllUsesWith(Context.getConstantInt(CI->getType(), 1));
|
||||
CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
|
||||
break;
|
||||
|
||||
case Intrinsic::var_annotation:
|
||||
@ -506,7 +506,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
|
||||
case Intrinsic::flt_rounds:
|
||||
// Lower to "round to the nearest"
|
||||
if (CI->getType() != Type::VoidTy)
|
||||
CI->replaceAllUsesWith(Context.getConstantInt(CI->getType(), 1));
|
||||
CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 1));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ unsigned FastISel::getRegForValue(Value *V) {
|
||||
APInt IntVal(IntBitWidth, 2, x);
|
||||
|
||||
unsigned IntegerReg =
|
||||
getRegForValue(V->getContext().getConstantInt(IntVal));
|
||||
getRegForValue(ConstantInt::get(V->getContext(), IntVal));
|
||||
if (IntegerReg != 0)
|
||||
Reg = FastEmit_r(IntVT.getSimpleVT(), VT, ISD::SINT_TO_FP, IntegerReg);
|
||||
}
|
||||
|
@ -2038,7 +2038,7 @@ SDValue SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned,
|
||||
case MVT::i64: FF = 0x5F800000ULL; break; // 2^64 (as a float)
|
||||
}
|
||||
if (TLI.isLittleEndian()) FF <<= 32;
|
||||
Constant *FudgeFactor = DAG.getContext()->getConstantInt(Type::Int64Ty, FF);
|
||||
Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF);
|
||||
|
||||
SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
|
||||
unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
|
||||
|
@ -2306,7 +2306,7 @@ SDValue DAGTypeLegalizer::ExpandIntOp_UINT_TO_FP(SDNode *N) {
|
||||
|
||||
// Build a 64 bit pair (0, FF) in the constant pool, with FF in the lo bits.
|
||||
SDValue FudgePtr = DAG.getConstantPool(
|
||||
DAG.getContext()->getConstantInt(FF.zext(64)),
|
||||
ConstantInt::get(*DAG.getContext(), FF.zext(64)),
|
||||
TLI.getPointerTy());
|
||||
|
||||
// Get a pointer to FF if the sign bit was set, or to 0 otherwise.
|
||||
|
@ -874,7 +874,7 @@ SDValue SelectionDAG::getConstant(uint64_t Val, MVT VT, bool isT) {
|
||||
}
|
||||
|
||||
SDValue SelectionDAG::getConstant(const APInt &Val, MVT VT, bool isT) {
|
||||
return getConstant(*Context->getConstantInt(Val), VT, isT);
|
||||
return getConstant(*ConstantInt::get(*Context, Val), VT, isT);
|
||||
}
|
||||
|
||||
SDValue SelectionDAG::getConstant(const ConstantInt &Val, MVT VT, bool isT) {
|
||||
|
@ -203,8 +203,8 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) {
|
||||
}
|
||||
|
||||
Constant *BaseElts[] = {
|
||||
Context.getConstantInt(Type::Int32Ty, Roots.size(), false),
|
||||
Context.getConstantInt(Type::Int32Ty, NumMeta, false),
|
||||
ConstantInt::get(Type::Int32Ty, Roots.size(), false),
|
||||
ConstantInt::get(Type::Int32Ty, NumMeta, false),
|
||||
};
|
||||
|
||||
Constant *DescriptorElts[] = {
|
||||
@ -236,8 +236,8 @@ Constant *ShadowStackGC::GetFrameMap(Function &F) {
|
||||
GlobalVariable::InternalLinkage,
|
||||
FrameMap, "__gc_" + F.getName());
|
||||
|
||||
Constant *GEPIndices[2] = { Context.getConstantInt(Type::Int32Ty, 0),
|
||||
Context.getConstantInt(Type::Int32Ty, 0) };
|
||||
Constant *GEPIndices[2] = { ConstantInt::get(Type::Int32Ty, 0),
|
||||
ConstantInt::get(Type::Int32Ty, 0) };
|
||||
return Context.getConstantExprGetElementPtr(GV, GEPIndices, 2);
|
||||
}
|
||||
|
||||
@ -342,9 +342,9 @@ void ShadowStackGC::CollectRoots(Function &F) {
|
||||
GetElementPtrInst *
|
||||
ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr,
|
||||
int Idx, int Idx2, const char *Name) {
|
||||
Value *Indices[] = { Context.getConstantInt(Type::Int32Ty, 0),
|
||||
Context.getConstantInt(Type::Int32Ty, Idx),
|
||||
Context.getConstantInt(Type::Int32Ty, Idx2) };
|
||||
Value *Indices[] = { ConstantInt::get(Type::Int32Ty, 0),
|
||||
ConstantInt::get(Type::Int32Ty, Idx),
|
||||
ConstantInt::get(Type::Int32Ty, Idx2) };
|
||||
Value* Val = B.CreateGEP(BasePtr, Indices, Indices + 3, Name);
|
||||
|
||||
assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant");
|
||||
@ -355,8 +355,8 @@ ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr,
|
||||
GetElementPtrInst *
|
||||
ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr,
|
||||
int Idx, const char *Name) {
|
||||
Value *Indices[] = { Context.getConstantInt(Type::Int32Ty, 0),
|
||||
Context.getConstantInt(Type::Int32Ty, Idx) };
|
||||
Value *Indices[] = { ConstantInt::get(Type::Int32Ty, 0),
|
||||
ConstantInt::get(Type::Int32Ty, Idx) };
|
||||
Value *Val = B.CreateGEP(BasePtr, Indices, Indices + 2, Name);
|
||||
|
||||
assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant");
|
||||
|
@ -487,7 +487,7 @@ GenericValue JIT::runFunction(Function *F,
|
||||
switch (ArgTy->getTypeID()) {
|
||||
default: llvm_unreachable("Unknown argument type for function call!");
|
||||
case Type::IntegerTyID:
|
||||
C = Context.getConstantInt(AV.IntVal);
|
||||
C = ConstantInt::get(F->getContext(), AV.IntVal);
|
||||
break;
|
||||
case Type::FloatTyID:
|
||||
C = Context.getConstantFP(APFloat(AV.FloatVal));
|
||||
@ -503,9 +503,9 @@ GenericValue JIT::runFunction(Function *F,
|
||||
case Type::PointerTyID:
|
||||
void *ArgPtr = GVTOP(AV);
|
||||
if (sizeof(void*) == 4)
|
||||
C = Context.getConstantInt(Type::Int32Ty, (int)(intptr_t)ArgPtr);
|
||||
C = ConstantInt::get(Type::Int32Ty, (int)(intptr_t)ArgPtr);
|
||||
else
|
||||
C = Context.getConstantInt(Type::Int64Ty, (intptr_t)ArgPtr);
|
||||
C = ConstantInt::get(Type::Int64Ty, (intptr_t)ArgPtr);
|
||||
// Cast the integer to pointer
|
||||
C = Context.getConstantExprIntToPtr(C, ArgTy);
|
||||
break;
|
||||
|
@ -903,8 +903,7 @@ emitLoadConstPool(MachineBasicBlock &MBB,
|
||||
unsigned PredReg) const {
|
||||
MachineFunction &MF = *MBB.getParent();
|
||||
MachineConstantPool *ConstantPool = MF.getConstantPool();
|
||||
Constant *C =
|
||||
MF.getFunction()->getContext().getConstantInt(Type::Int32Ty, Val);
|
||||
Constant *C = ConstantInt::get(Type::Int32Ty, Val);
|
||||
unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4);
|
||||
|
||||
BuildMI(MBB, MBBI, dl, TII.get(ARM::LDRcp))
|
||||
|
@ -877,8 +877,7 @@ SDNode *ARMDAGToDAGISel::Select(SDValue Op) {
|
||||
!ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
|
||||
if (UseCP) {
|
||||
SDValue CPIdx =
|
||||
CurDAG->getTargetConstantPool(
|
||||
CurDAG->getContext()->getConstantInt(Type::Int32Ty, Val),
|
||||
CurDAG->getTargetConstantPool(ConstantInt::get(Type::Int32Ty, Val),
|
||||
TLI.getPointerTy());
|
||||
|
||||
SDNode *ResNode;
|
||||
|
@ -58,8 +58,7 @@ void Thumb1RegisterInfo::emitLoadConstPool(MachineBasicBlock &MBB,
|
||||
unsigned PredReg) const {
|
||||
MachineFunction &MF = *MBB.getParent();
|
||||
MachineConstantPool *ConstantPool = MF.getConstantPool();
|
||||
Constant *C =
|
||||
MF.getFunction()->getContext().getConstantInt(Type::Int32Ty, Val);
|
||||
Constant *C = ConstantInt::get(Type::Int32Ty, Val);
|
||||
unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4);
|
||||
|
||||
BuildMI(MBB, MBBI, dl, TII.get(ARM::tLDRcp))
|
||||
|
@ -52,8 +52,7 @@ void Thumb2RegisterInfo::emitLoadConstPool(MachineBasicBlock &MBB,
|
||||
unsigned PredReg) const {
|
||||
MachineFunction &MF = *MBB.getParent();
|
||||
MachineConstantPool *ConstantPool = MF.getConstantPool();
|
||||
Constant *C =
|
||||
MF.getFunction()->getContext().getConstantInt(Type::Int32Ty, Val);
|
||||
Constant *C = ConstantInt::get(Type::Int32Ty, Val);
|
||||
unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4);
|
||||
|
||||
BuildMI(MBB, MBBI, dl, TII.get(ARM::t2LDRpci))
|
||||
|
@ -305,7 +305,7 @@ SDNode *AlphaDAGToDAGISel::Select(SDValue Op) {
|
||||
// val32 >= IMM_LOW + IMM_LOW * IMM_MULT) //always true
|
||||
break; //(zext (LDAH (LDA)))
|
||||
//Else use the constant pool
|
||||
ConstantInt *C = CurDAG->getContext()->getConstantInt(Type::Int64Ty, uval);
|
||||
ConstantInt *C = ConstantInt::get(Type::Int64Ty, uval);
|
||||
SDValue CPI = CurDAG->getTargetConstantPool(C, MVT::i64);
|
||||
SDNode *Tmp = CurDAG->getTargetNode(Alpha::LDAHr, dl, MVT::i64, CPI,
|
||||
SDValue(getGlobalBaseReg(), 0));
|
||||
|
@ -3500,7 +3500,7 @@ void CWriter::visitStoreInst(StoreInst &I) {
|
||||
if (!ITy->isPowerOf2ByteWidth())
|
||||
// We have a bit width that doesn't match an even power-of-2 byte
|
||||
// size. Consequently we must & the value with the type's bit mask
|
||||
BitMask = I.getContext().getConstantInt(ITy, ITy->getBitMask());
|
||||
BitMask = ConstantInt::get(ITy, ITy->getBitMask());
|
||||
if (BitMask)
|
||||
Out << "((";
|
||||
writeOperand(Operand);
|
||||
|
@ -4889,10 +4889,10 @@ SDValue X86TargetLowering::LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG) {
|
||||
|
||||
// Build some magic constants.
|
||||
std::vector<Constant*> CV0;
|
||||
CV0.push_back(Context->getConstantInt(APInt(32, 0x45300000)));
|
||||
CV0.push_back(Context->getConstantInt(APInt(32, 0x43300000)));
|
||||
CV0.push_back(Context->getConstantInt(APInt(32, 0)));
|
||||
CV0.push_back(Context->getConstantInt(APInt(32, 0)));
|
||||
CV0.push_back(ConstantInt::get(*Context, APInt(32, 0x45300000)));
|
||||
CV0.push_back(ConstantInt::get(*Context, APInt(32, 0x43300000)));
|
||||
CV0.push_back(ConstantInt::get(*Context, APInt(32, 0)));
|
||||
CV0.push_back(ConstantInt::get(*Context, APInt(32, 0)));
|
||||
Constant *C0 = Context->getConstantVector(CV0);
|
||||
SDValue CPIdx0 = DAG.getConstantPool(C0, getPointerTy(), 16);
|
||||
|
||||
|
@ -174,8 +174,7 @@ SDNode *XCoreDAGToDAGISel::Select(SDValue Op) {
|
||||
else if (! Predicate_immU16(N)) {
|
||||
unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
|
||||
SDValue CPIdx =
|
||||
CurDAG->getTargetConstantPool(
|
||||
CurDAG->getContext()->getConstantInt(Type::Int32Ty, Val),
|
||||
CurDAG->getTargetConstantPool(ConstantInt::get(Type::Int32Ty, Val),
|
||||
TLI.getPointerTy());
|
||||
return CurDAG->getTargetNode(XCore::LDWCP_lru6, dl, MVT::i32,
|
||||
MVT::Other, CPIdx,
|
||||
|
@ -638,9 +638,9 @@ Function *ArgPromotion::DoPromotion(Function *F,
|
||||
// Emit a GEP and load for each element of the struct.
|
||||
const Type *AgTy = cast<PointerType>(I->getType())->getElementType();
|
||||
const StructType *STy = cast<StructType>(AgTy);
|
||||
Value *Idxs[2] = { Context.getConstantInt(Type::Int32Ty, 0), 0 };
|
||||
Value *Idxs[2] = { ConstantInt::get(Type::Int32Ty, 0), 0 };
|
||||
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
|
||||
Idxs[1] = Context.getConstantInt(Type::Int32Ty, i);
|
||||
Idxs[1] = ConstantInt::get(Type::Int32Ty, i);
|
||||
Value *Idx = GetElementPtrInst::Create(*AI, Idxs, Idxs+2,
|
||||
(*AI)->getName()+"."+utostr(i),
|
||||
Call);
|
||||
@ -665,7 +665,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
|
||||
// Use i32 to index structs, and i64 for others (pointers/arrays).
|
||||
// This satisfies GEP constraints.
|
||||
const Type *IdxTy = (isa<StructType>(ElTy) ? Type::Int32Ty : Type::Int64Ty);
|
||||
Ops.push_back(Context.getConstantInt(IdxTy, *II));
|
||||
Ops.push_back(ConstantInt::get(IdxTy, *II));
|
||||
// Keep track of the type we're currently indexing
|
||||
ElTy = cast<CompositeType>(ElTy)->getTypeAtIndex(*II);
|
||||
}
|
||||
@ -758,10 +758,10 @@ Function *ArgPromotion::DoPromotion(Function *F,
|
||||
const Type *AgTy = cast<PointerType>(I->getType())->getElementType();
|
||||
Value *TheAlloca = new AllocaInst(AgTy, 0, "", InsertPt);
|
||||
const StructType *STy = cast<StructType>(AgTy);
|
||||
Value *Idxs[2] = { Context.getConstantInt(Type::Int32Ty, 0), 0 };
|
||||
Value *Idxs[2] = { ConstantInt::get(Type::Int32Ty, 0), 0 };
|
||||
|
||||
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
|
||||
Idxs[1] = Context.getConstantInt(Type::Int32Ty, i);
|
||||
Idxs[1] = ConstantInt::get(Type::Int32Ty, i);
|
||||
Value *Idx =
|
||||
GetElementPtrInst::Create(TheAlloca, Idxs, Idxs+2,
|
||||
TheAlloca->getName()+"."+utostr(i),
|
||||
|
@ -488,7 +488,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
|
||||
const StructLayout &Layout = *TD.getStructLayout(STy);
|
||||
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
|
||||
Constant *In = getAggregateConstantElement(Init,
|
||||
Context.getConstantInt(Type::Int32Ty, i),
|
||||
ConstantInt::get(Type::Int32Ty, i),
|
||||
Context);
|
||||
assert(In && "Couldn't get element of initializer?");
|
||||
GlobalVariable *NGV = new GlobalVariable(Context,
|
||||
@ -523,7 +523,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD,
|
||||
unsigned EltAlign = TD.getABITypeAlignment(STy->getElementType());
|
||||
for (unsigned i = 0, e = NumElements; i != e; ++i) {
|
||||
Constant *In = getAggregateConstantElement(Init,
|
||||
Context.getConstantInt(Type::Int32Ty, i),
|
||||
ConstantInt::get(Type::Int32Ty, i),
|
||||
Context);
|
||||
assert(In && "Couldn't get element of initializer?");
|
||||
|
||||
@ -1508,7 +1508,7 @@ static bool TryToOptimizeStoreOfMallocToGlobal(GlobalVariable *GV,
|
||||
if (const ArrayType *AT = dyn_cast<ArrayType>(MI->getAllocatedType())) {
|
||||
MallocInst *NewMI =
|
||||
new MallocInst(AllocSTy,
|
||||
Context.getConstantInt(Type::Int32Ty, AT->getNumElements()),
|
||||
ConstantInt::get(Type::Int32Ty, AT->getNumElements()),
|
||||
"", MI);
|
||||
NewMI->takeName(MI);
|
||||
Value *Cast = new BitCastInst(NewMI, MI->getType(), "tmp", MI);
|
||||
@ -1605,7 +1605,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal,
|
||||
// Only do this if we weren't storing a loaded value.
|
||||
Value *StoreVal;
|
||||
if (StoringOther || SI->getOperand(0) == InitVal)
|
||||
StoreVal = Context.getConstantInt(Type::Int1Ty, StoringOther);
|
||||
StoreVal = ConstantInt::get(Type::Int1Ty, StoringOther);
|
||||
else {
|
||||
// Otherwise, we are storing a previously loaded copy. To do this,
|
||||
// change the copy from copying the original value to just copying the
|
||||
@ -1947,7 +1947,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
|
||||
LLVMContext &Context) {
|
||||
// If we made a change, reassemble the initializer list.
|
||||
std::vector<Constant*> CSVals;
|
||||
CSVals.push_back(Context.getConstantInt(Type::Int32Ty, 65535));
|
||||
CSVals.push_back(ConstantInt::get(Type::Int32Ty, 65535));
|
||||
CSVals.push_back(0);
|
||||
|
||||
// Create the new init list.
|
||||
@ -1959,7 +1959,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL,
|
||||
const Type *FTy = Context.getFunctionType(Type::VoidTy, false);
|
||||
const PointerType *PFTy = Context.getPointerTypeUnqual(FTy);
|
||||
CSVals[1] = Context.getNullValue(PFTy);
|
||||
CSVals[0] = Context.getConstantInt(Type::Int32Ty, 2147483647);
|
||||
CSVals[0] = ConstantInt::get(Type::Int32Ty, 2147483647);
|
||||
}
|
||||
CAList.push_back(Context.getConstantStruct(CSVals));
|
||||
}
|
||||
|
@ -383,8 +383,7 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
|
||||
new BitCastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst);
|
||||
std::vector<Value*> Args =
|
||||
make_vector<Value*>(GetSetJmpMap(Func), BufPtr,
|
||||
Inst->getContext().getConstantInt(Type::Int32Ty,
|
||||
SetJmpIDMap[Func]++), 0);
|
||||
ConstantInt::get(Type::Int32Ty,SetJmpIDMap[Func]++), 0);
|
||||
CallInst::Create(AddSJToMap, Args.begin(), Args.end(), "", Inst);
|
||||
|
||||
// We are guaranteed that there are no values live across basic blocks
|
||||
@ -434,9 +433,8 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
|
||||
|
||||
// Add the case for this setjmp's number...
|
||||
SwitchValuePair SVP = GetSJSwitch(Func, GetRethrowBB(Func));
|
||||
SVP.first->addCase(Inst->getContext().getConstantInt(Type::Int32Ty,
|
||||
SetJmpIDMap[Func] - 1),
|
||||
SetJmpContBlock);
|
||||
SVP.first->addCase(ConstantInt::get(Type::Int32Ty, SetJmpIDMap[Func] - 1),
|
||||
SetJmpContBlock);
|
||||
|
||||
// Value coming from the handling of the exception.
|
||||
PHI->addIncoming(SVP.second, SVP.second->getParent());
|
||||
|
@ -55,7 +55,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
|
||||
// pass null.
|
||||
Args[2] = Context.getConstantPointerNull(UIntPtr);
|
||||
}
|
||||
Args[3] = Context.getConstantInt(Type::Int32Ty, NumElements);
|
||||
Args[3] = ConstantInt::get(Type::Int32Ty, NumElements);
|
||||
|
||||
Instruction *InitCall = CallInst::Create(InitFn, Args.begin(), Args.end(),
|
||||
"newargc", InsertPos);
|
||||
@ -111,7 +111,7 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
|
||||
// Create the getelementptr constant expression
|
||||
std::vector<Constant*> Indices(2);
|
||||
Indices[0] = Context.getNullValue(Type::Int32Ty);
|
||||
Indices[1] = Context.getConstantInt(Type::Int32Ty, CounterNum);
|
||||
Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum);
|
||||
Constant *ElementPtr =
|
||||
Context.getConstantExprGetElementPtr(CounterArray, &Indices[0],
|
||||
Indices.size());
|
||||
@ -119,7 +119,7 @@ void llvm::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNum,
|
||||
// Load, increment and store the value back.
|
||||
Value *OldVal = new LoadInst(ElementPtr, "OldFuncCounter", InsertPos);
|
||||
Value *NewVal = BinaryOperator::Create(Instruction::Add, OldVal,
|
||||
Context.getConstantInt(Type::Int32Ty, 1),
|
||||
ConstantInt::get(Type::Int32Ty, 1),
|
||||
"NewFuncCounter", InsertPos);
|
||||
new StoreInst(NewVal, ElementPtr, InsertPos);
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ static void getBackEdges(Function& F, T& BackEdges);
|
||||
|
||||
GlobalRandomCounter::GlobalRandomCounter(Module& M, const IntegerType* t,
|
||||
uint64_t resetval) : T(t) {
|
||||
ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
|
||||
ConstantInt* Init = ConstantInt::get(T, resetval);
|
||||
ResetValue = Init;
|
||||
Counter = new GlobalVariable(M, T, false, GlobalValue::InternalLinkage,
|
||||
Init, "RandomSteeringCounter");
|
||||
@ -209,16 +209,15 @@ void GlobalRandomCounter::PrepFunction(Function* F) {}
|
||||
|
||||
void GlobalRandomCounter::ProcessChoicePoint(BasicBlock* bb) {
|
||||
BranchInst* t = cast<BranchInst>(bb->getTerminator());
|
||||
LLVMContext &Context = bb->getContext();
|
||||
|
||||
//decrement counter
|
||||
LoadInst* l = new LoadInst(Counter, "counter", t);
|
||||
|
||||
ICmpInst* s = new ICmpInst(t, ICmpInst::ICMP_EQ, l,
|
||||
Context.getConstantInt(T, 0),
|
||||
ConstantInt::get(T, 0),
|
||||
"countercc");
|
||||
|
||||
Value* nv = BinaryOperator::CreateSub(l, Context.getConstantInt(T, 1),
|
||||
Value* nv = BinaryOperator::CreateSub(l, ConstantInt::get(T, 1),
|
||||
"counternew", t);
|
||||
new StoreInst(nv, Counter, t);
|
||||
t->setCondition(s);
|
||||
@ -236,7 +235,7 @@ void GlobalRandomCounter::ProcessChoicePoint(BasicBlock* bb) {
|
||||
GlobalRandomCounterOpt::GlobalRandomCounterOpt(Module& M, const IntegerType* t,
|
||||
uint64_t resetval)
|
||||
: AI(0), T(t) {
|
||||
ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
|
||||
ConstantInt* Init = ConstantInt::get(T, resetval);
|
||||
ResetValue = Init;
|
||||
Counter = new GlobalVariable(M, T, false, GlobalValue::InternalLinkage,
|
||||
Init, "RandomSteeringCounter");
|
||||
@ -283,16 +282,15 @@ void GlobalRandomCounterOpt::PrepFunction(Function* F) {
|
||||
|
||||
void GlobalRandomCounterOpt::ProcessChoicePoint(BasicBlock* bb) {
|
||||
BranchInst* t = cast<BranchInst>(bb->getTerminator());
|
||||
LLVMContext &Context = bb->getContext();
|
||||
|
||||
//decrement counter
|
||||
LoadInst* l = new LoadInst(AI, "counter", t);
|
||||
|
||||
ICmpInst* s = new ICmpInst(t, ICmpInst::ICMP_EQ, l,
|
||||
Context.getConstantInt(T, 0),
|
||||
ConstantInt::get(T, 0),
|
||||
"countercc");
|
||||
|
||||
Value* nv = BinaryOperator::CreateSub(l, Context.getConstantInt(T, 1),
|
||||
Value* nv = BinaryOperator::CreateSub(l, ConstantInt::get(T, 1),
|
||||
"counternew", t);
|
||||
new StoreInst(nv, AI, t);
|
||||
t->setCondition(s);
|
||||
@ -318,15 +316,14 @@ void CycleCounter::PrepFunction(Function* F) {}
|
||||
|
||||
void CycleCounter::ProcessChoicePoint(BasicBlock* bb) {
|
||||
BranchInst* t = cast<BranchInst>(bb->getTerminator());
|
||||
LLVMContext &Context = bb->getContext();
|
||||
|
||||
CallInst* c = CallInst::Create(F, "rdcc", t);
|
||||
BinaryOperator* b =
|
||||
BinaryOperator::CreateAnd(c, Context.getConstantInt(Type::Int64Ty, rm),
|
||||
BinaryOperator::CreateAnd(c, ConstantInt::get(Type::Int64Ty, rm),
|
||||
"mrdcc", t);
|
||||
|
||||
ICmpInst *s = new ICmpInst(t, ICmpInst::ICMP_EQ, b,
|
||||
Context.getConstantInt(Type::Int64Ty, 0),
|
||||
ConstantInt::get(Type::Int64Ty, 0),
|
||||
"mrdccc");
|
||||
|
||||
t->setCondition(s);
|
||||
@ -353,7 +350,7 @@ void RSProfilers_std::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNu
|
||||
// Create the getelementptr constant expression
|
||||
std::vector<Constant*> Indices(2);
|
||||
Indices[0] = BB->getContext().getNullValue(Type::Int32Ty);
|
||||
Indices[1] = BB->getContext().getConstantInt(Type::Int32Ty, CounterNum);
|
||||
Indices[1] = ConstantInt::get(Type::Int32Ty, CounterNum);
|
||||
Constant *ElementPtr =
|
||||
BB->getContext().getConstantExprGetElementPtr(CounterArray,
|
||||
&Indices[0], 2);
|
||||
@ -362,7 +359,7 @@ void RSProfilers_std::IncrementCounterInBlock(BasicBlock *BB, unsigned CounterNu
|
||||
Value *OldVal = new LoadInst(ElementPtr, "OldCounter", InsertPos);
|
||||
profcode.insert(OldVal);
|
||||
Value *NewVal = BinaryOperator::CreateAdd(OldVal,
|
||||
BB->getContext().getConstantInt(Type::Int32Ty, 1),
|
||||
ConstantInt::get(Type::Int32Ty, 1),
|
||||
"NewCounter", InsertPos);
|
||||
profcode.insert(NewVal);
|
||||
profcode.insert(new StoreInst(NewVal, ElementPtr, InsertPos));
|
||||
@ -483,7 +480,7 @@ void ProfilerRS::ProcessBackEdge(BasicBlock* src, BasicBlock* dst, Function& F)
|
||||
//b:
|
||||
BranchInst::Create(cast<BasicBlock>(Translate(dst)), bbC);
|
||||
BranchInst::Create(dst, cast<BasicBlock>(Translate(dst)),
|
||||
F.getContext().getConstantInt(Type::Int1Ty, true), bbCp);
|
||||
ConstantInt::get(Type::Int1Ty, true), bbCp);
|
||||
//c:
|
||||
{
|
||||
TerminatorInst* iB = src->getTerminator();
|
||||
@ -540,8 +537,7 @@ bool ProfilerRS::runOnFunction(Function& F) {
|
||||
ReplaceInstWithInst(T, BranchInst::Create(T->getSuccessor(0),
|
||||
cast<BasicBlock>(
|
||||
Translate(T->getSuccessor(0))),
|
||||
F.getContext().getConstantInt(Type::Int1Ty,
|
||||
true)));
|
||||
ConstantInt::get(Type::Int1Ty, true)));
|
||||
|
||||
//do whatever is needed now that the function is duplicated
|
||||
c->PrepFunction(&F);
|
||||
|
@ -617,7 +617,7 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
|
||||
V = new SExtInst(V, IntPtrTy, "sunkaddr", InsertPt);
|
||||
}
|
||||
if (AddrMode.Scale != 1)
|
||||
V = BinaryOperator::CreateMul(V, Context.getConstantInt(IntPtrTy,
|
||||
V = BinaryOperator::CreateMul(V, ConstantInt::get(IntPtrTy,
|
||||
AddrMode.Scale),
|
||||
"sunkaddr", InsertPt);
|
||||
Result = V;
|
||||
@ -649,7 +649,7 @@ bool CodeGenPrepare::OptimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
|
||||
|
||||
// Add in the Base Offset if present.
|
||||
if (AddrMode.BaseOffs) {
|
||||
Value *V = Context.getConstantInt(IntPtrTy, AddrMode.BaseOffs);
|
||||
Value *V = ConstantInt::get(IntPtrTy, AddrMode.BaseOffs);
|
||||
if (Result)
|
||||
Result = BinaryOperator::CreateAdd(Result, V, "sunkaddr", InsertPt);
|
||||
else
|
||||
|
@ -718,18 +718,18 @@ void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PH) {
|
||||
// Insert new integer induction variable.
|
||||
PHINode *NewPHI = PHINode::Create(Type::Int32Ty,
|
||||
PH->getName()+".int", PH);
|
||||
NewPHI->addIncoming(Context.getConstantInt(Type::Int32Ty, newInitValue),
|
||||
NewPHI->addIncoming(ConstantInt::get(Type::Int32Ty, newInitValue),
|
||||
PH->getIncomingBlock(IncomingEdge));
|
||||
|
||||
Value *NewAdd = BinaryOperator::CreateAdd(NewPHI,
|
||||
Context.getConstantInt(Type::Int32Ty,
|
||||
ConstantInt::get(Type::Int32Ty,
|
||||
newIncrValue),
|
||||
Incr->getName()+".int", Incr);
|
||||
NewPHI->addIncoming(NewAdd, PH->getIncomingBlock(BackEdge));
|
||||
|
||||
// The back edge is edge 1 of newPHI, whatever it may have been in the
|
||||
// original PHI.
|
||||
ConstantInt *NewEV = Context.getConstantInt(Type::Int32Ty, intEV);
|
||||
ConstantInt *NewEV = ConstantInt::get(Type::Int32Ty, intEV);
|
||||
Value *LHS = (EVIndex == 1 ? NewPHI->getIncomingValue(1) : NewEV);
|
||||
Value *RHS = (EVIndex == 1 ? NewEV : NewPHI->getIncomingValue(1));
|
||||
ICmpInst *NewEC = new ICmpInst(EC->getParent()->getTerminator(),
|
||||
|
@ -599,7 +599,7 @@ static inline Value *dyn_castNotVal(Value *V, LLVMContext *Context) {
|
||||
|
||||
// Constants can be considered to be not'ed values...
|
||||
if (ConstantInt *C = dyn_cast<ConstantInt>(V))
|
||||
return Context->getConstantInt(~C->getValue());
|
||||
return ConstantInt::get(*Context, ~C->getValue());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -620,7 +620,7 @@ static inline Value *dyn_castFoldableMul(Value *V, ConstantInt *&CST,
|
||||
// The multiplier is really 1 << CST.
|
||||
uint32_t BitWidth = cast<IntegerType>(V->getType())->getBitWidth();
|
||||
uint32_t CSTVal = CST->getLimitedValue(BitWidth);
|
||||
CST = Context->getConstantInt(APInt(BitWidth, 1).shl(CSTVal));
|
||||
CST = ConstantInt::get(*Context, APInt(BitWidth, 1).shl(CSTVal));
|
||||
return I->getOperand(0);
|
||||
}
|
||||
}
|
||||
@ -640,12 +640,12 @@ static User *dyn_castGetElementPtr(Value *V) {
|
||||
/// AddOne - Add one to a ConstantInt
|
||||
static Constant *AddOne(Constant *C, LLVMContext *Context) {
|
||||
return Context->getConstantExprAdd(C,
|
||||
Context->getConstantInt(C->getType(), 1));
|
||||
ConstantInt::get(C->getType(), 1));
|
||||
}
|
||||
/// SubOne - Subtract one from a ConstantInt
|
||||
static Constant *SubOne(ConstantInt *C, LLVMContext *Context) {
|
||||
return Context->getConstantExprSub(C,
|
||||
Context->getConstantInt(C->getType(), 1));
|
||||
ConstantInt::get(C->getType(), 1));
|
||||
}
|
||||
/// MultiplyOverflows - True if the multiply can not be expressed in an int
|
||||
/// this size.
|
||||
@ -692,7 +692,7 @@ static bool ShrinkDemandedConstant(Instruction *I, unsigned OpNo,
|
||||
|
||||
// This instruction is producing bits that are not demanded. Shrink the RHS.
|
||||
Demanded &= OpC->getValue();
|
||||
I->setOperand(OpNo, Context->getConstantInt(Demanded));
|
||||
I->setOperand(OpNo, ConstantInt::get(*Context, Demanded));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1023,7 +1023,8 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
|
||||
if ((DemandedMask & (RHSKnownZero|RHSKnownOne)) == DemandedMask) {
|
||||
// all known
|
||||
if ((RHSKnownOne & LHSKnownOne) == RHSKnownOne) {
|
||||
Constant *AndC = Context->getConstantInt(~RHSKnownOne & DemandedMask);
|
||||
Constant *AndC = ConstantInt::get(*Context,
|
||||
~RHSKnownOne & DemandedMask);
|
||||
Instruction *And =
|
||||
BinaryOperator::CreateAnd(I->getOperand(0), AndC, "tmp");
|
||||
return InsertNewInstBefore(And, *I);
|
||||
@ -1395,10 +1396,10 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
|
||||
Instruction *NewVal;
|
||||
if (InputBit > ResultBit)
|
||||
NewVal = BinaryOperator::CreateLShr(I->getOperand(1),
|
||||
Context->getConstantInt(I->getType(), InputBit-ResultBit));
|
||||
ConstantInt::get(I->getType(), InputBit-ResultBit));
|
||||
else
|
||||
NewVal = BinaryOperator::CreateShl(I->getOperand(1),
|
||||
Context->getConstantInt(I->getType(), ResultBit-InputBit));
|
||||
ConstantInt::get(I->getType(), ResultBit-InputBit));
|
||||
NewVal->takeName(I);
|
||||
return InsertNewInstBefore(NewVal, *I);
|
||||
}
|
||||
@ -1415,7 +1416,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
|
||||
// If the client is only demanding bits that we know, return the known
|
||||
// constant.
|
||||
if ((DemandedMask & (RHSKnownZero|RHSKnownOne)) == DemandedMask) {
|
||||
Constant *C = Context->getConstantInt(RHSKnownOne);
|
||||
Constant *C = ConstantInt::get(*Context, RHSKnownOne);
|
||||
if (isa<PointerType>(V->getType()))
|
||||
C = Context->getConstantExprIntToPtr(C, V->getType());
|
||||
return C;
|
||||
@ -1602,7 +1603,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
|
||||
if (UndefElts[i])
|
||||
Elts.push_back(Context->getUndef(Type::Int32Ty));
|
||||
else
|
||||
Elts.push_back(Context->getConstantInt(Type::Int32Ty,
|
||||
Elts.push_back(ConstantInt::get(Type::Int32Ty,
|
||||
Shuffle->getMaskValue(i)));
|
||||
}
|
||||
I->setOperand(2, Context->getConstantVector(Elts));
|
||||
@ -1733,9 +1734,9 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
|
||||
Value *RHS = II->getOperand(2);
|
||||
// Extract the element as scalars.
|
||||
LHS = InsertNewInstBefore(new ExtractElementInst(LHS,
|
||||
Context->getConstantInt(Type::Int32Ty, 0U, false), "tmp"), *II);
|
||||
ConstantInt::get(Type::Int32Ty, 0U, false), "tmp"), *II);
|
||||
RHS = InsertNewInstBefore(new ExtractElementInst(RHS,
|
||||
Context->getConstantInt(Type::Int32Ty, 0U, false), "tmp"), *II);
|
||||
ConstantInt::get(Type::Int32Ty, 0U, false), "tmp"), *II);
|
||||
|
||||
switch (II->getIntrinsicID()) {
|
||||
default: llvm_unreachable("Case stmts out of sync!");
|
||||
@ -1754,7 +1755,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
|
||||
Instruction *New =
|
||||
InsertElementInst::Create(
|
||||
Context->getUndef(II->getType()), TmpV,
|
||||
Context->getConstantInt(Type::Int32Ty, 0U, false), II->getName());
|
||||
ConstantInt::get(Type::Int32Ty, 0U, false), II->getName());
|
||||
InsertNewInstBefore(New, *II);
|
||||
AddSoonDeadInstToWorklist(*II, 0);
|
||||
return New;
|
||||
@ -1860,7 +1861,7 @@ struct AddRHS {
|
||||
bool shouldApply(Value *LHS) const { return LHS == RHS; }
|
||||
Instruction *apply(BinaryOperator &Add) const {
|
||||
return BinaryOperator::CreateShl(Add.getOperand(0),
|
||||
Context->getConstantInt(Add.getType(), 1));
|
||||
ConstantInt::get(Add.getType(), 1));
|
||||
}
|
||||
};
|
||||
|
||||
@ -2543,7 +2544,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
|
||||
ConstantInt *C2 = 0;
|
||||
if (dyn_castFoldableMul(Op1I, C2, Context) == Op0) {
|
||||
Constant *CP1 =
|
||||
Context->getConstantExprSub(Context->getConstantInt(I.getType(), 1),
|
||||
Context->getConstantExprSub(ConstantInt::get(I.getType(), 1),
|
||||
C2);
|
||||
return BinaryOperator::CreateMul(Op0, CP1);
|
||||
}
|
||||
@ -2654,7 +2655,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
|
||||
const APInt& Val = cast<ConstantInt>(CI)->getValue();
|
||||
if (Val.isPowerOf2()) { // Replace X*(2^C) with X << C
|
||||
return BinaryOperator::CreateShl(Op0,
|
||||
Context->getConstantInt(Op0->getType(), Val.logBase2()));
|
||||
ConstantInt::get(Op0->getType(), Val.logBase2()));
|
||||
}
|
||||
} else if (isa<VectorType>(Op1->getType())) {
|
||||
if (Op1->isNullValue())
|
||||
@ -2761,7 +2762,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
|
||||
isSignBitCheck(SCI->getPredicate(), cast<ConstantInt>(SCIOp1), TIS) &&
|
||||
TIS) {
|
||||
// Shift the X value right to turn it into "all signbits".
|
||||
Constant *Amt = Context->getConstantInt(SCIOp0->getType(),
|
||||
Constant *Amt = ConstantInt::get(SCIOp0->getType(),
|
||||
SCOpTy->getPrimitiveSizeInBits()-1);
|
||||
Value *V =
|
||||
InsertNewInstBefore(
|
||||
@ -2932,12 +2933,12 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
|
||||
// (sdiv X, X) --> 1 (udiv X, X) --> 1
|
||||
if (Op0 == Op1) {
|
||||
if (const VectorType *Ty = dyn_cast<VectorType>(I.getType())) {
|
||||
Constant *CI = Context->getConstantInt(Ty->getElementType(), 1);
|
||||
Constant *CI = ConstantInt::get(Ty->getElementType(), 1);
|
||||
std::vector<Constant*> Elts(Ty->getNumElements(), CI);
|
||||
return ReplaceInstUsesWith(I, Context->getConstantVector(Elts));
|
||||
}
|
||||
|
||||
Constant *CI = Context->getConstantInt(I.getType(), 1);
|
||||
Constant *CI = ConstantInt::get(I.getType(), 1);
|
||||
return ReplaceInstUsesWith(I, CI);
|
||||
}
|
||||
|
||||
@ -3008,7 +3009,7 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) {
|
||||
// if so, convert to a right shift.
|
||||
if (C->getValue().isPowerOf2()) // 0 not included in isPowerOf2
|
||||
return BinaryOperator::CreateLShr(Op0,
|
||||
Context->getConstantInt(Op0->getType(), C->getValue().logBase2()));
|
||||
ConstantInt::get(Op0->getType(), C->getValue().logBase2()));
|
||||
|
||||
// X udiv C, where C >= signbit
|
||||
if (C->getValue().isNegative()) {
|
||||
@ -3016,7 +3017,7 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) {
|
||||
ICmpInst::ICMP_ULT, Op0, C),
|
||||
I);
|
||||
return SelectInst::Create(IC, Context->getNullValue(I.getType()),
|
||||
Context->getConstantInt(I.getType(), 1));
|
||||
ConstantInt::get(I.getType(), 1));
|
||||
}
|
||||
}
|
||||
|
||||
@ -3029,7 +3030,7 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) {
|
||||
Value *N = RHSI->getOperand(1);
|
||||
const Type *NTy = N->getType();
|
||||
if (uint32_t C2 = C1.logBase2()) {
|
||||
Constant *C2V = Context->getConstantInt(NTy, C2);
|
||||
Constant *C2V = ConstantInt::get(NTy, C2);
|
||||
N = InsertNewInstBefore(BinaryOperator::CreateAdd(N, C2V, "tmp"), I);
|
||||
}
|
||||
return BinaryOperator::CreateLShr(Op0, N);
|
||||
@ -3047,13 +3048,13 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) {
|
||||
// Compute the shift amounts
|
||||
uint32_t TSA = TVA.logBase2(), FSA = FVA.logBase2();
|
||||
// Construct the "on true" case of the select
|
||||
Constant *TC = Context->getConstantInt(Op0->getType(), TSA);
|
||||
Constant *TC = ConstantInt::get(Op0->getType(), TSA);
|
||||
Instruction *TSI = BinaryOperator::CreateLShr(
|
||||
Op0, TC, SI->getName()+".t");
|
||||
TSI = InsertNewInstBefore(TSI, I);
|
||||
|
||||
// Construct the "on false" case of the select
|
||||
Constant *FC = Context->getConstantInt(Op0->getType(), FSA);
|
||||
Constant *FC = ConstantInt::get(Op0->getType(), FSA);
|
||||
Instruction *FSI = BinaryOperator::CreateLShr(
|
||||
Op0, FC, SI->getName()+".f");
|
||||
FSI = InsertNewInstBefore(FSI, I);
|
||||
@ -3577,7 +3578,7 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op,
|
||||
uint32_t BitWidth = AndRHS->getType()->getBitWidth();
|
||||
uint32_t OpRHSVal = OpRHS->getLimitedValue(BitWidth);
|
||||
APInt ShlMask(APInt::getHighBitsSet(BitWidth, BitWidth-OpRHSVal));
|
||||
ConstantInt *CI = Context->getConstantInt(AndRHS->getValue() & ShlMask);
|
||||
ConstantInt *CI = ConstantInt::get(*Context, AndRHS->getValue() & ShlMask);
|
||||
|
||||
if (CI->getValue() == ShlMask) {
|
||||
// Masking out bits that the shift already masks
|
||||
@ -3597,7 +3598,7 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op,
|
||||
uint32_t BitWidth = AndRHS->getType()->getBitWidth();
|
||||
uint32_t OpRHSVal = OpRHS->getLimitedValue(BitWidth);
|
||||
APInt ShrMask(APInt::getLowBitsSet(BitWidth, BitWidth - OpRHSVal));
|
||||
ConstantInt *CI = Context->getConstantInt(AndRHS->getValue() & ShrMask);
|
||||
ConstantInt *CI = ConstantInt::get(*Context, AndRHS->getValue() & ShrMask);
|
||||
|
||||
if (CI->getValue() == ShrMask) {
|
||||
// Masking out bits that the shift already masks.
|
||||
@ -3616,7 +3617,7 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op,
|
||||
uint32_t BitWidth = AndRHS->getType()->getBitWidth();
|
||||
uint32_t OpRHSVal = OpRHS->getLimitedValue(BitWidth);
|
||||
APInt ShrMask(APInt::getLowBitsSet(BitWidth, BitWidth - OpRHSVal));
|
||||
Constant *C = Context->getConstantInt(AndRHS->getValue() & ShrMask);
|
||||
Constant *C = ConstantInt::get(*Context, AndRHS->getValue() & ShrMask);
|
||||
if (C == AndRHS) { // Masking out bits shifted in.
|
||||
// (Val ashr C1) & C2 -> (Val lshr C1) & C2
|
||||
// Make the argument unsigned.
|
||||
@ -3856,7 +3857,7 @@ Instruction *InstCombiner::FoldAndOfICmps(Instruction &I,
|
||||
Val->getName()+".off");
|
||||
InsertNewInstBefore(Add, I);
|
||||
return new ICmpInst(*Context, ICmpInst::ICMP_UGT, Add,
|
||||
Context->getConstantInt(Add->getType(), 1));
|
||||
ConstantInt::get(Add->getType(), 1));
|
||||
}
|
||||
break; // (X != 13 & X != 15) -> no change
|
||||
}
|
||||
@ -4770,7 +4771,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
||||
InsertNewInstBefore(Or, I);
|
||||
Or->takeName(Op0);
|
||||
return BinaryOperator::CreateAnd(Or,
|
||||
Context->getConstantInt(RHS->getValue() | C1->getValue()));
|
||||
ConstantInt::get(*Context, RHS->getValue() | C1->getValue()));
|
||||
}
|
||||
|
||||
// (X ^ C1) | C2 --> (X | C2) ^ (C1&~C2)
|
||||
@ -4780,7 +4781,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
||||
InsertNewInstBefore(Or, I);
|
||||
Or->takeName(Op0);
|
||||
return BinaryOperator::CreateXor(Or,
|
||||
Context->getConstantInt(C1->getValue() & ~RHS->getValue()));
|
||||
ConstantInt::get(*Context, C1->getValue() & ~RHS->getValue()));
|
||||
}
|
||||
|
||||
// Try to fold constant and into select arguments.
|
||||
@ -5107,7 +5108,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
|
||||
if (Constant *Op0I0C = dyn_cast<Constant>(Op0I->getOperand(0))) {
|
||||
Constant *NegOp0I0C = Context->getConstantExprNeg(Op0I0C);
|
||||
Constant *ConstantRHS = Context->getConstantExprSub(NegOp0I0C,
|
||||
Context->getConstantInt(I.getType(), 1));
|
||||
ConstantInt::get(I.getType(), 1));
|
||||
return BinaryOperator::CreateAdd(Op0I->getOperand(1), ConstantRHS);
|
||||
}
|
||||
|
||||
@ -5118,12 +5119,12 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
|
||||
Constant *NegOp0CI = Context->getConstantExprNeg(Op0CI);
|
||||
return BinaryOperator::CreateSub(
|
||||
Context->getConstantExprSub(NegOp0CI,
|
||||
Context->getConstantInt(I.getType(), 1)),
|
||||
ConstantInt::get(I.getType(), 1)),
|
||||
Op0I->getOperand(0));
|
||||
} else if (RHS->getValue().isSignBit()) {
|
||||
// (X + C) ^ signbit -> (X + C + signbit)
|
||||
Constant *C =
|
||||
Context->getConstantInt(RHS->getValue() + Op0CI->getValue());
|
||||
Constant *C = ConstantInt::get(*Context,
|
||||
RHS->getValue() + Op0CI->getValue());
|
||||
return BinaryOperator::CreateAdd(Op0I->getOperand(0), C);
|
||||
|
||||
}
|
||||
@ -5327,7 +5328,7 @@ static bool AddWithOverflow(Constant *&Result, Constant *In1,
|
||||
|
||||
if (const VectorType *VTy = dyn_cast<VectorType>(In1->getType())) {
|
||||
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
|
||||
Constant *Idx = Context->getConstantInt(Type::Int32Ty, i);
|
||||
Constant *Idx = ConstantInt::get(Type::Int32Ty, i);
|
||||
if (HasAddOverflow(ExtractElement(Result, Idx, Context),
|
||||
ExtractElement(In1, Idx, Context),
|
||||
ExtractElement(In2, Idx, Context),
|
||||
@ -5363,7 +5364,7 @@ static bool SubWithOverflow(Constant *&Result, Constant *In1,
|
||||
|
||||
if (const VectorType *VTy = dyn_cast<VectorType>(In1->getType())) {
|
||||
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
|
||||
Constant *Idx = Context->getConstantInt(Type::Int32Ty, i);
|
||||
Constant *Idx = ConstantInt::get(Type::Int32Ty, i);
|
||||
if (HasSubOverflow(ExtractElement(Result, Idx, Context),
|
||||
ExtractElement(In1, Idx, Context),
|
||||
ExtractElement(In2, Idx, Context),
|
||||
@ -5405,16 +5406,17 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
|
||||
|
||||
if (ConstantInt *RC = dyn_cast<ConstantInt>(Result))
|
||||
Result =
|
||||
Context->getConstantInt(RC->getValue() + APInt(IntPtrWidth, Size));
|
||||
ConstantInt::get(*Context,
|
||||
RC->getValue() + APInt(IntPtrWidth, Size));
|
||||
else
|
||||
Result = IC.InsertNewInstBefore(
|
||||
BinaryOperator::CreateAdd(Result,
|
||||
Context->getConstantInt(IntPtrTy, Size),
|
||||
ConstantInt::get(IntPtrTy, Size),
|
||||
GEP->getName()+".offs"), I);
|
||||
continue;
|
||||
}
|
||||
|
||||
Constant *Scale = Context->getConstantInt(IntPtrTy, Size);
|
||||
Constant *Scale = ConstantInt::get(IntPtrTy, Size);
|
||||
Constant *OC =
|
||||
Context->getConstantExprIntegerCast(OpC, IntPtrTy, true /*SExt*/);
|
||||
Scale = Context->getConstantExprMul(OC, Scale);
|
||||
@ -5438,7 +5440,7 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
|
||||
Op->getName()+".c"), I);
|
||||
}
|
||||
if (Size != 1) {
|
||||
Constant *Scale = Context->getConstantInt(IntPtrTy, Size);
|
||||
Constant *Scale = ConstantInt::get(IntPtrTy, Size);
|
||||
if (Constant *OpC = dyn_cast<Constant>(Op))
|
||||
Op = Context->getConstantExprMul(OpC, Scale);
|
||||
else // We'll let instcombine(mul) convert this to a shl if possible.
|
||||
@ -5559,7 +5561,7 @@ static Value *EvaluateGEPOffsetExpression(User *GEP, Instruction &I,
|
||||
VariableIdx = CastInst::CreateIntegerCast(VariableIdx, IntPtrTy,
|
||||
true /*SExt*/,
|
||||
VariableIdx->getNameStart(), &I);
|
||||
Constant *OffsetVal = IC.getContext()->getConstantInt(IntPtrTy, NewOffs);
|
||||
Constant *OffsetVal = ConstantInt::get(IntPtrTy, NewOffs);
|
||||
return BinaryOperator::CreateAdd(VariableIdx, OffsetVal, "offset", &I);
|
||||
}
|
||||
|
||||
@ -5653,7 +5655,7 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
|
||||
|
||||
if (NumDifferences == 0) // SAME GEP?
|
||||
return ReplaceInstUsesWith(I, // No comparison is needed here.
|
||||
Context->getConstantInt(Type::Int1Ty,
|
||||
ConstantInt::get(Type::Int1Ty,
|
||||
ICmpInst::isTrueWhenEqual(Cond)));
|
||||
|
||||
else if (NumDifferences == 1) {
|
||||
@ -5985,7 +5987,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
|
||||
// icmp X, X
|
||||
if (Op0 == Op1)
|
||||
return ReplaceInstUsesWith(I, Context->getConstantInt(Type::Int1Ty,
|
||||
return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty,
|
||||
I.isTrueWhenEqual()));
|
||||
|
||||
if (isa<UndefValue>(Op1)) // X icmp undef -> undef
|
||||
@ -5997,7 +5999,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
isa<ConstantPointerNull>(Op0)) &&
|
||||
(isa<GlobalValue>(Op1) || isa<AllocaInst>(Op1) ||
|
||||
isa<ConstantPointerNull>(Op1)))
|
||||
return ReplaceInstUsesWith(I, Context->getConstantInt(Type::Int1Ty,
|
||||
return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty,
|
||||
!I.isTrueWhenEqual()));
|
||||
|
||||
// icmp's with boolean values can always be turned into bitwise operations
|
||||
@ -6141,10 +6143,10 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
// that code below can assume that Min != Max.
|
||||
if (!isa<Constant>(Op0) && Op0Min == Op0Max)
|
||||
return new ICmpInst(*Context, I.getPredicate(),
|
||||
Context->getConstantInt(Op0Min), Op1);
|
||||
ConstantInt::get(*Context, Op0Min), Op1);
|
||||
if (!isa<Constant>(Op1) && Op1Min == Op1Max)
|
||||
return new ICmpInst(*Context, I.getPredicate(), Op0,
|
||||
Context->getConstantInt(Op1Min));
|
||||
ConstantInt::get(*Context, Op1Min));
|
||||
|
||||
// Based on the range information we know about the LHS, see if we can
|
||||
// simplify this comparison. For example, (x&4) < 8 is always true.
|
||||
@ -6344,7 +6346,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
// can assume it is successful and remove the malloc.
|
||||
if (LHSI->hasOneUse() && isa<ConstantPointerNull>(RHSC)) {
|
||||
AddToWorkList(LHSI);
|
||||
return ReplaceInstUsesWith(I, Context->getConstantInt(Type::Int1Ty,
|
||||
return ReplaceInstUsesWith(I, ConstantInt::get(Type::Int1Ty,
|
||||
!I.isTrueWhenEqual()));
|
||||
}
|
||||
break;
|
||||
@ -6442,7 +6444,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
// Mask = -1 >> count-trailing-zeros(Cst).
|
||||
if (!CI->isZero() && !CI->isOne()) {
|
||||
const APInt &AP = CI->getValue();
|
||||
ConstantInt *Mask = Context->getConstantInt(
|
||||
ConstantInt *Mask = ConstantInt::get(*Context,
|
||||
APInt::getLowBitsSet(AP.getBitWidth(),
|
||||
AP.getBitWidth() -
|
||||
AP.countTrailingZeros()));
|
||||
@ -6489,7 +6491,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
|
||||
if (match(B, m_ConstantInt(C1), *Context) &&
|
||||
match(D, m_ConstantInt(C2), *Context) && Op1->hasOneUse()) {
|
||||
Constant *NC =
|
||||
Context->getConstantInt(C1->getValue() ^ C2->getValue());
|
||||
ConstantInt::get(*Context, C1->getValue() ^ C2->getValue());
|
||||
Instruction *Xor = BinaryOperator::CreateXor(C, NC, "tmp");
|
||||
return new ICmpInst(*Context, I.getPredicate(), A,
|
||||
InsertNewInstBefore(Xor, I));
|
||||
@ -6727,7 +6729,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
NewRHS.zext(SrcBits);
|
||||
NewRHS |= KnownOne;
|
||||
return new ICmpInst(*Context, ICI.getPredicate(), LHSI->getOperand(0),
|
||||
Context->getConstantInt(NewRHS));
|
||||
ConstantInt::get(*Context, NewRHS));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -6770,7 +6772,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
? ICI.getUnsignedPredicate()
|
||||
: ICI.getSignedPredicate();
|
||||
return new ICmpInst(*Context, Pred, LHSI->getOperand(0),
|
||||
Context->getConstantInt(RHSV ^ SignBit));
|
||||
ConstantInt::get(*Context, RHSV ^ SignBit));
|
||||
}
|
||||
|
||||
// (icmp u/s (xor A ~SignBit), C) -> (icmp s/u (xor C ~SignBit), A)
|
||||
@ -6781,7 +6783,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
: ICI.getSignedPredicate();
|
||||
Pred = ICI.getSwappedPredicate(Pred);
|
||||
return new ICmpInst(*Context, Pred, LHSI->getOperand(0),
|
||||
Context->getConstantInt(RHSV ^ NotSignBit));
|
||||
ConstantInt::get(*Context, RHSV ^ NotSignBit));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6810,10 +6812,10 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
NewCI.zext(BitWidth);
|
||||
Instruction *NewAnd =
|
||||
BinaryOperator::CreateAnd(Cast->getOperand(0),
|
||||
Context->getConstantInt(NewCST),LHSI->getName());
|
||||
ConstantInt::get(*Context, NewCST), LHSI->getName());
|
||||
InsertNewInstBefore(NewAnd, ICI);
|
||||
return new ICmpInst(*Context, ICI.getPredicate(), NewAnd,
|
||||
Context->getConstantInt(NewCI));
|
||||
ConstantInt::get(*Context, NewCI));
|
||||
}
|
||||
}
|
||||
|
||||
@ -6930,7 +6932,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
ShAmt);
|
||||
if (Comp != RHS) {// Comparing against a bit that we know is zero.
|
||||
bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE;
|
||||
Constant *Cst = Context->getConstantInt(Type::Int1Ty, IsICMP_NE);
|
||||
Constant *Cst = ConstantInt::get(Type::Int1Ty, IsICMP_NE);
|
||||
return ReplaceInstUsesWith(ICI, Cst);
|
||||
}
|
||||
|
||||
@ -6938,7 +6940,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
// Otherwise strength reduce the shift into an and.
|
||||
uint32_t ShAmtVal = (uint32_t)ShAmt->getLimitedValue(TypeBits);
|
||||
Constant *Mask =
|
||||
Context->getConstantInt(APInt::getLowBitsSet(TypeBits,
|
||||
ConstantInt::get(*Context, APInt::getLowBitsSet(TypeBits,
|
||||
TypeBits-ShAmtVal));
|
||||
|
||||
Instruction *AndI =
|
||||
@ -6946,7 +6948,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
Mask, LHSI->getName()+".mask");
|
||||
Value *And = InsertNewInstBefore(AndI, ICI);
|
||||
return new ICmpInst(*Context, ICI.getPredicate(), And,
|
||||
Context->getConstantInt(RHSV.lshr(ShAmtVal)));
|
||||
ConstantInt::get(*Context, RHSV.lshr(ShAmtVal)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -6955,7 +6957,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
if (LHSI->hasOneUse() &&
|
||||
isSignBitCheck(ICI.getPredicate(), RHS, TrueIfSigned)) {
|
||||
// (X << 31) <s 0 --> (X&1) != 0
|
||||
Constant *Mask = Context->getConstantInt(APInt(TypeBits, 1) <<
|
||||
Constant *Mask = ConstantInt::get(*Context, APInt(TypeBits, 1) <<
|
||||
(TypeBits-ShAmt->getZExtValue()-1));
|
||||
Instruction *AndI =
|
||||
BinaryOperator::CreateAnd(LHSI->getOperand(0),
|
||||
@ -6994,7 +6996,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
|
||||
if (Comp != RHSV) { // Comparing against a bit that we know is zero.
|
||||
bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE;
|
||||
Constant *Cst = Context->getConstantInt(Type::Int1Ty, IsICMP_NE);
|
||||
Constant *Cst = ConstantInt::get(Type::Int1Ty, IsICMP_NE);
|
||||
return ReplaceInstUsesWith(ICI, Cst);
|
||||
}
|
||||
|
||||
@ -7011,7 +7013,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
if (LHSI->hasOneUse()) {
|
||||
// Otherwise strength reduce the shift into an and.
|
||||
APInt Val(APInt::getHighBitsSet(TypeBits, TypeBits - ShAmtVal));
|
||||
Constant *Mask = Context->getConstantInt(Val);
|
||||
Constant *Mask = ConstantInt::get(*Context, Val);
|
||||
|
||||
Instruction *AndI =
|
||||
BinaryOperator::CreateAnd(LHSI->getOperand(0),
|
||||
@ -7051,18 +7053,18 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
if (ICI.isSignedPredicate()) {
|
||||
if (CR.getLower().isSignBit()) {
|
||||
return new ICmpInst(*Context, ICmpInst::ICMP_SLT, LHSI->getOperand(0),
|
||||
Context->getConstantInt(CR.getUpper()));
|
||||
ConstantInt::get(*Context, CR.getUpper()));
|
||||
} else if (CR.getUpper().isSignBit()) {
|
||||
return new ICmpInst(*Context, ICmpInst::ICMP_SGE, LHSI->getOperand(0),
|
||||
Context->getConstantInt(CR.getLower()));
|
||||
ConstantInt::get(*Context, CR.getLower()));
|
||||
}
|
||||
} else {
|
||||
if (CR.getLower().isMinValue()) {
|
||||
return new ICmpInst(*Context, ICmpInst::ICMP_ULT, LHSI->getOperand(0),
|
||||
Context->getConstantInt(CR.getUpper()));
|
||||
ConstantInt::get(*Context, CR.getUpper()));
|
||||
} else if (CR.getUpper().isMinValue()) {
|
||||
return new ICmpInst(*Context, ICmpInst::ICMP_UGE, LHSI->getOperand(0),
|
||||
Context->getConstantInt(CR.getLower()));
|
||||
ConstantInt::get(*Context, CR.getLower()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7136,7 +7138,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
Constant *NotCI = Context->getConstantExprNot(RHS);
|
||||
if (!Context->getConstantExprAnd(BOC, NotCI)->isNullValue())
|
||||
return ReplaceInstUsesWith(ICI,
|
||||
Context->getConstantInt(Type::Int1Ty,
|
||||
ConstantInt::get(Type::Int1Ty,
|
||||
isICMP_NE));
|
||||
}
|
||||
break;
|
||||
@ -7147,7 +7149,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
// comparison can never succeed!
|
||||
if ((RHSV & ~BOC->getValue()) != 0)
|
||||
return ReplaceInstUsesWith(ICI,
|
||||
Context->getConstantInt(Type::Int1Ty,
|
||||
ConstantInt::get(Type::Int1Ty,
|
||||
isICMP_NE));
|
||||
|
||||
// If we have ((X & C) == C), turn it into ((X & C) != 0).
|
||||
@ -7181,7 +7183,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
if (II->getIntrinsicID() == Intrinsic::bswap) {
|
||||
AddToWorkList(II);
|
||||
ICI.setOperand(0, II->getOperand(1));
|
||||
ICI.setOperand(1, Context->getConstantInt(RHSV.byteSwap()));
|
||||
ICI.setOperand(1, ConstantInt::get(*Context, RHSV.byteSwap()));
|
||||
return &ICI;
|
||||
}
|
||||
}
|
||||
@ -7411,7 +7413,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
if (I.getOpcode() != Instruction::AShr)
|
||||
return ReplaceInstUsesWith(I, Context->getNullValue(Op0->getType()));
|
||||
else {
|
||||
I.setOperand(1, Context->getConstantInt(I.getType(), TypeBits-1));
|
||||
I.setOperand(1, ConstantInt::get(I.getType(), TypeBits-1));
|
||||
return &I;
|
||||
}
|
||||
}
|
||||
@ -7467,7 +7469,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
}
|
||||
|
||||
Instruction *And =
|
||||
BinaryOperator::CreateAnd(NSh, Context->getConstantInt(MaskV),
|
||||
BinaryOperator::CreateAnd(NSh, ConstantInt::get(*Context, MaskV),
|
||||
TI->getName());
|
||||
InsertNewInstBefore(And, I); // shift1 & 0x00FF
|
||||
|
||||
@ -7501,7 +7503,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
Op0BO->getOperand(1)->getName());
|
||||
InsertNewInstBefore(X, I); // (X + (Y << C))
|
||||
uint32_t Op1Val = Op1->getLimitedValue(TypeBits);
|
||||
return BinaryOperator::CreateAnd(X, Context->getConstantInt(
|
||||
return BinaryOperator::CreateAnd(X, ConstantInt::get(*Context,
|
||||
APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
|
||||
}
|
||||
|
||||
@ -7541,7 +7543,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
Op0BO->getOperand(0)->getName());
|
||||
InsertNewInstBefore(X, I); // (X + (Y << C))
|
||||
uint32_t Op1Val = Op1->getLimitedValue(TypeBits);
|
||||
return BinaryOperator::CreateAnd(X, Context->getConstantInt(
|
||||
return BinaryOperator::CreateAnd(X, ConstantInt::get(*Context,
|
||||
APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
|
||||
}
|
||||
|
||||
@ -7642,14 +7644,14 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
}
|
||||
|
||||
return BinaryOperator::Create(I.getOpcode(), X,
|
||||
Context->getConstantInt(Ty, AmtSum));
|
||||
ConstantInt::get(Ty, AmtSum));
|
||||
} else if (ShiftOp->getOpcode() == Instruction::LShr &&
|
||||
I.getOpcode() == Instruction::AShr) {
|
||||
if (AmtSum >= TypeBits)
|
||||
return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
|
||||
|
||||
// ((X >>u C1) >>s C2) -> (X >>u (C1+C2)) since C1 != 0.
|
||||
return BinaryOperator::CreateLShr(X, Context->getConstantInt(Ty, AmtSum));
|
||||
return BinaryOperator::CreateLShr(X, ConstantInt::get(Ty, AmtSum));
|
||||
} else if (ShiftOp->getOpcode() == Instruction::AShr &&
|
||||
I.getOpcode() == Instruction::LShr) {
|
||||
// ((X >>s C1) >>u C2) -> ((X >>s (C1+C2)) & mask) since C1 != 0.
|
||||
@ -7657,11 +7659,11 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
AmtSum = TypeBits-1;
|
||||
|
||||
Instruction *Shift =
|
||||
BinaryOperator::CreateAShr(X, Context->getConstantInt(Ty, AmtSum));
|
||||
BinaryOperator::CreateAShr(X, ConstantInt::get(Ty, AmtSum));
|
||||
InsertNewInstBefore(Shift, I);
|
||||
|
||||
APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt2));
|
||||
return BinaryOperator::CreateAnd(Shift, Context->getConstantInt(Mask));
|
||||
return BinaryOperator::CreateAnd(Shift, ConstantInt::get(*Context, Mask));
|
||||
}
|
||||
|
||||
// Okay, if we get here, one shift must be left, and the other shift must be
|
||||
@ -7670,12 +7672,12 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
// If we have ((X >>? C) << C), turn this into X & (-1 << C).
|
||||
if (I.getOpcode() == Instruction::Shl) {
|
||||
APInt Mask(APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt1));
|
||||
return BinaryOperator::CreateAnd(X, Context->getConstantInt(Mask));
|
||||
return BinaryOperator::CreateAnd(X, ConstantInt::get(*Context, Mask));
|
||||
}
|
||||
// If we have ((X << C) >>u C), turn this into X & (-1 >>u C).
|
||||
if (I.getOpcode() == Instruction::LShr) {
|
||||
APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt1));
|
||||
return BinaryOperator::CreateAnd(X, Context->getConstantInt(Mask));
|
||||
return BinaryOperator::CreateAnd(X, ConstantInt::get(*Context, Mask));
|
||||
}
|
||||
// We can simplify ((X << C) >>s C) into a trunc + sext.
|
||||
// NOTE: we could do this for any C, but that would make 'unusual' integer
|
||||
@ -7707,22 +7709,24 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
assert(ShiftOp->getOpcode() == Instruction::LShr ||
|
||||
ShiftOp->getOpcode() == Instruction::AShr);
|
||||
Instruction *Shift =
|
||||
BinaryOperator::CreateShl(X, Context->getConstantInt(Ty, ShiftDiff));
|
||||
BinaryOperator::CreateShl(X, ConstantInt::get(Ty, ShiftDiff));
|
||||
InsertNewInstBefore(Shift, I);
|
||||
|
||||
APInt Mask(APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt2));
|
||||
return BinaryOperator::CreateAnd(Shift, Context->getConstantInt(Mask));
|
||||
return BinaryOperator::CreateAnd(Shift,
|
||||
ConstantInt::get(*Context, Mask));
|
||||
}
|
||||
|
||||
// (X << C1) >>u C2 --> X >>u (C2-C1) & (-1 >> C2)
|
||||
if (I.getOpcode() == Instruction::LShr) {
|
||||
assert(ShiftOp->getOpcode() == Instruction::Shl);
|
||||
Instruction *Shift =
|
||||
BinaryOperator::CreateLShr(X, Context->getConstantInt(Ty, ShiftDiff));
|
||||
BinaryOperator::CreateLShr(X, ConstantInt::get(Ty, ShiftDiff));
|
||||
InsertNewInstBefore(Shift, I);
|
||||
|
||||
APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt2));
|
||||
return BinaryOperator::CreateAnd(Shift, Context->getConstantInt(Mask));
|
||||
return BinaryOperator::CreateAnd(Shift,
|
||||
ConstantInt::get(*Context, Mask));
|
||||
}
|
||||
|
||||
// We can't handle (X << C1) >>s C2, it shifts arbitrary bits in.
|
||||
@ -7736,22 +7740,24 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
|
||||
ShiftOp->getOpcode() == Instruction::AShr);
|
||||
Instruction *Shift =
|
||||
BinaryOperator::Create(ShiftOp->getOpcode(), X,
|
||||
Context->getConstantInt(Ty, ShiftDiff));
|
||||
ConstantInt::get(Ty, ShiftDiff));
|
||||
InsertNewInstBefore(Shift, I);
|
||||
|
||||
APInt Mask(APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt2));
|
||||
return BinaryOperator::CreateAnd(Shift, Context->getConstantInt(Mask));
|
||||
return BinaryOperator::CreateAnd(Shift,
|
||||
ConstantInt::get(*Context, Mask));
|
||||
}
|
||||
|
||||
// (X << C1) >>u C2 --> X << (C1-C2) & (-1 >> C2)
|
||||
if (I.getOpcode() == Instruction::LShr) {
|
||||
assert(ShiftOp->getOpcode() == Instruction::Shl);
|
||||
Instruction *Shift =
|
||||
BinaryOperator::CreateShl(X, Context->getConstantInt(Ty, ShiftDiff));
|
||||
BinaryOperator::CreateShl(X, ConstantInt::get(Ty, ShiftDiff));
|
||||
InsertNewInstBefore(Shift, I);
|
||||
|
||||
APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt2));
|
||||
return BinaryOperator::CreateAnd(Shift, Context->getConstantInt(Mask));
|
||||
return BinaryOperator::CreateAnd(Shift,
|
||||
ConstantInt::get(*Context, Mask));
|
||||
}
|
||||
|
||||
// We can't handle (X << C1) >>a C2, it shifts arbitrary bits in.
|
||||
@ -7771,7 +7777,7 @@ static Value *DecomposeSimpleLinearExpr(Value *Val, unsigned &Scale,
|
||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) {
|
||||
Offset = CI->getZExtValue();
|
||||
Scale = 0;
|
||||
return Context->getConstantInt(Type::Int32Ty, 0);
|
||||
return ConstantInt::get(Type::Int32Ty, 0);
|
||||
} else if (BinaryOperator *I = dyn_cast<BinaryOperator>(Val)) {
|
||||
if (ConstantInt *RHS = dyn_cast<ConstantInt>(I->getOperand(1))) {
|
||||
if (I->getOpcode() == Instruction::Shl) {
|
||||
@ -7868,7 +7874,7 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI,
|
||||
Amt = NumElements;
|
||||
} else {
|
||||
// If the allocation size is constant, form a constant mul expression
|
||||
Amt = Context->getConstantInt(Type::Int32Ty, Scale);
|
||||
Amt = ConstantInt::get(Type::Int32Ty, Scale);
|
||||
if (isa<ConstantInt>(NumElements))
|
||||
Amt = Context->getConstantExprMul(cast<ConstantInt>(NumElements),
|
||||
cast<ConstantInt>(Amt));
|
||||
@ -7880,7 +7886,7 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI,
|
||||
}
|
||||
|
||||
if (int Offset = (AllocElTySize*ArrayOffset)/CastElTySize) {
|
||||
Value *Off = Context->getConstantInt(Type::Int32Ty, Offset, true);
|
||||
Value *Off = ConstantInt::get(Type::Int32Ty, Offset, true);
|
||||
Instruction *Tmp = BinaryOperator::CreateAdd(Amt, Off, "tmp");
|
||||
Amt = InsertNewInstBefore(Tmp, AI);
|
||||
}
|
||||
@ -8181,7 +8187,7 @@ static const Type *FindElementAtOffset(const Type *Ty, int64_t Offset,
|
||||
assert((uint64_t)Offset < (uint64_t)TySize && "Out of range offset");
|
||||
}
|
||||
|
||||
NewIndices.push_back(Context->getConstantInt(IntPtrTy, FirstIdx));
|
||||
NewIndices.push_back(ConstantInt::get(IntPtrTy, FirstIdx));
|
||||
|
||||
// Index into the types. If we fail, set OrigBase to null.
|
||||
while (Offset) {
|
||||
@ -8195,14 +8201,14 @@ static const Type *FindElementAtOffset(const Type *Ty, int64_t Offset,
|
||||
"Offset must stay within the indexed type");
|
||||
|
||||
unsigned Elt = SL->getElementContainingOffset(Offset);
|
||||
NewIndices.push_back(Context->getConstantInt(Type::Int32Ty, Elt));
|
||||
NewIndices.push_back(ConstantInt::get(Type::Int32Ty, Elt));
|
||||
|
||||
Offset -= SL->getElementOffset(Elt);
|
||||
Ty = STy->getElementType(Elt);
|
||||
} else if (const ArrayType *AT = dyn_cast<ArrayType>(Ty)) {
|
||||
uint64_t EltSize = TD->getTypeAllocSize(AT->getElementType());
|
||||
assert(EltSize && "Cannot index into a zero-sized array");
|
||||
NewIndices.push_back(Context->getConstantInt(IntPtrTy,Offset/EltSize));
|
||||
NewIndices.push_back(ConstantInt::get(IntPtrTy,Offset/EltSize));
|
||||
Offset %= EltSize;
|
||||
Ty = AT->getElementType();
|
||||
} else {
|
||||
@ -8399,8 +8405,8 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
|
||||
return ReplaceInstUsesWith(CI, Res);
|
||||
|
||||
// We need to emit an AND to clear the high bits.
|
||||
Constant *C = Context->getConstantInt(APInt::getLowBitsSet(DestBitSize,
|
||||
SrcBitSize));
|
||||
Constant *C = ConstantInt::get(*Context,
|
||||
APInt::getLowBitsSet(DestBitSize, SrcBitSize));
|
||||
return BinaryOperator::CreateAnd(Res, C);
|
||||
}
|
||||
case Instruction::SExt: {
|
||||
@ -8447,7 +8453,7 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
|
||||
(!Op0->hasOneUse() || !isa<CmpInst>(Op0))) {
|
||||
Value *New = InsertCastBefore(Instruction::ZExt, Op0, DestTy, CI);
|
||||
return BinaryOperator::CreateXor(New,
|
||||
Context->getConstantInt(CI.getType(), 1));
|
||||
ConstantInt::get(CI.getType(), 1));
|
||||
}
|
||||
break;
|
||||
|
||||
@ -8477,7 +8483,7 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
|
||||
|
||||
// Canonicalize trunc x to i1 -> (icmp ne (and x, 1), 0)
|
||||
if (DestBitWidth == 1) {
|
||||
Constant *One = Context->getConstantInt(Src->getType(), 1);
|
||||
Constant *One = ConstantInt::get(Src->getType(), 1);
|
||||
Src = InsertNewInstBefore(BinaryOperator::CreateAnd(Src, One, "tmp"), CI);
|
||||
Value *Zero = Context->getNullValue(Src->getType());
|
||||
return new ICmpInst(*Context, ICmpInst::ICMP_NE, Src, Zero);
|
||||
@ -8524,7 +8530,7 @@ Instruction *InstCombiner::transformZExtICmp(ICmpInst *ICI, Instruction &CI,
|
||||
if (!DoXform) return ICI;
|
||||
|
||||
Value *In = ICI->getOperand(0);
|
||||
Value *Sh = Context->getConstantInt(In->getType(),
|
||||
Value *Sh = ConstantInt::get(In->getType(),
|
||||
In->getType()->getScalarSizeInBits()-1);
|
||||
In = InsertNewInstBefore(BinaryOperator::CreateLShr(In, Sh,
|
||||
In->getName()+".lobit"),
|
||||
@ -8534,7 +8540,7 @@ Instruction *InstCombiner::transformZExtICmp(ICmpInst *ICI, Instruction &CI,
|
||||
false/*ZExt*/, "tmp", &CI);
|
||||
|
||||
if (ICI->getPredicate() == ICmpInst::ICMP_SGT) {
|
||||
Constant *One = Context->getConstantInt(In->getType(), 1);
|
||||
Constant *One = ConstantInt::get(In->getType(), 1);
|
||||
In = InsertNewInstBefore(BinaryOperator::CreateXor(In, One,
|
||||
In->getName()+".not"),
|
||||
CI);
|
||||
@ -8570,7 +8576,7 @@ Instruction *InstCombiner::transformZExtICmp(ICmpInst *ICI, Instruction &CI,
|
||||
if (Op1CV != 0 && (Op1CV != KnownZeroMask)) {
|
||||
// (X&4) == 2 --> false
|
||||
// (X&4) != 2 --> true
|
||||
Constant *Res = Context->getConstantInt(Type::Int1Ty, isNE);
|
||||
Constant *Res = ConstantInt::get(Type::Int1Ty, isNE);
|
||||
Res = Context->getConstantExprZExt(Res, CI.getType());
|
||||
return ReplaceInstUsesWith(CI, Res);
|
||||
}
|
||||
@ -8581,12 +8587,12 @@ Instruction *InstCombiner::transformZExtICmp(ICmpInst *ICI, Instruction &CI,
|
||||
// Perform a logical shr by shiftamt.
|
||||
// Insert the shift to put the result in the low bit.
|
||||
In = InsertNewInstBefore(BinaryOperator::CreateLShr(In,
|
||||
Context->getConstantInt(In->getType(), ShiftAmt),
|
||||
ConstantInt::get(In->getType(), ShiftAmt),
|
||||
In->getName()+".lobit"), CI);
|
||||
}
|
||||
|
||||
if ((Op1CV != 0) == isNE) { // Toggle the low bit.
|
||||
Constant *One = Context->getConstantInt(In->getType(), 1);
|
||||
Constant *One = ConstantInt::get(In->getType(), 1);
|
||||
In = BinaryOperator::CreateXor(In, One, "tmp");
|
||||
InsertNewInstBefore(cast<Instruction>(In), CI);
|
||||
}
|
||||
@ -8625,21 +8631,21 @@ Instruction *InstCombiner::visitZExt(ZExtInst &CI) {
|
||||
// SrcSize > DstSize: trunc(a) & mask
|
||||
if (SrcSize < DstSize) {
|
||||
APInt AndValue(APInt::getLowBitsSet(SrcSize, MidSize));
|
||||
Constant *AndConst = Context->getConstantInt(A->getType(), AndValue);
|
||||
Constant *AndConst = ConstantInt::get(A->getType(), AndValue);
|
||||
Instruction *And =
|
||||
BinaryOperator::CreateAnd(A, AndConst, CSrc->getName()+".mask");
|
||||
InsertNewInstBefore(And, CI);
|
||||
return new ZExtInst(And, CI.getType());
|
||||
} else if (SrcSize == DstSize) {
|
||||
APInt AndValue(APInt::getLowBitsSet(SrcSize, MidSize));
|
||||
return BinaryOperator::CreateAnd(A, Context->getConstantInt(A->getType(),
|
||||
return BinaryOperator::CreateAnd(A, ConstantInt::get(A->getType(),
|
||||
AndValue));
|
||||
} else if (SrcSize > DstSize) {
|
||||
Instruction *Trunc = new TruncInst(A, CI.getType(), "tmp");
|
||||
InsertNewInstBefore(Trunc, CI);
|
||||
APInt AndValue(APInt::getLowBitsSet(DstSize, MidSize));
|
||||
return BinaryOperator::CreateAnd(Trunc,
|
||||
Context->getConstantInt(Trunc->getType(),
|
||||
ConstantInt::get(Trunc->getType(),
|
||||
AndValue));
|
||||
}
|
||||
}
|
||||
@ -8754,7 +8760,7 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) {
|
||||
unsigned MidSize = Src->getType()->getScalarSizeInBits();
|
||||
unsigned SrcDstSize = CI.getType()->getScalarSizeInBits();
|
||||
unsigned ShAmt = CA->getZExtValue()+SrcDstSize-MidSize;
|
||||
Constant *ShAmtV = Context->getConstantInt(CI.getType(), ShAmt);
|
||||
Constant *ShAmtV = ConstantInt::get(CI.getType(), ShAmt);
|
||||
I = InsertNewInstBefore(BinaryOperator::CreateShl(I, ShAmtV,
|
||||
CI.getName()), CI);
|
||||
return BinaryOperator::CreateAShr(I, ShAmtV);
|
||||
@ -9089,7 +9095,7 @@ static Constant *GetSelectFoldableConstant(Instruction *I,
|
||||
case Instruction::And:
|
||||
return Context->getAllOnesValue(I->getType());
|
||||
case Instruction::Mul:
|
||||
return Context->getConstantInt(I->getType(), 1);
|
||||
return ConstantInt::get(I->getType(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9322,7 +9328,7 @@ Instruction *InstCombiner::visitSelectInstWithICmp(SelectInst &SI,
|
||||
if ((Pred == ICmpInst::ICMP_SLT && Op1CV == 0) ||
|
||||
(Pred == ICmpInst::ICMP_SGT && Op1CV.isAllOnesValue())) {
|
||||
Value *In = ICI->getOperand(0);
|
||||
Value *Sh = Context->getConstantInt(In->getType(),
|
||||
Value *Sh = ConstantInt::get(In->getType(),
|
||||
In->getType()->getScalarSizeInBits()-1);
|
||||
In = InsertNewInstBefore(BinaryOperator::CreateAShr(In, Sh,
|
||||
In->getName()+".lobit"),
|
||||
@ -9674,7 +9680,7 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
|
||||
unsigned CopyAlign = MI->getAlignment();
|
||||
|
||||
if (CopyAlign < MinAlign) {
|
||||
MI->setAlignment(Context->getConstantInt(MI->getAlignmentType(),
|
||||
MI->setAlignment(ConstantInt::get(MI->getAlignmentType(),
|
||||
MinAlign, false));
|
||||
return MI;
|
||||
}
|
||||
@ -9749,7 +9755,7 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
|
||||
Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) {
|
||||
unsigned Alignment = GetOrEnforceKnownAlignment(MI->getDest());
|
||||
if (MI->getAlignment() < Alignment) {
|
||||
MI->setAlignment(Context->getConstantInt(MI->getAlignmentType(),
|
||||
MI->setAlignment(ConstantInt::get(MI->getAlignmentType(),
|
||||
Alignment, false));
|
||||
return MI;
|
||||
}
|
||||
@ -9777,7 +9783,7 @@ Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) {
|
||||
|
||||
// Extract the fill value and store.
|
||||
uint64_t Fill = FillC->getZExtValue()*0x0101010101010101ULL;
|
||||
InsertNewInstBefore(new StoreInst(Context->getConstantInt(ITy, Fill),
|
||||
InsertNewInstBefore(new StoreInst(ConstantInt::get(ITy, Fill),
|
||||
Dest, false, Alignment), *MI);
|
||||
|
||||
// Set the size of the copy to 0, it will be deleted on the next iteration.
|
||||
@ -9950,14 +9956,14 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
||||
if (ExtractedElts[Idx] == 0) {
|
||||
Instruction *Elt =
|
||||
new ExtractElementInst(Idx < 16 ? Op0 : Op1,
|
||||
Context->getConstantInt(Type::Int32Ty, Idx&15, false), "tmp");
|
||||
ConstantInt::get(Type::Int32Ty, Idx&15, false), "tmp");
|
||||
InsertNewInstBefore(Elt, CI);
|
||||
ExtractedElts[Idx] = Elt;
|
||||
}
|
||||
|
||||
// Insert this value into the result vector.
|
||||
Result = InsertElementInst::Create(Result, ExtractedElts[Idx],
|
||||
Context->getConstantInt(Type::Int32Ty, i, false),
|
||||
ConstantInt::get(Type::Int32Ty, i, false),
|
||||
"tmp");
|
||||
InsertNewInstBefore(cast<Instruction>(Result), CI);
|
||||
}
|
||||
@ -11230,16 +11236,16 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
||||
if (ArrayEltSize == 1) {
|
||||
NewIdx = GEP.getOperand(1);
|
||||
Scale =
|
||||
Context->getConstantInt(cast<IntegerType>(NewIdx->getType()), 1);
|
||||
ConstantInt::get(cast<IntegerType>(NewIdx->getType()), 1);
|
||||
} else if (ConstantInt *CI = dyn_cast<ConstantInt>(GEP.getOperand(1))) {
|
||||
NewIdx = Context->getConstantInt(CI->getType(), 1);
|
||||
NewIdx = ConstantInt::get(CI->getType(), 1);
|
||||
Scale = CI;
|
||||
} else if (Instruction *Inst =dyn_cast<Instruction>(GEP.getOperand(1))){
|
||||
if (Inst->getOpcode() == Instruction::Shl &&
|
||||
isa<ConstantInt>(Inst->getOperand(1))) {
|
||||
ConstantInt *ShAmt = cast<ConstantInt>(Inst->getOperand(1));
|
||||
uint32_t ShAmtVal = ShAmt->getLimitedValue(64);
|
||||
Scale = Context->getConstantInt(cast<IntegerType>(Inst->getType()),
|
||||
Scale = ConstantInt::get(cast<IntegerType>(Inst->getType()),
|
||||
1ULL << ShAmtVal);
|
||||
NewIdx = Inst->getOperand(0);
|
||||
} else if (Inst->getOpcode() == Instruction::Mul &&
|
||||
@ -11255,7 +11261,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
||||
// operation after making sure Scale doesn't have the sign bit set.
|
||||
if (ArrayEltSize && Scale && Scale->getSExtValue() >= 0LL &&
|
||||
Scale->getZExtValue() % ArrayEltSize == 0) {
|
||||
Scale = Context->getConstantInt(Scale->getType(),
|
||||
Scale = ConstantInt::get(Scale->getType(),
|
||||
Scale->getZExtValue() / ArrayEltSize);
|
||||
if (Scale->getZExtValue() != 1) {
|
||||
Constant *C =
|
||||
@ -11466,7 +11472,7 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI,
|
||||
SingleChar = 0;
|
||||
StrVal = (StrVal << 8) | SingleChar;
|
||||
}
|
||||
Value *NL = Context->getConstantInt(StrVal);
|
||||
Value *NL = ConstantInt::get(*Context, StrVal);
|
||||
return IC.ReplaceInstUsesWith(LI, NL);
|
||||
}
|
||||
}
|
||||
@ -12462,7 +12468,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
|
||||
return ReplaceInstUsesWith(EI, Context->getUndef(EI.getType()));
|
||||
}
|
||||
return new ExtractElementInst(Src,
|
||||
Context->getConstantInt(Type::Int32Ty, SrcIdx, false));
|
||||
ConstantInt::get(Type::Int32Ty, SrcIdx, false));
|
||||
}
|
||||
}
|
||||
// FIXME: Canonicalize extractelement(bitcast) -> bitcast(extractelement)
|
||||
@ -12485,11 +12491,11 @@ static bool CollectSingleShuffleElements(Value *V, Value *LHS, Value *RHS,
|
||||
return true;
|
||||
} else if (V == LHS) {
|
||||
for (unsigned i = 0; i != NumElts; ++i)
|
||||
Mask.push_back(Context->getConstantInt(Type::Int32Ty, i));
|
||||
Mask.push_back(ConstantInt::get(Type::Int32Ty, i));
|
||||
return true;
|
||||
} else if (V == RHS) {
|
||||
for (unsigned i = 0; i != NumElts; ++i)
|
||||
Mask.push_back(Context->getConstantInt(Type::Int32Ty, i+NumElts));
|
||||
Mask.push_back(ConstantInt::get(Type::Int32Ty, i+NumElts));
|
||||
return true;
|
||||
} else if (InsertElementInst *IEI = dyn_cast<InsertElementInst>(V)) {
|
||||
// If this is an insert of an extract from some other vector, include it.
|
||||
@ -12523,11 +12529,11 @@ static bool CollectSingleShuffleElements(Value *V, Value *LHS, Value *RHS,
|
||||
// If so, update the mask to reflect the inserted value.
|
||||
if (EI->getOperand(0) == LHS) {
|
||||
Mask[InsertedIdx % NumElts] =
|
||||
Context->getConstantInt(Type::Int32Ty, ExtractedIdx);
|
||||
ConstantInt::get(Type::Int32Ty, ExtractedIdx);
|
||||
} else {
|
||||
assert(EI->getOperand(0) == RHS);
|
||||
Mask[InsertedIdx % NumElts] =
|
||||
Context->getConstantInt(Type::Int32Ty, ExtractedIdx+NumElts);
|
||||
ConstantInt::get(Type::Int32Ty, ExtractedIdx+NumElts);
|
||||
|
||||
}
|
||||
return true;
|
||||
@ -12555,7 +12561,7 @@ static Value *CollectShuffleElements(Value *V, std::vector<Constant*> &Mask,
|
||||
Mask.assign(NumElts, Context->getUndef(Type::Int32Ty));
|
||||
return V;
|
||||
} else if (isa<ConstantAggregateZero>(V)) {
|
||||
Mask.assign(NumElts, Context->getConstantInt(Type::Int32Ty, 0));
|
||||
Mask.assign(NumElts, ConstantInt::get(Type::Int32Ty, 0));
|
||||
return V;
|
||||
} else if (InsertElementInst *IEI = dyn_cast<InsertElementInst>(V)) {
|
||||
// If this is an insert of an extract from some other vector, include it.
|
||||
@ -12576,7 +12582,7 @@ static Value *CollectShuffleElements(Value *V, std::vector<Constant*> &Mask,
|
||||
RHS = EI->getOperand(0);
|
||||
Value *V = CollectShuffleElements(VecOp, Mask, RHS, Context);
|
||||
Mask[InsertedIdx % NumElts] =
|
||||
Context->getConstantInt(Type::Int32Ty, NumElts+ExtractedIdx);
|
||||
ConstantInt::get(Type::Int32Ty, NumElts+ExtractedIdx);
|
||||
return V;
|
||||
}
|
||||
|
||||
@ -12586,7 +12592,7 @@ static Value *CollectShuffleElements(Value *V, std::vector<Constant*> &Mask,
|
||||
// Everything but the extracted element is replaced with the RHS.
|
||||
for (unsigned i = 0; i != NumElts; ++i) {
|
||||
if (i != InsertedIdx)
|
||||
Mask[i] = Context->getConstantInt(Type::Int32Ty, NumElts+i);
|
||||
Mask[i] = ConstantInt::get(Type::Int32Ty, NumElts+i);
|
||||
}
|
||||
return V;
|
||||
}
|
||||
@ -12604,7 +12610,7 @@ static Value *CollectShuffleElements(Value *V, std::vector<Constant*> &Mask,
|
||||
|
||||
// Otherwise, can't do anything fancy. Return an identity vector.
|
||||
for (unsigned i = 0; i != NumElts; ++i)
|
||||
Mask.push_back(Context->getConstantInt(Type::Int32Ty, i));
|
||||
Mask.push_back(ConstantInt::get(Type::Int32Ty, i));
|
||||
return V;
|
||||
}
|
||||
|
||||
@ -12651,11 +12657,11 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
|
||||
Mask.assign(NumVectorElts, Context->getUndef(Type::Int32Ty));
|
||||
else {
|
||||
assert(isa<ConstantAggregateZero>(VecOp) && "Unknown thing");
|
||||
Mask.assign(NumVectorElts, Context->getConstantInt(Type::Int32Ty,
|
||||
Mask.assign(NumVectorElts, ConstantInt::get(Type::Int32Ty,
|
||||
NumVectorElts));
|
||||
}
|
||||
Mask[InsertedIdx] =
|
||||
Context->getConstantInt(Type::Int32Ty, ExtractedIdx);
|
||||
ConstantInt::get(Type::Int32Ty, ExtractedIdx);
|
||||
return new ShuffleVectorInst(EI->getOperand(0), VecOp,
|
||||
Context->getConstantVector(Mask));
|
||||
}
|
||||
@ -12728,7 +12734,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
|
||||
Elts.push_back(Context->getUndef(Type::Int32Ty));
|
||||
} else {
|
||||
Mask[i] = Mask[i] % e; // Force to LHS.
|
||||
Elts.push_back(Context->getConstantInt(Type::Int32Ty, Mask[i]));
|
||||
Elts.push_back(ConstantInt::get(Type::Int32Ty, Mask[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12786,7 +12792,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
|
||||
if (NewMask[i] >= LHSInNElts*2) {
|
||||
Elts.push_back(Context->getUndef(Type::Int32Ty));
|
||||
} else {
|
||||
Elts.push_back(Context->getConstantInt(Type::Int32Ty, NewMask[i]));
|
||||
Elts.push_back(ConstantInt::get(Type::Int32Ty, NewMask[i]));
|
||||
}
|
||||
}
|
||||
return new ShuffleVectorInst(LHSSVI->getOperand(0),
|
||||
|
@ -434,8 +434,7 @@ bool JumpThreading::ProcessBranchOnDuplicateCond(BasicBlock *PredBB,
|
||||
<< "' folding condition to '" << BranchDir << "': "
|
||||
<< *BB->getTerminator();
|
||||
++NumFolds;
|
||||
DestBI->setCondition(BB->getContext().getConstantInt(Type::Int1Ty,
|
||||
BranchDir));
|
||||
DestBI->setCondition(ConstantInt::get(Type::Int1Ty, BranchDir));
|
||||
ConstantFoldTerminator(BB);
|
||||
return true;
|
||||
}
|
||||
@ -757,7 +756,7 @@ bool JumpThreading::ProcessBranchOnLogical(Value *V, BasicBlock *BB,
|
||||
// We can only do the simplification for phi nodes of 'false' with AND or
|
||||
// 'true' with OR. See if we have any entries in the phi for this.
|
||||
unsigned PredNo = ~0U;
|
||||
ConstantInt *PredCst = V->getContext().getConstantInt(Type::Int1Ty, !isAnd);
|
||||
ConstantInt *PredCst = ConstantInt::get(Type::Int1Ty, !isAnd);
|
||||
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
|
||||
if (PN->getIncomingValue(i) == PredCst) {
|
||||
PredNo = i;
|
||||
|
@ -295,14 +295,14 @@ static bool isUsedOutsideLoop(Value *V, Loop *L) {
|
||||
// Return V+1
|
||||
static Value *getPlusOne(Value *V, bool Sign, Instruction *InsertPt,
|
||||
LLVMContext &Context) {
|
||||
Constant *One = Context.getConstantInt(V->getType(), 1, Sign);
|
||||
Constant *One = ConstantInt::get(V->getType(), 1, Sign);
|
||||
return BinaryOperator::CreateAdd(V, One, "lsp", InsertPt);
|
||||
}
|
||||
|
||||
// Return V-1
|
||||
static Value *getMinusOne(Value *V, bool Sign, Instruction *InsertPt,
|
||||
LLVMContext &Context) {
|
||||
Constant *One = Context.getConstantInt(V->getType(), 1, Sign);
|
||||
Constant *One = ConstantInt::get(V->getType(), 1, Sign);
|
||||
return BinaryOperator::CreateSub(V, One, "lsp", InsertPt);
|
||||
}
|
||||
|
||||
|
@ -1991,9 +1991,9 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond,
|
||||
|
||||
NewStride = &IU->StrideOrder[i];
|
||||
if (!isa<PointerType>(NewCmpTy))
|
||||
NewCmpRHS = Context.getConstantInt(NewCmpTy, NewCmpVal);
|
||||
NewCmpRHS = ConstantInt::get(NewCmpTy, NewCmpVal);
|
||||
else {
|
||||
Constant *CI = Context.getConstantInt(NewCmpIntTy, NewCmpVal);
|
||||
Constant *CI = ConstantInt::get(NewCmpIntTy, NewCmpVal);
|
||||
NewCmpRHS = Context.getConstantExprIntToPtr(CI, NewCmpTy);
|
||||
}
|
||||
NewOffset = TyBits == NewTyBits
|
||||
@ -2432,8 +2432,6 @@ void LoopStrengthReduce::OptimizeLoopCountIV(Loop *L) {
|
||||
if (!ExitingBlock)
|
||||
return; // More than one block exiting!
|
||||
|
||||
LLVMContext &Context = ExitingBlock->getContext();
|
||||
|
||||
// Okay, we've computed the exiting block. See what condition causes us to
|
||||
// exit.
|
||||
//
|
||||
@ -2506,7 +2504,7 @@ void LoopStrengthReduce::OptimizeLoopCountIV(Loop *L) {
|
||||
Value *startVal = phi->getIncomingValue(inBlock);
|
||||
Value *endVal = Cond->getOperand(1);
|
||||
// FIXME check for case where both are constant
|
||||
Constant* Zero = Context.getConstantInt(Cond->getOperand(1)->getType(), 0);
|
||||
Constant* Zero = ConstantInt::get(Cond->getOperand(1)->getType(), 0);
|
||||
BinaryOperator *NewStartVal =
|
||||
BinaryOperator::Create(Instruction::Sub, endVal, startVal,
|
||||
"tmp", PreInsertPt);
|
||||
|
@ -911,7 +911,7 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC,
|
||||
if (IsEqual)
|
||||
Replacement = Val;
|
||||
else
|
||||
Replacement = Context.getConstantInt(Type::Int1Ty,
|
||||
Replacement = ConstantInt::get(Type::Int1Ty,
|
||||
!cast<ConstantInt>(Val)->getZExtValue());
|
||||
|
||||
for (unsigned i = 0, e = Users.size(); i != e; ++i)
|
||||
|
@ -69,7 +69,7 @@ static Value *isBytewiseValue(Value *V, LLVMContext& Context) {
|
||||
if (Val != Val2)
|
||||
return 0;
|
||||
}
|
||||
return Context.getConstantInt(Val);
|
||||
return ConstantInt::get(Context, Val);
|
||||
}
|
||||
}
|
||||
|
||||
@ -448,9 +448,9 @@ bool MemCpyOpt::processStore(StoreInst *SI, BasicBlock::iterator& BBI) {
|
||||
Value *Ops[] = {
|
||||
StartPtr, ByteVal, // Start, value
|
||||
// size
|
||||
SI->getContext().getConstantInt(Type::Int64Ty, Range.End-Range.Start),
|
||||
ConstantInt::get(Type::Int64Ty, Range.End-Range.Start),
|
||||
// align
|
||||
SI->getContext().getConstantInt(Type::Int32Ty, Range.Alignment)
|
||||
ConstantInt::get(Type::Int32Ty, Range.Alignment)
|
||||
};
|
||||
Value *C = CallInst::Create(MemSetF, Ops, Ops+4, "", InsertPt);
|
||||
DEBUG(cerr << "Replace stores:\n";
|
||||
|
@ -1169,7 +1169,8 @@ namespace {
|
||||
Value *V = VN.value(n); // XXX: redesign worklist.
|
||||
const Type *Ty = V->getType();
|
||||
if (Ty->isInteger()) {
|
||||
addToWorklist(V, Context->getConstantInt(*I), ICmpInst::ICMP_EQ, VRP);
|
||||
addToWorklist(V, ConstantInt::get(*Context, *I),
|
||||
ICmpInst::ICMP_EQ, VRP);
|
||||
return;
|
||||
} else if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
|
||||
assert(*I == 0 && "Pointer is null but not zero?");
|
||||
@ -1783,7 +1784,7 @@ namespace {
|
||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(Canonical)) {
|
||||
if (ConstantInt *Arg = dyn_cast<ConstantInt>(LHS)) {
|
||||
add(RHS,
|
||||
Context->getConstantInt(CI->getValue() ^ Arg->getValue()),
|
||||
ConstantInt::get(*Context, CI->getValue() ^ Arg->getValue()),
|
||||
ICmpInst::ICMP_EQ, NewContext);
|
||||
}
|
||||
}
|
||||
@ -1895,7 +1896,7 @@ namespace {
|
||||
assert(!Ty->isFPOrFPVector() && "Float in work queue!");
|
||||
|
||||
Constant *Zero = Context->getNullValue(Ty);
|
||||
Constant *One = Context->getConstantInt(Ty, 1);
|
||||
Constant *One = ConstantInt::get(Ty, 1);
|
||||
ConstantInt *AllOnes = cast<ConstantInt>(Context->getAllOnesValue(Ty));
|
||||
|
||||
switch (Opcode) {
|
||||
@ -2535,23 +2536,23 @@ namespace {
|
||||
|
||||
void PredicateSimplifier::Forwards::visitSExtInst(SExtInst &SI) {
|
||||
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &SI);
|
||||
LLVMContext *Context = &SI.getContext();
|
||||
LLVMContext &Context = SI.getContext();
|
||||
uint32_t SrcBitWidth = cast<IntegerType>(SI.getSrcTy())->getBitWidth();
|
||||
uint32_t DstBitWidth = cast<IntegerType>(SI.getDestTy())->getBitWidth();
|
||||
APInt Min(APInt::getHighBitsSet(DstBitWidth, DstBitWidth-SrcBitWidth+1));
|
||||
APInt Max(APInt::getLowBitsSet(DstBitWidth, SrcBitWidth-1));
|
||||
VRP.add(Context->getConstantInt(Min), &SI, ICmpInst::ICMP_SLE);
|
||||
VRP.add(Context->getConstantInt(Max), &SI, ICmpInst::ICMP_SGE);
|
||||
VRP.add(ConstantInt::get(Context, Min), &SI, ICmpInst::ICMP_SLE);
|
||||
VRP.add(ConstantInt::get(Context, Max), &SI, ICmpInst::ICMP_SGE);
|
||||
VRP.solve();
|
||||
}
|
||||
|
||||
void PredicateSimplifier::Forwards::visitZExtInst(ZExtInst &ZI) {
|
||||
VRPSolver VRP(VN, IG, UB, VR, PS->DTDFS, PS->modified, &ZI);
|
||||
LLVMContext *Context = &ZI.getContext();
|
||||
LLVMContext &Context = ZI.getContext();
|
||||
uint32_t SrcBitWidth = cast<IntegerType>(ZI.getSrcTy())->getBitWidth();
|
||||
uint32_t DstBitWidth = cast<IntegerType>(ZI.getDestTy())->getBitWidth();
|
||||
APInt Max(APInt::getLowBitsSet(DstBitWidth, SrcBitWidth));
|
||||
VRP.add(Context->getConstantInt(Max), &ZI, ICmpInst::ICMP_UGE);
|
||||
VRP.add(ConstantInt::get(Context, Max), &ZI, ICmpInst::ICMP_UGE);
|
||||
VRP.solve();
|
||||
}
|
||||
|
||||
@ -2640,7 +2641,7 @@ namespace {
|
||||
|
||||
Pred = IC.getPredicate();
|
||||
|
||||
LLVMContext *Context = &IC.getContext();
|
||||
LLVMContext &Context = IC.getContext();
|
||||
|
||||
if (ConstantInt *Op1 = dyn_cast<ConstantInt>(IC.getOperand(1))) {
|
||||
ConstantInt *NextVal = 0;
|
||||
@ -2649,12 +2650,12 @@ namespace {
|
||||
case ICmpInst::ICMP_SLT:
|
||||
case ICmpInst::ICMP_ULT:
|
||||
if (Op1->getValue() != 0)
|
||||
NextVal = Context->getConstantInt(Op1->getValue()-1);
|
||||
NextVal = ConstantInt::get(Context, Op1->getValue()-1);
|
||||
break;
|
||||
case ICmpInst::ICMP_SGT:
|
||||
case ICmpInst::ICMP_UGT:
|
||||
if (!Op1->getValue().isAllOnesValue())
|
||||
NextVal = Context->getConstantInt(Op1->getValue()+1);
|
||||
NextVal = ConstantInt::get(Context, Op1->getValue()+1);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -466,7 +466,7 @@ static Instruction *ConvertShiftToMul(Instruction *Shl,
|
||||
(Shl->hasOneUse() &&
|
||||
(isReassociableOp(Shl->use_back(), Instruction::Mul) ||
|
||||
isReassociableOp(Shl->use_back(), Instruction::Add)))) {
|
||||
Constant *MulCst = Context.getConstantInt(Shl->getType(), 1);
|
||||
Constant *MulCst = ConstantInt::get(Shl->getType(), 1);
|
||||
MulCst =
|
||||
Context.getConstantExprShl(MulCst, cast<Constant>(Shl->getOperand(1)));
|
||||
|
||||
|
@ -776,7 +776,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst,
|
||||
unsigned OtherEltAlign = MemAlignment;
|
||||
|
||||
if (OtherPtr) {
|
||||
Value *Idx[2] = { Zero, Context.getConstantInt(Type::Int32Ty, i) };
|
||||
Value *Idx[2] = { Zero, ConstantInt::get(Type::Int32Ty, i) };
|
||||
OtherElt = GetElementPtrInst::Create(OtherPtr, Idx, Idx + 2,
|
||||
OtherPtr->getNameStr()+"."+utostr(i),
|
||||
MI);
|
||||
@ -839,7 +839,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst,
|
||||
}
|
||||
|
||||
// Convert the integer value to the appropriate type.
|
||||
StoreVal = Context.getConstantInt(TotalVal);
|
||||
StoreVal = ConstantInt::get(Context, TotalVal);
|
||||
if (isa<PointerType>(ValTy))
|
||||
StoreVal = Context.getConstantExprIntToPtr(StoreVal, ValTy);
|
||||
else if (ValTy->isFloatingPoint())
|
||||
@ -876,15 +876,15 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst,
|
||||
Value *Ops[] = {
|
||||
SROADest ? EltPtr : OtherElt, // Dest ptr
|
||||
SROADest ? OtherElt : EltPtr, // Src ptr
|
||||
Context.getConstantInt(MI->getOperand(3)->getType(), EltSize), // Size
|
||||
Context.getConstantInt(Type::Int32Ty, OtherEltAlign) // Align
|
||||
ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size
|
||||
ConstantInt::get(Type::Int32Ty, OtherEltAlign) // Align
|
||||
};
|
||||
CallInst::Create(TheFn, Ops, Ops + 4, "", MI);
|
||||
} else {
|
||||
assert(isa<MemSetInst>(MI));
|
||||
Value *Ops[] = {
|
||||
EltPtr, MI->getOperand(2), // Dest, Value,
|
||||
Context.getConstantInt(MI->getOperand(3)->getType(), EltSize), // Size
|
||||
ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size
|
||||
Zero // Align
|
||||
};
|
||||
CallInst::Create(TheFn, Ops, Ops + 4, "", MI);
|
||||
@ -934,7 +934,7 @@ void SROA::RewriteStoreUserOfWholeAlloca(StoreInst *SI,
|
||||
|
||||
Value *EltVal = SrcVal;
|
||||
if (Shift) {
|
||||
Value *ShiftVal = Context.getConstantInt(EltVal->getType(), Shift);
|
||||
Value *ShiftVal = ConstantInt::get(EltVal->getType(), Shift);
|
||||
EltVal = BinaryOperator::CreateLShr(EltVal, ShiftVal,
|
||||
"sroa.store.elt", SI);
|
||||
}
|
||||
@ -982,7 +982,7 @@ void SROA::RewriteStoreUserOfWholeAlloca(StoreInst *SI,
|
||||
|
||||
Value *EltVal = SrcVal;
|
||||
if (Shift) {
|
||||
Value *ShiftVal = Context.getConstantInt(EltVal->getType(), Shift);
|
||||
Value *ShiftVal = ConstantInt::get(EltVal->getType(), Shift);
|
||||
EltVal = BinaryOperator::CreateLShr(EltVal, ShiftVal,
|
||||
"sroa.store.elt", SI);
|
||||
}
|
||||
@ -1089,7 +1089,7 @@ void SROA::RewriteLoadUserOfWholeAlloca(LoadInst *LI, AllocationInst *AI,
|
||||
Shift = AllocaSizeBits-Shift-FieldIntTy->getBitWidth();
|
||||
|
||||
if (Shift) {
|
||||
Value *ShiftVal = Context.getConstantInt(SrcField->getType(), Shift);
|
||||
Value *ShiftVal = ConstantInt::get(SrcField->getType(), Shift);
|
||||
SrcField = BinaryOperator::CreateShl(SrcField, ShiftVal, "", LI);
|
||||
}
|
||||
|
||||
@ -1212,7 +1212,7 @@ void SROA::CleanupGEP(GetElementPtrInst *GEPI) {
|
||||
Indices.begin(),
|
||||
Indices.end(),
|
||||
GEPI->getName()+".0", GEPI);
|
||||
Indices[1] = Context.getConstantInt(Type::Int32Ty, 1);
|
||||
Indices[1] = ConstantInt::get(Type::Int32Ty, 1);
|
||||
Value *OneIdx = GetElementPtrInst::Create(GEPI->getOperand(0),
|
||||
Indices.begin(),
|
||||
Indices.end(),
|
||||
@ -1469,7 +1469,7 @@ void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, uint64_t Offset) {
|
||||
|
||||
Value *Old = Builder.CreateLoad(NewAI, (NewAI->getName()+".in").c_str());
|
||||
Value *New = ConvertScalar_InsertValue(
|
||||
User->getContext().getConstantInt(APVal),
|
||||
ConstantInt::get(User->getContext(), APVal),
|
||||
Old, Offset, Builder);
|
||||
Builder.CreateStore(New, NewAI);
|
||||
}
|
||||
@ -1558,7 +1558,7 @@ Value *SROA::ConvertScalar_ExtractValue(Value *FromVal, const Type *ToType,
|
||||
}
|
||||
// Return the element extracted out of it.
|
||||
Value *V = Builder.CreateExtractElement(FromVal,
|
||||
Context.getConstantInt(Type::Int32Ty,Elt),
|
||||
ConstantInt::get(Type::Int32Ty,Elt),
|
||||
"tmp");
|
||||
if (V->getType() != ToType)
|
||||
V = Builder.CreateBitCast(V, ToType, "tmp");
|
||||
@ -1611,11 +1611,11 @@ Value *SROA::ConvertScalar_ExtractValue(Value *FromVal, const Type *ToType,
|
||||
// only some bits are used.
|
||||
if (ShAmt > 0 && (unsigned)ShAmt < NTy->getBitWidth())
|
||||
FromVal = Builder.CreateLShr(FromVal,
|
||||
Context.getConstantInt(FromVal->getType(),
|
||||
ConstantInt::get(FromVal->getType(),
|
||||
ShAmt), "tmp");
|
||||
else if (ShAmt < 0 && (unsigned)-ShAmt < NTy->getBitWidth())
|
||||
FromVal = Builder.CreateShl(FromVal,
|
||||
Context.getConstantInt(FromVal->getType(),
|
||||
ConstantInt::get(FromVal->getType(),
|
||||
-ShAmt), "tmp");
|
||||
|
||||
// Finally, unconditionally truncate the integer to the right width.
|
||||
@ -1677,7 +1677,7 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old,
|
||||
SV = Builder.CreateBitCast(SV, VTy->getElementType(), "tmp");
|
||||
|
||||
SV = Builder.CreateInsertElement(Old, SV,
|
||||
Context.getConstantInt(Type::Int32Ty, Elt),
|
||||
ConstantInt::get(Type::Int32Ty, Elt),
|
||||
"tmp");
|
||||
return SV;
|
||||
}
|
||||
@ -1745,11 +1745,11 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old,
|
||||
// only some bits in the structure are set.
|
||||
APInt Mask(APInt::getLowBitsSet(DestWidth, SrcWidth));
|
||||
if (ShAmt > 0 && (unsigned)ShAmt < DestWidth) {
|
||||
SV = Builder.CreateShl(SV, Context.getConstantInt(SV->getType(),
|
||||
SV = Builder.CreateShl(SV, ConstantInt::get(SV->getType(),
|
||||
ShAmt), "tmp");
|
||||
Mask <<= ShAmt;
|
||||
} else if (ShAmt < 0 && (unsigned)-ShAmt < DestWidth) {
|
||||
SV = Builder.CreateLShr(SV, Context.getConstantInt(SV->getType(),
|
||||
SV = Builder.CreateLShr(SV, ConstantInt::get(SV->getType(),
|
||||
-ShAmt), "tmp");
|
||||
Mask = Mask.lshr(-ShAmt);
|
||||
}
|
||||
@ -1758,7 +1758,7 @@ Value *SROA::ConvertScalar_InsertValue(Value *SV, Value *Old,
|
||||
// in the new bits.
|
||||
if (SrcWidth != DestWidth) {
|
||||
assert(DestWidth > SrcWidth);
|
||||
Old = Builder.CreateAnd(Old, Context.getConstantInt(~Mask), "mask");
|
||||
Old = Builder.CreateAnd(Old, ConstantInt::get(Context, ~Mask), "mask");
|
||||
SV = Builder.CreateOr(Old, SV, "ins");
|
||||
}
|
||||
return SV;
|
||||
|
@ -157,7 +157,7 @@ Value *LibCallOptimization::EmitMemCpy(Value *Dst, Value *Src, Value *Len,
|
||||
Tys[0] = Len->getType();
|
||||
Value *MemCpy = Intrinsic::getDeclaration(M, IID, Tys, 1);
|
||||
return B.CreateCall4(MemCpy, CastToCStr(Dst, B), CastToCStr(Src, B), Len,
|
||||
Context->getConstantInt(Type::Int32Ty, Align));
|
||||
ConstantInt::get(Type::Int32Ty, Align));
|
||||
}
|
||||
|
||||
/// EmitMemChr - Emit a call to the memchr function. This assumes that Ptr is
|
||||
@ -213,7 +213,7 @@ Value *LibCallOptimization::EmitMemSet(Value *Dst, Value *Val,
|
||||
const Type *Tys[1];
|
||||
Tys[0] = Len->getType();
|
||||
Value *MemSet = Intrinsic::getDeclaration(M, IID, Tys, 1);
|
||||
Value *Align = Context->getConstantInt(Type::Int32Ty, 1);
|
||||
Value *Align = ConstantInt::get(Type::Int32Ty, 1);
|
||||
return B.CreateCall4(MemSet, CastToCStr(Dst, B), Val, Len, Align);
|
||||
}
|
||||
|
||||
@ -346,7 +346,7 @@ void LibCallOptimization::EmitFWrite(Value *Ptr, Value *Size, Value *File,
|
||||
TD->getIntPtrType(), TD->getIntPtrType(),
|
||||
File->getType(), NULL);
|
||||
CallInst *CI = B.CreateCall4(F, CastToCStr(Ptr, B), Size,
|
||||
Context->getConstantInt(TD->getIntPtrType(), 1), File);
|
||||
ConstantInt::get(TD->getIntPtrType(), 1), File);
|
||||
|
||||
if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
|
||||
CI->setCallingConv(Fn->getCallingConv());
|
||||
@ -580,7 +580,7 @@ struct VISIBILITY_HIDDEN StrCatOpt : public LibCallOptimization {
|
||||
// We have enough information to now generate the memcpy call to do the
|
||||
// concatenation for us. Make a memcpy to copy the nul byte with align = 1.
|
||||
EmitMemCpy(CpyDst, Src,
|
||||
Context->getConstantInt(TD->getIntPtrType(), Len+1), 1, B);
|
||||
ConstantInt::get(TD->getIntPtrType(), Len+1), 1, B);
|
||||
}
|
||||
};
|
||||
|
||||
@ -652,7 +652,7 @@ struct VISIBILITY_HIDDEN StrChrOpt : public LibCallOptimization {
|
||||
return 0;
|
||||
|
||||
return EmitMemChr(SrcStr, CI->getOperand(2), // include nul.
|
||||
Context->getConstantInt(TD->getIntPtrType(), Len), B);
|
||||
ConstantInt::get(TD->getIntPtrType(), Len), B);
|
||||
}
|
||||
|
||||
// Otherwise, the character is a constant, see if the first argument is
|
||||
@ -677,7 +677,7 @@ struct VISIBILITY_HIDDEN StrChrOpt : public LibCallOptimization {
|
||||
}
|
||||
|
||||
// strchr(s+n,c) -> gep(s+n+i,c)
|
||||
Value *Idx = Context->getConstantInt(Type::Int64Ty, i);
|
||||
Value *Idx = ConstantInt::get(Type::Int64Ty, i);
|
||||
return B.CreateGEP(SrcStr, Idx, "strchr");
|
||||
}
|
||||
};
|
||||
@ -696,7 +696,7 @@ struct VISIBILITY_HIDDEN StrCmpOpt : public LibCallOptimization {
|
||||
|
||||
Value *Str1P = CI->getOperand(1), *Str2P = CI->getOperand(2);
|
||||
if (Str1P == Str2P) // strcmp(x,x) -> 0
|
||||
return Context->getConstantInt(CI->getType(), 0);
|
||||
return ConstantInt::get(CI->getType(), 0);
|
||||
|
||||
std::string Str1, Str2;
|
||||
bool HasStr1 = GetConstantStringInfo(Str1P, Str1);
|
||||
@ -710,7 +710,7 @@ struct VISIBILITY_HIDDEN StrCmpOpt : public LibCallOptimization {
|
||||
|
||||
// strcmp(x, y) -> cnst (if both x and y are constant strings)
|
||||
if (HasStr1 && HasStr2)
|
||||
return Context->getConstantInt(CI->getType(),
|
||||
return ConstantInt::get(CI->getType(),
|
||||
strcmp(Str1.c_str(),Str2.c_str()));
|
||||
|
||||
// strcmp(P, "x") -> memcmp(P, "x", 2)
|
||||
@ -718,7 +718,7 @@ struct VISIBILITY_HIDDEN StrCmpOpt : public LibCallOptimization {
|
||||
uint64_t Len2 = GetStringLength(Str2P);
|
||||
if (Len1 && Len2) {
|
||||
return EmitMemCmp(Str1P, Str2P,
|
||||
Context->getConstantInt(TD->getIntPtrType(),
|
||||
ConstantInt::get(TD->getIntPtrType(),
|
||||
std::min(Len1, Len2)), B);
|
||||
}
|
||||
|
||||
@ -741,7 +741,7 @@ struct VISIBILITY_HIDDEN StrNCmpOpt : public LibCallOptimization {
|
||||
|
||||
Value *Str1P = CI->getOperand(1), *Str2P = CI->getOperand(2);
|
||||
if (Str1P == Str2P) // strncmp(x,x,n) -> 0
|
||||
return Context->getConstantInt(CI->getType(), 0);
|
||||
return ConstantInt::get(CI->getType(), 0);
|
||||
|
||||
// Get the length argument if it is constant.
|
||||
uint64_t Length;
|
||||
@ -751,7 +751,7 @@ struct VISIBILITY_HIDDEN StrNCmpOpt : public LibCallOptimization {
|
||||
return 0;
|
||||
|
||||
if (Length == 0) // strncmp(x,y,0) -> 0
|
||||
return Context->getConstantInt(CI->getType(), 0);
|
||||
return ConstantInt::get(CI->getType(), 0);
|
||||
|
||||
std::string Str1, Str2;
|
||||
bool HasStr1 = GetConstantStringInfo(Str1P, Str1);
|
||||
@ -765,7 +765,7 @@ struct VISIBILITY_HIDDEN StrNCmpOpt : public LibCallOptimization {
|
||||
|
||||
// strncmp(x, y) -> cnst (if both x and y are constant strings)
|
||||
if (HasStr1 && HasStr2)
|
||||
return Context->getConstantInt(CI->getType(),
|
||||
return ConstantInt::get(CI->getType(),
|
||||
strncmp(Str1.c_str(), Str2.c_str(), Length));
|
||||
return 0;
|
||||
}
|
||||
@ -795,7 +795,7 @@ struct VISIBILITY_HIDDEN StrCpyOpt : public LibCallOptimization {
|
||||
// We have enough information to now generate the memcpy call to do the
|
||||
// concatenation for us. Make a memcpy to copy the nul byte with align = 1.
|
||||
EmitMemCpy(Dst, Src,
|
||||
Context->getConstantInt(TD->getIntPtrType(), Len), 1, B);
|
||||
ConstantInt::get(TD->getIntPtrType(), Len), 1, B);
|
||||
return Dst;
|
||||
}
|
||||
};
|
||||
@ -823,7 +823,7 @@ struct VISIBILITY_HIDDEN StrNCpyOpt : public LibCallOptimization {
|
||||
|
||||
if (SrcLen == 0) {
|
||||
// strncpy(x, "", y) -> memset(x, '\0', y, 1)
|
||||
EmitMemSet(Dst, Context->getConstantInt(Type::Int8Ty, '\0'), LenOp, B);
|
||||
EmitMemSet(Dst, ConstantInt::get(Type::Int8Ty, '\0'), LenOp, B);
|
||||
return Dst;
|
||||
}
|
||||
|
||||
@ -840,7 +840,7 @@ struct VISIBILITY_HIDDEN StrNCpyOpt : public LibCallOptimization {
|
||||
|
||||
// strncpy(x, s, c) -> memcpy(x, s, c, 1) [s and c are constant]
|
||||
EmitMemCpy(Dst, Src,
|
||||
Context->getConstantInt(TD->getIntPtrType(), Len), 1, B);
|
||||
ConstantInt::get(TD->getIntPtrType(), Len), 1, B);
|
||||
|
||||
return Dst;
|
||||
}
|
||||
@ -861,7 +861,7 @@ struct VISIBILITY_HIDDEN StrLenOpt : public LibCallOptimization {
|
||||
|
||||
// Constant folding: strlen("xyz") -> 3
|
||||
if (uint64_t Len = GetStringLength(Src))
|
||||
return Context->getConstantInt(CI->getType(), Len-1);
|
||||
return ConstantInt::get(CI->getType(), Len-1);
|
||||
|
||||
// Handle strlen(p) != 0.
|
||||
if (!IsOnlyUsedInZeroEqualityComparison(CI)) return 0;
|
||||
@ -980,7 +980,7 @@ struct VISIBILITY_HIDDEN MemMoveOpt : public LibCallOptimization {
|
||||
Value *Dst = CastToCStr(CI->getOperand(1), B);
|
||||
Value *Src = CastToCStr(CI->getOperand(2), B);
|
||||
Value *Size = CI->getOperand(3);
|
||||
Value *Align = Context->getConstantInt(Type::Int32Ty, 1);
|
||||
Value *Align = ConstantInt::get(Type::Int32Ty, 1);
|
||||
B.CreateCall4(MemMove, Dst, Src, Size, Align);
|
||||
return CI->getOperand(1);
|
||||
}
|
||||
@ -1154,7 +1154,7 @@ struct VISIBILITY_HIDDEN FFSOpt : public LibCallOptimization {
|
||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
|
||||
if (CI->getValue() == 0) // ffs(0) -> 0.
|
||||
return Context->getNullValue(CI->getType());
|
||||
return Context->getConstantInt(Type::Int32Ty, // ffs(c) -> cttz(c)+1
|
||||
return ConstantInt::get(Type::Int32Ty, // ffs(c) -> cttz(c)+1
|
||||
CI->getValue().countTrailingZeros()+1);
|
||||
}
|
||||
|
||||
@ -1163,11 +1163,11 @@ struct VISIBILITY_HIDDEN FFSOpt : public LibCallOptimization {
|
||||
Value *F = Intrinsic::getDeclaration(Callee->getParent(),
|
||||
Intrinsic::cttz, &ArgType, 1);
|
||||
Value *V = B.CreateCall(F, Op, "cttz");
|
||||
V = B.CreateAdd(V, Context->getConstantInt(V->getType(), 1), "tmp");
|
||||
V = B.CreateAdd(V, ConstantInt::get(V->getType(), 1), "tmp");
|
||||
V = B.CreateIntCast(V, Type::Int32Ty, false, "tmp");
|
||||
|
||||
Value *Cond = B.CreateICmpNE(Op, Context->getNullValue(ArgType), "tmp");
|
||||
return B.CreateSelect(Cond, V, Context->getConstantInt(Type::Int32Ty, 0));
|
||||
return B.CreateSelect(Cond, V, ConstantInt::get(Type::Int32Ty, 0));
|
||||
}
|
||||
};
|
||||
|
||||
@ -1184,9 +1184,9 @@ struct VISIBILITY_HIDDEN IsDigitOpt : public LibCallOptimization {
|
||||
|
||||
// isdigit(c) -> (c-'0') <u 10
|
||||
Value *Op = CI->getOperand(1);
|
||||
Op = B.CreateSub(Op, Context->getConstantInt(Type::Int32Ty, '0'),
|
||||
Op = B.CreateSub(Op, ConstantInt::get(Type::Int32Ty, '0'),
|
||||
"isdigittmp");
|
||||
Op = B.CreateICmpULT(Op, Context->getConstantInt(Type::Int32Ty, 10),
|
||||
Op = B.CreateICmpULT(Op, ConstantInt::get(Type::Int32Ty, 10),
|
||||
"isdigit");
|
||||
return B.CreateZExt(Op, CI->getType());
|
||||
}
|
||||
@ -1205,7 +1205,7 @@ struct VISIBILITY_HIDDEN IsAsciiOpt : public LibCallOptimization {
|
||||
|
||||
// isascii(c) -> c <u 128
|
||||
Value *Op = CI->getOperand(1);
|
||||
Op = B.CreateICmpULT(Op, Context->getConstantInt(Type::Int32Ty, 128),
|
||||
Op = B.CreateICmpULT(Op, ConstantInt::get(Type::Int32Ty, 128),
|
||||
"isascii");
|
||||
return B.CreateZExt(Op, CI->getType());
|
||||
}
|
||||
@ -1246,7 +1246,7 @@ struct VISIBILITY_HIDDEN ToAsciiOpt : public LibCallOptimization {
|
||||
|
||||
// isascii(c) -> c & 0x7f
|
||||
return B.CreateAnd(CI->getOperand(1),
|
||||
Context->getConstantInt(CI->getType(),0x7F));
|
||||
ConstantInt::get(CI->getType(),0x7F));
|
||||
}
|
||||
};
|
||||
|
||||
@ -1274,13 +1274,13 @@ struct VISIBILITY_HIDDEN PrintFOpt : public LibCallOptimization {
|
||||
// Empty format string -> noop.
|
||||
if (FormatStr.empty()) // Tolerate printf's declared void.
|
||||
return CI->use_empty() ? (Value*)CI :
|
||||
Context->getConstantInt(CI->getType(), 0);
|
||||
ConstantInt::get(CI->getType(), 0);
|
||||
|
||||
// printf("x") -> putchar('x'), even for '%'.
|
||||
if (FormatStr.size() == 1) {
|
||||
EmitPutChar(Context->getConstantInt(Type::Int32Ty, FormatStr[0]), B);
|
||||
EmitPutChar(ConstantInt::get(Type::Int32Ty, FormatStr[0]), B);
|
||||
return CI->use_empty() ? (Value*)CI :
|
||||
Context->getConstantInt(CI->getType(), 1);
|
||||
ConstantInt::get(CI->getType(), 1);
|
||||
}
|
||||
|
||||
// printf("foo\n") --> puts("foo")
|
||||
@ -1294,7 +1294,7 @@ struct VISIBILITY_HIDDEN PrintFOpt : public LibCallOptimization {
|
||||
GlobalVariable::InternalLinkage, C, "str");
|
||||
EmitPutS(C, B);
|
||||
return CI->use_empty() ? (Value*)CI :
|
||||
Context->getConstantInt(CI->getType(), FormatStr.size()+1);
|
||||
ConstantInt::get(CI->getType(), FormatStr.size()+1);
|
||||
}
|
||||
|
||||
// Optimize specific format strings.
|
||||
@ -1303,7 +1303,7 @@ struct VISIBILITY_HIDDEN PrintFOpt : public LibCallOptimization {
|
||||
isa<IntegerType>(CI->getOperand(2)->getType())) {
|
||||
EmitPutChar(CI->getOperand(2), B);
|
||||
return CI->use_empty() ? (Value*)CI :
|
||||
Context->getConstantInt(CI->getType(), 1);
|
||||
ConstantInt::get(CI->getType(), 1);
|
||||
}
|
||||
|
||||
// printf("%s\n", str) --> puts(str)
|
||||
@ -1344,8 +1344,8 @@ struct VISIBILITY_HIDDEN SPrintFOpt : public LibCallOptimization {
|
||||
|
||||
// sprintf(str, fmt) -> llvm.memcpy(str, fmt, strlen(fmt)+1, 1)
|
||||
EmitMemCpy(CI->getOperand(1), CI->getOperand(2), // Copy the nul byte.
|
||||
Context->getConstantInt(TD->getIntPtrType(), FormatStr.size()+1),1,B);
|
||||
return Context->getConstantInt(CI->getType(), FormatStr.size());
|
||||
ConstantInt::get(TD->getIntPtrType(), FormatStr.size()+1),1,B);
|
||||
return ConstantInt::get(CI->getType(), FormatStr.size());
|
||||
}
|
||||
|
||||
// The remaining optimizations require the format string to be "%s" or "%c"
|
||||
@ -1360,10 +1360,10 @@ struct VISIBILITY_HIDDEN SPrintFOpt : public LibCallOptimization {
|
||||
Value *V = B.CreateTrunc(CI->getOperand(3), Type::Int8Ty, "char");
|
||||
Value *Ptr = CastToCStr(CI->getOperand(1), B);
|
||||
B.CreateStore(V, Ptr);
|
||||
Ptr = B.CreateGEP(Ptr, Context->getConstantInt(Type::Int32Ty, 1), "nul");
|
||||
Ptr = B.CreateGEP(Ptr, ConstantInt::get(Type::Int32Ty, 1), "nul");
|
||||
B.CreateStore(Context->getNullValue(Type::Int8Ty), Ptr);
|
||||
|
||||
return Context->getConstantInt(CI->getType(), 1);
|
||||
return ConstantInt::get(CI->getType(), 1);
|
||||
}
|
||||
|
||||
if (FormatStr[1] == 's') {
|
||||
@ -1372,7 +1372,7 @@ struct VISIBILITY_HIDDEN SPrintFOpt : public LibCallOptimization {
|
||||
|
||||
Value *Len = EmitStrLen(CI->getOperand(3), B);
|
||||
Value *IncLen = B.CreateAdd(Len,
|
||||
Context->getConstantInt(Len->getType(), 1),
|
||||
ConstantInt::get(Len->getType(), 1),
|
||||
"leninc");
|
||||
EmitMemCpy(CI->getOperand(1), CI->getOperand(3), IncLen, 1, B);
|
||||
|
||||
@ -1405,13 +1405,13 @@ struct VISIBILITY_HIDDEN FWriteOpt : public LibCallOptimization {
|
||||
|
||||
// If this is writing zero records, remove the call (it's a noop).
|
||||
if (Bytes == 0)
|
||||
return Context->getConstantInt(CI->getType(), 0);
|
||||
return ConstantInt::get(CI->getType(), 0);
|
||||
|
||||
// If this is writing one byte, turn it into fputc.
|
||||
if (Bytes == 1) { // fwrite(S,1,1,F) -> fputc(S[0],F)
|
||||
Value *Char = B.CreateLoad(CastToCStr(CI->getOperand(1), B), "char");
|
||||
EmitFPutC(Char, CI->getOperand(4), B);
|
||||
return Context->getConstantInt(CI->getType(), 1);
|
||||
return ConstantInt::get(CI->getType(), 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -1434,7 +1434,7 @@ struct VISIBILITY_HIDDEN FPutsOpt : public LibCallOptimization {
|
||||
uint64_t Len = GetStringLength(CI->getOperand(1));
|
||||
if (!Len) return 0;
|
||||
EmitFWrite(CI->getOperand(1),
|
||||
Context->getConstantInt(TD->getIntPtrType(), Len-1),
|
||||
ConstantInt::get(TD->getIntPtrType(), Len-1),
|
||||
CI->getOperand(2), B);
|
||||
return CI; // Known to have no uses (see above).
|
||||
}
|
||||
@ -1463,10 +1463,10 @@ struct VISIBILITY_HIDDEN FPrintFOpt : public LibCallOptimization {
|
||||
if (FormatStr[i] == '%') // Could handle %% -> % if we cared.
|
||||
return 0; // We found a format specifier.
|
||||
|
||||
EmitFWrite(CI->getOperand(2), Context->getConstantInt(TD->getIntPtrType(),
|
||||
EmitFWrite(CI->getOperand(2), ConstantInt::get(TD->getIntPtrType(),
|
||||
FormatStr.size()),
|
||||
CI->getOperand(1), B);
|
||||
return Context->getConstantInt(CI->getType(), FormatStr.size());
|
||||
return ConstantInt::get(CI->getType(), FormatStr.size());
|
||||
}
|
||||
|
||||
// The remaining optimizations require the format string to be "%s" or "%c"
|
||||
@ -1479,7 +1479,7 @@ struct VISIBILITY_HIDDEN FPrintFOpt : public LibCallOptimization {
|
||||
// fprintf(F, "%c", chr) --> *(i8*)dst = chr
|
||||
if (!isa<IntegerType>(CI->getOperand(3)->getType())) return 0;
|
||||
EmitFPutC(CI->getOperand(3), CI->getOperand(1), B);
|
||||
return Context->getConstantInt(CI->getType(), 1);
|
||||
return ConstantInt::get(CI->getType(), 1);
|
||||
}
|
||||
|
||||
if (FormatStr[1] == 's') {
|
||||
|
@ -306,7 +306,7 @@ Function *CodeExtractor::constructFunction(const Values &inputs,
|
||||
if (AggregateArgs) {
|
||||
Value *Idx[2];
|
||||
Idx[0] = Context.getNullValue(Type::Int32Ty);
|
||||
Idx[1] = Context.getConstantInt(Type::Int32Ty, i);
|
||||
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
|
||||
TerminatorInst *TI = newFunction->begin()->getTerminator();
|
||||
GetElementPtrInst *GEP =
|
||||
GetElementPtrInst::Create(AI, Idx, Idx+2,
|
||||
@ -396,7 +396,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
|
||||
Value *Idx[2];
|
||||
Idx[0] = Context.getNullValue(Type::Int32Ty);
|
||||
Idx[1] = Context.getConstantInt(Type::Int32Ty, i);
|
||||
Idx[1] = ConstantInt::get(Type::Int32Ty, i);
|
||||
GetElementPtrInst *GEP =
|
||||
GetElementPtrInst::Create(Struct, Idx, Idx + 2,
|
||||
"gep_" + StructValues[i]->getName());
|
||||
@ -422,7 +422,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
if (AggregateArgs) {
|
||||
Value *Idx[2];
|
||||
Idx[0] = Context.getNullValue(Type::Int32Ty);
|
||||
Idx[1] = Context.getConstantInt(Type::Int32Ty, FirstOut + i);
|
||||
Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i);
|
||||
GetElementPtrInst *GEP
|
||||
= GetElementPtrInst::Create(Struct, Idx, Idx + 2,
|
||||
"gep_reload_" + outputs[i]->getName());
|
||||
@ -474,17 +474,17 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
case 0:
|
||||
case 1: break; // No value needed.
|
||||
case 2: // Conditional branch, return a bool
|
||||
brVal = Context.getConstantInt(Type::Int1Ty, !SuccNum);
|
||||
brVal = ConstantInt::get(Type::Int1Ty, !SuccNum);
|
||||
break;
|
||||
default:
|
||||
brVal = Context.getConstantInt(Type::Int16Ty, SuccNum);
|
||||
brVal = ConstantInt::get(Type::Int16Ty, SuccNum);
|
||||
break;
|
||||
}
|
||||
|
||||
ReturnInst *NTRet = ReturnInst::Create(brVal, NewTarget);
|
||||
|
||||
// Update the switch instruction.
|
||||
TheSwitch->addCase(Context.getConstantInt(Type::Int16Ty, SuccNum),
|
||||
TheSwitch->addCase(ConstantInt::get(Type::Int16Ty, SuccNum),
|
||||
OldTarget);
|
||||
|
||||
// Restore values just before we exit
|
||||
@ -523,7 +523,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
||||
if (AggregateArgs) {
|
||||
Value *Idx[2];
|
||||
Idx[0] = Context.getNullValue(Type::Int32Ty);
|
||||
Idx[1] = Context.getConstantInt(Type::Int32Ty,FirstOut+out);
|
||||
Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out);
|
||||
GetElementPtrInst *GEP =
|
||||
GetElementPtrInst::Create(OAI, Idx, Idx + 2,
|
||||
"gep_" + outputs[out]->getName(),
|
||||
|
@ -324,14 +324,14 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
|
||||
if (TD == 0)
|
||||
Size = Context.getConstantExprSizeOf(AggTy);
|
||||
else
|
||||
Size = Context.getConstantInt(Type::Int64Ty,
|
||||
Size = ConstantInt::get(Type::Int64Ty,
|
||||
TD->getTypeStoreSize(AggTy));
|
||||
|
||||
// Always generate a memcpy of alignment 1 here because we don't know
|
||||
// the alignment of the src pointer. Other optimizations can infer
|
||||
// better alignment.
|
||||
Value *CallArgs[] = {
|
||||
DestCast, SrcCast, Size, Context.getConstantInt(Type::Int32Ty, 1)
|
||||
DestCast, SrcCast, Size, ConstantInt::get(Type::Int32Ty, 1)
|
||||
};
|
||||
CallInst *TheMemCpy =
|
||||
CallInst::Create(MemCpyFn, CallArgs, CallArgs+4, "", TheCall);
|
||||
|
@ -118,7 +118,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
|
||||
// malloc(type) becomes i8 *malloc(size)
|
||||
Value *MallocArg;
|
||||
if (LowerMallocArgToInteger)
|
||||
MallocArg = Context.getConstantInt(Type::Int64Ty,
|
||||
MallocArg = ConstantInt::get(Type::Int64Ty,
|
||||
TD.getTypeAllocSize(AllocTy));
|
||||
else
|
||||
MallocArg = Context.getConstantExprSizeOf(AllocTy);
|
||||
|
@ -272,7 +272,7 @@ void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
|
||||
AllocaInst *InvokeNum,
|
||||
SwitchInst *CatchSwitch) {
|
||||
LLVMContext &Context = II->getContext();
|
||||
ConstantInt *InvokeNoC = Context.getConstantInt(Type::Int32Ty, InvokeNo);
|
||||
ConstantInt *InvokeNoC = ConstantInt::get(Type::Int32Ty, InvokeNo);
|
||||
|
||||
// If the unwind edge has phi nodes, split the edge.
|
||||
if (isa<PHINode>(II->getUnwindDest()->begin())) {
|
||||
@ -483,7 +483,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
|
||||
|
||||
std::vector<Value*> Idx;
|
||||
Idx.push_back(Context.getNullValue(Type::Int32Ty));
|
||||
Idx.push_back(Context.getConstantInt(Type::Int32Ty, 1));
|
||||
Idx.push_back(ConstantInt::get(Type::Int32Ty, 1));
|
||||
OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
|
||||
"OldBuf",
|
||||
EntryBB->getTerminator());
|
||||
@ -504,7 +504,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
|
||||
// executing. For normal calls it contains zero.
|
||||
AllocaInst *InvokeNum = new AllocaInst(Type::Int32Ty, 0,
|
||||
"invokenum",EntryBB->begin());
|
||||
new StoreInst(Context.getConstantInt(Type::Int32Ty, 0), InvokeNum, true,
|
||||
new StoreInst(ConstantInt::get(Type::Int32Ty, 0), InvokeNum, true,
|
||||
EntryBB->getTerminator());
|
||||
|
||||
// Insert a load in the Catch block, and a switch on its value. By default,
|
||||
@ -523,7 +523,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
|
||||
BasicBlock *ContBlock = EntryBB->splitBasicBlock(EntryBB->getTerminator(),
|
||||
"setjmp.cont");
|
||||
|
||||
Idx[1] = Context.getConstantInt(Type::Int32Ty, 0);
|
||||
Idx[1] = ConstantInt::get(Type::Int32Ty, 0);
|
||||
Value *JmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
|
||||
"TheJmpBuf",
|
||||
EntryBB->getTerminator());
|
||||
@ -577,12 +577,12 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
|
||||
// Get a pointer to the jmpbuf and longjmp.
|
||||
std::vector<Value*> Idx;
|
||||
Idx.push_back(Context.getNullValue(Type::Int32Ty));
|
||||
Idx.push_back(Context.getConstantInt(Type::Int32Ty, 0));
|
||||
Idx.push_back(ConstantInt::get(Type::Int32Ty, 0));
|
||||
Idx[0] = GetElementPtrInst::Create(BufPtr, Idx.begin(), Idx.end(), "JmpBuf",
|
||||
UnwindBlock);
|
||||
Idx[0] = new BitCastInst(Idx[0], PointerType::getUnqual(Type::Int8Ty),
|
||||
"tmp", UnwindBlock);
|
||||
Idx[1] = Context.getConstantInt(Type::Int32Ty, 1);
|
||||
Idx[1] = ConstantInt::get(Type::Int32Ty, 1);
|
||||
CallInst::Create(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock);
|
||||
new UnreachableInst(UnwindBlock);
|
||||
|
||||
|
@ -1611,7 +1611,7 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
|
||||
if (BB->getSinglePredecessor()) {
|
||||
// Turn this into a branch on constant.
|
||||
bool CondIsTrue = PBI->getSuccessor(0) == BB;
|
||||
BI->setCondition(Context.getConstantInt(Type::Int1Ty, CondIsTrue));
|
||||
BI->setCondition(ConstantInt::get(Type::Int1Ty, CondIsTrue));
|
||||
return true; // Nuke the branch on constant.
|
||||
}
|
||||
|
||||
@ -1631,7 +1631,7 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
|
||||
PBI->getCondition() == BI->getCondition() &&
|
||||
PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
|
||||
bool CondIsTrue = PBI->getSuccessor(0) == BB;
|
||||
NewPN->addIncoming(Context.getConstantInt(Type::Int1Ty,
|
||||
NewPN->addIncoming(ConstantInt::get(Type::Int1Ty,
|
||||
CondIsTrue), *PI);
|
||||
} else {
|
||||
NewPN->addIncoming(BI->getCondition(), *PI);
|
||||
|
@ -271,20 +271,20 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
|
||||
Context.getPointerTypeUnqual(Type::DoubleTy),
|
||||
"upgraded.", CI);
|
||||
Value *Load = new LoadInst(Addr, "upgraded.", false, 8, CI);
|
||||
Value *Idx = Context.getConstantInt(Type::Int32Ty, 0);
|
||||
Value *Idx = ConstantInt::get(Type::Int32Ty, 0);
|
||||
Op1 = InsertElementInst::Create(Op1, Load, Idx, "upgraded.", CI);
|
||||
|
||||
if (isLoadH) {
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 0));
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 2));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 0));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
|
||||
} else {
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 2));
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 1));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1));
|
||||
}
|
||||
Value *Mask = Context.getConstantVector(Idxs);
|
||||
SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
|
||||
} else if (isMovL) {
|
||||
Constant *Zero = Context.getConstantInt(Type::Int32Ty, 0);
|
||||
Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
|
||||
Idxs.push_back(Zero);
|
||||
Idxs.push_back(Zero);
|
||||
Idxs.push_back(Zero);
|
||||
@ -292,32 +292,32 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
|
||||
Value *ZeroV = Context.getConstantVector(Idxs);
|
||||
|
||||
Idxs.clear();
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 4));
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 5));
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 2));
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 3));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 4));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 5));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 3));
|
||||
Value *Mask = Context.getConstantVector(Idxs);
|
||||
SI = new ShuffleVectorInst(ZeroV, Op0, Mask, "upgraded.", CI);
|
||||
} else if (isMovSD ||
|
||||
isUnpckhPD || isUnpcklPD || isPunpckhQPD || isPunpcklQPD) {
|
||||
Value *Op1 = CI->getOperand(2);
|
||||
if (isMovSD) {
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 2));
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 1));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1));
|
||||
} else if (isUnpckhPD || isPunpckhQPD) {
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 1));
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 3));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 3));
|
||||
} else {
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 0));
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, 2));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 0));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
|
||||
}
|
||||
Value *Mask = Context.getConstantVector(Idxs);
|
||||
SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
|
||||
} else if (isShufPD) {
|
||||
Value *Op1 = CI->getOperand(2);
|
||||
unsigned MaskVal = cast<ConstantInt>(CI->getOperand(3))->getZExtValue();
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty, MaskVal & 1));
|
||||
Idxs.push_back(Context.getConstantInt(Type::Int32Ty,
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty, MaskVal & 1));
|
||||
Idxs.push_back(ConstantInt::get(Type::Int32Ty,
|
||||
((MaskVal >> 1) & 1)+2));
|
||||
Value *Mask = Context.getConstantVector(Idxs);
|
||||
SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
|
||||
|
@ -171,7 +171,7 @@ static Constant *FoldBitCast(LLVMContext &Context,
|
||||
// Handle ConstantFP input.
|
||||
if (const ConstantFP *FP = dyn_cast<ConstantFP>(V))
|
||||
// FP -> Integral.
|
||||
return Context.getConstantInt(FP->getValueAPF().bitcastToAPInt());
|
||||
return ConstantInt::get(Context, FP->getValueAPF().bitcastToAPInt());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -258,7 +258,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
|
||||
(void) V.convertToInteger(x, DestBitWidth, opc==Instruction::FPToSI,
|
||||
APFloat::rmTowardZero, &ignored);
|
||||
APInt Val(DestBitWidth, 2, x);
|
||||
return Context.getConstantInt(Val);
|
||||
return ConstantInt::get(Context, Val);
|
||||
}
|
||||
return 0; // Can't fold.
|
||||
case Instruction::IntToPtr: //always treated as unsigned
|
||||
@ -267,7 +267,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
|
||||
return 0; // Other pointer types cannot be casted
|
||||
case Instruction::PtrToInt: // always treated as unsigned
|
||||
if (V->isNullValue()) // is it a null pointer value?
|
||||
return Context.getConstantInt(DestTy, 0);
|
||||
return ConstantInt::get(DestTy, 0);
|
||||
return 0; // Other pointer types cannot be casted
|
||||
case Instruction::UIToFP:
|
||||
case Instruction::SIToFP:
|
||||
@ -287,7 +287,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
|
||||
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
||||
APInt Result(CI->getValue());
|
||||
Result.zext(BitWidth);
|
||||
return Context.getConstantInt(Result);
|
||||
return ConstantInt::get(Context, Result);
|
||||
}
|
||||
return 0;
|
||||
case Instruction::SExt:
|
||||
@ -295,7 +295,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
|
||||
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
||||
APInt Result(CI->getValue());
|
||||
Result.sext(BitWidth);
|
||||
return Context.getConstantInt(Result);
|
||||
return ConstantInt::get(Context, Result);
|
||||
}
|
||||
return 0;
|
||||
case Instruction::Trunc:
|
||||
@ -303,7 +303,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
|
||||
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
|
||||
APInt Result(CI->getValue());
|
||||
Result.trunc(BitWidth);
|
||||
return Context.getConstantInt(Result);
|
||||
return ConstantInt::get(Context, Result);
|
||||
}
|
||||
return 0;
|
||||
case Instruction::BitCast:
|
||||
@ -721,51 +721,51 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
|
||||
default:
|
||||
break;
|
||||
case Instruction::Add:
|
||||
return Context.getConstantInt(C1V + C2V);
|
||||
return ConstantInt::get(Context, C1V + C2V);
|
||||
case Instruction::Sub:
|
||||
return Context.getConstantInt(C1V - C2V);
|
||||
return ConstantInt::get(Context, C1V - C2V);
|
||||
case Instruction::Mul:
|
||||
return Context.getConstantInt(C1V * C2V);
|
||||
return ConstantInt::get(Context, C1V * C2V);
|
||||
case Instruction::UDiv:
|
||||
assert(!CI2->isNullValue() && "Div by zero handled above");
|
||||
return Context.getConstantInt(C1V.udiv(C2V));
|
||||
return ConstantInt::get(Context, C1V.udiv(C2V));
|
||||
case Instruction::SDiv:
|
||||
assert(!CI2->isNullValue() && "Div by zero handled above");
|
||||
if (C2V.isAllOnesValue() && C1V.isMinSignedValue())
|
||||
return Context.getUndef(CI1->getType()); // MIN_INT / -1 -> undef
|
||||
return Context.getConstantInt(C1V.sdiv(C2V));
|
||||
return ConstantInt::get(Context, C1V.sdiv(C2V));
|
||||
case Instruction::URem:
|
||||
assert(!CI2->isNullValue() && "Div by zero handled above");
|
||||
return Context.getConstantInt(C1V.urem(C2V));
|
||||
return ConstantInt::get(Context, C1V.urem(C2V));
|
||||
case Instruction::SRem:
|
||||
assert(!CI2->isNullValue() && "Div by zero handled above");
|
||||
if (C2V.isAllOnesValue() && C1V.isMinSignedValue())
|
||||
return Context.getUndef(CI1->getType()); // MIN_INT % -1 -> undef
|
||||
return Context.getConstantInt(C1V.srem(C2V));
|
||||
return ConstantInt::get(Context, C1V.srem(C2V));
|
||||
case Instruction::And:
|
||||
return Context.getConstantInt(C1V & C2V);
|
||||
return ConstantInt::get(Context, C1V & C2V);
|
||||
case Instruction::Or:
|
||||
return Context.getConstantInt(C1V | C2V);
|
||||
return ConstantInt::get(Context, C1V | C2V);
|
||||
case Instruction::Xor:
|
||||
return Context.getConstantInt(C1V ^ C2V);
|
||||
return ConstantInt::get(Context, C1V ^ C2V);
|
||||
case Instruction::Shl: {
|
||||
uint32_t shiftAmt = C2V.getZExtValue();
|
||||
if (shiftAmt < C1V.getBitWidth())
|
||||
return Context.getConstantInt(C1V.shl(shiftAmt));
|
||||
return ConstantInt::get(Context, C1V.shl(shiftAmt));
|
||||
else
|
||||
return Context.getUndef(C1->getType()); // too big shift is undef
|
||||
}
|
||||
case Instruction::LShr: {
|
||||
uint32_t shiftAmt = C2V.getZExtValue();
|
||||
if (shiftAmt < C1V.getBitWidth())
|
||||
return Context.getConstantInt(C1V.lshr(shiftAmt));
|
||||
return ConstantInt::get(Context, C1V.lshr(shiftAmt));
|
||||
else
|
||||
return Context.getUndef(C1->getType()); // too big shift is undef
|
||||
}
|
||||
case Instruction::AShr: {
|
||||
uint32_t shiftAmt = C2V.getZExtValue();
|
||||
if (shiftAmt < C1V.getBitWidth())
|
||||
return Context.getConstantInt(C1V.ashr(shiftAmt));
|
||||
return ConstantInt::get(Context, C1V.ashr(shiftAmt));
|
||||
else
|
||||
return Context.getUndef(C1->getType()); // too big shift is undef
|
||||
}
|
||||
@ -1420,25 +1420,25 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
|
||||
switch (pred) {
|
||||
default: llvm_unreachable("Invalid ICmp Predicate"); return 0;
|
||||
case ICmpInst::ICMP_EQ:
|
||||
return Context.getConstantInt(Type::Int1Ty, V1 == V2);
|
||||
return ConstantInt::get(Type::Int1Ty, V1 == V2);
|
||||
case ICmpInst::ICMP_NE:
|
||||
return Context.getConstantInt(Type::Int1Ty, V1 != V2);
|
||||
return ConstantInt::get(Type::Int1Ty, V1 != V2);
|
||||
case ICmpInst::ICMP_SLT:
|
||||
return Context.getConstantInt(Type::Int1Ty, V1.slt(V2));
|
||||
return ConstantInt::get(Type::Int1Ty, V1.slt(V2));
|
||||
case ICmpInst::ICMP_SGT:
|
||||
return Context.getConstantInt(Type::Int1Ty, V1.sgt(V2));
|
||||
return ConstantInt::get(Type::Int1Ty, V1.sgt(V2));
|
||||
case ICmpInst::ICMP_SLE:
|
||||
return Context.getConstantInt(Type::Int1Ty, V1.sle(V2));
|
||||
return ConstantInt::get(Type::Int1Ty, V1.sle(V2));
|
||||
case ICmpInst::ICMP_SGE:
|
||||
return Context.getConstantInt(Type::Int1Ty, V1.sge(V2));
|
||||
return ConstantInt::get(Type::Int1Ty, V1.sge(V2));
|
||||
case ICmpInst::ICMP_ULT:
|
||||
return Context.getConstantInt(Type::Int1Ty, V1.ult(V2));
|
||||
return ConstantInt::get(Type::Int1Ty, V1.ult(V2));
|
||||
case ICmpInst::ICMP_UGT:
|
||||
return Context.getConstantInt(Type::Int1Ty, V1.ugt(V2));
|
||||
return ConstantInt::get(Type::Int1Ty, V1.ugt(V2));
|
||||
case ICmpInst::ICMP_ULE:
|
||||
return Context.getConstantInt(Type::Int1Ty, V1.ule(V2));
|
||||
return ConstantInt::get(Type::Int1Ty, V1.ule(V2));
|
||||
case ICmpInst::ICMP_UGE:
|
||||
return Context.getConstantInt(Type::Int1Ty, V1.uge(V2));
|
||||
return ConstantInt::get(Type::Int1Ty, V1.uge(V2));
|
||||
}
|
||||
} else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
|
||||
APFloat C1V = cast<ConstantFP>(C1)->getValueAPF();
|
||||
@ -1449,38 +1449,38 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
|
||||
case FCmpInst::FCMP_FALSE: return Context.getFalse();
|
||||
case FCmpInst::FCMP_TRUE: return Context.getTrue();
|
||||
case FCmpInst::FCMP_UNO:
|
||||
return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpUnordered);
|
||||
return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered);
|
||||
case FCmpInst::FCMP_ORD:
|
||||
return Context.getConstantInt(Type::Int1Ty, R!=APFloat::cmpUnordered);
|
||||
return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpUnordered);
|
||||
case FCmpInst::FCMP_UEQ:
|
||||
return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpUnordered ||
|
||||
return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered ||
|
||||
R==APFloat::cmpEqual);
|
||||
case FCmpInst::FCMP_OEQ:
|
||||
return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpEqual);
|
||||
return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpEqual);
|
||||
case FCmpInst::FCMP_UNE:
|
||||
return Context.getConstantInt(Type::Int1Ty, R!=APFloat::cmpEqual);
|
||||
return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpEqual);
|
||||
case FCmpInst::FCMP_ONE:
|
||||
return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpLessThan ||
|
||||
return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpLessThan ||
|
||||
R==APFloat::cmpGreaterThan);
|
||||
case FCmpInst::FCMP_ULT:
|
||||
return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpUnordered ||
|
||||
return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered ||
|
||||
R==APFloat::cmpLessThan);
|
||||
case FCmpInst::FCMP_OLT:
|
||||
return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpLessThan);
|
||||
return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpLessThan);
|
||||
case FCmpInst::FCMP_UGT:
|
||||
return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpUnordered ||
|
||||
return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpUnordered ||
|
||||
R==APFloat::cmpGreaterThan);
|
||||
case FCmpInst::FCMP_OGT:
|
||||
return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpGreaterThan);
|
||||
return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpGreaterThan);
|
||||
case FCmpInst::FCMP_ULE:
|
||||
return Context.getConstantInt(Type::Int1Ty, R!=APFloat::cmpGreaterThan);
|
||||
return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpGreaterThan);
|
||||
case FCmpInst::FCMP_OLE:
|
||||
return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpLessThan ||
|
||||
return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpLessThan ||
|
||||
R==APFloat::cmpEqual);
|
||||
case FCmpInst::FCMP_UGE:
|
||||
return Context.getConstantInt(Type::Int1Ty, R!=APFloat::cmpLessThan);
|
||||
return ConstantInt::get(Type::Int1Ty, R!=APFloat::cmpLessThan);
|
||||
case FCmpInst::FCMP_OGE:
|
||||
return Context.getConstantInt(Type::Int1Ty, R==APFloat::cmpGreaterThan ||
|
||||
return ConstantInt::get(Type::Int1Ty, R==APFloat::cmpGreaterThan ||
|
||||
R==APFloat::cmpEqual);
|
||||
}
|
||||
} else if (isa<VectorType>(C1->getType())) {
|
||||
@ -1555,7 +1555,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
|
||||
|
||||
// If we evaluated the result, return it now.
|
||||
if (Result != -1)
|
||||
return Context.getConstantInt(Type::Int1Ty, Result);
|
||||
return ConstantInt::get(Type::Int1Ty, Result);
|
||||
|
||||
} else {
|
||||
// Evaluate the relation between the two constants, per the predicate.
|
||||
@ -1632,7 +1632,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
|
||||
|
||||
// If we evaluated the result, return it now.
|
||||
if (Result != -1)
|
||||
return Context.getConstantInt(Type::Int1Ty, Result);
|
||||
return ConstantInt::get(Type::Int1Ty, Result);
|
||||
|
||||
if (!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) {
|
||||
// If C2 is a constant expr and C1 isn't, flip them around and fold the
|
||||
|
@ -11,6 +11,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "LLVMContextImpl.h"
|
||||
#include "llvm/Constants.h"
|
||||
#include "ConstantFold.h"
|
||||
#include "llvm/DerivedTypes.h"
|
||||
@ -171,6 +172,72 @@ ConstantInt::ConstantInt(const IntegerType *Ty, const APInt& V)
|
||||
assert(V.getBitWidth() == Ty->getBitWidth() && "Invalid constant for type");
|
||||
}
|
||||
|
||||
// Get a ConstantInt from an APInt. Note that the value stored in the DenseMap
|
||||
// as the key, is a DenseMapAPIntKeyInfo::KeyTy which has provided the
|
||||
// operator== and operator!= to ensure that the DenseMap doesn't attempt to
|
||||
// compare APInt's of different widths, which would violate an APInt class
|
||||
// invariant which generates an assertion.
|
||||
ConstantInt *ConstantInt::get(LLVMContext &Context, const APInt& V) {
|
||||
// Get the corresponding integer type for the bit width of the value.
|
||||
const IntegerType *ITy = Context.getIntegerType(V.getBitWidth());
|
||||
// get an existing value or the insertion position
|
||||
DenseMapAPIntKeyInfo::KeyTy Key(V, ITy);
|
||||
|
||||
Context.pImpl->ConstantsLock.reader_acquire();
|
||||
ConstantInt *&Slot = Context.pImpl->IntConstants[Key];
|
||||
Context.pImpl->ConstantsLock.reader_release();
|
||||
|
||||
if (!Slot) {
|
||||
sys::SmartScopedWriter<true> Writer(Context.pImpl->ConstantsLock);
|
||||
ConstantInt *&NewSlot = Context.pImpl->IntConstants[Key];
|
||||
if (!Slot) {
|
||||
NewSlot = new ConstantInt(ITy, V);
|
||||
}
|
||||
|
||||
return NewSlot;
|
||||
} else {
|
||||
return Slot;
|
||||
}
|
||||
}
|
||||
|
||||
Constant* ConstantInt::get(const Type* Ty, uint64_t V, bool isSigned) {
|
||||
Constant *C = get(cast<IntegerType>(Ty->getScalarType()),
|
||||
V, isSigned);
|
||||
|
||||
// For vectors, broadcast the value.
|
||||
if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
|
||||
return Ty->getContext().getConstantVector(
|
||||
std::vector<Constant *>(VTy->getNumElements(), C));
|
||||
|
||||
return C;
|
||||
}
|
||||
|
||||
ConstantInt* ConstantInt::get(const IntegerType* Ty, uint64_t V,
|
||||
bool isSigned) {
|
||||
return get(Ty->getContext(), APInt(Ty->getBitWidth(), V, isSigned));
|
||||
}
|
||||
|
||||
ConstantInt* ConstantInt::getSigned(const IntegerType* Ty, int64_t V) {
|
||||
return get(Ty, V, true);
|
||||
}
|
||||
|
||||
Constant *ConstantInt::getSigned(const Type *Ty, int64_t V) {
|
||||
return get(Ty, V, true);
|
||||
}
|
||||
|
||||
Constant* ConstantInt::get(const Type* Ty, const APInt& V) {
|
||||
ConstantInt *C = get(Ty->getContext(), V);
|
||||
assert(C->getType() == Ty->getScalarType() &&
|
||||
"ConstantInt type doesn't match the type implied by its value!");
|
||||
|
||||
// For vectors, broadcast the value.
|
||||
if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
|
||||
return Ty->getContext().getConstantVector(
|
||||
std::vector<Constant *>(VTy->getNumElements(), C));
|
||||
|
||||
return C;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ConstantFP
|
||||
//===----------------------------------------------------------------------===//
|
||||
@ -758,275 +825,6 @@ bool ConstantFP::isValueValidForType(const Type *Ty, const APFloat& Val) {
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Factory Function Implementation
|
||||
|
||||
|
||||
// The number of operands for each ConstantCreator::create method is
|
||||
// determined by the ConstantTraits template.
|
||||
// ConstantCreator - A class that is used to create constants by
|
||||
// ValueMap*. This class should be partially specialized if there is
|
||||
// something strange that needs to be done to interface to the ctor for the
|
||||
// constant.
|
||||
//
|
||||
namespace llvm {
|
||||
template<class ValType>
|
||||
struct ConstantTraits;
|
||||
|
||||
template<typename T, typename Alloc>
|
||||
struct VISIBILITY_HIDDEN ConstantTraits< std::vector<T, Alloc> > {
|
||||
static unsigned uses(const std::vector<T, Alloc>& v) {
|
||||
return v.size();
|
||||
}
|
||||
};
|
||||
|
||||
template<class ConstantClass, class TypeClass, class ValType>
|
||||
struct VISIBILITY_HIDDEN ConstantCreator {
|
||||
static ConstantClass *create(const TypeClass *Ty, const ValType &V) {
|
||||
return new(ConstantTraits<ValType>::uses(V)) ConstantClass(Ty, V);
|
||||
}
|
||||
};
|
||||
|
||||
template<class ConstantClass, class TypeClass>
|
||||
struct VISIBILITY_HIDDEN ConvertConstantType {
|
||||
static void convert(ConstantClass *OldC, const TypeClass *NewTy) {
|
||||
llvm_unreachable("This type cannot be converted!");
|
||||
}
|
||||
};
|
||||
|
||||
template<class ValType, class TypeClass, class ConstantClass,
|
||||
bool HasLargeKey = false /*true for arrays and structs*/ >
|
||||
class VISIBILITY_HIDDEN ValueMap : public AbstractTypeUser {
|
||||
public:
|
||||
typedef std::pair<const Type*, ValType> MapKey;
|
||||
typedef std::map<MapKey, Constant *> MapTy;
|
||||
typedef std::map<Constant*, typename MapTy::iterator> InverseMapTy;
|
||||
typedef std::map<const Type*, typename MapTy::iterator> AbstractTypeMapTy;
|
||||
private:
|
||||
/// Map - This is the main map from the element descriptor to the Constants.
|
||||
/// This is the primary way we avoid creating two of the same shape
|
||||
/// constant.
|
||||
MapTy Map;
|
||||
|
||||
/// InverseMap - If "HasLargeKey" is true, this contains an inverse mapping
|
||||
/// from the constants to their element in Map. This is important for
|
||||
/// removal of constants from the array, which would otherwise have to scan
|
||||
/// through the map with very large keys.
|
||||
InverseMapTy InverseMap;
|
||||
|
||||
/// AbstractTypeMap - Map for abstract type constants.
|
||||
///
|
||||
AbstractTypeMapTy AbstractTypeMap;
|
||||
|
||||
/// ValueMapLock - Mutex for this map.
|
||||
sys::SmartMutex<true> ValueMapLock;
|
||||
|
||||
public:
|
||||
// NOTE: This function is not locked. It is the caller's responsibility
|
||||
// to enforce proper synchronization.
|
||||
typename MapTy::iterator map_end() { return Map.end(); }
|
||||
|
||||
/// InsertOrGetItem - Return an iterator for the specified element.
|
||||
/// If the element exists in the map, the returned iterator points to the
|
||||
/// entry and Exists=true. If not, the iterator points to the newly
|
||||
/// inserted entry and returns Exists=false. Newly inserted entries have
|
||||
/// I->second == 0, and should be filled in.
|
||||
/// NOTE: This function is not locked. It is the caller's responsibility
|
||||
// to enforce proper synchronization.
|
||||
typename MapTy::iterator InsertOrGetItem(std::pair<MapKey, Constant *>
|
||||
&InsertVal,
|
||||
bool &Exists) {
|
||||
std::pair<typename MapTy::iterator, bool> IP = Map.insert(InsertVal);
|
||||
Exists = !IP.second;
|
||||
return IP.first;
|
||||
}
|
||||
|
||||
private:
|
||||
typename MapTy::iterator FindExistingElement(ConstantClass *CP) {
|
||||
if (HasLargeKey) {
|
||||
typename InverseMapTy::iterator IMI = InverseMap.find(CP);
|
||||
assert(IMI != InverseMap.end() && IMI->second != Map.end() &&
|
||||
IMI->second->second == CP &&
|
||||
"InverseMap corrupt!");
|
||||
return IMI->second;
|
||||
}
|
||||
|
||||
typename MapTy::iterator I =
|
||||
Map.find(MapKey(static_cast<const TypeClass*>(CP->getRawType()),
|
||||
getValType(CP)));
|
||||
if (I == Map.end() || I->second != CP) {
|
||||
// FIXME: This should not use a linear scan. If this gets to be a
|
||||
// performance problem, someone should look at this.
|
||||
for (I = Map.begin(); I != Map.end() && I->second != CP; ++I)
|
||||
/* empty */;
|
||||
}
|
||||
return I;
|
||||
}
|
||||
|
||||
ConstantClass* Create(const TypeClass *Ty, const ValType &V,
|
||||
typename MapTy::iterator I) {
|
||||
ConstantClass* Result =
|
||||
ConstantCreator<ConstantClass,TypeClass,ValType>::create(Ty, V);
|
||||
|
||||
assert(Result->getType() == Ty && "Type specified is not correct!");
|
||||
I = Map.insert(I, std::make_pair(MapKey(Ty, V), Result));
|
||||
|
||||
if (HasLargeKey) // Remember the reverse mapping if needed.
|
||||
InverseMap.insert(std::make_pair(Result, I));
|
||||
|
||||
// If the type of the constant is abstract, make sure that an entry
|
||||
// exists for it in the AbstractTypeMap.
|
||||
if (Ty->isAbstract()) {
|
||||
typename AbstractTypeMapTy::iterator TI =
|
||||
AbstractTypeMap.find(Ty);
|
||||
|
||||
if (TI == AbstractTypeMap.end()) {
|
||||
// Add ourselves to the ATU list of the type.
|
||||
cast<DerivedType>(Ty)->addAbstractTypeUser(this);
|
||||
|
||||
AbstractTypeMap.insert(TI, std::make_pair(Ty, I));
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
public:
|
||||
|
||||
/// getOrCreate - Return the specified constant from the map, creating it if
|
||||
/// necessary.
|
||||
ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) {
|
||||
sys::SmartScopedLock<true> Lock(ValueMapLock);
|
||||
MapKey Lookup(Ty, V);
|
||||
ConstantClass* Result = 0;
|
||||
|
||||
typename MapTy::iterator I = Map.find(Lookup);
|
||||
// Is it in the map?
|
||||
if (I != Map.end())
|
||||
Result = static_cast<ConstantClass *>(I->second);
|
||||
|
||||
if (!Result) {
|
||||
// If no preexisting value, create one now...
|
||||
Result = Create(Ty, V, I);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
void remove(ConstantClass *CP) {
|
||||
sys::SmartScopedLock<true> Lock(ValueMapLock);
|
||||
typename MapTy::iterator I = FindExistingElement(CP);
|
||||
assert(I != Map.end() && "Constant not found in constant table!");
|
||||
assert(I->second == CP && "Didn't find correct element?");
|
||||
|
||||
if (HasLargeKey) // Remember the reverse mapping if needed.
|
||||
InverseMap.erase(CP);
|
||||
|
||||
// Now that we found the entry, make sure this isn't the entry that
|
||||
// the AbstractTypeMap points to.
|
||||
const TypeClass *Ty = static_cast<const TypeClass *>(I->first.first);
|
||||
if (Ty->isAbstract()) {
|
||||
assert(AbstractTypeMap.count(Ty) &&
|
||||
"Abstract type not in AbstractTypeMap?");
|
||||
typename MapTy::iterator &ATMEntryIt = AbstractTypeMap[Ty];
|
||||
if (ATMEntryIt == I) {
|
||||
// Yes, we are removing the representative entry for this type.
|
||||
// See if there are any other entries of the same type.
|
||||
typename MapTy::iterator TmpIt = ATMEntryIt;
|
||||
|
||||
// First check the entry before this one...
|
||||
if (TmpIt != Map.begin()) {
|
||||
--TmpIt;
|
||||
if (TmpIt->first.first != Ty) // Not the same type, move back...
|
||||
++TmpIt;
|
||||
}
|
||||
|
||||
// If we didn't find the same type, try to move forward...
|
||||
if (TmpIt == ATMEntryIt) {
|
||||
++TmpIt;
|
||||
if (TmpIt == Map.end() || TmpIt->first.first != Ty)
|
||||
--TmpIt; // No entry afterwards with the same type
|
||||
}
|
||||
|
||||
// If there is another entry in the map of the same abstract type,
|
||||
// update the AbstractTypeMap entry now.
|
||||
if (TmpIt != ATMEntryIt) {
|
||||
ATMEntryIt = TmpIt;
|
||||
} else {
|
||||
// Otherwise, we are removing the last instance of this type
|
||||
// from the table. Remove from the ATM, and from user list.
|
||||
cast<DerivedType>(Ty)->removeAbstractTypeUser(this);
|
||||
AbstractTypeMap.erase(Ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map.erase(I);
|
||||
}
|
||||
|
||||
|
||||
/// MoveConstantToNewSlot - If we are about to change C to be the element
|
||||
/// specified by I, update our internal data structures to reflect this
|
||||
/// fact.
|
||||
/// NOTE: This function is not locked. It is the responsibility of the
|
||||
/// caller to enforce proper synchronization if using this method.
|
||||
void MoveConstantToNewSlot(ConstantClass *C, typename MapTy::iterator I) {
|
||||
// First, remove the old location of the specified constant in the map.
|
||||
typename MapTy::iterator OldI = FindExistingElement(C);
|
||||
assert(OldI != Map.end() && "Constant not found in constant table!");
|
||||
assert(OldI->second == C && "Didn't find correct element?");
|
||||
|
||||
// If this constant is the representative element for its abstract type,
|
||||
// update the AbstractTypeMap so that the representative element is I.
|
||||
if (C->getType()->isAbstract()) {
|
||||
typename AbstractTypeMapTy::iterator ATI =
|
||||
AbstractTypeMap.find(C->getType());
|
||||
assert(ATI != AbstractTypeMap.end() &&
|
||||
"Abstract type not in AbstractTypeMap?");
|
||||
if (ATI->second == OldI)
|
||||
ATI->second = I;
|
||||
}
|
||||
|
||||
// Remove the old entry from the map.
|
||||
Map.erase(OldI);
|
||||
|
||||
// Update the inverse map so that we know that this constant is now
|
||||
// located at descriptor I.
|
||||
if (HasLargeKey) {
|
||||
assert(I->second == C && "Bad inversemap entry!");
|
||||
InverseMap[C] = I;
|
||||
}
|
||||
}
|
||||
|
||||
void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
|
||||
sys::SmartScopedLock<true> Lock(ValueMapLock);
|
||||
typename AbstractTypeMapTy::iterator I =
|
||||
AbstractTypeMap.find(cast<Type>(OldTy));
|
||||
|
||||
assert(I != AbstractTypeMap.end() &&
|
||||
"Abstract type not in AbstractTypeMap?");
|
||||
|
||||
// Convert a constant at a time until the last one is gone. The last one
|
||||
// leaving will remove() itself, causing the AbstractTypeMapEntry to be
|
||||
// eliminated eventually.
|
||||
do {
|
||||
ConvertConstantType<ConstantClass,
|
||||
TypeClass>::convert(
|
||||
static_cast<ConstantClass *>(I->second->second),
|
||||
cast<TypeClass>(NewTy));
|
||||
|
||||
I = AbstractTypeMap.find(cast<Type>(OldTy));
|
||||
} while (I != AbstractTypeMap.end());
|
||||
}
|
||||
|
||||
// If the type became concrete without being refined to any other existing
|
||||
// type, we just remove ourselves from the ATU list.
|
||||
void typeBecameConcrete(const DerivedType *AbsTy) {
|
||||
AbsTy->removeAbstractTypeUser(this);
|
||||
}
|
||||
|
||||
void dump() const {
|
||||
DOUT << "Constant.cpp: ValueMap\n";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// destroyConstant - Remove the constant from the constant table...
|
||||
///
|
||||
void ConstantAggregateZero::destroyConstant() {
|
||||
|
@ -365,8 +365,7 @@ LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) {
|
||||
|
||||
LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
|
||||
int SignExtend) {
|
||||
return wrap(getGlobalContext().getConstantInt(unwrap<IntegerType>(IntTy), N,
|
||||
SignExtend != 0));
|
||||
return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
|
||||
}
|
||||
|
||||
static const fltSemantics &SemanticsForType(Type *Ty) {
|
||||
|
@ -704,7 +704,7 @@ void BranchInst::setSuccessorV(unsigned idx, BasicBlock *B) {
|
||||
|
||||
static Value *getAISize(LLVMContext &Context, Value *Amt) {
|
||||
if (!Amt)
|
||||
Amt = Context.getConstantInt(Type::Int32Ty, 1);
|
||||
Amt = ConstantInt::get(Type::Int32Ty, 1);
|
||||
else {
|
||||
assert(!isa<BasicBlock>(Amt) &&
|
||||
"Passed basic block into allocation size parameter! Use other ctor");
|
||||
|
@ -39,7 +39,7 @@ static const uint64_t zero[2] = {0, 0};
|
||||
Constant* LLVMContext::getNullValue(const Type* Ty) {
|
||||
switch (Ty->getTypeID()) {
|
||||
case Type::IntegerTyID:
|
||||
return getConstantInt(Ty, 0);
|
||||
return ConstantInt::get(Ty, 0);
|
||||
case Type::FloatTyID:
|
||||
return getConstantFP(APFloat(APInt(32, 0)));
|
||||
case Type::DoubleTyID:
|
||||
@ -65,7 +65,7 @@ Constant* LLVMContext::getNullValue(const Type* Ty) {
|
||||
|
||||
Constant* LLVMContext::getAllOnesValue(const Type* Ty) {
|
||||
if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
|
||||
return getConstantInt(APInt::getAllOnesValue(ITy->getBitWidth()));
|
||||
return ConstantInt::get(*this, APInt::getAllOnesValue(ITy->getBitWidth()));
|
||||
|
||||
std::vector<Constant*> Elts;
|
||||
const VectorType* VTy = cast<VectorType>(Ty);
|
||||
@ -92,51 +92,6 @@ ConstantInt* LLVMContext::getFalse() {
|
||||
return pImpl->getFalse();
|
||||
}
|
||||
|
||||
Constant* LLVMContext::getConstantInt(const Type* Ty, uint64_t V,
|
||||
bool isSigned) {
|
||||
Constant *C = getConstantInt(cast<IntegerType>(Ty->getScalarType()),
|
||||
V, isSigned);
|
||||
|
||||
// For vectors, broadcast the value.
|
||||
if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
|
||||
return
|
||||
getConstantVector(std::vector<Constant *>(VTy->getNumElements(), C));
|
||||
|
||||
return C;
|
||||
}
|
||||
|
||||
|
||||
ConstantInt* LLVMContext::getConstantInt(const IntegerType* Ty, uint64_t V,
|
||||
bool isSigned) {
|
||||
return getConstantInt(APInt(Ty->getBitWidth(), V, isSigned));
|
||||
}
|
||||
|
||||
ConstantInt* LLVMContext::getConstantIntSigned(const IntegerType* Ty,
|
||||
int64_t V) {
|
||||
return getConstantInt(Ty, V, true);
|
||||
}
|
||||
|
||||
Constant *LLVMContext::getConstantIntSigned(const Type *Ty, int64_t V) {
|
||||
return getConstantInt(Ty, V, true);
|
||||
}
|
||||
|
||||
ConstantInt* LLVMContext::getConstantInt(const APInt& V) {
|
||||
return pImpl->getConstantInt(V);
|
||||
}
|
||||
|
||||
Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) {
|
||||
ConstantInt *C = getConstantInt(V);
|
||||
assert(C->getType() == Ty->getScalarType() &&
|
||||
"ConstantInt type doesn't match the type implied by its value!");
|
||||
|
||||
// For vectors, broadcast the value.
|
||||
if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
|
||||
return
|
||||
getConstantVector(std::vector<Constant *>(VTy->getNumElements(), C));
|
||||
|
||||
return C;
|
||||
}
|
||||
|
||||
// ConstantPointerNull accessors.
|
||||
ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) {
|
||||
return ConstantPointerNull::get(T);
|
||||
@ -194,11 +149,11 @@ Constant* LLVMContext::getConstantArray(const std::string& Str,
|
||||
bool AddNull) {
|
||||
std::vector<Constant*> ElementVals;
|
||||
for (unsigned i = 0; i < Str.length(); ++i)
|
||||
ElementVals.push_back(getConstantInt(Type::Int8Ty, Str[i]));
|
||||
ElementVals.push_back(ConstantInt::get(Type::Int8Ty, Str[i]));
|
||||
|
||||
// Add a null terminator to the string...
|
||||
if (AddNull) {
|
||||
ElementVals.push_back(getConstantInt(Type::Int8Ty, 0));
|
||||
ElementVals.push_back(ConstantInt::get(Type::Int8Ty, 0));
|
||||
}
|
||||
|
||||
ArrayType *ATy = getArrayType(Type::Int8Ty, ElementVals.size());
|
||||
@ -302,8 +257,8 @@ Constant* LLVMContext::getConstantExprAlignOf(const Type* Ty) {
|
||||
// alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1
|
||||
const Type *AligningTy = getStructType(Type::Int8Ty, Ty, NULL);
|
||||
Constant *NullPtr = getNullValue(AligningTy->getPointerTo());
|
||||
Constant *Zero = getConstantInt(Type::Int32Ty, 0);
|
||||
Constant *One = getConstantInt(Type::Int32Ty, 1);
|
||||
Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
|
||||
Constant *One = ConstantInt::get(Type::Int32Ty, 1);
|
||||
Constant *Indices[2] = { Zero, One };
|
||||
Constant *GEP = getConstantExprGetElementPtr(NullPtr, Indices, 2);
|
||||
return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int32Ty);
|
||||
@ -463,7 +418,7 @@ Constant* LLVMContext::getConstantExprInsertValue(Constant* Agg, Constant* Val,
|
||||
|
||||
Constant* LLVMContext::getConstantExprSizeOf(const Type* Ty) {
|
||||
// sizeof is implemented as: (i64) gep (Ty*)null, 1
|
||||
Constant *GEPIdx = getConstantInt(Type::Int32Ty, 1);
|
||||
Constant *GEPIdx = ConstantInt::get(Type::Int32Ty, 1);
|
||||
Constant *GEP = getConstantExprGetElementPtr(
|
||||
getNullValue(getPointerTypeUnqual(Ty)), &GEPIdx, 1);
|
||||
return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int64Ty);
|
||||
|
@ -45,368 +45,10 @@ static std::vector<Constant*> getValType(ConstantVector *CP) {
|
||||
return Elements;
|
||||
}
|
||||
|
||||
namespace llvm {
|
||||
template<typename T, typename Alloc>
|
||||
struct VISIBILITY_HIDDEN ConstantTraits< std::vector<T, Alloc> > {
|
||||
static unsigned uses(const std::vector<T, Alloc>& v) {
|
||||
return v.size();
|
||||
}
|
||||
};
|
||||
|
||||
template<class ConstantClass, class TypeClass, class ValType>
|
||||
struct VISIBILITY_HIDDEN ConstantCreator {
|
||||
static ConstantClass *create(const TypeClass *Ty, const ValType &V) {
|
||||
return new(ConstantTraits<ValType>::uses(V)) ConstantClass(Ty, V);
|
||||
}
|
||||
};
|
||||
|
||||
template<class ConstantClass, class TypeClass>
|
||||
struct VISIBILITY_HIDDEN ConvertConstantType {
|
||||
static void convert(ConstantClass *OldC, const TypeClass *NewTy) {
|
||||
llvm_unreachable("This type cannot be converted!");
|
||||
}
|
||||
};
|
||||
|
||||
// ConstantAggregateZero does not take extra "value" argument...
|
||||
template<class ValType>
|
||||
struct ConstantCreator<ConstantAggregateZero, Type, ValType> {
|
||||
static ConstantAggregateZero *create(const Type *Ty, const ValType &V){
|
||||
return new ConstantAggregateZero(Ty);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ConvertConstantType<ConstantAggregateZero, Type> {
|
||||
static void convert(ConstantAggregateZero *OldC, const Type *NewTy) {
|
||||
// Make everyone now use a constant of the new type...
|
||||
Constant *New = NewTy->getContext().getConstantAggregateZero(NewTy);
|
||||
assert(New != OldC && "Didn't replace constant??");
|
||||
OldC->uncheckedReplaceAllUsesWith(New);
|
||||
OldC->destroyConstant(); // This constant is now dead, destroy it.
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ConvertConstantType<ConstantArray, ArrayType> {
|
||||
static void convert(ConstantArray *OldC, const ArrayType *NewTy) {
|
||||
// Make everyone now use a constant of the new type...
|
||||
std::vector<Constant*> C;
|
||||
for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
|
||||
C.push_back(cast<Constant>(OldC->getOperand(i)));
|
||||
Constant *New = NewTy->getContext().getConstantArray(NewTy, C);
|
||||
assert(New != OldC && "Didn't replace constant??");
|
||||
OldC->uncheckedReplaceAllUsesWith(New);
|
||||
OldC->destroyConstant(); // This constant is now dead, destroy it.
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ConvertConstantType<ConstantStruct, StructType> {
|
||||
static void convert(ConstantStruct *OldC, const StructType *NewTy) {
|
||||
// Make everyone now use a constant of the new type...
|
||||
std::vector<Constant*> C;
|
||||
for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
|
||||
C.push_back(cast<Constant>(OldC->getOperand(i)));
|
||||
Constant *New = NewTy->getContext().getConstantStruct(NewTy, C);
|
||||
assert(New != OldC && "Didn't replace constant??");
|
||||
|
||||
OldC->uncheckedReplaceAllUsesWith(New);
|
||||
OldC->destroyConstant(); // This constant is now dead, destroy it.
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ConvertConstantType<ConstantVector, VectorType> {
|
||||
static void convert(ConstantVector *OldC, const VectorType *NewTy) {
|
||||
// Make everyone now use a constant of the new type...
|
||||
std::vector<Constant*> C;
|
||||
for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
|
||||
C.push_back(cast<Constant>(OldC->getOperand(i)));
|
||||
Constant *New = OldC->getContext().getConstantVector(NewTy, C);
|
||||
assert(New != OldC && "Didn't replace constant??");
|
||||
OldC->uncheckedReplaceAllUsesWith(New);
|
||||
OldC->destroyConstant(); // This constant is now dead, destroy it.
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template<class ValType, class TypeClass, class ConstantClass,
|
||||
bool HasLargeKey /*true for arrays and structs*/ >
|
||||
class VISIBILITY_HIDDEN ValueMap : public AbstractTypeUser {
|
||||
public:
|
||||
typedef std::pair<const Type*, ValType> MapKey;
|
||||
typedef std::map<MapKey, Constant *> MapTy;
|
||||
typedef std::map<Constant*, typename MapTy::iterator> InverseMapTy;
|
||||
typedef std::map<const Type*, typename MapTy::iterator> AbstractTypeMapTy;
|
||||
private:
|
||||
/// Map - This is the main map from the element descriptor to the Constants.
|
||||
/// This is the primary way we avoid creating two of the same shape
|
||||
/// constant.
|
||||
MapTy Map;
|
||||
|
||||
/// InverseMap - If "HasLargeKey" is true, this contains an inverse mapping
|
||||
/// from the constants to their element in Map. This is important for
|
||||
/// removal of constants from the array, which would otherwise have to scan
|
||||
/// through the map with very large keys.
|
||||
InverseMapTy InverseMap;
|
||||
|
||||
/// AbstractTypeMap - Map for abstract type constants.
|
||||
///
|
||||
AbstractTypeMapTy AbstractTypeMap;
|
||||
|
||||
/// ValueMapLock - Mutex for this map.
|
||||
sys::SmartMutex<true> ValueMapLock;
|
||||
|
||||
public:
|
||||
// NOTE: This function is not locked. It is the caller's responsibility
|
||||
// to enforce proper synchronization.
|
||||
typename MapTy::iterator map_end() { return Map.end(); }
|
||||
|
||||
/// InsertOrGetItem - Return an iterator for the specified element.
|
||||
/// If the element exists in the map, the returned iterator points to the
|
||||
/// entry and Exists=true. If not, the iterator points to the newly
|
||||
/// inserted entry and returns Exists=false. Newly inserted entries have
|
||||
/// I->second == 0, and should be filled in.
|
||||
/// NOTE: This function is not locked. It is the caller's responsibility
|
||||
// to enforce proper synchronization.
|
||||
typename MapTy::iterator InsertOrGetItem(std::pair<MapKey, Constant *>
|
||||
&InsertVal,
|
||||
bool &Exists) {
|
||||
std::pair<typename MapTy::iterator, bool> IP = Map.insert(InsertVal);
|
||||
Exists = !IP.second;
|
||||
return IP.first;
|
||||
}
|
||||
|
||||
private:
|
||||
typename MapTy::iterator FindExistingElement(ConstantClass *CP) {
|
||||
if (HasLargeKey) {
|
||||
typename InverseMapTy::iterator IMI = InverseMap.find(CP);
|
||||
assert(IMI != InverseMap.end() && IMI->second != Map.end() &&
|
||||
IMI->second->second == CP &&
|
||||
"InverseMap corrupt!");
|
||||
return IMI->second;
|
||||
}
|
||||
|
||||
typename MapTy::iterator I =
|
||||
Map.find(MapKey(static_cast<const TypeClass*>(CP->getRawType()),
|
||||
getValType(CP)));
|
||||
if (I == Map.end() || I->second != CP) {
|
||||
// FIXME: This should not use a linear scan. If this gets to be a
|
||||
// performance problem, someone should look at this.
|
||||
for (I = Map.begin(); I != Map.end() && I->second != CP; ++I)
|
||||
/* empty */;
|
||||
}
|
||||
return I;
|
||||
}
|
||||
|
||||
ConstantClass* Create(const TypeClass *Ty, const ValType &V,
|
||||
typename MapTy::iterator I) {
|
||||
ConstantClass* Result =
|
||||
ConstantCreator<ConstantClass,TypeClass,ValType>::create(Ty, V);
|
||||
|
||||
assert(Result->getType() == Ty && "Type specified is not correct!");
|
||||
I = Map.insert(I, std::make_pair(MapKey(Ty, V), Result));
|
||||
|
||||
if (HasLargeKey) // Remember the reverse mapping if needed.
|
||||
InverseMap.insert(std::make_pair(Result, I));
|
||||
|
||||
// If the type of the constant is abstract, make sure that an entry
|
||||
// exists for it in the AbstractTypeMap.
|
||||
if (Ty->isAbstract()) {
|
||||
typename AbstractTypeMapTy::iterator TI =
|
||||
AbstractTypeMap.find(Ty);
|
||||
|
||||
if (TI == AbstractTypeMap.end()) {
|
||||
// Add ourselves to the ATU list of the type.
|
||||
cast<DerivedType>(Ty)->addAbstractTypeUser(this);
|
||||
|
||||
AbstractTypeMap.insert(TI, std::make_pair(Ty, I));
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
public:
|
||||
|
||||
/// getOrCreate - Return the specified constant from the map, creating it if
|
||||
/// necessary.
|
||||
ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) {
|
||||
sys::SmartScopedLock<true> Lock(ValueMapLock);
|
||||
MapKey Lookup(Ty, V);
|
||||
ConstantClass* Result = 0;
|
||||
|
||||
typename MapTy::iterator I = Map.find(Lookup);
|
||||
// Is it in the map?
|
||||
if (I != Map.end())
|
||||
Result = static_cast<ConstantClass *>(I->second);
|
||||
|
||||
if (!Result) {
|
||||
// If no preexisting value, create one now...
|
||||
Result = Create(Ty, V, I);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
void remove(ConstantClass *CP) {
|
||||
sys::SmartScopedLock<true> Lock(ValueMapLock);
|
||||
typename MapTy::iterator I = FindExistingElement(CP);
|
||||
assert(I != Map.end() && "Constant not found in constant table!");
|
||||
assert(I->second == CP && "Didn't find correct element?");
|
||||
|
||||
if (HasLargeKey) // Remember the reverse mapping if needed.
|
||||
InverseMap.erase(CP);
|
||||
|
||||
// Now that we found the entry, make sure this isn't the entry that
|
||||
// the AbstractTypeMap points to.
|
||||
const TypeClass *Ty = static_cast<const TypeClass *>(I->first.first);
|
||||
if (Ty->isAbstract()) {
|
||||
assert(AbstractTypeMap.count(Ty) &&
|
||||
"Abstract type not in AbstractTypeMap?");
|
||||
typename MapTy::iterator &ATMEntryIt = AbstractTypeMap[Ty];
|
||||
if (ATMEntryIt == I) {
|
||||
// Yes, we are removing the representative entry for this type.
|
||||
// See if there are any other entries of the same type.
|
||||
typename MapTy::iterator TmpIt = ATMEntryIt;
|
||||
|
||||
// First check the entry before this one...
|
||||
if (TmpIt != Map.begin()) {
|
||||
--TmpIt;
|
||||
if (TmpIt->first.first != Ty) // Not the same type, move back...
|
||||
++TmpIt;
|
||||
}
|
||||
|
||||
// If we didn't find the same type, try to move forward...
|
||||
if (TmpIt == ATMEntryIt) {
|
||||
++TmpIt;
|
||||
if (TmpIt == Map.end() || TmpIt->first.first != Ty)
|
||||
--TmpIt; // No entry afterwards with the same type
|
||||
}
|
||||
|
||||
// If there is another entry in the map of the same abstract type,
|
||||
// update the AbstractTypeMap entry now.
|
||||
if (TmpIt != ATMEntryIt) {
|
||||
ATMEntryIt = TmpIt;
|
||||
} else {
|
||||
// Otherwise, we are removing the last instance of this type
|
||||
// from the table. Remove from the ATM, and from user list.
|
||||
cast<DerivedType>(Ty)->removeAbstractTypeUser(this);
|
||||
AbstractTypeMap.erase(Ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map.erase(I);
|
||||
}
|
||||
|
||||
|
||||
/// MoveConstantToNewSlot - If we are about to change C to be the element
|
||||
/// specified by I, update our internal data structures to reflect this
|
||||
/// fact.
|
||||
/// NOTE: This function is not locked. It is the responsibility of the
|
||||
/// caller to enforce proper synchronization if using this method.
|
||||
void MoveConstantToNewSlot(ConstantClass *C, typename MapTy::iterator I) {
|
||||
// First, remove the old location of the specified constant in the map.
|
||||
typename MapTy::iterator OldI = FindExistingElement(C);
|
||||
assert(OldI != Map.end() && "Constant not found in constant table!");
|
||||
assert(OldI->second == C && "Didn't find correct element?");
|
||||
|
||||
// If this constant is the representative element for its abstract type,
|
||||
// update the AbstractTypeMap so that the representative element is I.
|
||||
if (C->getType()->isAbstract()) {
|
||||
typename AbstractTypeMapTy::iterator ATI =
|
||||
AbstractTypeMap.find(C->getType());
|
||||
assert(ATI != AbstractTypeMap.end() &&
|
||||
"Abstract type not in AbstractTypeMap?");
|
||||
if (ATI->second == OldI)
|
||||
ATI->second = I;
|
||||
}
|
||||
|
||||
// Remove the old entry from the map.
|
||||
Map.erase(OldI);
|
||||
|
||||
// Update the inverse map so that we know that this constant is now
|
||||
// located at descriptor I.
|
||||
if (HasLargeKey) {
|
||||
assert(I->second == C && "Bad inversemap entry!");
|
||||
InverseMap[C] = I;
|
||||
}
|
||||
}
|
||||
|
||||
void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
|
||||
sys::SmartScopedLock<true> Lock(ValueMapLock);
|
||||
typename AbstractTypeMapTy::iterator I =
|
||||
AbstractTypeMap.find(cast<Type>(OldTy));
|
||||
|
||||
assert(I != AbstractTypeMap.end() &&
|
||||
"Abstract type not in AbstractTypeMap?");
|
||||
|
||||
// Convert a constant at a time until the last one is gone. The last one
|
||||
// leaving will remove() itself, causing the AbstractTypeMapEntry to be
|
||||
// eliminated eventually.
|
||||
do {
|
||||
ConvertConstantType<ConstantClass,
|
||||
TypeClass>::convert(
|
||||
static_cast<ConstantClass *>(I->second->second),
|
||||
cast<TypeClass>(NewTy));
|
||||
|
||||
I = AbstractTypeMap.find(cast<Type>(OldTy));
|
||||
} while (I != AbstractTypeMap.end());
|
||||
}
|
||||
|
||||
// If the type became concrete without being refined to any other existing
|
||||
// type, we just remove ourselves from the ATU list.
|
||||
void typeBecameConcrete(const DerivedType *AbsTy) {
|
||||
AbsTy->removeAbstractTypeUser(this);
|
||||
}
|
||||
|
||||
void dump() const {
|
||||
DOUT << "Constant.cpp: ValueMap\n";
|
||||
}
|
||||
};
|
||||
|
||||
LLVMContextImpl::LLVMContextImpl(LLVMContext &C) :
|
||||
Context(C), TheTrueVal(0), TheFalseVal(0) {
|
||||
AggZeroConstants = new ValueMap<char, Type, ConstantAggregateZero>();
|
||||
ArrayConstants = new ArrayConstantsTy();
|
||||
StructConstants = new StructConstantsTy();
|
||||
VectorConstants = new VectorConstantsTy();
|
||||
}
|
||||
Context(C), TheTrueVal(0), TheFalseVal(0) { }
|
||||
|
||||
LLVMContextImpl::~LLVMContextImpl() {
|
||||
delete AggZeroConstants;
|
||||
delete ArrayConstants;
|
||||
delete StructConstants;
|
||||
delete VectorConstants;
|
||||
}
|
||||
|
||||
// Get a ConstantInt from an APInt. Note that the value stored in the DenseMap
|
||||
// as the key, is a DenseMapAPIntKeyInfo::KeyTy which has provided the
|
||||
// operator== and operator!= to ensure that the DenseMap doesn't attempt to
|
||||
// compare APInt's of different widths, which would violate an APInt class
|
||||
// invariant which generates an assertion.
|
||||
ConstantInt *LLVMContextImpl::getConstantInt(const APInt& V) {
|
||||
// Get the corresponding integer type for the bit width of the value.
|
||||
const IntegerType *ITy = Context.getIntegerType(V.getBitWidth());
|
||||
// get an existing value or the insertion position
|
||||
DenseMapAPIntKeyInfo::KeyTy Key(V, ITy);
|
||||
|
||||
ConstantsLock.reader_acquire();
|
||||
ConstantInt *&Slot = IntConstants[Key];
|
||||
ConstantsLock.reader_release();
|
||||
|
||||
if (!Slot) {
|
||||
sys::SmartScopedWriter<true> Writer(ConstantsLock);
|
||||
ConstantInt *&NewSlot = IntConstants[Key];
|
||||
if (!Slot) {
|
||||
NewSlot = new ConstantInt(ITy, V);
|
||||
}
|
||||
|
||||
return NewSlot;
|
||||
} else {
|
||||
return Slot;
|
||||
}
|
||||
}
|
||||
|
||||
ConstantFP *LLVMContextImpl::getConstantFP(const APFloat &V) {
|
||||
DenseMapAPFloatKeyInfo::KeyTy Key(V);
|
||||
@ -483,7 +125,7 @@ LLVMContextImpl::getConstantAggregateZero(const Type *Ty) {
|
||||
"Cannot create an aggregate zero of non-aggregate type!");
|
||||
|
||||
// Implicitly locked.
|
||||
return AggZeroConstants->getOrCreate(Ty, 0);
|
||||
return AggZeroConstants.getOrCreate(Ty, 0);
|
||||
}
|
||||
|
||||
Constant *LLVMContextImpl::getConstantArray(const ArrayType *Ty,
|
||||
@ -493,12 +135,12 @@ Constant *LLVMContextImpl::getConstantArray(const ArrayType *Ty,
|
||||
Constant *C = V[0];
|
||||
if (!C->isNullValue()) {
|
||||
// Implicitly locked.
|
||||
return ArrayConstants->getOrCreate(Ty, V);
|
||||
return ArrayConstants.getOrCreate(Ty, V);
|
||||
}
|
||||
for (unsigned i = 1, e = V.size(); i != e; ++i)
|
||||
if (V[i] != C) {
|
||||
// Implicitly locked.
|
||||
return ArrayConstants->getOrCreate(Ty, V);
|
||||
return ArrayConstants.getOrCreate(Ty, V);
|
||||
}
|
||||
}
|
||||
|
||||
@ -511,7 +153,7 @@ Constant *LLVMContextImpl::getConstantStruct(const StructType *Ty,
|
||||
for (unsigned i = 0, e = V.size(); i != e; ++i)
|
||||
if (!V[i]->isNullValue())
|
||||
// Implicitly locked.
|
||||
return StructConstants->getOrCreate(Ty, V);
|
||||
return StructConstants.getOrCreate(Ty, V);
|
||||
|
||||
return Context.getConstantAggregateZero(Ty);
|
||||
}
|
||||
@ -539,7 +181,7 @@ Constant *LLVMContextImpl::getConstantVector(const VectorType *Ty,
|
||||
return Context.getUndef(Ty);
|
||||
|
||||
// Implicitly locked.
|
||||
return VectorConstants->getOrCreate(Ty, V);
|
||||
return VectorConstants.getOrCreate(Ty, V);
|
||||
}
|
||||
|
||||
// *** erase methods ***
|
||||
@ -556,19 +198,19 @@ void LLVMContextImpl::erase(MDNode *M) {
|
||||
}
|
||||
|
||||
void LLVMContextImpl::erase(ConstantAggregateZero *Z) {
|
||||
AggZeroConstants->remove(Z);
|
||||
AggZeroConstants.remove(Z);
|
||||
}
|
||||
|
||||
void LLVMContextImpl::erase(ConstantArray *C) {
|
||||
ArrayConstants->remove(C);
|
||||
ArrayConstants.remove(C);
|
||||
}
|
||||
|
||||
void LLVMContextImpl::erase(ConstantStruct *S) {
|
||||
StructConstants->remove(S);
|
||||
StructConstants.remove(S);
|
||||
}
|
||||
|
||||
void LLVMContextImpl::erase(ConstantVector *V) {
|
||||
VectorConstants->remove(V);
|
||||
VectorConstants.remove(V);
|
||||
}
|
||||
|
||||
// *** RAUW helpers ***
|
||||
@ -621,7 +263,7 @@ Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantArray *CA,
|
||||
sys::SmartScopedWriter<true> Writer(ConstantsLock);
|
||||
bool Exists;
|
||||
ArrayConstantsTy::MapTy::iterator I =
|
||||
ArrayConstants->InsertOrGetItem(Lookup, Exists);
|
||||
ArrayConstants.InsertOrGetItem(Lookup, Exists);
|
||||
|
||||
if (Exists) {
|
||||
Replacement = I->second;
|
||||
@ -630,7 +272,7 @@ Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantArray *CA,
|
||||
// creating a new constant array, inserting it, replaceallusesof'ing the
|
||||
// old with the new, then deleting the old... just update the current one
|
||||
// in place!
|
||||
ArrayConstants->MoveConstantToNewSlot(CA, I);
|
||||
ArrayConstants.MoveConstantToNewSlot(CA, I);
|
||||
|
||||
// Update to the new value. Optimize for the case when we have a single
|
||||
// operand that we're changing, but handle bulk updates efficiently.
|
||||
@ -693,7 +335,7 @@ Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantStruct *CS,
|
||||
sys::SmartScopedWriter<true> Writer(ConstantsLock);
|
||||
bool Exists;
|
||||
StructConstantsTy::MapTy::iterator I =
|
||||
StructConstants->InsertOrGetItem(Lookup, Exists);
|
||||
StructConstants.InsertOrGetItem(Lookup, Exists);
|
||||
|
||||
if (Exists) {
|
||||
Replacement = I->second;
|
||||
@ -702,7 +344,7 @@ Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantStruct *CS,
|
||||
// creating a new constant struct, inserting it, replaceallusesof'ing the
|
||||
// old with the new, then deleting the old... just update the current one
|
||||
// in place!
|
||||
StructConstants->MoveConstantToNewSlot(CS, I);
|
||||
StructConstants.MoveConstantToNewSlot(CS, I);
|
||||
|
||||
// Update to the new value.
|
||||
CS->setOperand(OperandToUpdate, ToC);
|
||||
|
@ -16,6 +16,7 @@
|
||||
#define LLVM_LLVMCONTEXT_IMPL_H
|
||||
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Constants.h"
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
@ -29,14 +30,336 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
template<class ValType, class TypeClass, class ConstantClass,
|
||||
bool HasLargeKey = false /*true for arrays and structs*/ >
|
||||
class ValueMap;
|
||||
|
||||
namespace llvm {
|
||||
template<class ValType>
|
||||
struct ConstantTraits;
|
||||
|
||||
// The number of operands for each ConstantCreator::create method is
|
||||
// determined by the ConstantTraits template.
|
||||
// ConstantCreator - A class that is used to create constants by
|
||||
// ValueMap*. This class should be partially specialized if there is
|
||||
// something strange that needs to be done to interface to the ctor for the
|
||||
// constant.
|
||||
//
|
||||
template<typename T, typename Alloc>
|
||||
struct VISIBILITY_HIDDEN ConstantTraits< std::vector<T, Alloc> > {
|
||||
static unsigned uses(const std::vector<T, Alloc>& v) {
|
||||
return v.size();
|
||||
}
|
||||
};
|
||||
|
||||
template<class ConstantClass, class TypeClass, class ValType>
|
||||
struct VISIBILITY_HIDDEN ConstantCreator {
|
||||
static ConstantClass *create(const TypeClass *Ty, const ValType &V) {
|
||||
return new(ConstantTraits<ValType>::uses(V)) ConstantClass(Ty, V);
|
||||
}
|
||||
};
|
||||
|
||||
template<class ConstantClass, class TypeClass>
|
||||
struct VISIBILITY_HIDDEN ConvertConstantType {
|
||||
static void convert(ConstantClass *OldC, const TypeClass *NewTy) {
|
||||
llvm_unreachable("This type cannot be converted!");
|
||||
}
|
||||
};
|
||||
|
||||
// ConstantAggregateZero does not take extra "value" argument...
|
||||
template<class ValType>
|
||||
struct ConstantCreator<ConstantAggregateZero, Type, ValType> {
|
||||
static ConstantAggregateZero *create(const Type *Ty, const ValType &V){
|
||||
return new ConstantAggregateZero(Ty);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ConvertConstantType<ConstantAggregateZero, Type> {
|
||||
static void convert(ConstantAggregateZero *OldC, const Type *NewTy) {
|
||||
// Make everyone now use a constant of the new type...
|
||||
Constant *New = NewTy->getContext().getConstantAggregateZero(NewTy);
|
||||
assert(New != OldC && "Didn't replace constant??");
|
||||
OldC->uncheckedReplaceAllUsesWith(New);
|
||||
OldC->destroyConstant(); // This constant is now dead, destroy it.
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ConvertConstantType<ConstantArray, ArrayType> {
|
||||
static void convert(ConstantArray *OldC, const ArrayType *NewTy) {
|
||||
// Make everyone now use a constant of the new type...
|
||||
std::vector<Constant*> C;
|
||||
for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
|
||||
C.push_back(cast<Constant>(OldC->getOperand(i)));
|
||||
Constant *New = NewTy->getContext().getConstantArray(NewTy, C);
|
||||
assert(New != OldC && "Didn't replace constant??");
|
||||
OldC->uncheckedReplaceAllUsesWith(New);
|
||||
OldC->destroyConstant(); // This constant is now dead, destroy it.
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ConvertConstantType<ConstantStruct, StructType> {
|
||||
static void convert(ConstantStruct *OldC, const StructType *NewTy) {
|
||||
// Make everyone now use a constant of the new type...
|
||||
std::vector<Constant*> C;
|
||||
for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
|
||||
C.push_back(cast<Constant>(OldC->getOperand(i)));
|
||||
Constant *New = NewTy->getContext().getConstantStruct(NewTy, C);
|
||||
assert(New != OldC && "Didn't replace constant??");
|
||||
|
||||
OldC->uncheckedReplaceAllUsesWith(New);
|
||||
OldC->destroyConstant(); // This constant is now dead, destroy it.
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct ConvertConstantType<ConstantVector, VectorType> {
|
||||
static void convert(ConstantVector *OldC, const VectorType *NewTy) {
|
||||
// Make everyone now use a constant of the new type...
|
||||
std::vector<Constant*> C;
|
||||
for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
|
||||
C.push_back(cast<Constant>(OldC->getOperand(i)));
|
||||
Constant *New = OldC->getContext().getConstantVector(NewTy, C);
|
||||
assert(New != OldC && "Didn't replace constant??");
|
||||
OldC->uncheckedReplaceAllUsesWith(New);
|
||||
OldC->destroyConstant(); // This constant is now dead, destroy it.
|
||||
}
|
||||
};
|
||||
|
||||
template<class ValType, class TypeClass, class ConstantClass,
|
||||
bool HasLargeKey = false /*true for arrays and structs*/ >
|
||||
class ValueMap : public AbstractTypeUser {
|
||||
public:
|
||||
typedef std::pair<const Type*, ValType> MapKey;
|
||||
typedef std::map<MapKey, Constant *> MapTy;
|
||||
typedef std::map<Constant*, typename MapTy::iterator> InverseMapTy;
|
||||
typedef std::map<const Type*, typename MapTy::iterator> AbstractTypeMapTy;
|
||||
private:
|
||||
/// Map - This is the main map from the element descriptor to the Constants.
|
||||
/// This is the primary way we avoid creating two of the same shape
|
||||
/// constant.
|
||||
MapTy Map;
|
||||
|
||||
/// InverseMap - If "HasLargeKey" is true, this contains an inverse mapping
|
||||
/// from the constants to their element in Map. This is important for
|
||||
/// removal of constants from the array, which would otherwise have to scan
|
||||
/// through the map with very large keys.
|
||||
InverseMapTy InverseMap;
|
||||
|
||||
/// AbstractTypeMap - Map for abstract type constants.
|
||||
///
|
||||
AbstractTypeMapTy AbstractTypeMap;
|
||||
|
||||
/// ValueMapLock - Mutex for this map.
|
||||
sys::SmartMutex<true> ValueMapLock;
|
||||
|
||||
public:
|
||||
// NOTE: This function is not locked. It is the caller's responsibility
|
||||
// to enforce proper synchronization.
|
||||
typename MapTy::iterator map_end() { return Map.end(); }
|
||||
|
||||
/// InsertOrGetItem - Return an iterator for the specified element.
|
||||
/// If the element exists in the map, the returned iterator points to the
|
||||
/// entry and Exists=true. If not, the iterator points to the newly
|
||||
/// inserted entry and returns Exists=false. Newly inserted entries have
|
||||
/// I->second == 0, and should be filled in.
|
||||
/// NOTE: This function is not locked. It is the caller's responsibility
|
||||
// to enforce proper synchronization.
|
||||
typename MapTy::iterator InsertOrGetItem(std::pair<MapKey, Constant *>
|
||||
&InsertVal,
|
||||
bool &Exists) {
|
||||
std::pair<typename MapTy::iterator, bool> IP = Map.insert(InsertVal);
|
||||
Exists = !IP.second;
|
||||
return IP.first;
|
||||
}
|
||||
|
||||
private:
|
||||
typename MapTy::iterator FindExistingElement(ConstantClass *CP) {
|
||||
if (HasLargeKey) {
|
||||
typename InverseMapTy::iterator IMI = InverseMap.find(CP);
|
||||
assert(IMI != InverseMap.end() && IMI->second != Map.end() &&
|
||||
IMI->second->second == CP &&
|
||||
"InverseMap corrupt!");
|
||||
return IMI->second;
|
||||
}
|
||||
|
||||
typename MapTy::iterator I =
|
||||
Map.find(MapKey(static_cast<const TypeClass*>(CP->getRawType()),
|
||||
getValType(CP)));
|
||||
if (I == Map.end() || I->second != CP) {
|
||||
// FIXME: This should not use a linear scan. If this gets to be a
|
||||
// performance problem, someone should look at this.
|
||||
for (I = Map.begin(); I != Map.end() && I->second != CP; ++I)
|
||||
/* empty */;
|
||||
}
|
||||
return I;
|
||||
}
|
||||
|
||||
ConstantClass* Create(const TypeClass *Ty, const ValType &V,
|
||||
typename MapTy::iterator I) {
|
||||
ConstantClass* Result =
|
||||
ConstantCreator<ConstantClass,TypeClass,ValType>::create(Ty, V);
|
||||
|
||||
assert(Result->getType() == Ty && "Type specified is not correct!");
|
||||
I = Map.insert(I, std::make_pair(MapKey(Ty, V), Result));
|
||||
|
||||
if (HasLargeKey) // Remember the reverse mapping if needed.
|
||||
InverseMap.insert(std::make_pair(Result, I));
|
||||
|
||||
// If the type of the constant is abstract, make sure that an entry
|
||||
// exists for it in the AbstractTypeMap.
|
||||
if (Ty->isAbstract()) {
|
||||
typename AbstractTypeMapTy::iterator TI =
|
||||
AbstractTypeMap.find(Ty);
|
||||
|
||||
if (TI == AbstractTypeMap.end()) {
|
||||
// Add ourselves to the ATU list of the type.
|
||||
cast<DerivedType>(Ty)->addAbstractTypeUser(this);
|
||||
|
||||
AbstractTypeMap.insert(TI, std::make_pair(Ty, I));
|
||||
}
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
public:
|
||||
|
||||
/// getOrCreate - Return the specified constant from the map, creating it if
|
||||
/// necessary.
|
||||
ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) {
|
||||
sys::SmartScopedLock<true> Lock(ValueMapLock);
|
||||
MapKey Lookup(Ty, V);
|
||||
ConstantClass* Result = 0;
|
||||
|
||||
typename MapTy::iterator I = Map.find(Lookup);
|
||||
// Is it in the map?
|
||||
if (I != Map.end())
|
||||
Result = static_cast<ConstantClass *>(I->second);
|
||||
|
||||
if (!Result) {
|
||||
// If no preexisting value, create one now...
|
||||
Result = Create(Ty, V, I);
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
void remove(ConstantClass *CP) {
|
||||
sys::SmartScopedLock<true> Lock(ValueMapLock);
|
||||
typename MapTy::iterator I = FindExistingElement(CP);
|
||||
assert(I != Map.end() && "Constant not found in constant table!");
|
||||
assert(I->second == CP && "Didn't find correct element?");
|
||||
|
||||
if (HasLargeKey) // Remember the reverse mapping if needed.
|
||||
InverseMap.erase(CP);
|
||||
|
||||
// Now that we found the entry, make sure this isn't the entry that
|
||||
// the AbstractTypeMap points to.
|
||||
const TypeClass *Ty = static_cast<const TypeClass *>(I->first.first);
|
||||
if (Ty->isAbstract()) {
|
||||
assert(AbstractTypeMap.count(Ty) &&
|
||||
"Abstract type not in AbstractTypeMap?");
|
||||
typename MapTy::iterator &ATMEntryIt = AbstractTypeMap[Ty];
|
||||
if (ATMEntryIt == I) {
|
||||
// Yes, we are removing the representative entry for this type.
|
||||
// See if there are any other entries of the same type.
|
||||
typename MapTy::iterator TmpIt = ATMEntryIt;
|
||||
|
||||
// First check the entry before this one...
|
||||
if (TmpIt != Map.begin()) {
|
||||
--TmpIt;
|
||||
if (TmpIt->first.first != Ty) // Not the same type, move back...
|
||||
++TmpIt;
|
||||
}
|
||||
|
||||
// If we didn't find the same type, try to move forward...
|
||||
if (TmpIt == ATMEntryIt) {
|
||||
++TmpIt;
|
||||
if (TmpIt == Map.end() || TmpIt->first.first != Ty)
|
||||
--TmpIt; // No entry afterwards with the same type
|
||||
}
|
||||
|
||||
// If there is another entry in the map of the same abstract type,
|
||||
// update the AbstractTypeMap entry now.
|
||||
if (TmpIt != ATMEntryIt) {
|
||||
ATMEntryIt = TmpIt;
|
||||
} else {
|
||||
// Otherwise, we are removing the last instance of this type
|
||||
// from the table. Remove from the ATM, and from user list.
|
||||
cast<DerivedType>(Ty)->removeAbstractTypeUser(this);
|
||||
AbstractTypeMap.erase(Ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map.erase(I);
|
||||
}
|
||||
|
||||
|
||||
/// MoveConstantToNewSlot - If we are about to change C to be the element
|
||||
/// specified by I, update our internal data structures to reflect this
|
||||
/// fact.
|
||||
/// NOTE: This function is not locked. It is the responsibility of the
|
||||
/// caller to enforce proper synchronization if using this method.
|
||||
void MoveConstantToNewSlot(ConstantClass *C, typename MapTy::iterator I) {
|
||||
// First, remove the old location of the specified constant in the map.
|
||||
typename MapTy::iterator OldI = FindExistingElement(C);
|
||||
assert(OldI != Map.end() && "Constant not found in constant table!");
|
||||
assert(OldI->second == C && "Didn't find correct element?");
|
||||
|
||||
// If this constant is the representative element for its abstract type,
|
||||
// update the AbstractTypeMap so that the representative element is I.
|
||||
if (C->getType()->isAbstract()) {
|
||||
typename AbstractTypeMapTy::iterator ATI =
|
||||
AbstractTypeMap.find(C->getType());
|
||||
assert(ATI != AbstractTypeMap.end() &&
|
||||
"Abstract type not in AbstractTypeMap?");
|
||||
if (ATI->second == OldI)
|
||||
ATI->second = I;
|
||||
}
|
||||
|
||||
// Remove the old entry from the map.
|
||||
Map.erase(OldI);
|
||||
|
||||
// Update the inverse map so that we know that this constant is now
|
||||
// located at descriptor I.
|
||||
if (HasLargeKey) {
|
||||
assert(I->second == C && "Bad inversemap entry!");
|
||||
InverseMap[C] = I;
|
||||
}
|
||||
}
|
||||
|
||||
void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
|
||||
sys::SmartScopedLock<true> Lock(ValueMapLock);
|
||||
typename AbstractTypeMapTy::iterator I =
|
||||
AbstractTypeMap.find(cast<Type>(OldTy));
|
||||
|
||||
assert(I != AbstractTypeMap.end() &&
|
||||
"Abstract type not in AbstractTypeMap?");
|
||||
|
||||
// Convert a constant at a time until the last one is gone. The last one
|
||||
// leaving will remove() itself, causing the AbstractTypeMapEntry to be
|
||||
// eliminated eventually.
|
||||
do {
|
||||
ConvertConstantType<ConstantClass,
|
||||
TypeClass>::convert(
|
||||
static_cast<ConstantClass *>(I->second->second),
|
||||
cast<TypeClass>(NewTy));
|
||||
|
||||
I = AbstractTypeMap.find(cast<Type>(OldTy));
|
||||
} while (I != AbstractTypeMap.end());
|
||||
}
|
||||
|
||||
// If the type became concrete without being refined to any other existing
|
||||
// type, we just remove ourselves from the ATU list.
|
||||
void typeBecameConcrete(const DerivedType *AbsTy) {
|
||||
AbsTy->removeAbstractTypeUser(this);
|
||||
}
|
||||
|
||||
void dump() const {
|
||||
DOUT << "Constant.cpp: ValueMap\n";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ConstantInt;
|
||||
class ConstantFP;
|
||||
class MDString;
|
||||
@ -112,19 +435,19 @@ class LLVMContextImpl {
|
||||
|
||||
FoldingSet<MDNode> MDNodeSet;
|
||||
|
||||
ValueMap<char, Type, ConstantAggregateZero> *AggZeroConstants;
|
||||
ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
|
||||
|
||||
typedef ValueMap<std::vector<Constant*>, ArrayType,
|
||||
ConstantArray, true /*largekey*/> ArrayConstantsTy;
|
||||
ArrayConstantsTy *ArrayConstants;
|
||||
ArrayConstantsTy ArrayConstants;
|
||||
|
||||
typedef ValueMap<std::vector<Constant*>, StructType,
|
||||
ConstantStruct, true /*largekey*/> StructConstantsTy;
|
||||
StructConstantsTy *StructConstants;
|
||||
StructConstantsTy StructConstants;
|
||||
|
||||
typedef ValueMap<std::vector<Constant*>, VectorType,
|
||||
ConstantVector> VectorConstantsTy;
|
||||
VectorConstantsTy *VectorConstants;
|
||||
VectorConstantsTy VectorConstants;
|
||||
|
||||
LLVMContext &Context;
|
||||
ConstantInt *TheTrueVal;
|
||||
@ -132,13 +455,10 @@ class LLVMContextImpl {
|
||||
|
||||
LLVMContextImpl();
|
||||
LLVMContextImpl(const LLVMContextImpl&);
|
||||
|
||||
friend class ConstantInt;
|
||||
public:
|
||||
LLVMContextImpl(LLVMContext &C);
|
||||
~LLVMContextImpl();
|
||||
|
||||
/// Return a ConstantInt with the specified value and an implied Type. The
|
||||
/// type is the integer type that corresponds to the bit width of the value.
|
||||
ConstantInt *getConstantInt(const APInt &V);
|
||||
|
||||
ConstantFP *getConstantFP(const APFloat &V);
|
||||
|
||||
@ -161,14 +481,14 @@ public:
|
||||
if (TheTrueVal)
|
||||
return TheTrueVal;
|
||||
else
|
||||
return (TheTrueVal = Context.getConstantInt(IntegerType::get(1), 1));
|
||||
return (TheTrueVal = ConstantInt::get(IntegerType::get(1), 1));
|
||||
}
|
||||
|
||||
ConstantInt *getFalse() {
|
||||
if (TheFalseVal)
|
||||
return TheFalseVal;
|
||||
else
|
||||
return (TheFalseVal = Context.getConstantInt(IntegerType::get(1), 0));
|
||||
return (TheFalseVal = ConstantInt::get(IntegerType::get(1), 0));
|
||||
}
|
||||
|
||||
void erase(MDString *M);
|
||||
|
@ -185,7 +185,7 @@ static Constant *GetTorInit(std::vector<std::pair<Function*, int> > &TorList) {
|
||||
std::vector<Constant*> ArrayElts;
|
||||
for (unsigned i = 0, e = TorList.size(); i != e; ++i) {
|
||||
std::vector<Constant*> Elts;
|
||||
Elts.push_back(Context.getConstantInt(Type::Int32Ty, TorList[i].second));
|
||||
Elts.push_back(ConstantInt::get(Type::Int32Ty, TorList[i].second));
|
||||
Elts.push_back(TorList[i].first);
|
||||
ArrayElts.push_back(Context.getConstantStruct(Elts));
|
||||
}
|
||||
|
@ -39,8 +39,7 @@ Function *makeReturnGlobal(std::string Name, GlobalVariable *G, Module *M) {
|
||||
IRBuilder<> builder(Entry);
|
||||
Value *Load = builder.CreateLoad(G);
|
||||
const Type *GTy = G->getType()->getElementType();
|
||||
Value *Add = builder.CreateAdd(Load,
|
||||
getGlobalContext().getConstantInt(GTy, 1LL));
|
||||
Value *Add = builder.CreateAdd(Load, ConstantInt::get(GTy, 1LL));
|
||||
builder.CreateStore(Add, G);
|
||||
builder.CreateRet(Add);
|
||||
return F;
|
||||
|
@ -26,7 +26,7 @@ protected:
|
||||
std::auto_ptr<BitCastInst> BitcastV;
|
||||
|
||||
ValueHandle() :
|
||||
ConstantV(getGlobalContext().getConstantInt(Type::Int32Ty, 0)),
|
||||
ConstantV(ConstantInt::get(Type::Int32Ty, 0)),
|
||||
BitcastV(new BitCastInst(ConstantV, Type::Int32Ty)) {
|
||||
}
|
||||
};
|
||||
|
@ -17,11 +17,10 @@ namespace {
|
||||
|
||||
TEST(ConstantsTest, Integer_i1) {
|
||||
const IntegerType* Int1 = IntegerType::get(1);
|
||||
Constant* One = getGlobalContext().getConstantInt(Int1, 1, true);
|
||||
Constant* Zero = getGlobalContext().getConstantInt(Int1, 0);
|
||||
Constant* NegOne =
|
||||
getGlobalContext().getConstantInt(Int1, static_cast<uint64_t>(-1), true);
|
||||
EXPECT_EQ(NegOne, getGlobalContext().getConstantIntSigned(Int1, -1));
|
||||
Constant* One = ConstantInt::get(Int1, 1, true);
|
||||
Constant* Zero = ConstantInt::get(Int1, 0);
|
||||
Constant* NegOne = ConstantInt::get(Int1, static_cast<uint64_t>(-1), true);
|
||||
EXPECT_EQ(NegOne, ConstantInt::getSigned(Int1, -1));
|
||||
Constant* Undef = getGlobalContext().getUndef(Int1);
|
||||
|
||||
// Input: @b = constant i1 add(i1 1 , i1 1)
|
||||
@ -99,16 +98,15 @@ TEST(ConstantsTest, Integer_i1) {
|
||||
|
||||
TEST(ConstantsTest, IntSigns) {
|
||||
const IntegerType* Int8Ty = Type::Int8Ty;
|
||||
LLVMContext &Context = getGlobalContext();
|
||||
EXPECT_EQ(100, Context.getConstantInt(Int8Ty, 100, false)->getSExtValue());
|
||||
EXPECT_EQ(100, Context.getConstantInt(Int8Ty, 100, true)->getSExtValue());
|
||||
EXPECT_EQ(100, Context.getConstantIntSigned(Int8Ty, 100)->getSExtValue());
|
||||
EXPECT_EQ(-50, Context.getConstantInt(Int8Ty, 206)->getSExtValue());
|
||||
EXPECT_EQ(-50, Context.getConstantIntSigned(Int8Ty, -50)->getSExtValue());
|
||||
EXPECT_EQ(206U, Context.getConstantIntSigned(Int8Ty, -50)->getZExtValue());
|
||||
EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, false)->getSExtValue());
|
||||
EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, true)->getSExtValue());
|
||||
EXPECT_EQ(100, ConstantInt::getSigned(Int8Ty, 100)->getSExtValue());
|
||||
EXPECT_EQ(-50, ConstantInt::get(Int8Ty, 206)->getSExtValue());
|
||||
EXPECT_EQ(-50, ConstantInt::getSigned(Int8Ty, -50)->getSExtValue());
|
||||
EXPECT_EQ(206U, ConstantInt::getSigned(Int8Ty, -50)->getZExtValue());
|
||||
|
||||
// Overflow is handled by truncation.
|
||||
EXPECT_EQ(0x3b, Context.getConstantInt(Int8Ty, 0x13b)->getSExtValue());
|
||||
EXPECT_EQ(0x3b, ConstantInt::get(Int8Ty, 0x13b)->getSExtValue());
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
|
@ -69,7 +69,7 @@ TEST(MDNodeTest, Simple) {
|
||||
|
||||
MDString *s1 = getGlobalContext().getMDString(&x[0], 3);
|
||||
MDString *s2 = getGlobalContext().getMDString(&y[0], 3);
|
||||
ConstantInt *CI = getGlobalContext().getConstantInt(APInt(8, 0));
|
||||
ConstantInt *CI = ConstantInt::get(getGlobalContext(), APInt(8, 0));
|
||||
|
||||
std::vector<Value *> V;
|
||||
V.push_back(s1);
|
||||
@ -102,7 +102,7 @@ TEST(MDNodeTest, Simple) {
|
||||
}
|
||||
|
||||
TEST(MDNodeTest, Delete) {
|
||||
Constant *C = getGlobalContext().getConstantInt(Type::Int32Ty, 1);
|
||||
Constant *C = ConstantInt::get(Type::Int32Ty, 1);
|
||||
Instruction *I = new BitCastInst(C, Type::Int32Ty);
|
||||
|
||||
Value *const V = I;
|
||||
|
@ -1 +1 @@
|
||||
// This file has to be here because it's #included from the auto generated FileLexer.cpp
|
||||
// This file has to be here because it's #included from the auto generated FileLexer.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user