[llvm-dev] Writing simple intrinsic in clang (original) (raw)

Friedman, Eli via llvm-dev llvm-dev at lists.llvm.org
Tue Sep 25 11:12:01 PDT 2018


On 9/24/2018 6:47 AM, Павел Безбородов via llvm-dev wrote:

I want to write a simple backend-specific instrinsic that will just call an instruction. How should I do that?

Is this really not documented anywhere...?

Anyway, the basic steps:

  1. Add the builtin to the list of intrinsics for your target: include/llvm/IR/IntrinsicsYourTarget.td.  Use a GCCBuiltin for the corresponding C intrinisc name.
  2. Teach your target to lower the intrinsic to an instruction; you can usually just use the name of the intrinsic in a pattern in lib/Target/YourTarget/YourTargetInstrInfo.td.
  3. Add the builtin to include/clang/Basic/BuiltinsYourTarget.def

An example of an intrinsic implemented this way is int_arm_qadd8  in the ARM backend (corresponding to the C builtin __builtin_arm_qadd8); it should be straightforward to follow that example.

This approach assumes your intrinsic is simple: it returns at most one value, and all the parameter and return types are legal.  If that isn't true, you might need to write some C++ code to handle it in clang or in your backend.

Maybe we should add this as a section to http://llvm.org/docs/WritingAnLLVMBackend.html .

-Eli

-- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project



More information about the llvm-dev mailing list