1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
//===- AMDILIntrinsicInfo.cpp - AMDIL Intrinsic Information ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//==-----------------------------------------------------------------------===//
//
// This file contains the AMDIL Implementation of the IntrinsicInfo class.
//
//===-----------------------------------------------------------------------===//
#include "AMDILIntrinsicInfo.h"
#include "AMDIL.h"
#include "AMDILSubtarget.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Intrinsics.h"
#include "llvm/Module.h"
using namespace llvm;
#define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
#include "AMDILGenIntrinsics.inc"
#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
AMDILIntrinsicInfo::AMDILIntrinsicInfo(TargetMachine *tm)
: TargetIntrinsicInfo(), mTM(tm)
{
}
std::string
AMDILIntrinsicInfo::getName(unsigned int IntrID, Type **Tys,
unsigned int numTys) const
{
static const char* const names[] = {
#define GET_INTRINSIC_NAME_TABLE
#include "AMDILGenIntrinsics.inc"
#undef GET_INTRINSIC_NAME_TABLE
};
//assert(!isOverloaded(IntrID)
//&& "AMDIL Intrinsics are not overloaded");
if (IntrID < Intrinsic::num_intrinsics) {
return 0;
}
assert(IntrID < AMDGPUIntrinsic::num_AMDIL_intrinsics
&& "Invalid intrinsic ID");
std::string Result(names[IntrID - Intrinsic::num_intrinsics]);
return Result;
}
static bool
checkTruncation(const char *Name, unsigned int& Len)
{
const char *ptr = Name + (Len - 1);
while(ptr != Name && *ptr != '_') {
--ptr;
}
// We don't want to truncate on atomic instructions
// but we do want to enter the check Truncation
// section so that we can translate the atomic
// instructions if we need to.
if (!strncmp(Name, "__atom", 6)) {
return true;
}
if (strstr(ptr, "i32")
|| strstr(ptr, "u32")
|| strstr(ptr, "i64")
|| strstr(ptr, "u64")
|| strstr(ptr, "f32")
|| strstr(ptr, "f64")
|| strstr(ptr, "i16")
|| strstr(ptr, "u16")
|| strstr(ptr, "i8")
|| strstr(ptr, "u8")) {
Len = (unsigned int)(ptr - Name);
return true;
}
return false;
}
// We don't want to support both the OpenCL 1.0 atomics
// and the 1.1 atomics with different names, so we translate
// the 1.0 atomics to the 1.1 naming here if needed.
static char*
atomTranslateIfNeeded(const char *Name, unsigned int Len)
{
char *buffer = NULL;
if (strncmp(Name, "__atom_", 7)) {
// If we are not starting with __atom_, then
// go ahead and continue on with the allocation.
buffer = new char[Len + 1];
memcpy(buffer, Name, Len);
} else {
buffer = new char[Len + 3];
memcpy(buffer, "__atomic_", 9);
memcpy(buffer + 9, Name + 7, Len - 7);
Len += 2;
}
buffer[Len] = '\0';
return buffer;
}
unsigned int
AMDILIntrinsicInfo::lookupName(const char *Name, unsigned int Len) const
{
#define GET_FUNCTION_RECOGNIZER
#include "AMDILGenIntrinsics.inc"
#undef GET_FUNCTION_RECOGNIZER
AMDGPUIntrinsic::ID IntrinsicID
= (AMDGPUIntrinsic::ID)Intrinsic::not_intrinsic;
if (checkTruncation(Name, Len)) {
char *buffer = atomTranslateIfNeeded(Name, Len);
IntrinsicID = getIntrinsicForGCCBuiltin("AMDIL", buffer);
delete [] buffer;
} else {
IntrinsicID = getIntrinsicForGCCBuiltin("AMDIL", Name);
}
if (!isValidIntrinsic(IntrinsicID)) {
return 0;
}
if (IntrinsicID != (AMDGPUIntrinsic::ID)Intrinsic::not_intrinsic) {
return IntrinsicID;
}
return 0;
}
bool
AMDILIntrinsicInfo::isOverloaded(unsigned id) const
{
// Overload Table
#define GET_INTRINSIC_OVERLOAD_TABLE
#include "AMDILGenIntrinsics.inc"
#undef GET_INTRINSIC_OVERLOAD_TABLE
}
/// This defines the "getAttributes(ID id)" method.
#define GET_INTRINSIC_ATTRIBUTES
#include "AMDILGenIntrinsics.inc"
#undef GET_INTRINSIC_ATTRIBUTES
Function*
AMDILIntrinsicInfo::getDeclaration(Module *M, unsigned IntrID,
Type **Tys,
unsigned numTys) const
{
assert(!"Not implemented");
}
/// Because the code generator has to support different SC versions,
/// this function is added to check that the intrinsic being used
/// is actually valid. In the case where it isn't valid, the
/// function call is not translated into an intrinsic and the
/// fall back software emulated path should pick up the result.
bool
AMDILIntrinsicInfo::isValidIntrinsic(unsigned int IntrID) const
{
const AMDILSubtarget &STM = mTM->getSubtarget<AMDILSubtarget>();
switch (IntrID) {
default:
return true;
case AMDGPUIntrinsic::AMDIL_convert_f32_i32_rpi:
case AMDGPUIntrinsic::AMDIL_convert_f32_i32_flr:
case AMDGPUIntrinsic::AMDIL_convert_f32_f16_near:
case AMDGPUIntrinsic::AMDIL_convert_f32_f16_neg_inf:
case AMDGPUIntrinsic::AMDIL_convert_f32_f16_plus_inf:
return STM.calVersion() >= CAL_VERSION_SC_139;
};
}
|