[Mlir-commits] [mlir] [AMDGPU][MLIR][NFC] moved enc computation to a dedicated method (PR #189339)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Mar 30 02:09:36 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-gpu

Author: Ravil Dorozhinskii (ravil-mobile)

<details>
<summary>Changes</summary>

Tried to adapt `GlobalPrefetchOp` for projects like Triton that do not use `memref`s

---
Full diff: https://github.com/llvm/llvm-project/pull/189339.diff


3 Files Affected:

- (modified) mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPUOps.td (+4) 
- (modified) mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp (+2-15) 
- (modified) mlir/lib/Dialect/AMDGPU/IR/AMDGPUOps.cpp (+17) 


``````````diff
diff --git a/mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPUOps.td b/mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPUOps.td
index 0f01a46e147f5..5028f17bfa419 100644
--- a/mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPUOps.td
+++ b/mlir/include/mlir/Dialect/AMDGPU/IR/AMDGPUOps.td
@@ -1978,6 +1978,10 @@ def AMDGPU_GlobalPrefetchOp :
     ```
   }];
 
+  let extraClassDeclaration = [{
+    static int32_t getLLVMEncoding(amdgpu::TemporalHint hint, amdgpu::Scope scope, bool isSpeculative);
+  }];
+
   let assemblyFormat = [{
     $src `[` $indices `]` $temporalHint $cacheScope (`speculative` $speculative^)? attr-dict `:` qualified(type($src))
   }];
diff --git a/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp b/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp
index 96d4e5da3388c..0135859404da1 100644
--- a/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp
+++ b/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp
@@ -3961,22 +3961,9 @@ struct GlobalPrefetchOpLowering
     if (chipset < kGfx1250)
       return op->emitOpError("is only supported on gfx1250+");
 
-    const TemporalHint hint = op.getTemporalHint();
     const bool isSpeculative = op.getSpeculative();
-
-    int32_t immArgValue = static_cast<int32_t>(hint);
-
-    // Note that only RT and HT can operate in both speculative and
-    // non-speculative modes. The other variants (NT_RT, RT_NT, NT_HT, etc.)
-    // operate only in the speculative mode and, therefore, do not require
-    // toggling the least significant bit for mode changes
-    // Temporal hint is encoded in lower bits - i.e. [2:0]
-    if (llvm::is_contained({TemporalHint::RT, TemporalHint::HT}, hint))
-      immArgValue = isSpeculative ? immArgValue : immArgValue | 1;
-
-    // Prefetch scope level is encoded in upper bits - i.e., [4:3]
-    immArgValue = static_cast<int32_t>(op.getCacheScope()) << 3 | immArgValue;
-
+    const int32_t immArgValue = GlobalPrefetchOp::getLLVMEncoding(
+        op.getTemporalHint(), op.getCacheScope(), isSpeculative);
     IntegerAttr immArgAttr = rewriter.getI32IntegerAttr(immArgValue);
 
     ValueRange indices = adaptor.getIndices();
diff --git a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUOps.cpp b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUOps.cpp
index e27bd461908cd..9d5850a46e661 100644
--- a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUOps.cpp
+++ b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUOps.cpp
@@ -1306,6 +1306,23 @@ LogicalResult DsBarrierArriveOp::verify() {
 // GlobalPrefetchOp
 //===----------------------------------------------------------------------===//
 
+int32_t GlobalPrefetchOp::getLLVMEncoding(amdgpu::TemporalHint hint,
+                                          amdgpu::Scope scope,
+                                          bool isSpeculative) {
+  int32_t immArg = static_cast<int32_t>(hint);
+
+  // Note that only RT and HT can operate in both speculative and
+  // non-speculative modes. The other variants (NT_RT, RT_NT, NT_HT, etc.)
+  // operate only in the speculative mode and, therefore, do not require
+  // toggling the least significant bit for mode changes
+  // Temporal hint is encoded in lower bits - i.e. [2:0]
+  if (llvm::is_contained({TemporalHint::RT, TemporalHint::HT}, hint))
+    immArg = isSpeculative ? immArg : immArg | 1;
+
+  // Prefetch scope level is encoded in upper bits - i.e., [4:3]
+  return static_cast<int32_t>(scope) << 3 | immArg;
+}
+
 LogicalResult GlobalPrefetchOp::verify() {
   auto src = cast<MemRefType>(getSrc().getType());
 

``````````

</details>


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


More information about the Mlir-commits mailing list