|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * @author Alex Singer |
| 4 | + * @date September 2024 |
| 5 | + * @brief The definitions of the APNetlist methods |
| 6 | + */ |
| 7 | + |
| 8 | +#include "ap_netlist.h" |
| 9 | +#include <string> |
| 10 | +#include "netlist_fwd.h" |
| 11 | +#include "netlist_utils.h" |
| 12 | +#include "vpr_types.h" |
| 13 | +#include "vtr_assert.h" |
| 14 | + |
| 15 | +/* |
| 16 | + * Blocks |
| 17 | + */ |
| 18 | +const t_pack_molecule* APNetlist::block_molecule(const APBlockId id) const { |
| 19 | + VTR_ASSERT_SAFE(valid_block_id(id)); |
| 20 | + |
| 21 | + return block_molecules_[id]; |
| 22 | +} |
| 23 | + |
| 24 | +APBlockMobility APNetlist::block_mobility(const APBlockId id) const { |
| 25 | + VTR_ASSERT_SAFE(valid_block_id(id)); |
| 26 | + |
| 27 | + return block_mobilities_[id]; |
| 28 | +} |
| 29 | + |
| 30 | +const APFixedBlockLoc& APNetlist::block_loc(const APBlockId id) const { |
| 31 | + VTR_ASSERT_SAFE(valid_block_id(id)); |
| 32 | + VTR_ASSERT(block_mobility(id) == APBlockMobility::FIXED); |
| 33 | + |
| 34 | + return block_locs_[id]; |
| 35 | +} |
| 36 | + |
| 37 | +/* |
| 38 | + * Mutators |
| 39 | + */ |
| 40 | +APBlockId APNetlist::create_block(const std::string& name, const t_pack_molecule* mol) { |
| 41 | + APBlockId blk_id = Netlist::create_block(name); |
| 42 | + |
| 43 | + // Initialize the data |
| 44 | + block_molecules_.insert(blk_id, mol); |
| 45 | + block_mobilities_.insert(blk_id, APBlockMobility::MOVEABLE); |
| 46 | + block_locs_.insert(blk_id, APFixedBlockLoc()); |
| 47 | + |
| 48 | + // Check post-conditions: size |
| 49 | + VTR_ASSERT(validate_block_sizes()); |
| 50 | + |
| 51 | + // Check post-conditions: values |
| 52 | + VTR_ASSERT(block_molecule(blk_id) == mol); |
| 53 | + VTR_ASSERT(block_mobility(blk_id) == APBlockMobility::MOVEABLE); |
| 54 | + |
| 55 | + return blk_id; |
| 56 | +} |
| 57 | + |
| 58 | +void APNetlist::set_block_loc(const APBlockId id, const APFixedBlockLoc& loc) { |
| 59 | + VTR_ASSERT_SAFE(valid_block_id(id)); |
| 60 | + |
| 61 | + // Check that the location is fixed, if all values are -1 then it is not fixed. |
| 62 | + if (loc.x == -1 && loc.y == -1 && loc.sub_tile == -1 && loc.layer_num == -1) |
| 63 | + return; |
| 64 | + |
| 65 | + block_locs_[id] = loc; |
| 66 | + block_mobilities_[id] = APBlockMobility::FIXED; |
| 67 | +} |
| 68 | + |
| 69 | +APPortId APNetlist::create_port(const APBlockId blk_id, const std::string& name, BitIndex width, PortType type) { |
| 70 | + APPortId port_id = find_port(blk_id, name); |
| 71 | + if (!port_id) { |
| 72 | + port_id = Netlist::create_port(blk_id, name, width, type); |
| 73 | + associate_port_with_block(port_id, type, blk_id); |
| 74 | + } |
| 75 | + |
| 76 | + // Check post-conditions: size |
| 77 | + VTR_ASSERT(validate_port_sizes()); |
| 78 | + |
| 79 | + // Check post-conditions: values |
| 80 | + VTR_ASSERT(port_name(port_id) == name); |
| 81 | + VTR_ASSERT(find_port(blk_id, name) == port_id); |
| 82 | + |
| 83 | + return port_id; |
| 84 | +} |
| 85 | + |
| 86 | +APPinId APNetlist::create_pin(const APPortId port_id, BitIndex port_bit, const APNetId net_id, const PinType pin_type_, bool is_const) { |
| 87 | + APPinId pin_id = Netlist::create_pin(port_id, port_bit, net_id, pin_type_, is_const); |
| 88 | + |
| 89 | + // Check post-conditions: size |
| 90 | + VTR_ASSERT(validate_pin_sizes()); |
| 91 | + |
| 92 | + // Check post-conditions: values |
| 93 | + VTR_ASSERT(pin_type(pin_id) == pin_type_); |
| 94 | + VTR_ASSERT(pin_port(pin_id) == port_id); |
| 95 | + VTR_ASSERT(pin_port_type(pin_id) == port_type(port_id)); |
| 96 | + |
| 97 | + return pin_id; |
| 98 | +} |
| 99 | + |
| 100 | +APNetId APNetlist::create_net(const std::string& name) { |
| 101 | + APNetId net_id = Netlist::create_net(name); |
| 102 | + |
| 103 | + // Check post-conditions: size |
| 104 | + VTR_ASSERT(validate_net_sizes()); |
| 105 | + |
| 106 | + return net_id; |
| 107 | +} |
| 108 | + |
| 109 | +/* |
| 110 | + * Internal utilities |
| 111 | + */ |
| 112 | +void APNetlist::clean_blocks_impl(const vtr::vector_map<APBlockId, APBlockId>& block_id_map) { |
| 113 | + // Update all the block molecules |
| 114 | + block_molecules_ = clean_and_reorder_values(block_molecules_, block_id_map); |
| 115 | + // Update all the block mobilities |
| 116 | + block_mobilities_ = clean_and_reorder_values(block_mobilities_, block_id_map); |
| 117 | + // Update the fixed block locations |
| 118 | + block_locs_ = clean_and_reorder_values(block_locs_, block_id_map); |
| 119 | +} |
| 120 | + |
| 121 | +void APNetlist::clean_ports_impl(const vtr::vector_map<APPortId, APPortId>& /*port_id_map*/) { |
| 122 | + // Unused |
| 123 | +} |
| 124 | + |
| 125 | +void APNetlist::clean_pins_impl(const vtr::vector_map<APPinId, APPinId>& /*pin_id_map*/) { |
| 126 | + // Unused |
| 127 | +} |
| 128 | + |
| 129 | +void APNetlist::clean_nets_impl(const vtr::vector_map<APNetId, APNetId>& /*net_id_map*/) { |
| 130 | + // Unused |
| 131 | +} |
| 132 | + |
| 133 | +void APNetlist::rebuild_block_refs_impl(const vtr::vector_map<APPinId, APPinId>& /*pin_id_map*/, |
| 134 | + const vtr::vector_map<APPortId, APPortId>& /*port_id_map*/) { |
| 135 | + // Unused |
| 136 | +} |
| 137 | + |
| 138 | +void APNetlist::rebuild_port_refs_impl(const vtr::vector_map<APBlockId, APBlockId>& /*block_id_map*/, const vtr::vector_map<APPinId, APPinId>& /*pin_id_map*/) { |
| 139 | + // Unused |
| 140 | +} |
| 141 | + |
| 142 | +void APNetlist::rebuild_pin_refs_impl(const vtr::vector_map<APPortId, APPortId>& /*port_id_map*/, const vtr::vector_map<APNetId, APNetId>& /*net_id_map*/) { |
| 143 | + // Unused |
| 144 | +} |
| 145 | + |
| 146 | +void APNetlist::rebuild_net_refs_impl(const vtr::vector_map<APPinId, APPinId>& /*pin_id_map*/) { |
| 147 | + // Unused |
| 148 | +} |
| 149 | + |
| 150 | +void APNetlist::shrink_to_fit_impl() { |
| 151 | + // Block data |
| 152 | + block_molecules_.shrink_to_fit(); |
| 153 | + block_mobilities_.shrink_to_fit(); |
| 154 | + block_locs_.shrink_to_fit(); |
| 155 | +} |
| 156 | + |
| 157 | +void APNetlist::remove_block_impl(const APBlockId /*blk_id*/) { |
| 158 | + // Unused |
| 159 | +} |
| 160 | + |
| 161 | +void APNetlist::remove_port_impl(const APPortId /*port_id*/) { |
| 162 | + // Unused |
| 163 | +} |
| 164 | + |
| 165 | +void APNetlist::remove_pin_impl(const APPinId /*pin_id*/) { |
| 166 | + // Unused |
| 167 | +} |
| 168 | + |
| 169 | +void APNetlist::remove_net_impl(const APNetId /*net_id*/) { |
| 170 | + // Unused |
| 171 | +} |
| 172 | + |
| 173 | +/* |
| 174 | + * Sanity Checks |
| 175 | + */ |
| 176 | +bool APNetlist::validate_block_sizes_impl(size_t num_blocks) const { |
| 177 | + if (block_molecules_.size() != num_blocks) |
| 178 | + return false; |
| 179 | + if (block_mobilities_.size() != num_blocks) |
| 180 | + return false; |
| 181 | + if (block_locs_.size() != num_blocks) |
| 182 | + return false; |
| 183 | + return true; |
| 184 | +} |
| 185 | + |
| 186 | +bool APNetlist::validate_port_sizes_impl(size_t /*num_ports*/) const { |
| 187 | + // No AP-specific port data to check |
| 188 | + return true; |
| 189 | +} |
| 190 | + |
| 191 | +bool APNetlist::validate_pin_sizes_impl(size_t /*num_pins*/) const { |
| 192 | + // No AP-specific pin data to check |
| 193 | + return true; |
| 194 | +} |
| 195 | + |
| 196 | +bool APNetlist::validate_net_sizes_impl(size_t /*num_nets*/) const { |
| 197 | + // No AP-specific net data to check |
| 198 | + return true; |
| 199 | +} |
| 200 | + |
0 commit comments