Skip to content

Deduplicate call-DAG traversals and cache nullptr in InferType - #1677

Open
rjodinchr wants to merge 1 commit into
google:mainfrom
rjodinchr:dedup-call-dag-traversals
Open

rjodinchr wants to merge 1 commit into
google:mainfrom
rjodinchr:dedup-call-dag-traversals

Conversation

@rjodinchr

Copy link
Copy Markdown
Collaborator

Several passes traversed call graphs or argument user chains without marking nodes as visited when enqueuing, causing exponential O(2^D) traversal times and memory growth on deep diamond call DAGs:

  • AutoPodArgsPass: insert into visited_fct when pushing to next_fcts_to_visit
  • ShareModuleScopeVariables: return early if entry_point is already recorded
  • CallGraphOrderedFunctions: deduplicate sorted callees list
  • SpecializeImageTypes: track visited arguments in RemapUse
  • AllocateDescriptorsPass: track visited arguments in HasReadsAndWrites
  • Types: cache nullptr in InferType to avoid re-traversing call graphs for untyped pointer arguments

Ref #1668

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces several optimizations and safety checks across various passes to prevent redundant processing and infinite recursion. Specifically, it adds visited-set checks in AllocateDescriptorsPass, AutoPodArgsPass, and SpecializeImageTypesPass, deduplicates callees in CallGraphOrderedFunctions, and optimizes entry point tracing in ShareModuleScopeVariablesPass. In Types.cpp, recursion guards and caching are introduced to InferType. However, a critical issue was identified where permanently caching nullptr in InferType can lead to incorrect type inference failures due to recursion guards. It is recommended to revert this change and return nullptr without caching it permanently.

Comment thread lib/Types.cpp
@rjodinchr
rjodinchr force-pushed the dedup-call-dag-traversals branch from 12cadbd to b50e36e Compare October 16, 2026 13:26
Comment thread lib/CallGraphOrderedFunctions.cpp Outdated
Several passes traversed call graphs or argument user chains without
marking nodes as visited when enqueuing, causing exponential O(2^D)
traversal times and memory growth on deep diamond call DAGs:
- AutoPodArgsPass: insert into visited_fct when pushing to next_fcts_to_visit
- ShareModuleScopeVariables: return early if entry_point is already recorded
- CallGraphOrderedFunctions: deduplicate sorted callees list
- SpecializeImageTypes: track visited arguments in RemapUse
- AllocateDescriptorsPass: track visited arguments in HasReadsAndWrites
- Types: cache nullptr in InferType to avoid re-traversing call graphs
  for untyped pointer arguments
@rjodinchr
rjodinchr force-pushed the dedup-call-dag-traversals branch from b50e36e to e20f6fe Compare October 17, 2026 13:43
@rjodinchr
rjodinchr requested a review from dneto0 October 17, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants