15

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?

eonil
  • 83,476
  • 81
  • 317
  • 516
  • 5
    Yes, it *should* allow it. No, it does not do it yet, sorry. – SK-logic Mar 12 '13 at 07:50
  • Which intrinsics? If you just want to use, say, ARM NEON intrinsics, [you can do that without resorting to inline assembly](http://blog.llvm.org/2010/04/arm-advanced-simd-neon-intrinsics-and.html). – rob mayoff Mar 12 '13 at 08:12
  • @robmayoff This is what I meant: http://llvm.org/docs/LangRef.html#intrinsic-functions – eonil Mar 12 '13 at 08:13
  • @SK-logic is this still the case currently? – Jay Apr 29 '20 at 10:57

1 Answers1

9

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.

Community
  • 1
  • 1
Oak
  • 26,231
  • 8
  • 93
  • 152
  • 2
    @Jay the pass is still there and enabled by default: https://llvm.org/doxygen/AlwaysInliner_8cpp_source.html - and there is still no support for LLVM IR asm { ... } – SK-logic Apr 29 '20 at 12:02