diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -888,7 +888,7 @@ }]; let arguments = (ins SymbolNameAttr:$sym_name, - DefaultValuedAttr:$hint_val); + DefaultValuedOptionalAttr:$hint_val); let assemblyFormat = [{ $sym_name oilist(`hint` `(` custom($hint_val) `)`) @@ -1043,7 +1043,7 @@ let arguments = (ins OpenMP_PointerLikeType:$x, OpenMP_PointerLikeType:$v, - DefaultValuedAttr:$hint_val, + DefaultValuedOptionalAttr:$hint_val, OptionalAttr:$memory_order_val); let assemblyFormat = [{ $v `=` $x @@ -1090,7 +1090,7 @@ let arguments = (ins OpenMP_PointerLikeType:$address, AnyType:$value, - DefaultValuedAttr:$hint_val, + DefaultValuedOptionalAttr:$hint_val, OptionalAttr:$memory_order_val); let assemblyFormat = [{ $address `=` $value @@ -1154,7 +1154,7 @@ let arguments = (ins Arg:$x, - DefaultValuedAttr:$hint_val, + DefaultValuedOptionalAttr:$hint_val, OptionalAttr:$memory_order_val); let regions = (region SizedRegion<1>:$region); let assemblyFormat = [{ @@ -1216,7 +1216,7 @@ }]; - let arguments = (ins DefaultValuedAttr:$hint_val, + let arguments = (ins DefaultValuedOptionalAttr:$hint_val, OptionalAttr:$memory_order_val); let regions = (region SizedRegion<1>:$region); let assemblyFormat = [{ diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -77,6 +77,10 @@ char *mallocMem = reinterpret_cast(malloc(byteSize + prefixByteSize)); void *rawMem = mallocMem + prefixByteSize; + // Populate default attributes. + if (Optional info = name.getRegisteredInfo()) + info->populateDefaultAttrs(attributes); + // Create the new Operation. Operation *op = ::new (rawMem) Operation( location, name, numResults, numSuccessors, numRegions, diff --git a/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir b/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir --- a/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir +++ b/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir @@ -617,16 +617,16 @@ // ----- -// CHECK: llvm.mlir.global external @gv0() : !llvm.array<2 x f32> { +// CHECK: llvm.mlir.global external @gv0() {addr_space = 0 : i32} : !llvm.array<2 x f32> { // CHECK-NEXT: %0 = llvm.mlir.undef : !llvm.array<2 x f32> // CHECK-NEXT: llvm.return %0 : !llvm.array<2 x f32> // CHECK-NEXT: } memref.global @gv0 : memref<2xf32> = uninitialized -// CHECK: llvm.mlir.global private @gv1() : !llvm.array<2 x f32> +// CHECK: llvm.mlir.global private @gv1() {addr_space = 0 : i32} : !llvm.array<2 x f32> memref.global "private" @gv1 : memref<2xf32> -// CHECK: llvm.mlir.global external @gv2(dense<{{\[\[}}0.000000e+00, 1.000000e+00, 2.000000e+00], [3.000000e+00, 4.000000e+00, 5.000000e+00]]> : tensor<2x3xf32>) : !llvm.array<2 x array<3 x f32>> +// CHECK: llvm.mlir.global external @gv2(dense<{{\[\[}}0.000000e+00, 1.000000e+00, 2.000000e+00], [3.000000e+00, 4.000000e+00, 5.000000e+00]]> : tensor<2x3xf32>) {addr_space = 0 : i32} : !llvm.array<2 x array<3 x f32>> memref.global @gv2 : memref<2x3xf32> = dense<[[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]]> // Test 1D memref. @@ -676,7 +676,7 @@ } // Test scalar memref. -// CHECK: llvm.mlir.global external @gv3(1.000000e+00 : f32) : f32 +// CHECK: llvm.mlir.global external @gv3(1.000000e+00 : f32) {addr_space = 0 : i32} : f32 memref.global @gv3 : memref = dense<1.0> // CHECK-LABEL: func @get_gv3_memref @@ -696,7 +696,7 @@ } // Test scalar memref with an alignment. -// CHECK: llvm.mlir.global private @gv4(1.000000e+00 : f32) {alignment = 64 : i64} : f32 +// CHECK: llvm.mlir.global private @gv4(1.000000e+00 : f32) {addr_space = 0 : i32, alignment = 64 : i64} : f32 memref.global "private" @gv4 : memref = dense<1.0> {alignment = 64} // ----- diff --git a/mlir/test/Conversion/SPIRVToLLVM/lower-host-to-llvm-calls.mlir b/mlir/test/Conversion/SPIRVToLLVM/lower-host-to-llvm-calls.mlir --- a/mlir/test/Conversion/SPIRVToLLVM/lower-host-to-llvm-calls.mlir +++ b/mlir/test/Conversion/SPIRVToLLVM/lower-host-to-llvm-calls.mlir @@ -2,7 +2,7 @@ module attributes {gpu.container_module, spv.target_env = #spv.target_env<#spv.vce, #spv.resource_limits>} { - // CHECK: llvm.mlir.global linkonce @__spv__foo_bar_arg_0_descriptor_set0_binding0() : !llvm.struct<(array<6 x i32>)> + // CHECK: llvm.mlir.global linkonce @__spv__foo_bar_arg_0_descriptor_set0_binding0() {addr_space = 0 : i32} : !llvm.struct<(array<6 x i32>)> // CHECK: llvm.func @__spv__foo_bar() // CHECK: spv.module @__spv__foo diff --git a/mlir/test/Conversion/SPIRVToLLVM/memory-ops-to-llvm.mlir b/mlir/test/Conversion/SPIRVToLLVM/memory-ops-to-llvm.mlir --- a/mlir/test/Conversion/SPIRVToLLVM/memory-ops-to-llvm.mlir +++ b/mlir/test/Conversion/SPIRVToLLVM/memory-ops-to-llvm.mlir @@ -30,12 +30,12 @@ //===----------------------------------------------------------------------===// spv.module Logical GLSL450 { - // CHECK: llvm.mlir.global external constant @var() : f32 + // CHECK: llvm.mlir.global external constant @var() {addr_space = 0 : i32} : f32 spv.GlobalVariable @var : !spv.ptr } spv.module Logical GLSL450 { - // CHECK: llvm.mlir.global private @struct() : !llvm.struct)> + // CHECK: llvm.mlir.global private @struct() {addr_space = 0 : i32} : !llvm.struct)> // CHECK-LABEL: @func // CHECK: llvm.mlir.addressof @struct : !llvm.ptr)>> spv.GlobalVariable @struct : !spv.ptr)>, Private> @@ -46,7 +46,7 @@ } spv.module Logical GLSL450 { - // CHECK: llvm.mlir.global external @bar_descriptor_set0_binding0() : i32 + // CHECK: llvm.mlir.global external @bar_descriptor_set0_binding0() {addr_space = 0 : i32} : i32 // CHECK-LABEL: @foo // CHECK: llvm.mlir.addressof @bar_descriptor_set0_binding0 : !llvm.ptr spv.GlobalVariable @bar bind(0, 0) : !spv.ptr @@ -57,7 +57,7 @@ } spv.module @name Logical GLSL450 { - // CHECK: llvm.mlir.global external @name_bar_descriptor_set0_binding0() : i32 + // CHECK: llvm.mlir.global external @name_bar_descriptor_set0_binding0() {addr_space = 0 : i32} : i32 // CHECK-LABEL: @foo // CHECK: llvm.mlir.addressof @name_bar_descriptor_set0_binding0 : !llvm.ptr spv.GlobalVariable @bar bind(0, 0) : !spv.ptr @@ -68,7 +68,7 @@ } spv.module Logical GLSL450 { - // CHECK: llvm.mlir.global external @bar() {location = 1 : i32} : i32 + // CHECK: llvm.mlir.global external @bar() {addr_space = 0 : i32, location = 1 : i32} : i32 // CHECK-LABEL: @foo spv.GlobalVariable @bar {location = 1 : i32} : !spv.ptr spv.func @foo() "None" { @@ -78,7 +78,7 @@ } spv.module Logical GLSL450 { - // CHECK: llvm.mlir.global external constant @bar() {location = 3 : i32} : f32 + // CHECK: llvm.mlir.global external constant @bar() {addr_space = 0 : i32, location = 3 : i32} : f32 // CHECK-LABEL: @foo spv.GlobalVariable @bar {descriptor_set = 0 : i32, location = 3 : i32} : !spv.ptr spv.func @foo() "None" { diff --git a/mlir/test/Conversion/SPIRVToLLVM/misc-ops-to-llvm.mlir b/mlir/test/Conversion/SPIRVToLLVM/misc-ops-to-llvm.mlir --- a/mlir/test/Conversion/SPIRVToLLVM/misc-ops-to-llvm.mlir +++ b/mlir/test/Conversion/SPIRVToLLVM/misc-ops-to-llvm.mlir @@ -89,7 +89,7 @@ //===----------------------------------------------------------------------===// // CHECK: module { -// CHECK-NEXT: llvm.mlir.global external constant @{{.*}}() : !llvm.struct<(i32)> { +// CHECK-NEXT: llvm.mlir.global external constant @{{.*}}() {addr_space = 0 : i32} : !llvm.struct<(i32)> { // CHECK-NEXT: %[[UNDEF:.*]] = llvm.mlir.undef : !llvm.struct<(i32)> // CHECK-NEXT: %[[VAL:.*]] = llvm.mlir.constant(31 : i32) : i32 // CHECK-NEXT: %[[RET:.*]] = llvm.insertvalue %[[VAL]], %[[UNDEF]][0 : i32] : !llvm.struct<(i32)> @@ -108,7 +108,7 @@ } // CHECK: module { -// CHECK-NEXT: llvm.mlir.global external constant @{{.*}}() : !llvm.struct<(i32, array<3 x i32>)> { +// CHECK-NEXT: llvm.mlir.global external constant @{{.*}}() {addr_space = 0 : i32} : !llvm.struct<(i32, array<3 x i32>)> { // CHECK-NEXT: %[[UNDEF:.*]] = llvm.mlir.undef : !llvm.struct<(i32, array<3 x i32>)> // CHECK-NEXT: %[[EM:.*]] = llvm.mlir.constant(18 : i32) : i32 // CHECK-NEXT: %[[T0:.*]] = llvm.insertvalue %[[EM]], %[[UNDEF]][0 : i32] : !llvm.struct<(i32, array<3 x i32>)> @@ -120,7 +120,7 @@ // CHECK-NEXT: %[[RET:.*]] = llvm.insertvalue %[[C2]], %[[T2]][1 : i32, 2 : i32] : !llvm.struct<(i32, array<3 x i32>)> // CHECK-NEXT: llvm.return %[[RET]] : !llvm.struct<(i32, array<3 x i32>)> // CHECK-NEXT: } -// CHECK-NEXT: llvm.mlir.global external constant @{{.*}}() : !llvm.struct<(i32)> { +// CHECK-NEXT: llvm.mlir.global external constant @{{.*}}() {addr_space = 0 : i32} : !llvm.struct<(i32)> { // CHECK: llvm.func @bar // CHECK-NEXT: llvm.return // CHECK-NEXT: } diff --git a/mlir/test/Dialect/GPU/outlining.mlir b/mlir/test/Dialect/GPU/outlining.mlir --- a/mlir/test/Dialect/GPU/outlining.mlir +++ b/mlir/test/Dialect/GPU/outlining.mlir @@ -286,7 +286,7 @@ // CHECK: llvm.mlir.addressof @global : !llvm.ptr // CHECK: gpu.return // -// CHECK: llvm.mlir.global internal @global(42 : i64) : i64 +// CHECK: llvm.mlir.global internal @global(42 : i64) {addr_space = 0 : i32} : i64 // // CHECK: func @device_function() // CHECK: func @recursive_device_function() diff --git a/mlir/test/Dialect/LLVMIR/global.mlir b/mlir/test/Dialect/LLVMIR/global.mlir --- a/mlir/test/Dialect/LLVMIR/global.mlir +++ b/mlir/test/Dialect/LLVMIR/global.mlir @@ -6,16 +6,16 @@ // CHECK: llvm.mlir.global external constant @default_external_constant llvm.mlir.global constant @default_external_constant(42) : i64 -// CHECK: llvm.mlir.global internal @global(42 : i64) : i64 +// CHECK: llvm.mlir.global internal @global(42 : i64) {addr_space = 0 : i32} : i64 llvm.mlir.global internal @global(42 : i64) : i64 -// CHECK: llvm.mlir.global private @aligned_global(42 : i64) {aligned = 64 : i64} : i64 +// CHECK: llvm.mlir.global private @aligned_global(42 : i64) {addr_space = 0 : i32, aligned = 64 : i64} : i64 llvm.mlir.global private @aligned_global(42 : i64) {aligned = 64} : i64 -// CHECK: llvm.mlir.global private constant @aligned_global_const(42 : i64) {aligned = 32 : i64} : i64 +// CHECK: llvm.mlir.global private constant @aligned_global_const(42 : i64) {addr_space = 0 : i32, aligned = 32 : i64} : i64 llvm.mlir.global private constant @aligned_global_const(42 : i64) {aligned = 32} : i64 -// CHECK: llvm.mlir.global internal constant @constant(3.700000e+01 : f64) : f32 +// CHECK: llvm.mlir.global internal constant @constant(3.700000e+01 : f64) {addr_space = 0 : i32} : f32 llvm.mlir.global internal constant @constant(37.0) : f32 // CHECK: llvm.mlir.global internal constant @".string"("foobar") @@ -27,7 +27,7 @@ // CHECK: llvm.mlir.global internal @global_undef() llvm.mlir.global internal @global_undef() : i64 -// CHECK: llvm.mlir.global internal @global_mega_initializer() : i64 { +// CHECK: llvm.mlir.global internal @global_mega_initializer() {addr_space = 0 : i32} : i64 { // CHECK-NEXT: %[[c:[0-9]+]] = llvm.mlir.constant(42 : i64) : i64 // CHECK-NEXT: llvm.return %[[c]] : i64 // CHECK-NEXT: } @@ -57,9 +57,9 @@ llvm.mlir.global linkonce_odr @linkonce_odr() : i64 // CHECK: llvm.mlir.global weak_odr llvm.mlir.global weak_odr @weak_odr() : i64 -// CHECK: llvm.mlir.global external @has_thr_local(42 : i64) {thr_local} : i64 +// CHECK: llvm.mlir.global external @has_thr_local(42 : i64) {addr_space = 0 : i32, thr_local} : i64 llvm.mlir.global external @has_thr_local(42 : i64) {thr_local} : i64 -// CHECK: llvm.mlir.global external @has_dso_local(42 : i64) {dso_local} : i64 +// CHECK: llvm.mlir.global external @has_dso_local(42 : i64) {addr_space = 0 : i32, dso_local} : i64 llvm.mlir.global external @has_dso_local(42 : i64) {dso_local} : i64 // CHECK: llvm.mlir.global external @has_addr_space(32 : i64) {addr_space = 3 : i32} : i64 llvm.mlir.global external @has_addr_space(32 : i64) {addr_space = 3: i32} : i64 @@ -81,13 +81,13 @@ llvm.return } -// CHECK: llvm.mlir.global private local_unnamed_addr constant @local(42 : i64) : i64 +// CHECK: llvm.mlir.global private local_unnamed_addr constant @local(42 : i64) {addr_space = 0 : i32} : i64 llvm.mlir.global private local_unnamed_addr constant @local(42 : i64) : i64 -// CHECK: llvm.mlir.global private unnamed_addr constant @foo(42 : i64) : i64 +// CHECK: llvm.mlir.global private unnamed_addr constant @foo(42 : i64) {addr_space = 0 : i32} : i64 llvm.mlir.global private unnamed_addr constant @foo(42 : i64) : i64 -// CHECK: llvm.mlir.global internal constant @sectionvar("teststring") {section = ".mysection"} +// CHECK: llvm.mlir.global internal constant @sectionvar("teststring") {addr_space = 0 : i32, section = ".mysection"} llvm.mlir.global internal constant @sectionvar("teststring") {section = ".mysection"}: !llvm.array<10 x i8> // ----- diff --git a/mlir/test/Dialect/Linalg/vectorize-convolution.mlir b/mlir/test/Dialect/Linalg/vectorize-convolution.mlir --- a/mlir/test/Dialect/Linalg/vectorize-convolution.mlir +++ b/mlir/test/Dialect/Linalg/vectorize-convolution.mlir @@ -38,14 +38,14 @@ /// w == 0, kw == 0 // CHECK: %[[CONTRACT_0:.+]] = vector.contract { // CHECK-SAME: indexing_maps = [#[[INPUT_MAP]], #[[FILTER_MAP]], #[[OUTPUT_MAP]]], -// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"]} +// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"] // CHECK-SAME: %[[V_INPUT_0]], %[[V_FILTER]], %[[V_OUTPUT_0]] // CHECK-SAME: : vector<4x1x3xf32>, vector<3x8xf32> into vector<4x1x8xf32> /// w == 1, kw == 0 // CHECK: %[[CONTRACT_1:.+]] = vector.contract { // CHECK-SAME: indexing_maps = [#[[INPUT_MAP]], #[[FILTER_MAP]], #[[OUTPUT_MAP]]], -// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"]} +// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"] // CHECK-SAME: %[[V_INPUT_1]], %[[V_FILTER]], %[[V_OUTPUT_1]] // CHECK-SAME: : vector<4x1x3xf32>, vector<3x8xf32> into vector<4x1x8xf32> @@ -104,25 +104,25 @@ /// w == 0, kw == 0 // CHECK: %[[CONTRACT_0:.+]] = vector.contract { // CHECK-SAME: indexing_maps = [#[[INPUT_MAP]], #[[FILTER_MAP]], #[[OUTPUT_MAP]]], -// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"]} +// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"] // CHECK-SAME: %[[V_INPUT_0]], %[[V_FILTER_0]], %[[V_OUTPUT_0]] // CHECK-SAME: : vector<4x1x3xf32>, vector<3x8xf32> into vector<4x1x8xf32> /// w == 1, kw == 0 // CHECK: %[[CONTRACT_1:.+]] = vector.contract { // CHECK-SAME: indexing_maps = [#[[INPUT_MAP]], #[[FILTER_MAP]], #[[OUTPUT_MAP]]], -// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"]} +// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"] // CHECK-SAME: %[[V_INPUT_1]], %[[V_FILTER_0]], %[[V_OUTPUT_1]] // CHECK-SAME: : vector<4x1x3xf32>, vector<3x8xf32> into vector<4x1x8xf32> /// w == 1, kw == 1 // CHECK: %[[CONTRACT_2:.+]] = vector.contract { // CHECK-SAME: indexing_maps = [#[[INPUT_MAP]], #[[FILTER_MAP]], #[[OUTPUT_MAP]]], -// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"]} +// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"] // CHECK-SAME: %[[V_INPUT_2]], %[[V_FILTER_1]], %[[CONTRACT_0]] // CHECK-SAME: : vector<4x1x3xf32>, vector<3x8xf32> into vector<4x1x8xf32> /// w == 1, kw == 1 // CHECK: %[[CONTRACT_3:.+]] = vector.contract { // CHECK-SAME: indexing_maps = [#[[INPUT_MAP]], #[[FILTER_MAP]], #[[OUTPUT_MAP]]], -// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"]} +// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"] // CHECK-SAME: %[[V_INPUT_3]], %[[V_FILTER_1]], %[[CONTRACT_1]] // CHECK-SAME: : vector<4x1x3xf32>, vector<3x8xf32> into vector<4x1x8xf32> @@ -172,13 +172,13 @@ /// w == 0, kw == 0 // CHECK: %[[CONTRACT_0:.+]] = vector.contract { // CHECK-SAME: indexing_maps = [#[[INPUT_MAP]], #[[FILTER_MAP]], #[[OUTPUT_MAP]]], -// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"]} +// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"] // CHECK-SAME: %[[V_INPUT_0]], %[[V_FILTER_0]], %[[V_OUTPUT_R]] // CHECK-SAME: : vector<4x2x3xf32>, vector<3x8xf32> into vector<4x2x8xf32> /// w == 0, kw == 1 // CHECK: %[[CONTRACT_1:.+]] = vector.contract { // CHECK-SAME: indexing_maps = [#[[INPUT_MAP]], #[[FILTER_MAP]], #[[OUTPUT_MAP]]], -// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"]} +// CHECK-SAME: iterator_types = ["parallel", "parallel", "parallel", "reduction"] // CHECK-SAME: %[[V_INPUT_1]], %[[V_FILTER_1]], %[[CONTRACT_0]] // CHECK-SAME: : vector<4x2x3xf32>, vector<3x8xf32> into vector<4x2x8xf32> diff --git a/mlir/test/Target/LLVMIR/Import/basic.ll b/mlir/test/Target/LLVMIR/Import/basic.ll --- a/mlir/test/Target/LLVMIR/Import/basic.ll +++ b/mlir/test/Target/LLVMIR/Import/basic.ll @@ -3,24 +3,24 @@ %struct.t = type {} %struct.s = type { %struct.t, i64 } -; CHECK: llvm.mlir.global external @g1() {alignment = 8 : i64} : !llvm.struct<"struct.s", (struct<"struct.t", ()>, i64)> +; CHECK: llvm.mlir.global external @g1() {addr_space = 0 : i32, alignment = 8 : i64} : !llvm.struct<"struct.s", (struct<"struct.t", ()>, i64)> @g1 = external global %struct.s, align 8 -; CHECK: llvm.mlir.global external @g2() {alignment = 8 : i64} : f64 +; CHECK: llvm.mlir.global external @g2() {addr_space = 0 : i32, alignment = 8 : i64} : f64 @g2 = external global double, align 8 ; CHECK: llvm.mlir.global internal @g3("string") @g3 = internal global [6 x i8] c"string" -; CHECK: llvm.mlir.global external @g5() : vector<8xi32> +; CHECK: llvm.mlir.global external @g5() {addr_space = 0 : i32} : vector<8xi32> @g5 = external global <8 x i32> -; CHECK: llvm.mlir.global private @alig32(42 : i64) {alignment = 32 : i64, dso_local} : i64 +; CHECK: llvm.mlir.global private @alig32(42 : i64) {addr_space = 0 : i32, alignment = 32 : i64, dso_local} : i64 @alig32 = private global i64 42, align 32 -; CHECK: llvm.mlir.global private @alig64(42 : i64) {alignment = 64 : i64, dso_local} : i64 +; CHECK: llvm.mlir.global private @alig64(42 : i64) {addr_space = 0 : i32, alignment = 64 : i64, dso_local} : i64 @alig64 = private global i64 42, align 64 @g4 = external global i32, align 8 -; CHECK: llvm.mlir.global internal constant @int_gep() {dso_local} : !llvm.ptr { +; CHECK: llvm.mlir.global internal constant @int_gep() {addr_space = 0 : i32, dso_local} : !llvm.ptr { ; CHECK-DAG: %[[addr:[0-9]+]] = llvm.mlir.addressof @g4 : !llvm.ptr ; CHECK-DAG: %[[c2:[0-9]+]] = llvm.mlir.constant(2 : i32) : i32 ; CHECK-NEXT: %[[gepinit:[0-9]+]] = llvm.getelementptr %[[addr]][%[[c2]]] : (!llvm.ptr, i32) -> !llvm.ptr @@ -32,14 +32,14 @@ ; dso_local attribute ; -; CHECK: llvm.mlir.global external @dso_local_var() {dso_local} : !llvm.struct<"struct.s", (struct<"struct.t", ()>, i64)> +; CHECK: llvm.mlir.global external @dso_local_var() {addr_space = 0 : i32, dso_local} : !llvm.struct<"struct.s", (struct<"struct.t", ()>, i64)> @dso_local_var = external dso_local global %struct.s ; ; thread_local attribute ; -; CHECK: llvm.mlir.global external thread_local @thread_local_var() : !llvm.struct<"struct.s", (struct<"struct.t", ()>, i64)> +; CHECK: llvm.mlir.global external thread_local @thread_local_var() {addr_space = 0 : i32} : !llvm.struct<"struct.s", (struct<"struct.t", ()>, i64)> @thread_local_var = external thread_local global %struct.s ; @@ -53,27 +53,27 @@ ; Linkage attribute. ; -; CHECK: llvm.mlir.global private @private(42 : i32) {dso_local} : i32 +; CHECK: llvm.mlir.global private @private(42 : i32) {addr_space = 0 : i32, dso_local} : i32 @private = private global i32 42 -; CHECK: llvm.mlir.global internal @internal(42 : i32) {dso_local} : i32 +; CHECK: llvm.mlir.global internal @internal(42 : i32) {addr_space = 0 : i32, dso_local} : i32 @internal = internal global i32 42 -; CHECK: llvm.mlir.global available_externally @available_externally(42 : i32) : i32 +; CHECK: llvm.mlir.global available_externally @available_externally(42 : i32) {addr_space = 0 : i32} : i32 @available_externally = available_externally global i32 42 -; CHECK: llvm.mlir.global linkonce @linkonce(42 : i32) : i32 +; CHECK: llvm.mlir.global linkonce @linkonce(42 : i32) {addr_space = 0 : i32} : i32 @linkonce = linkonce global i32 42 -; CHECK: llvm.mlir.global weak @weak(42 : i32) : i32 +; CHECK: llvm.mlir.global weak @weak(42 : i32) {addr_space = 0 : i32} : i32 @weak = weak global i32 42 -; CHECK: llvm.mlir.global common @common(0 : i32) : i32 +; CHECK: llvm.mlir.global common @common(0 : i32) {addr_space = 0 : i32} : i32 @common = common global i32 zeroinitializer -; CHECK: llvm.mlir.global appending @appending(dense<[0, 1]> : tensor<2xi32>) : !llvm.array<2 x i32> +; CHECK: llvm.mlir.global appending @appending(dense<[0, 1]> : tensor<2xi32>) {addr_space = 0 : i32} : !llvm.array<2 x i32> @appending = appending global [2 x i32] [i32 0, i32 1] -; CHECK: llvm.mlir.global extern_weak @extern_weak() : i32 +; CHECK: llvm.mlir.global extern_weak @extern_weak() {addr_space = 0 : i32} : i32 @extern_weak = extern_weak global i32 -; CHECK: llvm.mlir.global linkonce_odr @linkonce_odr(42 : i32) : i32 +; CHECK: llvm.mlir.global linkonce_odr @linkonce_odr(42 : i32) {addr_space = 0 : i32} : i32 @linkonce_odr = linkonce_odr global i32 42 -; CHECK: llvm.mlir.global weak_odr @weak_odr(42 : i32) : i32 +; CHECK: llvm.mlir.global weak_odr @weak_odr(42 : i32) {addr_space = 0 : i32} : i32 @weak_odr = weak_odr global i32 42 -; CHECK: llvm.mlir.global external @external() : i32 +; CHECK: llvm.mlir.global external @external() {addr_space = 0 : i32} : i32 @external = external global i32 ; @@ -81,33 +81,33 @@ ; -; CHECK: llvm.mlir.global private constant @no_unnamed_addr(42 : i64) {dso_local} : i64 +; CHECK: llvm.mlir.global private constant @no_unnamed_addr(42 : i64) {addr_space = 0 : i32, dso_local} : i64 @no_unnamed_addr = private constant i64 42 -; CHECK: llvm.mlir.global private local_unnamed_addr constant @local_unnamed_addr(42 : i64) {dso_local} : i64 +; CHECK: llvm.mlir.global private local_unnamed_addr constant @local_unnamed_addr(42 : i64) {addr_space = 0 : i32, dso_local} : i64 @local_unnamed_addr = private local_unnamed_addr constant i64 42 -; CHECK: llvm.mlir.global private unnamed_addr constant @unnamed_addr(42 : i64) {dso_local} : i64 +; CHECK: llvm.mlir.global private unnamed_addr constant @unnamed_addr(42 : i64) {addr_space = 0 : i32, dso_local} : i64 @unnamed_addr = private unnamed_addr constant i64 42 ; ; Section attribute ; -; CHECK: llvm.mlir.global internal constant @sectionvar("teststring") {dso_local, section = ".mysection"} +; CHECK: llvm.mlir.global internal constant @sectionvar("teststring") {addr_space = 0 : i32, dso_local, section = ".mysection"} @sectionvar = internal constant [10 x i8] c"teststring", section ".mysection" ; ; Sequential constants. ; -; CHECK: llvm.mlir.global internal constant @vector_constant(dense<[1, 2]> : vector<2xi32>) {dso_local} : vector<2xi32> +; CHECK: llvm.mlir.global internal constant @vector_constant(dense<[1, 2]> : vector<2xi32>) {addr_space = 0 : i32, dso_local} : vector<2xi32> @vector_constant = internal constant <2 x i32> -; CHECK: llvm.mlir.global internal constant @array_constant(dense<[1.000000e+00, 2.000000e+00]> : tensor<2xf32>) {dso_local} : !llvm.array<2 x f32> +; CHECK: llvm.mlir.global internal constant @array_constant(dense<[1.000000e+00, 2.000000e+00]> : tensor<2xf32>) {addr_space = 0 : i32, dso_local} : !llvm.array<2 x f32> @array_constant = internal constant [2 x float] [float 1., float 2.] -; CHECK: llvm.mlir.global internal constant @nested_array_constant(dense<[{{\[}}1, 2], [3, 4]]> : tensor<2x2xi32>) {dso_local} : !llvm.array<2 x array<2 x i32>> +; CHECK: llvm.mlir.global internal constant @nested_array_constant(dense<[{{\[}}1, 2], [3, 4]]> : tensor<2x2xi32>) {addr_space = 0 : i32, dso_local} : !llvm.array<2 x array<2 x i32>> @nested_array_constant = internal constant [2 x [2 x i32]] [[2 x i32] [i32 1, i32 2], [2 x i32] [i32 3, i32 4]] -; CHECK: llvm.mlir.global internal constant @nested_array_constant3(dense<[{{\[}}[1, 2], [3, 4]]]> : tensor<1x2x2xi32>) {dso_local} : !llvm.array<1 x array<2 x array<2 x i32>>> +; CHECK: llvm.mlir.global internal constant @nested_array_constant3(dense<[{{\[}}[1, 2], [3, 4]]]> : tensor<1x2x2xi32>) {addr_space = 0 : i32, dso_local} : !llvm.array<1 x array<2 x array<2 x i32>>> @nested_array_constant3 = internal constant [1 x [2 x [2 x i32]]] [[2 x [2 x i32]] [[2 x i32] [i32 1, i32 2], [2 x i32] [i32 3, i32 4]]] -; CHECK: llvm.mlir.global internal constant @nested_array_vector(dense<[{{\[}}[1, 2], [3, 4]]]> : vector<1x2x2xi32>) {dso_local} : !llvm.array<1 x array<2 x vector<2xi32>>> +; CHECK: llvm.mlir.global internal constant @nested_array_vector(dense<[{{\[}}[1, 2], [3, 4]]]> : vector<1x2x2xi32>) {addr_space = 0 : i32, dso_local} : !llvm.array<1 x array<2 x vector<2xi32>>> @nested_array_vector = internal constant [1 x [2 x <2 x i32>]] [[2 x <2 x i32>] [<2 x i32> , <2 x i32> ]] ; diff --git a/mlir/test/Target/LLVMIR/Import/zeroinitializer.ll b/mlir/test/Target/LLVMIR/Import/zeroinitializer.ll --- a/mlir/test/Target/LLVMIR/Import/zeroinitializer.ll +++ b/mlir/test/Target/LLVMIR/Import/zeroinitializer.ll @@ -2,8 +2,8 @@ %Domain = type { %Domain**, %Domain* } -; CHECK: llvm.mlir.global external @D() : -; CHECK-SAME: !llvm.struct<"Domain", (ptr>>, ptr>)> +; CHECK: llvm.mlir.global external @D() +; CHECK-SAME: !llvm.struct<"Domain", (ptr>>, ptr>)> ; CHECK-DAG: %[[E0:.+]] = llvm.mlir.null : !llvm.ptr>>, ptr>)>> ; CHECK-DAG: %[[E1:.+]] = llvm.mlir.null : !llvm.ptr>>, ptr>)>>> ; CHECK: %[[ROOT:.+]] = llvm.mlir.undef : !llvm.struct<"Domain", (ptr>>, ptr>)> diff --git a/mlir/test/mlir-linalg-ods-gen/test-linalg-ods-yaml-gen.yaml b/mlir/test/mlir-linalg-ods-gen/test-linalg-ods-yaml-gen.yaml --- a/mlir/test/mlir-linalg-ods-gen/test-linalg-ods-yaml-gen.yaml +++ b/mlir/test/mlir-linalg-ods-gen/test-linalg-ods-yaml-gen.yaml @@ -70,7 +70,7 @@ # ODS: let arguments = # ODS-NEXT: Variadic:$inputs, # ODS-NEXT: Variadic:$outputs, -# ODS-NEXT: DefaultValuedAttr:$cast +# ODS-NEXT: DefaultValuedOptionalAttr:$cast # ODS: let builders = # ODS: (ins "TypeRange":$resultTensorTypes, "ValueRange":$inputs, @@ -157,7 +157,7 @@ # ODS: let arguments = # ODS-NEXT: Variadic:$inputs, # ODS-NEXT: Variadic:$outputs, -# ODS-NEXT: DefaultValuedAttr +# ODS-NEXT: DefaultValuedOptionalAttr # ODS-SAME: "{ static_cast(1), static_cast(2) }">:$strides # ODS: "Attribute":$strides @@ -305,8 +305,8 @@ # ODS: let arguments = # ODS-NEXT: Variadic:$inputs, # ODS-NEXT: Variadic:$outputs, -# ODS-NEXT: DefaultValuedAttr:$unary_fun, -# ODS-NEXT: DefaultValuedAttr:$binary_fun +# ODS-NEXT: DefaultValuedOptionalAttr:$unary_fun, +# ODS-NEXT: DefaultValuedOptionalAttr:$binary_fun # ODS: "Attribute":$unary_fun, "Attribute":$binary_fun, diff --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td --- a/mlir/test/mlir-tblgen/op-attribute.td +++ b/mlir/test/mlir-tblgen/op-attribute.td @@ -105,8 +105,6 @@ // DEF-NEXT: ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, bAttrAttrName()).dyn_cast_or_null() // DEF: some-return-type AOp::bAttr() { // DEF-NEXT: auto attr = bAttrAttr(); -// DEF-NEXT: if (!attr) -// DEF-NEXT: return some-const-builder-call(::mlir::Builder((*this)->getContext()), 4.2).some-convert-from-storage(); // DEF-NEXT: return attr.some-convert-from-storage(); // DEF: some-attr-kind AOp::cAttrAttr() @@ -323,11 +321,11 @@ def COp : NS_Op<"c_op", []> { let arguments = (ins - DefaultValuedAttr:$i32_array_attr, - DefaultValuedAttr:$i64_array_attr, - DefaultValuedAttr:$f32_array_attr, - DefaultValuedAttr:$f64_array_attr, - DefaultValuedAttr:$str_array_attr + DefaultValuedOptionalAttr:$i32_array_attr, + DefaultValuedOptionalAttr:$i64_array_attr, + DefaultValuedOptionalAttr:$f32_array_attr, + DefaultValuedOptionalAttr:$f64_array_attr, + DefaultValuedOptionalAttr:$str_array_attr ); } diff --git a/mlir/test/mlir-tblgen/op-python-bindings.td b/mlir/test/mlir-tblgen/op-python-bindings.td --- a/mlir/test/mlir-tblgen/op-python-bindings.td +++ b/mlir/test/mlir-tblgen/op-python-bindings.td @@ -188,8 +188,8 @@ // CHECK: results = [] // CHECK: attributes = {} // CHECK: regions = None - // CHECK: attributes["arr"] = arr if arr is not None else _ods_ir.ArrayAttr.get([]) - // CHECK: unsupported is not None, "attribute unsupported must be specified" + // CHECK: if arr is not None: attributes["arr"] = arr + // CHECK: if unsupported is not None: attributes["unsupported"] = unsupported // CHECK: _ods_successors = None // CHECK: super().__init__(self.build_generic( // CHECK: attributes=attributes, results=results, operands=operands, diff --git a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp --- a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp +++ b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp @@ -722,7 +722,7 @@ assert(arg.defaultFn); std::string enumName = convertOperandKindToEnumName(arg.kind); static const char typeFmt[] = "{0}::{1}"; - static const char defFmt[] = "DefaultValuedAttr<{0}, \"{1}\">:${2}"; + static const char defFmt[] = "DefaultValuedOptionalAttr<{0}, \"{1}\">:${2}"; attrDefs.push_back(llvm::formatv( defFmt, llvm::formatv("{0}Attr", enumName), llvm::formatv(typeFmt, enumName, arg.defaultFn), arg.name)); @@ -736,7 +736,7 @@ size_t size = arg.indexAttrMap->affineMap().getNumResults(); assert(arg.defaultIndices.value().size() == size); static const char typeFmt[] = "RankedI64ElementsAttr<[{0}]>"; - static const char defFmt[] = "DefaultValuedAttr<{0}, \"{ {1} }\">:${2}"; + static const char defFmt[] = "DefaultValuedOptionalAttr<{0}, \"{ {1} }\">:${2}"; std::string defaultVals; llvm::raw_string_ostream ss(defaultVals); llvm::interleave( diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -957,7 +957,7 @@ ERROR_IF_PRUNED(method, name, op); auto &body = method->body(); body << " auto attr = " << name << "Attr();\n"; - if (attr.hasDefaultValue()) { + if (attr.hasDefaultValue() && attr.isOptional()) { // Returns the default value if not set. // TODO: this is inefficient, we are recreating the attribute for every // call. This should be set instead. @@ -1616,7 +1616,7 @@ } for (const NamedAttribute &namedAttr : op.getAttributes()) { auto &attr = namedAttr.attr; - if (!attr.hasDefaultValue()) + if (!attr.hasDefaultValue() || attr.isOptional()) continue; auto index = attrIndex[namedAttr.name]; body << "if (!attributes.get(attrNames[" << index << "])) {\n"; @@ -2914,7 +2914,7 @@ : "cast", attr.getStorageType()); - if (attr.hasDefaultValue()) { + if (attr.hasDefaultValue() && attr.isOptional()) { // Use the default value if attribute is not set. // TODO: this is inefficient, we are recreating the attribute for every // call. This should be set instead. diff --git a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp --- a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp +++ b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp @@ -11,7 +11,6 @@ // //===----------------------------------------------------------------------===// -#include "mlir/Support/LogicalResult.h" #include "mlir/TableGen/GenInfo.h" #include "mlir/TableGen/Operator.h" #include "llvm/ADT/StringSet.h" @@ -543,21 +542,6 @@ constexpr const char *initOptionalAttributeTemplate = R"Py(if {1} is not None: attributes["{0}"] = {1})Py"; -/// Template for setting an attribute with a default value in the operation -/// builder. -/// {0} is the attribute name; -/// {1} is the builder argument name; -/// {2} is the default value. -constexpr const char *initDefaultValuedAttributeTemplate = - R"Py(attributes["{0}"] = {1} if {1} is not None else {2})Py"; - -/// Template for asserting that an attribute value was provided when calling a -/// builder. -/// {0} is the attribute name; -/// {1} is the builder argument name. -constexpr const char *assertAttributeValueSpecified = - R"Py(assert {1} is not None, "attribute {0} must be specified")Py"; - constexpr const char *initUnitAttributeTemplate = R"Py(if bool({1}): attributes["{0}"] = _ods_ir.UnitAttr.get( _ods_get_default_loc_context(loc)))Py"; @@ -663,21 +647,6 @@ } } -/// Generates Python code for the default value of the given attribute. -static FailureOr getAttributeDefaultValue(Attribute attr) { - assert(attr.hasDefaultValue() && "expected attribute with default value"); - StringRef storageType = attr.getStorageType().trim(); - StringRef defaultValCpp = attr.getDefaultValue().trim(); - - // A list of commonly used attribute types and default values for which - // we can generate Python code. Extend as needed. - if (storageType.equals("::mlir::ArrayAttr") && defaultValCpp.equals("{}")) - return std::string("_ods_ir.ArrayAttr.get([])"); - - // No match: Cannot generate Python code. - return failure(); -} - /// Populates `builderLines` with additional lines that are required in the /// builder to set up operation attributes. `argNames` is expected to contain /// the names of builder arguments that correspond to op arguments, i.e. to the @@ -700,29 +669,11 @@ continue; } - // Attributes with default value are handled specially. - if (attribute->attr.hasDefaultValue()) { - // In case we cannot generate Python code for the default value, the - // attribute must be specified by the user. - FailureOr defaultValPy = - getAttributeDefaultValue(attribute->attr); - if (succeeded(defaultValPy)) { - builderLines.push_back(llvm::formatv(initDefaultValuedAttributeTemplate, - attribute->name, argNames[i], - *defaultValPy)); - } else { - builderLines.push_back(llvm::formatv(assertAttributeValueSpecified, - attribute->name, argNames[i])); - builderLines.push_back( - llvm::formatv(initAttributeTemplate, attribute->name, argNames[i])); - } - continue; - } - - builderLines.push_back(llvm::formatv(attribute->attr.isOptional() - ? initOptionalAttributeTemplate - : initAttributeTemplate, - attribute->name, argNames[i])); + builderLines.push_back(llvm::formatv( + (attribute->attr.isOptional() || attribute->attr.hasDefaultValue()) + ? initOptionalAttributeTemplate + : initAttributeTemplate, + attribute->name, argNames[i])); } } diff --git a/mlir/unittests/IR/OperationSupportTest.cpp b/mlir/unittests/IR/OperationSupportTest.cpp --- a/mlir/unittests/IR/OperationSupportTest.cpp +++ b/mlir/unittests/IR/OperationSupportTest.cpp @@ -281,10 +281,9 @@ OpBuilder b(&context); auto req1 = b.getI32IntegerAttr(10); auto req2 = b.getI32IntegerAttr(60); + // Verify default attributes populated post op creation. Operation *op = b.create(b.getUnknownLoc(), req1, nullptr, nullptr, req2); - EXPECT_EQ(op->getAttr("default_valued_attr"), nullptr); - op->populateDefaultAttrs(); auto opt = op->getAttr("default_valued_attr"); EXPECT_NE(opt, nullptr) << *op;