diff options
author | Owen Anderson <resistor@mac.com> | 2009-07-14 23:09:55 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-07-14 23:09:55 +0000 |
commit | 9adc0abad3c3ed40a268ccbcee0c74cb9e1359fe (patch) | |
tree | f15d2aa3fea09947494a5d0bb36583dbe3be000a /lib/CodeGen/IntrinsicLowering.cpp | |
parent | a89b7ea9d6819606eea3ba945913127a212b836f (diff) |
Move EVER MORE stuff over to LLVMContext.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75703 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/IntrinsicLowering.cpp')
-rw-r--r-- | lib/CodeGen/IntrinsicLowering.cpp | 83 |
1 files changed, 44 insertions, 39 deletions
diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp index 6ec3a629fb..455adc44a1 100644 --- a/lib/CodeGen/IntrinsicLowering.cpp +++ b/lib/CodeGen/IntrinsicLowering.cpp @@ -149,7 +149,7 @@ void IntrinsicLowering::AddPrototypes(Module &M) { /// LowerBSWAP - Emit the code to lower bswap of V before the specified /// instruction IP. -static Value *LowerBSWAP(Value *V, Instruction *IP) { +static Value *LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP) { assert(V->getType()->isInteger() && "Can't bswap a non-integer type!"); unsigned BitSize = V->getType()->getPrimitiveSizeInBits(); @@ -159,25 +159,27 @@ static Value *LowerBSWAP(Value *V, Instruction *IP) { switch(BitSize) { default: llvm_unreachable("Unhandled type size of value to byteswap!"); case 16: { - Value *Tmp1 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8), + Value *Tmp1 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 8), "bswap.2"); - Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8), + Value *Tmp2 = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 8), "bswap.1"); V = Builder.CreateOr(Tmp1, Tmp2, "bswap.i16"); break; } case 32: { - Value *Tmp4 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24), + Value *Tmp4 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 24), "bswap.4"); - Value *Tmp3 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8), + Value *Tmp3 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 8), "bswap.3"); - Value *Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8), + Value *Tmp2 = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 8), "bswap.2"); - Value *Tmp1 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 24), + Value *Tmp1 = Builder.CreateLShr(V,Context.getConstantInt(V->getType(), 24), "bswap.1"); - Tmp3 = Builder.CreateAnd(Tmp3, ConstantInt::get(Type::Int32Ty, 0xFF0000), + Tmp3 = Builder.CreateAnd(Tmp3, + Context.getConstantInt(Type::Int32Ty, 0xFF0000), "bswap.and3"); - Tmp2 = Builder.CreateAnd(Tmp2, ConstantInt::get(Type::Int32Ty, 0xFF00), + Tmp2 = Builder.CreateAnd(Tmp2, + Context.getConstantInt(Type::Int32Ty, 0xFF00), "bswap.and2"); Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or1"); Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or2"); @@ -185,41 +187,44 @@ static Value *LowerBSWAP(Value *V, Instruction *IP) { break; } case 64: { - Value *Tmp8 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 56), + Value *Tmp8 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 56), "bswap.8"); - Value *Tmp7 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 40), + Value *Tmp7 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 40), "bswap.7"); - Value *Tmp6 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 24), + Value *Tmp6 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 24), "bswap.6"); - Value *Tmp5 = Builder.CreateShl(V, ConstantInt::get(V->getType(), 8), + Value *Tmp5 = Builder.CreateShl(V, Context.getConstantInt(V->getType(), 8), "bswap.5"); - Value* Tmp4 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 8), + Value* Tmp4 = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 8), "bswap.4"); - Value* Tmp3 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 24), + Value* Tmp3 = Builder.CreateLShr(V, + Context.getConstantInt(V->getType(), 24), "bswap.3"); - Value* Tmp2 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 40), + Value* Tmp2 = Builder.CreateLShr(V, + Context.getConstantInt(V->getType(), 40), "bswap.2"); - Value* Tmp1 = Builder.CreateLShr(V, ConstantInt::get(V->getType(), 56), + Value* Tmp1 = Builder.CreateLShr(V, + Context.getConstantInt(V->getType(), 56), "bswap.1"); Tmp7 = Builder.CreateAnd(Tmp7, - ConstantInt::get(Type::Int64Ty, + Context.getConstantInt(Type::Int64Ty, 0xFF000000000000ULL), "bswap.and7"); Tmp6 = Builder.CreateAnd(Tmp6, - ConstantInt::get(Type::Int64Ty, + Context.getConstantInt(Type::Int64Ty, 0xFF0000000000ULL), "bswap.and6"); Tmp5 = Builder.CreateAnd(Tmp5, - ConstantInt::get(Type::Int64Ty, 0xFF00000000ULL), + Context.getConstantInt(Type::Int64Ty, 0xFF00000000ULL), "bswap.and5"); Tmp4 = Builder.CreateAnd(Tmp4, - ConstantInt::get(Type::Int64Ty, 0xFF000000ULL), + Context.getConstantInt(Type::Int64Ty, 0xFF000000ULL), "bswap.and4"); Tmp3 = Builder.CreateAnd(Tmp3, - ConstantInt::get(Type::Int64Ty, 0xFF0000ULL), + Context.getConstantInt(Type::Int64Ty, 0xFF0000ULL), "bswap.and3"); Tmp2 = Builder.CreateAnd(Tmp2, - ConstantInt::get(Type::Int64Ty, 0xFF00ULL), + Context.getConstantInt(Type::Int64Ty, 0xFF00ULL), "bswap.and2"); Tmp8 = Builder.CreateOr(Tmp8, Tmp7, "bswap.or1"); Tmp6 = Builder.CreateOr(Tmp6, Tmp5, "bswap.or2"); @@ -236,7 +241,7 @@ static Value *LowerBSWAP(Value *V, Instruction *IP) { /// LowerCTPOP - Emit the code to lower ctpop of V before the specified /// instruction IP. -static Value *LowerCTPOP(Value *V, Instruction *IP) { +static Value *LowerCTPOP(LLVMContext &Context, Value *V, Instruction *IP) { assert(V->getType()->isInteger() && "Can't ctpop a non-integer type!"); static const uint64_t MaskValues[6] = { @@ -249,23 +254,23 @@ static Value *LowerCTPOP(Value *V, Instruction *IP) { unsigned BitSize = V->getType()->getPrimitiveSizeInBits(); unsigned WordSize = (BitSize + 63) / 64; - Value *Count = ConstantInt::get(V->getType(), 0); + Value *Count = Context.getConstantInt(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 = ConstantInt::get(V->getType(), MaskValues[ct]); + Value *MaskCst = Context.getConstantInt(V->getType(), MaskValues[ct]); Value *LHS = Builder.CreateAnd(PartValue, MaskCst, "cppop.and1"); Value *VShift = Builder.CreateLShr(PartValue, - ConstantInt::get(V->getType(), i), + Context.getConstantInt(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, ConstantInt::get(V->getType(), 64), + V = Builder.CreateLShr(V, Context.getConstantInt(V->getType(), 64), "ctpop.part.sh"); BitSize -= 64; } @@ -276,19 +281,19 @@ static Value *LowerCTPOP(Value *V, Instruction *IP) { /// LowerCTLZ - Emit the code to lower ctlz of V before the specified /// instruction IP. -static Value *LowerCTLZ(Value *V, Instruction *IP) { +static Value *LowerCTLZ(LLVMContext &Context, Value *V, Instruction *IP) { IRBuilder<> Builder(IP->getParent(), IP); unsigned BitSize = V->getType()->getPrimitiveSizeInBits(); for (unsigned i = 1; i < BitSize; i <<= 1) { - Value *ShVal = ConstantInt::get(V->getType(), i); + Value *ShVal = Context.getConstantInt(V->getType(), i); ShVal = Builder.CreateLShr(V, ShVal, "ctlz.sh"); V = Builder.CreateOr(V, ShVal, "ctlz.step"); } V = Builder.CreateNot(V); - return LowerCTPOP(V, IP); + return LowerCTPOP(Context, V, IP); } static void ReplaceFPIntrinsicWithCall(CallInst *CI, const char *Fname, @@ -357,15 +362,15 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { break; } case Intrinsic::ctpop: - CI->replaceAllUsesWith(LowerCTPOP(CI->getOperand(1), CI)); + CI->replaceAllUsesWith(LowerCTPOP(*Context, CI->getOperand(1), CI)); break; case Intrinsic::bswap: - CI->replaceAllUsesWith(LowerBSWAP(CI->getOperand(1), CI)); + CI->replaceAllUsesWith(LowerBSWAP(*Context, CI->getOperand(1), CI)); break; case Intrinsic::ctlz: - CI->replaceAllUsesWith(LowerCTLZ(CI->getOperand(1), CI)); + CI->replaceAllUsesWith(LowerCTLZ(*Context, CI->getOperand(1), CI)); break; case Intrinsic::cttz: { @@ -373,9 +378,9 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) { Value *Src = CI->getOperand(1); Value *NotSrc = Builder.CreateNot(Src); NotSrc->setName(Src->getName() + ".not"); - Value *SrcM1 = ConstantInt::get(Src->getType(), 1); + Value *SrcM1 = Context->getConstantInt(Src->getType(), 1); SrcM1 = Builder.CreateSub(Src, SrcM1); - Src = LowerCTPOP(Builder.CreateAnd(NotSrc, SrcM1), CI); + Src = LowerCTPOP(*Context, Builder.CreateAnd(NotSrc, SrcM1), CI); CI->replaceAllUsesWith(Src); break; } @@ -409,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(ConstantInt::get(Type::Int64Ty, 0)); + CI->replaceAllUsesWith(Context->getConstantInt(Type::Int64Ty, 0)); break; } @@ -429,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(ConstantInt::get(CI->getType(), 1)); + CI->replaceAllUsesWith(Context->getConstantInt(CI->getType(), 1)); break; case Intrinsic::var_annotation: @@ -501,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(ConstantInt::get(CI->getType(), 1)); + CI->replaceAllUsesWith(Context->getConstantInt(CI->getType(), 1)); break; } |