From 9e461284d01a628cf2b7a6dc54ba504d67a6517c Mon Sep 17 00:00:00 2001 From: tangxifan Date: Sat, 21 Sep 2024 21:38:32 -0700 Subject: [PATCH] [core] standardize API for clock network intermeidate drivers --- .../src/base/clock_network.cpp | 33 +++++++++++++++++++ .../src/base/clock_network.h | 7 +++- .../src/annotation/append_clock_rr_graph.cpp | 12 +------ .../src/annotation/route_clock_rr_graph.cpp | 24 ++------------ 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/libs/libclkarchopenfpga/src/base/clock_network.cpp b/libs/libclkarchopenfpga/src/base/clock_network.cpp index d70ed59a8..7c11c4541 100644 --- a/libs/libclkarchopenfpga/src/base/clock_network.cpp +++ b/libs/libclkarchopenfpga/src/base/clock_network.cpp @@ -283,6 +283,39 @@ std::vector ClockNetwork::spine_intermediate_drivers( return result->second; } +vtr::Point ClockNetwork::spine_intermediate_driver_routing_track_coord(const ClockSpineId& spine_id, const vtr::Point& coord) const { + vtr::Point des_coord(coord.x(), coord.y()); + Direction des_spine_direction = spine_direction(spine_id); + /* des node depends on the type of routing track and direction. But it + * should be a starting point at the current SB[x][y] */ + if (des_spine_direction == Direction::INC && + spine_track_type(spine_id) == CHANX) { + des_coord.set_x(coord.x() + 1); + } + if (des_spine_direction == Direction::INC && + spine_track_type(spine_id) == CHANY) { + des_coord.set_y(coord.y() + 1); + } + return des_coord; +} + +std::vector ClockNetwork::spine_intermediate_drivers_by_routing_track( + const ClockSpineId& spine_id, const vtr::Point& track_coord) const { + vtr::Point des_coord(track_coord.x(), track_coord.y()); + Direction des_spine_direction = spine_direction(spine_id); + /* des node depends on the type of routing track and direction. But it + * should be a starting point at the current SB[x][y] */ + if (des_spine_direction == Direction::INC && + spine_track_type(spine_id) == CHANX) { + des_coord.set_x(track_coord.x() - 1); + } + if (des_spine_direction == Direction::INC && + spine_track_type(spine_id) == CHANY) { + des_coord.set_y(track_coord.y() - 1); + } + return spine_intermediate_drivers(spine_id, des_coord); +} + ClockLevelId ClockNetwork::spine_level(const ClockSpineId& spine_id) const { VTR_ASSERT(valid_spine_id(spine_id)); if (is_dirty_) { diff --git a/libs/libclkarchopenfpga/src/base/clock_network.h b/libs/libclkarchopenfpga/src/base/clock_network.h index 1ee5dabcc..494d17220 100644 --- a/libs/libclkarchopenfpga/src/base/clock_network.h +++ b/libs/libclkarchopenfpga/src/base/clock_network.h @@ -97,8 +97,14 @@ class ClockNetwork { std::string spine_name(const ClockSpineId& spine_id) const; vtr::Point spine_start_point(const ClockSpineId& spine_id) const; vtr::Point spine_end_point(const ClockSpineId& spine_id) const; + /* Find the intermediate drivers by the SB coordinate */ std::vector spine_intermediate_drivers( const ClockSpineId& spine_id, const vtr::Point& coord) const; + /* Find the coordinate of routing track which the intermediate driver will driver. Note that the coordinate may be different than the coordinate of intermeidate driver. One of the exceptions lies in the CHANX with INC direction, which starts actually on the routing tracks on the right side of a SB, resulting in x -> x + 1. Another exception is on the CHANY with INC direction, which starts actually on the routing tracks on the top side of a SB, resulting in y - > y + 1. This function is to provide an official conversion the coordinates. */ + vtr::Point spine_intermediate_driver_routing_track_coord(const ClockSpineId& spine_id, const vtr::Point& coord) const; + /* Find the intermediate drivers by the routing track starting point. Note that the routing track starting point may be different from the SB coordinate. See the exceptions in the spine_intermediate_driver_track_coord() */ + std::vector spine_intermediate_drivers_by_routing_track( + const ClockSpineId& spine_id, const vtr::Point& track_coord) const; /* Return the level where the spine locates in the multi-layer clock tree * structure */ @@ -273,7 +279,6 @@ class ClockNetwork { /* Validate the internal data. Required to ensure clean data before usage. If * validation is successful, is_valid() will return true */ bool validate() const; - private: /* Public invalidators/validators */ /* Ensure tree data is clean. All the spines are valid, and switch points are * valid */ diff --git a/openfpga/src/annotation/append_clock_rr_graph.cpp b/openfpga/src/annotation/append_clock_rr_graph.cpp index d118c38f1..f45480b00 100644 --- a/openfpga/src/annotation/append_clock_rr_graph.cpp +++ b/openfpga/src/annotation/append_clock_rr_graph.cpp @@ -762,17 +762,7 @@ static int add_rr_graph_opin2clk_intermediate_edges( /* Get the rr node of destination spine */ Direction des_spine_direction = clk_ntwk.spine_direction(ispine); ClockLevelId des_spine_level = clk_ntwk.spine_level(ispine); - vtr::Point des_coord(coord.x(), coord.y()); - /* des node depends on the type of routing track and direction. But it - * should be a starting point at the current SB[x][y] */ - if (des_spine_direction == Direction::INC && - clk_ntwk.spine_track_type(ispine) == CHANX) { - des_coord.set_x(coord.x() + 1); - } - if (des_spine_direction == Direction::INC && - clk_ntwk.spine_track_type(ispine) == CHANY) { - des_coord.set_y(coord.y() + 1); - } + vtr::Point des_coord = clk_ntwk.spine_intermediate_driver_routing_track_coord(ispine, coord); RRNodeId des_node = clk_rr_lookup.find_node( des_coord.x(), des_coord.y(), clk_tree, des_spine_level, ipin, des_spine_direction, verbose); diff --git a/openfpga/src/annotation/route_clock_rr_graph.cpp b/openfpga/src/annotation/route_clock_rr_graph.cpp index 428dddc12..78f32eb65 100644 --- a/openfpga/src/annotation/route_clock_rr_graph.cpp +++ b/openfpga/src/annotation/route_clock_rr_graph.cpp @@ -440,17 +440,7 @@ static int rec_expand_and_route_clock_spine( * global net is mapped to the internal driver, use it as the previous * node */ size_t use_int_driver = 0; - vtr::Point int_driver_coord(des_coord.x(), des_coord.y()); - if (des_spine_direction == Direction::INC && - clk_ntwk.spine_track_type(curr_spine) == CHANX) { - int_driver_coord.set_x(des_coord.x() - 1); - } - if (des_spine_direction == Direction::INC && - clk_ntwk.spine_track_type(curr_spine) == CHANY) { - int_driver_coord.set_y(des_coord.y() - 1); - } - - if (!clk_ntwk.spine_intermediate_drivers(curr_spine, int_driver_coord) + if (!clk_ntwk.spine_intermediate_drivers_by_routing_track(curr_spine, des_coord) .empty() && tree2clk_pin_map.find(curr_pin) != tree2clk_pin_map.end()) { VTR_LOGV(verbose, @@ -517,17 +507,7 @@ static int rec_expand_and_route_clock_spine( * global net is mapped to the internal driver, use it as the previous * node */ size_t use_int_driver = 0; - vtr::Point int_driver_coord(des_coord.x(), des_coord.y()); - if (des_spine_direction == Direction::INC && - clk_ntwk.spine_track_type(curr_spine) == CHANX) { - int_driver_coord.set_x(des_coord.x() - 1); - } - if (des_spine_direction == Direction::INC && - clk_ntwk.spine_track_type(curr_spine) == CHANY) { - int_driver_coord.set_y(des_coord.y() - 1); - } - - if (!clk_ntwk.spine_intermediate_drivers(curr_spine, int_driver_coord) + if (!clk_ntwk.spine_intermediate_drivers_by_routing_track(curr_spine, des_coord) .empty() && tree2clk_pin_map.find(curr_pin) != tree2clk_pin_map.end()) { VTR_LOGV(