From 43f15e4d6f4beb92a1922194e1b3cc8ad4584a08 Mon Sep 17 00:00:00 2001 From: tangxifan Date: Wed, 19 Feb 2020 16:40:53 -0700 Subject: [PATCH] add methods to LbRouter for nets to be routed and access to routing traceback --- openfpga/src/repack/lb_router.cpp | 59 ++++++++++++++++++++++++++++++- openfpga/src/repack/lb_router.h | 15 +++++++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/openfpga/src/repack/lb_router.cpp b/openfpga/src/repack/lb_router.cpp index 610501dde..3ce17deaa 100644 --- a/openfpga/src/repack/lb_router.cpp +++ b/openfpga/src/repack/lb_router.cpp @@ -59,6 +59,22 @@ bool LbRouter::is_routed() const { return is_routed_; } +std::vector LbRouter::net_routed_nodes(const NetId& net) const { + VTR_ASSERT(true == is_routed()); + VTR_ASSERT(true == valid_net_id(net)); + + std::vector routed_nodes; + + t_trace* rt_tree = lb_net_rt_trees_[net]; + if (nullptr == rt_tree) { + return routed_nodes; + } + /* Walk through the routing tree of the net */ + rec_collect_trace_nodes(rt_tree, routed_nodes); + + return routed_nodes; +} + /************************************************** * Private accessors *************************************************/ @@ -108,9 +124,47 @@ bool LbRouter::route_has_conflict(const LbRRGraph& lb_rr_graph, t_trace* rt) con return false; } +void LbRouter::rec_collect_trace_nodes(const t_trace* trace, std::vector& routed_nodes) const { + if (routed_nodes.end() == std::find(routed_nodes.begin(), routed_nodes.end(), trace->current_node)) { + routed_nodes.push_back(trace->current_node); + } + + for (const t_trace& next : trace->next_nodes) { + rec_collect_trace_nodes(&next, routed_nodes); + } +} + /************************************************** * Public mutators *************************************************/ +LbRouter::NetId LbRouter::create_net_to_route(const LbRRNodeId& source, const std::vector& terminals) { + /* Create an new id */ + NetId net = NetId(lb_net_ids_.size()); + lb_net_ids_.push_back(net); + + /* Allocate other attributes */ + lb_net_atom_net_ids_.push_back(AtomNetId::INVALID()); + lb_net_atom_pins_.emplace_back(); + + std::vector net_terminals = terminals; + net_terminals.insert(net_terminals.begin(), source); + + lb_net_terminals_.push_back(net_terminals); + + return net; +} + +void LbRouter::add_net_atom_net_id(const NetId& net, const AtomNetId& atom_net) { + VTR_ASSERT(true == valid_net_id(net)); + lb_net_atom_net_ids_[net] = atom_net; +} + +void LbRouter::add_net_atom_pins(const NetId& net, const AtomPinId& src_pin, const std::vector& terminal_pins) { + VTR_ASSERT(true == valid_net_id(net)); + lb_net_atom_pins_[net] = terminal_pins; + lb_net_atom_pins_[net].insert(lb_net_atom_pins_[net].begin(), src_pin); +} + bool LbRouter::try_route(const LbRRGraph& lb_rr_graph, const AtomNetlist& atom_nlist, const int& verbosity) { @@ -644,6 +698,10 @@ bool LbRouter::matched_lb_rr_graph(const LbRRGraph& lb_rr_graph) const { && (explored_node_tb_.size() == lb_rr_graph.nodes().size()) ); } +bool LbRouter::valid_net_id(const NetId& net_id) const { + return ( size_t(net_id) < lb_net_ids_.size() ) && ( net_id == lb_net_ids_[net_id] ); +} + /************************************************** * Private Initializer and cleaner *************************************************/ @@ -679,7 +737,6 @@ void LbRouter::clear_nets() { lb_net_atom_net_ids_.clear(); lb_net_atom_pins_.clear(); lb_net_terminals_.clear(); - lb_net_fixed_terminals_.clear(); lb_net_rt_trees_.clear(); } diff --git a/openfpga/src/repack/lb_router.h b/openfpga/src/repack/lb_router.h index a922d1fb4..117ede40c 100644 --- a/openfpga/src/repack/lb_router.h +++ b/openfpga/src/repack/lb_router.h @@ -170,10 +170,19 @@ class LbRouter { /* Show if a valid routing solution has been founded or not */ bool is_routed() const; + /** + * Get the routing results for a Net + */ + std::vector net_routed_nodes(const NetId& net) const; + public : /* Public mutators */ /** * Add net to be routed */ + NetId create_net_to_route(const LbRRNodeId& source, const std::vector& terminals); + void add_net_atom_net_id(const NetId& net, const AtomNetId& atom_net); + void add_net_atom_pins(const NetId& net, const AtomPinId& src_pin, const std::vector& terminal_pins); + void set_net_fix_terminal(const NetId& net, const LbRRNodeId& terminal, const bool& fix); /** * Perform routing algorithm on a given logical tile routing resource graph @@ -197,6 +206,9 @@ class LbRouter { bool route_has_conflict(const LbRRGraph& lb_rr_graph, t_trace* rt) const; + /* Recursively find all the nodes in the trace */ + void rec_collect_trace_nodes(const t_trace* trace, std::vector& routed_nodes) const; + private : /* Private mutators */ /*It is possible that a net may connect multiple times to a logically equivalent set of primitive pins. *The cluster router will only route one connection for a particular net to the common sink of the @@ -249,6 +261,8 @@ class LbRouter { */ bool matched_lb_rr_graph(const LbRRGraph& lb_rr_graph) const; + bool valid_net_id(const NetId& net_id) const; + private : /* Private initializer and cleaner */ void reset_explored_node_tb(); void reset_net_rt(); @@ -265,7 +279,6 @@ class LbRouter { vtr::vector lb_net_atom_net_ids_; /* index of atom net this intra_lb_net represents */ vtr::vector> lb_net_atom_pins_; /* AtomPin's associated with each terminal */ vtr::vector> lb_net_terminals_; /* endpoints of the intra_lb_net, 0th position is the source, all others are sinks */ - vtr::vector> lb_net_fixed_terminals_; /* Marks a terminal as having a fixed target (i.e. a pin not a sink) */ vtr::vector lb_net_rt_trees_; /* Route tree head */ /* Logical-to-physical mapping info */