LLVM 22.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;
33
34/// This namespace contains an enum with a value for every intrinsic/builtin
35/// function known by LLVM. The enum values are returned by
36/// Function::getIntrinsicID().
37namespace Intrinsic {
38 // Abstraction for the arguments of the noalias intrinsics
39 static const int NoAliasScopeDeclScopeArg = 0;
40
41 // Intrinsic ID type. This is an opaque typedef to facilitate splitting up
42 // the enum into target-specific enums.
43 typedef unsigned ID;
44
45 enum IndependentIntrinsics : unsigned {
46 not_intrinsic = 0, // Must be zero
47
48 // Get the intrinsic enums generated from Intrinsics.td
49#define GET_INTRINSIC_ENUM_VALUES
50#include "llvm/IR/IntrinsicEnums.inc"
51#undef GET_INTRINSIC_ENUM_VALUES
52 };
53
54 /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
55 /// Note, this version is for intrinsics with no overloads. Use the other
56 /// version of getName if overloads are required.
57 LLVM_ABI StringRef getName(ID id);
58
59 /// Return the LLVM name for an intrinsic, without encoded types for
60 /// overloading, such as "llvm.ssa.copy".
61 LLVM_ABI StringRef getBaseName(ID id);
62
63 /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx" or
64 /// "llvm.ssa.copy.p0s_s.1". Note, this version of getName supports overloads.
65 /// This is less efficient than the StringRef version of this function. If no
66 /// overloads are required, it is safe to use this version, but better to use
67 /// the StringRef version. If one of the types is based on an unnamed type, a
68 /// function type will be computed. Providing FT will avoid this computation.
69 LLVM_ABI std::string getName(ID Id, ArrayRef<Type *> Tys, Module *M,
70 FunctionType *FT = nullptr);
71
72 /// Return the LLVM name for an intrinsic. This is a special version only to
73 /// be used by LLVMIntrinsicCopyOverloadedName. It only supports overloads
74 /// based on named types.
75 LLVM_ABI std::string getNameNoUnnamedTypes(ID Id, ArrayRef<Type *> Tys);
76
77 /// Return the function type for an intrinsic.
78 LLVM_ABI FunctionType *getType(LLVMContext &Context, ID id,
79 ArrayRef<Type *> Tys = {});
80
81 /// Returns true if the intrinsic can be overloaded.
82 LLVM_ABI bool isOverloaded(ID id);
83
84 /// isTargetIntrinsic - Returns true if IID is an intrinsic specific to a
85 /// certain target. If it is a generic intrinsic false is returned.
87
89
90 /// Return the attributes for an intrinsic.
92
93 /// Return the function attributes for an intrinsic.
95
96 /// Look up the Function declaration of the intrinsic \p id in the Module
97 /// \p M. If it does not exist, add a declaration and return it. Otherwise,
98 /// return the existing declaration.
99 ///
100 /// The \p Tys parameter is for intrinsics with overloaded types (e.g., those
101 /// using iAny, fAny, vAny, or pAny). For a declaration of an overloaded
102 /// intrinsic, Tys must provide exactly one type for each overloaded type in
103 /// the intrinsic.
105 ArrayRef<Type *> Tys = {});
106
107 /// Look up the Function declaration of the intrinsic \p id in the Module
108 /// \p M and return it if it exists. Otherwise, return nullptr. This version
109 /// supports non-overloaded intrinsics.
111
112 /// This version supports overloaded intrinsics.
115 FunctionType *FT = nullptr);
116
117 /// Map a Clang builtin name to an intrinsic ID.
119 StringRef BuiltinName);
120
121 /// Map a MS builtin name to an intrinsic ID.
123 StringRef BuiltinName);
124
125 /// Returns true if the intrinsic ID is for one of the "Constrained
126 /// Floating-Point Intrinsics".
128
129 /// Returns true if the intrinsic ID is for one of the "Constrained
130 /// Floating-Point Intrinsics" that take rounding mode metadata.
132
133 /// This is a type descriptor which explains the type requirements of an
134 /// intrinsic. This is returned by getIntrinsicInfoTableEntries.
165
166 union {
168 unsigned Float_Width;
173 };
174
175 // AK_% : Defined in Intrinsics.td
176 enum ArgKind {
177#define GET_INTRINSIC_ARGKIND
178#include "llvm/IR/IntrinsicEnums.inc"
179#undef GET_INTRINSIC_ARGKIND
180 };
181
182 unsigned getArgumentNumber() const {
187 return Argument_Info >> 3;
188 }
194 return (ArgKind)(Argument_Info & 7);
195 }
196
197 // VecOfAnyPtrsToElt uses both an overloaded argument (for address space)
198 // and a reference argument (for matching vector width and element types)
199 unsigned getOverloadArgNumber() const {
201 return Argument_Info >> 16;
202 }
203 // OneNthEltsVecArguments uses both a divisor N and a reference argument for
204 // the full-width vector to match
205 unsigned getVectorDivisor() const {
207 return Argument_Info >> 16;
208 }
209 unsigned getRefArgNumber() const {
211 return Argument_Info & 0xFFFF;
212 }
213
215 IITDescriptor Result = { K, { Field } };
216 return Result;
217 }
218
219 static IITDescriptor get(IITDescriptorKind K, unsigned short Hi,
220 unsigned short Lo) {
221 unsigned Field = Hi << 16 | Lo;
222 IITDescriptor Result = {K, {Field}};
223 return Result;
224 }
225
226 static IITDescriptor getVector(unsigned Width, bool IsScalable) {
227 IITDescriptor Result = {Vector, {0}};
228 Result.Vector_Width = ElementCount::get(Width, IsScalable);
229 return Result;
230 }
231 };
232
233 /// Return the IIT table descriptor for the specified intrinsic into an array
234 /// of IITDescriptors.
237
242 };
243
244 /// Match the specified function type with the type constraints specified by
245 /// the .td file. If the given type is an overloaded type it is pushed to the
246 /// ArgTys vector.
247 ///
248 /// Returns false if the given type matches with the constraints, true
249 /// otherwise.
253
254 /// Verify if the intrinsic has variable arguments. This method is intended to
255 /// be called after all the fixed arguments have been matched first.
256 ///
257 /// This method returns true on error.
258 LLVM_ABI bool matchIntrinsicVarArg(bool isVarArg,
260
261 /// Gets the type arguments of an intrinsic call by matching type contraints
262 /// specified by the .td file. The overloaded types are pushed into the
263 /// AgTys vector.
264 ///
265 /// Returns false if the given ID and function type combination is not a
266 /// valid intrinsic call.
269
270 /// Same as previous, but accepts a Function instead of ID and FunctionType.
273
274 // Checks if the intrinsic name matches with its signature and if not
275 // returns the declaration with the same signature and remangled name.
276 // An existing GlobalValue with the wanted name but with a wrong prototype
277 // or of the wrong kind will be renamed by adding ".renamed" to the name.
278 LLVM_ABI std::optional<Function *> remangleIntrinsicFunction(Function *F);
279
280 /// Returns the corresponding llvm.vector.interleaveN intrinsic for factor N.
282
283 /// Returns the corresponding llvm.vector.deinterleaveN intrinsic for factor
284 /// N.
286
287 } // namespace Intrinsic
288
289 } // namespace llvm
290
291#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
RelocType Type
Definition: COFFYAML.cpp:410
#define LLVM_ABI
Definition: Compiler.h:213
std::string Name
#define F(x, y, z)
Definition: MD5.cpp:55
Machine Check Debug Module
This class represents an incoming formal argument to a Function.
Definition: Argument.h:32
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
Definition: TypeSize.h:318
Class to represent function types.
Definition: DerivedTypes.h:105
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...
Definition: SmallVector.h:574
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
Definition: Intrinsics.cpp:751
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 AttributeSet getFnAttributes(LLVMContext &C, ID id)
Return the function attributes for an intrinsic.
Definition: Intrinsics.cpp:743
LLVM_ABI void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
Definition: Intrinsics.cpp:458
@ MatchIntrinsicTypes_Match
Definition: Intrinsics.h:239
@ MatchIntrinsicTypes_NoMatchRet
Definition: Intrinsics.h:240
@ MatchIntrinsicTypes_NoMatchArg
Definition: Intrinsics.h:241
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.
Definition: Intrinsics.cpp:762
LLVM_ABI std::string getNameNoUnnamedTypes(ID Id, ArrayRef< Type * > Tys)
Return the LLVM name for an intrinsic.
Definition: Intrinsics.cpp:187
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 "Constrained Floating-Point Intrinsics" that take ...
Definition: Intrinsics.cpp:794
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".
Definition: Intrinsics.cpp:49
LLVM_ABI bool isConstrainedFPIntrinsic(ID QID)
Returns true if the intrinsic ID is for one of the "Constrained Floating-Point Intrinsics".
Definition: Intrinsics.cpp:782
LLVM_ABI ID lookupIntrinsicID(StringRef Name)
This does the actual lookup of an intrinsic ID which matches the given function name.
Definition: Intrinsics.cpp:718
static const int NoAliasScopeDeclScopeArg
Definition: Intrinsics.h:39
LLVM_ABI StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
Definition: Intrinsics.cpp:44
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.
Definition: Intrinsics.cpp:618
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.
Definition: Intrinsics.cpp:596
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.
Definition: Intrinsics.cpp:629
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: AddressRanges.h:18
This is a type descriptor which explains the type requirements of an intrinsic.
Definition: Intrinsics.h:135
enum llvm::Intrinsic::IITDescriptor::IITDescriptorKind Kind
static IITDescriptor get(IITDescriptorKind K, unsigned Field)
Definition: Intrinsics.h:214
unsigned getArgumentNumber() const
Definition: Intrinsics.h:182
unsigned getVectorDivisor() const
Definition: Intrinsics.h:205
static IITDescriptor getVector(unsigned Width, bool IsScalable)
Definition: Intrinsics.h:226
static IITDescriptor get(IITDescriptorKind K, unsigned short Hi, unsigned short Lo)
Definition: Intrinsics.h:219
ArgKind getArgumentKind() const
Definition: Intrinsics.h:189
unsigned getRefArgNumber() const
Definition: Intrinsics.h:209
unsigned getOverloadArgNumber() const
Definition: Intrinsics.h:199