[flang-commits] [flang] cf40fde - [mlir] Don't emit forward declaration for user defined storage classes

Hideto Ueno via flang-commits flang-commits at lists.llvm.org
Thu Jul 13 21:20:04 PDT 2023


Author: Hideto Ueno
Date: 2023-07-13T21:14:48-07:00
New Revision: cf40fde4ed5cb76549aad733b8f540f9dda1e719

URL: https://github.com/llvm/llvm-project/commit/cf40fde4ed5cb76549aad733b8f540f9dda1e719
DIFF: https://github.com/llvm/llvm-project/commit/cf40fde4ed5cb76549aad733b8f540f9dda1e719.diff

LOG: [mlir] Don't emit forward declaration for user defined storage classes

Currently DefGen::emitDecl always emits forward declarations of storage classes even for user define ones, which makes it difficult to use template class directly in ODS. This patch changes `DefGen` not to emit forward decl when `genStorageClass` is false.

Original discussion: https://discourse.llvm.org/t/use-template-classes-as-user-defined-storage-classes/72015

Reviewed By: mehdi_amini, rriddle

Differential Revision: https://reviews.llvm.org/D155225

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Dialect/FIRType.h
    mlir/include/mlir/IR/BuiltinAttributes.h
    mlir/include/mlir/IR/BuiltinTypes.h
    mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h
index e91d6015aebbd4..bbc862483aea6d 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRType.h
+++ b/flang/include/flang/Optimizer/Dialect/FIRType.h
@@ -22,6 +22,11 @@ namespace fir {
 class FIROpsDialect;
 class KindMapping;
 using KindTy = unsigned;
+
+namespace detail {
+struct RecordTypeStorage;
+} // namespace detail
+
 } // namespace fir
 
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/include/mlir/IR/BuiltinAttributes.h b/mlir/include/mlir/IR/BuiltinAttributes.h
index d8b102f6393816..c8161604aad350 100644
--- a/mlir/include/mlir/IR/BuiltinAttributes.h
+++ b/mlir/include/mlir/IR/BuiltinAttributes.h
@@ -31,6 +31,12 @@ class Location;
 class Operation;
 class RankedTensorType;
 
+namespace detail {
+struct DenseIntOrFPElementsAttrStorage;
+struct DenseStringElementsAttrStorage;
+struct StringAttrStorage;
+} // namespace detail
+
 //===----------------------------------------------------------------------===//
 // Elements Attributes
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/include/mlir/IR/BuiltinTypes.h b/mlir/include/mlir/IR/BuiltinTypes.h
index 2fb8852cde94b4..c4a3c3e68b1ee7 100644
--- a/mlir/include/mlir/IR/BuiltinTypes.h
+++ b/mlir/include/mlir/IR/BuiltinTypes.h
@@ -32,6 +32,12 @@ class RankedTensorType;
 class StringAttr;
 class TypeRange;
 
+namespace detail {
+struct FunctionTypeStorage;
+struct IntegerTypeStorage;
+struct TupleTypeStorage;
+} // namespace detail
+
 //===----------------------------------------------------------------------===//
 // FloatType
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
index 4dbeb30bf77241..943e323c6af405 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
@@ -67,7 +67,7 @@ class DefGen {
   DefGen(const AttrOrTypeDef &def);
 
   void emitDecl(raw_ostream &os) const {
-    if (storageCls) {
+    if (storageCls && def.genStorageClass()) {
       NamespaceEmitter ns(os, def.getStorageNamespace());
       os << "struct " << def.getStorageClassName() << ";\n";
     }


        


More information about the flang-commits mailing list