LLVM API Documentation
00001 //===-- llvm/Instrinsics.h - LLVM Intrinsic Function Handling ---*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines a set of enums which allow processing of intrinsic 00011 // functions. Values of these enum types are returned by 00012 // Function::getIntrinsicID. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_IR_INTRINSICS_H 00017 #define LLVM_IR_INTRINSICS_H 00018 00019 #include "llvm/ADT/ArrayRef.h" 00020 #include <string> 00021 00022 namespace llvm { 00023 00024 class Type; 00025 class FunctionType; 00026 class Function; 00027 class LLVMContext; 00028 class Module; 00029 class AttributeSet; 00030 00031 /// Intrinsic Namespace - This namespace contains an enum with a value for 00032 /// every intrinsic/builtin function known by LLVM. These enum values are 00033 /// returned by Function::getIntrinsicID(). 00034 /// 00035 namespace Intrinsic { 00036 enum ID { 00037 not_intrinsic = 0, // Must be zero 00038 00039 // Get the intrinsic enums generated from Intrinsics.td 00040 #define GET_INTRINSIC_ENUM_VALUES 00041 #include "llvm/IR/Intrinsics.gen" 00042 #undef GET_INTRINSIC_ENUM_VALUES 00043 , num_intrinsics 00044 }; 00045 00046 /// Intrinsic::getName(ID) - Return the LLVM name for an intrinsic, such as 00047 /// "llvm.ppc.altivec.lvx". 00048 std::string getName(ID id, ArrayRef<Type*> Tys = None); 00049 00050 /// Intrinsic::getType(ID) - Return the function type for an intrinsic. 00051 /// 00052 FunctionType *getType(LLVMContext &Context, ID id, 00053 ArrayRef<Type*> Tys = None); 00054 00055 /// Intrinsic::isOverloaded(ID) - Returns true if the intrinsic can be 00056 /// overloaded. 00057 bool isOverloaded(ID id); 00058 00059 /// Intrinsic::getAttributes(ID) - Return the attributes for an intrinsic. 00060 /// 00061 AttributeSet getAttributes(LLVMContext &C, ID id); 00062 00063 /// Intrinsic::getDeclaration(M, ID) - Create or insert an LLVM Function 00064 /// declaration for an intrinsic, and return it. 00065 /// 00066 /// The Tys parameter is for intrinsics with overloaded types (e.g., those 00067 /// using iAny, fAny, vAny, or iPTRAny). For a declaration of an overloaded 00068 /// intrinsic, Tys must provide exactly one type for each overloaded type in 00069 /// the intrinsic. 00070 Function *getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys = None); 00071 00072 /// Map a GCC builtin name to an intrinsic ID. 00073 ID getIntrinsicForGCCBuiltin(const char *Prefix, const char *BuiltinName); 00074 00075 /// Map a MS builtin name to an intrinsic ID. 00076 ID getIntrinsicForMSBuiltin(const char *Prefix, const char *BuiltinName); 00077 00078 /// IITDescriptor - This is a type descriptor which explains the type 00079 /// requirements of an intrinsic. This is returned by 00080 /// getIntrinsicInfoTableEntries. 00081 struct IITDescriptor { 00082 enum IITDescriptorKind { 00083 Void, VarArg, MMX, Metadata, Half, Float, Double, 00084 Integer, Vector, Pointer, Struct, 00085 Argument, ExtendArgument, TruncArgument, HalfVecArgument 00086 } Kind; 00087 00088 union { 00089 unsigned Integer_Width; 00090 unsigned Float_Width; 00091 unsigned Vector_Width; 00092 unsigned Pointer_AddressSpace; 00093 unsigned Struct_NumElements; 00094 unsigned Argument_Info; 00095 }; 00096 00097 enum ArgKind { 00098 AK_AnyInteger, 00099 AK_AnyFloat, 00100 AK_AnyVector, 00101 AK_AnyPointer 00102 }; 00103 unsigned getArgumentNumber() const { 00104 assert(Kind == Argument || Kind == ExtendArgument || 00105 Kind == TruncArgument || Kind == HalfVecArgument); 00106 return Argument_Info >> 2; 00107 } 00108 ArgKind getArgumentKind() const { 00109 assert(Kind == Argument || Kind == ExtendArgument || 00110 Kind == TruncArgument || Kind == HalfVecArgument); 00111 return (ArgKind)(Argument_Info&3); 00112 } 00113 00114 static IITDescriptor get(IITDescriptorKind K, unsigned Field) { 00115 IITDescriptor Result = { K, { Field } }; 00116 return Result; 00117 } 00118 }; 00119 00120 /// getIntrinsicInfoTableEntries - Return the IIT table descriptor for the 00121 /// specified intrinsic into an array of IITDescriptors. 00122 /// 00123 void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl<IITDescriptor> &T); 00124 00125 } // End Intrinsic namespace 00126 00127 } // End llvm namespace 00128 00129 #endif