llvm-6502/tools/lli/RecordingMemoryManager.h
Filip Pizlo 6eb43d2956 This threads SectionName through the allocateCodeSection/allocateDataSection APIs, both in C++ and C land.
It's useful for the memory managers that are allocating a section to know what the name of the section is.  
At a minimum, this is useful for low-level debugging - it's customary for JITs to be able to tell you what 
memory they allocated, and as part of any such dump, they should be able to tell you some meta-data about 
what each allocation is for.  This allows clients that supply their own memory managers to do this.  
Additionally, we also envision the SectionName being useful for passing meta-data from within LLVM to an LLVM 
client.

This changes both the C and C++ APIs, and all of the clients of those APIs within LLVM.  I'm assuming that 
it's safe to change the C++ API because that API is allowed to change.  I'm assuming that it's safe to change 
the C API because we haven't shipped the API in a release yet (LLVM 3.3 doesn't include the MCJIT memory 
management C API).



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191804 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-02 00:59:25 +00:00

84 lines
3.1 KiB
C++

//===- 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;
// 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);
public:
RecordingMemoryManager() {}
virtual ~RecordingMemoryManager();
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, StringRef SectionName);
uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID, StringRef SectionName,
bool IsReadOnly);
void *getPointerToNamedFunction(const std::string &Name,
bool AbortOnFailure = true);
bool finalizeMemory(std::string *ErrMsg) { return false; }
// 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