LLVM API Documentation

MBlazeIntrinsicInfo.cpp
Go to the documentation of this file.
00001 //===-- MBlazeIntrinsicInfo.cpp - Intrinsic Information -------------------===//
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 contains the MBlaze implementation of TargetIntrinsicInfo.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "MBlazeIntrinsicInfo.h"
00015 #include "llvm/IR/DerivedTypes.h"
00016 #include "llvm/IR/Function.h"
00017 #include "llvm/IR/Intrinsics.h"
00018 #include "llvm/IR/Module.h"
00019 #include "llvm/IR/Type.h"
00020 #include "llvm/Support/ErrorHandling.h"
00021 #include "llvm/Support/raw_ostream.h"
00022 #include <cstring>
00023 
00024 using namespace llvm;
00025 
00026 namespace mblazeIntrinsic {
00027 
00028   enum ID {
00029     last_non_mblaze_intrinsic = Intrinsic::num_intrinsics-1,
00030 #define GET_INTRINSIC_ENUM_VALUES
00031 #include "MBlazeGenIntrinsics.inc"
00032 #undef GET_INTRINSIC_ENUM_VALUES
00033     , num_mblaze_intrinsics
00034   };
00035 
00036 #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
00037 #include "MBlazeGenIntrinsics.inc"
00038 #undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
00039 }
00040 
00041 std::string MBlazeIntrinsicInfo::getName(unsigned IntrID, Type **Tys,
00042                                          unsigned numTys) const {
00043   static const char *const names[] = {
00044 #define GET_INTRINSIC_NAME_TABLE
00045 #include "MBlazeGenIntrinsics.inc"
00046 #undef GET_INTRINSIC_NAME_TABLE
00047   };
00048 
00049   assert(!isOverloaded(IntrID) && "MBlaze intrinsics are not overloaded");
00050   if (IntrID < Intrinsic::num_intrinsics)
00051     return 0;
00052   assert(IntrID < mblazeIntrinsic::num_mblaze_intrinsics &&
00053          "Invalid intrinsic ID");
00054 
00055   std::string Result(names[IntrID - Intrinsic::num_intrinsics]);
00056   return Result;
00057 }
00058 
00059 unsigned MBlazeIntrinsicInfo::
00060 lookupName(const char *Name, unsigned Len) const {
00061   if (!StringRef(Name, Len).startswith("llvm."))
00062     return 0; // All intrinsics start with 'llvm.'
00063 
00064 #define GET_FUNCTION_RECOGNIZER
00065 #include "MBlazeGenIntrinsics.inc"
00066 #undef GET_FUNCTION_RECOGNIZER
00067   return 0;
00068 }
00069 
00070 unsigned MBlazeIntrinsicInfo::
00071 lookupGCCName(const char *Name) const {
00072     return mblazeIntrinsic::getIntrinsicForGCCBuiltin("mblaze",Name);
00073 }
00074 
00075 bool MBlazeIntrinsicInfo::isOverloaded(unsigned IntrID) const {
00076   if (IntrID == 0)
00077     return false;
00078 
00079   unsigned id = IntrID - Intrinsic::num_intrinsics + 1;
00080 #define GET_INTRINSIC_OVERLOAD_TABLE
00081 #include "MBlazeGenIntrinsics.inc"
00082 #undef GET_INTRINSIC_OVERLOAD_TABLE
00083 }
00084 
00085 /// This defines the "getAttributes(LLVMContext &C, ID id)" method.
00086 #define GET_INTRINSIC_ATTRIBUTES
00087 #include "MBlazeGenIntrinsics.inc"
00088 #undef GET_INTRINSIC_ATTRIBUTES
00089 
00090 static FunctionType *getType(LLVMContext &Context, unsigned id) {
00091   Type *ResultTy = NULL;
00092   SmallVector<Type*, 8> ArgTys;
00093   bool IsVarArg = false;
00094 
00095 #define GET_INTRINSIC_GENERATOR
00096 #include "MBlazeGenIntrinsics.inc"
00097 #undef GET_INTRINSIC_GENERATOR
00098 
00099   return FunctionType::get(ResultTy, ArgTys, IsVarArg);
00100 }
00101 
00102 Function *MBlazeIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID,
00103                                                 Type **Tys,
00104                                                 unsigned numTy) const {
00105   assert(!isOverloaded(IntrID) && "MBlaze intrinsics are not overloaded");
00106   AttributeSet AList = getAttributes(M->getContext(),
00107                                     (mblazeIntrinsic::ID) IntrID);
00108   return cast<Function>(M->getOrInsertFunction(getName(IntrID),
00109                                                getType(M->getContext(), IntrID),
00110                                                AList));
00111 }