summaryrefslogtreecommitdiff
path: root/lib/SPIRV/Mangler/ManglingUtils.cpp
blob: 41a55af93f9df782df9b68bed5082b76f396bfbe (plain)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//===------------------------- ManglingUtils.cpp -------------------------===//
//
//                              SPIR Tools
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===---------------------------------------------------------------------===//
/*
 * Contributed by: Intel Corporation.
 */

#include "ManglingUtils.h"

namespace SPIR {

// String represenration for the primitive types.
static const char *PrimitiveNames[PRIMITIVE_NUM] = {
    "bool",
    "uchar",
    "char",
    "ushort",
    "short",
    "uint",
    "int",
    "ulong",
    "long",
    "half",
    "float",
    "double",
    "void",
    "...",
    "image1d_t",
    "image1d_array_t",
    "image1d_buffer_t",
    "image2d_t",
    "image2d_array_t",
    "image3d_t",
    "image2d_msaa_t",
    "image2d_array_msaa_t",
    "image2d_msaa_depth_t",
    "image2d_array_msaa_depth_t",
    "image2d_depth_t",
    "image2d_array_depth_t",
    "event_t",
    "pipe_t",
    "reserve_id_t",
    "queue_t",
    "ndrange_t",
    "clk_event_t",
    "sampler_t",
    "kernel_enqueue_flags_t",
    "clk_profiling_info",
    "memory_order",
    "memory_scope"};

const char *mangledTypes[PRIMITIVE_NUM] = {
    "b",                           // BOOL
    "h",                           // UCHAR
    "c",                           // CHAR
    "t",                           // USHORT
    "s",                           // SHORT
    "j",                           // UINT
    "i",                           // INT
    "m",                           // ULONG
    "l",                           // LONG
    "Dh",                          // HALF
    "f",                           // FLOAT
    "d",                           // DOUBLE
    "v",                           // VOID
    "z",                           // VarArg
    "11ocl_image1d",               // PRIMITIVE_IMAGE_1D_T
    "16ocl_image1darray",          // PRIMITIVE_IMAGE_1D_ARRAY_T
    "17ocl_image1dbuffer",         // PRIMITIVE_IMAGE_1D_BUFFER_T
    "11ocl_image2d",               // PRIMITIVE_IMAGE_2D_T
    "16ocl_image2darray",          // PRIMITIVE_IMAGE_2D_ARRAY_T
    "11ocl_image3d",               // PRIMITIVE_IMAGE_3D_T
    "15ocl_image2dmsaa",           // PRIMITIVE_IMAGE_2D_MSAA_T
    "20ocl_image2darraymsaa",      // PRIMITIVE_IMAGE_2D_ARRAY_MSAA_T
    "20ocl_image2dmsaadepth",      // PRIMITIVE_IMAGE_2D_MSAA_DEPTH_T
    "25ocl_image2darraymsaadepth", // PRIMITIVE_IMAGE_2D_ARRAY_MSAA_DEPTH_T
    "16ocl_image2ddepth",          // PRIMITIVE_IMAGE_2D_DEPTH_T
    "21ocl_image2darraydepth",     // PRIMITIVE_IMAGE_2D_ARRAY_DEPTH_T
    "9ocl_event",                  // PRIMITIVE_EVENT_T
    "8ocl_pipe",                   // PRIMITIVE_PIPE_T
    "13ocl_reserveid",             // PRIMITIVE_RESERVE_ID_T
    "9ocl_queue",                  // PRIMITIVE_QUEUE_T
    "9ndrange_t",                  // PRIMITIVE_NDRANGE_T
    "12ocl_clkevent",              // PRIMITIVE_CLK_EVENT_T
    "11ocl_sampler",               // PRIMITIVE_SAMPLER_T
    "i",                           // PRIMITIVE_KERNEL_ENQUEUE_FLAGS_T
    "i",                           // PRIMITIVE_CLK_PROFILING_INFO
#if defined(SPIRV_SPIR20_MANGLING_REQUIREMENTS)
    "i", // PRIMITIVE_MEMORY_ORDER
    "i", // PRIMITIVE_MEMORY_SCOPE
#else
    "12memory_order", // PRIMITIVE_MEMORY_ORDER
    "12memory_scope"  // PRIMITIVE_MEMORY_SCOPE
#endif
};

const char *readableAttribute[ATTR_NUM] = {
    "restrict", "volatile",   "const",   "__private",
    "__global", "__constant", "__local", "__generic",
};

const char *mangledAttribute[ATTR_NUM] = {
    "r", "V", "K", "", "U3AS1", "U3AS2", "U3AS3", "U3AS4",
};

// SPIR supported version - stated version is oldest supported version.
static const SPIRversion primitiveSupportedVersions[PRIMITIVE_NUM] = {
    SPIR12, // BOOL
    SPIR12, // UCHAR
    SPIR12, // CHAR
    SPIR12, // USHORT
    SPIR12, // SHORT
    SPIR12, // UINT
    SPIR12, // INT
    SPIR12, // ULONG
    SPIR12, // LONG
    SPIR12, // HALF
    SPIR12, // FLOAT
    SPIR12, // DOUBLE
    SPIR12, // VOID
    SPIR12, // VarArg
    SPIR12, // PRIMITIVE_IMAGE_1D_T
    SPIR12, // PRIMITIVE_IMAGE_1D_ARRAY_T
    SPIR12, // PRIMITIVE_IMAGE_1D_BUFFER_T
    SPIR12, // PRIMITIVE_IMAGE_2D_T
    SPIR12, // PRIMITIVE_IMAGE_2D_ARRAY_T
    SPIR12, // PRIMITIVE_IMAGE_3D_T
    SPIR12, // PRIMITIVE_IMAGE_2D_MSAA_T
    SPIR12, // PRIMITIVE_IMAGE_2D_ARRAY_MSAA_T
    SPIR12, // PRIMITIVE_IMAGE_2D_MSAA_DEPTH_T
    SPIR12, // PRIMITIVE_IMAGE_2D_ARRAY_MSAA_DEPTH_T
    SPIR12, // PRIMITIVE_IMAGE_2D_DEPTH_T
    SPIR12, // PRIMITIVE_IMAGE_2D_ARRAY_DEPTH_T
    SPIR12, // PRIMITIVE_EVENT_T
    SPIR20, // PRIMITIVE_PIPE_T
    SPIR20, // PRIMITIVE_RESERVE_ID_T
    SPIR20, // PRIMITIVE_QUEUE_T
    SPIR20, // PRIMITIVE_NDRANGE_T
    SPIR20, // PRIMITIVE_CLK_EVENT_T
    SPIR12  // PRIMITIVE_SAMPLER_T
};

const char *mangledPrimitiveString(TypePrimitiveEnum t) {
  return mangledTypes[t];
}

const char *readablePrimitiveString(TypePrimitiveEnum t) {
  return PrimitiveNames[t];
}

const char *getMangledAttribute(TypeAttributeEnum attribute) {
  return mangledAttribute[attribute];
}

const char *getReadableAttribute(TypeAttributeEnum attribute) {
  return readableAttribute[attribute];
}

SPIRversion getSupportedVersion(TypePrimitiveEnum t) {
  return primitiveSupportedVersions[t];
}

const char *mangledPrimitiveStringfromName(std::string type) {
  for (size_t i = 0; i < (sizeof(PrimitiveNames) / sizeof(PrimitiveNames[0]));
       i++)
    if (type.compare(PrimitiveNames[i]) == 0)
      return mangledTypes[i];
  return NULL;
}

const char *getSPIRVersionAsString(SPIRversion version) {
  switch (version) {
  case SPIR12:
    return "SPIR 1.2";
  case SPIR20:
    return "SPIR 2.0";
  default:
    assert(false && "Unknown SPIR Version");
    return "Unknown SPIR Version";
  }
}

bool isPipeBuiltin(std::string unmangledName) {
  return unmangledName == "write_pipe" || unmangledName == "read_pipe" ||
         unmangledName == "reserve_write_pipe" ||
         unmangledName == "reserve_read_pipe" ||
         unmangledName == "commit_write_pipe" ||
         unmangledName == "commit_read_pipe" ||
         unmangledName == "work_group_reserve_write_pipe" ||
         unmangledName == "work_group_reserve_read_pipe" ||
         unmangledName == "work_group_commit_write_pipe" ||
         unmangledName == "work_group_commit_read_pipe" ||
         unmangledName == "get_pipe_num_packets" ||
         unmangledName == "get_pipe_max_packets" ||
         unmangledName == "sub_group_reserve_write_pipe" ||
         unmangledName == "sub_group_reserve_read_pipe" ||
         unmangledName == "sub_group_commit_write_pipe" ||
         unmangledName == "sub_group_commit_read_pipe";
}

} // namespace SPIR