Skip to content

Conversation

@mgehre-amd
Copy link
Contributor

This is allowed as a GCC extension, see https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html.

This is allowed as a GCC extension, see https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
and helps to make the lowering code more uniform.
@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2025

@llvm/pr-subscribers-mlir

Author: Matthias Gehre (mgehre-amd)

Changes

This is allowed as a GCC extension, see https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html.


Full diff: https://github.com/llvm/llvm-project/pull/123292.diff

4 Files Affected:

  • (modified) mlir/docs/Dialects/emitc.md (+2)
  • (modified) mlir/lib/Dialect/EmitC/IR/EmitC.cpp (+2-2)
  • (modified) mlir/test/Dialect/EmitC/invalid_types.mlir (-8)
  • (modified) mlir/test/Dialect/EmitC/types.mlir (+3-1)
diff --git a/mlir/docs/Dialects/emitc.md b/mlir/docs/Dialects/emitc.md
index 743d70959f3d8e..e2288f518dae1a 100644
--- a/mlir/docs/Dialects/emitc.md
+++ b/mlir/docs/Dialects/emitc.md
@@ -16,6 +16,8 @@ The following convention is followed:
     floating types.
 *   If `__bf16` is used, the code requires a compiler that supports it, such as 
     GCC or Clang.
+*   If `emitc.array` with a dimension of size zero is used, then the code
+    requires [a GCC extension](https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html).
 *   Else the generated code is compatible with C99.
 
 These restrictions are neither inherent to the EmitC dialect itself nor to the
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index fdc21d6c6e24b9..c818dd18a3d248 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -971,8 +971,8 @@ LogicalResult emitc::ArrayType::verify(
     return emitError() << "shape must not be empty";
 
   for (int64_t dim : shape) {
-    if (dim <= 0)
-      return emitError() << "dimensions must have positive size";
+    if (dim < 0)
+      return emitError() << "dimensions must have non-negative size";
   }
 
   if (!elementType)
diff --git a/mlir/test/Dialect/EmitC/invalid_types.mlir b/mlir/test/Dialect/EmitC/invalid_types.mlir
index 302a345c7c4f42..c39a881ff26ade 100644
--- a/mlir/test/Dialect/EmitC/invalid_types.mlir
+++ b/mlir/test/Dialect/EmitC/invalid_types.mlir
@@ -36,14 +36,6 @@ func.func @illegal_array_missing_x(
 
 // -----
 
-func.func @illegal_array_non_positive_dimenson(
-    // expected-error @+1 {{dimensions must have positive size}}
-    %arg0: !emitc.array<0xi32>
-) {
-}
-
-// -----
-
 func.func @illegal_array_missing_type(
     // expected-error @+1 {{expected non-function type}}
     %arg0: !emitc.array<10x>
diff --git a/mlir/test/Dialect/EmitC/types.mlir b/mlir/test/Dialect/EmitC/types.mlir
index e3462bffc5b0de..d4dd94457f39b9 100644
--- a/mlir/test/Dialect/EmitC/types.mlir
+++ b/mlir/test/Dialect/EmitC/types.mlir
@@ -17,7 +17,9 @@ func.func @array_types(
   // CHECK-SAME: !emitc.array<30x!emitc.ssize_t>
   %arg5: !emitc.array<30x!emitc.ssize_t>,
   // CHECK-SAME: !emitc.array<30x!emitc.ptrdiff_t>
-  %arg6: !emitc.array<30x!emitc.ptrdiff_t>
+  %arg6: !emitc.array<30x!emitc.ptrdiff_t>,
+  // CHECK-SAME: !emitc.array<0xi64>
+  %arg7: !emitc.array<0xi64>
 ) {
   return
 }

@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2025

@llvm/pr-subscribers-mlir-emitc

Author: Matthias Gehre (mgehre-amd)

Changes

This is allowed as a GCC extension, see https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html.


Full diff: https://github.com/llvm/llvm-project/pull/123292.diff

4 Files Affected:

  • (modified) mlir/docs/Dialects/emitc.md (+2)
  • (modified) mlir/lib/Dialect/EmitC/IR/EmitC.cpp (+2-2)
  • (modified) mlir/test/Dialect/EmitC/invalid_types.mlir (-8)
  • (modified) mlir/test/Dialect/EmitC/types.mlir (+3-1)
diff --git a/mlir/docs/Dialects/emitc.md b/mlir/docs/Dialects/emitc.md
index 743d70959f3d8e..e2288f518dae1a 100644
--- a/mlir/docs/Dialects/emitc.md
+++ b/mlir/docs/Dialects/emitc.md
@@ -16,6 +16,8 @@ The following convention is followed:
     floating types.
 *   If `__bf16` is used, the code requires a compiler that supports it, such as 
     GCC or Clang.
+*   If `emitc.array` with a dimension of size zero is used, then the code
+    requires [a GCC extension](https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html).
 *   Else the generated code is compatible with C99.
 
 These restrictions are neither inherent to the EmitC dialect itself nor to the
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
index fdc21d6c6e24b9..c818dd18a3d248 100644
--- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
+++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp
@@ -971,8 +971,8 @@ LogicalResult emitc::ArrayType::verify(
     return emitError() << "shape must not be empty";
 
   for (int64_t dim : shape) {
-    if (dim <= 0)
-      return emitError() << "dimensions must have positive size";
+    if (dim < 0)
+      return emitError() << "dimensions must have non-negative size";
   }
 
   if (!elementType)
diff --git a/mlir/test/Dialect/EmitC/invalid_types.mlir b/mlir/test/Dialect/EmitC/invalid_types.mlir
index 302a345c7c4f42..c39a881ff26ade 100644
--- a/mlir/test/Dialect/EmitC/invalid_types.mlir
+++ b/mlir/test/Dialect/EmitC/invalid_types.mlir
@@ -36,14 +36,6 @@ func.func @illegal_array_missing_x(
 
 // -----
 
-func.func @illegal_array_non_positive_dimenson(
-    // expected-error @+1 {{dimensions must have positive size}}
-    %arg0: !emitc.array<0xi32>
-) {
-}
-
-// -----
-
 func.func @illegal_array_missing_type(
     // expected-error @+1 {{expected non-function type}}
     %arg0: !emitc.array<10x>
diff --git a/mlir/test/Dialect/EmitC/types.mlir b/mlir/test/Dialect/EmitC/types.mlir
index e3462bffc5b0de..d4dd94457f39b9 100644
--- a/mlir/test/Dialect/EmitC/types.mlir
+++ b/mlir/test/Dialect/EmitC/types.mlir
@@ -17,7 +17,9 @@ func.func @array_types(
   // CHECK-SAME: !emitc.array<30x!emitc.ssize_t>
   %arg5: !emitc.array<30x!emitc.ssize_t>,
   // CHECK-SAME: !emitc.array<30x!emitc.ptrdiff_t>
-  %arg6: !emitc.array<30x!emitc.ptrdiff_t>
+  %arg6: !emitc.array<30x!emitc.ptrdiff_t>,
+  // CHECK-SAME: !emitc.array<0xi64>
+  %arg7: !emitc.array<0xi64>
 ) {
   return
 }

@mgehre-amd mgehre-amd merged commit 0bd0765 into llvm:main Jan 17, 2025
11 checks passed
@mgehre-amd mgehre-amd deleted the matthias.emitc_array_zero branch January 17, 2025 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants