diff --git a/src/drt/src/dr/FlexDR_init.cpp b/src/drt/src/dr/FlexDR_init.cpp index 81a8a94843e..fc7e57d4e24 100644 --- a/src/drt/src/dr/FlexDR_init.cpp +++ b/src/drt/src/dr/FlexDR_init.cpp @@ -2722,6 +2722,14 @@ void FlexDRWorker::initMazeCost_fixedObj(const frDesign* design) result.clear(); if (getTech()->getLayer(layerNum)->getType() == dbTechLayerType::ROUTING) { isRoutingLayer = true; + // The grid graph need not span the full layer stack: TOP_ROUTING_LAYER + // can trim routing layers above it out of the grid. Skip fixed-shape + // costing on layers absent from the grid so getMazeZIdx / getLayerNum + // stay in range. No-op when the grid spans every routing layer. + if (layerNum < gridGraph_.getMinLayerNum() + || layerNum > gridGraph_.getMaxLayerNum()) { + continue; + } zIdx = gridGraph_.getMazeZIdx(layerNum); } else if (getTech()->getLayer(layerNum)->getType() == dbTechLayerType::CUT) { @@ -2729,6 +2737,10 @@ void FlexDRWorker::initMazeCost_fixedObj(const frDesign* design) if (getTech()->getBottomLayerNum() <= layerNum - 1 && getTech()->getLayer(layerNum - 1)->getType() == dbTechLayerType::ROUTING) { + if (layerNum - 1 < gridGraph_.getMinLayerNum() + || layerNum - 1 > gridGraph_.getMaxLayerNum()) { + continue; + } zIdx = gridGraph_.getMazeZIdx(layerNum - 1); } else { continue; @@ -2894,6 +2906,12 @@ void FlexDRWorker::initMazeCost_terms( if (getTech()->getLayer(layerNum)->getType() == dbTechLayerType::ROUTING) { isRoutingLayer = true; + // Grid may not span the full stack (TOP_ROUTING_LAYER trim); + // skip layers absent from the grid. No-op when fully spanned. + if (layerNum < gridGraph_.getMinLayerNum() + || layerNum > gridGraph_.getMaxLayerNum()) { + continue; + } zIdx = gridGraph_.getMazeZIdx(layerNum); } else if (getTech()->getLayer(layerNum)->getType() == dbTechLayerType::CUT) { @@ -2901,6 +2919,10 @@ void FlexDRWorker::initMazeCost_terms( if (getTech()->getBottomLayerNum() <= layerNum - 1 && getTech()->getLayer(layerNum - 1)->getType() == dbTechLayerType::ROUTING) { + if (layerNum - 1 < gridGraph_.getMinLayerNum() + || layerNum - 1 > gridGraph_.getMaxLayerNum()) { + continue; + } zIdx = gridGraph_.getMazeZIdx(layerNum - 1); } else { continue; @@ -2971,6 +2993,12 @@ void FlexDRWorker::initMazeCost_terms( if (getTech()->getLayer(layerNum)->getType() == dbTechLayerType::ROUTING) { isRoutingLayer = true; + // Grid may not span the full stack (TOP_ROUTING_LAYER trim); + // skip layers absent from the grid. No-op when fully spanned. + if (layerNum < gridGraph_.getMinLayerNum() + || layerNum > gridGraph_.getMaxLayerNum()) { + continue; + } zIdx = gridGraph_.getMazeZIdx(layerNum); } else if (getTech()->getLayer(layerNum)->getType() == dbTechLayerType::CUT) { @@ -2978,6 +3006,10 @@ void FlexDRWorker::initMazeCost_terms( if (getTech()->getBottomLayerNum() <= layerNum - 1 && getTech()->getLayer(layerNum - 1)->getType() == dbTechLayerType::ROUTING) { + if (layerNum - 1 < gridGraph_.getMinLayerNum() + || layerNum - 1 > gridGraph_.getMaxLayerNum()) { + continue; + } zIdx = gridGraph_.getMazeZIdx(layerNum - 1); } else { continue; diff --git a/src/drt/src/dr/FlexGridGraph.cpp b/src/drt/src/dr/FlexGridGraph.cpp index 70dcfe0cf4a..8b778c03f28 100644 --- a/src/drt/src/dr/FlexGridGraph.cpp +++ b/src/drt/src/dr/FlexGridGraph.cpp @@ -471,6 +471,17 @@ void FlexGridGraph::initTracks( continue; } frLayerNum currLayerNum = layer->getLayerNum(); + // Layers above TOP_ROUTING_LAYER carry no routing edges or access vias + // (initEdges and the special-access via loop already cap work at + // TOP_ROUTING_LAYER), yet they were still added to the grid here, sizing + // nodes_, the per-node arrays, and the maze search bounds across the full + // layer stack. Skip them so the grid graph spans only the routing range, + // cutting detailed-route memory and runtime when the design's top routing + // layer is below the technology top. Default TOP_ROUTING_LAYER is INT_MAX, + // so this is a no-op unless the top routing layer is explicitly lowered. + if (currLayerNum > router_cfg_->TOP_ROUTING_LAYER) { + continue; + } dbTechLayerDir currPrefRouteDir = layer->getDir(); for (auto& tp : design->getTopBlock()->getTrackPatterns(currLayerNum)) { // allow wrongway if global variable and design rule allow