Home | History | Annotate | Download | only in lli
      1 //===- RecordingMemoryManager.h - LLI MCJIT recording memory manager ------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This memory manager allocates local storage and keeps a record of each
     11 // allocation. Iterators are provided for all data and code allocations.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef RECORDINGMEMORYMANAGER_H
     16 #define RECORDINGMEMORYMANAGER_H
     17 
     18 #include "llvm/ADT/SmallVector.h"
     19 #include "llvm/ExecutionEngine/JITMemoryManager.h"
     20 #include "llvm/Support/ErrorHandling.h"
     21 #include "llvm/Support/Memory.h"
     22 #include <utility>
     23 
     24 namespace llvm {
     25 
     26 class RecordingMemoryManager : public JITMemoryManager {
     27 public:
     28   typedef std::pair<sys::MemoryBlock, unsigned> Allocation;
     29 
     30 private:
     31   SmallVector<Allocation, 16> AllocatedDataMem;
     32   SmallVector<Allocation, 16> AllocatedCodeMem;
     33 
     34   // FIXME: This is part of a work around to keep sections near one another
     35   // when MCJIT performs relocations after code emission but before
     36   // the generated code is moved to the remote target.
     37   sys::MemoryBlock Near;
     38   sys::MemoryBlock allocateSection(uintptr_t Size);
     39 
     40 public:
     41   RecordingMemoryManager() {}
     42   virtual ~RecordingMemoryManager();
     43 
     44   typedef SmallVectorImpl<Allocation>::const_iterator const_data_iterator;
     45   typedef SmallVectorImpl<Allocation>::const_iterator const_code_iterator;
     46 
     47   const_data_iterator data_begin() const { return AllocatedDataMem.begin(); }
     48   const_data_iterator   data_end() const { return AllocatedDataMem.end(); }
     49   const_code_iterator code_begin() const { return AllocatedCodeMem.begin(); }
     50   const_code_iterator   code_end() const { return AllocatedCodeMem.end(); }
     51 
     52   uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
     53                                        unsigned SectionID);
     54 
     55   uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
     56                                        unsigned SectionID, bool IsReadOnly);
     57 
     58   void *getPointerToNamedFunction(const std::string &Name,
     59                                   bool AbortOnFailure = true);
     60 
     61   bool applyPermissions(std::string *ErrMsg) { return false; }
     62 
     63   // The following obsolete JITMemoryManager calls are stubbed out for
     64   // this model.
     65   void setMemoryWritable();
     66   void setMemoryExecutable();
     67   void setPoisonMemory(bool poison);
     68   void AllocateGOT();
     69   uint8_t *getGOTBase() const;
     70   uint8_t *startFunctionBody(const Function *F, uintptr_t &ActualSize);
     71   uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize,
     72                         unsigned Alignment);
     73   void endFunctionBody(const Function *F, uint8_t *FunctionStart,
     74                        uint8_t *FunctionEnd);
     75   uint8_t *allocateSpace(intptr_t Size, unsigned Alignment);
     76   uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment);
     77   void deallocateFunctionBody(void *Body);
     78   uint8_t* startExceptionTable(const Function* F, uintptr_t &ActualSize);
     79   void endExceptionTable(const Function *F, uint8_t *TableStart,
     80                          uint8_t *TableEnd, uint8_t* FrameRegister);
     81   void deallocateExceptionTable(void *ET);
     82 
     83 };
     84 
     85 } // end namespace llvm
     86 
     87 #endif
     88