LLVM 23.0.0git
Intrinsics.h
Go to the documentation of this file.
1//===- Intrinsics.h - LLVM Intrinsic Function Handling ----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines a set of enums which allow processing of intrinsic
10// functions. Values of these enum types are returned by
11// Function::getIntrinsicID.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_IR_INTRINSICS_H
16#define LLVM_IR_INTRINSICS_H
17
18#include "llvm/ADT/ArrayRef.h"
21#include <optional>
22#include <string>
23
24namespace llvm {
25
26class Type;
27class FunctionType;
28class Function;
29class LLVMContext;
30class Module;
31class AttributeList;
32class AttributeSet;
33class raw_ostream;
34class Constant;
35
36/// This namespace contains an enum with a value for every intrinsic/builtin
37/// function known by LLVM. The enum values are returned by
38/// Function::getIntrinsicID().
39namespace Intrinsic {
40 // Abstraction for the arguments of the noalias intrinsics
41 static const int NoAliasScopeDeclScopeArg = 0;
42
43 // Intrinsic ID type. This is an opaque typedef to facilitate splitting up
44 // the enum into target-specific enums.
45 typedef unsigned ID;
46
47 enum IndependentIntrinsics : unsigned {
48 not_intrinsic = 0, // Must be zero
49
50 // Get the intrinsic enums generated from Intrinsics.td
51#define GET_INTRINSIC_ENUM_VALUES
52#include "llvm/IR/IntrinsicEnums.inc"
53 };
54
55 /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
56 /// Note, this version is for intrinsics with no overloads. Use the other
57 /// version of getName if overloads are required.
58 LLVM_ABI StringRef getName(ID id);
59
60 /// Return the LLVM name for an intrinsic, without encoded types for
61 /// overloading, such as "llvm.ssa.copy".
62 LLVM_ABI StringRef getBaseName(ID id);
63
64 /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx" or
65 /// "llvm.ssa.copy.p0s_s.1". Note, this version of getName supports overloads.
66 /// This is less efficient than the StringRef version of this function. If no
67 /// overloads are required, it is safe to use this version, but better to use
68 /// the StringRef version. If one of the types is based on an unnamed type, a
69 /// function type will be computed. Providing FT will avoid this computation.
70 LLVM_ABI std::string getName(ID Id, ArrayRef<Type *> Tys, Module *M,
71 FunctionType *FT = nullptr);
72
73 /// Return the LLVM name for an intrinsic. This is a special version only to
74 /// be used by LLVMIntrinsicCopyOverloadedName. It only supports overloads
75 /// based on named types.
77
78 /// Return the function type for an intrinsic.
79 LLVM_ABI FunctionType *getType(LLVMContext &Context, ID id,
80 ArrayRef<Type *> Tys = {});
81
82 /// Returns true if the intrinsic can be overloaded.
83 LLVM_ABI bool isOverloaded(ID id);
84
85 /// Returns true if the intrinsic has pretty printed immediate arguments.
87
88 /// isTargetIntrinsic - Returns true if IID is an intrinsic specific to a
89 /// certain target. If it is a generic intrinsic false is returned.
91
92 LLVM_ABI ID lookupIntrinsicID(StringRef Name);
93
94 /// Return the attributes for an intrinsic.
96
97 /// Return the function attributes for an intrinsic.
99
100 /// Look up the Function declaration of the intrinsic \p id in the Module
101 /// \p M. If it does not exist, add a declaration and return it. Otherwise,
102 /// return the existing declaration.
103 ///
104 /// The \p Tys parameter is for intrinsics with overloaded types (e.g., those
105 /// using iAny, fAny, vAny, or pAny). For a declaration of an overloaded
106 /// intrinsic, Tys must provide exactly one type for each overloaded type in
107 /// the intrinsic.
109 ArrayRef<Type *> Tys = {});
110
111 /// Look up the Function declaration of the intrinsic \p IID in the Module
112 /// \p M. If it does not exist, add a declaration and return it. Otherwise,
113 /// return the existing declaration.
114 ///
115 /// This overload automatically resolves overloaded intrinsics based on the
116 /// provided return type and argument types. For non-overloaded intrinsics,
117 /// the return type and argument types are ignored.
118 ///
119 /// \param M - The module to get or insert the intrinsic declaration.
120 /// \param IID - The intrinsic ID.
121 /// \param RetTy - The return type of the intrinsic.
122 /// \param ArgTys - The argument types of the intrinsic.
124 ArrayRef<Type *> ArgTys);
125
126 /// Look up the Function declaration of the intrinsic \p id in the Module
127 /// \p M and return it if it exists. Otherwise, return nullptr. This version
128 /// supports non-overloaded intrinsics.
130
131 /// This version supports overloaded intrinsics.
134 FunctionType *FT = nullptr);
135
136 /// Map a Clang builtin name to an intrinsic ID.
138 StringRef BuiltinName);
139
140 /// Map a MS builtin name to an intrinsic ID.
142 StringRef BuiltinName);
143
144 /// Returns true if the intrinsic ID is for one of the "Constrained
145 /// Floating-Point Intrinsics".
147
148 /// Returns true if the intrinsic ID is for one of the "Constrained
149 /// Floating-Point Intrinsics" that take rounding mode metadata.
151
152 /// This is a type descriptor which explains the type requirements of an
153 /// intrinsic. This is returned by getIntrinsicInfoTableEntries.
184
185 union {
187 unsigned Float_Width;
192 };
193
194 // AK_% : Defined in Intrinsics.td
195 enum ArgKind {
196#define GET_INTRINSIC_ARGKIND
197#include "llvm/IR/IntrinsicEnums.inc"
198 };
199
214
215 // VecOfAnyPtrsToElt uses both an overloaded argument (for address space)
216 // and a reference argument (for matching vector width and element types)
217 unsigned getOverloadArgNumber() const {
219 return Argument_Info >> 16;
220 }
221 // OneNthEltsVecArguments uses both a divisor N and a reference argument for
222 // the full-width vector to match
223 unsigned getVectorDivisor() const {
225 return Argument_Info >> 16;
226 }
227 unsigned getRefArgNumber() const {
229 return Argument_Info & 0xFFFF;
230 }
231
233 IITDescriptor Result = { K, { Field } };
234 return Result;
235 }
236
237 static IITDescriptor get(IITDescriptorKind K, unsigned short Hi,
238 unsigned short Lo) {
239 unsigned Field = Hi << 16 | Lo;
240 IITDescriptor Result = {K, {Field}};
241 return Result;
242 }
243
244 static IITDescriptor getVector(unsigned Width, bool IsScalable) {
245 IITDescriptor Result = {Vector, {0}};
246 Result.Vector_Width = ElementCount::get(Width, IsScalable);
247 return Result;
248 }
249 };
250
251 /// Return the IIT table descriptor for the specified intrinsic into an array
252 /// of IITDescriptors.
255
261
262 /// Match the specified function type with the type constraints specified by
263 /// the .td file. If the given type is an overloaded type it is pushed to the
264 /// ArgTys vector.
265 ///
266 /// Returns false if the given type matches with the constraints, true
267 /// otherwise.
271
272 /// Verify if the intrinsic has variable arguments. This method is intended to
273 /// be called after all the fixed arguments have been matched first.
274 ///
275 /// This method returns true on error.
276 LLVM_ABI bool matchIntrinsicVarArg(bool isVarArg,
278
279 /// Gets the type arguments of an intrinsic call by matching type contraints
280 /// specified by the .td file. The overloaded types are pushed into the
281 /// AgTys vector.
282 ///
283 /// Returns false if the given ID and function type combination is not a
284 /// valid intrinsic call.
287
288 /// Same as previous, but accepts a Function instead of ID and FunctionType.
291
292 // Checks if the intrinsic name matches with its signature and if not
293 // returns the declaration with the same signature and remangled name.
294 // An existing GlobalValue with the wanted name but with a wrong prototype
295 // or of the wrong kind will be renamed by adding ".renamed" to the name.
296 LLVM_ABI std::optional<Function *> remangleIntrinsicFunction(Function *F);
297
298 /// Returns the corresponding llvm.vector.interleaveN intrinsic for factor N.
300
301 /// Returns the corresponding llvm.vector.deinterleaveN intrinsic for factor
302 /// N.
304
305 /// Print the argument info for the arguments with ArgInfo.
306 LLVM_ABI void printImmArg(ID IID, unsigned ArgIdx, raw_ostream &OS,
307 const Constant *ImmArgVal);
308
309 } // namespace Intrinsic
310
311 } // namespace llvm
312
313#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:213
#define F(x, y, z)
Definition MD5.cpp:54
Machine Check Debug Module
#define T
OptimizedStructLayoutField Field
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:407
This is an important base class in LLVM.
Definition Constant.h:43
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
Definition TypeSize.h:315
Class to represent function types.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
LLVM_ABI Intrinsic::ID getDeinterleaveIntrinsicID(unsigned Factor)
Returns the corresponding llvm.vector.deinterleaveN intrinsic for factor N.
LLVM_ABI MatchIntrinsicTypesResult matchIntrinsicSignature(FunctionType *FTy, ArrayRef< IITDescriptor > &Infos, SmallVectorImpl< Type * > &ArgTys)
Match the specified function type with the type constraints specified by the .td file.
LLVM_ABI void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
@ MatchIntrinsicTypes_NoMatchRet
Definition Intrinsics.h:258
@ MatchIntrinsicTypes_NoMatchArg
Definition Intrinsics.h:259
LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)
Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.
LLVM_ABI std::string getNameNoUnnamedTypes(ID Id, ArrayRef< Type * > Tys)
Return the LLVM name for an intrinsic.
LLVM_ABI std::optional< Function * > remangleIntrinsicFunction(Function *F)
LLVM_ABI bool hasConstrainedFPRoundingModeOperand(ID QID)
Returns true if the intrinsic ID is for one of the "ConstrainedFloating-Point Intrinsics" that take r...
LLVM_ABI void printImmArg(ID IID, unsigned ArgIdx, raw_ostream &OS, const Constant *ImmArgVal)
Print the argument info for the arguments with ArgInfo.
LLVM_ABI ID getIntrinsicForMSBuiltin(StringRef TargetPrefix, StringRef BuiltinName)
Map a MS builtin name to an intrinsic ID.
LLVM_ABI StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
LLVM_ABI bool isConstrainedFPIntrinsic(ID QID)
Returns true if the intrinsic ID is for one of the "ConstrainedFloating-Point Intrinsics".
LLVM_ABI ID lookupIntrinsicID(StringRef Name)
This does the actual lookup of an intrinsic ID which matches the given function name.
LLVM_ABI bool hasPrettyPrintedArgs(ID id)
Returns true if the intrinsic has pretty printed immediate arguments.
LLVM_ABI AttributeSet getFnAttributes(LLVMContext &C, ID id)
Return the function attributes for an intrinsic.
static const int NoAliasScopeDeclScopeArg
Definition Intrinsics.h:41
LLVM_ABI StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
LLVM_ABI Intrinsic::ID getInterleaveIntrinsicID(unsigned Factor)
Returns the corresponding llvm.vector.interleaveN intrinsic for factor N.
LLVM_ABI AttributeList getAttributes(LLVMContext &C, ID id, FunctionType *FT)
Return the attributes for an intrinsic.
LLVM_ABI bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
LLVM_ABI ID getIntrinsicForClangBuiltin(StringRef TargetPrefix, StringRef BuiltinName)
Map a Clang builtin name to an intrinsic ID.
LLVM_ABI FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys={})
Return the function type for an intrinsic.
LLVM_ABI bool getIntrinsicSignature(Intrinsic::ID, FunctionType *FT, SmallVectorImpl< Type * > &ArgTys)
Gets the type arguments of an intrinsic call by matching type contraints specified by the ....
LLVM_ABI bool isTargetIntrinsic(ID IID)
isTargetIntrinsic - Returns true if IID is an intrinsic specific to a certain target.
LLVM_ABI bool matchIntrinsicVarArg(bool isVarArg, ArrayRef< IITDescriptor > &Infos)
Verify if the intrinsic has variable arguments.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
ArrayRef(const T &OneElt) -> ArrayRef< T >
This is a type descriptor which explains the type requirements of an intrinsic.
Definition Intrinsics.h:154
enum llvm::Intrinsic::IITDescriptor::IITDescriptorKind Kind
static IITDescriptor get(IITDescriptorKind K, unsigned Field)
Definition Intrinsics.h:232
unsigned getArgumentNumber() const
Definition Intrinsics.h:200
unsigned getVectorDivisor() const
Definition Intrinsics.h:223
static IITDescriptor getVector(unsigned Width, bool IsScalable)
Definition Intrinsics.h:244
static IITDescriptor get(IITDescriptorKind K, unsigned short Hi, unsigned short Lo)
Definition Intrinsics.h:237
ArgKind getArgumentKind() const
Definition Intrinsics.h:207
unsigned getRefArgNumber() const
Definition Intrinsics.h:227
unsigned getOverloadArgNumber() const
Definition Intrinsics.h:217