|
| 1 | +#include "clustered_netlist_fwd.h" |
1 | 2 | #include "vtr_assert.h"
|
2 | 3 | #include "vtr_log.h"
|
| 4 | +#include "vtr_optional.h" |
3 | 5 |
|
4 | 6 | #include "atom_lookup.h"
|
5 | 7 | /*
|
@@ -85,36 +87,51 @@ void AtomLookup::set_atom_clb(const AtomBlockId blk_id, const ClusterBlockId clb
|
85 | 87 | * Nets
|
86 | 88 | */
|
87 | 89 | AtomNetId AtomLookup::atom_net(const ClusterNetId clb_net_index) const {
|
88 |
| - auto iter = atom_net_to_clb_net_.find(clb_net_index); |
89 |
| - if (iter == atom_net_to_clb_net_.inverse_end()) { |
| 90 | + auto iter = clb_net_to_atom_net_.find(clb_net_index); |
| 91 | + if (iter == clb_net_to_atom_net_.end()) { |
90 | 92 | //Not found
|
91 | 93 | return AtomNetId::INVALID();
|
92 | 94 | }
|
93 | 95 | return iter->second;
|
94 | 96 | }
|
95 | 97 |
|
96 |
| -ClusterNetId AtomLookup::clb_net(const AtomNetId net_id) const { |
97 |
| - auto iter = atom_net_to_clb_net_.find(net_id); |
98 |
| - if (iter == atom_net_to_clb_net_.end()) { |
| 98 | +vtr::optional<const std::vector<ClusterNetId>&> AtomLookup::clb_nets(const AtomNetId atom_net) const { |
| 99 | + auto iter = atom_net_to_clb_nets_.find(atom_net); |
| 100 | + if (iter == atom_net_to_clb_nets_.end()) { |
99 | 101 | //Not found
|
100 |
| - return ClusterNetId::INVALID(); |
| 102 | + return vtr::nullopt; |
101 | 103 | }
|
102 | 104 | return iter->second;
|
103 | 105 | }
|
104 | 106 |
|
105 |
| -void AtomLookup::set_atom_clb_net(const AtomNetId net_id, const ClusterNetId clb_net_index) { |
106 |
| - VTR_ASSERT(net_id); |
107 |
| - //If either are invalid remove any mapping |
108 |
| - if (!net_id && clb_net_index != ClusterNetId::INVALID()) { |
109 |
| - //Remove |
110 |
| - atom_net_to_clb_net_.erase(clb_net_index); |
111 |
| - } else if (net_id && clb_net_index == ClusterNetId::INVALID()) { |
112 |
| - //Remove |
113 |
| - atom_net_to_clb_net_.erase(net_id); |
114 |
| - } else if (net_id && clb_net_index != ClusterNetId::INVALID()) { |
115 |
| - //Store |
116 |
| - atom_net_to_clb_net_.update(net_id, clb_net_index); |
| 107 | +void AtomLookup::add_atom_clb_net(const AtomNetId atom_net, const ClusterNetId clb_net) { |
| 108 | + VTR_ASSERT(atom_net && clb_net); |
| 109 | + |
| 110 | + /* Use the default behavior of [] operator */ |
| 111 | + atom_net_to_clb_nets_[atom_net].push_back(clb_net); |
| 112 | + clb_net_to_atom_net_[clb_net] = atom_net; |
| 113 | +} |
| 114 | + |
| 115 | +void AtomLookup::remove_clb_net(const ClusterNetId clb_net){ |
| 116 | + if(!clb_net_to_atom_net_.count(clb_net)) |
| 117 | + return; |
| 118 | + |
| 119 | + auto atom_net = clb_net_to_atom_net_[clb_net]; |
| 120 | + auto& all_clb_nets = atom_net_to_clb_nets_[atom_net]; |
| 121 | + /* This is o(n), but an AtomNetId rarely has >5 ClusterNetIds */ |
| 122 | + all_clb_nets.erase(std::remove(all_clb_nets.begin(), all_clb_nets.end(), clb_net), all_clb_nets.end()); |
| 123 | +} |
| 124 | + |
| 125 | +/* Remove mapping for given atom net */ |
| 126 | +void AtomLookup::remove_atom_net(const AtomNetId atom_net) { |
| 127 | + if(!atom_net_to_clb_nets_.count(atom_net)) |
| 128 | + return; |
| 129 | + |
| 130 | + auto cluster_nets = atom_net_to_clb_nets_[atom_net]; |
| 131 | + for(auto c: cluster_nets){ |
| 132 | + clb_net_to_atom_net_.erase(c); |
117 | 133 | }
|
| 134 | + atom_net_to_clb_nets_.erase(atom_net); |
118 | 135 | }
|
119 | 136 |
|
120 | 137 | /*
|
|
0 commit comments