The Wayback Machine - https://web.archive.org/web/20220106232704/https://github.com/github/codeql/pull/7525
Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: Remove rank aggregate in SsaInternals #7525

Merged
merged 3 commits into from Jan 6, 2022

Conversation

@MathiasVP
Copy link
Contributor

@MathiasVP MathiasVP commented Jan 6, 2022

This is hopefully a behavior-preserving optimization 馃.

Thanks to @hvitved for suggesting this.

@MathiasVP MathiasVP added the C++ label Jan 6, 2022
@MathiasVP MathiasVP requested a review from as a code owner Jan 6, 2022
hvitved
hvitved approved these changes Jan 6, 2022
cached
final predicate hasRankInBlock(IRBlock block, int rnk) { rnk = getRank(this, block) }
/** Holds if this definition or use has index `index` in block `block`. */
final predicate hasIndexInBlock(IRBlock block, int index) {
Copy link
Contributor

@intrigus-lgtm intrigus-lgtm Jan 6, 2022

Choose a reason for hiding this comment

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

OOI: Why has the cached annotation been removed?

Copy link
Contributor

@rdmarsh2 rdmarsh2 Jan 6, 2022

Choose a reason for hiding this comment

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

The annotation was there to force the work done by getRank to be cached, but the new predicate uses the IRBlock::getInstruction member predicate, which itself uses a cached nonmember getInstruction predicate. Those predicates will all have the same contents and column order, so in practice any use of hasIndexInBlock will use the cached getInstruction directly.

cached
final predicate hasRankInBlock(IRBlock block, int rnk) { rnk = getRank(this, block) }
/** Holds if this definition or use has index `index` in block `block`. */
final predicate hasIndexInBlock(IRBlock block, int index) {
Copy link
Contributor

@intrigus-lgtm intrigus-lgtm Jan 6, 2022

Choose a reason for hiding this comment

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

Previously, hasRankInBlock could only hold for rnk \in [1, ...] because it delegates to getRank which uses a rank aggregate (and rank aggregates start at 1).
But hasIndexInBlock will now also hold for index in [0, ...] because it delegates to block.getInstruction which is zero-based I assume.

Isn't this a behavior change or is rnk/index only used transparently and so this does not matter?

Copy link
Contributor Author

@MathiasVP MathiasVP Jan 6, 2022

Choose a reason for hiding this comment

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

Good point. This isn't completely behavior preserving, but all current uses of this predicate shouldn't depend on this change for the exact reason that you mentioned :)

@rdmarsh2 rdmarsh2 merged commit d5682f1 into github:main Jan 6, 2022
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.