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.”
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.
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.
llvm/lib/Analysis/ConstantFolding.cpp: If it is possible to constant fold your intrinsic, add support to it in the canConstantFoldCallTo and ConstantFoldCall functions.
llvm/test/*: Add test cases for your test cases to the test suite
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.
If you could revise
the fundmental principles of
computer system design
to improve security...
... what would you change?