diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -809,12 +809,12 @@ ```mlir global @variable : tuple { - %0 = constant 45 : i32 - %1 = constant 100.0 : f32 + %0 = arith.constant 45 : i32 + %1 = arith.constant 100.0 : f32 %2 = fir.undefined tuple - %3 = constant 0 : index + %3 = arith.constant 0 : index %4 = fir.insert_value %2, %0, %3 : (tuple, i32, index) -> tuple - %5 = constant 1 : index + %5 = arith.constant 1 : index %6 = fir.insert_value %4, %1, %5 : (tuple, f32, index) -> tuple fir.has_value %6 : tuple } @@ -840,8 +840,8 @@ by the calling routine. (In Fortran, these are called descriptors.) ```mlir - %c1 = constant 1 : index - %c10 = constant 10 : index + %c1 = arith.constant 1 : index + %c10 = arith.constant 10 : index %5 = ... : !fir.ref> %6 = fir.embox %5 : (!fir.ref>) -> !fir.box> ``` @@ -955,7 +955,7 @@ ``` ```mlir %4 = ... : !fir.ref>> - %5 = constant 10 : i32 + %5 = arith.constant 10 : i32 %6 = fir.emboxchar %4, %5 : (!fir.ref>>, i32) -> !fir.boxchar<1> ``` @@ -1128,7 +1128,7 @@ `dim` is out of bounds. ```mlir - %c1 = constant 0 : i32 + %c1 = arith.constant 0 : i32 %52:3 = fir.box_dims %40, %c1 : (!fir.box>, i32) -> (index, index, index) ``` @@ -1204,7 +1204,7 @@ ```mlir %r = ... : !fir.ref - %c_100 = constant 100 : index + %c_100 = arith.constant 100 : index %d = fir.shape %c_100 : (index) -> !fir.shape<1> %b = fir.embox %r(%d) : (!fir.ref, !fir.shape<1>) -> !fir.box %a = fir.box_isarray %b : (!fir.box) -> i1 // true @@ -1937,7 +1937,7 @@ %a = ... : !fir.array<10xtuple> %f = ... : f32 %o = ... : i32 - %c = constant 1 : i32 + %c = arith.constant 1 : i32 %b = fir.insert_value %a, %f, %o, %c : (!fir.array<10x20xtuple>, f32, i32, i32) -> !fir.array<10x20xtuple> ``` }]; @@ -1969,7 +1969,7 @@ ```mlir %a = fir.undefined !fir.array<10x10xf32> - %c = constant 3.0 : f32 + %c = arith.constant 3.0 : f32 %1 = fir.insert_on_range %a, %c, [0 : index, 7 : index, 0 : index, 2 : index] : (!fir.array<10x10xf32>, f32) -> !fir.array<10x10xf32> ``` @@ -2074,9 +2074,9 @@ MLIR's `scf.for`. ```mlir - %l = constant 0 : index - %u = constant 9 : index - %s = constant 1 : index + %l = arith.constant 0 : index + %u = arith.constant 9 : index + %s = arith.constant 1 : index fir.do_loop %i = %l to %u step %s unordered { %x = fir.convert %i : (index) -> i32 %v = fir.call @compute(%x) : (i32) -> f32 @@ -2702,11 +2702,11 @@ ```mlir fir.global @_QV_Mquark_Vvarble : tuple { - %1 = constant 1 : i32 - %2 = constant 2.0 : f32 + %1 = arith.constant 1 : i32 + %2 = arith.constant 2.0 : f32 %3 = fir.undefined tuple - %z = constant 0 : index - %o = constant 1 : index + %z = arith.constant 0 : index + %o = arith.constant 1 : index %4 = fir.insert_value %3, %1, %z : (tuple, i32, index) -> tuple %5 = fir.insert_value %4, %2, %o : (tuple, f32, index) -> tuple fir.has_value %5 : tuple diff --git a/mlir/docs/Bufferization.md b/mlir/docs/Bufferization.md --- a/mlir/docs/Bufferization.md +++ b/mlir/docs/Bufferization.md @@ -241,7 +241,7 @@ - Bufferizes only `arith.constant` ops of `tensor` type. - This is an example of setting up the legality so that only a subset of - `std.constant` ops get bufferized. + `arith.constant` ops get bufferized. - This is an example of a pass that is not split along dialect subdivisions. diff --git a/mlir/docs/DialectConversion.md b/mlir/docs/DialectConversion.md --- a/mlir/docs/DialectConversion.md +++ b/mlir/docs/DialectConversion.md @@ -86,8 +86,8 @@ /// Mark all operations within the LLVM dialect are legal. addLegalDialect(); - /// Mark `std.constant` op is always legal on this target. - addLegalOp(); + /// Mark `arith.constant` op is always legal on this target. + addLegalOp(); //-------------------------------------------------------------------------- // Marking an operation as dynamically legal. diff --git a/mlir/docs/Dialects/Affine.md b/mlir/docs/Dialects/Affine.md --- a/mlir/docs/Dialects/Affine.md +++ b/mlir/docs/Dialects/Affine.md @@ -398,7 +398,7 @@ '%src' in memory space 0 at indices [%i + 3, %j] to memref '%dst' in memory space 1 at indices [%k + 7, %l], would be specified as follows: - %num_elements = constant 256 + %num_elements = arith.constant 256 %idx = arith.constant 0 : index %tag = memref.alloc() : memref<1xi32, 4> affine.dma_start %src[%i + 3, %j], %dst[%k + 7, %l], %tag[%idx], diff --git a/mlir/docs/PassManagement.md b/mlir/docs/PassManagement.md --- a/mlir/docs/PassManagement.md +++ b/mlir/docs/PassManagement.md @@ -1093,8 +1093,8 @@ *** IR Dump Before CSE *** func @simple_constant() -> (i32, i32) { - %c1_i32 = constant 1 : i32 - %c1_i32_0 = constant 1 : i32 + %c1_i32 = arith.constant 1 : i32 + %c1_i32_0 = arith.constant 1 : i32 return %c1_i32, %c1_i32_0 : i32, i32 } ``` @@ -1109,7 +1109,7 @@ *** IR Dump After CSE *** func @simple_constant() -> (i32, i32) { - %c1_i32 = constant 1 : i32 + %c1_i32 = arith.constant 1 : i32 return %c1_i32, %c1_i32 : i32, i32 } ``` @@ -1130,7 +1130,7 @@ *** IR Dump After CSE *** func @simple_constant() -> (i32, i32) { - %c1_i32 = constant 1 : i32 + %c1_i32 = arith.constant 1 : i32 return %c1_i32, %c1_i32 : i32, i32 } ``` @@ -1145,7 +1145,7 @@ *** IR Dump After BadPass Failed *** func @simple_constant() -> (i32, i32) { - %c1_i32 = constant 1 : i32 + %c1_i32 = arith.constant 1 : i32 return %c1_i32, %c1_i32 : i32, i32 } ``` @@ -1165,8 +1165,8 @@ } func @simple_constant() -> (i32, i32) { - %c1_i32 = constant 1 : i32 - %c1_i32_0 = constant 1 : i32 + %c1_i32 = arith.constant 1 : i32 + %c1_i32_0 = arith.constant 1 : i32 return %c1_i32, %c1_i32_0 : i32, i32 } @@ -1176,7 +1176,7 @@ } func @simple_constant() -> (i32, i32) { - %c1_i32 = constant 1 : i32 + %c1_i32 = arith.constant 1 : i32 return %c1_i32, %c1_i32 : i32, i32 } ``` diff --git a/mlir/docs/Rationale/MLIRForGraphAlgorithms.md b/mlir/docs/Rationale/MLIRForGraphAlgorithms.md --- a/mlir/docs/Rationale/MLIRForGraphAlgorithms.md +++ b/mlir/docs/Rationale/MLIRForGraphAlgorithms.md @@ -160,7 +160,7 @@ return %y: i32 } // CHECK-LABEL: func @test_subi_zero_cfg(%arg0: i32) - // CHECK-NEXT: %c0_i32 = constant 0 : i32 + // CHECK-NEXT: %c0_i32 = arith.constant 0 : i32 // CHECK-NEXT: return %c0 ``` diff --git a/mlir/examples/standalone/include/Standalone/StandaloneOps.td b/mlir/examples/standalone/include/Standalone/StandaloneOps.td --- a/mlir/examples/standalone/include/Standalone/StandaloneOps.td +++ b/mlir/examples/standalone/include/Standalone/StandaloneOps.td @@ -25,7 +25,7 @@ Example: ```mlir - %0 = constant 2 : i32 + %0 = arith.constant 2 : i32 // Apply the foo operation to %0 %1 = standalone.foo %0 : i32 ``` diff --git a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h --- a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h +++ b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.h @@ -54,8 +54,8 @@ // memref '%src' in memory space 0 at indices [%i + 3, %j] to memref '%dst' in // memory space 1 at indices [%k + 7, %l], would be specified as follows: // -// %num_elements = constant 256 -// %idx = constant 0 : index +// %num_elements = arith.constant 256 +// %idx = arith.constant 0 : index // %tag = alloc() : memref<1xi32, 4> // affine.dma_start %src[%i + 3, %j], %dst[%k + 7, %l], %tag[%idx], // %num_elements : diff --git a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td --- a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td +++ b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td @@ -197,7 +197,7 @@ ```mlir func @reduce(%buffer: memref<1024xf32>) -> (f32) { // Initial sum set to 0. - %sum_0 = constant 0.0 : f32 + %sum_0 = arith.constant 0.0 : f32 // iter_args binds initial values to the loop's region arguments. %sum = affine.for %i = 0 to 10 step 2 iter_args(%sum_iter = %sum_0) -> (f32) { @@ -415,7 +415,7 @@ %2 = load %I[%i - 1, %j - 1] : memref<10x10xf32> affine.yield %2 } else { - %2 = constant 0.0 : f32 + %2 = arith.constant 0.0 : f32 affine.yield %2 : f32 } affine.store %1, %O[%i, %j] : memref<12x12xf32> diff --git a/mlir/include/mlir/Dialect/Affine/Passes.td b/mlir/include/mlir/Dialect/Affine/Passes.td --- a/mlir/include/mlir/Dialect/Affine/Passes.td +++ b/mlir/include/mlir/Dialect/Affine/Passes.td @@ -106,7 +106,7 @@ ```mlir func @store_load_affine_apply() -> memref<10x10xf32> { - %cf7 = constant 7.0 : f32 + %cf7 = arith.constant 7.0 : f32 %m = alloc() : memref<10x10xf32> affine.for %i0 = 0 to 10 { affine.for %i1 = 0 to 10 { @@ -124,7 +124,7 @@ ```mlir module { func @store_load_affine_apply() -> memref<10x10xf32> { - %cst = constant 7.000000e+00 : f32 + %cst = arith.constant 7.000000e+00 : f32 %0 = alloc() : memref<10x10xf32> affine.for %arg0 = 0 to 10 { affine.for %arg1 = 0 to 10 { diff --git a/mlir/include/mlir/Dialect/Affine/Utils.h b/mlir/include/mlir/Dialect/Affine/Utils.h --- a/mlir/include/mlir/Dialect/Affine/Utils.h +++ b/mlir/include/mlir/Dialect/Affine/Utils.h @@ -68,7 +68,7 @@ /// affine.for %arg2 = 0 to 64 { /// affine.for %arg3 = 0 to 128 step 8 { /// affine.for %arg4 = 0 to 512 step 4 { -/// %cst = constant 0.000000e+00 : f32 +/// %cst = arith.constant 0.000000e+00 : f32 /// %0 = vector.transfer_read %arg0[%arg2, %arg3, %arg4], %cst : ... /// vector.transfer_write %0, %arg1[%arg2, %arg3, %arg4] : ... /// } diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td --- a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td +++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td @@ -536,11 +536,11 @@ ```mlir // Always returns 4, can be constant folded: - %c0 = constant 0 : index + %c0 = arith.constant 0 : index %x = memref.dim %A, %c0 : memref<4 x ? x f32> // Returns the dynamic dimension of %A. - %c1 = constant 1 : index + %c1 = arith.constant 1 : index %y = memref.dim %A, %c1 : memref<4 x ? x f32> // Equivalent generic form: @@ -600,8 +600,8 @@ space 1 at indices [%k, %l], would be specified as follows: ```mlir - %num_elements = constant 256 - %idx = constant 0 : index + %num_elements = arith.constant 256 + %idx = arith.constant 0 : index %tag = alloc() : memref<1 x i32, (d0) -> (d0), 4> dma_start %src[%i, %j], %dst[%k, %l], %num_elements, %tag[%idx] : memref<40 x 128 x f32>, (d0) -> (d0), 0>, diff --git a/mlir/include/mlir/Dialect/SCF/SCFOps.td b/mlir/include/mlir/Dialect/SCF/SCFOps.td --- a/mlir/include/mlir/Dialect/SCF/SCFOps.td +++ b/mlir/include/mlir/Dialect/SCF/SCFOps.td @@ -91,11 +91,11 @@ cond_br %cond, ^bb1, ^bb2 ^bb1: - %c1 = constant 1 : i64 + %c1 = arith.constant 1 : i64 br ^bb3(%c1 : i64) ^bb2: - %c2 = constant 2 : i64 + %c2 = arith.constant 2 : i64 br ^bb3(%c2 : i64) ^bb3(%x : i64): @@ -166,7 +166,7 @@ func @reduce(%buffer: memref<1024xf32>, %lb: index, %ub: index, %step: index) -> (f32) { // Initial sum set to 0. - %sum_0 = constant 0.0 : f32 + %sum_0 = arith.constant 0.0 : f32 // iter_args binds initial values to the loop's region arguments. %sum = scf.for %iv = %lb to %ub step %step iter_args(%sum_iter = %sum_0) -> (f32) { @@ -190,8 +190,8 @@ ```mlir func @conditional_reduce(%buffer: memref<1024xf32>, %lb: index, %ub: index, %step: index) -> (f32) { - %sum_0 = constant 0.0 : f32 - %c0 = constant 0.0 : f32 + %sum_0 = arith.constant 0.0 : f32 + %c0 = arith.constant 0.0 : f32 %sum = scf.for %iv = %lb to %ub step %step iter_args(%sum_iter = %sum_0) -> (f32) { %t = load %buffer[%iv] : memref<1024xf32> @@ -447,7 +447,7 @@ Example: ```mlir - %init = constant 0.0 : f32 + %init = arith.constant 0.0 : f32 scf.parallel (%iv) = (%lb) to (%ub) step (%step) init (%init) -> f32 { %elem_to_reduce = load %buffer[%iv] : memref<100xf32> scf.reduce(%elem_to_reduce) : f32 { @@ -517,7 +517,7 @@ Example: ```mlir - %operand = constant 1.0 : f32 + %operand = arith.constant 1.0 : f32 scf.reduce(%operand) : f32 { ^bb0(%lhs : f32, %rhs: f32): %res = arith.addf %lhs, %rhs : f32 diff --git a/mlir/include/mlir/Dialect/SparseTensor/Transforms/Passes.td b/mlir/include/mlir/Dialect/SparseTensor/Transforms/Passes.td --- a/mlir/include/mlir/Dialect/SparseTensor/Transforms/Passes.td +++ b/mlir/include/mlir/Dialect/SparseTensor/Transforms/Passes.td @@ -89,7 +89,7 @@ ```mlir Before: - %c1 = constant 1 : index + %c1 = arith.constant 1 : index %0 = sparse_tensor.pointers %arg0, %c1 : tensor<8x8xf32, #sparse_tensor.encoding<{ dimLevelType = [ "dense", "compressed" ], @@ -98,7 +98,7 @@ }>> to memref After: - %c1 = constant 1 : index + %c1 = arith.constant 1 : index %0 = call @sparsePointers(%arg0, %c1) : (!llvm.ptr, index) -> memref ``` }]; diff --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td --- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td +++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td @@ -281,7 +281,7 @@ ```mlir %x = generic_atomic_rmw %I[%i] : memref<10xf32> { ^bb0(%current_value : f32): - %c1 = constant 1.0 : f32 + %c1 = arith.constant 1.0 : f32 %inc = arith.addf %c1, %current_value : f32 atomic_yield %inc : f32 } @@ -664,15 +664,16 @@ Example: ```mlir - // Integer constant - %1 = constant 42 : i32 + // Complex constant + %1 = constant [1.0 : f32, 1.0 : f32] : complex // Reference to function @myfn. - %3 = constant @myfn : (tensor<16xf32>, f32) -> tensor<16xf32> + %2 = constant @myfn : (tensor<16xf32>, f32) -> tensor<16xf32> // Equivalent generic forms - %1 = "std.constant"() {value = 42 : i32} : () -> i32 - %3 = "std.constant"() {value = @myfn} + %1 = "std.constant"() {value = [1.0 : f32, 1.0 : f32] : complex} + : () -> complex + %2 = "std.constant"() {value = @myfn} : () -> ((tensor<16xf32>, f32) -> tensor<16xf32>) ``` diff --git a/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td b/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td --- a/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td +++ b/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td @@ -78,11 +78,11 @@ ```mlir // Always returns 4, can be constant folded: - %c0 = constant 0 : index + %c0 = arith.constant 0 : index %x = tensor.dim %A, %c0 : tensor<4x?xf32> // Returns the dynamic dimension of %A. - %c1 = constant 1 : index + %c1 = arith.constant 1 : index %y = tensor.dim %A, %c1 : memref<4x?xf32> // Equivalent generic form: diff --git a/mlir/include/mlir/Dialect/Vector/VectorOps.td b/mlir/include/mlir/Dialect/Vector/VectorOps.td --- a/mlir/include/mlir/Dialect/Vector/VectorOps.td +++ b/mlir/include/mlir/Dialect/Vector/VectorOps.td @@ -406,7 +406,7 @@ Example: ```mlir - %0 = constant 0.0 : f32 + %0 = arith.constant 0.0 : f32 %1 = vector.broadcast %0 : f32 to vector<16xf32> %2 = vector.broadcast %1 : vector<16xf32> to vector<4x16xf32> ``` @@ -495,7 +495,7 @@ Example: ```mlir - %c = constant 15 : i32 + %c = arith.constant 15 : i32 %1 = vector.extractelement %0[%c : i32]: vector<16xf32> ``` }]; @@ -672,8 +672,8 @@ Example: ```mlir - %c = constant 15 : i32 - %f = constant 0.0f : f32 + %c = arith.constant 15 : i32 + %f = arith.constant 0.0f : f32 %1 = vector.insertelement %f, %0[%c : i32]: vector<16xf32> ``` }]; @@ -1206,7 +1206,7 @@ memref store %tmp[%i, %j, %k] : vector<3x4x5xf32> }}} - %c0 = constant 0 : index + %c0 = arith.constant 0 : index %vec = load %view_in_tmp[%c0] : vector<3x4x5xf32> ``` @@ -1227,7 +1227,7 @@ memref store %tmp[%i, 0, %k] : vector<3x4x5xf32> }} - %c0 = constant 0 : index + %c0 = arith.constant 0 : index %tmpvec = load %view_in_tmp[%c0] : vector<3x4x5xf32> %vec = broadcast %tmpvec, 1 : vector<3x4x5xf32> ``` @@ -1249,7 +1249,7 @@ ```mlir // Read the slice `%A[%i0, %i1:%i1+256, %i2:%i2+32]` into vector<32x256xf32> // and pad with %f0 to handle the boundary case: - %f0 = constant 0.0f : f32 + %f0 = arith.constant 0.0f : f32 for %i0 = 0 to %0 { affine.for %i1 = 0 to %1 step 256 { affine.for %i2 = 0 to %2 step 32 { @@ -2229,7 +2229,7 @@ Example: ```mlir - %0 = constant 0.0 : f32 + %0 = arith.constant 0.0 : f32 %1 = vector.broadcast %0 : f32 to vector<4xf32> vector.print %1 : vector<4xf32> diff --git a/mlir/include/mlir/Dialect/Vector/VectorTransforms.h b/mlir/include/mlir/Dialect/Vector/VectorTransforms.h --- a/mlir/include/mlir/Dialect/Vector/VectorTransforms.h +++ b/mlir/include/mlir/Dialect/Vector/VectorTransforms.h @@ -276,7 +276,7 @@ /// Progressive lowering of a `vector.contract %a, %b, %c` with row-major matmul /// semantics to an output-size-unrolled sequence: /// ``` -/// %out = constant ... : vector +/// %out = arith.constant ... : vector /// %bt = vector.transpose %b, [1, 0] /// %aRow0 = vector.extract %a[0] /// %btRow0 = vector.extract %bt[0] diff --git a/mlir/include/mlir/Dialect/Vector/VectorUtils.h b/mlir/include/mlir/Dialect/Vector/VectorUtils.h --- a/mlir/include/mlir/Dialect/Vector/VectorUtils.h +++ b/mlir/include/mlir/Dialect/Vector/VectorUtils.h @@ -131,7 +131,7 @@ /// The following MLIR snippet: /// /// ```mlir -/// %cst0 = constant 0 : index +/// %cst0 = arith.constant 0 : index /// affine.for %i0 = 0 to %0 { /// %a0 = load %arg0[%cst0, %cst0] : memref /// } diff --git a/mlir/include/mlir/Transforms/Passes.td b/mlir/include/mlir/Transforms/Passes.td --- a/mlir/include/mlir/Transforms/Passes.td +++ b/mlir/include/mlir/Transforms/Passes.td @@ -39,7 +39,7 @@ func @producer_consumer_fusion(%arg0: memref<10xf32>, %arg1: memref<10xf32>) { %0 = alloc() : memref<10xf32> %1 = alloc() : memref<10xf32> - %cst = constant 0.000000e+00 : f32 + %cst = arith.constant 0.000000e+00 : f32 affine.for %arg2 = 0 to 10 { affine.store %cst, %0[%arg2] : memref<10xf32> affine.store %cst, %1[%arg2] : memref<10xf32> @@ -62,7 +62,7 @@ func @producer_consumer_fusion(%arg0: memref<10xf32>, %arg1: memref<10xf32>) { %0 = alloc() : memref<1xf32> %1 = alloc() : memref<1xf32> - %cst = constant 0.000000e+00 : f32 + %cst = arith.constant 0.000000e+00 : f32 affine.for %arg2 = 0 to 10 { affine.store %cst, %0[0] : memref<1xf32> affine.store %cst, %1[0] : memref<1xf32> @@ -164,8 +164,8 @@ %0 = alloc() : memref<256xf32> %1 = alloc() : memref<32xf32, 1> %2 = alloc() : memref<1xf32> - %c0 = constant 0 : index - %c128 = constant 128 : index + %c0 = arith.constant 0 : index + %c128 = arith.constant 128 : index affine.for %i0 = 0 to 8 { affine.dma_start %0[%i0], %1[%i0], %2[%c0], %c128 : memref<256xf32>, memref<32xf32, 1>, memref<1xf32> affine.dma_wait %2[%c0], %c128 : memref<1xf32> @@ -182,11 +182,11 @@ ```mlir module { func @pipelinedatatransfer() { - %c8 = constant 8 : index - %c0 = constant 0 : index + %c8 = arith.constant 8 : index + %c0 = arith.constant 0 : index %0 = alloc() : memref<256xf32> - %c0_0 = constant 0 : index - %c128 = constant 128 : index + %c0_0 = arith.constant 0 : index + %c128 = arith.constant 128 : index %1 = alloc() : memref<2x32xf32, 1> %2 = alloc() : memref<2x1xf32> affine.dma_start %0[%c0], %1[%c0 mod 2, %c0], %2[%c0 mod 2, symbol(%c0_0)], %c128 : memref<256xf32>, memref<2x32xf32, 1>, memref<2x1xf32> @@ -558,9 +558,9 @@ func @linearize(%arg0: memref<8x8xi32, #linear8>, %arg1: memref<8x8xi32, #linear8>, %arg2: memref<8x8xi32, #linear8>) { - %c8 = constant 8 : index - %c0 = constant 0 : index - %c1 = constant 1 : index + %c8 = arith.constant 8 : index + %c0 = arith.constant 0 : index + %c1 = arith.constant 1 : index affine.for %arg3 = %c0 to %c8 { affine.for %arg4 = %c0 to %c8 { affine.for %arg5 = %c0 to %c8 { @@ -583,8 +583,8 @@ func @linearize(%arg0: memref<64xi32>, %arg1: memref<64xi32>, %arg2: memref<64xi32>) { - %c8 = constant 8 : index - %c0 = constant 0 : index + %c8 = arith.constant 8 : index + %c0 = arith.constant 0 : index affine.for %arg3 = %c0 to %c8 { affine.for %arg4 = %c0 to %c8 { affine.for %arg5 = %c0 to %c8 { diff --git a/mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp b/mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp --- a/mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp +++ b/mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp @@ -267,7 +267,7 @@ if (!srcType) return failure(); - // std.constant should only have vector or tenor types. + // arith.constant should only have vector or tenor types. assert((srcType.isa())); auto dstType = getTypeConverter()->convertType(srcType); @@ -375,8 +375,8 @@ // Bool type. if (srcType.isInteger(1)) { - // std.constant can use 0/1 instead of true/false for i1 values. We need to - // handle that here. + // arith.constant can use 0/1 instead of true/false for i1 values. We need + // to handle that here. auto dstAttr = convertBoolAttr(constOp.value(), rewriter); if (!dstAttr) return failure(); diff --git a/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp b/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp --- a/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp +++ b/mlir/lib/Conversion/ShapeToStandard/ShapeToStandard.cpp @@ -436,7 +436,7 @@ /// /// becomes /// -/// %c0 = constant 0 : index +/// %c0 = arith.constant 0 : index /// %0 = dim %arg0, %c0 : tensor /// %1 = dim %arg1, %c0 : tensor /// %2 = arith.cmpi "eq", %0, %1 : index diff --git a/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.cpp b/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.cpp --- a/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.cpp +++ b/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.cpp @@ -26,70 +26,6 @@ using namespace mlir; -//===----------------------------------------------------------------------===// -// Utility functions -//===----------------------------------------------------------------------===// - -/// Converts the given `srcAttr` into a boolean attribute if it holds an -/// integral value. Returns null attribute if conversion fails. -static BoolAttr convertBoolAttr(Attribute srcAttr, Builder builder) { - if (auto boolAttr = srcAttr.dyn_cast()) - return boolAttr; - if (auto intAttr = srcAttr.dyn_cast()) - return builder.getBoolAttr(intAttr.getValue().getBoolValue()); - return BoolAttr(); -} - -/// Converts the given `srcAttr` to a new attribute of the given `dstType`. -/// Returns null attribute if conversion fails. -static IntegerAttr convertIntegerAttr(IntegerAttr srcAttr, IntegerType dstType, - Builder builder) { - // If the source number uses less active bits than the target bitwidth, then - // it should be safe to convert. - if (srcAttr.getValue().isIntN(dstType.getWidth())) - return builder.getIntegerAttr(dstType, srcAttr.getInt()); - - // XXX: Try again by interpreting the source number as a signed value. - // Although integers in the standard dialect are signless, they can represent - // a signed number. It's the operation decides how to interpret. This is - // dangerous, but it seems there is no good way of handling this if we still - // want to change the bitwidth. Emit a message at least. - if (srcAttr.getValue().isSignedIntN(dstType.getWidth())) { - auto dstAttr = builder.getIntegerAttr(dstType, srcAttr.getInt()); - LLVM_DEBUG(llvm::dbgs() << "attribute '" << srcAttr << "' converted to '" - << dstAttr << "' for type '" << dstType << "'\n"); - return dstAttr; - } - - LLVM_DEBUG(llvm::dbgs() << "attribute '" << srcAttr - << "' illegal: cannot fit into target type '" - << dstType << "'\n"); - return IntegerAttr(); -} - -/// Converts the given `srcAttr` to a new attribute of the given `dstType`. -/// Returns null attribute if `dstType` is not 32-bit or conversion fails. -static FloatAttr convertFloatAttr(FloatAttr srcAttr, FloatType dstType, - Builder builder) { - // Only support converting to float for now. - if (!dstType.isF32()) - return FloatAttr(); - - // Try to convert the source floating-point number to single precision. - APFloat dstVal = srcAttr.getValue(); - bool losesInfo = false; - APFloat::opStatus status = - dstVal.convert(APFloat::IEEEsingle(), APFloat::rmTowardZero, &losesInfo); - if (status != APFloat::opOK || losesInfo) { - LLVM_DEBUG(llvm::dbgs() - << srcAttr << " illegal: cannot fit into converted type '" - << dstType << "'\n"); - return FloatAttr(); - } - - return builder.getF32FloatAttr(dstVal.convertToFloat()); -} - //===----------------------------------------------------------------------===// // Operation conversion //===----------------------------------------------------------------------===// @@ -100,27 +36,6 @@ namespace { -/// Converts composite std.constant operation to spv.Constant. -class ConstantCompositeOpPattern final - : public OpConversionPattern { -public: - using OpConversionPattern::OpConversionPattern; - - LogicalResult - matchAndRewrite(ConstantOp constOp, OpAdaptor adaptor, - ConversionPatternRewriter &rewriter) const override; -}; - -/// Converts scalar std.constant operation to spv.Constant. -class ConstantScalarOpPattern final : public OpConversionPattern { -public: - using OpConversionPattern::OpConversionPattern; - - LogicalResult - matchAndRewrite(ConstantOp constOp, OpAdaptor adaptor, - ConversionPatternRewriter &rewriter) const override; -}; - /// Converts std.return to spv.Return. class ReturnOpPattern final : public OpConversionPattern { public: @@ -213,148 +128,6 @@ } // namespace -//===----------------------------------------------------------------------===// -// ConstantOp with composite type. -//===----------------------------------------------------------------------===// - -// TODO: This probably should be split into the vector case and tensor case, -// so that the tensor case can be moved to TensorToSPIRV conversion. But, -// std.constant is for the standard dialect though. -LogicalResult ConstantCompositeOpPattern::matchAndRewrite( - ConstantOp constOp, OpAdaptor adaptor, - ConversionPatternRewriter &rewriter) const { - auto srcType = constOp.getType().dyn_cast(); - if (!srcType) - return failure(); - - // std.constant should only have vector or tenor types. - assert((srcType.isa())); - - auto dstType = getTypeConverter()->convertType(srcType); - if (!dstType) - return failure(); - - auto dstElementsAttr = constOp.value().dyn_cast(); - ShapedType dstAttrType = dstElementsAttr.getType(); - if (!dstElementsAttr) - return failure(); - - // If the composite type has more than one dimensions, perform linearization. - if (srcType.getRank() > 1) { - if (srcType.isa()) { - dstAttrType = RankedTensorType::get(srcType.getNumElements(), - srcType.getElementType()); - dstElementsAttr = dstElementsAttr.reshape(dstAttrType); - } else { - // TODO: add support for large vectors. - return failure(); - } - } - - Type srcElemType = srcType.getElementType(); - Type dstElemType; - // Tensor types are converted to SPIR-V array types; vector types are - // converted to SPIR-V vector/array types. - if (auto arrayType = dstType.dyn_cast()) - dstElemType = arrayType.getElementType(); - else - dstElemType = dstType.cast().getElementType(); - - // If the source and destination element types are different, perform - // attribute conversion. - if (srcElemType != dstElemType) { - SmallVector elements; - if (srcElemType.isa()) { - for (FloatAttr srcAttr : dstElementsAttr.getValues()) { - FloatAttr dstAttr = - convertFloatAttr(srcAttr, dstElemType.cast(), rewriter); - if (!dstAttr) - return failure(); - elements.push_back(dstAttr); - } - } else if (srcElemType.isInteger(1)) { - return failure(); - } else { - for (IntegerAttr srcAttr : dstElementsAttr.getValues()) { - IntegerAttr dstAttr = convertIntegerAttr( - srcAttr, dstElemType.cast(), rewriter); - if (!dstAttr) - return failure(); - elements.push_back(dstAttr); - } - } - - // Unfortunately, we cannot use dialect-specific types for element - // attributes; element attributes only works with builtin types. So we need - // to prepare another converted builtin types for the destination elements - // attribute. - if (dstAttrType.isa()) - dstAttrType = RankedTensorType::get(dstAttrType.getShape(), dstElemType); - else - dstAttrType = VectorType::get(dstAttrType.getShape(), dstElemType); - - dstElementsAttr = DenseElementsAttr::get(dstAttrType, elements); - } - - rewriter.replaceOpWithNewOp(constOp, dstType, - dstElementsAttr); - return success(); -} - -//===----------------------------------------------------------------------===// -// ConstantOp with scalar type. -//===----------------------------------------------------------------------===// - -LogicalResult ConstantScalarOpPattern::matchAndRewrite( - ConstantOp constOp, OpAdaptor adaptor, - ConversionPatternRewriter &rewriter) const { - Type srcType = constOp.getType(); - if (!srcType.isIntOrIndexOrFloat()) - return failure(); - - Type dstType = getTypeConverter()->convertType(srcType); - if (!dstType) - return failure(); - - // Floating-point types. - if (srcType.isa()) { - auto srcAttr = constOp.value().cast(); - auto dstAttr = srcAttr; - - // Floating-point types not supported in the target environment are all - // converted to float type. - if (srcType != dstType) { - dstAttr = convertFloatAttr(srcAttr, dstType.cast(), rewriter); - if (!dstAttr) - return failure(); - } - - rewriter.replaceOpWithNewOp(constOp, dstType, dstAttr); - return success(); - } - - // Bool type. - if (srcType.isInteger(1)) { - // std.constant can use 0/1 instead of true/false for i1 values. We need to - // handle that here. - auto dstAttr = convertBoolAttr(constOp.value(), rewriter); - if (!dstAttr) - return failure(); - rewriter.replaceOpWithNewOp(constOp, dstType, dstAttr); - return success(); - } - - // IndexType or IntegerType. Index values are converted to 32-bit integer - // values when converting to SPIR-V. - auto srcAttr = constOp.value().cast(); - auto dstAttr = - convertIntegerAttr(srcAttr, dstType.cast(), rewriter); - if (!dstAttr) - return failure(); - rewriter.replaceOpWithNewOp(constOp, dstType, dstAttr); - return success(); -} - //===----------------------------------------------------------------------===// // ReturnOp //===----------------------------------------------------------------------===// @@ -420,9 +193,6 @@ spirv::UnaryAndBinaryOpPattern, spirv::UnaryAndBinaryOpPattern, - // Constant patterns - ConstantCompositeOpPattern, ConstantScalarOpPattern, - ReturnOpPattern, SelectOpPattern, SplatPattern>(typeConverter, context); } diff --git a/mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp b/mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp --- a/mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp +++ b/mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp @@ -61,7 +61,7 @@ // each yielded value. // // %token, %result = async.execute -> !async.value { - // %0 = constant ... : T + // %0 = arith.constant ... : T // async.yield %0 : T // } Value asyncToken; // token representing completion of the async region diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -886,7 +886,7 @@ /// defined as dynamic, but the size was defined using a `constant` op. For /// example /// -/// %c5 = constant 5: index +/// %c5 = arith.constant 5: index /// %0 = linalg.init_tensor [%arg0, %c5] : tensor /// /// to diff --git a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp --- a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp @@ -99,10 +99,10 @@ // // #strided = (i, j)[s0, s1, s2] -> (i * s1 + s0 + j * s2) // -// %c1 = constant 1 : index -// %c0 = constant 0 : index -// %c25 = constant 25 : index -// %c10 = constant 10 : index +// %c1 = arith.constant 1 : index +// %c0 = arith.constant 0 : index +// %c25 = arith.constant 25 : index +// %c10 = arith.constant 10 : index // operand_dim_0 = dim %operand, 0 : memref<50x100xf32> // operand_dim_1 = dim %operand, 1 : memref<50x100xf32> // scf.for %k = %c0 to operand_dim_0 step %c10 { diff --git a/mlir/lib/Transforms/Utils/Utils.cpp b/mlir/lib/Transforms/Utils/Utils.cpp --- a/mlir/lib/Transforms/Utils/Utils.cpp +++ b/mlir/lib/Transforms/Utils/Utils.cpp @@ -578,7 +578,7 @@ /// 4. Create AffineApplyOp to apply the new maps. The output of AffineApplyOp /// is used in dynamicSizes of new AllocOp. /// %0 = dim %arg0, %c1 : memref<4x?xf32> -/// %c4 = constant 4 : index +/// %c4 = arith.constant 4 : index /// %1 = affine.apply #map1(%c4, %0) /// %2 = affine.apply #map2(%c4, %0) static void createNewDynamicSizes(MemRefType oldMemRefType, diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c --- a/mlir/test/CAPI/ir.c +++ b/mlir/test/CAPI/ir.c @@ -1795,7 +1795,7 @@ MlirNamedAttribute indexZeroValueAttr = mlirNamedAttributeGet( mlirIdentifierGet(ctx, valueStringRef), indexZeroLiteral); MlirOperationState constZeroState = mlirOperationStateGet( - mlirStringRefCreateFromCString("std.constant"), loc); + mlirStringRefCreateFromCString("arith.constant"), loc); mlirOperationStateAddResults(&constZeroState, 1, &indexType); mlirOperationStateAddAttributes(&constZeroState, 1, &indexZeroValueAttr); MlirOperation constZero = mlirOperationCreate(&constZeroState);