aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>2009-05-30 20:51:52 +0000
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>2009-05-30 20:51:52 +0000
commita3f99f90338d89354384ca25f53ca4450a1a9d18 (patch)
tree1e3eb946af54ca0dd5e57486978e10f11d2a4210
parent0e98e4d299e76ab627d53c976f0f84b449106d15 (diff)
First patch in the direction of splitting MachineCodeEmitter in two subclasses:
JITCodeEmitter and ObjectCodeEmitter. No functional changes yet. Patch by Aaron Gray git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72631 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/CodeGen/JITCodeEmitter.h322
-rw-r--r--include/llvm/Target/TargetJITInfo.h16
-rw-r--r--include/llvm/Target/TargetMachine.h58
-rw-r--r--lib/CodeGen/LLVMTargetMachine.cpp43
-rw-r--r--lib/ExecutionEngine/JIT/JIT.cpp18
-rw-r--r--lib/ExecutionEngine/JIT/JIT.h6
-rw-r--r--lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp174
-rw-r--r--lib/ExecutionEngine/JIT/JITDwarfEmitter.h8
-rw-r--r--lib/ExecutionEngine/JIT/JITEmitter.cpp36
-rw-r--r--lib/Target/ARM/ARM.h12
-rw-r--r--lib/Target/ARM/ARMCodeEmitter.cpp157
-rw-r--r--lib/Target/ARM/ARMJITInfo.cpp48
-rw-r--r--lib/Target/ARM/ARMJITInfo.h10
-rw-r--r--lib/Target/ARM/ARMTargetMachine.cpp36
-rw-r--r--lib/Target/ARM/ARMTargetMachine.h6
-rw-r--r--lib/Target/Alpha/Alpha.h2
-rw-r--r--lib/Target/Alpha/AlphaCodeEmitter.cpp72
-rw-r--r--lib/Target/Alpha/AlphaJITInfo.cpp12
-rw-r--r--lib/Target/Alpha/AlphaJITInfo.h2
-rw-r--r--lib/Target/Alpha/AlphaTargetMachine.cpp15
-rw-r--r--lib/Target/Alpha/AlphaTargetMachine.h6
-rw-r--r--lib/Target/PowerPC/PPC.h2
-rw-r--r--lib/Target/PowerPC/PPCCodeEmitter.cpp62
-rw-r--r--lib/Target/PowerPC/PPCJITInfo.cpp63
-rw-r--r--lib/Target/PowerPC/PPCJITInfo.h3
-rw-r--r--lib/Target/PowerPC/PPCTargetMachine.cpp47
-rw-r--r--lib/Target/PowerPC/PPCTargetMachine.h5
-rw-r--r--lib/Target/X86/X86.h8
-rw-r--r--lib/Target/X86/X86CodeEmitter.cpp78
-rw-r--r--lib/Target/X86/X86JITInfo.cpp81
-rw-r--r--lib/Target/X86/X86JITInfo.h13
-rw-r--r--lib/Target/X86/X86TargetMachine.cpp43
-rw-r--r--lib/Target/X86/X86TargetMachine.h5
33 files changed, 1103 insertions, 366 deletions
diff --git a/include/llvm/CodeGen/JITCodeEmitter.h b/include/llvm/CodeGen/JITCodeEmitter.h
new file mode 100644
index 0000000000..81a7c60bdb
--- /dev/null
+++ b/include/llvm/CodeGen/JITCodeEmitter.h
@@ -0,0 +1,322 @@
+//===-- llvm/CodeGen/JITCodeEmitter.h - Code emission ----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines an abstract interface that is used by the machine code
+// emission framework to output the code. This allows machine code emission to
+// be separated from concerns such as resolution of call targets, and where the
+// machine code will be written (memory or disk, f.e.).
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_JITCODEEMITTER_H
+#define LLVM_CODEGEN_JITCODEEMITTER_H
+
+#include <string>
+#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/Streams.h"
+#include "llvm/CodeGen/MachineCodeEmitter.h"
+
+using namespace std;
+
+namespace llvm {
+
+class MachineBasicBlock;
+class MachineConstantPool;
+class MachineJumpTableInfo;
+class MachineFunction;
+class MachineModuleInfo;
+class MachineRelocation;
+class Value;
+class GlobalValue;
+class Function;
+
+/// JITCodeEmitter - This class defines two sorts of methods: those for
+/// emitting the actual bytes of machine code, and those for emitting auxillary
+/// structures, such as jump tables, relocations, etc.
+///
+/// Emission of machine code is complicated by the fact that we don't (in
+/// general) know the size of the machine code that we're about to emit before
+/// we emit it. As such, we preallocate a certain amount of memory, and set the
+/// BufferBegin/BufferEnd pointers to the start and end of the buffer. As we
+/// emit machine instructions, we advance the CurBufferPtr to indicate the
+/// location of the next byte to emit. In the case of a buffer overflow (we
+/// need to emit more machine code than we have allocated space for), the
+/// CurBufferPtr will saturate to BufferEnd and ignore stores. Once the entire
+/// function has been emitted, the overflow condition is checked, and if it has
+/// occurred, more memory is allocated, and we reemit the code into it.
+///
+class JITCodeEmitter : public MachineCodeEmitter {
+public:
+ virtual ~JITCodeEmitter() {}
+
+ /// startFunction - This callback is invoked when the specified function is
+ /// about to be code generated. This initializes the BufferBegin/End/Ptr
+ /// fields.
+ ///
+ virtual void startFunction(MachineFunction &F) = 0;
+
+ /// finishFunction - This callback is invoked when the specified function has
+ /// finished code generation. If a buffer overflow has occurred, this method
+ /// returns true (the callee is required to try again), otherwise it returns
+ /// false.
+ ///
+ virtual bool finishFunction(MachineFunction &F) = 0;
+
+ /// startGVStub - This callback is invoked when the JIT needs the
+ /// address of a GV (e.g. function) that has not been code generated yet.
+ /// The StubSize specifies the total size required by the stub.
+ ///
+ virtual void startGVStub(const GlobalValue* GV, unsigned StubSize,
+ unsigned Alignment = 1) = 0;
+
+ /// startGVStub - This callback is invoked when the JIT needs the address of a
+ /// GV (e.g. function) that has not been code generated yet. Buffer points to
+ /// memory already allocated for this stub.
+ ///
+ virtual void startGVStub(const GlobalValue* GV, void *Buffer,
+ unsigned StubSize) = 0;
+
+ /// finishGVStub - This callback is invoked to terminate a GV stub.
+ ///
+ virtual void *finishGVStub(const GlobalValue* F) = 0;
+
+ /// emitByte - This callback is invoked when a byte needs to be written to the
+ /// output stream.
+ ///
+ void emitByte(unsigned char B) {
+ if (CurBufferPtr != BufferEnd)
+ *CurBufferPtr++ = B;
+ }
+
+ /// emitWordLE - This callback is invoked when a 32-bit word needs to be
+ /// written to the output stream in little-endian format.
+ ///
+ void emitWordLE(unsigned W) {
+ if (4 <= BufferEnd-CurBufferPtr) {
+ *CurBufferPtr++ = (unsigned char)(W >> 0);
+ *CurBufferPtr++ = (unsigned char)(W >> 8);
+ *CurBufferPtr++ = (unsigned char)(W >> 16);
+ *CurBufferPtr++ = (unsigned char)(W >> 24);
+ } else {
+ CurBufferPtr = BufferEnd;
+ }
+ }
+
+ /// emitWordBE - This callback is invoked when a 32-bit word needs to be
+ /// written to the output stream in big-endian format.
+ ///
+ void emitWordBE(unsigned W) {
+ if (4 <= BufferEnd-CurBufferPtr) {
+ *CurBufferPtr++ = (unsigned char)(W >> 24);
+ *CurBufferPtr++ = (unsigned char)(W >> 16);
+ *CurBufferPtr++ = (unsigned char)(W >> 8);
+ *CurBufferPtr++ = (unsigned char)(W >> 0);
+ } else {
+ CurBufferPtr = BufferEnd;
+ }
+ }
+
+ /// emitDWordLE - This callback is invoked when a 64-bit word needs to be
+ /// written to the output stream in little-endian format.
+ ///
+ void emitDWordLE(uint64_t W) {
+ if (8 <= BufferEnd-CurBufferPtr) {
+ *CurBufferPtr++ = (unsigned char)(W >> 0);
+ *CurBufferPtr++ = (unsigned char)(W >> 8);
+ *CurBufferPtr++ = (unsigned char)(W >> 16);
+ *CurBufferPtr++ = (unsigned char)(W >> 24);
+ *CurBufferPtr++ = (unsigned char)(W >> 32);
+ *CurBufferPtr++ = (unsigned char)(W >> 40);
+ *CurBufferPtr++ = (unsigned char)(W >> 48);
+ *CurBufferPtr++ = (unsigned char)(W >> 56);
+ } else {
+ CurBufferPtr = BufferEnd;
+ }
+ }
+
+ /// emitDWordBE - This callback is invoked when a 64-bit word needs to be
+ /// written to the output stream in big-endian format.
+ ///
+ void emitDWordBE(uint64_t W) {
+ if (8 <= BufferEnd-CurBufferPtr) {
+ *CurBufferPtr++ = (unsigned char)(W >> 56);
+ *CurBufferPtr++ = (unsigned char)(W >> 48);
+ *CurBufferPtr++ = (unsigned char)(W >> 40);
+ *CurBufferPtr++ = (unsigned char)(W >> 32);
+ *CurBufferPtr++ = (unsigned char)(W >> 24);
+ *CurBufferPtr++ = (unsigned char)(W >> 16);
+ *CurBufferPtr++ = (unsigned char)(W >> 8);
+ *CurBufferPtr++ = (unsigned char)(W >> 0);
+ } else {
+ CurBufferPtr = BufferEnd;
+ }
+ }
+
+ /// emitAlignment - Move the CurBufferPtr pointer up the the specified
+ /// alignment (saturated to BufferEnd of course).
+ void emitAlignment(unsigned Alignment) {
+ if (Alignment == 0) Alignment = 1;
+
+ if(Alignment <= (uintptr_t)(BufferEnd-CurBufferPtr)) {
+ // Move the current buffer ptr up to the specified alignment.
+ CurBufferPtr =
+ (unsigned char*)(((uintptr_t)CurBufferPtr+Alignment-1) &
+ ~(uintptr_t)(Alignment-1));
+ } else {
+ CurBufferPtr = BufferEnd;
+ }
+ }
+
+
+ /// emitULEB128Bytes - This callback is invoked when a ULEB128 needs to be
+ /// written to the output stream.
+ void emitULEB128Bytes(unsigned Value) {
+ do {
+ unsigned char Byte = Value & 0x7f;
+ Value >>= 7;
+ if (Value) Byte |= 0x80;
+ emitByte(Byte);
+ } while (Value);
+ }
+
+ /// emitSLEB128Bytes - This callback is invoked when a SLEB128 needs to be
+ /// written to the output stream.
+ void emitSLEB128Bytes(int Value) {
+ int Sign = Value >> (8 * sizeof(Value) - 1);
+ bool IsMore;
+
+ do {
+ unsigned char Byte = Value & 0x7f;
+ Value >>= 7;
+ IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
+ if (IsMore) Byte |= 0x80;
+ emitByte(Byte);
+ } while (IsMore);
+ }
+
+ /// emitString - This callback is invoked when a String needs to be
+ /// written to the output stream.
+ void emitString(const std::string &String) {
+ for (unsigned i = 0, N = static_cast<unsigned>(String.size());
+ i < N; ++i) {
+ unsigned char C = String[i];
+ emitByte(C);
+ }
+ emitByte(0);
+ }
+
+ /// emitInt32 - Emit a int32 directive.
+ void emitInt32(int Value) {
+ if (4 <= BufferEnd-CurBufferPtr) {
+ *((uint32_t*)CurBufferPtr) = Value;
+ CurBufferPtr += 4;
+ } else {
+ CurBufferPtr = BufferEnd;
+ }
+ }
+
+ /// emitInt64 - Emit a int64 directive.
+ void emitInt64(uint64_t Value) {
+ if (8 <= BufferEnd-CurBufferPtr) {
+ *((uint64_t*)CurBufferPtr) = Value;
+ CurBufferPtr += 8;
+ } else {
+ CurBufferPtr = BufferEnd;
+ }
+ }
+
+ /// emitInt32At - Emit the Int32 Value in Addr.
+ void emitInt32At(uintptr_t *Addr, uintptr_t Value) {
+ if (Addr >= (uintptr_t*)BufferBegin && Addr < (uintptr_t*)BufferEnd)
+ (*(uint32_t*)Addr) = (uint32_t)Value;
+ }
+
+ /// emitInt64At - Emit the Int64 Value in Addr.
+ void emitInt64At(uintptr_t *Addr, uintptr_t Value) {
+ if (Addr >= (uintptr_t*)BufferBegin && Addr < (uintptr_t*)BufferEnd)
+ (*(uint64_t*)Addr) = (uint64_t)Value;
+ }
+
+
+ /// emitLabel - Emits a label
+ virtual void emitLabel(uint64_t LabelID) = 0;
+
+ /// allocateSpace - Allocate a block of space in the current output buffer,
+ /// returning null (and setting conditions to indicate buffer overflow) on
+ /// failure. Alignment is the alignment in bytes of the buffer desired.
+ virtual void *allocateSpace(uintptr_t Size, unsigned Alignment) {
+ emitAlignment(Alignment);
+ void *Result;
+
+ // Check for buffer overflow.
+ if (Size >= (uintptr_t)(BufferEnd-CurBufferPtr)) {
+ CurBufferPtr = BufferEnd;
+ Result = 0;
+ } else {
+ // Allocate the space.
+ Result = CurBufferPtr;
+ CurBufferPtr += Size;
+ }
+
+ return Result;
+ }
+
+ /// StartMachineBasicBlock - This should be called by the target when a new
+ /// basic block is about to be emitted. This way the MCE knows where the
+ /// start of the block is, and can implement getMachineBasicBlockAddress.
+ virtual void StartMachineBasicBlock(MachineBasicBlock *MBB) = 0;
+
+ /// getCurrentPCValue - This returns the address that the next emitted byte
+ /// will be output to.
+ ///
+ virtual uintptr_t getCurrentPCValue() const {
+ return (uintptr_t)CurBufferPtr;
+ }
+
+ /// getCurrentPCOffset - Return the offset from the start of the emitted
+ /// buffer that we are currently writing to.
+ uintptr_t getCurrentPCOffset() const {
+ return CurBufferPtr-BufferBegin;
+ }
+
+ /// addRelocation - Whenever a relocatable address is needed, it should be
+ /// noted with this interface.
+ virtual void addRelocation(const MachineRelocation &MR) = 0;
+
+ /// FIXME: These should all be handled with relocations!
+
+ /// getConstantPoolEntryAddress - Return the address of the 'Index' entry in
+ /// the constant pool that was last emitted with the emitConstantPool method.
+ ///
+ virtual uintptr_t getConstantPoolEntryAddress(unsigned Index) const = 0;
+
+ /// getJumpTableEntryAddress - Return the address of the jump table with index
+ /// 'Index' in the function that last called initJumpTableInfo.
+ ///
+ virtual uintptr_t getJumpTableEntryAddress(unsigned Index) const = 0;
+
+ /// getMachineBasicBlockAddress - Return the address of the specified
+ /// MachineBasicBlock, only usable after the label for the MBB has been
+ /// emitted.
+ ///
+ virtual uintptr_t getMachineBasicBlockAddress(MachineBasicBlock *MBB) const= 0;
+
+ /// getLabelAddress - Return the address of the specified LabelID, only usable
+ /// after the LabelID has been emitted.
+ ///
+ virtual uintptr_t getLabelAddress(uint64_t LabelID) const = 0;
+
+ /// Specifies the MachineModuleInfo object. This is used for exception handling
+ /// purposes.
+ virtual void setModuleInfo(MachineModuleInfo* Info) = 0;
+};
+
+} // End llvm namespace
+
+#endif
diff --git a/include/llvm/Target/TargetJITInfo.h b/include/llvm/Target/TargetJITInfo.h
index 3f48da9f40..9545689cb7 100644
--- a/include/llvm/Target/TargetJITInfo.h
+++ b/include/llvm/Target/TargetJITInfo.h
@@ -23,7 +23,7 @@
namespace llvm {
class Function;
class GlobalValue;
- class MachineCodeEmitter;
+ class JITCodeEmitter;
class MachineRelocation;
/// TargetJITInfo - Target specific information required by the Just-In-Time
@@ -39,29 +39,29 @@ namespace llvm {
///
virtual void replaceMachineCodeForFunction(void *Old, void *New) = 0;
- /// emitGlobalValueIndirectSym - Use the specified MachineCodeEmitter object
+ /// emitGlobalValueIndirectSym - Use the specified JITCodeEmitter object
/// to emit an indirect symbol which contains the address of the specified
/// ptr.
virtual void *emitGlobalValueIndirectSym(const GlobalValue* GV, void *ptr,
- MachineCodeEmitter &MCE) {
+ JITCodeEmitter &JCE) {
assert(0 && "This target doesn't implement emitGlobalValueIndirectSym!");
return 0;
}
- /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a
+ /// emitFunctionStub - Use the specified JITCodeEmitter object to emit a
/// small native function that simply calls the function at the specified
/// address. Return the address of the resultant function.
virtual void *emitFunctionStub(const Function* F, void *Fn,
- MachineCodeEmitter &MCE) {
+ JITCodeEmitter &JCE) {
assert(0 && "This target doesn't implement emitFunctionStub!");
return 0;
}
- /// emitFunctionStubAtAddr - Use the specified MachineCodeEmitter object to
+ /// emitFunctionStubAtAddr - Use the specified JITCodeEmitter object to
/// emit a small native function that simply calls Fn. Emit the stub into
/// the supplied buffer.
virtual void emitFunctionStubAtAddr(const Function* F, void *Fn,
- void *Buffer, MachineCodeEmitter &MCE) {
+ void *Buffer, JITCodeEmitter &JCE) {
assert(0 && "This target doesn't implement emitFunctionStubAtAddr!");
}
@@ -125,7 +125,7 @@ namespace llvm {
/// allocateSeparateGVMemory - If true, globals should be placed in
/// separately allocated heap memory rather than in the same
- /// code memory allocated by MachineCodeEmitter.
+ /// code memory allocated by JITCodeEmitter.
virtual bool allocateSeparateGVMemory() const { return false; }
protected:
bool useGOT;
diff --git a/include/llvm/Target/TargetMachine.h b/include/llvm/Target/TargetMachine.h
index 405f22eeb4..bdcc4eff67 100644
--- a/include/llvm/Target/TargetMachine.h
+++ b/include/llvm/Target/TargetMachine.h
@@ -28,6 +28,7 @@ class TargetJITInfo;
class TargetLowering;
class TargetFrameInfo;
class MachineCodeEmitter;
+class JITCodeEmitter;
class TargetRegisterInfo;
class Module;
class PassManagerBase;
@@ -236,6 +237,16 @@ public:
return true;
}
+ /// addPassesToEmitFileFinish - If the passes to emit the specified file had
+ /// to be split up (e.g., to add an object writer pass), this method can be
+ /// used to finish up adding passes to emit the file, if necessary.
+ ///
+ virtual bool addPassesToEmitFileFinish(PassManagerBase &,
+ JITCodeEmitter *,
+ CodeGenOpt::Level) {
+ return true;
+ }
+
/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
/// get machine code emitted. This uses a MachineCodeEmitter object to handle
/// actually outputting the machine code and resolving things like the address
@@ -248,6 +259,18 @@ public:
return true;
}
+ /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
+ /// get machine code emitted. This uses a MachineCodeEmitter object to handle
+ /// actually outputting the machine code and resolving things like the address
+ /// of functions. This method returns true if machine code emission is
+ /// not supported.
+ ///
+ virtual bool addPassesToEmitMachineCode(PassManagerBase &,
+ JITCodeEmitter &,
+ CodeGenOpt::Level) {
+ return true;
+ }
+
/// addPassesToEmitWholeFile - This method can be implemented by targets that
/// require having the entire module at once. This is not recommended, do not
/// use this.
@@ -297,6 +320,14 @@ public:
MachineCodeEmitter *MCE,
CodeGenOpt::Level);
+ /// addPassesToEmitFileFinish - If the passes to emit the specified file had
+ /// to be split up (e.g., to add an object writer pass), this method can be
+ /// used to finish up adding passes to emit the file, if necessary.
+ ///
+ virtual bool addPassesToEmitFileFinish(PassManagerBase &PM,
+ JITCodeEmitter *MCE,
+ CodeGenOpt::Level);
+
/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
/// get machine code emitted. This uses a MachineCodeEmitter object to handle
/// actually outputting the machine code and resolving things like the address
@@ -307,6 +338,16 @@ public:
MachineCodeEmitter &MCE,
CodeGenOpt::Level);
+ /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
+ /// get machine code emitted. This uses a MachineCodeEmitter object to handle
+ /// actually outputting the machine code and resolving things like the address
+ /// of functions. This method returns true if machine code emission is
+ /// not supported.
+ ///
+ virtual bool addPassesToEmitMachineCode(PassManagerBase &PM,
+ JITCodeEmitter &MCE,
+ CodeGenOpt::Level);
+
/// Target-Independent Code Generator Pass Configuration Options.
/// addInstSelector - This method should add any "last minute" LLVM->LLVM
@@ -355,6 +396,14 @@ public:
return true;
}
+ /// addCodeEmitter - This pass should be overridden by the target to add a
+ /// code emitter, if supported. If this is not supported, 'true' should be
+ /// returned. If DumpAsm is true, the generated assembly is printed to cerr.
+ virtual bool addCodeEmitter(PassManagerBase &, CodeGenOpt::Level,
+ bool /*DumpAsm*/, JITCodeEmitter &) {
+ return true;
+ }
+
/// addSimpleCodeEmitter - This pass should be overridden by the target to add
/// a code emitter (without setting flags), if supported. If this is not
/// supported, 'true' should be returned. If DumpAsm is true, the generated
@@ -364,6 +413,15 @@ public:
return true;
}
+ /// addSimpleCodeEmitter - This pass should be overridden by the target to add
+ /// a code emitter (without setting flags), if supported. If this is not
+ /// supported, 'true' should be returned. If DumpAsm is true, the generated
+ /// assembly is printed to cerr.
+ virtual bool addSimpleCodeEmitter(PassManagerBase &, CodeGenOpt::Level,
+ bool /*DumpAsm*/, JITCodeEmitter &) {
+ return true;
+ }
+
/// getEnableTailMergeDefault - the default setting for -enable-tail-merge
/// on this target. User flag overrides.
virtual bool getEnableTailMergeDefault() const { return true; }
diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp
index 41a047780e..b3c60e6393 100644
--- a/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/lib/CodeGen/LLVMTargetMachine.cpp
@@ -109,6 +109,23 @@ bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
return false; // success!
}
+/// addPassesToEmitFileFinish - If the passes to emit the specified file had to
+/// be split up (e.g., to add an object writer pass), this method can be used to
+/// finish up adding passes to emit the file, if necessary.
+bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
+ JITCodeEmitter *JCE,
+ CodeGenOpt::Level OptLevel) {
+ if (JCE)
+ addSimpleCodeEmitter(PM, OptLevel, PrintEmittedAsm, *JCE);
+
+ PM.add(createGCInfoDeleter());
+
+ // Delete machine code for this function
+ PM.add(createMachineCodeDeleter());
+
+ return false; // success!
+}
+
/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
/// get machine code emitted. This uses a MachineCodeEmitter object to handle
/// actually outputting the machine code and resolving things like the address
@@ -135,6 +152,32 @@ bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM,
return false; // success!
}
+/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
+/// get machine code emitted. This uses a MachineCodeEmitter object to handle
+/// actually outputting the machine code and resolving things like the address
+/// of functions. This method should returns true if machine code emission is
+/// not supported.
+///
+bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM,
+ JITCodeEmitter &JCE,
+ CodeGenOpt::Level OptLevel) {
+ // Add common CodeGen passes.
+ if (addCommonCodeGenPasses(PM, OptLevel))
+ return true;
+
+ if (addPreEmitPass(PM, OptLevel) && PrintMachineCode)
+ PM.add(createMachineFunctionPrinterPass(cerr));
+
+ addCodeEmitter(PM, OptLevel, PrintEmittedAsm, JCE);
+
+ PM.add(createGCInfoDeleter());
+
+ // Delete machine code for this function
+ PM.add(createMachineCodeDeleter());
+
+ return false; // success!
+}
+
static void printAndVerify(PassManagerBase &PM,
bool allowDoubleDefs = false) {
if (PrintMachineCode)
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp
index 522a08dd78..f8ae884461 100644
--- a/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/lib/ExecutionEngine/JIT/JIT.cpp
@@ -19,7 +19,7 @@
#include "llvm/GlobalVariable.h"
#include "llvm/Instructions.h"
#include "llvm/ModuleProvider.h"
-#include "llvm/CodeGen/MachineCodeEmitter.h"
+#include "llvm/CodeGen/JITCodeEmitter.h"
#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/CodeGen/MachineCodeInfo.h"
#include "llvm/Target/TargetData.h"
@@ -214,8 +214,8 @@ JIT::JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji,
jitstate = new JITState(MP);
- // Initialize MCE
- MCE = createEmitter(*this, JMM);
+ // Initialize JCE
+ JCE = createEmitter(*this, JMM);
// Add target data
MutexGuard locked(lock);
@@ -224,7 +224,7 @@ JIT::JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji,
// Turn the machine code intermediate representation into bytes in memory that
// may be executed.
- if (TM.addPassesToEmitMachineCode(PM, *MCE, OptLevel)) {
+ if (TM.addPassesToEmitMachineCode(PM, *JCE, OptLevel)) {
cerr << "Target does not support machine code emission!\n";
abort();
}
@@ -253,7 +253,7 @@ JIT::JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji,
JIT::~JIT() {
delete jitstate;
- delete MCE;
+ delete JCE;
delete &TM;
}
@@ -273,7 +273,7 @@ void JIT::addModuleProvider(ModuleProvider *MP) {
// Turn the machine code intermediate representation into bytes in memory
// that may be executed.
- if (TM.addPassesToEmitMachineCode(PM, *MCE, CodeGenOpt::Default)) {
+ if (TM.addPassesToEmitMachineCode(PM, *JCE, CodeGenOpt::Default)) {
cerr << "Target does not support machine code emission!\n";
abort();
}
@@ -306,7 +306,7 @@ Module *JIT::removeModuleProvider(ModuleProvider *MP, std::string *E) {
// Turn the machine code intermediate representation into bytes in memory
// that may be executed.
- if (TM.addPassesToEmitMachineCode(PM, *MCE, CodeGenOpt::Default)) {
+ if (TM.addPassesToEmitMachineCode(PM, *JCE, CodeGenOpt::Default)) {
cerr << "Target does not support machine code emission!\n";
abort();
}
@@ -338,7 +338,7 @@ void JIT::deleteModuleProvider(ModuleProvider *MP, std::string *E) {
// Turn the machine code intermediate representation into bytes in memory
// that may be executed.
- if (TM.addPassesToEmitMachineCode(PM, *MCE, CodeGenOpt::Default)) {
+ if (TM.addPassesToEmitMachineCode(PM, *JCE, CodeGenOpt::Default)) {
cerr << "Target does not support machine code emission!\n";
abort();
}
@@ -654,7 +654,7 @@ void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
Ptr = (char*)Ptr + (MisAligned ? (A-MisAligned) : 0);
}
} else {
- Ptr = MCE->allocateSpace(S, A);
+ Ptr = JCE->allocateSpace(S, A);
}
addGlobalMapping(GV, Ptr);
EmitGlobalVariable(GV);
diff --git a/lib/ExecutionEngine/JIT/JIT.h b/lib/ExecutionEngine/JIT/JIT.h
index 02955ab3ad..9924d0bfa9 100644
--- a/lib/ExecutionEngine/JIT/JIT.h
+++ b/lib/ExecutionEngine/JIT/JIT.h
@@ -51,7 +51,7 @@ public:
class JIT : public ExecutionEngine {
TargetMachine &TM; // The current target we are compiling to
TargetJITInfo &TJI; // The JITInfo for the target we are compiling to
- MachineCodeEmitter *MCE; // MCE object
+ JITCodeEmitter *JCE; // JCE object
JITState *jitstate;
@@ -147,7 +147,7 @@ public:
void addPendingFunction(Function *F);
/// getCodeEmitter - Return the code emitter this JIT is emitting into.
- MachineCodeEmitter *getCodeEmitter() const { return MCE; }
+ JITCodeEmitter *getCodeEmitter() const { return JCE; }
static ExecutionEngine *createJIT(ModuleProvider *MP, std::string *Err,
JITMemoryManager *JMM,
@@ -158,7 +158,7 @@ public:
void runJITOnFunction(Function *F, MachineCodeInfo *MCI = 0);
private:
- static MachineCodeEmitter *createEmitter(JIT &J, JITMemoryManager *JMM);
+ static JITCodeEmitter *createEmitter(JIT &J, JITMemoryManager *JMM);
void registerMachineCodeInfo(MachineCodeInfo *MCI);
void runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked);
void updateFunctionStub(Function *F);
diff --git a/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp b/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp
index bb2f92bb02..e101ef371e 100644
--- a/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp
+++ b/lib/ExecutionEngine/JIT/JITDwarfEmitter.cpp
@@ -16,7 +16,7 @@
#include "JITDwarfEmitter.h"
#include "llvm/Function.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/CodeGen/MachineCodeEmitter.h"
+#include "llvm/CodeGen/JITCodeEmitter.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineLocation.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
@@ -34,7 +34,7 @@ JITDwarfEmitter::JITDwarfEmitter(JIT& theJit) : Jit(theJit) {}
unsigned char* JITDwarfEmitter::EmitDwarfTable(MachineFunction& F,
- MachineCodeEmitter& mce,
+ JITCodeEmitter& jce,
unsigned char* StartFunction,
unsigned char* EndFunction) {
const TargetMachine& TM = F.getTarget();
@@ -42,7 +42,7 @@ unsigned char* JITDwarfEmitter::EmitDwarfTable(MachineFunction& F,
needsIndirectEncoding = TM.getTargetAsmInfo()->getNeedsIndirectEncoding();
stackGrowthDirection = TM.getFrameInfo()->getStackGrowthDirection();
RI = TM.getRegisterInfo();
- MCE = &mce;
+ JCE = &jce;
unsigned char* ExceptionTable = EmitExceptionTable(&F, StartFunction,
EndFunction);
@@ -81,15 +81,15 @@ JITDwarfEmitter::EmitFrameMoves(intptr_t BaseLabelPtr,
}
intptr_t LabelPtr = 0;
- if (LabelID) LabelPtr = MCE->getLabelAddress(LabelID);
+ if (LabelID) LabelPtr = JCE->getLabelAddress(LabelID);
const MachineLocation &Dst = Move.getDestination();