diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CodeGen/ELFWriter.cpp | 10 | ||||
| -rw-r--r-- | llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp | 62 | ||||
| -rw-r--r-- | llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp | 1 | ||||
| -rw-r--r-- | llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/Target/X86/X86CodeEmitter.cpp | 2 | 
5 files changed, 29 insertions, 48 deletions
diff --git a/llvm/lib/CodeGen/ELFWriter.cpp b/llvm/lib/CodeGen/ELFWriter.cpp index 483c49059c4..69302a3605d 100644 --- a/llvm/lib/CodeGen/ELFWriter.cpp +++ b/llvm/lib/CodeGen/ELFWriter.cpp @@ -58,10 +58,6 @@ namespace llvm {      void startFunction(MachineFunction &F);      bool finishFunction(MachineFunction &F); -    void emitConstantPool(MachineConstantPool *MCP) { -      if (MCP->isEmpty()) return; -      assert(0 && "unimp"); -    }      void addRelocation(const MachineRelocation &MR) {        assert(0 && "relo not handled yet!");      } @@ -73,6 +69,12 @@ namespace llvm {        assert(0 && "JT not implementated yet!");        return 0;      } +     +    virtual void emitJumpTableInfo(MachineJumpTableInfo *MJTI, +                                   std::map<MachineBasicBlock*,uint64_t> &MBBM){ +      assert(0 && "JT not implementated yet!"); +    } +      /// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE!      void startFunctionStub(unsigned StubSize) { diff --git a/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp b/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp index 47b45a0daf5..7d8848e0698 100644 --- a/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp +++ b/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp @@ -54,8 +54,7 @@ namespace {    class JITMemoryManager {      std::list<sys::MemoryBlock> Blocks; // List of blocks allocated by the JIT      unsigned char *FunctionBase; // Start of the function body area -    unsigned char *ConstantBase; // Memory allocated for constant pools -    unsigned char *CurStubPtr, *CurFunctionPtr, *CurConstantPtr; +    unsigned char *CurStubPtr, *CurFunctionPtr;      unsigned char *GOTBase;      // Target Specific reserved memory      // centralize memory block allocation @@ -65,8 +64,6 @@ namespace {      ~JITMemoryManager();      inline unsigned char *allocateStub(unsigned StubSize); -    inline unsigned char *allocateConstant(unsigned ConstantSize, -                                           unsigned Alignment);      inline unsigned char *startFunctionBody();      inline void endFunctionBody(unsigned char *FunctionEnd); @@ -82,21 +79,15 @@ namespace {  JITMemoryManager::JITMemoryManager(bool useGOT) {    // Allocate a 16M block of memory for functions    sys::MemoryBlock FunBlock = getNewMemoryBlock(16 << 20); -  // Allocate a 1M block of memory for Constants -  sys::MemoryBlock ConstBlock = getNewMemoryBlock(1 << 20);    Blocks.push_front(FunBlock); -  Blocks.push_front(ConstBlock);    FunctionBase = reinterpret_cast<unsigned char*>(FunBlock.base()); -  ConstantBase = reinterpret_cast<unsigned char*>(ConstBlock.base());    // Allocate stubs backwards from the base, allocate functions forward    // from the base.    CurStubPtr = CurFunctionPtr = FunctionBase + 512*1024;// Use 512k for stubs -  CurConstantPtr = ConstantBase + ConstBlock.size(); -    // Allocate the GOT.    GOTBase = NULL;    if (useGOT) GOTBase = (unsigned char*)malloc(sizeof(void*) * 8192); @@ -119,23 +110,6 @@ unsigned char *JITMemoryManager::allocateStub(unsigned StubSize) {    return CurStubPtr;  } -unsigned char *JITMemoryManager::allocateConstant(unsigned ConstantSize, -                                                  unsigned Alignment) { -  // Reserve space and align pointer. -  CurConstantPtr -= ConstantSize; -  CurConstantPtr = -    (unsigned char *)((intptr_t)CurConstantPtr & ~((intptr_t)Alignment - 1)); - -  if (CurConstantPtr < ConstantBase) { -    //Either allocate another MB or 2xConstantSize -    sys::MemoryBlock ConstBlock = getNewMemoryBlock(2 * ConstantSize); -    ConstantBase = reinterpret_cast<unsigned char*>(ConstBlock.base()); -    CurConstantPtr = ConstantBase + ConstBlock.size(); -    return allocateConstant(ConstantSize, Alignment); -  } -  return CurConstantPtr; -} -  unsigned char *JITMemoryManager::startFunctionBody() {    // Round up to an even multiple of 8 bytes, this should eventually be target    // specific. @@ -414,10 +388,12 @@ public:      virtual void startFunction(MachineFunction &F);      virtual bool finishFunction(MachineFunction &F); -    virtual void emitConstantPool(MachineConstantPool *MCP); -    virtual void initJumpTableInfo(MachineJumpTableInfo *MJTI); +     +    void emitConstantPool(MachineConstantPool *MCP); +    void initJumpTableInfo(MachineJumpTableInfo *MJTI);      virtual void emitJumpTableInfo(MachineJumpTableInfo *MJTI,                                     std::map<MachineBasicBlock*,uint64_t> &MBBM); +          virtual void startFunctionStub(unsigned StubSize);      virtual void* finishFunctionStub(const Function *F); @@ -471,10 +447,16 @@ void *JITEmitter::getPointerToGlobal(GlobalValue *V, void *Reference,  void JITEmitter::startFunction(MachineFunction &F) {    BufferBegin = CurBufferPtr = MemMgr.startFunctionBody(); -  TheJIT->updateGlobalMapping(F.getFunction(), BufferBegin);    /// FIXME: implement out of space handling correctly!    BufferEnd = (unsigned char*)(intptr_t)~0ULL; +   +  emitConstantPool(F.getConstantPool()); +  initJumpTableInfo(F.getJumpTableInfo()); + +  // About to start emitting the machine code for the function. +  // FIXME: align it? +  TheJIT->updateGlobalMapping(F.getFunction(), CurBufferPtr);  }  bool JITEmitter::finishFunction(MachineFunction &F) { @@ -548,10 +530,11 @@ void JITEmitter::emitConstantPool(MachineConstantPool *MCP) {    unsigned Size = Constants.back().Offset;    Size += TheJIT->getTargetData().getTypeSize(Constants.back().Val->getType()); -  ConstantPoolBase = MemMgr.allocateConstant(Size,  -                                       1 << MCP->getConstantPoolAlignment()); +  ConstantPoolBase = allocateSpace(Size, 1 << MCP->getConstantPoolAlignment());    ConstantPool = MCP; -   + +  if (ConstantPoolBase == 0) return;  // Buffer overflow. +    // Initialize the memory for all of the constant pool entries.    for (unsigned i = 0, e = Constants.size(); i != e; ++i) {      void *CAddr = (char*)ConstantPoolBase+Constants[i].Offset; @@ -563,22 +546,23 @@ void JITEmitter::initJumpTableInfo(MachineJumpTableInfo *MJTI) {    const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();    if (JT.empty()) return; -  unsigned Size = 0; -  unsigned EntrySize = MJTI->getEntrySize(); +  unsigned NumEntries = 0;    for (unsigned i = 0, e = JT.size(); i != e; ++i) -    Size += JT[i].MBBs.size() * EntrySize; -   +    NumEntries += JT[i].MBBs.size(); + +  unsigned EntrySize = MJTI->getEntrySize(); +    // Just allocate space for all the jump tables now.  We will fix up the actual    // MBB entries in the tables after we emit the code for each block, since then    // we will know the final locations of the MBBs in memory.    JumpTable = MJTI; -  JumpTableBase = MemMgr.allocateConstant(Size, MJTI->getAlignment()); +  JumpTableBase = allocateSpace(NumEntries * EntrySize, MJTI->getAlignment());  }  void JITEmitter::emitJumpTableInfo(MachineJumpTableInfo *MJTI,                                     std::map<MachineBasicBlock*,uint64_t> &MBBM){    const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables(); -  if (JT.empty()) return; +  if (JT.empty() || JumpTableBase == 0) return;    unsigned Offset = 0;    unsigned EntrySize = MJTI->getEntrySize(); diff --git a/llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp b/llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp index a04cd37adce..1c3398ea07a 100644 --- a/llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp +++ b/llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp @@ -81,7 +81,6 @@ bool AlphaCodeEmitter::runOnMachineFunction(MachineFunction &MF) {      BasicBlockAddrs.clear();      MCE.startFunction(MF); -    MCE.emitConstantPool(MF.getConstantPool());      for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)        emitBasicBlock(*I);    } while (MCE.finishFunction(MF)); diff --git a/llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp b/llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp index 6fe68292080..a01ae99df18 100644 --- a/llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp +++ b/llvm/lib/Target/PowerPC/PPCCodeEmitter.cpp @@ -90,8 +90,6 @@ bool PPCCodeEmitter::runOnMachineFunction(MachineFunction &MF) {      BBLocations.clear();      MCE.startFunction(MF); -    MCE.emitConstantPool(MF.getConstantPool()); -    MCE.initJumpTableInfo(MF.getJumpTableInfo());      for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); BB != E; ++BB)        emitBasicBlock(*BB);      MCE.emitJumpTableInfo(MF.getJumpTableInfo(), BBLocations); diff --git a/llvm/lib/Target/X86/X86CodeEmitter.cpp b/llvm/lib/Target/X86/X86CodeEmitter.cpp index 175dae5ee16..20e17d0dbf5 100644 --- a/llvm/lib/Target/X86/X86CodeEmitter.cpp +++ b/llvm/lib/Target/X86/X86CodeEmitter.cpp @@ -86,8 +86,6 @@ bool Emitter::runOnMachineFunction(MachineFunction &MF) {      BasicBlockAddrs.clear();      MCE.startFunction(MF); -    MCE.emitConstantPool(MF.getConstantPool()); -    MCE.initJumpTableInfo(MF.getJumpTableInfo());      for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)        emitBasicBlock(*I);      MCE.emitJumpTableInfo(MF.getJumpTableInfo(), BasicBlockAddrs);  | 

