[mlir][llvm] Remove the metadata op

This revision removes the metadata op, that to the best of our
knowledge, has no more uses after switching to a purely attribute based
metadata representation:
https://reviews.llvm.org/D155444
https://reviews.llvm.org/D155285
https://reviews.llvm.org/D155159
These changes got unlocked after landing distinct attribute support:
https://reviews.llvm.org/D153360,
which enables modeling distinct metadata using attributes. As a result,
all metadata kinds are now represented using attributes. Previously,
there has been a mix of attribute and op based representations.

Having attribute only metadata makes it possible to update the metadata
in-parallel, while updating the global metadata operation has been
a sequential process. The LLVM Dialect inliner already benefits from
this change and now creates new alias scopes and domains during
inlining rather than dropping the no alias information:
https://reviews.llvm.org/D155712

Reviewed By: Dinistro

Differential Revision: https://reviews.llvm.org/D156217
This commit is contained in:
Tobias Gysi 2023-07-26 11:38:47 +00:00
parent f6307b260b
commit 0fc8d9e41a
6 changed files with 10 additions and 85 deletions

View File

@ -1074,37 +1074,6 @@ def LLVM_AddressOfOp : LLVM_Op<"mlir.addressof",
let assemblyFormat = "$global_name attr-dict `:` qualified(type($res))";
}
def LLVM_MetadataOp : LLVM_Op<"metadata", [
NoRegionArguments, NoTerminator, SymbolTable, Symbol
]> {
let arguments = (ins
SymbolNameAttr:$sym_name
);
let summary = "LLVM dialect metadata.";
let description = [{
llvm.metadata op defines one or more metadata nodes.
Example:
```mlir
llvm.metadata @metadata {
llvm.access_group @group1
llvm.access_group @group2
}
```
}];
let regions = (region SizedRegion<1>:$body);
let skipDefaultBuilders = 1;
let builders = [
OpBuilder<(ins "StringRef":$symName,
CArg<"bool", "true">:$createBodyBlock,
CArg<"ArrayRef<NamedAttribute>", "{}">:$attributes)>
];
let hasCustomAssemblyFormat = 1;
}
def LLVM_GlobalOp : LLVM_Op<"mlir.global",
[IsolatedFromAbove, SingleBlockImplicitTerminator<"ReturnOp">, Symbol]> {
let arguments = (ins

View File

@ -2785,49 +2785,6 @@ OpFoldResult LLVM::OrOp::fold(FoldAdaptor adaptor) {
return IntegerAttr::get(getType(), lhs.getValue() | rhs.getValue());
}
//===----------------------------------------------------------------------===//
// Utilities for LLVM::MetadataOp
//===----------------------------------------------------------------------===//
void MetadataOp::build(OpBuilder &builder, OperationState &result,
StringRef symName, bool createBodyBlock,
ArrayRef<NamedAttribute> attributes) {
result.addAttribute(getSymNameAttrName(result.name),
builder.getStringAttr(symName));
result.attributes.append(attributes.begin(), attributes.end());
Region *body = result.addRegion();
if (createBodyBlock)
body->emplaceBlock();
}
ParseResult MetadataOp::parse(OpAsmParser &parser, OperationState &result) {
StringAttr symName;
if (parser.parseSymbolName(symName, getSymNameAttrName(result.name),
result.attributes) ||
parser.parseOptionalAttrDictWithKeyword(result.attributes))
return failure();
Region *bodyRegion = result.addRegion();
if (parser.parseRegion(*bodyRegion))
return failure();
// If the region appeared to be empty to parseRegion(),
// add the body block explicitly.
if (bodyRegion->empty())
bodyRegion->emplaceBlock();
return success();
}
void MetadataOp::print(OpAsmPrinter &printer) {
printer << ' ';
printer.printSymbolName(getSymName());
printer.printOptionalAttrDictWithKeyword((*this)->getAttrs(),
{getSymNameAttrName().getValue()});
printer << ' ';
printer.printRegion(getBody());
}
//===----------------------------------------------------------------------===//
// OpAsmDialectInterface
//===----------------------------------------------------------------------===//

View File

@ -22,8 +22,7 @@ namespace LLVM {
namespace detail {
/// A helper class that converts llvm.loop metadata nodes into corresponding
/// LoopAnnotationAttrs and llvm.access.group nodes into
/// AccessGroupMetadataOps.
/// LoopAnnotationAttrs and llvm.access.group nodes into AccessGroupAttrs.
class LoopAnnotationImporter {
public:
LoopAnnotationImporter(ModuleImport &moduleImport, OpBuilder &builder)

View File

@ -21,8 +21,8 @@ namespace mlir {
namespace LLVM {
namespace detail {
/// A helper class that converts LoopAnnotationAttrs and AccessGroupMetadataOps
/// into a corresponding llvm::MDNodes.
/// A helper class that converts LoopAnnotationAttrs and AccessGroupAttrs into
/// corresponding llvm::MDNodes.
class LoopAnnotationTranslation {
public:
LoopAnnotationTranslation(ModuleTranslation &moduleTranslation,

View File

@ -361,7 +361,7 @@ LogicalResult ModuleImport::processTBAAMetadata(const llvm::MDNode *node) {
? builder.getStringAttr(**rootNodeIdentity)
: nullptr;
// The root nodes do not have operands, so we can create
// the TBAARootMetadataOp on the first walk.
// the TBAARootAttr on the first walk.
tbaaMapping.insert({current, builder.getAttr<TBAARootAttr>(stringAttr)});
continue;
}

View File

@ -1142,18 +1142,18 @@ llvm::MDNode *ModuleTranslation::getAliasScopes(
ArrayRef<AliasScopeAttr> aliasScopeAttrs) const {
SmallVector<llvm::Metadata *> nodes;
nodes.reserve(aliasScopeAttrs.size());
for (AliasScopeAttr aliasScopeRef : aliasScopeAttrs)
nodes.push_back(getAliasScope(aliasScopeRef));
for (AliasScopeAttr aliasScopeAttr : aliasScopeAttrs)
nodes.push_back(getAliasScope(aliasScopeAttr));
return llvm::MDNode::get(getLLVMContext(), nodes);
}
void ModuleTranslation::setAliasScopeMetadata(AliasAnalysisOpInterface op,
llvm::Instruction *inst) {
auto populateScopeMetadata = [&](ArrayAttr aliasScopeRefs, unsigned kind) {
if (!aliasScopeRefs || aliasScopeRefs.empty())
auto populateScopeMetadata = [&](ArrayAttr aliasScopeAttrs, unsigned kind) {
if (!aliasScopeAttrs || aliasScopeAttrs.empty())
return;
llvm::MDNode *node = getAliasScopes(
llvm::to_vector(aliasScopeRefs.getAsRange<AliasScopeAttr>()));
llvm::to_vector(aliasScopeAttrs.getAsRange<AliasScopeAttr>()));
inst->setMetadata(kind, node);
};
@ -1398,7 +1398,7 @@ mlir::translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext,
llvm::IRBuilder<> llvmBuilder(llvmContext);
for (Operation &o : getModuleBody(module).getOperations()) {
if (!isa<LLVM::LLVMFuncOp, LLVM::GlobalOp, LLVM::GlobalCtorsOp,
LLVM::GlobalDtorsOp, LLVM::MetadataOp, LLVM::ComdatOp>(&o) &&
LLVM::GlobalDtorsOp, LLVM::ComdatOp>(&o) &&
!o.hasTrait<OpTrait::IsTerminator>() &&
failed(translator.convertOperation(o, llvmBuilder))) {
return nullptr;