Intrinsics

Reference: Extending LLVM: Adding instructions, intrinsics, types, etc.

“Adding a new intrinsic function to LLVM is much easier than adding a new instruction. Almost all extensions to LLVM should start as an intrinsic function and then be turned into an instruction if warranted.”

  1. llvm/docs/LangRef.html: Document the intrinsic. Decide whether it is code generator specific and what the restrictions are. Talk to other people about it so that you are sure it’s a good idea.

  2. llvm/include/llvm/IR/Intrinsics*.td: Add an entry for your intrinsic. Describe its memory access characteristics for optimization (this controls whether it will be DCE’d, CSE’d, etc). If any arguments need to be immediates, these must be indicated with the ImmArg property. Note that any intrinsic using one of the llvm_any*_ty types for an argument or return type will be deemed by tblgen as overloaded and the corresponding suffix will be required on the intrinsic’s name.

  3. llvm/lib/Analysis/ConstantFolding.cpp: If it is possible to constant fold your intrinsic, add support to it in the canConstantFoldCallTo and ConstantFoldCall functions.

  4. llvm/test/*: Add test cases for your test cases to the test suite

  5. lib/Target/*/*.td: Once the intrinsic has been added to the system, you must add code generator support for it. Generally you must do the following steps: Add support to the .td file for the target(s) of your choice in lib/Target/*/*.td. This is usually a matter of adding a pattern to the .td file that matches the intrinsic, though it may obviously require adding the instructions you want to generate as well. There are lots of examples in the PowerPC and X86 backend to follow.

Created Aug 25, 2019 // Last Updated Aug 25, 2020

If you could revise
the fundmental principles of
computer system design
to improve security...

... what would you change?