blob: c8faffc84527365025351a717329fd67b00a3cb0 [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
40std::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
46 };
47
48 assert(!isOverloaded(IntrID) && "MBlaze intrinsics are not overloaded");
49 if (IntrID < Intrinsic::num_intrinsics)
50 return 0;
51 assert(IntrID < mblazeIntrinsic::num_mblaze_intrinsics &&
52 "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 {
60#define GET_FUNCTION_RECOGNIZER
61#include "MBlazeGenIntrinsics.inc"
62#undef GET_FUNCTION_RECOGNIZER
63 return 0;
64}
65
Wesley Peck173c5c42010-02-24 20:16:27 +000066unsigned MBlazeIntrinsicInfo::
67lookupGCCName(const char *Name) const {
68 return mblazeIntrinsic::getIntrinsicForGCCBuiltin("mblaze",Name);
69}
70
Wesley Pecka70f28c2010-02-23 19:15:24 +000071bool MBlazeIntrinsicInfo::isOverloaded(unsigned IntrID) const {
72 // Overload Table
73 const bool OTable[] = {
74#define GET_INTRINSIC_OVERLOAD_TABLE
75#include "MBlazeGenIntrinsics.inc"
76#undef GET_INTRINSIC_OVERLOAD_TABLE
77 };
78 if (IntrID == 0)
79 return false;
80 else
81 return OTable[IntrID - Intrinsic::num_intrinsics];
82}
83
84/// This defines the "getAttributes(ID id)" method.
85#define GET_INTRINSIC_ATTRIBUTES
86#include "MBlazeGenIntrinsics.inc"
87#undef GET_INTRINSIC_ATTRIBUTES
88
89static const FunctionType *getType(LLVMContext &Context, unsigned id) {
90 const Type *ResultTy = NULL;
91 std::vector<const Type*> ArgTys;
92 bool IsVarArg = false;
93
94#define GET_INTRINSIC_GENERATOR
95#include "MBlazeGenIntrinsics.inc"
96#undef GET_INTRINSIC_GENERATOR
97
98 return FunctionType::get(ResultTy, ArgTys, IsVarArg);
99}
100
101Function *MBlazeIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID,
102 const Type **Tys,
103 unsigned numTy) const {
104 assert(!isOverloaded(IntrID) && "MBlaze intrinsics are not overloaded");
105 AttrListPtr AList = getAttributes((mblazeIntrinsic::ID) IntrID);
106 return cast<Function>(M->getOrInsertFunction(getName(IntrID),
107 getType(M->getContext(), IntrID),
108 AList));
109}