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
22namespace llvm {
23
24class Type;
25class FunctionType;
26class Function;
27class LLVMContext;
28class Module;
29class 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().
34namespace Intrinsic {
35  enum ID {
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
42    , num_intrinsics
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  /// Return the attributes for an intrinsic.
56  AttributeSet getAttributes(LLVMContext &C, ID id);
57
58  /// Create or insert an LLVM Function declaration for an intrinsic, and return
59  /// it.
60  ///
61  /// The Tys parameter is for intrinsics with overloaded types (e.g., those
62  /// using iAny, fAny, vAny, or iPTRAny).  For a declaration of an overloaded
63  /// intrinsic, Tys must provide exactly one type for each overloaded type in
64  /// the intrinsic.
65  Function *getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys = None);
66
67  /// Map a GCC builtin name to an intrinsic ID.
68  ID getIntrinsicForGCCBuiltin(const char *Prefix, const char *BuiltinName);
69
70  /// Map a MS builtin name to an intrinsic ID.
71  ID getIntrinsicForMSBuiltin(const char *Prefix, const char *BuiltinName);
72
73  /// This is a type descriptor which explains the type requirements of an
74  /// intrinsic. This is returned by getIntrinsicInfoTableEntries.
75  struct IITDescriptor {
76    enum IITDescriptorKind {
77      Void, VarArg, MMX, Metadata, Half, Float, Double,
78      Integer, Vector, Pointer, Struct,
79      Argument, ExtendArgument, TruncArgument, HalfVecArgument,
80      SameVecWidthArgument, PtrToArgument, VecOfPtrsToElt
81    } Kind;
82
83    union {
84      unsigned Integer_Width;
85      unsigned Float_Width;
86      unsigned Vector_Width;
87      unsigned Pointer_AddressSpace;
88      unsigned Struct_NumElements;
89      unsigned Argument_Info;
90    };
91
92    enum ArgKind {
93      AK_Any,
94      AK_AnyInteger,
95      AK_AnyFloat,
96      AK_AnyVector,
97      AK_AnyPointer
98    };
99    unsigned getArgumentNumber() const {
100      assert(Kind == Argument || Kind == ExtendArgument ||
101             Kind == TruncArgument || Kind == HalfVecArgument ||
102             Kind == SameVecWidthArgument || Kind == PtrToArgument ||
103             Kind == VecOfPtrsToElt);
104      return Argument_Info >> 3;
105    }
106    ArgKind getArgumentKind() const {
107      assert(Kind == Argument || Kind == ExtendArgument ||
108             Kind == TruncArgument || Kind == HalfVecArgument ||
109             Kind == SameVecWidthArgument || Kind == PtrToArgument ||
110             Kind == VecOfPtrsToElt);
111      return (ArgKind)(Argument_Info & 7);
112    }
113
114    static IITDescriptor get(IITDescriptorKind K, unsigned Field) {
115      IITDescriptor Result = { K, { Field } };
116      return Result;
117    }
118  };
119
120  /// Return the IIT table descriptor for the specified intrinsic into an array
121  /// of IITDescriptors.
122  void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl<IITDescriptor> &T);
123
124} // End Intrinsic namespace
125
126} // End llvm namespace
127
128#endif
129