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 24namespace llvm { 25 26class RecordingMemoryManager : public JITMemoryManager { 27public: 28 typedef std::pair<sys::MemoryBlock, unsigned> Allocation; 29 30private: 31 SmallVector<Allocation, 16> AllocatedDataMem; 32 SmallVector<Allocation, 16> AllocatedCodeMem; 33 34public: 35 RecordingMemoryManager() {} 36 virtual ~RecordingMemoryManager() {} 37 38 typedef SmallVectorImpl<Allocation>::const_iterator const_data_iterator; 39 typedef SmallVectorImpl<Allocation>::const_iterator const_code_iterator; 40 41 const_data_iterator data_begin() const { return AllocatedDataMem.begin(); } 42 const_data_iterator data_end() const { return AllocatedDataMem.end(); } 43 const_code_iterator code_begin() const { return AllocatedCodeMem.begin(); } 44 const_code_iterator code_end() const { return AllocatedCodeMem.end(); } 45 46 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, 47 unsigned SectionID); 48 49 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, 50 unsigned SectionID); 51 52 void *getPointerToNamedFunction(const std::string &Name, 53 bool AbortOnFailure = true); 54 // The following obsolete JITMemoryManager calls are stubbed out for 55 // this model. 56 void setMemoryWritable(); 57 void setMemoryExecutable(); 58 void setPoisonMemory(bool poison); 59 void AllocateGOT(); 60 uint8_t *getGOTBase() const; 61 uint8_t *startFunctionBody(const Function *F, uintptr_t &ActualSize); 62 uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize, 63 unsigned Alignment); 64 void endFunctionBody(const Function *F, uint8_t *FunctionStart, 65 uint8_t *FunctionEnd); 66 uint8_t *allocateSpace(intptr_t Size, unsigned Alignment); 67 uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment); 68 void deallocateFunctionBody(void *Body); 69 uint8_t* startExceptionTable(const Function* F, uintptr_t &ActualSize); 70 void endExceptionTable(const Function *F, uint8_t *TableStart, 71 uint8_t *TableEnd, uint8_t* FrameRegister); 72 void deallocateExceptionTable(void *ET); 73 74}; 75 76} // end namespace llvm 77 78#endif 79