Home > database >  How to output ARM V8 assembly from LLVM IR?
How to output ARM V8 assembly from LLVM IR?

Time:02-13

I have this C file:

int mult() {
  int a =5;
  int b = 3;
  int c = a * b;
  return c;
}

I compile it to LLVM IR like this:

$ clang -emit-llvm -S multiply.c -o multiply.ll

I then compile it to various x86 assemblies like this:

$ llc --filetype asm -o multiply.apple.s --aarch64-neon-syntax=apple multiply.ll
$ llc --filetype asm -o multiply.intel.s --x86-asm-syntax=intel multiply.ll

How do I output ARM V8 assembly? Is there any way to convert a C file to output ARM V8 assembly, even without LLVM IR if LLVM IR can't do it? I don't see it in the llc docs for example.

CodePudding user response:

llc -march=aarch64 multiply.ll -o multiply.s will do it.

However, you shouldn't actually do that because the translation from C to LLVM IR is target-dependent. Simple things will work and complex programs will break in seemingly impossible ways.

Instead, go directly from C to your target with clang -target arm64. As your programs get more complicated, such as using system headers, you'll need to have an SDK matching the target platform installed. Even #include <stdlib.h> is very different on two platforms.

  • Related