ldc-developers/ldc — pull request #226 by jerro (2012-11-05 01:20:56+00:00)
Title: Pragma llvm_inline_ir

This pull request adds pragma llvm_inline_ir, which allows you to use llvm assembly language from D. Here's a simple usage example:

```d
pragma(llvm_inline_ir)
R inlineIR(string s, R, P...)(P);

int add(int a, int b)
{
return inlineIR!(`
%r = add i32 %0, %1
ret i32 %r`, int)(a, b);
}
```

The code in this pull request wraps the string, passed as a template parameter, in braces and prepends "define", a return type and a parameter list to it. Parameter names are %0, %1, %2... . Then it uses llvm::ParseAssemblyString on it to generate an LLFunction. It appends "\nret void" to the input string if the return type is void. It also marks the generated function as alwaysinline.

I used pragma llvm_inline_ir in my fork of TurkeyMan's std.simd [here](https://github.com/jerro/phobos/blob/std.simd-use-llvm_inline_ir/std/simd.d#L517). I tested it with the tests [here]( https://github.com/jerro/std.simd-tests/blob/master/test.d) and it seems to work fine. A few tests still fail to compile, but that is not related to LDC or this feature. The tests that do compile all pass.