Skip to content

Developed new insert buffer APIs - #9157

Merged
maliberty merged 179 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:secure-insert-buffer
Dec 31, 2025
Merged

maliberty merged 179 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:secure-insert-buffer

Conversation

@openroad-ci

Copy link
Copy Markdown
Member

Summary

Added new standard APIs for buffering that handles hierarchy processing.

Goal

  1. Provide standardized APIs for buffering
  2. Hide the complicated hierarchy processing
  3. Close the QoR gap b/w flat and hier flows
  4. Export Tcl commands for ECO

Note that this PR affects QoR of the flat flow.

New feature

New APIs to insert buffers

  1. dbNet::insertBufferAfterDriver(dbObject* drvr_term, ...)
  • Insert a new buffer after the given driver pin (driver pin buffering).
  • The new buffer will be placed in the driver instance hierarchy.
  1. dbNet::insertBufferBeforeLoad(dbObject* load_term, ...)
  • Insert a new buffer before the given load pin (load pin buffering).
  • The new buffer will be placed in the load instance hierarchy.
  1. dbNet::insertBufferBeforeLoads(std::set<dbObject*> load_pins, ...)
  • Insert a new buffer that drives the given load pins (partial-load buffering).
  • The new buffer will be placed in the LCA (Lowest Common Ancestor) of the given loads.

New Tcl command

insert_buffer -buffer_cell lib_cell
              [-net net]
              [-load_pins list_of_pins]
              [-location {x y}]
              [-buffer_name name]
              [-net_name name]
              [-load_pins_on_diff_nets]
Argument Description
-buffer_cell Specified the library cell to use for the buffer. (Required)
-location Specifies the {x y} coordinates (in microns) where the buffer should be placed. If not specified, the buffer is placed at the driver or load pin location.
-buffer_name Specifies the base name for the new buffer instance. If not specified, "buf" is used. Note that a unique suffix number will always be added to the base name to avoid a name collision.
-net_name Specifies the base name for the new net created by the buffer insertion. If not specified, "net" is used. Note that a unique suffix number will always be added to the base name to avoid a name collision.
-net Specifies the net to be buffered. When used without -load_pins, it performs driver-side buffering.
-load_pins Specifies a single load pin or a list of load pins to buffer together.
-load_pins_on_diff_nets A flag indicating that the specified -load_pins are on the different nets. If specified, multiple load pins on different flat nets can be buffered together and the target net among the multiple flat nets can be selected by -net. This option should be used with caution not to change the logical function of the design.

Detailed explanations in src/rsz/doc/insert_buffer.md.

Enhancement

Enhancement1. Added dbSta::checkSanity().

It checks consistency b/w ODB and STA data structures. It can be executed by the Tcl command sta::check_axioms.

Bug fixes

Fix1. Added overriding APIs dbNetwork::drivers().

ODB has dbNet and dbModNet while OpenSTA has a Net.
Network::drivers() API is implemented to handle Net in open STA.
But it is not suitable for dbNet and dbModNet in ODB.
So I overridden the drivers() APIs in dbNetwork to support ODB.

Fix2. dbNetwork::net(const Pin*) returns Net* instead of nullptr

Previously, it returns the dbNet connected to the input dbBTerm pin.
Modified it to return dbModNet first if the input dbBTerm has a hier net connection. This is to make it consistent with other pin types (dbITerm).

Net* dbNetwork::net(const Pin* pin) const
{
...
  if (bterm) {
    // NEW BEHAVIOR
    if (dbModNet* mnet = bterm->getModNet()) {
      return dbToSta(mnet);
    }
    if (dbNet* dnet = bterm->getNet()) {
      return dbToSta(dnet);
    }
   
    // return nullptr;          // OLD BEHAVIOR
  }
...
}

Fix3. Added hierarchical pin handling in dbNetwork::connectPinAfter(Pin*) and dbNetwork::disconnectPinBefore(Pin*)

This is needed to update the net_drvr_pin_map_ correctly.
Otherwise, it can remove an existing timing edge or create a wrong timing edge by sta_->connectPinAfter(pin) when ECO is performed, which is a critical issue breaking STA.

