Skip to content

Commit 1a7af2a

Browse files
authored
[mlir][DataLayout] Add IsolatedFromAbove to DataLayoutOpInterface (#132742)
This patch adds the `IsolatedFromAbove` trait as a dependent trait to the `DataLayoutOpInterface` op interface. The motivation behind this change comes from the implementation of the `ptr` dialect, specifically the `ptr.type_offset` op. This op produces an int-like value that equates to the size of a memory element. This is useful for ptr arithmetic and indexing arrays. For example: ```mlir %f32_off = ptr.type_offset f32 : index %addr = ptr.ptradd %ptr, %f32_off : !ptr, index %x = ptr.load %addr : !ptr -> f32 // Read ptr[1] ``` Without the `IsolatedFromAvobe` trait in the DL interface, the `ptr.type_offset` cannot be `ConstantLike`. Why? Take the example: ```mlir op {DL1} { %f32_off0 = ptr.type_offset f32 : index op {DL2} { %f32_off1 = ptr.type_offset f32 : index } } ``` If `ptr.type_offset` were to be `ConstantLike` then `canonicalize` would hoist and unique the value. However, that could be wrong as DL2 could have an entry to specify the size that's different from the size in DL1. The best solution to the above problem is to make `DataLayoutOpInterface` require the `IsolatedFromAbove` trait, as it preserves the constness of values in the DL with respect to the canonicalizer.
1 parent 8ddbc01 commit 1a7af2a

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

mlir/include/mlir/Dialect/GPU/IR/GPUOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ def GPU_BarrierOp : GPU_Op<"barrier"> {
13881388
}
13891389

13901390
def GPU_GPUModuleOp : GPU_Op<"module", [
1391-
DataLayoutOpInterface, HasDefaultDLTIDataLayout, IsolatedFromAbove,
1391+
IsolatedFromAbove, DataLayoutOpInterface, HasDefaultDLTIDataLayout,
13921392
NoRegionArguments, SymbolTable, Symbol] # GraphRegionNoTerminator.traits> {
13931393
let summary = "A top level compilation unit containing code to be run on a GPU.";
13941394
let description = [{

mlir/include/mlir/Interfaces/DataLayoutInterfaces.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ def DataLayoutOpInterface : OpInterface<"DataLayoutOpInterface"> {
565565
}]
566566
>
567567
];
568-
568+
let dependentTraits = [IsolatedFromAbove];
569569
let verify = [{ return ::mlir::detail::verifyDataLayoutOp($_op); }];
570570
}
571571

mlir/test/lib/Dialect/Test/TestOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2555,7 +2555,7 @@ def MakeTupleOp: TEST_Op<"make_tuple"> {
25552555
//===----------------------------------------------------------------------===//
25562556

25572557
def OpWithDataLayoutOp : TEST_Op<"op_with_data_layout",
2558-
[HasDefaultDLTIDataLayout, DataLayoutOpInterface]> {
2558+
[IsolatedFromAbove, HasDefaultDLTIDataLayout, DataLayoutOpInterface]> {
25592559
let summary =
25602560
"An op that uses DataLayout implementation from the Target dialect";
25612561
let regions = (region VariadicRegion<AnyRegion>:$regions);

0 commit comments

Comments
 (0)