I am trying to create and append inline assembly expressions using an llvm pass. I am aware that I can use void appendModuleInlineAsm(StringRef Asm) , but I couldn't make it work.
Basically I want to append an instruction like this:
%X = call i32 asm "bswap $0", "=r,r"(i32 %Y)
Just before an other instruction. Has anybody tried it?
Basic idea:
a) You'll want a function pass to iterate over instructions, b) You'll want to iterate through the basic blocks and the instructions until you find the instruction you want to insert before, c) Do something like the below:
llvm::InlineAsm *IA =
llvm::InlineAsm::get(FTy, AsmString, Constraints, HasSideEffect,
/* IsAlignStack */ false, AsmDialect);
llvm::CallInst *Result = Builder.CreateCall(IA, Args);
Result->addAttribute(llvm::AttributeSet::FunctionIndex,
llvm::Attribute::NoUnwind);
which was liberally stolen from clang. Take a look at the docs to InlineAsm for the rest of the arguments and Builder is a DIBuilder instance. Make sure you set up the DIBuilder insertion point at the location you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With