1 #ifndef CPPAD_CG_LLVM_MODEL_LIBRARY_4_0_INCLUDED 2 #define CPPAD_CG_LLVM_MODEL_LIBRARY_4_0_INCLUDED 22 template<
class Base>
class LlvmModel;
32 llvm::Module* _module;
33 std::shared_ptr<llvm::LLVMContext> _context;
34 std::unique_ptr<llvm::ExecutionEngine> _executionEngine;
35 std::unique_ptr<llvm::legacy::FunctionPassManager> _fpm;
39 std::shared_ptr<llvm::LLVMContext> context) :
40 _module(module.get()),
46 _executionEngine.reset(EngineBuilder(std::move(module))
48 .setEngineKind(EngineKind::JIT)
50 .setVerifyModules(
true)
54 if (!_executionEngine.get()) {
55 throw CGException(
"Could not create ExecutionEngine: ", errStr);
58 _fpm.reset(
new llvm::legacy::FunctionPassManager(_module));
62 _fpm->doInitialization();
81 llvm::PassManagerBuilder builder;
83 builder.populateFunctionPassManager(*_fpm);
87 void*
loadFunction(
const std::string& functionName,
bool required =
true)
override {
88 llvm::Function* func = _module->getFunction(functionName);
89 if (func ==
nullptr) {
91 throw CGException(
"Unable to find function '", functionName,
"' in LLVM module");
97 llvm::raw_os_ostream os(std::cerr);
98 bool failed = llvm::verifyFunction(*func, &os);
100 throw CGException(
"Function '", functionName,
"' verification failed");
107 uint64_t fPtr = _executionEngine->getFunctionAddress(functionName);
108 if (fPtr == 0 && required) {
109 throw CGException(
"Unable to find function '", functionName,
"' in LLVM module");
void * loadFunction(const std::string &functionName, bool required=true) override
LlvmModelLibrary4_0(std::unique_ptr< llvm::Module > module, std::shared_ptr< llvm::LLVMContext > context)
virtual void preparePassManager()