I get an obj file by lowering mlir. This is my lower pipline.
@${MLIR_OPT} ./test.mlir \
-pass-pipeline="builtin.module(func.func(tosa-to-linalg-named),func.func(tosa-to-linalg),func.func(tosa-to-tensor),func.func(tosa-to-arith))" | \
${MLIR_OPT} \
--arith-expand \
--empty-tensor-to-alloc-tensor \
--linalg-bufferize \
--convert-linalg-to-affine-loops \
--affine-loop-fusion \
--affine-parallelize \
--lower-affine \
--convert-scf-to-openmp \
--func-bufferize \
--arith-bufferize \
--tensor-bufferize \
--finalizing-bufferize \
--convert-vector-to-scf \
--expand-strided-metadata \
--convert-vector-to-llvm \
--memref-expand \
--arith-expand \
--convert-arith-to-llvm \
--finalize-memref-to-llvm \
--convert-scf-to-cf \
--convert-openmp-to-llvm \
--convert-arith-to-llvm \
--convert-math-to-llvm \
--convert-math-to-libm \
--llvm-request-c-wrappers \
--convert-func-to-llvm \
--reconcile-unrealized-casts | \
${MLIR_TRANSLATE} \
-mlir-to-llvmir | \
${LLVM_AS} | \
${LLC} -filetype=obj --relocation-model=pic ${OPT_FLAG} -o test.o
When I link this test.o, I get some errors.
LLVMDialectModule:(.text+0x3c738c): undefined reference to `__kmpc_global_thread_num'
/usr/bin/ld: LLVMDialectModule:(.text+0x3c73dc): undefined reference to `__kmpc_for_static_init_8u'
/usr/bin/ld: LLVMDialectModule:(.text+0x3c742d): undefined reference to `__kmpc_for_static_fini'
/usr/bin/ld: LLVMDialectModule:(.text+0x3c7439): undefined reference to `__kmpc_global_thread_num'
/usr/bin/ld: LLVMDialectModule:(.text+0x3c7447): undefined reference to `__kmpc_barrier'
/usr/bin/ld: LLVMDialectModule:(.text+0x3c747e): undefined reference to `__kmpc_global_thread_num'
/usr/bin/ld: LLVMDialectModule:(.text+0x3c756b): undefined reference to `__kmpc_fork_call'
My CMAKELists.txt is as follows.
add_executable(test test_run.cc llama.o)
find_package(OpenMP REQUIRED)
add_compile_options(${OpenMP_CXX_FLAGS})
target_link_libraries(test mlir_c_runner_utils OpenMP::OpenMP_CXX)
It seems lack some libraries to link. But I have no idea. Thank you for your help.