Skip to content

[mlir][LLVMIR][NFC] Migrate to OpAsmAttrInterface for ASM alias generation #130479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def LoopVectorizeAttr : LLVM_Attr<"LoopVectorize", "loop_vectorize"> {
);

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

def LoopInterleaveAttr : LLVM_Attr<"LoopInterleave", "loop_interleave"> {
Expand All @@ -92,6 +95,9 @@ def LoopInterleaveAttr : LLVM_Attr<"LoopInterleave", "loop_interleave"> {
);

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

def LoopUnrollAttr : LLVM_Attr<"LoopUnroll", "loop_unroll"> {
Expand All @@ -111,6 +117,9 @@ def LoopUnrollAttr : LLVM_Attr<"LoopUnroll", "loop_unroll"> {
);

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

def LoopUnrollAndJamAttr : LLVM_Attr<"LoopUnrollAndJam", "loop_unroll_and_jam"> {
Expand All @@ -130,6 +139,9 @@ def LoopUnrollAndJamAttr : LLVM_Attr<"LoopUnrollAndJam", "loop_unroll_and_jam">
);

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

def LoopLICMAttr : LLVM_Attr<"LoopLICM", "loop_licm"> {
Expand All @@ -145,6 +157,9 @@ def LoopLICMAttr : LLVM_Attr<"LoopLICM", "loop_licm"> {
);

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

def LoopDistributeAttr : LLVM_Attr<"LoopDistribute", "loop_distribute"> {
Expand All @@ -162,6 +177,9 @@ def LoopDistributeAttr : LLVM_Attr<"LoopDistribute", "loop_distribute"> {
);

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

def LoopPipelineAttr : LLVM_Attr<"LoopPipeline", "loop_pipeline"> {
Expand All @@ -176,6 +194,9 @@ def LoopPipelineAttr : LLVM_Attr<"LoopPipeline", "loop_pipeline"> {
);

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

def LoopPeeledAttr : LLVM_Attr<"LoopPeeled", "loop_peeled"> {
Expand All @@ -189,6 +210,9 @@ def LoopPeeledAttr : LLVM_Attr<"LoopPeeled", "loop_peeled"> {
);

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

def LoopUnswitchAttr : LLVM_Attr<"LoopUnswitch", "loop_unswitch"> {
Expand All @@ -202,6 +226,9 @@ def LoopUnswitchAttr : LLVM_Attr<"LoopUnswitch", "loop_unswitch"> {
);

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

def LoopAnnotationAttr : LLVM_Attr<"LoopAnnotation", "loop_annotation"> {
Expand Down Expand Up @@ -232,6 +259,9 @@ def LoopAnnotationAttr : LLVM_Attr<"LoopAnnotation", "loop_annotation"> {
);

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -311,6 +341,9 @@ def LLVM_DIExpressionAttr : LLVM_Attr<"DIExpression", "di_expression"> {
def LLVM_DINullTypeAttr : LLVM_Attr<"DINullType", "di_null_type",
/*traits=*/[], "DITypeAttr"> {
let parameters = (ins);

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand All @@ -336,6 +369,9 @@ def LLVM_DIBasicTypeAttr : LLVM_Attr<"DIBasicType", "di_basic_type",
}]>
];
let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -365,6 +401,9 @@ def LLVM_DICompileUnitAttr : LLVM_Attr<"DICompileUnit", "di_compile_unit",
}]>
];
let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -422,6 +461,9 @@ def LLVM_DICompositeTypeAttr : LLVM_Attr<"DICompositeType", "di_composite_type",

/// @}
}];

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand All @@ -441,6 +483,9 @@ def LLVM_DIDerivedTypeAttr : LLVM_Attr<"DIDerivedType", "di_derived_type",
OptionalParameter<"DINodeAttr">:$extraData
);
let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand All @@ -455,6 +500,9 @@ def LLVM_DIFileAttr : LLVM_Attr<"DIFile", "di_file", /*traits=*/[], "DIScopeAttr
}]>
];
let assemblyFormat = "`<` $name `in` $directory `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand All @@ -469,6 +517,9 @@ def LLVM_DIGlobalVariableExpressionAttr
);
let assemblyFormat = "`<` struct(params) `>`";
let constBuilderCall = "$0";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

def DIGlobalVariableExpressionArrayAttr :
Expand All @@ -492,6 +543,9 @@ def LLVM_DIGlobalVariable : LLVM_Attr<"DIGlobalVariable", "di_global_variable",
OptionalParameter<"bool">:$isDefined,
OptionalParameter<"unsigned">:$alignInBits);
let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand All @@ -515,6 +569,9 @@ def LLVM_DILexicalBlockAttr : LLVM_Attr<"DILexicalBlock", "di_lexical_block",
}]>
];
let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand All @@ -536,6 +593,9 @@ def LLVM_DILexicalBlockFile : LLVM_Attr<"DILexicalBlockFile", "di_lexical_block_
}]>
];
let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -566,6 +626,9 @@ def LLVM_DILocalVariableAttr : LLVM_Attr<"DILocalVariable", "di_local_variable",
}]>
];
let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -619,6 +682,9 @@ def LLVM_DISubprogramAttr : LLVM_Attr<"DISubprogram", "di_subprogram",

