#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/ExecutionEngine/JITEventListener.h"
#include "llvm/ExecutionEngine/ObjectCache.h"
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/TargetParser/Host.h"
#include <cmath>
#include <cstring>
#include <mutex>
usingnamespacellvm;
#define DEBUG_TYPE …
STATISTIC(NumInitBytes, "Number of bytes of global vars initialized");
STATISTIC(NumGlobals , "Number of global vars initialized");
ExecutionEngine *(*ExecutionEngine::MCJITCtor)(
std::unique_ptr<Module> M, std::string *ErrorStr,
std::shared_ptr<MCJITMemoryManager> MemMgr,
std::shared_ptr<LegacyJITSymbolResolver> Resolver,
std::unique_ptr<TargetMachine> TM) = …;
ExecutionEngine *(*ExecutionEngine::InterpCtor)(std::unique_ptr<Module> M,
std::string *ErrorStr) = …;
void JITEventListener::anchor() { … }
void ObjectCache::anchor() { … }
void ExecutionEngine::Init(std::unique_ptr<Module> M) { … }
ExecutionEngine::ExecutionEngine(std::unique_ptr<Module> M)
: … { … }
ExecutionEngine::ExecutionEngine(DataLayout DL, std::unique_ptr<Module> M)
: … { … }
ExecutionEngine::~ExecutionEngine() { … }
namespace {
class GVMemoryBlock final : public CallbackVH { … };
}
char *ExecutionEngine::getMemoryForGV(const GlobalVariable *GV) { … }
void ExecutionEngine::addObjectFile(std::unique_ptr<object::ObjectFile> O) { … }
void
ExecutionEngine::addObjectFile(object::OwningBinary<object::ObjectFile> O) { … }
void ExecutionEngine::addArchive(object::OwningBinary<object::Archive> A) { … }
bool ExecutionEngine::removeModule(Module *M) { … }
Function *ExecutionEngine::FindFunctionNamed(StringRef FnName) { … }
GlobalVariable *ExecutionEngine::FindGlobalVariableNamed(StringRef Name, bool AllowInternal) { … }
uint64_t ExecutionEngineState::RemoveMapping(StringRef Name) { … }
std::string ExecutionEngine::getMangledName(const GlobalValue *GV) { … }
void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) { … }
void ExecutionEngine::addGlobalMapping(StringRef Name, uint64_t Addr) { … }
void ExecutionEngine::clearAllGlobalMappings() { … }
void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) { … }
uint64_t ExecutionEngine::updateGlobalMapping(const GlobalValue *GV,
void *Addr) { … }
uint64_t ExecutionEngine::updateGlobalMapping(StringRef Name, uint64_t Addr) { … }
uint64_t ExecutionEngine::getAddressToGlobalIfAvailable(StringRef S) { … }
void *ExecutionEngine::getPointerToGlobalIfAvailable(StringRef S) { … }
void *ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) { … }
const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) { … }
namespace {
class ArgvArray { … };
}
void *ArgvArray::reset(LLVMContext &C, ExecutionEngine *EE,
const std::vector<std::string> &InputArgv) { … }
void ExecutionEngine::runStaticConstructorsDestructors(Module &module,
bool isDtors) { … }
void ExecutionEngine::runStaticConstructorsDestructors(bool isDtors) { … }
#ifndef NDEBUG
static bool isTargetNullPtr(ExecutionEngine *EE, void *Loc) {
unsigned PtrSize = EE->getDataLayout().getPointerSize();
for (unsigned i = 0; i < PtrSize; ++i)
if (*(i + (uint8_t*)Loc))
return false;
return true;
}
#endif
int ExecutionEngine::runFunctionAsMain(Function *Fn,
const std::vector<std::string> &argv,
const char * const * envp) { … }
EngineBuilder::EngineBuilder() : … { … }
EngineBuilder::EngineBuilder(std::unique_ptr<Module> M)
: … { … }
EngineBuilder::~EngineBuilder() = default;
EngineBuilder &EngineBuilder::setMCJITMemoryManager(
std::unique_ptr<RTDyldMemoryManager> mcjmm) { … }
EngineBuilder&
EngineBuilder::setMemoryManager(std::unique_ptr<MCJITMemoryManager> MM) { … }
EngineBuilder &
EngineBuilder::setSymbolResolver(std::unique_ptr<LegacyJITSymbolResolver> SR) { … }
ExecutionEngine *EngineBuilder::create(TargetMachine *TM) { … }
void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) { … }
GenericValue ExecutionEngine::getConstantValue(const Constant *C) { … }
void ExecutionEngine::StoreValueToMemory(const GenericValue &Val,
GenericValue *Ptr, Type *Ty) { … }
void ExecutionEngine::LoadValueFromMemory(GenericValue &Result,
GenericValue *Ptr,
Type *Ty) { … }
void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) { … }
void ExecutionEngine::emitGlobals() { … }
void ExecutionEngine::emitGlobalVariable(const GlobalVariable *GV) { … }