-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[mlir] Use getAttr to replace getInherentAttr in the test-symbol-uses pass #172675
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
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-mlir Author: lonely eagle (linuxlonelyeagle) ChangesFix #172603. Full diff: https://github.com/llvm/llvm-project/pull/172675.diff 1 Files Affected:
diff --git a/mlir/test/lib/IR/TestSymbolUses.cpp b/mlir/test/lib/IR/TestSymbolUses.cpp
index b470b15c533b5..59014b93a0df7 100644
--- a/mlir/test/lib/IR/TestSymbolUses.cpp
+++ b/mlir/test/lib/IR/TestSymbolUses.cpp
@@ -59,7 +59,7 @@ struct SymbolUsesPass
symbolUse.getUser()->getParentOp(), symbolUse.getSymbolRef())) {
symbolUse.getUser()->emitRemark()
<< "found use of symbol : " << symbolUse.getSymbolRef() << " : "
- << *symbol->getInherentAttr(SymbolTable::getSymbolAttrName());
+ << symbol->getAttr(SymbolTable::getSymbolAttrName());
}
}
symbol->emitRemark() << "symbol has " << llvm::size(*symbolUses) << " uses";
|
|
I didn't add anything new, I just fixed it by changing the use of the API. So I didn't add any new tests. |
| @@ -59,7 +59,7 @@ struct SymbolUsesPass | |||
| symbolUse.getUser()->getParentOp(), symbolUse.getSymbolRef())) { | |||
| symbolUse.getUser()->emitRemark() | |||
| << "found use of symbol : " << symbolUse.getSymbolRef() << " : " | |||
| << *symbol->getInherentAttr(SymbolTable::getSymbolAttrName()); | |||
| << symbol->getAttr(SymbolTable::getSymbolAttrName()); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getAttr should be considered deprecated.
There is something suspicious here: which operation is "symbol" here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the "launch_func" is the culprit, it does not seem to be defined as SymbolUserOpInterface, so I'm not even sure why it is visited at all. We seem to have some inconsistency here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no, this is necessarily an operation defining the SymbolOpInterface, can't be launch_func
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So can we update:
WalkResult operateOnSymbol(Operation *symbol,
to be:
WalkResult operateOnSymbol(SymbolOpInterface symbol,
and rely on the interface instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest with you, I'm a bit confused. Using getAttr surprisingly works.I looked at the implementation of getAttr. Isn't it because getProperties Storage Size() returned 0? I thought dict-attr was not used when defining 'launch_func'. If there is anything wrong, I hope to point it out. I am sure there are some areas that I am not very clear about.😂
Attribute getAttr(StringRef name) {
if (getPropertiesStorageSize()) {
if (std::optional<Attribute> inherentAttr = getInherentAttr(name))
return *inherentAttr;
}
return attrs.get(name);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So can we update:
WalkResult operateOnSymbol(Operation *symbol,to be:
WalkResult operateOnSymbol(SymbolOpInterface symbol,and rely on the interface instead?
I think there is something a bit incorrect, I don't know if I misunderstood. Accessing "launch_func" is done through walk "gpu. func". The walk function does not directly access " launch_func ", In the crash example, it first walked "func.func" and then "gpu.func".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the "launch_func" is the culprit, it does not seem to be defined as
SymbolUserOpInterface, so I'm not even sure why it is visited at all. We seem to have some inconsistency here.
When walking to "gpu.func", the "symbol" (follow variable) is "gpu.func", we use SymbolTable::getSymbolUses(symbol, &module.getBodyRegion()); to visit the "launch_func"
symbolUses = SymbolTable::getSymbolUses(symbol, &module.getBodyRegion());
assert(symbolUses && "expected no unknown operations");
for (SymbolTable::SymbolUse symbolUse : *symbolUses) {
// Check that we can resolve back to our symbol.
if (SymbolTable::lookupNearestSymbolFrom(
symbolUse.getUser()->getParentOp(), symbolUse.getSymbolRef())) {
symbolUse.getUser()->emitRemark()
<< "found use of symbol : " << symbolUse.getSymbolRef() << " : "
<< symbol->getAttr(SymbolTable::getSymbolAttrName());
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is something a bit incorrect, I don't know if I misunderstood. Accessing "launch_func" is done through walk "gpu. func". The walk function does not directly access " launch_func ", In the crash example, it first walked "func.func" and then "gpu.func".
I am not talking about launch_fun, the diff I sent above is unrelated to launch_func. It is about the method used to get the symbol ref and the use of the interface.
Fix #172603.