LLVM  9.0.0svn
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 <string>
22 
23 namespace llvm {
24 
25 class Type;
26 class FunctionType;
27 class Function;
28 class LLVMContext;
29 class Module;
30 class AttributeList;
31 
32 /// This namespace contains an enum with a value for every intrinsic/builtin
33 /// function known by LLVM. The enum values are returned by
34 /// Function::getIntrinsicID().
35 namespace Intrinsic {
36  enum ID : unsigned {
37  not_intrinsic = 0, // Must be zero
38 
39  // Get the intrinsic enums generated from Intrinsics.td
40 #define GET_INTRINSIC_ENUM_VALUES
41 #include "llvm/IR/IntrinsicEnums.inc"
42 #undef GET_INTRINSIC_ENUM_VALUES
44  };
45 
46  /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
47  /// Note, this version is for intrinsics with no overloads. Use the other
48  /// version of getName if overloads are required.
49  StringRef getName(ID id);
50 
51  /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
52  /// Note, this version of getName supports overloads, but is less efficient
53  /// than the StringRef version of this function. If no overloads are
54  /// requried, it is safe to use this version, but better to use the StringRef
55  /// version.
56  std::string getName(ID id, ArrayRef<Type*> Tys);
57 
58  /// Return the function type for an intrinsic.
60  ArrayRef<Type*> Tys = None);
61 
62  /// Returns true if the intrinsic can be overloaded.
63  bool isOverloaded(ID id);
64 
65  /// Returns true if the intrinsic is a leaf, i.e. it does not make any calls
66  /// itself. Most intrinsics are leafs, the exceptions being the patchpoint
67  /// and statepoint intrinsics. These call (or invoke) their "target" argument.
68  bool isLeaf(ID id);
69 
70  /// Return the attributes for an intrinsic.
72 
73  /// Create or insert an LLVM Function declaration for an intrinsic, and return
74  /// it.
75  ///
76  /// The Tys parameter is for intrinsics with overloaded types (e.g., those
77  /// using iAny, fAny, vAny, or iPTRAny). For a declaration of an overloaded
78  /// intrinsic, Tys must provide exactly one type for each overloaded type in
79  /// the intrinsic.
80  Function *getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys = None);
81 
82  /// Looks up Name in NameTable via binary search. NameTable must be sorted
83  /// and all entries must start with "llvm.". If NameTable contains an exact
84  /// match for Name or a prefix of Name followed by a dot, its index in
85  /// NameTable is returned. Otherwise, -1 is returned.
87  StringRef Name);
88 
89  /// Map a GCC builtin name to an intrinsic ID.
90  ID getIntrinsicForGCCBuiltin(const char *Prefix, StringRef BuiltinName);
91 
92  /// Map a MS builtin name to an intrinsic ID.
93  ID getIntrinsicForMSBuiltin(const char *Prefix, StringRef BuiltinName);
94 
95  /// This is a type descriptor which explains the type requirements of an
96  /// intrinsic. This is returned by getIntrinsicInfoTableEntries.
97  struct IITDescriptor {
103  } Kind;
104 
105  union {
106  unsigned Integer_Width;
107  unsigned Float_Width;
108  unsigned Vector_Width;
111  unsigned Argument_Info;
112  };
113 
114  enum ArgKind {
120  };
121 
122  unsigned getArgumentNumber() const {
123  assert(Kind == Argument || Kind == ExtendArgument ||
124  Kind == TruncArgument || Kind == HalfVecArgument ||
125  Kind == SameVecWidthArgument || Kind == PtrToArgument ||
126  Kind == PtrToElt);
127  return Argument_Info >> 3;
128  }
130  assert(Kind == Argument || Kind == ExtendArgument ||
131  Kind == TruncArgument || Kind == HalfVecArgument ||
132  Kind == SameVecWidthArgument || Kind == PtrToArgument);
133  return (ArgKind)(Argument_Info & 7);
134  }
135 
136  // VecOfAnyPtrsToElt uses both an overloaded argument (for address space)
137  // and a reference argument (for matching vector width and element types)
138  unsigned getOverloadArgNumber() const {
139  assert(Kind == VecOfAnyPtrsToElt);
140  return Argument_Info >> 16;
141  }
142  unsigned getRefArgNumber() const {
143  assert(Kind == VecOfAnyPtrsToElt);
144  return Argument_Info & 0xFFFF;
145  }
146 
147  static IITDescriptor get(IITDescriptorKind K, unsigned Field) {
148  IITDescriptor Result = { K, { Field } };
149  return Result;
150  }
151 
152  static IITDescriptor get(IITDescriptorKind K, unsigned short Hi,
153  unsigned short Lo) {
154  unsigned Field = Hi << 16 | Lo;
155  IITDescriptor Result = {K, {Field}};
156  return Result;
157  }
158  };
159 
160  /// Return the IIT table descriptor for the specified intrinsic into an array
161  /// of IITDescriptors.
163 
164  /// Match the specified type (which comes from an intrinsic argument or return
165  /// value) with the type constraints specified by the .td file. If the given
166  /// type is an overloaded type it is pushed to the ArgTys vector.
167  ///
168  /// Returns false if the given type matches with the constraints, true
169  /// otherwise.
171  SmallVectorImpl<Type*> &ArgTys);
172 
173  /// Verify if the intrinsic has variable arguments. This method is intended to
174  /// be called after all the fixed arguments have been matched first.
175  ///
176  /// This method returns true on error.
177  bool matchIntrinsicVarArg(bool isVarArg, ArrayRef<IITDescriptor> &Infos);
178 
179  // Checks if the intrinsic name matches with its signature and if not
180  // returns the declaration with the same signature and remangled name.
182 
183 } // End Intrinsic namespace
184 
185 } // End llvm namespace
186 
187 #endif
uint64_t CallInst * C
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:48
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
LLVMContext & Context
ArgKind getArgumentKind() const
Definition: Intrinsics.h:129
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:64
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
Definition: Function.cpp:995
F(f)
This is a type descriptor which explains the type requirements of an intrinsic.
Definition: Intrinsics.h:97
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:625
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
unsigned getArgumentNumber() const
Definition: Intrinsics.h:122
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
llvm::Optional< Function * > remangleIntrinsicFunction(Function *F)
Definition: Function.cpp:1221
Class to represent function types.
Definition: DerivedTypes.h:102
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1018
bool isLeaf(ID id)
Returns true if the intrinsic is a leaf, i.e.
Definition: Function.cpp:1001
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
unsigned getOverloadArgNumber() const
Definition: Intrinsics.h:138
enum llvm::Intrinsic::IITDescriptor::IITDescriptorKind Kind
bool matchIntrinsicVarArg(bool isVarArg, ArrayRef< IITDescriptor > &Infos)
Verify if the intrinsic has variable arguments.
Definition: Function.cpp:1202
ID getIntrinsicForGCCBuiltin(const char *Prefix, StringRef BuiltinName)
Map a GCC builtin name to an intrinsic ID.
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
Definition: Function.cpp:863
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type *> Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:974
unsigned getRefArgNumber() const
Definition: Intrinsics.h:142
bool matchIntrinsicType(Type *Ty, ArrayRef< IITDescriptor > &Infos, SmallVectorImpl< Type *> &ArgTys)
Match the specified type (which comes from an intrinsic argument or return value) with the type const...
Definition: Function.cpp:1037
ID getIntrinsicForMSBuiltin(const char *Prefix, StringRef BuiltinName)
Map a MS builtin name to an intrinsic ID.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
int lookupLLVMIntrinsicByName(ArrayRef< const char *> NameTable, StringRef Name)
Looks up Name in NameTable via binary search.