Sayantan Majumdar via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 28 04:33:39 PDT 2017

Being new to LLVM, I am finding some difficulties in properly defining a
custom intrinsic (*foo_sqrt_test*). So far I have done the following steps:

*Back-end: *
1. Added IntrinsicsFoo.td <https://pastebin.com/psrUCNGH> in
2. Added FooInstrInfo.td <https://pastebin.com/9LsXYGMR> in
3. Added case for *Intrinsic::foo_sqrt_test *in
const Function *).*

1. Added BuiltinsFoo.def <https://pastebin.com/kTXE3GRA> in
2. Added namespace Foo in *include/clang/Basic/TargetBuiltins.h *like this
3. Added declaration for *EmitFooBuiltinExpr(unsigned BuiltinID, const
CallExpr *E)* in *clang/lib/CodeGen/CodeGenFunction.h*.
4. Defined above function in *clang/lib/CodeGen/*CGBuiltin.cpp like this

*Custom Pass: *I added a custom pass InsertInst.cpp
<https://pastebin.com/J7pSPEtR>  in *llvm/lib/Transforms/Insert.*

After making the above changes, I built the entire *llvm* project (along
with *clang*) using *ninja* and the build was successful.

So basically what I'm trying to do here is, whenever there is a *fadd
in the *IR *file, a floating point constant 5 will be added and the square
root of this new value will be taken to be as the final value to be
displayed. (This is working fine with the predefined Intrinsic::sqrt that
LLVM provides)
1. C file: test.c
2. IR file (test1.s <https://pastebin.com/yN3aBtFQ>) generated using:

*           $clang -c -emit-llvm test.c -o test.ll*

*           $llvm-dis < test.ll > test1.s *
3. IR file (test2.s <https://pastebin.com/tLNnqedf>) generated using:

*$opt -load ../build/lib/LLVMInsertInstruction.so -insertinst -o
test_opt.ll < test.ll           $llvm-dis < test_opt.ll > test2.s$lli
test.ll *is working fine.
*$lli test_opt.ll *is showing:

*LLVM ERROR: Cannot select: intrinsic %llvm.foo.foo_sqrt_test*
I cannot find any clue as to what other changes to be made. It would be
great if I am able to get some help regarding this issue. Thanks!


Sayantan Majumdar
Research Intern at RISE Lab,
Indian Institute of Technology Madras, Chennai
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170628/b59b22da/attachment.html>

More information about the llvm-dev mailing list