如何将LLVM IR文件转为RISC-V64汇编?llc命令执行失败
将LLVM IR转换为RISC-V64汇编的问题解决
问题场景
在x86平台的Ubuntu 22.04系统下,执行命令./llc -march=riscv64 test.ll将LLVM IR文件转换为RISC-V64汇编时,出现以下错误:
'x86-64' is not a recognized processor for this target (ignoring processor) '+cx8' is not a recognized feature for this target (ignoring feature) '+fxsr' is not a recognized feature for this target (ignoring feature) '+mmx' is not a recognized feature for this target (ignoring feature) '+sse' is not a recognized feature for this target (ignoring feature) '+sse2' is not a recognized feature for this target (ignoring feature) '+x87' is not a recognized feature for this target (ignoring feature) 'x86-64' is not a recognized processor for this target (ignoring processor) '+cx8' is not a recognized feature for this target (ignoring feature) '+fxsr' is not a recognized feature for this target (ignoring feature) '+mmx' is not a recognized feature for this target (ignoring feature) '+sse' is not a recognized feature for this target (ignoring feature) '+sse2' is not a recognized feature for this target (ignoring feature) '+x87' is not a recognized feature for this target (ignoring feature) LLVM ERROR: RV64 target requires an RV64 CPU PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: ./llc -march=riscv64 test.ll 1. Running pass 'Function Pass Manager' on module 'test.ll'. 2. Running pass 'Expand large div/rem' on function '@main' #0 0x000056420e885d30 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./llc+0x3474d30) #1 0x000056420e8832fe SignalHandler(int) Signals.cpp:0:0 #2 0x00007f3a4f41f520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #3 0x00007f3a4f4739fc __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76 #4 0x00007f3a4f4739fc __pthread_kill_internal ./nptl/./nptl/pthread_kill.c:78:10 #5 0x00007f3a4f4739fc pthread_kill ./nptl/./nptl/pthread_kill.c:89:10 #6 0x00007f3a4f41f476 gsignal ./signal/../sysdeps/posix/raise.c:27:6 #7 0x00007f3a4f4057f3 abort ./stdlib/./stdlib/abort.c:81:7 #8 0x000056420ba042c4 llvm::RISCVISAInfo::updateCombination() (.cold) RISCVISAInfo.cpp:0:0 #9 0x000056420e7cdc6e (./llc+0x33bcc6e) #10 0x000056420d3d2936 llvm::RISCVFeatures::validate(llvm::Triple const&, llvm::FeatureBitset const&) (./llc+0x1fc1936) #11 0x000056420cb09ef8 llvm::RISCVSubtarget::initializeSubtargetDependencies(llvm::Triple const&, llvm::StringRef, llvm::StringRef, llvm::StringRef, llvm::StringRef) (./llc+0x16f8ef8) #12 0x000056420cb0a149 llvm::RISCVSubtarget::RISCVSubtarget(llvm::Triple const&, llvm::StringRef, llvm::StringRef, llvm::StringRef, llvm::StringRef, unsigned int, unsigned int, llvm::TargetMachine const&) (./llc+0x16f9149) #13 0x000056420cb0f525 llvm::RISCVTargetMachine::getSubtargetImpl(llvm::Function const&) const (./llc+0x16fe525) #14 0x000056420d85d6ec (anonymous namespace)::ExpandLargeDivRemLegacyPass::runOnFunction(llvm::Function&) ExpandLargeDivRem.cpp:0:0 #15 0x000056420ded2b8a llvm::FPPassManager::runOnFunction(llvm::Function&) (./llc+0x2ac1b8a) #16 0x000056420ded2d14 llvm::FPPassManager::runOnModule(llvm::Module&) (./llc+0x2ac1d14) #17 0x000056420ded3774 llvm::legacy::PassManagerImpl::run(llvm::Module&) (./llc+0x2ac2774) #18 0x000056420bb06fca compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0 #19 0x000056420ba15d2e main (./llc+0x604d2e) #20 0x00007f3a4f406d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #21 0x00007f3a4f406e40 call_init ./csu/../csu/libc-start.c:128:20 #22 0x00007f3a4f406e40 __libc_start_main ./csu/../csu/libc-start.c:379:5 #23 0x000056420bafe525 _start (./llc+0x6ed525) [1] 152291 IOT instruction (core dumped) ./llc -march=riscv64 test.ll
问题原因
- 核心错误:仅指定
-march=riscv64不足以让llc明确目标CPU配置,必须指定具体的RV64型号。 - x86特性报错:x86平台下的llc默认继承了x86架构的处理器特性,切换到RISC-V64目标时,这些特性无法被识别,导致警告。
解决方法
执行llc命令时,明确指定RV64的CPU型号,同时可附加所需的ISA扩展特性:
./llc -march=riscv64 -mcpu=rv64gc test.ll
-mcpu=rv64gc:指定通用的RV64GC CPU(包含RISC-V的I、M、A、F、D、C扩展),覆盖默认的x86配置。- 若需自定义特性,可使用
-mattr参数,例如:
./llc -march=riscv64 -mattr=+m,+a,+f,+d,+c test.ll
此命令直接指定启用乘法/除法、原子操作、单精度浮点、双精度浮点、压缩指令集等扩展。
内容的提问来源于stack exchange,提问作者侯华为
相关产品推荐
相关产品推荐

