Posts

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

Working with alias.scope and noalias metadata in LLVM

This post briefly talks about the ScopedNoAlias alias-analysis pass in LLVM. It demonstrates the code snippets to attach, read and remove the metadata related to the ScopedNoAlias alias-analysis pass. It also talks about how the metadata is interpreted by the ScopedNoAlias alias-analysis pass. The ScopedNoAlias alias-analysis pass in LLVM is used to determine whether a pair of pointers can alias with respect to the domains. A domain consists of multiple scopes and is defined by an id and an optional descriptive string. A scope consists of an id, a domain, and an optional descriptive string. The list of scopes can be specified using the alias.scope and noalias metadata. Metadata is essentially some additional information that is used by optimization passes. The alias.scope and noalias metadata can be attached to the load and store instructions. The ScopedNoAlias alias-analysis pass relies on the alias.scope and noalias metadata to infer the alias result for a given pair of pointers.