@@ -273,31 +273,11 @@ class OCL20ToSPIRV : public ModulePass, public InstVisitor<OCL20ToSPIRV> {
273
273
Module *M;
274
274
LLVMContext *Ctx;
275
275
unsigned CLVer; // / OpenCL version as major*10+minor
276
- unsigned CLLang; // / OpenCL language, see `spv::SourceLanguage`.
277
276
std::set<Value *> ValuesToDelete;
278
277
279
278
ConstantInt *addInt32 (int I) { return getInt32 (M, I); }
280
279
ConstantInt *addSizet (uint64_t I) { return getSizet (M, I); }
281
280
282
- // / Return the index of the id dimension represented by the demangled built-in name.
283
- // / ie. given `__spirv__GlobalInvocationId_x`, return `0`.
284
- Optional<uint64_t > spirvDimensionFromBuiltin (StringRef Name) {
285
- if (!Name.startswith (" __spirv_" )) {
286
- return {};
287
- }
288
-
289
- Optional<uint64_t > Result = {};
290
- if (Name.endswith (" _x" )) {
291
- Result = 0 ;
292
- } else if (Name.endswith (" _y" )) {
293
- Result = 1 ;
294
- } else if (Name.endswith (" _z" )) {
295
- Result = 2 ;
296
- }
297
-
298
- return Result;
299
- }
300
-
301
281
// / Get vector width from OpenCL vload* function name.
302
282
SPIRVWord getVecLoadWidth (const std::string &DemangledName) {
303
283
SPIRVWord Width = 0 ;
@@ -347,8 +327,7 @@ bool OCL20ToSPIRV::runOnModule(Module &Module) {
347
327
M = &Module;
348
328
Ctx = &M->getContext ();
349
329
auto Src = getSPIRVSource (&Module);
350
- CLLang = std::get<0 >(Src);
351
- if (CLLang != spv::SourceLanguageOpenCL_C && CLLang != spv::SourceLanguageOpenCL_CPP)
330
+ if (std::get<0 >(Src) != spv::SourceLanguageOpenCL_C)
352
331
return false ;
353
332
354
333
CLVer = std::get<1 >(Src);
@@ -1245,18 +1224,9 @@ void OCL20ToSPIRV::transWorkItemBuiltinsToVariables() {
1245
1224
std::vector<Function *> WorkList;
1246
1225
for (auto &I : *M) {
1247
1226
StringRef DemangledName;
1248
- auto MangledName = I.getName ();
1249
- LLVM_DEBUG (dbgs () << " Function mangled name: " << MangledName << ' \n ' );
1250
- if (!oclIsBuiltin (MangledName, DemangledName))
1227
+ if (!oclIsBuiltin (I.getName (), DemangledName))
1251
1228
continue ;
1252
1229
LLVM_DEBUG (dbgs () << " Function demangled name: " << DemangledName << ' \n ' );
1253
- auto SpirvDimension {spirvDimensionFromBuiltin (DemangledName)};
1254
- auto IsSpirvBuiltinWithDimensions {SpirvDimension.hasValue ()};
1255
- if ((!IsSpirvBuiltinWithDimensions && CLLang == spv::SourceLanguageOpenCL_CPP) ||
1256
- (IsSpirvBuiltinWithDimensions && CLLang == spv::SourceLanguageOpenCL_C)) {
1257
- // Only transform `__spirv_` builtins in OpenCL C++.
1258
- continue ;
1259
- }
1260
1230
std::string BuiltinVarName;
1261
1231
SPIRVBuiltinVariableKind BVKind;
1262
1232
if (!SPIRSPIRVBuiltinVariableMap::find (DemangledName.str (), &BVKind))
@@ -1265,15 +1235,11 @@ void OCL20ToSPIRV::transWorkItemBuiltinsToVariables() {
1265
1235
std::string (kSPIRVName ::Prefix) + SPIRVBuiltInNameMap::map (BVKind);
1266
1236
LLVM_DEBUG (dbgs () << " builtin variable name: " << BuiltinVarName << ' \n ' );
1267
1237
bool IsVec = I.getFunctionType ()->getNumParams () > 0 ;
1268
- Type *GVType = (IsVec || IsSpirvBuiltinWithDimensions) ?
1269
- VectorType::get (I.getReturnType (), 3 ) : I.getReturnType ();
1270
- // Each of the `__spirv__GlobalInvocationId_*` functions all extract an element of
1271
- // the same global variable, so ensure that we only create the global once.
1272
- auto BV = M->getOrInsertGlobal (BuiltinVarName, GVType, [&] {
1273
- return new GlobalVariable (
1274
- *M, GVType, true , GlobalValue::ExternalLinkage, nullptr , BuiltinVarName,
1275
- 0 , GlobalVariable::NotThreadLocal, SPIRAS_Input);
1276
- });
1238
+ Type *GVType =
1239
+ IsVec ? VectorType::get (I.getReturnType (), 3 ) : I.getReturnType ();
1240
+ auto BV = new GlobalVariable (*M, GVType, true , GlobalValue::ExternalLinkage,
1241
+ nullptr , BuiltinVarName, 0 ,
1242
+ GlobalVariable::NotThreadLocal, SPIRAS_Input);
1277
1243
std::vector<Instruction *> InstList;
1278
1244
for (auto UI = I.user_begin (), UE = I.user_end (); UI != UE; ++UI) {
1279
1245
auto CI = dyn_cast<CallInst>(*UI);
@@ -1284,10 +1250,6 @@ void OCL20ToSPIRV::transWorkItemBuiltinsToVariables() {
1284
1250
NewValue =
1285
1251
ExtractElementInst::Create (NewValue, CI->getArgOperand (0 ), " " , CI);
1286
1252
LLVM_DEBUG (dbgs () << *NewValue << ' \n ' );
1287
- } else if (IsSpirvBuiltinWithDimensions) {
1288
- auto Index = ConstantInt::get (I.getReturnType (), SpirvDimension.getValue (), false );
1289
- NewValue = ExtractElementInst::Create (NewValue, Index, " " , CI);
1290
- LLVM_DEBUG (dbgs () << *NewValue << ' \n ' );
1291
1253
}
1292
1254
NewValue->takeName (CI);
1293
1255
CI->replaceAllUsesWith (NewValue);
0 commit comments