Posts

Showing posts from December, 2021

Adding intrinsics to LLVM’s backend

An LLVM intrinsic is a compiler’s built-in function. The compiler implements the functionality of an LLVM intrinsic in the most optimized way possible to avoid performance overheads. The names for the intrinsics are reserved, starting with the prefix “llvm.”. These functions are introduced at the LLVM IR level to hold additional information related to the program. These functions can only appear in a call or invoke instructions. The advantage of using an intrinsic is that the information present in it gets updated with every IR transformation. LLVM users can contribute to LLVM by adding custom intrinsics to its backend. One method of adding a custom intrinsic to LLVM’s backend is: 1) Create a new case in the switch case inside the function unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, ArrayRef ParamTys, const User *U) present in the file include/llvm/Analysis/TargetTransformInfoImpl.h. case Intrinsic::&lt intrinsic_name &gt: 2) Create a new case i