LLVM  16.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"
19 #include "llvm/ADT/None.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/Support/TypeSize.h"
22 #include <string>
23 
24 namespace llvm {
25 
26 class Type;
27 class FunctionType;
28 class Function;
29 class LLVMContext;
30 class Module;
31 class AttributeList;
32 
33 /// This namespace contains an enum with a value for every intrinsic/builtin
34 /// function known by LLVM. The enum values are returned by
35 /// Function::getIntrinsicID().
36 namespace Intrinsic {
37  // Abstraction for the arguments of the noalias intrinsics
38  static const int NoAliasScopeDeclScopeArg = 0;
39 
40  // Intrinsic ID type. This is an opaque typedef to facilitate splitting up
41  // the enum into target-specific enums.
42  typedef unsigned ID;
43 
44  enum IndependentIntrinsics : unsigned {
45  not_intrinsic = 0, // Must be zero
46 
47  // Get the intrinsic enums generated from Intrinsics.td
48 #define GET_INTRINSIC_ENUM_VALUES
49 #include "llvm/IR/IntrinsicEnums.inc"
50 #undef GET_INTRINSIC_ENUM_VALUES
51  };
52 
53  /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
54  /// Note, this version is for intrinsics with no overloads. Use the other
55  /// version of getName if overloads are required.
56  StringRef getName(ID id);
57 
58  /// Return the LLVM name for an intrinsic, without encoded types for
59  /// overloading, such as "llvm.ssa.copy".
60  StringRef getBaseName(ID id);
61 
62  /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx" or
63  /// "llvm.ssa.copy.p0s_s.1". Note, this version of getName supports overloads.
64  /// This is less efficient than the StringRef version of this function. If no
65  /// overloads are required, it is safe to use this version, but better to use
66  /// the StringRef version. If one of the types is based on an unnamed type, a
67  /// function type will be computed. Providing FT will avoid this computation.
68  std::string getName(ID Id, ArrayRef<Type *> Tys, Module *M,
69  FunctionType *FT = nullptr);
70 
71  /// Return the LLVM name for an intrinsic. This is a special version only to
72  /// be used by LLVMIntrinsicCopyOverloadedName. It only supports overloads
73  /// based on named types.
74  std::string getNameNoUnnamedTypes(ID Id, ArrayRef<Type *> Tys);
75 
76  /// Return the function type for an intrinsic.
77  FunctionType *getType(LLVMContext &Context, ID id,
78  ArrayRef<Type *> Tys = std::nullopt);
79 
80  /// Returns true if the intrinsic can be overloaded.
81  bool isOverloaded(ID id);
82 
83  /// Returns true if the intrinsic is a leaf, i.e. it does not make any calls
84  /// itself. Most intrinsics are leafs, the exceptions being the patchpoint
85  /// and statepoint intrinsics. These call (or invoke) their "target" argument.
86  bool isLeaf(ID id);
87 
88  /// Return the attributes for an intrinsic.
89  AttributeList getAttributes(LLVMContext &C, ID id);
90 
91  /// Create or insert an LLVM Function declaration for an intrinsic, and return
92  /// it.
93  ///
94  /// The Tys parameter is for intrinsics with overloaded types (e.g., those
95  /// using iAny, fAny, vAny, or iPTRAny). For a declaration of an overloaded
96  /// intrinsic, Tys must provide exactly one type for each overloaded type in
97  /// the intrinsic.
99  ArrayRef<Type *> Tys = std::nullopt);
100 
101  /// Looks up Name in NameTable via binary search. NameTable must be sorted
102  /// and all entries must start with "llvm.". If NameTable contains an exact
103  /// match for Name or a prefix of Name followed by a dot, its index in
104  /// NameTable is returned. Otherwise, -1 is returned.
105  int lookupLLVMIntrinsicByName(ArrayRef<const char *> NameTable,
106  StringRef Name);
107 
108  /// Map a Clang builtin name to an intrinsic ID.
109  ID getIntrinsicForClangBuiltin(const char *Prefix, StringRef BuiltinName);
110 
111  /// Map a MS builtin name to an intrinsic ID.
112  ID getIntrinsicForMSBuiltin(const char *Prefix, StringRef BuiltinName);
113 
114  /// This is a type descriptor which explains the type requirements of an
115  /// intrinsic. This is returned by getIntrinsicInfoTableEntries.
116  struct IITDescriptor {
147  } Kind;
148 
149  union {
150  unsigned Integer_Width;
151  unsigned Float_Width;
154  unsigned Argument_Info;
156  };
157 
158  enum ArgKind {
165  };
166 
167  unsigned getArgumentNumber() const {
174  return Argument_Info >> 3;
175  }
182  return (ArgKind)(Argument_Info & 7);
183  }
184 
185  // VecOfAnyPtrsToElt and AnyPtrToElt uses both an overloaded argument (for
186  // address space) and a reference argument (for matching vector width and
187  // element types)
188  unsigned getOverloadArgNumber() const {
190  return Argument_Info >> 16;
191  }
192  unsigned getRefArgNumber() const {
194  return Argument_Info & 0xFFFF;
195  }
196 
197  static IITDescriptor get(IITDescriptorKind K, unsigned Field) {
198  IITDescriptor Result = { K, { Field } };
199  return Result;
200  }
201 
202  static IITDescriptor get(IITDescriptorKind K, unsigned short Hi,
203  unsigned short Lo) {
204  unsigned Field = Hi << 16 | Lo;
205  IITDescriptor Result = {K, {Field}};
206  return Result;
207  }
208 
209  static IITDescriptor getVector(unsigned Width, bool IsScalable) {
210  IITDescriptor Result = {Vector, {0}};
211  Result.Vector_Width = ElementCount::get(Width, IsScalable);
212  return Result;
213  }
214  };
215 
216  /// Return the IIT table descriptor for the specified intrinsic into an array
217  /// of IITDescriptors.
219 
224  };
225 
226  /// Match the specified function type with the type constraints specified by
227  /// the .td file. If the given type is an overloaded type it is pushed to the
228  /// ArgTys vector.
229  ///
230  /// Returns false if the given type matches with the constraints, true
231  /// otherwise.
234  SmallVectorImpl<Type *> &ArgTys);
235 
236  /// Verify if the intrinsic has variable arguments. This method is intended to
237  /// be called after all the fixed arguments have been matched first.
238  ///
239  /// This method returns true on error.
240  bool matchIntrinsicVarArg(bool isVarArg, ArrayRef<IITDescriptor> &Infos);
241 
242  /// Gets the type arguments of an intrinsic call by matching type contraints
243  /// specified by the .td file. The overloaded types are pushed into the
244  /// AgTys vector.
245  ///
246  /// Returns false if the given function is not a valid intrinsic call.
248 
249  // Checks if the intrinsic name matches with its signature and if not
250  // returns the declaration with the same signature and remangled name.
251  // An existing GlobalValue with the wanted name but with a wrong prototype
252  // or of the wrong kind will be renamed by adding ".renamed" to the name.
254 
255 } // End Intrinsic namespace
256 
257 } // End llvm namespace
258 
259 #endif
llvm::Intrinsic::getBaseName
StringRef getBaseName(ID id)
Return the LLVM name for an intrinsic, without encoded types for overloading, such as "llvm....
Definition: Function.cpp:937
llvm::Intrinsic::IITDescriptor::AK_AnyVector
@ AK_AnyVector
Definition: Intrinsics.h:162
llvm::Intrinsic::IITDescriptor::Subdivide4Argument
@ Subdivide4Argument
Definition: Intrinsics.h:142
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
llvm::Intrinsic::remangleIntrinsicFunction
llvm::Optional< Function * > remangleIntrinsicFunction(Function *F)
Definition: Function.cpp:1846
llvm::Intrinsic::isOverloaded
bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
Definition: Function.cpp:1458
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::Intrinsic::IITDescriptor::get
static IITDescriptor get(IITDescriptorKind K, unsigned short Hi, unsigned short Lo)
Definition: Intrinsics.h:202
llvm::Intrinsic::MatchIntrinsicTypes_NoMatchArg
@ MatchIntrinsicTypes_NoMatchArg
Definition: Intrinsics.h:223
llvm::Intrinsic::IITDescriptor::VecOfBitcastsToInt
@ VecOfBitcastsToInt
Definition: Intrinsics.h:143
Optional.h
llvm::Intrinsic::IITDescriptor::Kind
enum llvm::Intrinsic::IITDescriptor::IITDescriptorKind Kind
FunctionType
Definition: ItaniumDemangle.h:775
llvm::ElementCount
Definition: TypeSize.h:404
llvm::Intrinsic::IITDescriptor::BFloat
@ BFloat
Definition: Intrinsics.h:124
llvm::cl::Prefix
@ Prefix
Definition: CommandLine.h:161
llvm::Function
Definition: Function.h:60
llvm::Intrinsic::IITDescriptor::VarArg
@ VarArg
Definition: Intrinsics.h:119
TypeSize.h
llvm::Intrinsic::IITDescriptor::Quad
@ Quad
Definition: Intrinsics.h:127
llvm::Intrinsic::getName
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:942
llvm::Intrinsic::IITDescriptor::MMX
@ MMX
Definition: Intrinsics.h:120
llvm::Intrinsic::IITDescriptor::AnyPtrToElt
@ AnyPtrToElt
Definition: Intrinsics.h:146
llvm::Intrinsic::IITDescriptor::Argument_Info
unsigned Argument_Info
Definition: Intrinsics.h:154
llvm::Intrinsic::IITDescriptor::Metadata
@ Metadata
Definition: Intrinsics.h:122
llvm::Intrinsic::IITDescriptor::PtrToArgument
@ PtrToArgument
Definition: Intrinsics.h:137
llvm::Intrinsic::lookupLLVMIntrinsicByName
int lookupLLVMIntrinsicByName(ArrayRef< const char * > NameTable, StringRef Name)
Looks up Name in NameTable via binary search.
Definition: IntrinsicInst.cpp:220
llvm::Optional
Definition: APInt.h:33
llvm::Intrinsic::getAttributes
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
llvm::Intrinsic::IITDescriptor::ExtendArgument
@ ExtendArgument
Definition: Intrinsics.h:133
llvm::Intrinsic::not_intrinsic
@ not_intrinsic
Definition: Intrinsics.h:45
llvm::Intrinsic::IITDescriptor::Pointer
@ Pointer
Definition: Intrinsics.h:130
llvm::Intrinsic::IITDescriptor::AK_Any
@ AK_Any
Definition: Intrinsics.h:159
llvm::Intrinsic::IITDescriptor::Void
@ Void
Definition: Intrinsics.h:118
llvm::Intrinsic::IITDescriptor::AK_MatchType
@ AK_MatchType
Definition: Intrinsics.h:164
llvm::Intrinsic::getIntrinsicSignature
bool getIntrinsicSignature(Function *F, SmallVectorImpl< Type * > &ArgTys)
Gets the type arguments of an intrinsic call by matching type contraints specified by the ....
Definition: Function.cpp:1825
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::Intrinsic::IITDescriptor::Float
@ Float
Definition: Intrinsics.h:125
llvm::Intrinsic::MatchIntrinsicTypes_NoMatchRet
@ MatchIntrinsicTypes_NoMatchRet
Definition: Intrinsics.h:222
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::Intrinsic::IITDescriptor::AK_AnyPointer
@ AK_AnyPointer
Definition: Intrinsics.h:163
llvm::LinearPolySize< ElementCount >::get
static ElementCount get(ScalarTy MinVal, bool Scalable)
Definition: TypeSize.h:289
llvm::Intrinsic::IITDescriptor::Struct_NumElements
unsigned Struct_NumElements
Definition: Intrinsics.h:153
llvm::Intrinsic::getIntrinsicForClangBuiltin
ID getIntrinsicForClangBuiltin(const char *Prefix, StringRef BuiltinName)
Map a Clang builtin name to an intrinsic ID.
llvm::Intrinsic::IITDescriptor::Double
@ Double
Definition: Intrinsics.h:126
llvm::Intrinsic::IITDescriptor::SameVecWidthArgument
@ SameVecWidthArgument
Definition: Intrinsics.h:136
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::Intrinsic::IITDescriptor::HalfVecArgument
@ HalfVecArgument
Definition: Intrinsics.h:135
llvm::Intrinsic::IITDescriptor::getArgumentNumber
unsigned getArgumentNumber() const
Definition: Intrinsics.h:167
llvm::Intrinsic::getType
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=std::nullopt)
Return the function type for an intrinsic.
Definition: Function.cpp:1437
llvm::Intrinsic::IITDescriptor::Pointer_AddressSpace
unsigned Pointer_AddressSpace
Definition: Intrinsics.h:152
llvm::Intrinsic::IITDescriptor::PPCQuad
@ PPCQuad
Definition: Intrinsics.h:145
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::codeview::ClassOptions::Intrinsic
@ Intrinsic
llvm::Intrinsic::IITDescriptor::TruncArgument
@ TruncArgument
Definition: Intrinsics.h:134
llvm::Intrinsic::MatchIntrinsicTypes_Match
@ MatchIntrinsicTypes_Match
Definition: Intrinsics.h:221
llvm::Intrinsic::IndependentIntrinsics
IndependentIntrinsics
Definition: Intrinsics.h:44
llvm::Intrinsic::IITDescriptor::get
static IITDescriptor get(IITDescriptorKind K, unsigned Field)
Definition: Intrinsics.h:197
llvm::Intrinsic::IITDescriptor::Integer_Width
unsigned Integer_Width
Definition: Intrinsics.h:150
llvm::Intrinsic::matchIntrinsicVarArg
bool matchIntrinsicVarArg(bool isVarArg, ArrayRef< IITDescriptor > &Infos)
Verify if the intrinsic has variable arguments.
Definition: Function.cpp:1806
llvm::Intrinsic::IITDescriptor::Half
@ Half
Definition: Intrinsics.h:123
llvm::Intrinsic::IITDescriptor::Float_Width
unsigned Float_Width
Definition: Intrinsics.h:151
llvm::Intrinsic::getIntrinsicInfoTableEntries
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
Definition: Function.cpp:1299
llvm::Intrinsic::getIntrinsicForMSBuiltin
ID getIntrinsicForMSBuiltin(const char *Prefix, StringRef BuiltinName)
Map a MS builtin name to an intrinsic ID.
llvm::Intrinsic::IITDescriptor::AK_AnyInteger
@ AK_AnyInteger
Definition: Intrinsics.h:160
llvm::Intrinsic::IITDescriptor::VecOfAnyPtrsToElt
@ VecOfAnyPtrsToElt
Definition: Intrinsics.h:139
ArrayRef.h
TemplateParamKind::Type
@ Type
llvm::Intrinsic::isLeaf
bool isLeaf(ID id)
Returns true if the intrinsic is a leaf, i.e.
Definition: Function.cpp:1464
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::Intrinsic::IITDescriptor::getOverloadArgNumber
unsigned getOverloadArgNumber() const
Definition: Intrinsics.h:188
llvm::Intrinsic::IITDescriptor::AMX
@ AMX
Definition: Intrinsics.h:144
llvm::Intrinsic::IITDescriptor::Argument
@ Argument
Definition: Intrinsics.h:132
llvm::Intrinsic::IITDescriptor::Subdivide2Argument
@ Subdivide2Argument
Definition: Intrinsics.h:141
llvm::Intrinsic::IITDescriptor::ArgKind
ArgKind
Definition: Intrinsics.h:158
llvm::Intrinsic::NoAliasScopeDeclScopeArg
static const int NoAliasScopeDeclScopeArg
Definition: Intrinsics.h:38
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
None.h
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::Intrinsic::IITDescriptor::PtrToElt
@ PtrToElt
Definition: Intrinsics.h:138
llvm::Intrinsic::IITDescriptor::VecElementArgument
@ VecElementArgument
Definition: Intrinsics.h:140
llvm::Intrinsic::getDeclaration
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1481
llvm::Intrinsic::IITDescriptor::AK_AnyFloat
@ AK_AnyFloat
Definition: Intrinsics.h:161
llvm::Intrinsic::IITDescriptor::IITDescriptorKind
IITDescriptorKind
Definition: Intrinsics.h:117
llvm::AMDGPU::Hwreg::Width
Width
Definition: SIDefines.h:433
llvm::Intrinsic::getNameNoUnnamedTypes
std::string getNameNoUnnamedTypes(ID Id, ArrayRef< Type * > Tys)
Return the LLVM name for an intrinsic.
Definition: Function.cpp:982
llvm::Intrinsic::IITDescriptor::Struct
@ Struct
Definition: Intrinsics.h:131
llvm::Intrinsic::IITDescriptor::Token
@ Token
Definition: Intrinsics.h:121
llvm::Intrinsic::IITDescriptor::Vector_Width
ElementCount Vector_Width
Definition: Intrinsics.h:155
llvm::Intrinsic::IITDescriptor::Vector
@ Vector
Definition: Intrinsics.h:129
llvm::Intrinsic::IITDescriptor::getRefArgNumber
unsigned getRefArgNumber() const
Definition: Intrinsics.h:192
llvm::Intrinsic::matchIntrinsicSignature
MatchIntrinsicTypesResult matchIntrinsicSignature(FunctionType *FTy, ArrayRef< IITDescriptor > &Infos, SmallVectorImpl< Type * > &ArgTys)
Match the specified function type with the type constraints specified by the .td file.
Definition: Function.cpp:1780
llvm::Intrinsic::IITDescriptor::getVector
static IITDescriptor getVector(unsigned Width, bool IsScalable)
Definition: Intrinsics.h:209
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::Intrinsic::IITDescriptor::Integer
@ Integer
Definition: Intrinsics.h:128
llvm::OptimizedStructLayoutField
A field in a structure.
Definition: OptimizedStructLayout.h:45
llvm::Intrinsic::IITDescriptor
This is a type descriptor which explains the type requirements of an intrinsic.
Definition: Intrinsics.h:116
llvm::AMDGPU::VGPRIndexMode::Id
Id
Definition: SIDefines.h:241
llvm::Intrinsic::MatchIntrinsicTypesResult
MatchIntrinsicTypesResult
Definition: Intrinsics.h:220
llvm::Intrinsic::IITDescriptor::getArgumentKind
ArgKind getArgumentKind() const
Definition: Intrinsics.h:176
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:103
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:39