llvm-llc生成riscv64文件并测试的流程

llvm-llc生成riscv64文件并测试的流程

环境:

  • Ubuntu 18.04、Qemu 5.4、LLVM 11.0、GNU交叉编译工具链
  • Benchmark:Mibench:http://vhosts.eecs.umich.edu/mibench/
  • 配置过程见https://blog.csdn.net/qq_40037872/article/details/114667480

在上述环境下,修改LLVM中Codegen面相RISC-V的源码,并测试的流程如下:

  • 在Clion下修改LLVM源码并build

  • 找到测试文件——这里用Mibbench中的basicmath作为例子

    • cd  ~/llvmwd/Mibench/automotive/basicmath
      
  • 使用clang生成LLVM IR(.ll文件)

    • clang -O3 -emit-llvm --target=riscv64-unknown-linux-gnu --gcc-toolchain=/opt/riscv64 --sysroot=/opt/riscv64/sysroot/  -S *.c
      
  • 使用llc命令生成汇编文件

    • llc -O3 --march=riscv64 --enable-machine-outliner=always basicmath_small.ll
      llc -O3 --march=riscv64 --enable-machine-outliner=always basicmath_large.ll
      llc -O3 --march=riscv64 --enable-machine-outliner=always cubic.ll
      llc -O3 --march=riscv64 --enable-machine-outliner=always rad2deg.ll
      llc -O3 --march=riscv64 --enable-machine-outliner=always isqrt.ll
      
  • 使用clang命令进行汇编和链接

    • clang -O3 --target=riscv64-unknown-linux-gnu --gcc-toolchain=/opt/riscv64 --sysroot=/opt/riscv64/sysroot/ --static basicmath_large.s cubic.s isqrt.s rad2deg.s -lm
      
  • 打开risc64-linux文件夹并挂载文件系统到rootfs

    • sudo mount -o loop rootfs.img  ~/riscv64-linux/rootfs
      
  • 将生成的可执行文件复制到文件系统中

    • sudo cp ~/llvmwd/Mibench/automotive/basicmath/basicmath rootfs/root/
      
  • 取消挂载

    • sudo umount rootfs 
      
  • 启动qemu-riscv64并执行

  • qemu-system-riscv64 -M virt -m 256M -nographic -kernel linux/arch/riscv/boot/Image -drive file=rootfs.img,format=raw,id=hd0  -device v    irtio-blk-device,drive=hd0 -append "root=/dev/vda rw console=ttyS0"
    
    ./root/basicmath
    
  • 关闭qemu

  • poweroff
    
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值