blob: 0d3f7d8cfe943c3d76e7ad7c3a151ea0520d982d [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- MBlazeIntrinsicInfo.cpp - Intrinsic Information -------------------===//
Wesley Pecka70f28c2010-02-23 19:15:24 +00002//
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"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000015#include "llvm/IR/DerivedTypes.h"
16#include "llvm/IR/Function.h"
17#include "llvm/IR/Intrinsics.h"
18#include "llvm/IR/Module.h"
19#include "llvm/IR/Type.h"
Craig Topper655b8de2012-02-05 07:21:30 +000020#include "llvm/Support/ErrorHandling.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000021#include "llvm/Support/raw_ostream.h"
Wesley Pecka70f28c2010-02-23 19:15:24 +000022#include <cstring>
23
24using namespace llvm;
25
26namespace mblazeIntrinsic {
27
28 enum ID {
29 last_non_mblaze_intrinsic = Intrinsic::num_intrinsics-1,
30#define GET_INTRINSIC_ENUM_VALUES
31#include "MBlazeGenIntrinsics.inc"
32#undef GET_INTRINSIC_ENUM_VALUES
33 , num_mblaze_intrinsics
34 };
35
Wesley Peck173c5c42010-02-24 20:16:27 +000036#define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
37#include "MBlazeGenIntrinsics.inc"
38#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
Wesley Pecka70f28c2010-02-23 19:15:24 +000039}
40
Chris Lattnerdb125cf2011-07-18 04:54:35 +000041std::string MBlazeIntrinsicInfo::getName(unsigned IntrID, Type **Tys,
Wesley Pecka70f28c2010-02-23 19:15:24 +000042 unsigned numTys) const {
43 static const char *const names[] = {
44#define GET_INTRINSIC_NAME_TABLE
45#include "MBlazeGenIntrinsics.inc"
46#undef GET_INTRINSIC_NAME_TABLE
47 };
48
49 assert(!isOverloaded(IntrID) && "MBlaze intrinsics are not overloaded");
50 if (IntrID < Intrinsic::num_intrinsics)
51 return 0;
Wesley Peck0a67d922010-11-08 19:40:01 +000052 assert(IntrID < mblazeIntrinsic::num_mblaze_intrinsics &&
Wesley Pecka70f28c2010-02-23 19:15:24 +000053 "Invalid intrinsic ID");
54
55 std::string Result(names[IntrID - Intrinsic::num_intrinsics]);
56 return Result;
57}
58
59unsigned MBlazeIntrinsicInfo::
60lookupName(const char *Name, unsigned Len) const {
Rafael Espindola431c73b2013-05-22 14:57:42 +000061 if (!StringRef(Name, Len).startswith("llvm."))
62 return 0; // All intrinsics start with 'llvm.'
Bob Wilson35ee7d62010-03-18 16:52:15 +000063
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 {
Benjamin Kramer36a21382012-03-01 02:16:57 +000076 if (IntrID == 0)
77 return false;
78
79 unsigned id = IntrID - Intrinsic::num_intrinsics + 1;
Wesley Pecka70f28c2010-02-23 19:15:24 +000080#define GET_INTRINSIC_OVERLOAD_TABLE
81#include "MBlazeGenIntrinsics.inc"
82#undef GET_INTRINSIC_OVERLOAD_TABLE
Wesley Pecka70f28c2010-02-23 19:15:24 +000083}
84
Bill Wendlingcb3de0b2012-10-15 04:46:55 +000085/// This defines the "getAttributes(LLVMContext &C, ID id)" method.
Wesley Pecka70f28c2010-02-23 19:15:24 +000086#define GET_INTRINSIC_ATTRIBUTES
87#include "MBlazeGenIntrinsics.inc"
88#undef GET_INTRINSIC_ATTRIBUTES
89
Chris Lattnerdb125cf2011-07-18 04:54:35 +000090static FunctionType *getType(LLVMContext &Context, unsigned id) {
91 Type *ResultTy = NULL;
Benjamin Kramerd2c6ff12011-10-17 21:33:26 +000092 SmallVector<Type*, 8> ArgTys;
Wesley Pecka70f28c2010-02-23 19:15:24 +000093 bool IsVarArg = false;
Wesley Peck0a67d922010-11-08 19:40:01 +000094
Wesley Pecka70f28c2010-02-23 19:15:24 +000095#define GET_INTRINSIC_GENERATOR
96#include "MBlazeGenIntrinsics.inc"
97#undef GET_INTRINSIC_GENERATOR
98
Wesley Peck0a67d922010-11-08 19:40:01 +000099 return FunctionType::get(ResultTy, ArgTys, IsVarArg);
Wesley Pecka70f28c2010-02-23 19:15:24 +0000100}
101
102Function *MBlazeIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID,
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000103 Type **Tys,
Wesley Pecka70f28c2010-02-23 19:15:24 +0000104 unsigned numTy) const {
105 assert(!isOverloaded(IntrID) && "MBlaze intrinsics are not overloaded");
Bill Wendling99faa3b2012-12-07 23:16:57 +0000106 AttributeSet AList = getAttributes(M->getContext(),
Bill Wendlingcb3de0b2012-10-15 04:46:55 +0000107 (mblazeIntrinsic::ID) IntrID);
Wesley Pecka70f28c2010-02-23 19:15:24 +0000108 return cast<Function>(M->getOrInsertFunction(getName(IntrID),
109 getType(M->getContext(), IntrID),
110 AList));
111}