@@ -242,12 +242,17 @@ Type *BuiltinCallHelper::adjustImageType(Type *T, StringRef OldImageKind,
242
242
Type *StructTy = TypedPtrTy->getElementType ();
243
243
// Adapt opencl.* struct type names to spirv.* struct type names.
244
244
if (isOCLImageType (T)) {
245
+ if (OldImageKind != kSPIRVTypeName ::Image)
246
+ report_fatal_error (" Type was not an image type" );
245
247
auto ImageTypeName = StructTy->getStructName ();
246
- StringRef Acc = kAccessQualName ::ReadOnly;
248
+ auto Desc =
249
+ map<SPIRVTypeImageDescriptor>(getImageBaseTypeName (ImageTypeName));
250
+ spv::AccessQualifier Acc = AccessQualifierReadOnly;
247
251
if (hasAccessQualifiedName (ImageTypeName))
248
- Acc = getAccessQualifierFullName (ImageTypeName);
249
- StructTy = getOrCreateOpaqueStructType (
250
- M, mapOCLTypeNameToSPIRV (ImageTypeName, Acc));
252
+ Acc = getAccessQualifier (ImageTypeName);
253
+ auto NewImageType = SPIRVOpaqueTypeOpCodeMap::map (NewImageKind.str ());
254
+ return getSPIRVType (NewImageType, Type::getVoidTy (M->getContext ()), Desc,
255
+ Acc);
251
256
}
252
257
253
258
// Change type name (e.g., spirv.Image -> spirv.SampledImg) if necessary.
@@ -263,6 +268,53 @@ Type *BuiltinCallHelper::adjustImageType(Type *T, StringRef OldImageKind,
263
268
report_fatal_error (" Expected type to be a SPIRV image type" );
264
269
}
265
270
271
+ Type *BuiltinCallHelper::getSPIRVType (spv::Op TypeOpcode, bool UseRealType) {
272
+ return getSPIRVType (TypeOpcode, " " , {}, UseRealType);
273
+ }
274
+
275
+ Type *BuiltinCallHelper::getSPIRVType (spv::Op TypeOpcode,
276
+ spv::AccessQualifier Access,
277
+ bool UseRealType) {
278
+ return getSPIRVType (TypeOpcode, " " , {(unsigned )Access}, UseRealType);
279
+ }
280
+
281
+ Type *BuiltinCallHelper::getSPIRVType (spv::Op TypeOpcode, Type *InnerType,
282
+ SPIRVTypeImageDescriptor Desc,
283
+ Optional<spv::AccessQualifier> Access,
284
+ bool UseRealType) {
285
+ return getSPIRVType (TypeOpcode, convertTypeToPostfix (InnerType),
286
+ {(unsigned )Desc.Dim , (unsigned )Desc.Depth ,
287
+ (unsigned )Desc.Arrayed , (unsigned )Desc.MS ,
288
+ (unsigned )Desc.Sampled , (unsigned )Desc.Format ,
289
+ (unsigned )Access.value_or (AccessQualifierReadOnly)},
290
+ UseRealType);
291
+ }
292
+
293
+ Type *BuiltinCallHelper::getSPIRVType (spv::Op TypeOpcode,
294
+ StringRef InnerTypeName,
295
+ ArrayRef<unsigned > Parameters,
296
+ bool UseRealType) {
297
+ std::string FullName;
298
+ {
299
+ raw_string_ostream OS (FullName);
300
+ OS << kSPIRVTypeName ::PrefixAndDelim
301
+ << SPIRVOpaqueTypeOpCodeMap::rmap (TypeOpcode);
302
+ if (!InnerTypeName.empty () || !Parameters.empty ())
303
+ OS << kSPIRVTypeName ::Delimiter;
304
+ if (!InnerTypeName.empty ())
305
+ OS << kSPIRVTypeName ::PostfixDelim << InnerTypeName;
306
+ for (unsigned IntParam : Parameters)
307
+ OS << kSPIRVTypeName ::PostfixDelim << IntParam;
308
+ }
309
+ auto *STy = StructType::getTypeByName (M->getContext (), FullName);
310
+ if (!STy)
311
+ STy = StructType::create (M->getContext (), FullName);
312
+
313
+ unsigned AddrSpace = getOCLOpaqueTypeAddrSpace (TypeOpcode);
314
+ return UseRealType ? (Type *)PointerType::get (STy, AddrSpace)
315
+ : TypedPointerType::get (STy, AddrSpace);
316
+ }
317
+
266
318
BuiltinCallMutator::ValueTypePair
267
319
BuiltinCallHelper::getCallValue (CallInst *CI, unsigned ArgNo) {
268
320
Function *CalledFunc = CI->getCalledFunction ();
0 commit comments