1 //===- MBlazeIntrinsicInfo.cpp - Intrinsic Information -00-------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the MBlaze implementation of TargetIntrinsicInfo.
12 //===----------------------------------------------------------------------===//
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"
25 namespace mblazeIntrinsic
{
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
35 #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
36 #include "MBlazeGenIntrinsics.inc"
37 #undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
40 std::string
MBlazeIntrinsicInfo::getName(unsigned IntrID
, const 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
48 assert(!isOverloaded(IntrID
) && "MBlaze intrinsics are not overloaded");
49 if (IntrID
< Intrinsic::num_intrinsics
)
51 assert(IntrID
< mblazeIntrinsic::num_mblaze_intrinsics
&&
52 "Invalid intrinsic ID");
54 std::string
Result(names
[IntrID
- Intrinsic::num_intrinsics
]);
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.'
64 #define GET_FUNCTION_RECOGNIZER
65 #include "MBlazeGenIntrinsics.inc"
66 #undef GET_FUNCTION_RECOGNIZER
70 unsigned MBlazeIntrinsicInfo::
71 lookupGCCName(const char *Name
) const {
72 return mblazeIntrinsic::getIntrinsicForGCCBuiltin("mblaze",Name
);
75 bool MBlazeIntrinsicInfo::isOverloaded(unsigned IntrID
) const {
77 const bool OTable
[] = {
78 #define GET_INTRINSIC_OVERLOAD_TABLE
79 #include "MBlazeGenIntrinsics.inc"
80 #undef GET_INTRINSIC_OVERLOAD_TABLE
85 return OTable
[IntrID
- Intrinsic::num_intrinsics
];
88 /// This defines the "getAttributes(ID id)" method.
89 #define GET_INTRINSIC_ATTRIBUTES
90 #include "MBlazeGenIntrinsics.inc"
91 #undef GET_INTRINSIC_ATTRIBUTES
93 static const FunctionType
*getType(LLVMContext
&Context
, unsigned id
) {
94 const Type
*ResultTy
= NULL
;
95 std::vector
<const Type
*> ArgTys
;
96 bool IsVarArg
= false;
98 #define GET_INTRINSIC_GENERATOR
99 #include "MBlazeGenIntrinsics.inc"
100 #undef GET_INTRINSIC_GENERATOR
102 return FunctionType::get(ResultTy
, ArgTys
, IsVarArg
);
105 Function
*MBlazeIntrinsicInfo::getDeclaration(Module
*M
, unsigned IntrID
,
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
),