}
+void *ExecutionEngineState::RemoveMapping(
+ const MutexGuard &, const GlobalValue *ToUnmap) {
+ std::map<AssertingVH<const GlobalValue>, void *>::iterator I =
+ GlobalAddressMap.find(ToUnmap);
+ void *OldVal;
+ if (I == GlobalAddressMap.end())
+ OldVal = 0;
+ else {
+ OldVal = I->second;
+ GlobalAddressMap.erase(I);
+ }
+
+ GlobalAddressReverseMap.erase(OldVal);
+ return OldVal;
+}
+
/// addGlobalMapping - Tell the execution engine that the specified global is
/// at the specified location. This is used internally as functions are JIT'd
/// and as global variables are laid out in memory. It can and should also be
MutexGuard locked(lock);
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI) {
- state.getGlobalAddressMap(locked).erase(&*FI);
- state.getGlobalAddressReverseMap(locked).erase(&*FI);
+ state.RemoveMapping(locked, FI);
}
for (Module::global_iterator GI = M->global_begin(), GE = M->global_end();
GI != GE; ++GI) {
- state.getGlobalAddressMap(locked).erase(&*GI);
- state.getGlobalAddressReverseMap(locked).erase(&*GI);
+ state.RemoveMapping(locked, GI);
}
}
// Deleting from the mapping?
if (Addr == 0) {
- std::map<AssertingVH<const GlobalValue>, void *>::iterator I = Map.find(GV);
- void *OldVal;
- if (I == Map.end())
- OldVal = 0;
- else {
- OldVal = I->second;
- Map.erase(I);
- }
-
- if (!state.getGlobalAddressReverseMap(locked).empty())
- state.getGlobalAddressReverseMap(locked).erase(OldVal);
- return OldVal;
+ return state.RemoveMapping(locked, GV);
}
void *&CurVal = Map[GV];
char *Result = new char[(InputArgv.size()+1)*PtrSize];
DEBUG(errs() << "JIT: ARGV = " << (void*)Result << "\n");
- const Type *SBytePtr = PointerType::getUnqual(Type::getInt8Ty(C));
+ const Type *SBytePtr = Type::getInt8PtrTy(C);
for (unsigned i = 0; i != InputArgv.size(); ++i) {
unsigned Size = InputArgv[i].size()+1;
if (WhichEngine & EngineKind::JIT)
WhichEngine = EngineKind::JIT;
else {
- *ErrorStr = "Cannot create an interpreter with a memory manager.";
+ if (ErrorStr)
+ *ErrorStr = "Cannot create an interpreter with a memory manager.";
return 0;
}
}
ExecutionEngine::JITCtor(MP, ErrorStr, JMM, OptLevel,
AllocateGVsWithCode);
if (EE) return EE;
- } else {
- *ErrorStr = "JIT has not been linked in.";
- return 0;
}
}
if (WhichEngine & EngineKind::Interpreter) {
if (ExecutionEngine::InterpCtor)
return ExecutionEngine::InterpCtor(MP, ErrorStr);
- *ErrorStr = "Interpreter has not been linked in.";
+ if (ErrorStr)
+ *ErrorStr = "Interpreter has not been linked in.";
return 0;
}
-
+
+ if ((WhichEngine & EngineKind::JIT) && ExecutionEngine::JITCtor == 0) {
+ if (ErrorStr)
+ *ErrorStr = "JIT has not been linked in.";
+ }
return 0;
}
}
case Instruction::UIToFP: {
GenericValue GV = getConstantValue(Op0);
- if (CE->getType() == Type::getFloatTy(CE->getContext()))
+ if (CE->getType()->isFloatTy())
GV.FloatVal = float(GV.IntVal.roundToDouble());
- else if (CE->getType() == Type::getDoubleTy(CE->getContext()))
+ else if (CE->getType()->isDoubleTy())
GV.DoubleVal = GV.IntVal.roundToDouble();
- else if (CE->getType() == Type::getX86_FP80Ty(Op0->getContext())) {
+ else if (CE->getType()->isX86_FP80Ty()) {
const uint64_t zero[] = {0, 0};
APFloat apf = APFloat(APInt(80, 2, zero));
(void)apf.convertFromAPInt(GV.IntVal,
}
case Instruction::SIToFP: {
GenericValue GV = getConstantValue(Op0);
- if (CE->getType() == Type::getFloatTy(CE->getContext()))
+ if (CE->getType()->isFloatTy())
GV.FloatVal = float(GV.IntVal.signedRoundToDouble());
- else if (CE->getType() == Type::getDoubleTy(CE->getContext()))
+ else if (CE->getType()->isDoubleTy())
GV.DoubleVal = GV.IntVal.signedRoundToDouble();
- else if (CE->getType() == Type::getX86_FP80Ty(CE->getContext())) {
+ else if (CE->getType()->isX86_FP80Ty()) {
const uint64_t zero[] = { 0, 0};
APFloat apf = APFloat(APInt(80, 2, zero));
(void)apf.convertFromAPInt(GV.IntVal,
case Instruction::FPToSI: {
GenericValue GV = getConstantValue(Op0);
uint32_t BitWidth = cast<IntegerType>(CE->getType())->getBitWidth();
- if (Op0->getType() == Type::getFloatTy(Op0->getContext()))
+ if (Op0->getType()->isFloatTy())
GV.IntVal = APIntOps::RoundFloatToAPInt(GV.FloatVal, BitWidth);
- else if (Op0->getType() == Type::getDoubleTy(Op0->getContext()))
+ else if (Op0->getType()->isDoubleTy())
GV.IntVal = APIntOps::RoundDoubleToAPInt(GV.DoubleVal, BitWidth);
- else if (Op0->getType() == Type::getX86_FP80Ty(Op0->getContext())) {
+ else if (Op0->getType()->isX86_FP80Ty()) {
APFloat apf = APFloat(GV.IntVal);
uint64_t v;
bool ignored;
default: llvm_unreachable("Invalid bitcast operand");
case Type::IntegerTyID:
assert(DestTy->isFloatingPoint() && "invalid bitcast");
- if (DestTy == Type::getFloatTy(Op0->getContext()))
+ if (DestTy->isFloatTy())
GV.FloatVal = GV.IntVal.bitsToFloat();
- else if (DestTy == Type::getDoubleTy(DestTy->getContext()))
+ else if (DestTy->isDoubleTy())
GV.DoubleVal = GV.IntVal.bitsToDouble();
break;
case Type::FloatTyID: