1 //===------------------------- ManglingUtils.cpp -------------------------===// 2 // 3 // SPIR Tools 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===---------------------------------------------------------------------===// 9 /* 10 * Contributed by: Intel Corporation. 11 */ 12 13 #include "ManglingUtils.h" 14 15 namespace SPIR { 16 17 // String represenration for the primitive types. 18 static const char* PrimitiveNames[PRIMITIVE_NUM] ={ 19 "bool", 20 "uchar", 21 "char", 22 "ushort", 23 "short", 24 "uint", 25 "int", 26 "ulong", 27 "long", 28 "half", 29 "float", 30 "double", 31 "void", 32 "...", 33 "image1d_t", 34 "image1d_array_t", 35 "image1d_buffer_t", 36 "image2d_t", 37 "image2d_array_t", 38 "image3d_t", 39 "image2d_msaa_t", 40 "image2d_array_msaa_t", 41 "image2d_msaa_depth_t", 42 "image2d_array_msaa_depth_t", 43 "image2d_depth_t", 44 "image2d_array_depth_t", 45 "event_t", 46 "pipe_t", 47 "reserve_id_t", 48 "queue_t", 49 "ndrange_t", 50 "clk_event_t", 51 "sampler_t", 52 "kernel_enqueue_flags_t", 53 "clk_profiling_info", 54 }; 55 56 const char* mangledTypes[PRIMITIVE_NUM] = { 57 "b", //BOOL 58 "h", //UCHAR 59 "c", //CHAR 60 "t", //USHORT 61 "s", //SHORT 62 "j", //UINT 63 "i", //INT 64 "m", //ULONG 65 "l", //LONG 66 "Dh", //HALF 67 "f", //FLOAT 68 "d", //DOUBLE 69 "v", //VOID 70 "z", //VarArg 71 "11ocl_image1d", //PRIMITIVE_IMAGE_1D_T 72 "16ocl_image1darray", //PRIMITIVE_IMAGE_1D_ARRAY_T 73 "17ocl_image1dbuffer", //PRIMITIVE_IMAGE_1D_BUFFER_T 74 "11ocl_image2d", //PRIMITIVE_IMAGE_2D_T 75 "16ocl_image2darray", //PRIMITIVE_IMAGE_2D_ARRAY_T 76 "11ocl_image3d", //PRIMITIVE_IMAGE_3D_T 77 "15ocl_image2dmsaa", //PRIMITIVE_IMAGE_2D_MSAA_T 78 "20ocl_image2darraymsaa", //PRIMITIVE_IMAGE_2D_ARRAY_MSAA_T 79 "20ocl_image2dmsaadepth", //PRIMITIVE_IMAGE_2D_MSAA_DEPTH_T 80 "25ocl_image2darraymsaadepth", //PRIMITIVE_IMAGE_2D_ARRAY_MSAA_DEPTH_T 81 "16ocl_image2ddepth", //PRIMITIVE_IMAGE_2D_DEPTH_T 82 "21ocl_image2darraydepth", //PRIMITIVE_IMAGE_2D_ARRAY_DEPTH_T 83 "9ocl_event", //PRIMITIVE_EVENT_T 84 "8ocl_pipe", //PRIMITIVE_PIPE_T 85 "13ocl_reserveid", //PRIMITIVE_RESERVE_ID_T 86 "9ocl_queue", //PRIMITIVE_QUEUE_T 87 "9ndrange_t", //PRIMITIVE_NDRANGE_T 88 "12ocl_clkevent", //PRIMITIVE_CLK_EVENT_T 89 "11ocl_sampler", //PRIMITIVE_SAMPLER_T 90 #if defined(SPIRV_SPIR20_MANGLING_REQUIREMENTS) 91 "i", //PRIMITIVE_KERNEL_ENQUEUE_FLAGS_T 92 "i", //PRIMITIVE_CLK_PROFILING_INFO 93 #else 94 "22kernel_enqueue_flags_t", //PRIMITIVE_KERNEL_ENQUEUE_FLAGS_T 95 "18clk_profiling_info", //PRIMITIVE_CLK_PROFILING_INFO 96 #endif 97 }; 98 99 const char* readableAttribute[ATTR_NUM] = { 100 "restrict", 101 "volatile", 102 "const", 103 "__private", 104 "__global", 105 "__constant", 106 "__local", 107 "__generic", 108 }; 109 110 const char* mangledAttribute[ATTR_NUM] = { 111 "r", 112 "V", 113 "K", 114 "", 115 "U3AS1", 116 "U3AS2", 117 "U3AS3", 118 "U3AS4", 119 }; 120 121 // SPIR supported version - stated version is oldest supported version. 122 static const SPIRversion primitiveSupportedVersions[PRIMITIVE_NUM] ={ 123 SPIR12, //BOOL 124 SPIR12, //UCHAR 125 SPIR12, //CHAR 126 SPIR12, //USHORT 127 SPIR12, //SHORT 128 SPIR12, //UINT 129 SPIR12, //INT 130 SPIR12, //ULONG 131 SPIR12, //LONG 132 SPIR12, //HALF 133 SPIR12, //FLOAT 134 SPIR12, //DOUBLE 135 SPIR12, //VOID 136 SPIR12, //VarArg 137 SPIR12, //PRIMITIVE_IMAGE_1D_T 138 SPIR12, //PRIMITIVE_IMAGE_1D_ARRAY_T 139 SPIR12, //PRIMITIVE_IMAGE_1D_BUFFER_T 140 SPIR12, //PRIMITIVE_IMAGE_2D_T 141 SPIR12, //PRIMITIVE_IMAGE_2D_ARRAY_T 142 SPIR12, //PRIMITIVE_IMAGE_3D_T 143 SPIR12, //PRIMITIVE_IMAGE_2D_MSAA_T 144 SPIR12, //PRIMITIVE_IMAGE_2D_ARRAY_MSAA_T 145 SPIR12, //PRIMITIVE_IMAGE_2D_MSAA_DEPTH_T 146 SPIR12, //PRIMITIVE_IMAGE_2D_ARRAY_MSAA_DEPTH_T 147 SPIR12, //PRIMITIVE_IMAGE_2D_DEPTH_T 148 SPIR12, //PRIMITIVE_IMAGE_2D_ARRAY_DEPTH_T 149 SPIR12, //PRIMITIVE_EVENT_T 150 SPIR20, //PRIMITIVE_PIPE_T 151 SPIR20, //PRIMITIVE_RESERVE_ID_T 152 SPIR20, //PRIMITIVE_QUEUE_T 153 SPIR20, //PRIMITIVE_NDRANGE_T 154 SPIR20, //PRIMITIVE_CLK_EVENT_T 155 SPIR12 //PRIMITIVE_SAMPLER_T 156 }; 157 158 const char* mangledPrimitiveString(TypePrimitiveEnum t) { 159 return mangledTypes[t]; 160 } 161 162 const char* readablePrimitiveString(TypePrimitiveEnum t) { 163 return PrimitiveNames[t]; 164 } 165 166 const char* getMangledAttribute(TypeAttributeEnum attribute) { 167 return mangledAttribute[attribute]; 168 } 169 170 const char* getReadableAttribute(TypeAttributeEnum attribute) { 171 return readableAttribute[attribute]; 172 } 173 174 SPIRversion getSupportedVersion(TypePrimitiveEnum t) { 175 return primitiveSupportedVersions[t]; 176 } 177 178 const char* mangledPrimitiveStringfromName(std::string type) { 179 for (size_t i = 0; i < (sizeof(PrimitiveNames) / sizeof(PrimitiveNames[0])); i++) 180 if (type.compare(PrimitiveNames[i]) == 0) 181 return mangledTypes[i]; 182 return NULL; 183 } 184 185 const char* getSPIRVersionAsString(SPIRversion version) { 186 switch (version) { 187 case SPIR12: return "SPIR 1.2"; 188 case SPIR20: return "SPIR 2.0"; 189 default: 190 assert(false && "Unknown SPIR Version"); 191 return "Unknown SPIR Version"; 192 } 193 } 194 195 } // End SPIR namespace 196