Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 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 | |
Wesley Peck | 173c5c4 | 2010-02-24 20:16:27 +0000 | [diff] [blame] | 35 | #define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN |
| 36 | #include "MBlazeGenIntrinsics.inc" |
| 37 | #undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 40 | std::string MBlazeIntrinsicInfo::getName(unsigned IntrID, Type **Tys, |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 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; |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 51 | assert(IntrID < mblazeIntrinsic::num_mblaze_intrinsics && |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 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 { |
Bob Wilson | 35ee7d6 | 2010-03-18 16:52:15 +0000 | [diff] [blame] | 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 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 64 | #define GET_FUNCTION_RECOGNIZER |
| 65 | #include "MBlazeGenIntrinsics.inc" |
| 66 | #undef GET_FUNCTION_RECOGNIZER |
| 67 | return 0; |
| 68 | } |
| 69 | |
Wesley Peck | 173c5c4 | 2010-02-24 20:16:27 +0000 | [diff] [blame] | 70 | unsigned MBlazeIntrinsicInfo:: |
| 71 | lookupGCCName(const char *Name) const { |
| 72 | return mblazeIntrinsic::getIntrinsicForGCCBuiltin("mblaze",Name); |
| 73 | } |
| 74 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 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 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 93 | static FunctionType *getType(LLVMContext &Context, unsigned id) { |
| 94 | Type *ResultTy = NULL; |
Jay Foad | 5fdd6c8 | 2011-07-12 14:06:48 +0000 | [diff] [blame] | 95 | std::vector<Type*> ArgTys; |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 96 | bool IsVarArg = false; |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 97 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 98 | #define GET_INTRINSIC_GENERATOR |
| 99 | #include "MBlazeGenIntrinsics.inc" |
| 100 | #undef GET_INTRINSIC_GENERATOR |
| 101 | |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 102 | return FunctionType::get(ResultTy, ArgTys, IsVarArg); |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | Function *MBlazeIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 106 | Type **Tys, |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 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 | } |