Adding the MicroBlaze backend.
[oota-llvm.git] / lib / Target / MBlaze / MBlazeIntrinsicInfo.cpp
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 }
36
37 std::string MBlazeIntrinsicInfo::getName(unsigned IntrID, const Type **Tys,
38                                          unsigned numTys) const {
39   static const char *const names[] = {
40 #define GET_INTRINSIC_NAME_TABLE
41 #include "MBlazeGenIntrinsics.inc"
42 #undef GET_INTRINSIC_NAME_TABLE
43   };
44
45   assert(!isOverloaded(IntrID) && "MBlaze intrinsics are not overloaded");
46   if (IntrID < Intrinsic::num_intrinsics)
47     return 0;
48   assert(IntrID < mblazeIntrinsic::num_mblaze_intrinsics && 
49          "Invalid intrinsic ID");
50
51   std::string Result(names[IntrID - Intrinsic::num_intrinsics]);
52   return Result;
53 }
54
55 unsigned MBlazeIntrinsicInfo::
56 lookupName(const char *Name, unsigned Len) const {
57 #define GET_FUNCTION_RECOGNIZER
58 #include "MBlazeGenIntrinsics.inc"
59 #undef GET_FUNCTION_RECOGNIZER
60   return 0;
61 }
62
63 bool MBlazeIntrinsicInfo::isOverloaded(unsigned IntrID) const {
64   // Overload Table
65   const bool OTable[] = {
66 #define GET_INTRINSIC_OVERLOAD_TABLE
67 #include "MBlazeGenIntrinsics.inc"
68 #undef GET_INTRINSIC_OVERLOAD_TABLE
69   };
70   if (IntrID == 0)
71     return false;
72   else
73     return OTable[IntrID - Intrinsic::num_intrinsics];
74 }
75
76 /// This defines the "getAttributes(ID id)" method.
77 #define GET_INTRINSIC_ATTRIBUTES
78 #include "MBlazeGenIntrinsics.inc"
79 #undef GET_INTRINSIC_ATTRIBUTES
80
81 static const FunctionType *getType(LLVMContext &Context, unsigned id) {
82   const Type *ResultTy = NULL;
83   std::vector<const Type*> ArgTys;
84   bool IsVarArg = false;
85   
86 #define GET_INTRINSIC_GENERATOR
87 #include "MBlazeGenIntrinsics.inc"
88 #undef GET_INTRINSIC_GENERATOR
89
90   return FunctionType::get(ResultTy, ArgTys, IsVarArg); 
91 }
92
93 Function *MBlazeIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID,
94                                                 const Type **Tys,
95                                                 unsigned numTy) const {
96   assert(!isOverloaded(IntrID) && "MBlaze intrinsics are not overloaded");
97   AttrListPtr AList = getAttributes((mblazeIntrinsic::ID) IntrID);
98   return cast<Function>(M->getOrInsertFunction(getName(IntrID),
99                                                getType(M->getContext(), IntrID),
100                                                AList));
101 }