Skip to content

Drt layer preference sorting#10585

Draft
openroad-ci wants to merge 5 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:drt_layer_preference_sorting
Draft

Drt layer preference sorting#10585
openroad-ci wants to merge 5 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:drt_layer_preference_sorting

Conversation

@openroad-ci
Copy link
Copy Markdown
Collaborator

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.

image

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 RightWayOnlyOnGrid and RectOnly PDKs.

Type of Change

  • Bug fix
  • New feature

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

  • I have verified that the local build succeeds (./etc/Build.sh).
  • I have run the relevant tests and they pass.
  • My code follows the repository's formatting guidelines.
  • I have included tests to prevent regressions.
  • I have signed my commits (DCO).

Related Issues

issue #9948

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +85 to +107
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;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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;
}

@bnmfw bnmfw added the drt Detailed Routing label Jun 3, 2026
bnmfw added 2 commits June 3, 2026 04:37
Signed-off-by: bnmfw <bernardoborgessandoval@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

drt Detailed Routing size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants