LLVM  mainline
Intrinsics.h
Go to the documentation of this file.
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 /// This namespace contains an enum with a value for every intrinsic/builtin
00032 /// function known by LLVM. The enum values are returned by
00033 /// Function::getIntrinsicID().
00034 namespace Intrinsic {
00035   enum ID : unsigned {
00036     not_intrinsic = 0,   // Must be zero
00037 
00038     // Get the intrinsic enums generated from Intrinsics.td
00039 #define GET_INTRINSIC_ENUM_VALUES
00040 #include "llvm/IR/Intrinsics.gen"
00041 #undef GET_INTRINSIC_ENUM_VALUES
00042     , num_intrinsics
00043   };
00044 
00045   /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
00046   std::string getName(ID id, ArrayRef<Type*> Tys = None);
00047 
00048   /// Return the function type for an intrinsic.
00049   FunctionType *getType(LLVMContext &Context, ID id,
00050                         ArrayRef<Type*> Tys = None);
00051 
00052   /// Returns true if the intrinsic can be overloaded.
00053   bool isOverloaded(ID id);
00054 
00055   /// Returns true if the intrinsic is a leaf, i.e. it does not make any calls
00056   /// itself.  Most intrinsics are leafs, the exceptions being the patchpoint
00057   /// and statepoint intrinsics. These call (or invoke) their "target" argument.
00058   bool isLeaf(ID id);
00059 
00060   /// Return the attributes for an intrinsic.
00061   AttributeSet getAttributes(LLVMContext &C, ID id);
00062 
00063   /// Create or insert an LLVM Function declaration for an intrinsic, and return
00064   /// 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   /// This is a type descriptor which explains the type requirements of an
00079   /// intrinsic. This is returned by getIntrinsicInfoTableEntries.
00080   struct IITDescriptor {
00081     enum IITDescriptorKind {
00082       Void, VarArg, MMX, Metadata, Half, Float, Double,
00083       Integer, Vector, Pointer, Struct,
00084       Argument, ExtendArgument, TruncArgument, HalfVecArgument,
00085       SameVecWidthArgument, PtrToArgument, VecOfPtrsToElt
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_Any,
00099       AK_AnyInteger,
00100       AK_AnyFloat,
00101       AK_AnyVector,
00102       AK_AnyPointer
00103     };
00104     unsigned getArgumentNumber() const {
00105       assert(Kind == Argument || Kind == ExtendArgument ||
00106              Kind == TruncArgument || Kind == HalfVecArgument ||
00107              Kind == SameVecWidthArgument || Kind == PtrToArgument ||
00108              Kind == VecOfPtrsToElt);
00109       return Argument_Info >> 3;
00110     }
00111     ArgKind getArgumentKind() const {
00112       assert(Kind == Argument || Kind == ExtendArgument ||
00113              Kind == TruncArgument || Kind == HalfVecArgument ||
00114              Kind == SameVecWidthArgument || Kind == PtrToArgument ||
00115              Kind == VecOfPtrsToElt);
00116       return (ArgKind)(Argument_Info & 7);
00117     }
00118 
00119     static IITDescriptor get(IITDescriptorKind K, unsigned Field) {
00120       IITDescriptor Result = { K, { Field } };
00121       return Result;
00122     }
00123   };
00124 
00125   /// Return the IIT table descriptor for the specified intrinsic into an array
00126   /// of IITDescriptors.
00127   void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl<IITDescriptor> &T);
00128 
00129 } // End Intrinsic namespace
00130 
00131 } // End llvm namespace
00132 
00133 #endif