blob: ea81dd63d195c38a23d7589777f00e2a3fbf23dd [file] [log] [blame]
Wesley Pecka70f28c2010-02-23 19:15:24 +00001//===- 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
23using namespace llvm;
24
25namespace 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 Peck173c5c42010-02-24 20:16:27 +000035#define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
36#include "MBlazeGenIntrinsics.inc"
37#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
Wesley Pecka70f28c2010-02-23 19:15:24 +000038}
39
Chris Lattnerdb125cf2011-07-18 04:54:35 +000040std::string MBlazeIntrinsicInfo::getName(unsigned IntrID, Type **Tys,
Wesley Pecka70f28c2010-02-23 19:15:24 +000041 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 Peck0a67d922010-11-08 19:40:01 +000051 assert(IntrID < mblazeIntrinsic::num_mblaze_intrinsics &&
Wesley Pecka70f28c2010-02-23 19:15:24 +000052 "Invalid intrinsic ID");
53
54 std::string Result(names[IntrID - Intrinsic::num_intrinsics]);
55 return Result;
56}
57
58unsigned MBlazeIntrinsicInfo::
59lookupName(const char *Name, unsigned Len) const {
Bob Wilson35ee7d62010-03-18 16:52:15 +000060 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 Pecka70f28c2010-02-23 19:15:24 +000064#define GET_FUNCTION_RECOGNIZER
65#include "MBlazeGenIntrinsics.inc"
66#undef GET_FUNCTION_RECOGNIZER
67 return 0;
68}
69
Wesley Peck173c5c42010-02-24 20:16:27 +000070unsigned MBlazeIntrinsicInfo::
71lookupGCCName(const char *Name) const {
72 return mblazeIntrinsic::getIntrinsicForGCCBuiltin("mblaze",Name);
73}
74
Wesley Pecka70f28c2010-02-23 19:15:24 +000075bool 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 Lattnerdb125cf2011-07-18 04:54:35 +000093static FunctionType *getType(LLVMContext &Context, unsigned id) {
94 Type *ResultTy = NULL;
Jay Foad5fdd6c82011-07-12 14:06:48 +000095 std::vector<Type*> ArgTys;
Wesley Pecka70f28c2010-02-23 19:15:24 +000096 bool IsVarArg = false;
Wesley Peck0a67d922010-11-08 19:40:01 +000097
Wesley Pecka70f28c2010-02-23 19:15:24 +000098#define GET_INTRINSIC_GENERATOR
99#include "MBlazeGenIntrinsics.inc"
100#undef GET_INTRINSIC_GENERATOR
101
Wesley Peck0a67d922010-11-08 19:40:01 +0000102 return FunctionType::get(ResultTy, ArgTys, IsVarArg);
Wesley Pecka70f28c2010-02-23 19:15:24 +0000103}
104
105Function *MBlazeIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID,
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000106 Type **Tys,
Wesley Pecka70f28c2010-02-23 19:15:24 +0000107 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}