/// @}
}];

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand All @@ -639,6 +705,9 @@ def LLVM_DIModuleAttr : LLVM_Attr<"DIModule", "di_module",
);

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand All @@ -654,6 +723,9 @@ def LLVM_DINamespaceAttr : LLVM_Attr<"DINamespace", "di_namespace",
);

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand All @@ -673,6 +745,9 @@ def LLVM_DIImportedEntityAttr : LLVM_Attr<"DIImportedEntity", "di_imported_entit
);

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -719,6 +794,9 @@ def LLVM_DICommonBlockAttr : LLVM_Attr<"DICommonBlock", "di_common_block",
OptionalParameter<"unsigned">:$line
);
let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -753,6 +831,9 @@ def LLVM_DISubroutineTypeAttr : LLVM_Attr<"DISubroutineType", "di_subroutine_typ
}]>
];
let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand All @@ -778,6 +859,9 @@ def LLVM_DILabelAttr : LLVM_Attr<"DILabel", "di_label",
];

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand All @@ -797,6 +881,9 @@ def LLVM_DIStringTypeAttr : LLVM_Attr<"DIStringType", "di_string_type",
LLVM_DIEncodingParameter:$encoding
);
let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -845,6 +932,9 @@ def LLVM_AliasScopeDomainAttr : LLVM_Attr<"AliasScopeDomain",
}];

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -902,6 +992,9 @@ def LLVM_AliasScopeAttr : LLVM_Attr<"AliasScope", "alias_scope"> {
let assemblyFormat = "`<` struct(params) `>`";

let genVerifyDecl = 1;

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

def LLVM_AliasScopeArrayAttr
Expand Down Expand Up @@ -937,6 +1030,9 @@ def LLVM_AccessGroupAttr : LLVM_Attr<"AccessGroup", "access_group"> {
}];

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

def LLVM_AccessGroupArrayAttr
Expand Down Expand Up @@ -967,6 +1063,9 @@ def LLVM_TBAARootAttr : LLVM_Attr<"TBAARoot", "tbaa_root", [], "TBAANodeAttr"> {
}];

let assemblyFormat = "(`<` struct(params)^ `>`)?";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -1040,6 +1139,9 @@ def LLVM_TBAATypeDescriptorAttr : LLVM_Attr<"TBAATypeDescriptor",
}];

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -1082,6 +1184,9 @@ def LLVM_TBAATagAttr : LLVM_Attr<"TBAATag", "tbaa_tag"> {
}];

let assemblyFormat = "`<` struct(params) `>`";

// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
}

def LLVM_TBAATagArrayAttr
Expand Down
33 changes: 0 additions & 33 deletions mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3726,36 +3726,6 @@ void CallIntrinsicOp::print(OpAsmPrinter &p) {
/*isVariadic=*/false, getResultTypes(), getResAttrsAttr());
}

//===----------------------------------------------------------------------===//
// OpAsmDialectInterface
//===----------------------------------------------------------------------===//

namespace {
struct LLVMOpAsmDialectInterface : public OpAsmDialectInterface {
using OpAsmDialectInterface::OpAsmDialectInterface;

AliasResult getAlias(Attribute attr, raw_ostream &os) const override {
return TypeSwitch<Attribute, AliasResult>(attr)
.Case<AccessGroupAttr, AliasScopeAttr, AliasScopeDomainAttr,
DIBasicTypeAttr, DICommonBlockAttr, DICompileUnitAttr,
DICompositeTypeAttr, DIDerivedTypeAttr, DIFileAttr,
DIGlobalVariableAttr, DIGlobalVariableExpressionAttr,
DIImportedEntityAttr, DILabelAttr, DILexicalBlockAttr,
DILexicalBlockFileAttr, DILocalVariableAttr, DIModuleAttr,
DINamespaceAttr, DINullTypeAttr, DIStringTypeAttr,
DISubprogramAttr, DISubroutineTypeAttr, LoopAnnotationAttr,
LoopVectorizeAttr, LoopInterleaveAttr, LoopUnrollAttr,
LoopUnrollAndJamAttr, LoopLICMAttr, LoopDistributeAttr,
LoopPipelineAttr, LoopPeeledAttr, LoopUnswitchAttr, TBAARootAttr,
TBAATagAttr, TBAATypeDescriptorAttr>([&](auto attr) {
os << decltype(attr)::getMnemonic();
return AliasResult::OverridableAlias;
})
.Default([](Attribute) { return AliasResult::NoAlias; });
}
};
} // namespace

//===----------------------------------------------------------------------===//
// LinkerOptionsOp
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -4024,9 +3994,6 @@ void LLVMDialect::initialize() {

// Support unknown operations because not all LLVM operations are registered.
allowUnknownOperations();
// clang-format off
addInterfaces<LLVMOpAsmDialectInterface>();
// clang-format on
declarePromisedInterface<DialectInlinerInterface, LLVMDialect>();
}

Expand Down
Loading