How to embed LLVM assembly or intrinsics in C prog

2019-01-23 17:01发布

问题:

C compilers allows to embed assembly code in a C program.

I am pretty sure that Clang should allow embedding LLVM assembly or intrinsic code in C program. How can I embed LLVM assembly in C code?

回答1:

Right now you can't.

You can, however, write an LLVM assembly function separately in its own file, mark it as alwaysinline, then compile it with the rest of your files - this should get you the same result. See this related question on how to first compile your C files to IR and then link them together.

You can even compile the files separately and make sure you perform link-time optimization (LTO), should do the same thing.