Skip to content

Commit 7e5a95b

Browse files
imporve doc, test, change trait check.
1 parent cb2e5a8 commit 7e5a95b

File tree

6 files changed

+39
-18
lines changed

6 files changed

+39
-18
lines changed

mlir/docs/Dialects/Affine.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ immediately enclosed by the latter),
6969
3. a value that dominates the `AffineScope` op enclosing the value's
7070
use,
7171
4. the result of a constant operation,
72-
5. the result of an `AffineSymbol` op,
72+
5. the result of an op with [`AffineSymbol`](Traits.md#AffineSymbol) trait,
7373
6. the result of an
7474
[`affine.apply` operation](#affineapply-mliraffineapplyop) that recursively takes as
7575
arguments any valid symbolic identifiers, or

mlir/docs/Traits/_index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@ affine.load, and affine.store. The polyhedral scope defined by an operation with
223223
this trait includes all operations in its region excluding operations that are
224224
nested inside of other operations that themselves have this trait.
225225

226+
* `OpTrait::AffineSymbol` -- `AffineSymbol`
227+
228+
This trait will make the results of the operation that holds it become valid symbols.
229+
It complements the AffineScope trait, allowing SSA values in the region of operation
230+
to be used as operands for various Affine dialect operations depending on the AffineScope
231+
trait, without altering the properties of the operation. In contrast, the AffineSymbol
232+
trait directly changes the properties of the operations. Additionally, the AffineScope
233+
trait cannot make SSA values in the nested region of operations valid symbols, operations
234+
can hold the AffineSymbol trait, then their results whill be vaild symbols.
235+
226236
### AutomaticAllocationScope
227237

228238
* `OpTrait::AutomaticAllocationScope` -- `AutomaticAllocationScope`

mlir/include/mlir/IR/OpDefinition.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,8 +1269,10 @@ class AffineScope : public TraitBase<ConcreteType, AffineScope> {
12691269
}
12701270
};
12711271

1272-
/// A trait of operation. Any operation holds the AffineSymbol, and its result
1273-
/// can be used as a symbol.
1272+
/// A trait of operation. The results of an operation with the AffineSymbol
1273+
/// trait can be used as symbols for the purposes for affine dialect purposes.
1274+
/// This trait will make the results of the operation that holds it become valid
1275+
/// symbols. For more details, see `Traits.md#AffineSymbol`.
12741276
template <typename ConcreteType>
12751277
class AffineSymbol : public TraitBase<ConcreteType, AffineSymbol> {
12761278
public:

mlir/lib/Dialect/Affine/IR/AffineOps.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ bool mlir::affine::isValidSymbol(Value value) {
410410
/// A value can be used as a symbol for `region` iff it meets one of the
411411
/// following conditions:
412412
/// *) It is a constant.
413+
/// *) It is a result, its defineOp is holded by `AffineSymbol` Trait.
413414
/// *) It is the result of an affine apply operation with symbol arguments.
414415
/// *) It is a result of the dim op on a memref whose corresponding size is
415416
/// a valid symbol.
@@ -443,7 +444,7 @@ bool mlir::affine::isValidSymbol(Value value, Region *region) {
443444
if (matchPattern(defOp, m_Constant(&operandCst)))
444445
return true;
445446

446-
// AffineScope Op.
447+
// AffineSymbol Op.
447448
if (defOp->hasTrait<OpTrait::AffineSymbol>())
448449
return true;
449450

mlir/lib/IR/Operation.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,10 +1391,17 @@ LogicalResult OpTrait::impl::verifyIsIsolatedFromAbove(Operation *isolatedOp) {
13911391
}
13921392

13931393
LogicalResult OpTrait::impl::verifyIndexResultType(Operation *op) {
1394-
if (op->getNumResults() != 1)
1395-
op->emitError("operation's result number should be 1.");
1396-
if (!mlir::isa<IndexType>(op->getResult(0).getType()))
1397-
op->emitError("operation's result type should be index.");
1394+
ResultRange results = op->getResults();
1395+
if (results.empty()) {
1396+
op->emitError("operation must have at least one result");
1397+
return failure();
1398+
}
1399+
for (OpResult result : results) {
1400+
if (!mlir::isa<IndexType>(result.getType())) {
1401+
op->emitError("operation's result type should be index");
1402+
return failure();
1403+
}
1404+
}
13981405
return success();
13991406
}
14001407

mlir/test/Dialect/Affine/ops.mlir

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ module attributes {gpu.container_module} {
331331

332332
// CHECK: #[[$ATTR_0:.+]] = affine_map<()[s0] -> (s0 mod 32)>
333333

334+
// CHECK-LABEL: @affine_thread_id
335+
334336
module {
335337
gpu.module @gpu {
336338
gpu.func @affine_thread_id(%arg0: memref<?x?xf32>) kernel {
@@ -350,13 +352,12 @@ module {
350352
}
351353
}
352354

353-
// CHECK-LABEL: @affine_thread_id
354-
// CHECK-SAME: (%[[VAL_0:.*]]: memref<?x?xf32>) kernel {
355-
// CHECK: %[[VAL_1:.*]] = arith.constant 3 : index
356-
// CHECK: %[[VAL_2:.*]] = memref.dim %[[VAL_0]], %[[VAL_1]] : memref<?x?xf32>
357-
// CHECK: %[[VAL_3:.*]] = arith.constant 0 : index
358-
// CHECK: affine.for %[[VAL_4:.*]] = %[[VAL_3]] to %[[VAL_2]] step 32 {
359-
// CHECK: %[[VAL_5:.*]] = gpu.thread_id x
360-
// CHECK: %[[VAL_6:.*]] = affine.apply #[[$ATTR_0]](){{\[}}%[[VAL_5]]]
361-
// CHECK: %[[VAL_7:.*]] = arith.constant 128 : index
362-
// CHECK: affine.for %[[VAL_8:.*]] = %[[VAL_6]] to %[[VAL_7]] step 8 {
355+
// CHECK-SAME: (%[[VAL_0:.*]]: memref<?x?xf32>) kernel {
356+
// CHECK: %[[VAL_1:.*]] = arith.constant 3 : index
357+
// CHECK: %[[VAL_2:.*]] = memref.dim %[[VAL_0]], %[[VAL_1]] : memref<?x?xf32>
358+
// CHECK: %[[VAL_3:.*]] = arith.constant 0 : index
359+
// CHECK: affine.for %[[VAL_4:.*]] = %[[VAL_3]] to %[[VAL_2]] step 32 {
360+
// CHECK: %[[VAL_5:.*]] = gpu.thread_id x
361+
// CHECK: %[[VAL_6:.*]] = affine.apply #[[$ATTR_0]](){{\[}}%[[VAL_5]]]
362+
// CHECK: %[[VAL_7:.*]] = arith.constant 128 : index
363+
// CHECK: affine.for %[[VAL_8:.*]] = %[[VAL_6]] to %[[VAL_7]] step 8 {

0 commit comments

Comments
 (0)