[Mlir-commits] [mlir] afa81ff - [mlir][LLVM] Stop using Operation::getAttrs in custom printers (NCF) (#226418)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Sep 25 02:58:44 PDT 2026
Author: Mehdi Amini
Date: 2026-09-25T09:58:36Z
New Revision: afa81ffa95ca08a20c28d9e9487404ea06a89c55
URL: https://github.com/llvm/llvm-project/commit/afa81ffa95ca08a20c28d9e9487404ea06a89c55
DIFF: https://github.com/llvm/llvm-project/commit/afa81ffa95ca08a20c28d9e9487404ea06a89c55.diff
LOG: [mlir][LLVM] Stop using Operation::getAttrs in custom printers (NCF) (#226418)
At the moment, the assembly format for these operations mixes
discardable and inherent attributes. We should fix it. But for now, stop
using the `getAttrs()` API that is on its way to deprecation.
Part of #155475
Assisted-by: Codex
Added:
Modified:
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index b931631369e6f..ff75b5a7dfb2e 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -59,6 +59,19 @@ static NamedAttrList getAttrsForPrinting(Operation *op) {
return attrs;
}
+// TODO: Split inherent attributes from discardable attributes in the assembly
+// syntax of GlobalOp and AliasOp. For now, print the selected inherent
+// attributes in the regular attribute dictionary.
+static NamedAttrList
+getAttrsForPrinting(Operation *op, ArrayRef<StringAttr> inherentAttrNames) {
+ NamedAttrList attrs(op->getRawDictionaryAttrs());
+ for (StringAttr name : inherentAttrNames)
+ if (std::optional<Attribute> attr = op->getInherentAttr(name);
+ attr && *attr)
+ attrs.set(name, *attr);
+ return attrs;
+}
+
static auto processFMFAttr(ArrayRef<NamedAttribute> attrs) {
SmallVector<NamedAttribute, 8> filteredAttrs(
llvm::make_filter_range(attrs, [&](NamedAttribute attr) {
@@ -2502,7 +2515,13 @@ void GlobalOp::print(OpAsmPrinter &p) {
// default syntax here, even though it is an inherent attribute
// (as defined in https://mlir.llvm.org/docs/LangRef/#attributes)
p.printOptionalAttrDict(
- (*this)->getAttrs(),
+ getAttrsForPrinting(
+ *this, {getDsoLocalAttrName(), getExternallyInitializedAttrName(),
+ getAlignmentAttrName(), getAddrSpaceAttrName(),
+ getSectionAttrName(), getAssociatedAttrName(),
+ getAbsoluteSymbolAttrName(), getDbgExprsAttrName(),
+ getTargetSpecificAttrsAttrName(), getSymVisibilityAttrName()})
+ .getAttrs(),
{getSymNameAttrName(), getGlobalTypeAttrName(), getConstantAttrName(),
getValueAttrName(), getLinkageAttrName(), getUnnamedAddrAttrName(),
getTlsModeAttrName(), getVisibility_AttrName(), getComdatAttrName()});
@@ -2883,10 +2902,13 @@ void AliasOp::print(OpAsmPrinter &p) {
printCommonGlobalAndAlias<AliasOp>(p, *this);
p.printSymbolName(getSymName());
- p.printOptionalAttrDict((*this)->getAttrs(),
- {getSymNameAttrName(), getAliasTypeAttrName(),
- getLinkageAttrName(), getUnnamedAddrAttrName(),
- getTlsModeAttrName(), getVisibility_AttrName()});
+ p.printOptionalAttrDict(
+ getAttrsForPrinting(*this,
+ {getDsoLocalAttrName(), getSymVisibilityAttrName()})
+ .getAttrs(),
+ {getSymNameAttrName(), getAliasTypeAttrName(), getLinkageAttrName(),
+ getUnnamedAddrAttrName(), getTlsModeAttrName(),
+ getVisibility_AttrName()});
// Print the trailing type.
p << " : " << getType() << ' ';
More information about the Mlir-commits
mailing list