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 /// IITDescriptor - This is a type descriptor which explains the type 00076 /// requirements of an intrinsic. This is returned by 00077 /// getIntrinsicInfoTableEntries. 00078 struct IITDescriptor { 00079 enum IITDescriptorKind { 00080 Void, MMX, Metadata, Half, Float, Double, 00081 Integer, Vector, Pointer, Struct, 00082 Argument, ExtendVecArgument, TruncVecArgument 00083 } Kind; 00084 00085 union { 00086 unsigned Integer_Width; 00087 unsigned Float_Width; 00088 unsigned Vector_Width; 00089 unsigned Pointer_AddressSpace; 00090 unsigned Struct_NumElements; 00091 unsigned Argument_Info; 00092 }; 00093 00094 enum ArgKind { 00095 AK_AnyInteger, 00096 AK_AnyFloat, 00097 AK_AnyVector, 00098 AK_AnyPointer 00099 }; 00100 unsigned getArgumentNumber() const { 00101 assert(Kind == Argument || Kind == ExtendVecArgument || 00102 Kind == TruncVecArgument); 00103 return Argument_Info >> 2; 00104 } 00105 ArgKind getArgumentKind() const { 00106 assert(Kind == Argument || Kind == ExtendVecArgument || 00107 Kind == TruncVecArgument); 00108 return (ArgKind)(Argument_Info&3); 00109 } 00110 00111 static IITDescriptor get(IITDescriptorKind K, unsigned Field) { 00112 IITDescriptor Result = { K, { Field } }; 00113 return Result; 00114 } 00115 }; 00116 00117 /// getIntrinsicInfoTableEntries - Return the IIT table descriptor for the 00118 /// specified intrinsic into an array of IITDescriptors. 00119 /// 00120 void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl<IITDescriptor> &T); 00121 00122 } // End Intrinsic namespace 00123 00124 } // End llvm namespace 00125 00126 #endif