Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed LLVM assembly or intrinsics in C program with Clang?

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?

like image 879
eonil Avatar asked Mar 12 '13 06:03

eonil


1 Answers

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.

like image 84
Oak Avatar answered Nov 12 '22 14:11

Oak