Skip to content

Commit c60f967

Browse files
Merge pull request #3013 from verilog-to-routing/pb_type_helper_func
Add functions to p_tb_type for checking if it's root or primitive
2 parents 43f2a94 + c4ad99e commit c60f967

17 files changed

+105
-93
lines changed

libs/libarchfpga/src/arch_util.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ bool pb_type_contains_blif_model(const t_pb_type* pb_type, const std::string& bl
10771077

10781078
if (pb_type->blif_model != nullptr) {
10791079
//Leaf pb_type
1080-
VTR_ASSERT(pb_type->num_modes == 0);
1080+
VTR_ASSERT(pb_type->is_primitive());
10811081
if (blif_model_name == pb_type->blif_model
10821082
|| ".subckt " + blif_model_name == pb_type->blif_model) {
10831083
return true;

libs/libarchfpga/src/physical_types.h

+56-37
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,25 @@ struct t_pb_type {
10681068
t_pb_type_power* pb_type_power = nullptr;
10691069

10701070
t_metadata_dict meta;
1071+
1072+
/**
1073+
* @brief Check if t_pb_type is the root of the pb graph. Root pb_types correspond to a single top level block type and map to a particular type
1074+
* of location in the FPGA device grid (e.g. Logic, DSP, RAM etc.)
1075+
*
1076+
* @return if t_pb_type is root ot not
1077+
*/
1078+
inline bool is_root() const {
1079+
return parent_mode == nullptr;
1080+
}
1081+
1082+
/**
1083+
* @brief Check if t_pb_type is a primitive block or equivalently a leaf of the pb graph.
1084+
*
1085+
* @return if t_pb_type is primitive/leaf ot not
1086+
*/
1087+
inline bool is_primitive() const {
1088+
return num_modes == 0;
1089+
}
10711090
};
10721091

10731092
/** Describes an operational mode of a clustered logic block
@@ -1353,7 +1372,7 @@ class t_pb_graph_node {
13531372
t_interconnect_pins** interconnect_pins; /* [0..num_modes-1][0..num_interconnect_in_mode] */
13541373

13551374
// Returns true if this pb_graph_node represents a primitive type (primitives have 0 modes)
1356-
bool is_primitive() const { return this->pb_type->num_modes == 0; }
1375+
bool is_primitive() const { return this->pb_type->is_primitive(); }
13571376

13581377
// Returns true if this pb_graph_node represents a root graph node (ex. clb)
13591378
bool is_root() const { return this->parent_pb_graph_node == nullptr; }
@@ -1567,7 +1586,7 @@ enum e_directionality {
15671586
};
15681587

15691588
/* X_AXIS: Data that describes an x-directed wire segment (CHANX) *
1570-
* Y_AXIS: Data that describes an y-directed wire segment (CHANY) *
1589+
* Y_AXIS: Data that describes an y-directed wire segment (CHANY) *
15711590
* BOTH_AXIS: Data that can be applied to both x-directed and y-directed wire segment */
15721591
enum e_parallel_axis {
15731592
X_AXIS,
@@ -1624,65 +1643,65 @@ enum e_Fc_type {
16241643
*/
16251644
struct t_segment_inf {
16261645
/**
1627-
* @brief The name of the segment type
1646+
* @brief The name of the segment type
16281647
*/
16291648
std::string name;
16301649

16311650
/**
1632-
* @brief ratio of tracks which are of this segment type.
1651+
* @brief ratio of tracks which are of this segment type.
16331652
*/
16341653
int frequency;
16351654

16361655
/**
1637-
* @brief Length (in clbs) of the segment.
1656+
* @brief Length (in clbs) of the segment.
16381657
*/
16391658
int length;
16401659

16411660
/**
1642-
* @brief Index of the switch type that connects other wires to this segment.
1643-
* Note that this index is in relation to the switches from the architecture file,
1644-
* not the expanded list of switches that is built at the end of build_rr_graph.
1661+
* @brief Index of the switch type that connects other wires to this segment.
1662+
* Note that this index is in relation to the switches from the architecture file,
1663+
* not the expanded list of switches that is built at the end of build_rr_graph.
16451664
*/
16461665
short arch_wire_switch;
16471666

16481667
/**
1649-
* @brief Index of the switch type that connects output pins to this segment.
1650-
* Note that this index is in relation to the switches from the architecture file,
1651-
* not the expanded list of switches that is built at the end of build_rr_graph.
1668+
* @brief Index of the switch type that connects output pins to this segment.
1669+
* Note that this index is in relation to the switches from the architecture file,
1670+
* not the expanded list of switches that is built at the end of build_rr_graph.
16521671
*/
16531672
short arch_opin_switch;
16541673

16551674
/**
1656-
* @brief Same as arch_wire_switch but used only for decremental tracks if it is
1657-
* specified in the architecture file. If -1, this value was not set in the
1658-
* architecture file and arch_wire_switch should be used for "DEC_DIR" wire segments.
1675+
* @brief Same as arch_wire_switch but used only for decremental tracks if it is
1676+
* specified in the architecture file. If -1, this value was not set in the
1677+
* architecture file and arch_wire_switch should be used for "DEC_DIR" wire segments.
16591678
*/
16601679
short arch_wire_switch_dec = -1;
16611680

16621681
/**
1663-
* @brief Same as arch_opin_switch but used only for decremental tracks if
1664-
* it is specified in the architecture file. If -1, this value was not set in
1665-
* the architecture file and arch_opin_switch should be used for "DEC_DIR" wire segments.
1682+
* @brief Same as arch_opin_switch but used only for decremental tracks if
1683+
* it is specified in the architecture file. If -1, this value was not set in
1684+
* the architecture file and arch_opin_switch should be used for "DEC_DIR" wire segments.
16661685
*/
16671686
short arch_opin_switch_dec = -1;
16681687

16691688
/**
1670-
* @brief Index of the switch type that connects output pins (OPINs) to this
1671-
* segment from another die (layer). Note that this index is in relation to
1672-
* the switches from the architecture file, not the expanded list of switches
1673-
* that is built at the end of build_rr_graph.
1689+
* @brief Index of the switch type that connects output pins (OPINs) to this
1690+
* segment from another die (layer). Note that this index is in relation to
1691+
* the switches from the architecture file, not the expanded list of switches
1692+
* that is built at the end of build_rr_graph.
16741693
*/
16751694
short arch_inter_die_switch = -1;
16761695

16771696
/**
1678-
* @brief The fraction of logic blocks along its length to which this segment can connect.
1679-
* (i.e. internal population).
1697+
* @brief The fraction of logic blocks along its length to which this segment can connect.
1698+
* (i.e. internal population).
16801699
*/
16811700
float frac_cb;
16821701

16831702
/**
1684-
* @brief The fraction of the length + 1 switch blocks along the segment to which the segment can connect.
1685-
* Segments that aren't long lines must connect to at least two switch boxes.
1703+
* @brief The fraction of the length + 1 switch blocks along the segment to which the segment can connect.
1704+
* Segments that aren't long lines must connect to at least two switch boxes.
16861705
*/
16871706
float frac_sb;
16881707

@@ -1699,27 +1718,27 @@ struct t_segment_inf {
16991718
enum e_directionality directionality;
17001719

17011720
/**
1702-
* @brief Defines what axis the segment is parallel to. See e_parallel_axis
1703-
* comments for more details on the values.
1721+
* @brief Defines what axis the segment is parallel to. See e_parallel_axis
1722+
* comments for more details on the values.
17041723
*/
17051724
enum e_parallel_axis parallel_axis;
17061725

17071726
/**
1708-
* @brief A vector of booleans indicating whether the segment can connect to a logic block.
1727+
* @brief A vector of booleans indicating whether the segment can connect to a logic block.
17091728
*/
17101729
std::vector<bool> cb;
17111730

17121731
/**
1713-
* @brief A vector of booleans indicating whether the segment can connect to a switch block.
1732+
* @brief A vector of booleans indicating whether the segment can connect to a switch block.
17141733
*/
17151734
std::vector<bool> sb;
17161735

17171736
/**
17181737
* @brief The index of the segment as stored in the appropriate Segs list.
1719-
* Upon loading the architecture, we use this field to keep track of the
1720-
* segment's index in the unified segment_inf vector. This is useful when
1721-
* building the rr_graph for different Y & X channels in terms of track
1722-
* distribution and segment type.
1738+
* Upon loading the architecture, we use this field to keep track of the
1739+
* segment's index in the unified segment_inf vector. This is useful when
1740+
* building the rr_graph for different Y & X channels in terms of track
1741+
* distribution and segment type.
17231742
*/
17241743
int seg_index;
17251744

@@ -1728,7 +1747,7 @@ struct t_segment_inf {
17281747
* Possible values are:
17291748
* - GENERAL: The segment is part of the general routing resources.
17301749
* - GCLK: The segment is part of the global routing network.
1731-
* For backward compatibility, this attribute is optional. If not specified,
1750+
* For backward compatibility, this attribute is optional. If not specified,
17321751
* the resource type for the segment is considered to be GENERAL.
17331752
*/
17341753
enum SegResType res_type = SegResType::GENERAL;
@@ -1778,12 +1797,12 @@ constexpr std::array<const char*, size_t(SwitchType::NUM_SWITCH_TYPES)> SWITCH_T
17781797

17791798
/* Constant/Reserved names for switches in architecture XML
17801799
* Delayless switch:
1781-
* The zero-delay switch created by VPR internally
1800+
* The zero-delay switch created by VPR internally
17821801
* This is a special switch just to ease CAD algorithms
17831802
* It is mainly used in
1784-
* - the edges between SOURCE and SINK nodes in routing resource graphs
1803+
* - the edges between SOURCE and SINK nodes in routing resource graphs
17851804
* - the edges in CLB-to-CLB connections (defined by <directlist> in arch XML)
1786-
*
1805+
*
17871806
*/
17881807
constexpr const char* VPR_DELAYLESS_SWITCH_NAME = "__vpr_delayless_switch__";
17891808

libs/libarchfpga/src/read_xml_arch_file.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ static void ProcessPb_Type(pugi::xml_node Parent,
14151415
pb_type->pb_type_power->leakage_default_mode = 0;
14161416
int mode_idx = 0;
14171417

1418-
if (pb_type->num_modes == 0) {
1418+
if (pb_type->is_primitive()) {
14191419
/* The pb_type operates in an implied one mode */
14201420
pb_type->num_modes = 1;
14211421
pb_type->modes = new t_mode[pb_type->num_modes];

vpr/src/analytical_place/flat_placement_mass_calculator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static PrimitiveVector calc_pb_type_capacity(const t_pb_type* pb_type) {
6868
// capacities as if the pb could choose either one.
6969
PrimitiveVector capacity;
7070
// If this is a leaf / primitive, create the base PrimitiveVector capacity.
71-
if (pb_type->num_modes == 0) {
71+
if (pb_type->is_primitive()) {
7272
LogicalModelId model_id = pb_type->model_id;
7373
VTR_ASSERT(model_id.is_valid());
7474
capacity.add_val_to_dim(get_model_mass(model_id), (size_t)model_id);

vpr/src/base/netlist_walker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void NetlistWalker::walk_blocks(const t_pb_routes& top_pb_route, const t_pb* pb)
4242

4343
//Recurse
4444
const t_pb_type* pb_type = pb->pb_graph_node->pb_type;
45-
if (pb_type->num_modes > 0) {
45+
if (!pb_type->is_primitive()) {
4646
const t_mode* mode = &pb_type->modes[pb->mode];
4747
for (int i = 0; i < mode->num_pb_type_children; i++) {
4848
for (int j = 0; j < mode->pb_type_children[i].num_pb; j++) {

vpr/src/base/read_netlist.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static void processPb(pugi::xml_node Parent, const ClusterBlockId index, t_pb* p
463463
VTR_ASSERT(clb_nlist->block_ports(index).size() == (unsigned)pb_type->num_ports);
464464
}
465465

466-
if (pb_type->num_modes == 0) {
466+
if (pb_type->is_primitive()) {
467467
/* A primitive type */
468468
AtomBlockId blk_id = atom_ctx.netlist().find_block(pb->name);
469469
if (!blk_id) {

vpr/src/draw/intra_logic_block.cpp

+14-19
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ static int draw_internal_find_max_lvl(const t_pb_type& pb_type) {
202202
t_mode mode;
203203
int max_levels = 0;
204204

205-
/* If no modes, we have reached the end of pb_graph */
206-
if (pb_type.num_modes == 0)
205+
/* If pb_type is a primitive, we have reached the end of pb_graph */
206+
if (pb_type.is_primitive())
207207
return (pb_type.depth);
208208

209209
for (i = 0; i < pb_type.num_modes; ++i) {
@@ -221,30 +221,25 @@ static int draw_internal_find_max_lvl(const t_pb_type& pb_type) {
221221
* calls helper function to compute bounding box values.
222222
*/
223223
static void draw_internal_load_coords(int type_descrip_index, t_pb_graph_node* pb_graph_node, float parent_width, float parent_height) {
224-
int i, j, k;
225-
t_pb_type* pb_type;
226-
int num_modes, num_children, num_pb;
227-
t_mode mode;
228224
float blk_width = 0.;
229225
float blk_height = 0.;
230226

231-
/* Get information about the pb_type */
232-
pb_type = pb_graph_node->pb_type;
233-
num_modes = pb_type->num_modes;
234-
235-
/* If no modes, we have reached the end of pb_graph */
236-
if (num_modes == 0)
227+
t_pb_type* pb_type = pb_graph_node->pb_type;
228+
int num_modes = pb_type->num_modes;
229+
/* If pb_type is primitive, we have reached the end of pb_graph */
230+
if (pb_type->is_primitive()) {
237231
return;
232+
}
238233

239-
for (i = 0; i < num_modes; ++i) {
240-
mode = pb_type->modes[i];
241-
num_children = mode.num_pb_type_children;
234+
for (int i = 0; i < num_modes; ++i) {
235+
t_mode mode = pb_type->modes[i];
236+
int num_children = mode.num_pb_type_children;
242237

243-
for (j = 0; j < num_children; ++j) {
238+
for (int j = 0; j < num_children; ++j) {
244239
/* Find the number of instances for each child pb_type. */
245-
num_pb = mode.pb_type_children[j].num_pb;
240+
int num_pb = mode.pb_type_children[j].num_pb;
246241

247-
for (k = 0; k < num_pb; ++k) {
242+
for (int k = 0; k < num_pb; ++k) {
248243
/* Compute bound box for block. Don't call if pb_type is root-level pb. */
249244
draw_internal_calc_coords(type_descrip_index,
250245
&pb_graph_node->child_pb_graph_nodes[i][j][k],
@@ -721,7 +716,7 @@ t_pb* highlight_sub_block_helper(const ClusterBlockId clb_index, t_pb* pb, const
721716
// and if pb is dud
722717
if (pb_type->depth + 1 > max_depth
723718
|| pb->child_pbs == nullptr
724-
|| pb_type->num_modes == 0) {
719+
|| pb_type->is_primitive()) {
725720
return nullptr;
726721
}
727722

vpr/src/pack/cluster_legalizer.cpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void check_cluster_atom_blocks(t_pb* pb, std::unordered_set<AtomBlockId>&
6565
const AtomContext& atom_ctx = g_vpr_ctx.atom();
6666

6767
const t_pb_type* pb_type = pb->pb_graph_node->pb_type;
68-
if (pb_type->num_modes == 0) {
68+
if (pb_type->is_primitive()) {
6969
/* primitive */
7070
AtomBlockId blk_id = atom_pb_lookup.pb_atom(pb);
7171
if (blk_id) {
@@ -396,7 +396,7 @@ static bool primitive_memory_sibling_feasible(const AtomBlockId blk_id, const t_
396396
static bool primitive_feasible(const AtomBlockId blk_id, t_pb* cur_pb, const AtomPBBimap& atom_to_pb) {
397397
const t_pb_type* cur_pb_type = cur_pb->pb_graph_node->pb_type;
398398

399-
VTR_ASSERT(cur_pb_type->num_modes == 0); /* primitive */
399+
VTR_ASSERT(cur_pb_type->is_primitive()); /* primitive */
400400

401401
AtomBlockId cur_pb_blk_id = atom_to_pb.pb_atom(cur_pb);
402402
if (cur_pb_blk_id && cur_pb_blk_id != blk_id) {
@@ -511,9 +511,7 @@ try_place_atom_block_rec(const t_pb_graph_node* pb_graph_node,
511511
return e_block_pack_status::BLK_FAILED_FEASIBLE;
512512
}
513513

514-
bool is_primitive = (pb_type->num_modes == 0);
515-
516-
if (is_primitive) {
514+
if (pb_type->is_primitive()) {
517515
VTR_ASSERT(!atom_to_pb.pb_atom(pb)
518516
&& atom_to_pb.atom_pb(blk_id) == nullptr
519517
&& atom_cluster[blk_id] == LegalizationClusterId::INVALID());
@@ -576,7 +574,7 @@ static void reset_lookahead_pins_used(t_pb* cur_pb) {
576574
return; /* No pins used, no need to continue */
577575
}
578576

579-
if (pb_type->num_modes > 0 && cur_pb->name != nullptr) {
577+
if (!pb_type->is_primitive() && cur_pb->name != nullptr) {
580578
for (int i = 0; i < cur_pb->pb_graph_node->num_input_pin_class; i++) {
581579
cur_pb->pb_stats->lookahead_input_pins_used[i].clear();
582580
}
@@ -821,7 +819,7 @@ static void try_update_lookahead_pins_used(t_pb* cur_pb,
821819
const AtomPBBimap& atom_to_pb) {
822820
// run recursively till a leaf (primitive) pb block is reached
823821
const t_pb_type* pb_type = cur_pb->pb_graph_node->pb_type;
824-
if (pb_type->num_modes > 0 && cur_pb->name != nullptr) {
822+
if (!pb_type->is_primitive() && cur_pb->name != nullptr) {
825823
if (cur_pb->child_pbs != nullptr) {
826824
for (int i = 0; i < pb_type->modes[cur_pb->mode].num_pb_type_children; i++) {
827825
if (cur_pb->child_pbs[i] != nullptr) {
@@ -848,7 +846,7 @@ static void try_update_lookahead_pins_used(t_pb* cur_pb,
848846
static bool check_lookahead_pins_used(t_pb* cur_pb, t_ext_pin_util max_external_pin_util) {
849847
const t_pb_type* pb_type = cur_pb->pb_graph_node->pb_type;
850848

851-
if (pb_type->num_modes > 0 && cur_pb->name) {
849+
if (!pb_type->is_primitive() && cur_pb->name) {
852850
for (int i = 0; i < cur_pb->pb_graph_node->num_input_pin_class; i++) {
853851
size_t class_size = cur_pb->pb_graph_node->input_pin_class_size[i];
854852

@@ -1015,7 +1013,7 @@ static void revert_place_atom_block(const AtomBlockId blk_id,
10151013
static void commit_lookahead_pins_used(t_pb* cur_pb) {
10161014
const t_pb_type* pb_type = cur_pb->pb_graph_node->pb_type;
10171015

1018-
if (pb_type->num_modes > 0 && cur_pb->name) {
1016+
if (!pb_type->is_primitive() && cur_pb->name) {
10191017
for (int i = 0; i < cur_pb->pb_graph_node->num_input_pin_class; i++) {
10201018
VTR_ASSERT(cur_pb->pb_stats->lookahead_input_pins_used[i].size() <= (unsigned int)cur_pb->pb_graph_node->input_pin_class_size[i]);
10211019
for (size_t j = 0; j < cur_pb->pb_stats->lookahead_input_pins_used[i].size(); j++) {
@@ -1076,7 +1074,7 @@ static bool cleanup_pb(t_pb* pb) {
10761074
t_pb_type* pb_type = pb_child->pb_graph_node->pb_type;
10771075

10781076
/* Primitive, check occupancy */
1079-
if (pb_type->num_modes == 0) {
1077+
if (pb_type->is_primitive()) {
10801078
if (pb_child->name != nullptr) {
10811079
can_free = false;
10821080
}

vpr/src/pack/cluster_util.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ size_t update_pb_type_count(const t_pb* pb, std::map<t_pb_type*, int>& pb_type_c
215215

216216
pb_type_count[pb_type]++;
217217

218-
if (pb_type->num_modes > 0) {
218+
if (!pb_type->is_primitive()) {
219219
for (int i = 0; i < mode->num_pb_type_children; i++) {
220220
for (int j = 0; j < mode->pb_type_children[i].num_pb; j++) {
221221
if (pb->child_pbs[i] && pb->child_pbs[i][j].name) {
@@ -365,7 +365,7 @@ bool pb_used_for_blif_model(const t_pb* pb, const std::string& blif_model_name)
365365
}
366366
}
367367

368-
if (pb_type->num_modes > 0) {
368+
if (!pb_type->is_primitive()) {
369369
for (int i = 0; i < mode->num_pb_type_children; i++) {
370370
for (int j = 0; j < mode->pb_type_children[i].num_pb; j++) {
371371
if (pb->child_pbs[i] && pb->child_pbs[i][j].name) {

0 commit comments

Comments
 (0)