1 #ifndef CPPAD_CG_LLVM_MODEL_LIBRARY_3_2_INCLUDED 2 #define CPPAD_CG_LLVM_MODEL_LIBRARY_3_2_INCLUDED 22 template<
class Base>
class LlvmModel;
32 llvm::Module* _module;
33 std::unique_ptr<llvm::LLVMContext> _context;
34 std::unique_ptr<llvm::ExecutionEngine> _executionEngine;
35 std::unique_ptr<llvm::FunctionPassManager> _fpm;
39 llvm::LLVMContext* context) :
46 _executionEngine.reset(EngineBuilder(_module)
48 .setEngineKind(EngineKind::JIT)
50 if (!_executionEngine.get()) {
51 throw CGException(
"Could not create ExecutionEngine: ", errStr);
54 _fpm.reset(
new llvm::FunctionPassManager(_module));
58 _fpm->doInitialization();
77 llvm::PassManagerBuilder builder;
79 builder.populateFunctionPassManager(*_fpm);
99 void*
loadFunction(
const std::string& functionName,
bool required =
true)
override {
100 llvm::Function* func = _module->getFunction(functionName);
101 if (func ==
nullptr) {
103 throw CGException(
"Unable to find function '", functionName,
"' in LLVM module");
109 llvm::verifyFunction(*func);
115 void *fPtr = _executionEngine->getPointerToFunction(func);
virtual void preparePassManager()
LlvmModelLibrary3_2(llvm::Module *module, llvm::LLVMContext *context)
void * loadFunction(const std::string &functionName, bool required=true) override