LLVM  3.7.0
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 <string>
21 
22 namespace llvm {
23 
24 class Type;
25 class FunctionType;
26 class Function;
27 class LLVMContext;
28 class Module;
29 class AttributeSet;
30 
31 /// This namespace contains an enum with a value for every intrinsic/builtin
32 /// function known by LLVM. The enum values are returned by
33 /// Function::getIntrinsicID().
34 namespace Intrinsic {
35  enum ID : unsigned {
36  not_intrinsic = 0, // Must be zero
37 
38  // Get the intrinsic enums generated from Intrinsics.td
39 #define GET_INTRINSIC_ENUM_VALUES
40 #include "llvm/IR/Intrinsics.gen"
41 #undef GET_INTRINSIC_ENUM_VALUES
43  };
44 
45  /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
46  std::string getName(ID id, ArrayRef<Type*> Tys = None);
47 
48  /// Return the function type for an intrinsic.
49  FunctionType *getType(LLVMContext &Context, ID id,
50  ArrayRef<Type*> Tys = None);
51 
52  /// Returns true if the intrinsic can be overloaded.
53  bool isOverloaded(ID id);
54 
55  /// Returns true if the intrinsic is a leaf, i.e. it does not make any calls
56  /// itself. Most intrinsics are leafs, the exceptions being the patchpoint
57  /// and statepoint intrinsics. These call (or invoke) their "target" argument.
58  bool isLeaf(ID id);
59 
60  /// Return the attributes for an intrinsic.
62 
63  /// Create or insert an LLVM Function declaration for an intrinsic, and return
64  /// it.
65  ///
66  /// The Tys parameter is for intrinsics with overloaded types (e.g., those
67  /// using iAny, fAny, vAny, or iPTRAny). For a declaration of an overloaded
68  /// intrinsic, Tys must provide exactly one type for each overloaded type in
69  /// the intrinsic.
70  Function *getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys = None);
71 
72  /// Map a GCC builtin name to an intrinsic ID.
73  ID getIntrinsicForGCCBuiltin(const char *Prefix, const char *BuiltinName);
74 
75  /// Map a MS builtin name to an intrinsic ID.
76  ID getIntrinsicForMSBuiltin(const char *Prefix, const char *BuiltinName);
77 
78  /// This is a type descriptor which explains the type requirements of an
79  /// intrinsic. This is returned by getIntrinsicInfoTableEntries.
80  struct IITDescriptor {
86  } Kind;
87 
88  union {
89  unsigned Integer_Width;
90  unsigned Float_Width;
91  unsigned Vector_Width;
94  unsigned Argument_Info;
95  };
96 
97  enum ArgKind {
103  };
104  unsigned getArgumentNumber() const {
105  assert(Kind == Argument || Kind == ExtendArgument ||
108  Kind == VecOfPtrsToElt);
109  return Argument_Info >> 3;
110  }
112  assert(Kind == Argument || Kind == ExtendArgument ||
115  Kind == VecOfPtrsToElt);
116  return (ArgKind)(Argument_Info & 7);
117  }
118 
119  static IITDescriptor get(IITDescriptorKind K, unsigned Field) {
120  IITDescriptor Result = { K, { Field } };
121  return Result;
122  }
123  };
124 
125  /// Return the IIT table descriptor for the specified intrinsic into an array
126  /// of IITDescriptors.
128 
129 } // End Intrinsic namespace
130 
131 } // End llvm namespace
132 
133 #endif
LLVM Argument representation.
Definition: Argument.h:35
unsigned getArgumentNumber() const
Definition: Intrinsics.h:104
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
bool isOverloaded(ID id)
Returns true if the intrinsic can be overloaded.
Definition: Function.cpp:843
This is a type descriptor which explains the type requirements of an intrinsic.
Definition: Intrinsics.h:80
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
Definition: Function.cpp:822
ArgKind getArgumentKind() const
Definition: Intrinsics.h:111
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APInt.h:33
FunctionType - Class to represent function types.
Definition: DerivedTypes.h:96
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: ArrayRef.h:31
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:866
ID getIntrinsicForGCCBuiltin(const char *Prefix, const char *BuiltinName)
Map a GCC builtin name to an intrinsic ID.
bool isLeaf(ID id)
Returns true if the intrinsic is a leaf, i.e.
Definition: Function.cpp:849
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:41
enum llvm::Intrinsic::IITDescriptor::IITDescriptorKind Kind
void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
Definition: Function.cpp:710
std::string getName(ID id, ArrayRef< Type * > Tys=None)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:500
AttributeSet getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
ID getIntrinsicForMSBuiltin(const char *Prefix, const char *BuiltinName)
Map a MS builtin name to an intrinsic ID.