Skip to content

Conversation

MathiasVP
Copy link
Contributor

@MathiasVP MathiasVP commented Sep 4, 2025

We've seen quite high iteration counts for this predicate in C/C++ on some projects. I don't see why we shouldn't use a HOP here 🤷

In particular, this significantly reduces the analysis time on https://github.com/openvinotoolkit/oneDNN when running with --ram=6000 (which we saw in the 2.23.0 upgrade)

@MathiasVP MathiasVP force-pushed the source-bounded-fast-tc-in-typetracking branch from 09ff926 to efa5766 Compare September 5, 2025 11:57
@MathiasVP MathiasVP marked this pull request as ready for review September 5, 2025 14:59
@Copilot Copilot AI review requested due to automatic review settings September 5, 2025 14:59
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Sep 5, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes the TypeTracking implementation by using sourceBoundedFastTC for transitive closure computation instead of manual recursion. The change aims to reduce high iteration counts observed in C/C++ projects by leveraging a Higher-Order Predicate (HOP) for better performance.

Key Changes

  • Replaced manual recursion in standardFlowsTo with sourceBoundedFastTC transitive closure
  • Introduced simpleLocalSmallStepPlus predicate using the optimized transitive closure
  • Modified isLocalSourceNode predicate to support the new approach

@MathiasVP MathiasVP force-pushed the source-bounded-fast-tc-in-typetracking branch from efa5766 to eae9a6f Compare September 8, 2025 08:35
}

private predicate simpleLocalSmallStepPlus(Node localSource, Node dst) =
sourceBoundedFastTC(simpleLocalSmallStep/2, isLocalSourceNode/1)(localSource, dst)

cached
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it better to cache simpleLocalSmallStepPlus, which will persist the underlying FastTC structure instead of the materialized relation? standardFlowsTo then needs to be non-cached and pragma[inline]ed. See also

predicate epsilonStar(ApiNode pred, ApiNode succ) = fastTC(epsilonEdge/2)(pred, succ)
for another example of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uh, that's a good idea. I didn't actually know that caching a fastTC didn't just cache the materialized relation. I've fixed this in bd7e20d

@MathiasVP MathiasVP force-pushed the source-bounded-fast-tc-in-typetracking branch from 4dd45dc to bd7e20d Compare September 9, 2025 09:53
@MathiasVP MathiasVP force-pushed the source-bounded-fast-tc-in-typetracking branch from bd7e20d to 3aee4a8 Compare September 9, 2025 11:22
@@ -70,6 +70,10 @@ module TypeTracking<LocationSig Location, TypeTrackingInput<Location> I> {

private class ContentOption = ContentOption::Option;

private predicate isLocalSourceNode(LocalSourceNode n) {
Copy link
Contributor

@aschackmull aschackmull Sep 10, 2025

Choose a reason for hiding this comment

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

This is a small helper for standardFlowsTo. I think it should be moved down, so it appears directly before standardFlowsTo. Also, check whether the RA is affected by manually inlining this - if not, then that simplifies things. Gah, never mind, it's of course also input to the TC.

@MathiasVP
Copy link
Contributor Author

:til: when you fix a Code Scanning warning the conversation just ... disappears? I've made standardFlowsTo private in f8bdf92 now. Thanks for explaining how it should be fixed, @aschackmull! I was planning on asking either you or the Foundations team about it at some point so I appreciate that you just told me an easy fix (which I guess I could've also spotted by looking at the ql-for-ql query 😅)

@MathiasVP MathiasVP merged commit edec76a into github:main Sep 10, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants