On 06/28/2017 07:33 AM, Sayantan Majumdar via llvm-dev
wrote:> 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
/include/llvm/IR//.
> 2. Added FooInstrInfo.td <https://pastebin.com/9LsXYGMR> in
/llvm/Target/Foo/.
> /
You need to replace fadd in the pattern you define in FooInstrInfo.td
with int_foo_sqrt_test.
-Tom> 3. Added case for /Intrinsic::foo_sqrt_test /in
/llvm/lib/Analysis/ConstantFolding.cpp#canConstantFoldCallTo(ImmutableCallSite,
const Function *)./
> /
> /
> /*Front-end:
> */
> 1. Added BuiltinsFoo.def <https://pastebin.com/kTXE3GRA> in
/include/clang/Basic/.
> /
> 2. Added namespace Foo in /include/clang/Basic/TargetBuiltins.h /like this
<https://pastebin.com/J18Vi2kV>.
> 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 likethis
<https://pastebin.com/hAD2tdjY>.
>
> /*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.
>
> /*Testing:
> */
> So basically what I'm trying to do here is, whenever there is a /fadd
/instruction 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
> <https://pastebin.com/XgKBwzcL>
> 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
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>