Skip to content

LTO-off blocks inlining of dbNetwork::dbToSta() and dbNetwork::staToDb() #9050

@jhkim-pii

Description

@jhkim-pii

Description

Currently, OpenROAD disables Link Time Optimization (LTO) due to a Qt issue.

LTO-off prevents inlining of staToDb() and dbToSta() and they require redundant function calls even if most of them do just a simple casting.

LTO-on is the right direction if it is possible.
Otherwise, moving those APIs to dbNetwork.hh can be an alternative because it provides chances of inlining.

...
Net* dbNetwork::dbToSta(dbModNet* net) const
{
  return reinterpret_cast<Net*>(net);
}

Port* dbNetwork::dbToSta(dbModBTerm* modbterm) const
{
  return reinterpret_cast<Port*>(modbterm);
}

Term* dbNetwork::dbToStaTerm(dbModBTerm* modbterm) const
{
  return reinterpret_cast<Term*>(modbterm);
}
...

What is Link Time Optimization (LTO)?

Link Time Optimization (LTO) is a compiler optimization technique. Instead of optimizing each source file individually (as is done in standard compilation), LTO allows the compiler to analyze the entire program as a single unit during the linking stage. This enables the compiler to "see" across module boundaries.

Advantages (Pros)

The primary goal of LTO is to improve the runtime performance of the final executable.

1. Cross-Module Inlining:

This is the most significant benefit. Without LTO, a function defined in File A cannot be inlined into File B. With LTO, the compiler can inline small, frequently used functions across different files, reducing function call overhead.

2. Aggressive Dead Code Elimination:

Because the linker sees the whole program, it can identify functions or global variables that are defined but never actually used anywhere in the project, allowing it to strip them out completely.

3. Reduced Binary Size:

Due to better dead code elimination and constant merging, the final executable size is often smaller (though aggressive inlining can sometimes counteract this).

4. Better Constant Propagation:

The compiler can track constant values passed between different translation units, allowing for more efficient code generation (e.g., pre-calculating results).

Disadvantages (Cons)

The benefits of LTO come at the cost of the development process and resource usage.

1. Significantly Longer Build Times:

The linking step becomes a massive bottleneck. Instead of just combining object files, the linker has to perform complex analysis and optimization on the entire codebase at once. This can drastically slow down incremental builds.

2. High Memory Consumption:

To analyze the whole program, the linker must load the Intermediate Representation (IR) of all modules into memory. For large projects, this requires a massive amount of RAM (often gigabytes).

3. Harder Debugging:

Because the code is heavily transformed and moved around (inlined) across files, mapping the machine code back to the original source lines becomes more difficult. Stepping through code in a debugger can be jumpy or confusing.

4. Toolchain Complexity:

LTO requires strict compatibility between the compiler and the linker (e.g., using LLVM's lld or GNU gold with plugins). Mixing object files compiled with different compiler versions usually fails.

Suggested Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

Labels

dbStaBinds sta to odb

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions