2012-09-06 00:50:34 +08:00
|
|
|
//===- RecordingMemoryManager.h - LLI MCJIT recording memory manager ------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This memory manager allocates local storage and keeps a record of each
|
|
|
|
// allocation. Iterators are provided for all data and code allocations.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef RECORDINGMEMORYMANAGER_H
|
|
|
|
#define RECORDINGMEMORYMANAGER_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ExecutionEngine/JITMemoryManager.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/Memory.h"
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class RecordingMemoryManager : public JITMemoryManager {
|
|
|
|
public:
|
|
|
|
typedef std::pair<sys::MemoryBlock, unsigned> Allocation;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SmallVector<Allocation, 16> AllocatedDataMem;
|
|
|
|
SmallVector<Allocation, 16> AllocatedCodeMem;
|
|
|
|
|
2013-02-26 07:00:19 +08:00
|
|
|
// FIXME: This is part of a work around to keep sections near one another
|
|
|
|
// when MCJIT performs relocations after code emission but before
|
|
|
|
// the generated code is moved to the remote target.
|
|
|
|
sys::MemoryBlock Near;
|
|
|
|
sys::MemoryBlock allocateSection(uintptr_t Size);
|
|
|
|
|
2012-09-06 00:50:34 +08:00
|
|
|
public:
|
|
|
|
RecordingMemoryManager() {}
|
2013-01-24 22:12:12 +08:00
|
|
|
virtual ~RecordingMemoryManager();
|
2012-09-06 00:50:34 +08:00
|
|
|
|
|
|
|
typedef SmallVectorImpl<Allocation>::const_iterator const_data_iterator;
|
|
|
|
typedef SmallVectorImpl<Allocation>::const_iterator const_code_iterator;
|
|
|
|
|
|
|
|
const_data_iterator data_begin() const { return AllocatedDataMem.begin(); }
|
|
|
|
const_data_iterator data_end() const { return AllocatedDataMem.end(); }
|
|
|
|
const_code_iterator code_begin() const { return AllocatedCodeMem.begin(); }
|
|
|
|
const_code_iterator code_end() const { return AllocatedCodeMem.end(); }
|
|
|
|
|
|
|
|
uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
|
|
|
|
unsigned SectionID);
|
|
|
|
|
|
|
|
uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
|
2012-11-16 07:50:01 +08:00
|
|
|
unsigned SectionID, bool IsReadOnly);
|
2012-09-06 00:50:34 +08:00
|
|
|
|
|
|
|
void *getPointerToNamedFunction(const std::string &Name,
|
|
|
|
bool AbortOnFailure = true);
|
2012-11-16 07:50:01 +08:00
|
|
|
|
2013-05-17 18:01:46 +08:00
|
|
|
bool finalizeMemory(std::string *ErrMsg) { return false; }
|
2012-11-16 07:50:01 +08:00
|
|
|
|
2012-09-06 00:50:34 +08:00
|
|
|
// The following obsolete JITMemoryManager calls are stubbed out for
|
|
|
|
// this model.
|
|
|
|
void setMemoryWritable();
|
|
|
|
void setMemoryExecutable();
|
|
|
|
void setPoisonMemory(bool poison);
|
|
|
|
void AllocateGOT();
|
|
|
|
uint8_t *getGOTBase() const;
|
|
|
|
uint8_t *startFunctionBody(const Function *F, uintptr_t &ActualSize);
|
|
|
|
uint8_t *allocateStub(const GlobalValue* F, unsigned StubSize,
|
|
|
|
unsigned Alignment);
|
|
|
|
void endFunctionBody(const Function *F, uint8_t *FunctionStart,
|
|
|
|
uint8_t *FunctionEnd);
|
|
|
|
uint8_t *allocateSpace(intptr_t Size, unsigned Alignment);
|
|
|
|
uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment);
|
|
|
|
void deallocateFunctionBody(void *Body);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|