Drt layer preference sorting#10585
Conversation
…nstance Signed-off-by: bnmfw <bernardoborgessandoval@gmail.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a new helper method instPrefersHorizontal to determine whether an instance prefers horizontal routing based on its pin access points, and integrates this preference into prepPatternInst to prioritize routing directions accordingly. The review feedback suggests adding defensive checks in instPrefersHorizontal to handle negative pin_access_idx values and null pin_access pointers, preventing potential out-of-bounds memory access or null pointer dereferences.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| bool FlexPA::instPrefersHorizontal(frInst* unique_inst) | ||
| { | ||
| const int pin_access_idx = unique_inst->getPinAccessIdx(); | ||
| // Positive if most access points are on Horizontal layers, Negative if on | ||
| // Vertical Layers | ||
| int layer_direction_bias = 0; | ||
| const auto tech = getDesign()->getTech(); | ||
| for (auto& inst_term : unique_inst->getInstTerms()) { | ||
| if (isSkipInstTerm(inst_term.get())) { | ||
| continue; | ||
| } | ||
| for (auto& pin : inst_term->getTerm()->getPins()) { | ||
| for (auto& ap : pin->getPinAccess(pin_access_idx)->getAccessPoints()) { | ||
| if (tech->getLayer(ap->getLayerNum())->isHorizontal()) { | ||
| layer_direction_bias++; | ||
| } else { | ||
| layer_direction_bias--; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return layer_direction_bias >= 0; | ||
| } |
There was a problem hiding this comment.
To prevent potential crashes or undefined behavior, add defensive checks to ensure pin_access_idx is valid (non-negative) and that the retrieved pin_access pointer is not null before dereferencing it. Since pin_access_idx defaults to -1 when uninitialized, accessing it directly can lead to out-of-bounds memory access or null pointer dereferences.
bool FlexPA::instPrefersHorizontal(frInst* unique_inst)
{
const int pin_access_idx = unique_inst->getPinAccessIdx();
if (pin_access_idx < 0) {
return true;
}
// Positive if most access points are on Horizontal layers, Negative if on
// Vertical Layers
int layer_direction_bias = 0;
const auto tech = getDesign()->getTech();
for (auto& inst_term : unique_inst->getInstTerms()) {
if (isSkipInstTerm(inst_term.get())) {
continue;
}
for (auto& pin : inst_term->getTerm()->getPins()) {
auto pin_access = pin->getPinAccess(pin_access_idx);
if (!pin_access) {
continue;
}
for (auto& ap : pin_access->getAccessPoints()) {
if (tech->getLayer(ap->getLayerNum())->isHorizontal()) {
layer_direction_bias++;
} else {
layer_direction_bias--;
}
}
}
}
return layer_direction_bias >= 0;
}Signed-off-by: bnmfw <bernardoborgessandoval@gmail.com>
Summary
Found this while working on issue #9948, but this is general to all designs. Pin Access sorts the pins horizontally by default when running Access Pattern generation. The sorting is important, because when checking for DRVs inside the cell, only pins next to each other on the sorting are checked. For the example instance in the image this would make the access points on the top pin not be checked against the middle pin, but instead against the bottom pin, which is incorrect.
There is no correct default. Some PDKs and some instances will have pins arranges vertically, some will have them arranged horizontally. Instead, this PR looks at the preferred direction of the layer of the majority of access points and sort the pins on the other direction. So if all pins are in a horizontal layer, like the image, they will be sorted vertically and vice versa. This is always correct for
RightWayOnlyOnGridandRectOnlyPDKs.Type of Change
Impact
This changes how pins are sorted during access patterns, which in turn changes which access patterns can be created and can change preferred access points downstream.
Verification
./etc/Build.sh).Related Issues
issue #9948