Just another follow-up, seems like ExecutionEngine is still not usable without editing CMakeLists, on my setup I had to edit CMakeLists.txt as well to get the example working.
Below is the modifications I made:
Modified Hello.cpp for testing:
bool runOnFunction(Function &F) override {
++HelloCounter;
std::string errStr;
EngineBuilder eb;
eb.setErrorStr(&errStr);
eb.setEngineKind(EngineKind::Kind::JIT);
ExecutionEngine* ee=eb.create();
errs()<<"ExecutionEngine:"<<ee<<" Error:"<<errStr<<"\n";
delete ee;
errs() << "Hello: ";
errs().write_escaped(F.getName()) << '\n';
return false;
}
Modified opt’s CMakeLists.txt:
set(LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
AggressiveInstCombine
Analysis
BitWriter
CodeGen
Core
MC
MCJIT
Object
OrcJIT
Interpreter
RuntimeDyld
Coroutines
IPO
IRReader
InstCombine
Instrumentation
MC
ObjCARCOpts
ScalarOpts
Support
Target
TransformUtils
Vectorize
Passes
ExecutionEngine
)
# Support plugins.
set(LLVM_NO_DEAD_STRIP 1)
add_llvm_tool(opt
AnalysisWrappers.cpp
BreakpointPrinter.cpp
Debugify.cpp
GraphPrinters.cpp
NewPMDriver.cpp
PassPrinters.cpp
PrintSCC.cpp
opt.cpp
DEPENDS
intrinsics_gen
)
export_executable_symbols(opt)
if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
target_link_libraries(opt PRIVATE Polly)
endif(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
target_link_libraries(opt PUBLIC LLVMExecutionEngine)
Modified opt’s LLVMBuild.txt:
;===- ./tools/opt/LLVMBuild.txt --------------------------------*- Conf -*--===;
;
; The LLVM Compiler Infrastructure
;
; This file is distributed under the University of Illinois Open Source
; License. See LICENSE.TXT for details.
;
;===------------------------------------------------------------------------===;
;
; This is an LLVMBuild description file for the components in this subdirectory.
;
; For more information on the LLVMBuild system, please see:
;
; http://llvm.org/docs/LLVMBuild.html
;
;===------------------------------------------------------------------------===;
[component_0]
type = Tool
name = opt
parent = Tools
required_libraries =
AsmParser
BitReader
BitWriter
CodeGen
IRReader
IPO
Instrumentation
Scalar
ObjCARC
Passes
ExecutionEngine
Interpreter
MCJIT
Native
NativeCodeGen
all-targets
On top of that I also added these lines to the beginning of main function in opt.cpp to force linking ExecutionEngine:
if(argc==-1){
EngineBuilder eb;
ExecutionEngine* ee=eb.create();
delete ee;
}
as well as force linking MCJIT and Interpreter by including headers in opt:
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/Interpreter.h"
#include "llvm/ExecutionEngine/MCJIT.h"
Moving cl::parseCommandLineOptions doesn’t seem to be related to the issue, my previous assumption was wrong.
Those modifications works at least on my setup with the following output:
λ : >>> bin/opt -load lib/LLVMHello.dylib hw.ll -hello
WARNING: You're attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the `-f' option.
Assertion failed: (M && "Module is null?"), function Init, file /Users/naville/Development/Hikari/lib/ExecutionEngine/ExecutionEngine.cpp, line 80.
Which is due to i didn’t initialize the EEBuilder properly, but at least the pass now loads and executes properly
Zhang