2010-11-17 16:06:43 +00:00
|
|
|
//===-- MCJIT.h - Class definition for the MCJIT ----------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_EXECUTIONENGINE_MCJIT_H
|
|
|
|
#define LLVM_LIB_EXECUTIONENGINE_MCJIT_H
|
|
|
|
|
2011-03-18 22:48:41 +00:00
|
|
|
#include "llvm/PassManager.h"
|
2010-11-17 16:06:43 +00:00
|
|
|
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
2011-03-22 01:06:42 +00:00
|
|
|
#include "llvm/ExecutionEngine/RuntimeDyld.h"
|
2010-11-17 16:06:43 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2012-10-02 21:18:39 +00:00
|
|
|
class ObjectImage;
|
|
|
|
|
2011-03-18 22:48:41 +00:00
|
|
|
// FIXME: This makes all kinds of horrible assumptions for the time being,
|
|
|
|
// like only having one module, not needing to worry about multi-threading,
|
|
|
|
// blah blah. Purely in get-it-up-and-limping mode for now.
|
|
|
|
|
2010-11-17 16:06:43 +00:00
|
|
|
class MCJIT : public ExecutionEngine {
|
2012-08-21 15:42:49 +00:00
|
|
|
MCJIT(Module *M, TargetMachine *tm, RTDyldMemoryManager *MemMgr,
|
|
|
|
bool AllocateGVsWithCode);
|
2011-03-18 22:48:41 +00:00
|
|
|
|
|
|
|
TargetMachine *TM;
|
|
|
|
MCContext *Ctx;
|
2011-04-04 23:04:39 +00:00
|
|
|
RTDyldMemoryManager *MemMgr;
|
2012-08-07 18:33:00 +00:00
|
|
|
RuntimeDyld Dyld;
|
2011-03-18 22:48:41 +00:00
|
|
|
|
2012-08-07 18:33:00 +00:00
|
|
|
// FIXME: Add support for multiple modules
|
|
|
|
bool isCompiled;
|
2011-03-18 22:48:41 +00:00
|
|
|
Module *M;
|
2012-10-02 21:18:39 +00:00
|
|
|
OwningPtr<ObjectImage> LoadedObject;
|
2011-03-18 22:48:41 +00:00
|
|
|
|
2010-11-17 16:06:43 +00:00
|
|
|
public:
|
|
|
|
~MCJIT();
|
|
|
|
|
|
|
|
/// @name ExecutionEngine interface implementation
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
virtual void *getPointerToBasicBlock(BasicBlock *BB);
|
|
|
|
|
|
|
|
virtual void *getPointerToFunction(Function *F);
|
|
|
|
|
|
|
|
virtual void *recompileAndRelinkFunction(Function *F);
|
|
|
|
|
|
|
|
virtual void freeMachineCodeForFunction(Function *F);
|
|
|
|
|
|
|
|
virtual GenericValue runFunction(Function *F,
|
|
|
|
const std::vector<GenericValue> &ArgValues);
|
|
|
|
|
2011-03-22 18:05:27 +00:00
|
|
|
/// getPointerToNamedFunction - This method returns the address of the
|
|
|
|
/// specified function by using the dlsym function call. As such it is only
|
|
|
|
/// useful for resolving library symbols, not code generated symbols.
|
|
|
|
///
|
|
|
|
/// If AbortOnFailure is false and no function with the given name is
|
|
|
|
/// found, this function silently returns a null pointer. Otherwise,
|
|
|
|
/// it prints a message to stderr and aborts.
|
|
|
|
///
|
2012-01-05 21:16:14 +00:00
|
|
|
virtual void *getPointerToNamedFunction(const std::string &Name,
|
|
|
|
bool AbortOnFailure = true);
|
2012-03-28 21:46:36 +00:00
|
|
|
|
2012-01-16 23:50:55 +00:00
|
|
|
/// mapSectionAddress - map a section to its target address space value.
|
|
|
|
/// Map the address of a JIT section as returned from the memory manager
|
|
|
|
/// to the address in the target process as the running code will see it.
|
|
|
|
/// This is the address which will be used for relocation resolution.
|
2012-09-13 21:50:06 +00:00
|
|
|
virtual void mapSectionAddress(const void *LocalAddress,
|
|
|
|
uint64_t TargetAddress) {
|
2012-01-16 23:50:55 +00:00
|
|
|
Dyld.mapSectionAddress(LocalAddress, TargetAddress);
|
|
|
|
}
|
|
|
|
|
2010-11-17 16:06:43 +00:00
|
|
|
/// @}
|
|
|
|
/// @name (Private) Registration Interfaces
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
static void Register() {
|
|
|
|
MCJITCtor = createJIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ExecutionEngine *createJIT(Module *M,
|
|
|
|
std::string *ErrorStr,
|
|
|
|
JITMemoryManager *JMM,
|
|
|
|
bool GVsWithCode,
|
2011-05-13 21:51:29 +00:00
|
|
|
TargetMachine *TM);
|
2010-11-17 16:06:43 +00:00
|
|
|
|
|
|
|
// @}
|
2012-08-07 18:33:00 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/// emitObject -- Generate a JITed object in memory from the specified module
|
|
|
|
/// Currently, MCJIT only supports a single module and the module passed to
|
|
|
|
/// this function call is expected to be the contained module. The module
|
|
|
|
/// is passed as a parameter here to prepare for multiple module support in
|
|
|
|
/// the future.
|
|
|
|
void emitObject(Module *M);
|
2010-11-17 16:06:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|