Skip to content
5 changes: 3 additions & 2 deletions src/grt/include/grt/GlobalRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class GlobalRouter
int track_count,
bool horizontal);
odb::Rect getGCellRect(int x, int y);
void initNetlist(std::vector<Net*>& nets);
void initNetlist(std::vector<Net*>& nets, bool incremental = false);
void makeFastrouteNet(Net* net);
bool pinPositionsChanged(Net* net);
bool newPinOnGrid(Net* net, std::multiset<RoutePt>& last_pos);
Expand All @@ -375,7 +375,7 @@ class GlobalRouter
void savePositionWithReducedResources(const odb::Rect& rect,
odb::dbTechLayer* tech_layer,
odb::dbNet* db_net);
void addResourcesForPinAccess();
void addResourcesForPinAccess(const std::vector<Net*>& nets);
bool isPinReachable(const Pin& pin, const odb::Point& pos_on_grid);
int computeNetWirelength(odb::dbNet* db_net);
void computeWirelength();
Expand Down Expand Up @@ -529,6 +529,7 @@ class GlobalRouter
bool is_congested_{false};
bool use_cugr_{false};
int skip_large_fanout_{std::numeric_limits<int>::max()};
bool has_macros_or_pads_{false};

// Region adjustment variables
std::vector<RegionAdjustment> region_adjustments_;
Expand Down
102 changes: 58 additions & 44 deletions src/grt/src/GlobalRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ float GlobalRouter::getNetSlack(Net* net)
return slack;
}

void GlobalRouter::initNetlist(std::vector<Net*>& nets)
void GlobalRouter::initNetlist(std::vector<Net*>& nets, bool incremental)
{
pad_pins_connections_.clear();

Expand Down Expand Up @@ -1343,9 +1343,12 @@ void GlobalRouter::initNetlist(std::vector<Net*>& nets)
logger_->info(GRT, 2, "Maximum degree: {}", max_degree);
}

// add resources for pin access in macro/pad pins after defining their on grid
// position
addResourcesForPinAccess();
// Add resources for pin access in macro/pad pins after defining their on grid
// position. It must be done only in the initialization of the tool, not
// during incremental.
if (has_macros_or_pads_ && !incremental) {
addResourcesForPinAccess(nets);
}
fastroute_->initAuxVar();
}

