LLVM  6.0.0svn
Intrinsics.h
Go to the documentation of this file.
1 //===-- llvm/Instrinsics.h - LLVM Intrinsic Function Handling ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a set of enums which allow processing of intrinsic
11 // functions. Values of these enum types are returned by
12 // Function::getIntrinsicID.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_IR_INTRINSICS_H
17 #define LLVM_IR_INTRINSICS_H
18 
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/None.h"
21 #include "llvm/ADT/Optional.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  enum ID : unsigned {
38  not_intrinsic = 0, // Must be zero
39 
40  // Get the intrinsic enums generated from Intrinsics.td
41 #define GET_INTRINSIC_ENUM_VALUES
42 #include "llvm/IR/Intrinsics.gen"
43 #undef GET_INTRINSIC_ENUM_VALUES
45  };
46 
47  /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
48  /// Note, this version is for intrinsics with no overloads. Use the other
49  /// version of getName if overloads are required.
50  StringRef getName(ID id);
51 
52  /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
53  /// Note, this version of getName supports overloads, but is less efficient
54  /// than the StringRef version of this function. If no overloads are
55  /// requried, it is safe to use this version, but better to use the StringRef
56  /// version.
57  std::string getName(ID id, ArrayRef<Type*> Tys);
58 
59  /// Return the function type for an intrinsic.
61  ArrayRef<Type*> Tys = None);
62 
63  /// Returns true if the intrinsic can be overloaded.
64  bool isOverloaded(ID id);
65 
66  /// Returns true if the intrinsic is a leaf, i.e. it does not make any calls
67  /// itself. Most intrinsics are leafs, the exceptions being the patchpoint
68  /// and statepoint intrinsics. These call (or invoke) their "target" argument.
69  bool isLeaf(ID id);
70 
71  /// Return the attributes for an intrinsic.
73 
74  /// Create or insert an LLVM Function declaration for an intrinsic, and return
75  /// it.
76  ///
77  /// The Tys parameter is for intrinsics with overloaded types (e.g., those
78  /// using iAny, fAny, vAny, or iPTRAny). For a declaration of an overloaded
79  /// intrinsic, Tys must provide exactly one type for each overloaded type in
80  /// the intrinsic.
81  Function *getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys = None);
82 
83  /// Looks up Name in NameTable via binary search. NameTable must be sorted
84  /// and all entries must start with "llvm.". If NameTable contains an exact
85  /// match for Name or a prefix of Name followed by a dot, its index in
86  /// NameTable is returned. Otherwise, -1 is returned.
88  StringRef Name);
89 
90  /// Map a GCC builtin name to an intrinsic ID.
91  ID getIntrinsicForGCCBuiltin(const char *Prefix, StringRef BuiltinName);
92 
93  /// Map a MS builtin name to an intrinsic ID.
94  ID getIntrinsicForMSBuiltin(const char *Prefix, StringRef BuiltinName);
95 
96  /// This is a type descriptor which explains the type requirements of an
97  /// intrinsic. This is returned by getIntrinsicInfoTableEntries.
98  struct IITDescriptor {
104  } Kind;
105 
106  union {
107  unsigned Integer_Width;
108  unsigned Float_Width;
109  unsigned Vector_Width;
112  unsigned Argument_Info;
113  };
114 
115  enum ArgKind {
121  };
122 
123  unsigned getArgumentNumber() const {
124  assert(Kind == Argument || Kind == ExtendArgument ||
125  Kind == TruncArgument || Kind == HalfVecArgument ||
126  Kind == SameVecWidthArgument || Kind == PtrToArgument ||
127  Kind == PtrToElt);
128  return Argument_Info >> 3;
129  }
131  assert(Kind == Argument || Kind == ExtendArgument ||
132  Kind == TruncArgument || Kind == HalfVecArgument ||
133  Kind == SameVecWidthArgument || Kind == PtrToArgument);
134  return (ArgKind)(Argument_Info & 7);
135  }
136 
137  // VecOfAnyPtrsToElt uses both an overloaded argument (for address space)
138  // and a reference argument (for matching vector width and element types)
139  unsigned getOverloadArgNumber() const {
140  assert(Kind == VecOfAnyPtrsToElt);
141  return Argument_Info >> 16;
142  }
143  unsigned getRefArgNumber() const {
144  assert(Kind == VecOfAnyPtrsToElt);
145  return Argument_Info & 0xFFFF;
146  }
147 
148  static IITDescriptor get(IITDescriptorKind K, unsigned Field) {
149  IITDescriptor Result = { K, { Field } };
150  return Result;
151  }
152 
153  static IITDescriptor get(IITDescriptorKind K, unsigned short Hi,
154  unsigned short Lo) {
155  unsigned Field = Hi << 16 | Lo;
156  IITDescriptor Result = {K, {Field}};
157  return Result;
158  }
159  };
160 
161  /// Return the IIT table descriptor for the specified intrinsic into an array
162  /// of IITDescriptors.
164 
165  /// Match the specified type (which comes from an intrinsic argument or return
166  /// value) with the type constraints specified by the .td file. If the given
167  /// type is an overloaded type it is pushed to the ArgTys vector.
168  ///
169  /// Returns false if the given type matches with the constraints, true
170  /// otherwise.
172  SmallVectorImpl<Type*> &ArgTys);
173 
174  /// Verify if the intrinsic has variable arguments. This method is intended to
175  /// be called after all the fixed arguments have been matched first.
176  ///
177  /// This method returns true on error.
178  bool matchIntrinsicVarArg(bool isVarArg, ArrayRef<IITDescriptor> &Infos);
179 
180  // Checks if the intrinsic name matches with its signature and if not
181  // returns the declaration with the same signature and remangled name.
183 
184 } // End Intrinsic namespace
185 
186 } // End llvm namespace
187 
188 #endif
uint64_t CallInst * C
This class represents an incoming formal argument to a Function.
Definition: Argument.h:30
LLVMContext & Context
ArgKind getArgumentKind() const
Definition: Intrinsics.h:130
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
Definition: Function.cpp:957
F(f)
This is a type descriptor which explains the type requirements of an intrinsic.
Definition: Intrinsics.h:98
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:591
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
unsigned getArgumentNumber() const
Definition: Intrinsics.h:123
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
llvm::Optional< Function * > remangleIntrinsicFunction(Function *F)
Definition: Function.cpp:1177
Class to represent function types.
Definition: DerivedTypes.h:103
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
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:980
bool isLeaf(ID id)
Returns true if the intrinsic is a leaf, i.e.
Definition: Function.cpp:963
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
unsigned getOverloadArgNumber() const
Definition: Intrinsics.h:139
enum llvm::Intrinsic::IITDescriptor::IITDescriptorKind Kind
bool matchIntrinsicVarArg(bool isVarArg, ArrayRef< IITDescriptor > &Infos)
Verify if the intrinsic has variable arguments.
Definition: Function.cpp:1158
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:825
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type *> Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:936
unsigned getRefArgNumber() const
Definition: Intrinsics.h:143
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:998
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:49
int lookupLLVMIntrinsicByName(ArrayRef< const char *> NameTable, StringRef Name)
Looks up Name in NameTable via binary search.