diff options
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r-- | lib/ExecutionEngine/ExecutionEngine.cpp | 21 | ||||
-rw-r--r-- | lib/ExecutionEngine/Interpreter/Execution.cpp | 56 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/JITEmitter.cpp | 17 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/JITMemoryManager.cpp | 54 |
4 files changed, 74 insertions, 74 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 29a05bb..a80513f 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -573,8 +573,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { return GV; } case Instruction::Add: + case Instruction::FAdd: case Instruction::Sub: + case Instruction::FSub: case Instruction::Mul: + case Instruction::FMul: case Instruction::UDiv: case Instruction::SDiv: case Instruction::URem: @@ -605,11 +608,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { case Type::FloatTyID: switch (CE->getOpcode()) { default: assert(0 && "Invalid float opcode"); abort(); - case Instruction::Add: + case Instruction::FAdd: GV.FloatVal = LHS.FloatVal + RHS.FloatVal; break; - case Instruction::Sub: + case Instruction::FSub: GV.FloatVal = LHS.FloatVal - RHS.FloatVal; break; - case Instruction::Mul: + case Instruction::FMul: GV.FloatVal = LHS.FloatVal * RHS.FloatVal; break; case Instruction::FDiv: GV.FloatVal = LHS.FloatVal / RHS.FloatVal; break; @@ -620,11 +623,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { case Type::DoubleTyID: switch (CE->getOpcode()) { default: assert(0 && "Invalid double opcode"); abort(); - case Instruction::Add: + case Instruction::FAdd: GV.DoubleVal = LHS.DoubleVal + RHS.DoubleVal; break; - case Instruction::Sub: + case Instruction::FSub: GV.DoubleVal = LHS.DoubleVal - RHS.DoubleVal; break; - case Instruction::Mul: + case Instruction::FMul: GV.DoubleVal = LHS.DoubleVal * RHS.DoubleVal; break; case Instruction::FDiv: GV.DoubleVal = LHS.DoubleVal / RHS.DoubleVal; break; @@ -638,15 +641,15 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) { APFloat apfLHS = APFloat(LHS.IntVal); switch (CE->getOpcode()) { default: assert(0 && "Invalid long double opcode"); abort(); - case Instruction::Add: + case Instruction::FAdd: apfLHS.add(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven); GV.IntVal = apfLHS.bitcastToAPInt(); break; - case Instruction::Sub: + case Instruction::FSub: apfLHS.subtract(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven); GV.IntVal = apfLHS.bitcastToAPInt(); break; - case Instruction::Mul: + case Instruction::FMul: apfLHS.multiply(APFloat(RHS.IntVal), APFloat::rmNearestTiesToEven); GV.IntVal = apfLHS.bitcastToAPInt(); break; diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index 765fed2..7dfeae0 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -64,45 +64,35 @@ void Interpreter::initializeExecutionEngine() { Dest.TY##Val = Src1.TY##Val OP Src2.TY##Val; \ break -#define IMPLEMENT_INTEGER_BINOP1(OP, TY) \ - case Type::IntegerTyID: { \ - Dest.IntVal = Src1.IntVal OP Src2.IntVal; \ - break; \ - } - - -static void executeAddInst(GenericValue &Dest, GenericValue Src1, - GenericValue Src2, const Type *Ty) { +static void executeFAddInst(GenericValue &Dest, GenericValue Src1, + GenericValue Src2, const Type *Ty) { switch (Ty->getTypeID()) { - IMPLEMENT_INTEGER_BINOP1(+, Ty); IMPLEMENT_BINARY_OPERATOR(+, Float); IMPLEMENT_BINARY_OPERATOR(+, Double); default: - cerr << "Unhandled type for Add instruction: " << *Ty << "\n"; + cerr << "Unhandled type for FAdd instruction: " << *Ty << "\n"; abort(); } } -static void executeSubInst(GenericValue &Dest, GenericValue Src1, - GenericValue Src2, const Type *Ty) { +static void executeFSubInst(GenericValue &Dest, GenericValue Src1, + GenericValue Src2, const Type *Ty) { switch (Ty->getTypeID()) { - IMPLEMENT_INTEGER_BINOP1(-, Ty); IMPLEMENT_BINARY_OPERATOR(-, Float); IMPLEMENT_BINARY_OPERATOR(-, Double); default: - cerr << "Unhandled type for Sub instruction: " << *Ty << "\n"; + cerr << "Unhandled type for FSub instruction: " << *Ty << "\n"; abort(); } } -static void executeMulInst(GenericValue &Dest, GenericValue Src1, - GenericValue Src2, const Type *Ty) { +static void executeFMulInst(GenericValue &Dest, GenericValue Src1, + GenericValue Src2, const Type *Ty) { switch (Ty->getTypeID()) { - IMPLEMENT_INTEGER_BINOP1(*, Ty); IMPLEMENT_BINARY_OPERATOR(*, Float); IMPLEMENT_BINARY_OPERATOR(*, Double); default: - cerr << "Unhandled type for Mul instruction: " << *Ty << "\n"; + cerr << "Unhandled type for FMul instruction: " << *Ty << "\n"; abort(); } } @@ -550,11 +540,14 @@ void Interpreter::visitBinaryOperator(BinaryOperator &I) { GenericValue R; // Result switch (I.getOpcode()) { - case Instruction::Add: executeAddInst (R, Src1, Src2, Ty); break; - case Instruction::Sub: executeSubInst (R, Src1, Src2, Ty); break; - case Instruction::Mul: executeMulInst (R, Src1, Src2, Ty); break; - case Instruction::FDiv: executeFDivInst (R, Src1, Src2, Ty); break; - case Instruction::FRem: executeFRemInst (R, Src1, Src2, Ty); break; + case Instruction::Add: R.IntVal = Src1.IntVal + Src2.IntVal; break; + case Instruction::Sub: R.IntVal = Src1.IntVal - Src2.IntVal; break; + case Instruction::Mul: R.IntVal = Src1.IntVal * Src2.IntVal; break; + case Instruction::FAdd: executeFAddInst(R, Src1, Src2, Ty); break; + case Instruction::FSub: executeFSubInst(R, Src1, Src2, Ty); break; + case Instruction::FMul: executeFMulInst(R, Src1, Src2, Ty); break; + case Instruction::FDiv: executeFDivInst(R, Src1, Src2, Ty); break; + case Instruction::FRem: executeFRemInst(R, Src1, Src2, Ty); break; case Instruction::UDiv: R.IntVal = Src1.IntVal.udiv(Src2.IntVal); break; case Instruction::SDiv: R.IntVal = Src1.IntVal.sdiv(Src2.IntVal); break; case Instruction::URem: R.IntVal = Src1.IntVal.urem(Src2.IntVal); break; @@ -1258,18 +1251,21 @@ GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE, GenericValue Dest; const Type * Ty = CE->getOperand(0)->getType(); switch (CE->getOpcode()) { - case Instruction::Add: executeAddInst (Dest, Op0, Op1, Ty); break; - case Instruction::Sub: executeSubInst (Dest, Op0, Op1, Ty); break; - case Instruction::Mul: executeMulInst (Dest, Op0, Op1, Ty); break; + case Instruction::Add: Dest.IntVal = Op0.IntVal + Op1.IntVal; break; + case Instruction::Sub: Dest.IntVal = Op0.IntVal - Op1.IntVal; break; + case Instruction::Mul: Dest.IntVal = Op0.IntVal * Op1.IntVal; break; + case Instruction::FAdd: executeFAddInst(Dest, Op0, Op1, Ty); break; + case Instruction::FSub: executeFSubInst(Dest, Op0, Op1, Ty); break; + case Instruction::FMul: executeFMulInst(Dest, Op0, Op1, Ty); break; case Instruction::FDiv: executeFDivInst(Dest, Op0, Op1, Ty); break; case Instruction::FRem: executeFRemInst(Dest, Op0, Op1, Ty); break; case Instruction::SDiv: Dest.IntVal = Op0.IntVal.sdiv(Op1.IntVal); break; case Instruction::UDiv: Dest.IntVal = Op0.IntVal.udiv(Op1.IntVal); break; case Instruction::URem: Dest.IntVal = Op0.IntVal.urem(Op1.IntVal); break; case Instruction::SRem: Dest.IntVal = Op0.IntVal.srem(Op1.IntVal); break; - case Instruction::And: Dest.IntVal = Op0.IntVal.And(Op1.IntVal); break; - case Instruction::Or: Dest.IntVal = Op0.IntVal.Or(Op1.IntVal); break; - case Instruction::Xor: Dest.IntVal = Op0.IntVal.Xor(Op1.IntVal); break; + case Instruction::And: Dest.IntVal = Op0.IntVal & Op1.IntVal; break; + case Instruction::Or: Dest.IntVal = Op0.IntVal | Op1.IntVal; break; + case Instruction::Xor: Dest.IntVal = Op0.IntVal ^ Op1.IntVal; break; case Instruction::Shl: Dest.IntVal = Op0.IntVal.shl(Op1.IntVal.getZExtValue()); break; diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp index 89131a0..43f23e4 100644 --- a/lib/ExecutionEngine/JIT/JITEmitter.cpp +++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp @@ -551,7 +551,7 @@ namespace { // When outputting a function stub in the context of some other function, we // save BufferBegin/BufferEnd/CurBufferPtr here. - unsigned char *SavedBufferBegin, *SavedBufferEnd, *SavedCurBufferPtr; + uint8_t *SavedBufferBegin, *SavedBufferEnd, *SavedCurBufferPtr; /// Relocations - These are the relocations that the function needs, as /// emitted. @@ -891,8 +891,11 @@ unsigned JITEmitter::addSizeOfGlobalsInConstantVal(const Constant *C, break; } case Instruction::Add: + case Instruction::FAdd: case Instruction::Sub: + case Instruction::FSub: case Instruction::Mul: + case Instruction::FMul: case Instruction::UDiv: case Instruction::SDiv: case Instruction::URem: @@ -1056,11 +1059,11 @@ bool JITEmitter::finishFunction(MachineFunction &F) { // FnStart is the start of the text, not the start of the constant pool and // other per-function data. - unsigned char *FnStart = - (unsigned char *)TheJIT->getPointerToGlobalIfAvailable(F.getFunction()); + uint8_t *FnStart = + (uint8_t *)TheJIT->getPointerToGlobalIfAvailable(F.getFunction()); // FnEnd is the end of the function's machine code. - unsigned char *FnEnd = CurBufferPtr; + uint8_t *FnEnd = CurBufferPtr; if (!Relocations.empty()) { CurFn = F.getFunction(); @@ -1183,7 +1186,7 @@ bool JITEmitter::finishFunction(MachineFunction &F) { } else { DOUT << "JIT: Binary code:\n"; DOUT << std::hex; - unsigned char* q = FnStart; + uint8_t* q = FnStart; for (int i = 0; q < FnEnd; q += 4, ++i) { if (i == 4) i = 0; @@ -1221,7 +1224,7 @@ bool JITEmitter::finishFunction(MachineFunction &F) { BufferBegin = CurBufferPtr = MemMgr->startExceptionTable(F.getFunction(), ActualSize); BufferEnd = BufferBegin+ActualSize; - unsigned char* FrameRegister = DE->EmitDwarfTable(F, *this, FnStart, FnEnd); + uint8_t* FrameRegister = DE->EmitDwarfTable(F, *this, FnStart, FnEnd); MemMgr->endExceptionTable(F.getFunction(), BufferBegin, CurBufferPtr, FrameRegister); BufferBegin = SavedBufferBegin; @@ -1416,7 +1419,7 @@ void JITEmitter::startGVStub(const GlobalValue* GV, void *Buffer, SavedBufferEnd = BufferEnd; SavedCurBufferPtr = CurBufferPtr; - BufferBegin = CurBufferPtr = (unsigned char *)Buffer; + BufferBegin = CurBufferPtr = (uint8_t *)Buffer; BufferEnd = BufferBegin+StubSize+1; } diff --git a/lib/ExecutionEngine/JIT/JITMemoryManager.cpp b/lib/ExecutionEngine/JIT/JITMemoryManager.cpp index 2819b6d..70ccdcc 100644 --- a/lib/ExecutionEngine/JIT/JITMemoryManager.cpp +++ b/lib/ExecutionEngine/JIT/JITMemoryManager.cpp @@ -257,9 +257,9 @@ namespace { // When emitting code into a memory block, this is the block. MemoryRangeHeader *CurBlock; - unsigned char *CurStubPtr, *StubBase; - unsigned char *GOTBase; // Target Specific reserved memory - void *DlsymTable; // Stub external symbol information + uint8_t *CurStubPtr, *StubBase; + uint8_t *GOTBase; // Target Specific reserved memory + void *DlsymTable; // Stub external symbol information // Centralize memory block allocation. sys::MemoryBlock getNewMemoryBlock(unsigned size); @@ -273,12 +273,12 @@ namespace { void AllocateGOT(); void SetDlsymTable(void *); - unsigned char *allocateStub(const GlobalValue* F, unsigned StubSize, - unsigned Alignment); + uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize, + unsigned Alignment); /// startFunctionBody - When a function starts, allocate a block of free /// executable memory, returning a pointer to it and its actual size. - unsigned char *startFunctionBody(const Function *F, uintptr_t &ActualSize) { + uint8_t *startFunctionBody(const Function *F, uintptr_t &ActualSize) { FreeRangeHeader* candidateBlock = FreeMemoryList; FreeRangeHeader* head = FreeMemoryList; @@ -301,18 +301,18 @@ namespace { // Allocate the entire memory block. FreeMemoryList = candidateBlock->AllocateBlock(); ActualSize = CurBlock->BlockSize-sizeof(MemoryRangeHeader); - return (unsigned char *)(CurBlock+1); + return (uint8_t *)(CurBlock+1); } /// endFunctionBody - The function F is now allocated, and takes the memory /// in the range [FunctionStart,FunctionEnd). - void endFunctionBody(const Function *F, unsigned char *FunctionStart, - unsigned char *FunctionEnd) { + void endFunctionBody(const Function *F, uint8_t *FunctionStart, + uint8_t *FunctionEnd) { assert(FunctionEnd > FunctionStart); - assert(FunctionStart == (unsigned char *)(CurBlock+1) && + assert(FunctionStart == (uint8_t *)(CurBlock+1) && "Mismatched function start/end!"); - uintptr_t BlockSize = FunctionEnd - (unsigned char *)CurBlock; + uintptr_t BlockSize = FunctionEnd - (uint8_t *)CurBlock; FunctionBlocks[F] = CurBlock; // Release the memory at the end of this block that isn't needed. @@ -320,17 +320,17 @@ namespace { } /// allocateSpace - Allocate a memory block of the given size. - unsigned char *allocateSpace(intptr_t Size, unsigned Alignment) { + uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) { CurBlock = FreeMemoryList; FreeMemoryList = FreeMemoryList->AllocateBlock(); - unsigned char *result = (unsigned char *)CurBlock+1; + uint8_t *result = (uint8_t *)CurBlock+1; if (Alignment == 0) Alignment = 1; - result = (unsigned char*)(((intptr_t)result+Alignment-1) & + result = (uint8_t*)(((intptr_t)result+Alignment-1) & ~(intptr_t)(Alignment-1)); - uintptr_t BlockSize = result + Size - (unsigned char *)CurBlock; + uintptr_t BlockSize = result + Size - (uint8_t *)CurBlock; FreeMemoryList =CurBlock->TrimAllocationToSize(FreeMemoryList, BlockSize); return result; @@ -338,28 +338,26 @@ namespace { /// startExceptionTable - Use startFunctionBody to allocate memory for the /// function's exception table. - unsigned char* startExceptionTable(const Function* F, - uintptr_t &ActualSize) { + uint8_t* startExceptionTable(const Function* F, uintptr_t &ActualSize) { return startFunctionBody(F, ActualSize); } /// endExceptionTable - The exception table of F is now allocated, /// and takes the memory in the range [TableStart,TableEnd). - void endExceptionTable(const Function *F, unsigned char *TableStart, - unsigned char *TableEnd, - unsigned char* FrameRegister) { + void endExceptionTable(const Function *F, uint8_t *TableStart, + uint8_t *TableEnd, uint8_t* FrameRegister) { assert(TableEnd > TableStart); - assert(TableStart == (unsigned char *)(CurBlock+1) && + assert(TableStart == (uint8_t *)(CurBlock+1) && "Mismatched table start/end!"); - uintptr_t BlockSize = TableEnd - (unsigned char *)CurBlock; + uintptr_t BlockSize = TableEnd - (uint8_t *)CurBlock; TableBlocks[F] = CurBlock; // Release the memory at the end of this block that isn't needed. FreeMemoryList =CurBlock->TrimAllocationToSize(FreeMemoryList, BlockSize); } - unsigned char *getGOTBase() const { + uint8_t *getGOTBase() const { return GOTBase; } @@ -433,7 +431,7 @@ DefaultJITMemoryManager::DefaultJITMemoryManager() { sys::MemoryBlock MemBlock = getNewMemoryBlock(16 << 20); #endif - unsigned char *MemBase = static_cast<unsigned char*>(MemBlock.base()); + uint8_t *MemBase = static_cast<uint8_t*>(MemBlock.base()); // Allocate stubs backwards from the base, allocate functions forward // from the base. @@ -492,7 +490,7 @@ DefaultJITMemoryManager::DefaultJITMemoryManager() { void DefaultJITMemoryManager::AllocateGOT() { assert(GOTBase == 0 && "Cannot allocate the got multiple times"); - GOTBase = new unsigned char[sizeof(void*) * 8192]; + GOTBase = new uint8_t[sizeof(void*) * 8192]; HasGOT = true; } @@ -508,12 +506,12 @@ DefaultJITMemoryManager::~DefaultJITMemoryManager() { Blocks.clear(); } -unsigned char *DefaultJITMemoryManager::allocateStub(const GlobalValue* F, +uint8_t *DefaultJITMemoryManager::allocateStub(const GlobalValue* F, unsigned StubSize, unsigned Alignment) { CurStubPtr -= StubSize; - CurStubPtr = (unsigned char*)(((intptr_t)CurStubPtr) & - ~(intptr_t)(Alignment-1)); + CurStubPtr = (uint8_t*)(((intptr_t)CurStubPtr) & + ~(intptr_t)(Alignment-1)); if (CurStubPtr < StubBase) { // FIXME: allocate a new block fprintf(stderr, "JIT ran out of memory for function stubs!\n"); |