Skip to content

Commit

Permalink
[mlir][llvm] Remove the metadata op
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gysit committed Jul 26, 2023
1 parent f6307b2 commit 0fc8d9e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 85 deletions.
31 changes: 0 additions & 31 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 0 additions & 43 deletions mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//===----------------------------------------------------------------------===//
Expand Down
3 changes: 1 addition & 2 deletions mlir/lib/Target/LLVMIR/LoopAnnotationImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Target/LLVMIR/LoopAnnotationTranslation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Target/LLVMIR/ModuleImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0fc8d9e

Please sign in to comment.