Home | History | Annotate | Download | only in MBlaze
      1 //===- MBlazeIntrinsicInfo.cpp - Intrinsic Information -00-------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file contains the MBlaze implementation of TargetIntrinsicInfo.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "MBlazeIntrinsicInfo.h"
     15 #include "llvm/DerivedTypes.h"
     16 #include "llvm/Function.h"
     17 #include "llvm/Intrinsics.h"
     18 #include "llvm/Module.h"
     19 #include "llvm/Type.h"
     20 #include "llvm/Support/raw_ostream.h"
     21 #include <cstring>
     22 
     23 using namespace llvm;
     24 
     25 namespace mblazeIntrinsic {
     26 
     27   enum ID {
     28     last_non_mblaze_intrinsic = Intrinsic::num_intrinsics-1,
     29 #define GET_INTRINSIC_ENUM_VALUES
     30 #include "MBlazeGenIntrinsics.inc"
     31 #undef GET_INTRINSIC_ENUM_VALUES
     32     , num_mblaze_intrinsics
     33   };
     34 
     35 #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
     36 #include "MBlazeGenIntrinsics.inc"
     37 #undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
     38 }
     39 
     40 std::string MBlazeIntrinsicInfo::getName(unsigned IntrID, Type **Tys,
     41                                          unsigned numTys) const {
     42   static const char *const names[] = {
     43 #define GET_INTRINSIC_NAME_TABLE
     44 #include "MBlazeGenIntrinsics.inc"
     45 #undef GET_INTRINSIC_NAME_TABLE
     46   };
     47 
     48   assert(!isOverloaded(IntrID) && "MBlaze intrinsics are not overloaded");
     49   if (IntrID < Intrinsic::num_intrinsics)
     50     return 0;
     51   assert(IntrID < mblazeIntrinsic::num_mblaze_intrinsics &&
     52          "Invalid intrinsic ID");
     53 
     54   std::string Result(names[IntrID - Intrinsic::num_intrinsics]);
     55   return Result;
     56 }
     57 
     58 unsigned MBlazeIntrinsicInfo::
     59 lookupName(const char *Name, unsigned Len) const {
     60   if (Len < 5 || Name[4] != '.' || Name[0] != 'l' || Name[1] != 'l'
     61       || Name[2] != 'v' || Name[3] != 'm')
     62     return 0;  // All intrinsics start with 'llvm.'
     63 
     64 #define GET_FUNCTION_RECOGNIZER
     65 #include "MBlazeGenIntrinsics.inc"
     66 #undef GET_FUNCTION_RECOGNIZER
     67   return 0;
     68 }
     69 
     70 unsigned MBlazeIntrinsicInfo::
     71 lookupGCCName(const char *Name) const {
     72     return mblazeIntrinsic::getIntrinsicForGCCBuiltin("mblaze",Name);
     73 }
     74 
     75 bool MBlazeIntrinsicInfo::isOverloaded(unsigned IntrID) const {
     76   // Overload Table
     77   const bool OTable[] = {
     78 #define GET_INTRINSIC_OVERLOAD_TABLE
     79 #include "MBlazeGenIntrinsics.inc"
     80 #undef GET_INTRINSIC_OVERLOAD_TABLE
     81   };
     82   if (IntrID == 0)
     83     return false;
     84   else
     85     return OTable[IntrID - Intrinsic::num_intrinsics];
     86 }
     87 
     88 /// This defines the "getAttributes(ID id)" method.
     89 #define GET_INTRINSIC_ATTRIBUTES
     90 #include "MBlazeGenIntrinsics.inc"
     91 #undef GET_INTRINSIC_ATTRIBUTES
     92 
     93 static FunctionType *getType(LLVMContext &Context, unsigned id) {
     94   Type *ResultTy = NULL;
     95   SmallVector<Type*, 8> ArgTys;
     96   bool IsVarArg = false;
     97 
     98 #define GET_INTRINSIC_GENERATOR
     99 #include "MBlazeGenIntrinsics.inc"
    100 #undef GET_INTRINSIC_GENERATOR
    101 
    102   return FunctionType::get(ResultTy, ArgTys, IsVarArg);
    103 }
    104 
    105 Function *MBlazeIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID,
    106                                                 Type **Tys,
    107                                                 unsigned numTy) const {
    108   assert(!isOverloaded(IntrID) && "MBlaze intrinsics are not overloaded");
    109   AttrListPtr AList = getAttributes((mblazeIntrinsic::ID) IntrID);
    110   return cast<Function>(M->getOrInsertFunction(getName(IntrID),
    111                                                getType(M->getContext(), IntrID),
    112                                                AList));
    113 }
    114