[Mlir-commits] [mlir] 9c7ba57 - [mlir] Allow `Attribute::print` to elide the type
Jeff Niu
llvmlistbot at llvm.org
Wed Sep 14 18:17:39 PDT 2022
Author: Jeff Niu
Date: 2022-09-14T18:17:30-07:00
New Revision: 9c7ba57e7039c4408b273404c61cc0b93f4368fd
URL: https://github.com/llvm/llvm-project/commit/9c7ba57e7039c4408b273404c61cc0b93f4368fd
DIFF: https://github.com/llvm/llvm-project/commit/9c7ba57e7039c4408b273404c61cc0b93f4368fd.diff
LOG: [mlir] Allow `Attribute::print` to elide the type
This patch adds a flag to `Attribute::print` that prints the attribute
without its type.
Fixes #57689
Reviewed By: rriddle, lattner
Differential Revision: https://reviews.llvm.org/D133822
Added:
Modified:
mlir/include/mlir/IR/Attributes.h
mlir/lib/IR/AsmPrinter.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h
index a3ee5d2db56eb..50738b20cc42e 100644
--- a/mlir/include/mlir/IR/Attributes.h
+++ b/mlir/include/mlir/IR/Attributes.h
@@ -76,8 +76,8 @@ class Attribute {
}
/// Print the attribute.
- void print(raw_ostream &os) const;
- void print(raw_ostream &os, AsmState &state) const;
+ void print(raw_ostream &os, bool elideType = false) const;
+ void print(raw_ostream &os, AsmState &state, bool elideType = false) const;
void dump() const;
/// Get an opaque pointer to the attribute.
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 310e5efbd8f89..c27c685bf2e9d 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -3262,17 +3262,20 @@ void OperationPrinter::printAffineExprOfSSAIds(AffineExpr expr,
// print and dump methods
//===----------------------------------------------------------------------===//
-void Attribute::print(raw_ostream &os) const {
+void Attribute::print(raw_ostream &os, bool elideType) const {
if (!*this) {
os << "<<NULL ATTRIBUTE>>";
return;
}
AsmState state(getContext());
- print(os, state);
+ print(os, state, elideType);
}
-void Attribute::print(raw_ostream &os, AsmState &state) const {
- AsmPrinter::Impl(os, state.getImpl()).printAttribute(*this);
+void Attribute::print(raw_ostream &os, AsmState &state, bool elideType) const {
+ using AttrTypeElision = AsmPrinter::Impl::AttrTypeElision;
+ AsmPrinter::Impl(os, state.getImpl())
+ .printAttribute(*this, elideType ? AttrTypeElision::Must
+ : AttrTypeElision::Never);
}
void Attribute::dump() const {
More information about the Mlir-commits
mailing list