This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][Liveness][RFC][NFC] Propose to turn statement liveness into expression liveness
AbandonedPublic

Authored by Szelethus on Jun 18 2020, 1:17 PM.

Details

Summary

I had a bit of fun with the tags.

Liveness analysis calculates the set of live/dead values in the program. However, statements don't always have a value associated with them, expressions do. For this reason, I found it puzzling why LivenessAnalysis work with "live statements", or answers questions such as "is this statement live". After a bit of digging, I found that the only client of statement liveness is EnvironmentManager::removeDeadBindings (the one modified in this patch), and the only non-expression statement it queries are ObjCForCollectionStmts, but no lit tests crashed on the added asserts.

This patch isn't necesserily intended to be committed -- it more of a request for comments whether it would be safe to change statement liveness to strictly expression liveness. It would be great, because my ultimate goal is to merge the implementation of UninitializedVariable and LivenessAnalaysis, and add Reaching Definitions under the same hood, but the statement liveness was very much out of place and makes the merge very awkward, if even possible.

I have a number of changes planned, but I didn't want to go too far ahead of myself, in case I missed something fundamental that justifies statement liveness as it is.

Diff Detail

Event Timeline

Szelethus created this revision.Jun 18 2020, 1:17 PM
NoQ added a comment.Jun 19 2020, 7:43 AM

I think you're right, this entire thing only makes sense for expressions. I think Environment occasionally carries values of ReturnStmts (by which it means values of their sub-expressions) but even then liveness analysis doesn't need to be aware of that flex.

no lit tests crashed on the added asserts

the only non-expression statement it queries are ObjCForCollectionStmts

Wait, how did you figure that out if not through crashing tests?

Szelethus marked an inline comment as done.Jun 20 2020, 4:28 AM
Szelethus added inline comments.
clang/lib/StaticAnalyzer/Core/Environment.cpp
193
In D82122#2103638, @NoQ wrote:

I think you're right, this entire thing only makes sense for expressions. I think Environment occasionally carries values of ReturnStmts (by which it means values of their sub-expressions) but even then liveness analysis doesn't need to be aware of that flex.

no lit tests crashed on the added asserts

the only non-expression statement it queries are ObjCForCollectionStmts

Wait, how did you figure that out if not through crashing tests?

if (IsBlkExprLive && !isa<Expr>(BlkExpr.getStmt()) {
  BlkExpr.getStmt()->dump();
  llvm_unreachable("Gotcha!");
}

Cheers! I'll leave this here for conversation's sake, and start working on refactoring LivenessAnalysis.

Szelethus abandoned this revision.Jun 25 2020, 3:46 PM

This revision has done its job.

This was accidentally committed as a part of rGb6cbe6cb0399d4671e5384dcc326af56bc6bd122.