Skip to content

C++: add support for GNU StmtExpr in IR#984

Merged
rdmarsh2 merged 6 commits into
github:masterfrom
rdmarsh2:rdmarsh/cpp/ir-stmtexpr
Apr 9, 2019
Merged

C++: add support for GNU StmtExpr in IR#984
rdmarsh2 merged 6 commits into
github:masterfrom
rdmarsh2:rdmarsh/cpp/ir-stmtexpr

Conversation

@rdmarsh2
Copy link
Copy Markdown
Contributor

No description provided.

@rdmarsh2 rdmarsh2 added the C++ label Feb 25, 2019
@rdmarsh2 rdmarsh2 requested a review from a team as a code owner February 25, 2019 19:31
@rdmarsh2 rdmarsh2 force-pushed the rdmarsh/cpp/ir-stmtexpr branch from 73250dc to b39d985 Compare February 25, 2019 19:40
Copy link
Copy Markdown
Contributor

@dave-bartolomeo dave-bartolomeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple minor but important issues.

}

override Instruction getChildSuccessor(TranslatedElement child) {
result = getParent().getChildSuccessor(this)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs and child = getStmt() to avoid holding for all TranslatedElements in the snapshot.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rdmarsh2 Given that this went unnoticed, please make sure you test these changes for performance on a snapshot that uses many statement expressions. The heaviest user I know of is the Linux kernel.

}

override Instruction getResult() {
result = getTranslatedExpr(expr.getResultExpr()).getResult()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
result = getTranslatedExpr(expr.getResultExpr()).getResult()
result = getTranslatedExpr(expr.getResultExpr().getFullyConverted()).getResult()

Comment thread cpp/ql/test/library-tests/ir/ir/ir.cpp Outdated
return a[0] + fn(1.0);
}

int ExprStmt(int x) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add another test case with multiple statements and some control flow within the StmtExpr.

# 1002| 1: return ...
# 1002| 0: (statement expression)
# 1002| Type = int
# 1002| ValueCategory = prvalue
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like PrintAST doesn't support StmtExpr. That's not a blocker for this PR.

Copy link
Copy Markdown
Contributor

@dave-bartolomeo dave-bartolomeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but please check performance on Linux kernel snapshot as suggested by @jbj.

@rdmarsh2
Copy link
Copy Markdown
Contributor Author

rdmarsh2 commented Apr 1, 2019

Benchmarked - it's about a 7% slowdown on the Linux kernel. Over 20% of functions in the kernel have a statement expression included, which means that without this PR, portions of the function are unreachable in the raw IR and therefore don't have later stages of IR generation performed. Given that, the slowdown actually seems smaller than I would have guessed. I'll get the conflicts fixed tomorrow.

@jbj
Copy link
Copy Markdown
Contributor

jbj commented Apr 2, 2019

7% sounds like a lot. Does it mean 7% time added to the query select strictcount(Instruction i) from a clean cache? If so, that's a lot. How does the result of that query compare before and after this change? Does the number of Instructions go up by about 7% too?

Are there any predicates or stages that stand out as contributing the majority of this 7% slowdown? How does performance change on a big snapshot that doesn't use StmtExpr at all?

@rdmarsh2
Copy link
Copy Markdown
Contributor Author

rdmarsh2 commented Apr 2, 2019

The number of instructions in the final IR goes from 6,538,958 to 8,986,093 - an increase of about 37%. On master, raw IR generation is performed for the contents of the StmtExpr and for all of its successors, but anything that is reachable only via the StmtExpr is excluded as unreachable while building unaliased SSA, so the change only increases the number of tuples starting with dominance and reachability predicates on the raw IR. I think these numbers roughly line up with the percentage of time spent in those stages.

@rdmarsh2
Copy link
Copy Markdown
Contributor Author

rdmarsh2 commented Apr 4, 2019

Testing on Wireshark shows a 3% increase in instructions in the final IR, and no meaningful change in evaluation time (2 second increase on a 40 minute run)

@rdmarsh2 rdmarsh2 force-pushed the rdmarsh/cpp/ir-stmtexpr branch from 4f5dd2a to 46f93ff Compare April 4, 2019 17:55
dave-bartolomeo
dave-bartolomeo previously approved these changes Apr 4, 2019
Copy link
Copy Markdown
Contributor

@dave-bartolomeo dave-bartolomeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once the test failures are fixed

jbj
jbj previously approved these changes Apr 5, 2019
Copy link
Copy Markdown
Contributor

@jbj jbj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for verifying performance.

@rdmarsh2
Copy link
Copy Markdown
Contributor Author

rdmarsh2 commented Apr 5, 2019

That test failure actually shows a potential issue. We don't generate an instruction for the StmtExpr, and instead just pass the result instruction of the last expression to the parent of the StmtExpr. That means the selected location doesn't quite match the old data flow library. We could potentially insert a copy instruction to make that location appear.

@jbj
Copy link
Copy Markdown
Contributor

jbj commented Apr 5, 2019

Inserting a copy instruction sounds good. I agree we should aim to map each AST element to a unique IR element.

@rdmarsh2 rdmarsh2 dismissed stale reviews from jbj and dave-bartolomeo via 8087cb5 April 5, 2019 18:27
@rdmarsh2 rdmarsh2 merged commit c9fbbfe into github:master Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants