blob: c8c592539513a9a78b6053bdaea46ea5bc455d02 [file] [log] [blame]
Jakob Stoklund Olesen1b2cfa42009-10-15 18:50:52 +00001//===- 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 Wang3b0f2732009-11-05 03:19:08 +000015#include "llvm/DerivedTypes.h"
16#include "llvm/Function.h"
Jakob Stoklund Olesen1b2cfa42009-10-15 18:50:52 +000017#include "llvm/Intrinsics.h"
Mon P Wang3b0f2732009-11-05 03:19:08 +000018#include "llvm/Module.h"
19#include "llvm/Type.h"
Jakob Stoklund Olesen1b2cfa42009-10-15 18:50:52 +000020#include "llvm/Support/raw_ostream.h"
21#include <cstring>
22
23using namespace llvm;
24
25namespace 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 Wang3b0f2732009-11-05 03:19:08 +000037std::string BlackfinIntrinsicInfo::getName(unsigned IntrID, const Type **Tys,
38 unsigned numTys) const {
Jakob Stoklund Olesen1b2cfa42009-10-15 18:50:52 +000039 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 Wang3b0f2732009-11-05 03:19:08 +000045 assert(!isOverloaded(IntrID) && "Blackfin intrinsics are not overloaded");
Jakob Stoklund Olesen1b2cfa42009-10-15 18:50:52 +000046 if (IntrID < Intrinsic::num_intrinsics)
47 return 0;
48 assert(IntrID < bfinIntrinsic::num_bfin_intrinsics && "Invalid intrinsic ID");
49
Mon P Wang3b0f2732009-11-05 03:19:08 +000050 std::string Result(names[IntrID - Intrinsic::num_intrinsics]);
51 return Result;
Jakob Stoklund Olesen1b2cfa42009-10-15 18:50:52 +000052}
53
54unsigned
55BlackfinIntrinsicInfo::lookupName(const char *Name, unsigned Len) const {
56#define GET_FUNCTION_RECOGNIZER
57#include "BlackfinGenIntrinsics.inc"
58#undef GET_FUNCTION_RECOGNIZER
59 return 0;
60}
Mon P Wang3b0f2732009-11-05 03:19:08 +000061
62bool BlackfinIntrinsicInfo::isOverloaded(unsigned IntrID) const {
63 // Overload Table
64 const bool OTable[] = {
65 false, // illegal intrinsic
66#define GET_INTRINSIC_OVERLOAD_TABLE
67#include "BlackfinGenIntrinsics.inc"
68#undef GET_INTRINSIC_OVERLOAD_TABLE
69 };
70 if (IntrID == 0)
71 return false;
72 else
73 return OTable[IntrID - Intrinsic::num_intrinsics];
74}
75
76/// This defines the "getAttributes(ID id)" method.
77#define GET_INTRINSIC_ATTRIBUTES
78#include "BlackfinGenIntrinsics.inc"
79#undef GET_INTRINSIC_ATTRIBUTES
80
81static const FunctionType *getType(LLVMContext &Context, unsigned id) {
82 const Type *ResultTy = NULL;
83 std::vector<const Type*> ArgTys;
84 bool IsVarArg = false;
85
86#define GET_INTRINSIC_GENERATOR
87#include "BlackfinGenIntrinsics.inc"
88#undef GET_INTRINSIC_GENERATOR
89
90 return FunctionType::get(ResultTy, ArgTys, IsVarArg);
91}
92
93Function *BlackfinIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID,
94 const Type **Tys,
95 unsigned numTy) const {
96 assert(!isOverloaded(IntrID) && "Blackfin intrinsics are not overloaded");
97 AttrListPtr AList = getAttributes((bfinIntrinsic::ID) IntrID);
98 return cast<Function>(M->getOrInsertFunction(getName(IntrID),
99 getType(M->getContext(), IntrID),
100 AList));
101}