Fix4. Made feedthrough connection in a module by enhancing Verilog2db::constructModNet(Net*, dbModule*)

In Verilog2db::constructModNet(Net*, dbModule*), there is pin iteration, but there is no term iteration.
So feedthrough connection b/w input dbModBTerm and output dbModBTerm connection by dbModNet was omiited.

Added the term iteration as below.

dbModNet* Verilog2db::constructModNet(Net* inst_pin_net, dbModule* module)
{
...
  std::unique_ptr<sta::NetTermIterator> nti{network_->termIterator(inst_pin_net)};
  while (nti->hasNext()) {
    const sta::Term* term = nti->next();
    dbModBTerm* mod_bterm = module->findModBTerm(network_->name(term));
    if (mod_bterm) {
      mod_bterm->connect(db_mod_net);
      debugPrint(logger_,
                 utl::ODB,
                 "dbReadVerilog",
                 2,
                 "connected feed-through mod_bterm '{}' (id={}) to mod net "
                 "'{}' (id={})",
                 mod_bterm->getName(),
                 mod_bterm->getId(),
                 db_mod_net->getName(),
                 db_mod_net->getId());
    }
  }
  return db_mod_net;
}

Fix5. Removed redundant betweenPorts restrictions in UnbufferMove::canRemoveBuffer()

There was remove_buffer restriction that a buffer driving output dbBTerm cannot be removed.
This was due to the incomplete dbSta implementation that removing a buffer connecting an input dbBTerm and an output dbBTerm causes mal-function.

Thanks to the dbSta enhancement in this PR, now we can remove the redundant restrictions in canRemoveBuffer().

