[LLHD] Add option to specify shared libs to load in llhd-sim (#789)

This adds a -shared-libs option to llhd-sim that is analogous to the
same option for mlir-cpu-runner. If specified, those libraries are
passed to the ExecutionEngine to dynamically load and link.
This commit is contained in:
mikeurbach 2021-03-19 08:10:36 -06:00 committed by GitHub
parent e5f2c74583
commit cce113ea55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 34 additions and 29 deletions

View File

@ -60,12 +60,6 @@ jobs:
cxx: clang++
- cc: gcc
cxx: g++
exclude:
# We can't build with GCC+sharedlibs and succesfully run the tests.
# See issue https://github.com/llvm/circt/issues/708
- build-shared: ON
compiler:
cc: gcc
steps:
- name: Configure Environment

View File

@ -40,7 +40,7 @@ public:
llvm::raw_ostream &out, ModuleOp module,
llvm::function_ref<mlir::LogicalResult(mlir::ModuleOp)> mlirTransformer,
llvm::function_ref<llvm::Error(llvm::Module *)> llvmTransformer,
std::string root, int mode);
std::string root, int mode, ArrayRef<StringRef> sharedLibPaths);
/// Default destructor
~Engine();

View File

@ -27,7 +27,7 @@ Engine::Engine(
llvm::raw_ostream &out, ModuleOp module,
llvm::function_ref<mlir::LogicalResult(mlir::ModuleOp)> mlirTransformer,
llvm::function_ref<llvm::Error(llvm::Module *)> llvmTransformer,
std::string root, int mode)
std::string root, int mode, ArrayRef<StringRef> sharedLibPaths)
: out(out), root(root), traceMode(mode) {
state = std::make_unique<State>();
state->root = root + '.' + root;
@ -52,8 +52,10 @@ Engine::Engine(
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
auto maybeEngine =
mlir::ExecutionEngine::create(this->module, nullptr, llvmTransformer);
auto maybeEngine = mlir::ExecutionEngine::create(
this->module, nullptr, llvmTransformer,
/*jitCodeGenOptLevel=*/llvm::None, /*sharedLibPaths=*/sharedLibPaths);
assert(maybeEngine && "failed to create JIT");
engine = std::move(*maybeEngine);
}

View File

@ -14,14 +14,11 @@ set(CIRCT_TEST_DEPENDS
circt-translate
handshake-runner
firtool
llhd-sim
mlir-opt
mlir-cpu-runner
)
if(NOT WIN32)
list(APPEND CIRCT_TEST_DEPENDS llhd-sim)
endif()
add_lit_testsuite(check-circt "Running the CIRCT regression tests"
${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${CIRCT_TEST_DEPENDS}

View File

@ -1,4 +1,4 @@
// RUN: llhd-sim %s | FileCheck %s
// RUN: llhd-sim %s -shared-libs=%shlibdir/libcirct-llhd-signals-runtime-wrappers%shlibext | FileCheck %s
// CHECK: 0ps 0d 0e root/bool 0x01
// CHECK-NEXT: 0ps 0d 0e root/fair 0xff00

View File

@ -1,4 +1,4 @@
// RUN: llhd-sim %s | FileCheck %s
// RUN: llhd-sim %s -shared-libs=%shlibdir/libcirct-llhd-signals-runtime-wrappers%shlibext | FileCheck %s
// CHECK: 0ps 0d 0e root/sig[0] 0xffff
// CHECK-NEXT: 0ps 0d 0e root/sig[1] 0xffff

View File

@ -1,4 +1,4 @@
// RUN: llhd-sim %s | FileCheck %s
// RUN: llhd-sim %s -shared-libs=%shlibdir/libcirct-llhd-signals-runtime-wrappers%shlibext | FileCheck %s
// CHECK: 0ps 0d 0e root/sameByte 0xffffffff
// CHECK-NEXT: 0ps 0d 0e root/spanBytes 0xffffffff

View File

@ -1,8 +1,8 @@
// RUN: llhd-sim %s -T 5000 --trace-format=full | FileCheck %s --check-prefix=FULL
// RUN: llhd-sim %s -T 5000 --trace-format=reduced | FileCheck %s --check-prefix=REDUCED
// RUN: llhd-sim %s -T 5000 --trace-format=merged | FileCheck %s --check-prefix=MERGED
// RUN: llhd-sim %s -T 5000 --trace-format=merged-reduce | FileCheck %s --check-prefix=MERGEDRED
// RUN: llhd-sim %s -T 5000 --trace-format=named-only | FileCheck %s --check-prefix=NAMED
// RUN: llhd-sim %s -T 5000 --trace-format=full -shared-libs=%shlibdir/libcirct-llhd-signals-runtime-wrappers%shlibext | FileCheck %s --check-prefix=FULL
// RUN: llhd-sim %s -T 5000 --trace-format=reduced -shared-libs=%shlibdir/libcirct-llhd-signals-runtime-wrappers%shlibext | FileCheck %s --check-prefix=REDUCED
// RUN: llhd-sim %s -T 5000 --trace-format=merged -shared-libs=%shlibdir/libcirct-llhd-signals-runtime-wrappers%shlibext | FileCheck %s --check-prefix=MERGED
// RUN: llhd-sim %s -T 5000 --trace-format=merged-reduce -shared-libs=%shlibdir/libcirct-llhd-signals-runtime-wrappers%shlibext | FileCheck %s --check-prefix=MERGEDRED
// RUN: llhd-sim %s -T 5000 --trace-format=named-only -shared-libs=%shlibdir/libcirct-llhd-signals-runtime-wrappers%shlibext | FileCheck %s --check-prefix=NAMED
// FULL: 0ps 0d 0e root/1 0x01
// FULL: 0ps 0d 0e root/foo/s 0x01

View File

@ -1,4 +1,4 @@
// RUN: llhd-sim %s | FileCheck %s
// RUN: llhd-sim %s -shared-libs=%shlibdir/libcirct-llhd-signals-runtime-wrappers%shlibext | FileCheck %s
// CHECK: 0ps 0d 0e root/proc/toggle 0x01
// CHECK-NEXT: 0ps 0d 0e root/toggle 0x01

View File

@ -1,4 +1,4 @@
// RUN: llhd-sim %s -n 10 | FileCheck %s
// RUN: llhd-sim %s -n 10 -shared-libs=%shlibdir/libcirct-llhd-signals-runtime-wrappers%shlibext | FileCheck %s
// CHECK: 0ps 0d 0e root/clock 0x00
// CHECK-NEXT: 0ps 0d 0e root/sig1 0x00000000

View File

@ -1,4 +1,4 @@
// RUN: llhd-sim %s | FileCheck %s
// RUN: llhd-sim %s -shared-libs=%shlibdir/libcirct-llhd-signals-runtime-wrappers%shlibext | FileCheck %s
// CHECK: 0ps 0d 0e root/shl 0x01
// CHECK-NEXT: 0ps 0d 0e root/shr 0x08

View File

@ -1,4 +1,4 @@
// RUN: llhd-sim %s -n 10 -r Foo | FileCheck %s
// RUN: llhd-sim %s -n 10 -r Foo -shared-libs=%shlibdir/libcirct-llhd-signals-runtime-wrappers%shlibext | FileCheck %s
// CHECK: 0ps 0d 0e Foo/toggle 0x00
// CHECK-NEXT: 1000ps 0d 0e Foo/toggle 0x01

View File

@ -1,4 +1,4 @@
// RUN: llhd-sim %s | FileCheck %s
// RUN: llhd-sim %s -shared-libs=%shlibdir/libcirct-llhd-signals-runtime-wrappers%shlibext | FileCheck %s
// CHECK: 0ps 0d 0e root/proc/s1 0x00000000
// CHECK-NEXT: 0ps 0d 0e root/proc/s2 0x00000000

View File

@ -32,6 +32,7 @@ config.test_exec_root = os.path.join(config.circt_obj_root, 'test')
config.substitutions.append(('%PATH%', config.environment['PATH']))
config.substitutions.append(('%shlibext', config.llvm_shlib_ext))
config.substitutions.append(('%shlibdir', config.circt_shlib_dir))
llvm_config.with_system_environment(
['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP'])

View File

@ -34,6 +34,7 @@ config.mlir_tools_dir = "@MLIR_TOOLS_DIR@"
config.circt_src_root = "@CIRCT_SOURCE_DIR@"
config.circt_obj_root = "@CIRCT_BINARY_DIR@"
config.circt_tools_dir = "@CIRCT_TOOLS_DIR@"
config.circt_shlib_dir = "@LLVM_LIBRARY_OUTPUT_INTDIR@"
config.verilator_path = "@VERILATOR_PATH@"
config.esi_capnp = "@ESI_CAPNP@"

View File

@ -102,6 +102,13 @@ static cl::opt<TraceFormat> traceMode(
"instance and signals not having the default name '(sig)?[0-9]*'"),
clEnumValN(noTrace, "no-trace", "Don't dump a signal trace")));
static cl::list<std::string>
sharedLibs("shared-libs",
cl::desc("Libraries to link dynamically. Specify absolute path "
"to llhd-signals-runtime-wrappers for GCC or Windows. "
"Optional otherwise."),
cl::ZeroOrMore, cl::MiscFlags::CommaSeparated);
static int dumpLLVM(ModuleOp module, MLIRContext &context) {
if (dumpLLVMDialect) {
module.dump();
@ -174,10 +181,13 @@ int main(int argc, char **argv) {
return 0;
}
SmallVector<StringRef, 1> sharedLibPaths(sharedLibs.begin(),
sharedLibs.end());
llhd::sim::Engine engine(
output->os(), *module, &applyMLIRPasses,
makeOptimizingTransformer(optimizationLevel, 0, nullptr), root,
traceMode);
makeOptimizingTransformer(optimizationLevel, 0, nullptr), root, traceMode,
sharedLibPaths);
if (dumpLLVMDialect || dumpLLVMIR) {
return dumpLLVM(engine.getModule(), context);