[llvm] [AMDGPU] Introduce custom MIR formatting for s_wait_alu (PR #176316)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 30 08:43:45 PST 2026


================
@@ -90,6 +140,90 @@ void AMDGPUMIRFormatter::printSDelayAluImm(int64_t Imm,
   Outdep(Id1);
 }
 
+bool AMDGPUMIRFormatter::parseSWaitAluImmMnemonic(
+    const unsigned int OpIdx, int64_t &Imm, StringRef &Src,
+    MIRFormatter::ErrorCallbackType &ErrorCallback) const {
+  // TODO: For now accept integer masks for compatibility with old MIR.
+  if (!Src.consumeInteger(10, Imm))
+    return false;
+
+  // Initialize with all checks off.
+  Imm = AMDGPU::DepCtr::getDefaultDepCtrEncoding(STI);
+  // The input is in the form: .Name1_Num1_Name2_Num2
+  // Drop the '.' prefix.
+  bool ConsumePrefix = Src.consume_front(SWaitAluImmPrefix);
+  if (!ConsumePrefix)
+    return ErrorCallback(Src.begin(), "expected prefix");
+  if (Src.empty())
+    return ErrorCallback(Src.begin(), "expected <CounterName>_<CounterNum>");
+
+  // Special case for all off.
+  if (Src == AllOff)
+    return false;
+
+  // Parse a counter name, number pair in each iteration.
+  while (!Src.empty()) {
+    // Src: Name1_Num1_Name2_Num2
+    //           ^
+    size_t DelimIdx = Src.find(SWaitAluDelim);
+    if (DelimIdx == StringRef::npos)
+      return ErrorCallback(Src.begin(), "expected <CounterName>_<CounterNum>");
+    // Src: Name1_Num1_Name2_Num2
+    //      ^^^^^
+    StringRef Name = Src.substr(0, DelimIdx);
+    // Save the position of the name for accurate error reporting.
+    StringRef::iterator NamePos = Src.begin();
+    [[maybe_unused]] bool ConsumeName = Src.consume_front(Name);
+    // assert(ConsumeName && "Expected name");
+    assert(ConsumeName);
----------------
jayfoad wrote:

```suggestion
    assert(ConsumeName && "Expected name");
```

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


More information about the llvm-commits mailing list