[flang-commits] [flang] [mlir] [mlir][GPU] Refactor GPUOps lowering (PR #188905)
Hocky Yudhiono via flang-commits
flang-commits at lists.llvm.org
Mon Mar 30 01:05:57 PDT 2026
hockyy wrote:
### GPU dialect
- **`gpu.func`**: Add inherent `kernel` (unit) and `workgroup_attributions` (optional non-negative `i64`). `isKernel()` prefers the inherent flag and still treats legacy discardable `gpu.kernel` as a kernel for old IR. Workgroup block arguments are accessed via **`getWorkgroupAttributionBBArgs()`** (replacing the old name that collided with the new inherent accessor). This removes the hardcode inherent attributes check from the GPU filtering.
- **`gpu.launch`**: Same inherent `workgroup_attributions` shape; builders/parser only attach the attribute when the count is non-zero.
- **`GPUDialect::isKernel`**: For `gpu.func`, delegates to `GPUFuncOp::isKernel()` so both inherent and legacy representations work. **`gpu.launch_func`** verification uses this helper when checking the callee. I believe it's natural for kernel annotation to be inherent to the function. Wondering why this is discardable in the first place.
- **Kernel outlining** and other sites use **`setKernel(true)`** on outlined/generated `gpu.func` ops.
### LLVM lowering
- **New** `mlir/Conversion/LLVMCommon/LowerFunctionAttrsToLLVM.{h,cpp}`: **`lowerDiscardableAttrsForLLVMFunc`** splits discardable attributes into `LLVMFuncOp` properties vs. forwarded discardables, mirroring the previous `FuncToLLVM` logic but skipping names that resolve as **inherent** on the source op (important for property-backed ops where the raw dictionary can still reflect inherent fields).
- **`FuncToLLVM`**: Calls the shared helper instead of a local duplicate.
- **`GPUFuncOpLowering`**: Builds `llvm.func` via **`buildLoweredGPULLVMFuncAttrs`**, which runs the same lowering path as `func.func`, then fills symbol name, type, calling convention, and GPU/target discardable metadata (known block/grid/cluster sizes, kernel markers, etc.).
https://github.com/llvm/llvm-project/pull/188905
More information about the flang-commits
mailing list