-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[MLIR] Enable import of non self referential alias scopes #121987
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
Changes from 2 commits
023dbba
a2f845a
efe67be
bd0bb3c
b91ba34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -427,6 +427,11 @@ ModuleImport::processAliasScopeMetadata(const llvm::MDNode *node) { | |
| return node->getNumOperands() != 0 && | ||
| node == dyn_cast<llvm::MDNode>(node->getOperand(0)); | ||
| }; | ||
| auto verifySelfRefOrString = [](const llvm::MDNode *node) { | ||
| return node->getNumOperands() != 0 && | ||
| (node == dyn_cast<llvm::MDNode>(node->getOperand(0)) || | ||
| isa<llvm::MDString>(node->getOperand(0))); | ||
| }; | ||
| // Helper that verifies the given operand is a string or does not exist. | ||
| auto verifyDescription = [](const llvm::MDNode *node, unsigned idx) { | ||
| return idx >= node->getNumOperands() || | ||
|
|
@@ -438,8 +443,14 @@ ModuleImport::processAliasScopeMetadata(const llvm::MDNode *node) { | |
| if (aliasDomain->getNumOperands() >= 2) | ||
| if (auto *operand = dyn_cast<llvm::MDString>(aliasDomain->getOperand(1))) | ||
| description = builder.getStringAttr(operand->getString()); | ||
| return builder.getAttr<AliasScopeDomainAttr>( | ||
| DistinctAttr::create(builder.getUnitAttr()), description); | ||
| Attribute idAttr; | ||
| if (verifySelfRef(aliasDomain)) { | ||
| idAttr = DistinctAttr::create(builder.getUnitAttr()); | ||
| } else { | ||
| auto name = cast<llvm::MDString>(aliasDomain->getOperand(0)); | ||
| idAttr = builder.getStringAttr(name->getString()); | ||
| } | ||
|
||
| return builder.getAttr<AliasScopeDomainAttr>(idAttr, description); | ||
| }; | ||
|
|
||
| // Collect the alias scopes and domains to translate them. | ||
|
|
@@ -452,10 +463,11 @@ ModuleImport::processAliasScopeMetadata(const llvm::MDNode *node) { | |
| // verifying its domain. Perform the verification before looking it up in | ||
| // the alias scope mapping since it could have been inserted as a domain | ||
| // node before. | ||
| if (!verifySelfRef(scope) || !domain || !verifyDescription(scope, 2)) | ||
| if (!verifySelfRefOrString(scope) || !domain || | ||
| !verifyDescription(scope, 2)) | ||
| return emitError(loc) << "unsupported alias scope node: " | ||
| << diagMD(scope, llvmModule.get()); | ||
| if (!verifySelfRef(domain) || !verifyDescription(domain, 1)) | ||
| if (!verifySelfRefOrString(domain) || !verifyDescription(domain, 1)) | ||
| return emitError(loc) << "unsupported alias domain node: " | ||
| << diagMD(domain, llvmModule.get()); | ||
|
|
||
|
|
@@ -473,9 +485,17 @@ ModuleImport::processAliasScopeMetadata(const llvm::MDNode *node) { | |
| StringAttr description = nullptr; | ||
| if (!aliasScope.getName().empty()) | ||
| description = builder.getStringAttr(aliasScope.getName()); | ||
| Attribute idAttr; | ||
| if (verifySelfRef(scope)) { | ||
| idAttr = DistinctAttr::create(builder.getUnitAttr()); | ||
| } else { | ||
| auto Name = cast<llvm::MDString>(scope->getOperand(0)); | ||
ftynse marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| idAttr = builder.getStringAttr(Name->getString()); | ||
ftynse marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| auto aliasScopeOp = builder.getAttr<AliasScopeAttr>( | ||
| DistinctAttr::create(builder.getUnitAttr()), | ||
| cast<AliasScopeDomainAttr>(it->second), description); | ||
| idAttr, cast<AliasScopeDomainAttr>(it->second), description); | ||
|
|
||
| aliasScopeMapping.try_emplace(aliasScope.getNode(), aliasScopeOp); | ||
| } | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed in this PR: We should consider to introduce splits in these files, as debugging issues in this file is a menace. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -750,6 +750,16 @@ llvm.func @experimental_noalias_scope_decl() { | |||||
| llvm.return | ||||||
| } | ||||||
|
|
||||||
| #alias_scope_domain2 = #llvm.alias_scope_domain<id = "domainid", description = "The domain"> | ||||||
| #alias_scope2 = #llvm.alias_scope<id = "stringid", domain = #alias_scope_domain2, description = "The domain"> | ||||||
|
|
||||||
| // CHECK-LABEL: @experimental_noalias_scope_decl | ||||||
|
||||||
| // CHECK-LABEL: @experimental_noalias_scope_decl | |
| // CHECK-LABEL: @experimental_noalias_scope_decl2 |
nit: I would probably rename to @experimental_noalias_scope_decl_with_string_id rather than postfixing with a number. In any case the check line should match the function name.
Uh oh!
There was an error while loading. Please reload this page.