[llvm] [SPIRV] Upd SPV_KHR_shader_clock extension (PR #160147)

Nikita Kornev via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 25 11:15:42 PDT 2025


================
@@ -1443,18 +1443,25 @@ static bool generateKernelClockInst(const SPIRV::IncomingCall *Call,
 
   Register ResultReg = Call->ReturnRegister;
 
-  // Deduce the `Scope` operand from the builtin function name.
-  SPIRV::Scope::Scope ScopeArg =
-      StringSwitch<SPIRV::Scope::Scope>(Builtin->Name)
-          .EndsWith("device", SPIRV::Scope::Scope::Device)
-          .EndsWith("work_group", SPIRV::Scope::Scope::Workgroup)
-          .EndsWith("sub_group", SPIRV::Scope::Scope::Subgroup);
-  Register ScopeReg = buildConstantIntReg32(ScopeArg, MIRBuilder, GR);
-
-  MIRBuilder.buildInstr(SPIRV::OpReadClockKHR)
-      .addDef(ResultReg)
-      .addUse(GR->getSPIRVTypeID(Call->ReturnType))
-      .addUse(ScopeReg);
+  if (Builtin->Name == "__spirv_ReadClockKHR") {
+    MIRBuilder.buildInstr(SPIRV::OpReadClockKHR)
+        .addDef(ResultReg)
+        .addUse(GR->getSPIRVTypeID(Call->ReturnType))
+        .addUse(Call->Arguments[0]);
+  } else {
----------------
KornevNikita wrote:

Tried to apply this, but it doesn't work like that - llc crashes. I believe `DemangledGroupBuiltinWrapper` is intended for different Group operations. Looking at how other built-ins are processed, I guess the way suggested here should be correct.

https://github.com/llvm/llvm-project/pull/160147


More information about the llvm-commits mailing list