Jakob Stoklund Olesen | 460ceae | 2009-10-15 18:50:52 +0000 | [diff] [blame] | 1 | //===- BlackfinIntrinsicInfo.cpp - Intrinsic Information --------*- 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 Blackfin implementation of TargetIntrinsicInfo. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "BlackfinIntrinsicInfo.h" |
Mon P Wang | 1a58236 | 2009-11-05 03:19:08 +0000 | [diff] [blame] | 15 | #include "llvm/DerivedTypes.h" |
| 16 | #include "llvm/Function.h" |
Jakob Stoklund Olesen | 460ceae | 2009-10-15 18:50:52 +0000 | [diff] [blame] | 17 | #include "llvm/Intrinsics.h" |
Mon P Wang | 1a58236 | 2009-11-05 03:19:08 +0000 | [diff] [blame] | 18 | #include "llvm/Module.h" |
| 19 | #include "llvm/Type.h" |
Jakob Stoklund Olesen | 460ceae | 2009-10-15 18:50:52 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
| 21 | #include <cstring> |
| 22 | |
| 23 | using namespace llvm; |
| 24 | |
| 25 | namespace bfinIntrinsic { |
| 26 | |
| 27 | enum ID { |
| 28 | last_non_bfin_intrinsic = Intrinsic::num_intrinsics-1, |
| 29 | #define GET_INTRINSIC_ENUM_VALUES |
| 30 | #include "BlackfinGenIntrinsics.inc" |
| 31 | #undef GET_INTRINSIC_ENUM_VALUES |
| 32 | , num_bfin_intrinsics |
| 33 | }; |
| 34 | |
| 35 | } |
| 36 | |
Mon P Wang | 1a58236 | 2009-11-05 03:19:08 +0000 | [diff] [blame] | 37 | std::string BlackfinIntrinsicInfo::getName(unsigned IntrID, const Type **Tys, |
| 38 | unsigned numTys) const { |
Jakob Stoklund Olesen | 460ceae | 2009-10-15 18:50:52 +0000 | [diff] [blame] | 39 | static const char *const names[] = { |
| 40 | #define GET_INTRINSIC_NAME_TABLE |
| 41 | #include "BlackfinGenIntrinsics.inc" |
| 42 | #undef GET_INTRINSIC_NAME_TABLE |
| 43 | }; |
| 44 | |
Mon P Wang | 1a58236 | 2009-11-05 03:19:08 +0000 | [diff] [blame] | 45 | assert(!isOverloaded(IntrID) && "Blackfin intrinsics are not overloaded"); |
Jakob Stoklund Olesen | 460ceae | 2009-10-15 18:50:52 +0000 | [diff] [blame] | 46 | if (IntrID < Intrinsic::num_intrinsics) |
| 47 | return 0; |
| 48 | assert(IntrID < bfinIntrinsic::num_bfin_intrinsics && "Invalid intrinsic ID"); |
| 49 | |
Mon P Wang | 1a58236 | 2009-11-05 03:19:08 +0000 | [diff] [blame] | 50 | std::string Result(names[IntrID - Intrinsic::num_intrinsics]); |
| 51 | return Result; |
Jakob Stoklund Olesen | 460ceae | 2009-10-15 18:50:52 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | unsigned |
| 55 | BlackfinIntrinsicInfo::lookupName(const char *Name, unsigned Len) const { |
Bob Wilson | ce51f78 | 2010-03-18 16:52:15 +0000 | [diff] [blame] | 56 | if (Len < 5 || Name[4] != '.' || Name[0] != 'l' || Name[1] != 'l' |
| 57 | || Name[2] != 'v' || Name[3] != 'm') |
| 58 | return 0; // All intrinsics start with 'llvm.' |
| 59 | |
Jakob Stoklund Olesen | 460ceae | 2009-10-15 18:50:52 +0000 | [diff] [blame] | 60 | #define GET_FUNCTION_RECOGNIZER |
| 61 | #include "BlackfinGenIntrinsics.inc" |
| 62 | #undef GET_FUNCTION_RECOGNIZER |
| 63 | return 0; |
| 64 | } |
Mon P Wang | 1a58236 | 2009-11-05 03:19:08 +0000 | [diff] [blame] | 65 | |
| 66 | bool BlackfinIntrinsicInfo::isOverloaded(unsigned IntrID) const { |
| 67 | // Overload Table |
| 68 | const bool OTable[] = { |
Mon P Wang | 1a58236 | 2009-11-05 03:19:08 +0000 | [diff] [blame] | 69 | #define GET_INTRINSIC_OVERLOAD_TABLE |
| 70 | #include "BlackfinGenIntrinsics.inc" |
| 71 | #undef GET_INTRINSIC_OVERLOAD_TABLE |
| 72 | }; |
| 73 | if (IntrID == 0) |
| 74 | return false; |
| 75 | else |
| 76 | return OTable[IntrID - Intrinsic::num_intrinsics]; |
| 77 | } |
| 78 | |
| 79 | /// This defines the "getAttributes(ID id)" method. |
| 80 | #define GET_INTRINSIC_ATTRIBUTES |
| 81 | #include "BlackfinGenIntrinsics.inc" |
| 82 | #undef GET_INTRINSIC_ATTRIBUTES |
| 83 | |
| 84 | static const FunctionType *getType(LLVMContext &Context, unsigned id) { |
| 85 | const Type *ResultTy = NULL; |
| 86 | std::vector<const Type*> ArgTys; |
| 87 | bool IsVarArg = false; |
| 88 | |
| 89 | #define GET_INTRINSIC_GENERATOR |
| 90 | #include "BlackfinGenIntrinsics.inc" |
| 91 | #undef GET_INTRINSIC_GENERATOR |
| 92 | |
| 93 | return FunctionType::get(ResultTy, ArgTys, IsVarArg); |
| 94 | } |
| 95 | |
| 96 | Function *BlackfinIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID, |
| 97 | const Type **Tys, |
| 98 | unsigned numTy) const { |
| 99 | assert(!isOverloaded(IntrID) && "Blackfin intrinsics are not overloaded"); |
| 100 | AttrListPtr AList = getAttributes((bfinIntrinsic::ID) IntrID); |
| 101 | return cast<Function>(M->getOrInsertFunction(getName(IntrID), |
| 102 | getType(M->getContext(), IntrID), |
| 103 | AList)); |
| 104 | } |