[flang-commits] [flang] [flang] Fix attribute printing for fir.global op (PR #81197)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Thu Feb 8 14:09:09 PST 2024
https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/81197
>From 5711c389617dbe4290866cd8211421cd69962b7c Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Thu, 8 Feb 2024 14:02:40 -0800
Subject: [PATCH 1/2] [flang] Fix attribute printing for fir.global op
---
flang/lib/Optimizer/Dialect/FIROps.cpp | 18 +++++++++++-------
flang/test/Fir/fir-ops.fir | 7 +++++++
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index 483f318b649d9..991d83df7f674 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -1348,12 +1348,12 @@ mlir::ParseResult fir::GlobalOp::parse(mlir::OpAsmParser &parser,
if (parser.parseOptionalAttrDict(result.attributes))
return mlir::failure();
- if (succeeded(parser.parseOptionalKeyword("constant"))) {
+ if (succeeded(parser.parseOptionalKeyword(getConstantAttrNameStr()))) {
// if "constant" keyword then mark this as a constant, not a variable
- result.addAttribute("constant", builder.getUnitAttr());
+ result.addAttribute(getConstantAttrNameStr(), builder.getUnitAttr());
}
- if (succeeded(parser.parseOptionalKeyword("target")))
+ if (succeeded(parser.parseOptionalKeyword(getTargetAttrNameStr())))
result.addAttribute(getTargetAttrNameStr(), builder.getUnitAttr());
mlir::Type globalType;
@@ -1382,11 +1382,15 @@ void fir::GlobalOp::print(mlir::OpAsmPrinter &p) {
p.printAttributeWithoutType(getSymrefAttr());
if (auto val = getValueOrNull())
p << '(' << val << ')';
- p.printOptionalAttrDict((*this)->getAttrs(), (*this).getAttributeNames());
- if (getOperation()->getAttr(fir::GlobalOp::getConstantAttrNameStr()))
- p << " constant";
+ // Print all other attributes that are not pretty printed here.
+ p.printOptionalAttrDict((*this)->getAttrs(), /*elideAttrs=*/{
+ getSymNameAttrName(), getSymrefAttrName(), getTypeAttrName(),
+ getConstantAttrName(), getTargetAttrName(), getLinkNameAttrName(),
+ getInitValAttrName()});
+ if (getOperation()->getAttr(getConstantAttrName()))
+ p << " " << getConstantAttrNameStr();
if (getOperation()->getAttr(getTargetAttrName()))
- p << " target";
+ p << " " << getTargetAttrNameStr();
p << " : ";
p.printType(getType());
if (hasInitializationBody()) {
diff --git a/flang/test/Fir/fir-ops.fir b/flang/test/Fir/fir-ops.fir
index 3c4095b9fdb14..962621c4e2e1a 100644
--- a/flang/test/Fir/fir-ops.fir
+++ b/flang/test/Fir/fir-ops.fir
@@ -893,3 +893,10 @@ func.func @test_box_typecode(%a: !fir.class<none>) {
// CHECK-LABEL: func.func @test_box_typecode(
// CHECK-SAME: %[[A:.*]]: !fir.class<none>)
// CHECK: %{{.*}} = fir.box_typecode %[[A]] : (!fir.class<none>) -> i32
+
+fir.global @t1 {keep_my_attr = "data"} : i32 {
+ %1 = arith.constant 0 : i32
+ fir.has_value %1 : i32
+}
+
+// CHECK-LABEL: fir.global @t1 {keep_my_attr = "data"} : i32
>From 7b629ed6404d44af17d4c675a93f5728c52cda86 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Thu, 8 Feb 2024 14:08:58 -0800
Subject: [PATCH 2/2] clang-format
---
flang/lib/Optimizer/Dialect/FIROps.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index 991d83df7f674..a5b31daa6440a 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -1384,9 +1384,10 @@ void fir::GlobalOp::print(mlir::OpAsmPrinter &p) {
p << '(' << val << ')';
// Print all other attributes that are not pretty printed here.
p.printOptionalAttrDict((*this)->getAttrs(), /*elideAttrs=*/{
- getSymNameAttrName(), getSymrefAttrName(), getTypeAttrName(),
- getConstantAttrName(), getTargetAttrName(), getLinkNameAttrName(),
- getInitValAttrName()});
+ getSymNameAttrName(), getSymrefAttrName(),
+ getTypeAttrName(), getConstantAttrName(),
+ getTargetAttrName(), getLinkNameAttrName(),
+ getInitValAttrName()});
if (getOperation()->getAttr(getConstantAttrName()))
p << " " << getConstantAttrNameStr();
if (getOperation()->getAttr(getTargetAttrName()))
More information about the flang-commits
mailing list