@@ -1775,7 +1775,7 @@ static const Type *getMachineInstrType(MachineInstr *MI) {
1775
1775
return nullptr ;
1776
1776
Type *Ty = getMDOperandAsType (NextMI->getOperand (2 ).getMetadata (), 0 );
1777
1777
assert (Ty && " Type is expected" );
1778
- return getTypedPtrEltType (Ty) ;
1778
+ return Ty ;
1779
1779
}
1780
1780
1781
1781
static const Type *getBlockStructType (Register ParamReg,
@@ -1787,7 +1787,7 @@ static const Type *getBlockStructType(Register ParamReg,
1787
1787
// section 6.12.5 should guarantee that we can do this.
1788
1788
MachineInstr *MI = getBlockStructInstr (ParamReg, MRI);
1789
1789
if (MI->getOpcode () == TargetOpcode::G_GLOBAL_VALUE)
1790
- return getTypedPtrEltType ( MI->getOperand (1 ).getGlobal ()->getType () );
1790
+ return MI->getOperand (1 ).getGlobal ()->getType ();
1791
1791
assert (isSpvIntrinsic (*MI, Intrinsic::spv_alloca) &&
1792
1792
" Blocks in OpenCL C must be traceable to allocation site" );
1793
1793
return getMachineInstrType (MI);
@@ -2043,7 +2043,8 @@ static bool generateVectorLoadStoreInst(const SPIRV::IncomingCall *Call,
2043
2043
.addImm (Builtin->Number );
2044
2044
for (auto Argument : Call->Arguments )
2045
2045
MIB.addUse (Argument);
2046
- MIB.addImm (Builtin->ElementCount );
2046
+ if (Builtin->Name .contains (" load" ) && Builtin->ElementCount > 1 )
2047
+ MIB.addImm (Builtin->ElementCount );
2047
2048
2048
2049
// Rounding mode should be passed as a last argument in the MI for builtins
2049
2050
// like "vstorea_halfn_r".
@@ -2179,6 +2180,61 @@ std::optional<bool> lowerBuiltin(const StringRef DemangledCall,
2179
2180
return false ;
2180
2181
}
2181
2182
2183
+ Type *parseBuiltinCallArgumentBaseType (const StringRef DemangledCall,
2184
+ unsigned ArgIdx, LLVMContext &Ctx) {
2185
+ SmallVector<StringRef, 10 > BuiltinArgsTypeStrs;
2186
+ StringRef BuiltinArgs =
2187
+ DemangledCall.slice (DemangledCall.find (' (' ) + 1 , DemangledCall.find (' )' ));
2188
+ BuiltinArgs.split (BuiltinArgsTypeStrs, ' ,' , -1 , false );
2189
+ if (ArgIdx >= BuiltinArgsTypeStrs.size ())
2190
+ return nullptr ;
2191
+ StringRef TypeStr = BuiltinArgsTypeStrs[ArgIdx].trim ();
2192
+
2193
+ // Parse strings representing OpenCL builtin types.
2194
+ if (hasBuiltinTypePrefix (TypeStr)) {
2195
+ // OpenCL builtin types in demangled call strings have the following format:
2196
+ // e.g. ocl_image2d_ro
2197
+ bool IsOCLBuiltinType = TypeStr.consume_front (" ocl_" );
2198
+ assert (IsOCLBuiltinType && " Invalid OpenCL builtin prefix" );
2199
+
2200
+ // Check if this is pointer to a builtin type and not just pointer
2201
+ // representing a builtin type. In case it is a pointer to builtin type,
2202
+ // this will require additional handling in the method calling
2203
+ // parseBuiltinCallArgumentBaseType(...) as this function only retrieves the
2204
+ // base types.
2205
+ if (TypeStr.ends_with (" *" ))
2206
+ TypeStr = TypeStr.slice (0 , TypeStr.find_first_of (" " ));
2207
+
2208
+ return parseBuiltinTypeNameToTargetExtType (" opencl." + TypeStr.str () + " _t" ,
2209
+ Ctx);
2210
+ }
2211
+
2212
+ // Parse type name in either "typeN" or "type vector[N]" format, where
2213
+ // N is the number of elements of the vector.
2214
+ Type *BaseType;
2215
+ unsigned VecElts = 0 ;
2216
+
2217
+ BaseType = parseBasicTypeName (TypeStr, Ctx);
2218
+ if (!BaseType)
2219
+ // Unable to recognize SPIRV type name.
2220
+ return nullptr ;
2221
+
2222
+ if (BaseType->isVoidTy ())
2223
+ BaseType = Type::getInt8Ty (Ctx);
2224
+
2225
+ // Handle "typeN*" or "type vector[N]*".
2226
+ TypeStr.consume_back (" *" );
2227
+
2228
+ if (TypeStr.consume_front (" vector[" ))
2229
+ TypeStr = TypeStr.substr (0 , TypeStr.find (' ]' ));
2230
+
2231
+ TypeStr.getAsInteger (10 , VecElts);
2232
+ if (VecElts > 0 )
2233
+ BaseType = VectorType::get (BaseType, VecElts, false );
2234
+
2235
+ return BaseType;
2236
+ }
2237
+
2182
2238
struct BuiltinType {
2183
2239
StringRef Name;
2184
2240
uint32_t Opcode;
@@ -2277,9 +2333,8 @@ static SPIRVType *getSampledImageType(const TargetExtType *OpaqueType,
2277
2333
}
2278
2334
2279
2335
namespace SPIRV {
2280
- const TargetExtType *
2281
- parseBuiltinTypeNameToTargetExtType (std::string TypeName,
2282
- MachineIRBuilder &MIRBuilder) {
2336
+ TargetExtType *parseBuiltinTypeNameToTargetExtType (std::string TypeName,
2337
+ LLVMContext &Context) {
2283
2338
StringRef NameWithParameters = TypeName;
2284
2339
2285
2340
// Pointers-to-opaque-structs representing OpenCL types are first translated
@@ -2303,7 +2358,7 @@ parseBuiltinTypeNameToTargetExtType(std::string TypeName,
2303
2358
// Parameterized SPIR-V builtins names follow this format:
2304
2359
// e.g. %spirv.Image._void_1_0_0_0_0_0_0, %spirv.Pipe._0
2305
2360
if (!NameWithParameters.contains (' _' ))
2306
- return TargetExtType::get (MIRBuilder. getContext () , NameWithParameters);
2361
+ return TargetExtType::get (Context , NameWithParameters);
2307
2362
2308
2363
SmallVector<StringRef> Parameters;
2309
2364
unsigned BaseNameLength = NameWithParameters.find (' _' ) - 1 ;
@@ -2312,8 +2367,7 @@ parseBuiltinTypeNameToTargetExtType(std::string TypeName,
2312
2367
SmallVector<Type *, 1 > TypeParameters;
2313
2368
bool HasTypeParameter = !isDigit (Parameters[0 ][0 ]);
2314
2369
if (HasTypeParameter)
2315
- TypeParameters.push_back (parseTypeString (
2316
- Parameters[0 ], MIRBuilder.getMF ().getFunction ().getContext ()));
2370
+ TypeParameters.push_back (parseTypeString (Parameters[0 ], Context));
2317
2371
SmallVector<unsigned > IntParameters;
2318
2372
for (unsigned i = HasTypeParameter ? 1 : 0 ; i < Parameters.size (); i++) {
2319
2373
unsigned IntParameter = 0 ;
@@ -2323,7 +2377,7 @@ parseBuiltinTypeNameToTargetExtType(std::string TypeName,
2323
2377
" Invalid format of SPIR-V builtin parameter literal!" );
2324
2378
IntParameters.push_back (IntParameter);
2325
2379
}
2326
- return TargetExtType::get (MIRBuilder. getContext () ,
2380
+ return TargetExtType::get (Context ,
2327
2381
NameWithParameters.substr (0 , BaseNameLength),
2328
2382
TypeParameters, IntParameters);
2329
2383
}
@@ -2343,7 +2397,7 @@ SPIRVType *lowerBuiltinType(const Type *OpaqueType,
2343
2397
const TargetExtType *BuiltinType = dyn_cast<TargetExtType>(OpaqueType);
2344
2398
if (!BuiltinType)
2345
2399
BuiltinType = parseBuiltinTypeNameToTargetExtType (
2346
- OpaqueType->getStructName ().str (), MIRBuilder);
2400
+ OpaqueType->getStructName ().str (), MIRBuilder. getContext () );
2347
2401
2348
2402
unsigned NumStartingVRegs = MIRBuilder.getMRI ()->getNumVirtRegs ();
2349
2403
0 commit comments