-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[mlir][Transforms] --remove-dead-values: keep values used in public function calls #83249
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?
Changes from all commits
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 |
---|---|---|
|
@@ -169,7 +169,10 @@ static SmallVector<OpOperand *> operandsToOpOperands(OperandRange operands) { | |
/// Here, cleaning means: | ||
/// (1) Dropping all its uses, AND | ||
/// (2) Erasing it | ||
/// iff it has no memory effects and none of its results are live. | ||
/// iff: | ||
/// (1) It has no memory effects | ||
/// (2) None of its results are live | ||
/// (3) It is not used as an argument in a public function call | ||
/// | ||
/// It is assumed that `op` is simple. Here, a simple op is one which isn't a | ||
/// symbol op, a symbol-user op, a region branch op, a branch op, a region | ||
|
@@ -178,6 +181,12 @@ static void cleanSimpleOp(Operation *op, RunLivenessAnalysis &la) { | |
if (!isMemoryEffectFree(op) || hasLive(op->getResults(), la)) | ||
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. I never looked into the liveness analysis, but shouldn't a value be considered "alive" it is passed as a function call operand? 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. From what I understand, if the parameter is not used inside the function, the value (argument) will not be considered "alive". |
||
return; | ||
|
||
for (OpOperand &use : op->getUses()) | ||
if (auto callOp = dyn_cast<CallOpInterface>(use.getOwner())) | ||
if (auto funcOp = dyn_cast<FunctionOpInterface>(callOp.resolveCallable())) | ||
if (funcOp.isPublic()) | ||
return; | ||
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. How does this work transitively though? To me it seems like we can still kill the op here, we could replace the SSA value with "undef" since it is dead 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. I see 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. @joker-eph ping |
||
|
||
op->dropAllUses(); | ||
op->erase(); | ||
} | ||
|
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.
Why does it matter whether the function is private or public?
Uh oh!
There was an error while loading. Please reload this page.
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've posted a detailed analysis here: #82788 (comment). Please also see a test case. The short answer is that if the function is public, its unused parameters will not be removed, but the argument is erased, resulting in a NULL value error afterwards.
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.
You can't touch a function API when you don't see all the calls, and by definition a public function has external calls you don't see.
You may clone the function to specialize it though, but that's a different tradeoff to make