diff options
author | Owen Anderson <resistor@mac.com> | 2009-08-13 21:58:54 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-08-13 21:58:54 +0000 |
commit | 1d0be15f89cb5056e20e2d24faa8d6afb1573bca (patch) | |
tree | 2cdabe223bfce83bd12e10dd557147a2f68c9bf8 /lib/ExecutionEngine | |
parent | d163e8b14c8aa5bbbb129e3f0dffdbe7213a3c72 (diff) |
Push LLVMContexts through the IntegerType APIs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78948 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r-- | lib/ExecutionEngine/ExecutionEngine.cpp | 45 | ||||
-rw-r--r-- | lib/ExecutionEngine/Interpreter/Execution.cpp | 25 | ||||
-rw-r--r-- | lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp | 21 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/JIT.cpp | 24 |
4 files changed, 65 insertions, 50 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 348190a75b..a20122d9f9 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -238,13 +238,13 @@ const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) { // CreateArgv - Turn a vector of strings into a nice argv style array of // pointers to null terminated strings. // -static void *CreateArgv(ExecutionEngine *EE, +static void *CreateArgv(LLVMContext &C, ExecutionEngine *EE, const std::vector<std::string> &InputArgv) { unsigned PtrSize = EE->getTargetData()->getPointerSize(); char *Result = new char[(InputArgv.size()+1)*PtrSize]; DOUT << "JIT: ARGV = " << (void*)Result << "\n"; - const Type *SBytePtr = PointerType::getUnqual(Type::Int8Ty); + const Type *SBytePtr = PointerType::getUnqual(Type::getInt8Ty(C)); for (unsigned i = 0; i != InputArgv.size(); ++i) { unsigned Size = InputArgv[i].size()+1; @@ -340,7 +340,8 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn, unsigned NumArgs = Fn->getFunctionType()->getNumParams(); const FunctionType *FTy = Fn->getFunctionType(); const Type* PPInt8Ty = - PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty)); + PointerType::getUnqual(PointerType::getUnqual( + Type::getInt8Ty(Fn->getContext()))); switch (NumArgs) { case 3: if (FTy->getParamType(2) != PPInt8Ty) { @@ -353,13 +354,13 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn, } // FALLS THROUGH case 1: - if (FTy->getParamType(0) != Type::Int32Ty) { + if (FTy->getParamType(0) != Type::getInt32Ty(Fn->getContext())) { llvm_report_error("Invalid type for first argument of main() supplied"); } // FALLS THROUGH case 0: if (!isa<IntegerType>(FTy->getReturnType()) && - FTy->getReturnType() != Type::VoidTy) { + FTy->getReturnType() != Type::getVoidTy(FTy->getContext())) { llvm_report_error("Invalid return type of main() supplied"); } break; @@ -370,14 +371,16 @@ int ExecutionEngine::runFunctionAsMain(Function *Fn, if (NumArgs) { GVArgs.push_back(GVArgc); // Arg #0 = argc. if (NumArgs > 1) { - GVArgs.push_back(PTOGV(CreateArgv(this, argv))); // Arg #1 = argv. + // Arg #1 = argv. + GVArgs.push_back(PTOGV(CreateArgv(Fn->getContext(), this, argv))); assert(!isTargetNullPtr(this, GVTOP(GVArgs[1])) && "argv[0] was null after CreateArgv"); if (NumArgs > 2) { std::vector<std::string> EnvVars; for (unsigned i = 0; envp[i]; ++i) EnvVars.push_back(envp[i]); - GVArgs.push_back(PTOGV(CreateArgv(this, EnvVars))); // Arg #2 = envp. + // Arg #2 = envp. + GVArgs.push_back(PTOGV(CreateArgv(Fn->getContext(), this, EnvVars))); } } } @@ -525,11 +528,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { } case Instruction::UIToFP: { GenericValue GV = getConstantValue(Op0); - if (CE->getType() == Type::FloatTy) + if (CE->getType() == Type::getFloatTy(CE->getContext())) GV.FloatVal = float(GV.IntVal.roundToDouble()); - else if (CE->getType() == Type::DoubleTy) + else if (CE->getType() == Type::getDoubleTy(CE->getContext())) GV.DoubleVal = GV.IntVal.roundToDouble(); - else if (CE->getType() == Type::X86_FP80Ty) { + else if (CE->getType() == Type::getX86_FP80Ty(Op0->getContext())) { const uint64_t zero[] = {0, 0}; APFloat apf = APFloat(APInt(80, 2, zero)); (void)apf.convertFromAPInt(GV.IntVal, @@ -541,11 +544,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { } case Instruction::SIToFP: { GenericValue GV = getConstantValue(Op0); - if (CE->getType() == Type::FloatTy) + if (CE->getType() == Type::getFloatTy(CE->getContext())) GV.FloatVal = float(GV.IntVal.signedRoundToDouble()); - else if (CE->getType() == Type::DoubleTy) + else if (CE->getType() == Type::getDoubleTy(CE->getContext())) GV.DoubleVal = GV.IntVal.signedRoundToDouble(); - else if (CE->getType() == Type::X86_FP80Ty) { + else if (CE->getType() == Type::getX86_FP80Ty(CE->getContext())) { const uint64_t zero[] = { 0, 0}; APFloat apf = APFloat(APInt(80, 2, zero)); (void)apf.convertFromAPInt(GV.IntVal, @@ -559,11 +562,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { case Instruction::FPToSI: { GenericValue GV = getConstantValue(Op0); uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth(); - if (Op0->getType() == Type::FloatTy) + if (Op0->getType() == Type::getFloatTy(Op0->getContext())) GV.IntVal = APIntOps::RoundFloatToAPInt(GV.FloatVal, BitWidth); - else if (Op0->getType() == Type::DoubleTy) + else if (Op0->getType() == Type::getDoubleTy(Op0->getContext())) GV.IntVal = APIntOps::RoundDoubleToAPInt(GV.DoubleVal, BitWidth); - else if (Op0->getType() == Type::X86_FP80Ty) { + else if (Op0->getType() == Type::getX86_FP80Ty(Op0->getContext())) { APFloat apf = APFloat(GV.IntVal); uint64_t v; bool ignored; @@ -596,17 +599,19 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { default: llvm_unreachable("Invalid bitcast operand"); case Type::IntegerTyID: assert(DestTy->isFloatingPoint() && "invalid bitcast"); - if (DestTy == Type::FloatTy) + if (DestTy == Type::getFloatTy(Op0->getContext())) GV.FloatVal = GV.IntVal.bitsToFloat(); - else if (DestTy == Type::DoubleTy) + else if (DestTy == Type::getDoubleTy(DestTy->getContext())) GV.DoubleVal = GV.IntVal.bitsToDouble(); break; case Type::FloatTyID: - assert(DestTy == Type::Int32Ty && "Invalid bitcast"); + assert(DestTy == Type::getInt32Ty(DestTy->getContext()) && + "Invalid bitcast"); GV.IntVal.floatToBits(GV.FloatVal); break; case Type::DoubleTyID: - assert(DestTy == Type::Int64Ty && "Invalid bitcast"); + assert(DestTy == Type::getInt64Ty(DestTy->getContext()) && + "Invalid bitcast"); GV.IntVal.doubleToBits(GV.DoubleVal); break; case Type::PointerTyID: diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index 8d21d1f40b..45180c91f0 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -366,7 +366,7 @@ static GenericValue executeFCMP_OGT(GenericValue Src1, GenericValue Src2, } #define IMPLEMENT_UNORDERED(TY, X,Y) \ - if (TY == Type::FloatTy) { \ + if (TY == Type::getFloatTy(Ty->getContext())) { \ if (X.FloatVal != X.FloatVal || Y.FloatVal != Y.FloatVal) { \ Dest.IntVal = APInt(1,true); \ return Dest; \ @@ -422,7 +422,7 @@ static GenericValue executeFCMP_UGT(GenericValue Src1, GenericValue Src2, static GenericValue executeFCMP_ORD(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; - if (Ty == Type::FloatTy) + if (Ty == Type::getFloatTy(Ty->getContext())) Dest.IntVal = APInt(1,(Src1.FloatVal == Src1.FloatVal && Src2.FloatVal == Src2.FloatVal)); else @@ -434,7 +434,7 @@ static GenericValue executeFCMP_ORD(GenericValue Src1, GenericValue Src2, static GenericValue executeFCMP_UNO(GenericValue Src1, GenericValue Src2, const Type *Ty) { GenericValue Dest; - if (Ty == Type::FloatTy) + if (Ty == Type::getFloatTy(Ty->getContext())) Dest.IntVal = APInt(1,(Src1.FloatVal != Src1.FloatVal || Src2.FloatVal != Src2.FloatVal)); else @@ -602,7 +602,8 @@ void Interpreter::popStackAndReturnValueToCaller (const Type *RetTy, // fill in the return value... ExecutionContext &CallingSF = ECStack.back(); if (Instruction *I = CallingSF.Caller.getInstruction()) { - if (CallingSF.Caller.getType() != Type::VoidTy) // Save result... + // Save result... + if (CallingSF.Caller.getType() != Type::getVoidTy(RetTy->getContext())) SetValue(I, Result, CallingSF); if (InvokeInst *II = dyn_cast<InvokeInst> (I)) SwitchToNewBasicBlock (II->getNormalDest (), CallingSF); @@ -613,7 +614,7 @@ void Interpreter::popStackAndReturnValueToCaller (const Type *RetTy, void Interpreter::visitReturnInst(ReturnInst &I) { ExecutionContext &SF = ECStack.back(); - const Type *RetTy = Type::VoidTy; + const Type *RetTy = Type::getVoidTy(I.getContext()); GenericValue Result; // Save away the return value... (if we are not 'ret void') @@ -970,7 +971,8 @@ GenericValue Interpreter::executeZExtInst(Value *SrcVal, const Type *DstTy, GenericValue Interpreter::executeFPTruncInst(Value *SrcVal, const Type *DstTy, ExecutionContext &SF) { GenericValue Dest, Src = getOperandValue(SrcVal, SF); - assert(SrcVal->getType() == Type::DoubleTy && DstTy == Type::FloatTy && + assert(SrcVal->getType() == Type::getDoubleTy(SrcVal->getContext()) && + DstTy == Type::getFloatTy(SrcVal->getContext()) && "Invalid FPTrunc instruction"); Dest.FloatVal = (float) Src.DoubleVal; return Dest; @@ -979,7 +981,8 @@ GenericValue Interpreter::executeFPTruncInst(Value *SrcVal, const Type *DstTy, GenericValue Interpreter::executeFPExtInst(Value *SrcVal, const Type *DstTy, ExecutionContext &SF) { GenericValue Dest, Src = getOperandValue(SrcVal, SF); - assert(SrcVal->getType() == Type::FloatTy && DstTy == Type::DoubleTy && + assert(SrcVal->getType() == Type::getFloatTy(SrcVal->getContext()) && + DstTy == Type::getDoubleTy(SrcVal->getContext()) && "Invalid FPTrunc instruction"); Dest.DoubleVal = (double) Src.FloatVal; return Dest; @@ -1070,22 +1073,22 @@ GenericValue Interpreter::executeBitCastInst(Value *SrcVal, const Type *DstTy, assert(isa<PointerType>(SrcTy) && "Invalid BitCast"); Dest.PointerVal = Src.PointerVal; } else if (DstTy->isInteger()) { - if (SrcTy == Type::FloatTy) { + if (SrcTy == Type::getFloatTy(SrcVal->getContext())) { Dest.IntVal.zext(sizeof(Src.FloatVal) * CHAR_BIT); Dest.IntVal.floatToBits(Src.FloatVal); - } else if (SrcTy == Type::DoubleTy) { + } else if (SrcTy == Type::getDoubleTy(SrcVal->getContext())) { Dest.IntVal.zext(sizeof(Src.DoubleVal) * CHAR_BIT); Dest.IntVal.doubleToBits(Src.DoubleVal); } else if (SrcTy->isInteger()) { Dest.IntVal = Src.IntVal; } else llvm_unreachable("Invalid BitCast"); - } else if (DstTy == Type::FloatTy) { + } else if (DstTy == Type::getFloatTy(SrcVal->getContext())) { if (SrcTy->isInteger()) Dest.FloatVal = Src.IntVal.bitsToFloat(); else Dest.FloatVal = Src.FloatVal; - } else if (DstTy == Type::DoubleTy) { + } else if (DstTy == Type::getDoubleTy(SrcVal->getContext())) { if (SrcTy->isInteger()) Dest.DoubleVal = Src.IntVal.bitsToDouble(); else diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp index 37f6ef07f6..92fd817cde 100644 --- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -418,7 +418,8 @@ GenericValue lle_X_printf(const FunctionType *FT, return GV; } -static void ByteswapSCANFResults(const char *Fmt, void *Arg0, void *Arg1, +static void ByteswapSCANFResults(LLVMContext &C, + const char *Fmt, void *Arg0, void *Arg1, void *Arg2, void *Arg3, void *Arg4, void *Arg5, void *Arg6, void *Arg7, void *Arg8) { void *Args[] = { Arg0, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, 0 }; @@ -458,26 +459,26 @@ static void ByteswapSCANFResults(const char *Fmt, void *Arg0, void *Arg1, case 'i': case 'o': case 'u': case 'x': case 'X': case 'n': case 'p': case 'd': if (Long || LongLong) { - Size = 8; Ty = Type::Int64Ty; + Size = 8; Ty = Type::getInt64Ty(C); } else if (Half) { - Size = 4; Ty = Type::Int16Ty; + Size = 4; Ty = Type::getInt16Ty(C); } else { - Size = 4; Ty = Type::Int32Ty; + Size = 4; Ty = Type::getInt32Ty(C); } break; case 'e': case 'g': case 'E': case 'f': if (Long || LongLong) { - Size = 8; Ty = Type::DoubleTy; + Size = 8; Ty = Type::getDoubleTy(C); } else { - Size = 4; Ty = Type::FloatTy; + Size = 4; Ty = Type::getFloatTy(C); } break; case 's': case 'c': case '[': // No byteswap needed Size = 1; - Ty = Type::Int8Ty; + Ty = Type::getInt8Ty(C); break; default: break; @@ -506,7 +507,8 @@ GenericValue lle_X_sscanf(const FunctionType *FT, GenericValue GV; GV.IntVal = APInt(32, sscanf(Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6], Args[7], Args[8], Args[9])); - ByteswapSCANFResults(Args[1], Args[2], Args[3], Args[4], + ByteswapSCANFResults(FT->getContext(), + Args[1], Args[2], Args[3], Args[4], Args[5], Args[6], Args[7], Args[8], Args[9], 0); return GV; } @@ -523,7 +525,8 @@ GenericValue lle_X_scanf(const FunctionType *FT, GenericValue GV; GV.IntVal = APInt(32, scanf( Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6], Args[7], Args[8], Args[9])); - ByteswapSCANFResults(Args[0], Args[1], Args[2], Args[3], Args[4], + ByteswapSCANFResults(FT->getContext(), + Args[0], Args[1], Args[2], Args[3], Args[4], Args[5], Args[6], Args[7], Args[8], Args[9]); return GV; } diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index b932c8cef1..3743350433 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -382,10 +382,11 @@ GenericValue JIT::runFunction(Function *F, // Handle some common cases first. These cases correspond to common `main' // prototypes. - if (RetTy == Type::Int32Ty || RetTy == Type::VoidTy) { + if (RetTy == Type::getInt32Ty(F->getContext()) || + RetTy == Type::getVoidTy(F->getContext())) { switch (ArgValues.size()) { case 3: - if (FTy->getParamType(0) == Type::Int32Ty && + if (FTy->getParamType(0) == Type::getInt32Ty(F->getContext()) && isa<PointerType>(FTy->getParamType(1)) && isa<PointerType>(FTy->getParamType(2))) { int (*PF)(int, char **, const char **) = @@ -400,7 +401,7 @@ GenericValue JIT::runFunction(Function *F, } break; case 2: - if (FTy->getParamType(0) == Type::Int32Ty && + if (FTy->getParamType(0) == Type::getInt32Ty(F->getContext()) && isa<PointerType>(FTy->getParamType(1))) { int (*PF)(int, char **) = (int(*)(int, char **))(intptr_t)FPtr; @@ -413,7 +414,7 @@ GenericValue JIT::runFunction(Function *F, break; case 1: if (FTy->getNumParams() == 1 && - FTy->getParamType(0) == Type::Int32Ty) { + FTy->getParamType(0) == Type::getInt32Ty(F->getContext())) { GenericValue rv; int (*PF)(int) = (int(*)(int))(intptr_t)FPtr; rv.IntVal = APInt(32, PF(ArgValues[0].IntVal.getZExtValue())); @@ -474,7 +475,7 @@ GenericValue JIT::runFunction(Function *F, F->getParent()); // Insert a basic block. - BasicBlock *StubBB = BasicBlock::Create("", Stub); + BasicBlock *StubBB = BasicBlock::Create(F->getContext(), "", Stub); // Convert all of the GenericValue arguments over to constants. Note that we // currently don't support varargs. @@ -502,9 +503,11 @@ GenericValue JIT::runFunction(Function *F, case Type::PointerTyID: void *ArgPtr = GVTOP(AV); if (sizeof(void*) == 4) - C = ConstantInt::get(Type::Int32Ty, (int)(intptr_t)ArgPtr); + C = ConstantInt::get(Type::getInt32Ty(F->getContext()), + (int)(intptr_t)ArgPtr); else - C = ConstantInt::get(Type::Int64Ty, (intptr_t)ArgPtr); + C = ConstantInt::get(Type::getInt64Ty(F->getContext()), + (intptr_t)ArgPtr); // Cast the integer to pointer C = ConstantExpr::getIntToPtr(C, ArgTy); break; @@ -516,10 +519,11 @@ GenericValue JIT::runFunction(Function *F, "", StubBB); TheCall->setCallingConv(F->getCallingConv()); TheCall->setTailCall(); - if (TheCall->getType() != Type::VoidTy) - ReturnInst::Create(TheCall, StubBB); // Return result of the call. + if (TheCall->getType() != Type::getVoidTy(F->getContext())) + // Return result of the call. + ReturnInst::Create(F->getContext(), TheCall, StubBB); else - ReturnInst::Create(StubBB); // Just return void. + ReturnInst::Create(F->getContext(), StubBB); // Just return void. // Finally, return the value returned by our nullary stub function. return runFunction(Stub, std::vector<GenericValue>()); |