Skip to content

Conversation

uenoku
Copy link
Member

@uenoku uenoku commented Jul 1, 2025

This patch refactors the Longest Path Analysis in the AIG dialect with several enhancements:

  • Refactor DataflowPath to use a clean variant-based API for different endpoint types
  • Reorganize the API with purpose-specific methods replacing complex tuple returns
  • Add support for hierarchical path elaboration with prependPaths methods
  • Introduce a unified getAllPaths convenience method to collect all timing paths
  • Simplify the PrintLongestPathAnalysis pass to use the new API

The refactoring enables more comprehensive timing path analysis across module boundaries with proper hierarchical instance information while providing a cleaner, more maintainable API.

@uenoku uenoku force-pushed the dev/hidetou/refactor-aig branch 2 times, most recently from 0c57de8 to a4b1174 Compare July 1, 2025 04:17
@uenoku uenoku requested a review from teqdruid as a code owner July 1, 2025 04:26
@uenoku uenoku force-pushed the dev/hidetou/refactor-aig branch from eee46e9 to a29bea2 Compare July 1, 2025 04:36
@uenoku uenoku removed the request for review from teqdruid July 1, 2025 04:37
This patch refactors the Longest Path Analysis in the AIG dialect with several
enhancements:

- Refactor DataflowPath to use a clean variant-based API for different endpoint types
- Reorganize the API with purpose-specific methods replacing complex tuple returns
- Add support for hierarchical path elaboration with prependPaths methods
- Introduce a unified getAllPaths convenience method to collect all timing paths
- Simplify the PrintLongestPathAnalysis pass to use the new API

The refactoring enables more comprehensive timing path analysis across module
boundaries with proper hierarchical instance information while providing a
cleaner, more maintainable API.
@uenoku uenoku force-pushed the dev/hidetou/refactor-aig branch from a29bea2 to 9fc57cb Compare July 1, 2025 07:51
Copy link
Contributor

@fabianschuiki fabianschuiki left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +204 to +223
// Return input-to-internal timing paths for the given module.
// These are open paths from module input ports to internal sequential
// elements (registers/flip-flops).
LogicalResult getOpenPathsFromInputPortsToInternal(
StringAttr moduleName, SmallVectorImpl<DataflowPath> &results) const;

// Return internal-to-output timing paths for the given module.
// These are open paths from internal sequential elements to module output
// ports.
LogicalResult getOpenPathsFromInternalToOutputPorts(
StringAttr moduleName, SmallVectorImpl<DataflowPath> &results) const;

// Get all timing paths in the given module including both closed and open
// paths. This is a convenience method that combines results from
// getClosedPaths, getOpenPathsFromInputPortsToInternal, and
// getOpenPathsFromInternalToOutputPorts. If elaboratedPaths is true, paths
// include full hierarchical instance information.
LogicalResult getAllPaths(StringAttr moduleName,
SmallVectorImpl<DataflowPath> &results,
bool elaboratePaths = false) const;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice split! Convenient to have results be the same type everywhere.

// FanOut can be either an internal circuit object or a module output port
// This flexibility allows representing both closed paths
// (register-to-register) and open paths (register-to-output) in a unified way
using FanOutType = std::variant<Object, std::pair<size_t, size_t>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably not really useful, but maybe a using Port = std::pair<size_t, size_t> could help give the int pair discernible meaning?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! I created OutputPort alias as input port is represented as blockarg.

Comment on lines +260 to +261
using Info = llvm::DenseMapInfo<
std::tuple<circt::igraph::InstancePath, mlir::Value, size_t>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Clever 😏

Comment on lines +1401 to +1403
if (elaboratePaths)
return impl->getClosedPaths<true>(moduleName, results);
return impl->getClosedPaths<false>(moduleName, results);
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you pull the elaborate boolean out into a template argument to get two optimized hot loops in getClosedPaths for the two cases? That's pretty neat 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep 👍

@uenoku uenoku merged commit 4205d72 into llvm:main Jul 1, 2025
7 checks passed
TaoBi22 pushed a commit to TaoBi22/circt that referenced this pull request Jul 17, 2025
…lvm#8630)

This patch refactors the Longest Path Analysis in the AIG dialect with several
enhancements:

- Refactor DataflowPath to use a clean variant-based API for different endpoint types
- Reorganize the API with purpose-specific methods replacing complex tuple returns
- Add support for hierarchical path elaboration with prependPaths methods
- Introduce a unified getAllPaths convenience method to collect all timing paths
- Simplify the PrintLongestPathAnalysis pass to use the new API

The refactoring enables more comprehensive timing path analysis across module
boundaries with proper hierarchical instance information while providing a
cleaner, more maintainable API.
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