Expand Down Expand Up @@ -1925,49 +1928,51 @@ void GlobalRouter::applyObstructionAdjustment(const odb::Rect& obstruction,
// This function adds the resources necessary to route these pins. Only pins in
// the east and north edges are affected because FastRoute routes from left to
// right, and bottom to top.
void GlobalRouter::addResourcesForPinAccess()
void GlobalRouter::addResourcesForPinAccess(const std::vector<Net*>& nets)
{
odb::dbTech* tech = db_->getTech();
for (const auto& [db_net, net] : db_net_map_) {
for (const Pin& pin : net->getPins()) {
if (pin.isConnectedToPadOrMacro() && (pin.getEdge() != PinEdge::none)) {
const odb::Point& pos = pin.getOnGridPosition();
int pin_x = ((pos.x() - grid_->getXMin()) / grid_->getTileSize());
int pin_y = ((pos.y() - grid_->getYMin()) / grid_->getTileSize());
const int layer = pin.getConnectionLayer();
odb::dbTechLayer* tech_layer = tech->findRoutingLayer(layer);
if (tech_layer->getDirection() == odb::dbTechLayerDir::VERTICAL) {
const bool north_pin = pin.getEdge() == PinEdge::north;
const int pin_y1 = north_pin ? pin_y : pin_y - 1;
const int pin_y2 = north_pin ? pin_y + 1 : pin_y;

// Ensure we do not go out of bounds when the pin is at the edge of
// the grid. If the pin is on the south edge and at y=0, there is no
// room for adding resources.
if (pin_y1 < 0) {
continue;
}
for (const auto& net : nets) {
if (net->isConnectedToPadOrMacro()) {
for (const Pin& pin : net->getPins()) {
if (pin.isConnectedToPadOrMacro() && (pin.getEdge() != PinEdge::none)) {
const odb::Point& pos = pin.getOnGridPosition();
int pin_x = ((pos.x() - grid_->getXMin()) / grid_->getTileSize());
int pin_y = ((pos.y() - grid_->getYMin()) / grid_->getTileSize());
const int layer = pin.getConnectionLayer();
odb::dbTechLayer* tech_layer = tech->findRoutingLayer(layer);
if (tech_layer->getDirection() == odb::dbTechLayerDir::VERTICAL) {
const bool north_pin = pin.getEdge() == PinEdge::north;
const int pin_y1 = north_pin ? pin_y : pin_y - 1;
const int pin_y2 = north_pin ? pin_y + 1 : pin_y;

// Ensure we do not go out of bounds when the pin is at the edge of
// the grid. If the pin is on the south edge and at y=0, there is no
// room for adding resources.
if (pin_y1 < 0) {
continue;
}

const int edge_cap = fastroute_->getEdgeCapacity(
pin_x, pin_y1, pin_x, pin_y2, layer);
fastroute_->addAdjustment(
pin_x, pin_y1, pin_x, pin_y2, layer, edge_cap + 1, false);
} else {
const bool east_pin = pin.getEdge() == PinEdge::east;
const int pin_x1 = east_pin ? pin_x : pin_x - 1;
const int pin_x2 = east_pin ? pin_x + 1 : pin_x;

// Ensure we do not go out of bounds when the pin is at the edge of
// the grid. If the pin is on the west edge and at x=0, there is no
// room for adding resources.
if (pin_x1 < 0) {
continue;
}
const int edge_cap = fastroute_->getEdgeCapacity(
pin_x, pin_y1, pin_x, pin_y2, layer);
fastroute_->addAdjustment(
pin_x, pin_y1, pin_x, pin_y2, layer, edge_cap + 1, false);
} else {
const bool east_pin = pin.getEdge() == PinEdge::east;
const int pin_x1 = east_pin ? pin_x : pin_x - 1;
const int pin_x2 = east_pin ? pin_x + 1 : pin_x;

// Ensure we do not go out of bounds when the pin is at the edge of
// the grid. If the pin is on the west edge and at x=0, there is no
// room for adding resources.
if (pin_x1 < 0) {
continue;
}

const int edge_cap = fastroute_->getEdgeCapacity(
pin_x1, pin_y, pin_x2, pin_y, layer);
fastroute_->addAdjustment(
pin_x1, pin_y, pin_x2, pin_y, layer, edge_cap + 1, false);
const int edge_cap = fastroute_->getEdgeCapacity(
pin_x1, pin_y, pin_x2, pin_y, layer);
fastroute_->addAdjustment(
pin_x1, pin_y, pin_x2, pin_y, layer, edge_cap + 1, false);
}
}
}
}
Expand Down Expand Up @@ -4365,6 +4370,10 @@ void GlobalRouter::makeItermPins(Net* net,
const bool connected_to_pad = type.isPad();
const bool connected_to_macro = master->isBlock();

if (connected_to_pad || connected_to_macro) {
net->setIsConnectedToPadOrMacro(true);
}

odb::dbInst* inst = iterm->getInst();
if (!inst->isPlaced()) {
logger_->error(GRT, 10, "Instance {} is not placed.", inst->getName());
Expand Down Expand Up @@ -4686,6 +4695,11 @@ int GlobalRouter::findInstancesObstructions(
if (master->isBlock()) {
macros_cnt++;
is_macro = true;
has_macros_or_pads_ = true;
}

if (master->getType().isPad()) {
has_macros_or_pads_ = true;
}

if (is_macro) {
Expand Down Expand Up @@ -5827,7 +5841,7 @@ void GlobalRouter::getCongestionNets(std::set<odb::dbNet*>& congestion_nets)

void GlobalRouter::initFastRouteIncr(std::vector<Net*>& nets)
{
initNetlist(nets);
initNetlist(nets, true);
fastroute_->initAuxVar();
fastroute_->setIncrementalGrt(true);
}
Expand Down
3 changes: 2 additions & 1 deletion src/grt/src/Net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Net::Net(odb::dbNet* net, bool has_wires)
merged_net_(nullptr),
is_merged_net_(false),
is_dirty_net_(false),
is_clk_(false)
is_clk_(false),
is_connected_to_pad_or_macro_(false)
{
}

Expand Down
6 changes: 6 additions & 0 deletions src/grt/src/Net.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class Net
bool isDirtyNet() const { return is_dirty_net_; }
void setIsClockNet(bool is_clk) { is_clk_ = is_clk; }
bool isClockNet() const { return is_clk_; }
void setIsConnectedToPadOrMacro(bool is_connected)
{
is_connected_to_pad_or_macro_ = is_connected;
}
bool isConnectedToPadOrMacro() const { return is_connected_to_pad_or_macro_; }

private:
int getNumBTermsAboveMaxLayer(odb::dbTechLayer* max_routing_layer);
Expand All @@ -74,6 +79,7 @@ class Net
bool is_merged_net_;
bool is_dirty_net_;
bool is_clk_;
bool is_connected_to_pad_or_macro_;
};

} // namespace grt