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

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 28 11:12:01 PST 2026


================
@@ -90,6 +138,88 @@ void AMDGPUMIRFormatter::printSDelayAluImm(int64_t Imm,
   Outdep(Id1);
 }
 
+bool AMDGPUMIRFormatter::parseSWaitAluImmMnemonic(
+    const unsigned int OpIdx, int64_t &Imm, llvm::StringRef &Src,
+    llvm::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();
+    bool ConsumeName = Src.consume_front(Name);
+    assert(ConsumeName && "Expected name");
+    bool ConsumeDelim = Src.consume_front(SWaitAluDelim);
+    assert(ConsumeDelim && "Expected delimiter");
----------------
vporpo wrote:

I think such cases are pretty common in the LLVM codebase. A common pattern is:
```
bool Inserted = SomeSet.insert().second;
assert(Inserted);
```
like in LazyCallGraph.cpp.
Though in in some cases I do see some (void)Inserted. 

Anyway I will add a [[maybe_unused]].


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


More information about the llvm-commits mailing list