LLVM API Documentation

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 {
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   /// Return the attributes for an intrinsic.
00056   AttributeSet getAttributes(LLVMContext &C, ID id);
00057 
00058   /// Create or insert an LLVM Function declaration for an intrinsic, and return
00059   /// it.
00060   ///
00061   /// The Tys parameter is for intrinsics with overloaded types (e.g., those
00062   /// using iAny, fAny, vAny, or iPTRAny).  For a declaration of an overloaded
00063   /// intrinsic, Tys must provide exactly one type for each overloaded type in
00064   /// the intrinsic.
00065   Function *getDeclaration(Module *M, ID id, ArrayRef<Type*> Tys = None);
00066 
00067   /// Map a GCC builtin name to an intrinsic ID.
00068   ID getIntrinsicForGCCBuiltin(const char *Prefix, const char *BuiltinName);
00069 
00070   /// Map a MS builtin name to an intrinsic ID.
00071   ID getIntrinsicForMSBuiltin(const char *Prefix, const char *BuiltinName);
00072   
00073   /// This is a type descriptor which explains the type requirements of an
00074   /// intrinsic. This is returned by getIntrinsicInfoTableEntries.
00075   struct IITDescriptor {
00076     enum IITDescriptorKind {
00077       Void, VarArg, MMX, Metadata, Half, Float, Double,
00078       Integer, Vector, Pointer, Struct,
00079       Argument, ExtendArgument, TruncArgument, HalfVecArgument,
00080       SameVecWidthArgument
00081     } Kind;
00082     
00083     union {
00084       unsigned Integer_Width;
00085       unsigned Float_Width;
00086       unsigned Vector_Width;
00087       unsigned Pointer_AddressSpace;
00088       unsigned Struct_NumElements;
00089       unsigned Argument_Info;
00090     };
00091     
00092     enum ArgKind {
00093       AK_AnyInteger,
00094       AK_AnyFloat,
00095       AK_AnyVector,
00096       AK_AnyPointer
00097     };
00098     unsigned getArgumentNumber() const {
00099       assert(Kind == Argument || Kind == ExtendArgument ||
00100              Kind == TruncArgument || Kind == HalfVecArgument ||
00101              Kind == SameVecWidthArgument);
00102       return Argument_Info >> 2;
00103     }
00104     ArgKind getArgumentKind() const {
00105       assert(Kind == Argument || Kind == ExtendArgument ||
00106              Kind == TruncArgument || Kind == HalfVecArgument ||
00107              Kind == SameVecWidthArgument);
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   /// Return the IIT table descriptor for the specified intrinsic into an array
00118   /// of IITDescriptors.
00119   void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl<IITDescriptor> &T);
00120   
00121 } // End Intrinsic namespace
00122 
00123 } // End llvm namespace
00124 
00125 #endif