bool UnbufferMove::canRemoveBuffer(Instance* buffer, bool honorDontTouchFixed)
{
  LibertyCell* lib_cell = network_->libertyCell(buffer);
  if (!lib_cell || !resizer_->isLogicStdCell(buffer) || !lib_cell->isBuffer()) {
    return false;
  }
...

  ***********  Fix5-1. Removed redundant restriction  *************************************
  // Do not remove buffers connected to input/output ports
  // because verilog netlists use the net name for the port.
  // if (bufferBetweenPorts(buffer)) {
  //  return false;
  //}

...

  bool out_net_ports = db_network_->hasPort(out_net);
  Net* removed = nullptr;
  odb::dbNet* db_net_survivor = nullptr;
  odb::dbNet* db_net_removed = nullptr;
  if (out_net_ports) {
  ***********  Fix5-2. Removed redundant restriction  *************************************
    // if (db_network_->hasPort(in_net)) {
    //  return false;
    //}
...

}

Fix 6. Used flat net always instead of a mix of flat & hier nets in Resizer::net_slack_map.

This issue caused QoR difference b/w flat and hier flows because a mixed use of flat & hier nets causes net_slack_map_ cache lookup fail in hier flow.

void Resizer::findResizeSlacks1()
{
  // Use driver pin slacks rather than Sta::netSlack to save visiting
  // the net pins and min'ing the slack.
  net_slack_map_.clear();
  for (int i = level_drvr_vertices_.size() - 1; i >= 0; i--) {
    Vertex* drvr = level_drvr_vertices_[i];
    Pin* drvr_pin = drvr->pin();

    // PROBLEM ----------------------------------------------------------------------------------
    // - dbNetwork::net() returns dbModNet first if exists. 
    // - In hier flow, this logic inserts dbNet & dbModNet. 
    //   But net_slack_map_ query is performed with dbNet key always, 
    //   which causes a lookup fail when the dbModNet key was stored.
    //-----------------------------------------------------------------------------------------------
    Net* net = network_->isTopLevelPort(drvr_pin)
                   ? network_->net(network_->term(drvr_pin))     
                   : network_->net(drvr_pin);
    if (net
        && !drvr->isConstant()
        // Hands off special nets.
        && !db_network_->isSpecial(net) && !sta_->isClock(drvr_pin)) {
      net_slack_map_[net] = sta_->vertexSlack(drvr, max_);
    }
  }
}

Solution

Use flat net always.

// OLD
    Net* net = network_->isTopLevelPort(drvr_pin)
                   ? network_->net(network_->term(drvr_pin))     
                   : network_->net(drvr_pin);
// NEW: Use flat net always.
    Net* net = db_network_->dbToSta(db_network_->flatNet(drvr_pin));

Fix 7. Fixed no incremental parasitics invalidation issue when Net* indicates a dbModNet

Previously, the following code skipped incremental parasitics invalidation when a dbModNet is returned by dbNetwork::net(Pin*), which is wrong.

The fix is to find the related dbNet with the given dbModNet and invalidate the parasitics correctly.

void OdbCallBack::inDbInstSwapMasterAfter(odb::dbInst* inst)
{
...
  // Invalidate estimated parasitics on all instance pins.
  std::unique_ptr<InstancePinIterator> pin_iter{
      network_->pinIterator(sta_inst)};
  while (pin_iter->hasNext()) {
    Pin* pin = pin_iter->next();
    Net* net = network_->net(pin);

    const sta::LibertyPort* port = network_->libertyPort(pin);
    // Tristate nets have multiple drivers and this is drivers^2 if
    // the parasitics are updated for each resize.
    if (!port || !port->direction()->isAnyTristate()) {
      // we can only update parasitics for flat net

// OLD ///////////////
      // odb::dbNet* db_net = db_network_->flatNet(net);       // PROBLEM. No invalidation when the net is a dbModNet
/////////////////////////

// NEW ///////////////
      odb::dbNet* db_net = db_network_->findFlatDbNet(net);       // It returns the corresponding flat net when net is a dbModNet
///////////////////////

      estimate_parasitics_->parasiticsInvalid(db_network_->dbToSta(db_net));
    }
  }
}

Fix 8. Sorted instances by name in Resizer::findCellInstances()

In hier flow, the cell instances are gathered by visiting module by module while flat flow visits just a single top module.
So the resulting instance orders are different b/w flat and hier flows, which results in QoR gap.
A solution is to sort the cell instances by name.

  • But the sorting by name is expensive. So this sorting will be removed when the hier flow is enabled by default.
  • Note that sorting the instances by object ID cannot resolve the issue because object IDs are very different in flat and hier flows.

Now they return number of warnings.

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Moved getBaseName from dbEditHierarchy to dbBlock.

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
…ate/OpenROAD into secure-insert-buffer

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
…ate/OpenROAD into secure-insert-buffer

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
…g later

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
void dbInsertBuffer::setBufferAttributes(dbInst* buffer_inst)
{
new_flat_net_->setSigType(net_->getSigType());
buffer_inst->setSourceType(dbSourceType::TIMING);

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.

I fixed the source type attribute for the new buffer as TIMING. Is this ok?


if (dbTechNonDefaultRule* ndr = net_->getNonDefaultRule()) {
new_flat_net_->setNonDefaultRule(ndr);
}

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.

@jfgava Copied the NDR attribute.

@maliberty

Copy link
Copy Markdown
Member

No problem to waive clang-tidy

@maliberty

Copy link
Copy Markdown
Member

Does this need a metrics PR for any flat flow changes?

@jhkim-pii

Copy link
Copy Markdown
Contributor

Does this need a metrics PR for any flat flow changes?

Yes. I am preparing a new ORFS PR.

@jhkim-pii

Copy link
Copy Markdown
Contributor

This is the related ORFS PR The-OpenROAD-Project/OpenROAD-flow-scripts#3737.

@maliberty maliberty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

partial review

@@ -34,6 +34,18 @@ class IntegratedFixture : public tst::Fixture
void dumpVerilogAndOdb(const std::string& name) const;
void removeFile(const std::string& path);

// Compare with verilog string input
// 'remove_file=false' will keep the output verilog for debug
void writeAndCompareVerilogOutputString(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is fine but eventually I would like VerilogWriter to take an ostream so we can pass an ostringstream and do this in memory.

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.

I think writing on a file is better for debugging.
When a test case fails, we can debug it easier by opening the output verilog file (can be generated by setting remove_file = false).
If the verilog is just on a memory, we should write it on a file and run a diff for debugging

Comment thread src/odb/include/odb/db.h Resolved
return nullptr;
}

void dbBTerm::connect(dbNet* db_net, dbModNet* modnet)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does it suffice to only take the dbModNet - would db_net ever not be modnet->findRelatedNet() ?

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.

It has the following issues.

  1. If netlist editing finishes successfully, modnet->findRelatedNet() will find the correct dbNet. But it takes computational cost.
  2. If netlist is being actively edited, modnet->findRelatedNet() may not return the correct dbNet because the netlist is incomplete.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I worry that some caller could give an invalid pair. Do we have a sanity check for this elsewhere?

Comment thread src/odb/src/db/dbInsertBuffer.cpp Resolved
Comment thread src/odb/src/db/dbInsertBuffer.cpp Resolved
Comment thread src/odb/src/db/dbInsertBuffer.cpp Outdated
if (buffer_inst == nullptr) {
logger_->error(
utl::ODB, 1205, "BeforeLoads: Failed to create buffer instance.");
return nullptr;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unreachable as error will throw

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>

@povik povik left a comment

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.

I have reviewed Rebuffer.cc which looks good, I have also reviewed elsewhere in rsz except for the cpp tests

Comment thread src/rsz/src/CloneMove.cc
// - No dont_touch
// - No pending-move cell
// - No multiple output cell
//

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.

I haven't reviewed this comment

Comment thread src/rsz/src/Rebuffer.cc Outdated
// Martin (2024-04-18): This is copied over from original RepairSetup
// buffering mostly unchanged and is ripe for clean-up/rewrite later.
// Jaehyun (2025-11-27): Re-implemented using insertBufferBeforeLoads to
// simplify hierarchy handling and avoid direct use of hierarchicalConnect.

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.

@jhkim-pii I think you have now done the rewrite this code was waiting for so we can drop the comments

Comment thread src/rsz/src/Rebuffer.cc Outdated
insertBuffers = [&](const BufferedNetPtr& node,
PinSet& current_loads,
int& count) {
if (!node) {

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.

Nit: I think !node is unreachable

Comment thread src/rsz/src/Rebuffer.cc
sdc_network_->pathName(load_pin));
return 0;
// Skip DontTouch pins
if (resizer_->dontTouch(load_pin)) {

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.

I think later we should make sure that the choice topology never has a buffer in front of a dont touch load pin. Otherwise what gets implemented in odb differs from what the buffering algorithm evaluated and we are losing QoR.

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.

Yeah. It is a better approach.

Comment thread src/rsz/src/Rebuffer.cc
// node
odb::dbITerm* input_term = buf_inst->findITerm(input->name());
if (input_term) {
Pin* sta_input_pin = db_network_->dbToSta(input_term);

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.

Can db_network_->dbToSta for an ITerm fail?

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.

You're right. I don't think so. Let me remove the redundant code.

Comment thread src/rsz/include/rsz/Resizer.hh Outdated
/// - This accepts STA objects instead of db objects.
///
Instance* insertBufferBeforeLoads(Net* net,
PinSeq* loads,

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.

As far as I can see the PinSeq* variant isn't being used within rsz

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.

Yeah. I added it for future usage.

Some logics play with PinSet while other logics paly with PinSeq.
If this overloaded API does not exists, developers will do the PinSeq -> PinSet conversion here and there before calling the insertBuffer API.
IMO, having this prototype looks better to avoid the expected redundant codes in the future.

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.

I think RepairHold has one case of this conversion in your branch

Comment thread src/rsz/include/rsz/Resizer.hh Outdated
const odb::dbNameUniquifyType& uniquify
= odb::dbNameUniquifyType::ALWAYS,
bool loads_on_diff_nets = false);
odb::dbInst* insertBufferBeforeLoads(odb::dbNet* net,

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.

Could we drop the odb type variants of the insert APIs on the resizer object? I don't think we use them and one can always do the cast on the caller side

@jhkim-pii jhkim-pii Dec 30, 2025 •

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.

Hmm.. IMO, it would be better to have these APIs.

  • If the caller already plays with ODB objects rather than STA objects by some reasons, calling this API is better because it can omit the redundant ODB -> STA -> ODB object conversions.

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.

On the other hand we mainly work with STA pointers in the resizer, and we don't provide ODB variants for other APIs

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.

Oh, I see.

But ODB is more powerful than STA data structures (e.g., due to richer physical data).
So I think we would play more with ODB especially in the future because new algorithm requires more and more physical information.
What do you think about this?

// These buffers occupy as special place in hierarchy and cannot
// be removed without destroying the hierarchy.
// This is the hierarchical equivalent of "bufferBetweenPorts" above

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.

@jhkim-pii Does dropping the check above mean that we would allow the removal of a feedthrough buffer?

Comment thread src/rsz/src/Resizer.tcl Outdated
keys {-buffer_cell -location -buffer_name -net_name -net -load_pins} \
flags {-load_pins_on_diff_nets}

# Validate mutually exclusive arguments

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.

As far as I can tell -net and -load_pins are not mutually exclusive

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.

You're right. Let me modify the comment.

Comment thread src/rsz/src/Resizer.tcl
# For a single load pin, use insert_buffer_before_load_cmd
set pin [lindex $loads 0]
return [rsz::insert_buffer_before_load_cmd $pin $buffer_cell $x $y $has_loc \
$new_buf_base_name $new_net_base_name]

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.

If both -net and -load_pins are supplied and -load_pins_on_diff_nets is not, are we meant to check all the load pins are on the provided net? If so, the check won't work for load_count==1 as we are discarding $net in that case

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.

If both -net and -load_pins are supplied and -load_pins_on_diff_nets is not, are we meant to check all the load pins are on the provided net?

Yes. The check is located at dbNet::insertBufferBeforeLoads().

If so, the check won't work for load_count==1 as we are discarding $net in that case

Yes. When the load_count is 1, the both -net and -load_pins_on_diff_nets are meaningless.

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.

That can surprising to the user as a check occurs or doesn't occur based on the number of loads

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.

Right.

Let me add this warning in the Resizer.tcl.

    if { $load_count == 1 } {
      if { $has_net } {
        utl::warn RSZ 69 "-net argument is ignored if there is only one load pin."
      }

      # For a single load pin, use insert_buffer_before_load_cmd
      set pin [lindex $loads 0]
      return [rsz::insert_buffer_before_load_cmd $pin $buffer_cell $x $y $has_loc \
        $new_buf_base_name $new_net_base_name]

Let me add the following statement in insert_buffer.md.

Note that -load_pins_on_diff_nets and -net are meaningless
when a single load pin is given by -load_pins.

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.

Thanks, warning resolves it

@vvbandeira

Copy link
Copy Markdown
Member

@vvbandeira Could you please look into the clang-tidy-review issue? The large PR may be the cause. I wonder if you have any solutions.

github.GithubException.GithubException: Sorry, the diff exceeded the maximum number of lines (20000): 406 {"message": "Sorry, the diff exceeded the maximum number of lines (20000)", "errors": [{"resource": "PullRequest", "field": "diff", "code": "too_large"}], "documentation_url": "https://docs.github.com/rest/pulls/pulls#get-a-pull-request", "status": "406"}

This is a known limitation for large PRs; the only solution is to split into multiple PRs.

@arthurjolo arthurjolo left a comment

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.

Changes on LatencyBalancer.cpp looks fine, the changes seem to be replicating the previous code behavior correctly.

I just have one question about the static_cast.

Comment thread src/cts/src/LatencyBalancer.cpp Outdated
Comment on lines +550 to +551
odb::dbObject* drvrPin = lastBuffer->getFirstOutput();
drivingNet = static_cast<odb::dbITerm*>(drvrPin)->getNet();

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.

This is just a question, but I was wondering what is the reason for getting the driver pin as dbObject and static cast it when serching for the net?

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.

Oops. Thank you for catching this. It is a redundant casting.

@maliberty

Copy link
Copy Markdown
Member

This same API can also be used to insert inverters. Perhaps it would be better to use repeater or unary rather than buffer in the name.

@maliberty maliberty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

More progress on the simple cases

Comment thread src/odb/src/db/dbInsertBuffer.cpp Outdated
Comment on lines +97 to +99
if (term_obj == nullptr || buffer_master == nullptr) {
return nullptr;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These seems more like an error by the caller. I think error here would be better than a quiet nullptr.

Comment thread src/odb/src/db/dbInsertBuffer.cpp Outdated
}
mod_net = bterm->getModNet();
} else {
return false; // Invalid term type

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make an error

Comment thread src/odb/src/db/dbInsertBuffer.cpp Outdated
Comment on lines +298 to +300
if (iterm && iterm->getInst()->isDoNotTouch()) {
return true;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This limitation can be solved by swapping the roles of the new and existing nets. That can be handled in another PR. I believe the current code does this.

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.

Got your point.
Let me think more about it.

}

mod_net = iterm->getModNet();
} else if (term_obj->getObjectType() == dbBTermObj) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is a dont-touch check needed on the net attached to the bterm?

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.

I modified the code to check the dont_touch flag of the net connected to the bterm.

Comment thread src/odb/src/db/dbInsertBuffer.cpp Outdated
Comment on lines +278 to +279
const char* inst_base_name
= (new_buf_base_name_) ? new_buf_base_name_ : "buf";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think new_buf_base_name_ can be null at this point.

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.

I think I can be null here. Could you please double check?

@maliberty maliberty Dec 30, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it considered acceptable for the user to pass in a nullptr? If so then it could be. I would change the signature from

const char* new_buf_base_name = nullptr

to

const char* new_buf_base_name = "buf"

in that case rather than bury the default deep in the code and also to avoid the conditional here.

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.

Good suggestion. Let me do this.

// db.h
inline constexpr const char* kDefaultBufBaseName{"buf"};
inline constexpr const char* kDefaultNetBaseName{"net"};
// dbInsertBuffer.h
  dbInst* insertBufferBeforeLoad(
      dbObject* load_input_term,
      const dbMaster* buffer_master,
      const Point* loc = nullptr,
      const char* new_buf_base_name = kDefaultBufBaseName,
      const char* new_net_base_name = kDefaultNetBaseName,
      const dbNameUniquifyType& uniquify = dbNameUniquifyType::ALWAYS);

// This ensures that the net name matches the port name for Verilog
// compatibility.

std::string new_net_name = (new_net_base_name_) ? new_net_base_name_ : "net";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think new_net_base_name_ can be null

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.

I think it can also be null.

  // In dbInsertBuffer.h
  dbInst* insertBufferAfterDriver(dbObject* drvr_output_term,
                                  const dbMaster* buffer_master,
                                  const Point* loc = nullptr,
                                  const char* new_buf_base_name = nullptr,    // CAN BE NULL
                                  const char* new_net_base_name = nullptr,    // CAN BE NULL
                                  const dbNameUniquifyType& uniquify
                                  = dbNameUniquifyType::ALWAYS);

...

dbInst* dbInsertBuffer::insertBufferAfterDriver(
    dbObject* drvr_output_term,
    const dbMaster* buffer_master,
    const Point* loc,
    const char* new_buf_base_name,
    const char* new_net_base_name,
    const dbNameUniquifyType& uniquify)
{
  dlogInsertBufferStart(++insert_buffer_call_count_, "AfterDriver");

  return insertBufferSimple(drvr_output_term,
                            buffer_master,
                            loc,
                            new_buf_base_name,     // CAN BE NULL
                            new_net_base_name,     // CAN BE NULL
                            uniquify,
                            /* insertBefore */ false);
}


dbInst* dbInsertBuffer::insertBufferSimple(dbObject* term_obj,
                                           const dbMaster* buffer_master,
                                           const Point* loc,
                                           const char* new_buf_base_name,
                                           const char* new_net_base_name,
                                           const dbNameUniquifyType& uniquify,
                                           bool insertBefore)
{
...
  buffer_master_ = buffer_master;
  new_buf_base_name_ = new_buf_base_name;   // CAN BE NULL
  new_net_base_name_ = new_net_base_name;    // CAN BE NULL
  uniquify_ = uniquify;
...

  dbInst* buffer_inst = checkAndCreateBuffer();
...
}


dbInst* dbInsertBuffer::checkAndCreateBuffer()
{
...

  const char* inst_base_name
      = (new_buf_base_name_) ? new_buf_base_name_ : "buf";    // new_buf_base_name_ CAN BE NULL
  dbInst* buffer_inst = dbInst::create(block_,
                                       const_cast<dbMaster*>(buffer_master_),
                                       inst_base_name,
                                       uniquify_,
                                       target_module_);
...
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same as buf name


dbBTerm* bterm = static_cast<dbBTerm*>(obj);
std::string_view bterm_name{bterm->getConstName()};
if (bterm_name == block_->getBaseName(net_->getConstName())) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is getBaseName needed here? You wouldn't want bterm 'X' to match net 'A/X' (which would be very odd to happen in the first place).

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.

I don't get your point.

It is to check if the original net name is the same as any of output dbBTerm names.
If it is true, the original net (driving the new buffer) name should be changed and the new net (driving load pins) name should have the dbBTerm name.

net_ name has a full hierarchical name. So I used getBaseName() to extract the last token in the full name.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How can a bterm be connected to a net that is not at the top of the hierarchy (i.e. without any delimiters in its name)?

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.

By the insert buffer, when a new net "hier/net" is going to be connected to an output bterm "out", it can happen.
"hier/net" can be connected to the bterm "out". But by this logic, it will be renamed to "out" soon.

Regardless of the renaming, "hier/net" connecting to the "out" can happen. In this case, verilog writer generates an assign statement to connect them (e.g., assign out = net; // 'net' from 'hier/net' ).

Comment thread src/odb/src/db/dbInsertBuffer.cpp Outdated
Comment on lines +444 to +449
// The original net names uses the BTerm name.
// Rename this net if its name is the same as a port name in loads_pins
std::string new_orig_net_name = block_->makeNewNetName(
target_module_ ? target_module_->getModInst() : nullptr,
"net",
uniquify_);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If uniquify is IF_NEEDED* this may not produce a different name. Would it be better to use ALWAYS*?

Comment thread src/odb/src/db/dbInsertBuffer.cpp Outdated
terms.insert(term_obj);

new_flat_net_ = createNewFlatNet(terms);
if (new_flat_net_ == nullptr) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The only way this could happen is if you messed up name uniquification. It should be an error in that case.

Comment on lines +330 to +331
dbNet* in_net = insertBefore ? net_ : new_flat_net_;
dbNet* out_net = insertBefore ? new_flat_net_ : net_;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In the driver-side buffering we have insertBefore=false. The doc says:
The original net is connected to the buffer input, and a new net is created for the buffer output to drive all original loads.
however this code says in_net is new_flat_net_ and out_net is net_. This seems to be the opposite.

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.

Oh, the doc is wrong. Thank you for catching this.

dbModule* dbInsertBuffer::validateLoadPinsAndFindLCA(
std::set<dbObject*>& load_pins,
std::set<dbNet*>& other_dbnets,
bool loads_on_diff_nets) const

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

const (here and dlogBeforeLoadsParams).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

still not const

load_name);
return nullptr;
}
} else if (load_obj->getObjectType() == dbBTermObj) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

similar - does a bterm need a dont-touch on the net check?

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.

Added the dont_touch check logic for the net connected to the bterm.

Comment thread src/odb/src/db/dbInsertBuffer.cpp Outdated
Comment on lines +520 to +523
while (m1 != m2 && m1 != nullptr && m2 != nullptr) {
m1 = m1->getModInst() ? m1->getModInst()->getParent() : nullptr;
m2 = m2->getModInst() ? m2->getModInst()->getParent() : nullptr;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The only way you could get these to be null would be if they came from different blocks, otherwise the top_module would also be the common parent. We should error early if we see different blocks as that is a caller error.

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.

Reimplemented it. How about this?

dbModule* dbInsertBuffer::findLCA(dbModule* m1, dbModule* m2) const
{
  dbModule* top_module = block_->getTopModule();
  if (m1 == nullptr || m2 == nullptr) {
    return top_module;
  }

  if (m1->getOwner() != m2->getOwner()) {
    logger_->error(utl::ODB,
                   1212,
                   "findLCA: Two modules '{}' (block: {}) and '{}' (block: {}) "
                   "must be in the same block.",
                   m1->getName(),
                   m1->getOwner()->getName(),
                   m2->getName(),
                   m2->getOwner()->getName());
  }

  if (m1 == top_module || m2 == top_module) {
    return top_module;
  }

  int d1 = getModuleDepth(m1);
  int d2 = getModuleDepth(m2);

  // Bring m1 and m2 to the same depth
  while (d1 > d2) {
    m1 = m1->getParentModule();
    d1--;
  }
  while (d2 > d1) {
    m2 = m2->getParentModule();
    d2--;
  }

  // Move up until they meet
  while (m1 != m2) {
    m1 = m1->getParentModule();
    m2 = m2->getParentModule();
  }
  return m1;
}

target_module = curr_mod;
first = false;
} else {
target_module = findLCA(target_module, curr_mod);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if the target_module is the top_module there is no point in calling findLCA

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.

In the new implementation of findLCA(), I added the top module check logic to cover this.
This can make callers simpler.

Comment thread src/odb/src/db/dbInsertBuffer.cpp Outdated
Comment on lines +1320 to +1322
if (target_module == nullptr) {
target_module = block_->getTopModule();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can't happen

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.

Removed

Comment thread src/odb/src/db/dbInsertBuffer.h Outdated
dbNet* new_flat_net_{nullptr}; // New flat net connected to the new buffer
dbModNet* new_mod_net_{nullptr}; // New modnet connected to the new buffer
dbModule* target_module_{nullptr}; // Target module for the new buffer
const dbMaster* buffer_master_{nullptr}; // Buffer master

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comments that don't add any information should be dropped (buffer_master_ is obviously the buffer master).

Comment thread src/odb/src/db/dbInsertBuffer.cpp Outdated
trace_module = static_cast<dbITerm*>(trace_obj)->getInst()->getModule();
}

while (trace_module != target_module_ && trace_module != nullptr) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

trace_module == nullptr can't happen

Comment thread src/odb/src/db/dbInsertBuffer.cpp Outdated
return worker(start_net);
}

void dbInsertBuffer::populateReusableNets(const std::set<dbObject*>& load_pins)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

populateReusableModNets is more precise. A descriptive comment would be helpful.

Comment thread src/odb/src/db/dbInsertBuffer.cpp Outdated
if (modnets_in_target_module.contains(curr_modnet)) {
return curr_modnet;
}
curr_modnet = curr_modnet->getNextModNetInFanout();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I unclear on how this works - this search from one path forward. If the module is in a different path it won't be found.

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.

You're right. I just considered a simple case that there is no multiple fanout.
Let me revise this.

Comment thread src/odb/src/db/dbInsertBuffer.cpp Outdated
if (loc) {
placement_loc = *loc;
} else {
placement_loc = computeCentroid(orig_drvr_pin_, load_pins);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

similar - if all instances are unplaced then don't place this one.

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.

Refactored the buffer placement code.

@jhkim-pii

Copy link
Copy Markdown
Contributor

This same API can also be used to insert inverters. Perhaps it would be better to use repeater or unary rather than buffer in the name.

IMO,

  • Even if we want to insert inverters in the future, it should be a pair of inverters not to break the logic. Actually, a pair of inverters is functionally equivalent to a buffer. So I think using the name buffer looks not that bad.
  • I think buffer looks more intuitive than repeater or unary.

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
…ate/OpenROAD into secure-insert-buffer

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
@jhkim-pii
jhkim-pii requested a review from maliberty December 31, 2025 15:30
const std::function<bool(dbModNet*)>& condition,
dbHierSearchDir dir) const
{
std::vector<dbModNet*> worklist;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be better to use a deque so you can pop off the front rather than having the worklist keep all the visited nets. It can wait for another PR.

dbModule* dbInsertBuffer::validateLoadPinsAndFindLCA(
std::set<dbObject*>& load_pins,
std::set<dbNet*>& other_dbnets,
bool loads_on_diff_nets) const

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

still not const

@maliberty
maliberty merged commit a95464d into The-OpenROAD-Project:master Dec 31, 2025
9 of 10 checks passed
@maliberty
maliberty deleted the secure-insert-buffer branch December 31, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants