Skip to content

Commit 169f2b2

Browse files
committed
syn: avoid including private header from a public header & tidy
syn/synthesis.h was including syn/ir/Graph.h which was no accessible to clients. This was for a std::optional<Graph> which is replaced by a std::unique_ptr<Graph>. Misc other clang-tidy cleanups. Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
1 parent 6606407 commit 169f2b2

27 files changed

Lines changed: 162 additions & 153 deletions

src/syn/include/syn/synthesis.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33

44
#pragma once
55

6-
#include <optional>
6+
#include <memory>
77
#include <string>
88
#include <vector>
99

1010
#include "db_sta/dbSta.hh"
1111
#include "odb/db.h"
12-
#include "syn/ir/Graph.h"
1312
#include "utl/Logger.h"
1413

1514
namespace sta {
@@ -23,6 +22,7 @@ class Resizer;
2322

2423
namespace syn {
2524

25+
class Graph;
2626
class Net;
2727

2828
class Synthesis : public sta::dbStaState
@@ -102,7 +102,7 @@ class Synthesis : public sta::dbStaState
102102
// which mirrors liberty's dont_use plus any user-set entries).
103103
bool dontUse(const sta::LibertyCell* cell) const;
104104

105-
Graph* graph() { return graph_ ? &*graph_ : nullptr; }
105+
Graph* graph() { return graph_.get(); }
106106

107107
private:
108108
// Resolve a net reference string to a Net.
@@ -111,7 +111,7 @@ class Synthesis : public sta::dbStaState
111111
odb::dbDatabase* db_ = nullptr;
112112
rsz::Resizer* resizer_ = nullptr;
113113
utl::Logger* logger_ = nullptr;
114-
std::optional<Graph> graph_;
114+
std::unique_ptr<Graph> graph_;
115115
};
116116

117117
// Free-function entry points re-declared here so tests don't need to

src/syn/src/elab/backend_builder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace slang_frontend {
3030

3131
BackendGraphBuilder::BackendGraphBuilder()
3232
{
33-
graph_.emplace();
33+
graph_ = std::make_unique<syn::Graph>();
3434
}
3535

3636
std::unique_ptr<BackendGraphBuilder> BackendGraphBuilder::start_new_graph(

src/syn/src/elab/backend_builder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <cassert>
1212
#include <cstdint>
1313
#include <memory>
14-
#include <optional>
1514
#include <string>
1615
#include <string_view>
1716
#include <vector>
@@ -124,7 +123,7 @@ class BackendGraphBuilder : public BackendGraphBuilderBase
124123
bool clk_polarity,
125124
bool aload_polarity) override;
126125

127-
std::optional<syn::Graph> graph_;
126+
std::unique_ptr<syn::Graph> graph_;
128127
unsigned next_id = 0;
129128
};
130129

src/syn/src/elab/driver.cc

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "backend_builder.h"
1717
#include "blackboxes.h"
18-
#include "log_stubs.h"
1918
#include "slang/ast/Compilation.h"
2019
#include "slang/ast/SemanticFacts.h"
2120
#include "slang/ast/symbols/CompilationUnitSymbols.h"
@@ -37,10 +36,10 @@ using namespace slang_frontend; // NOLINT(google-build-using-namespace)
3736
// Non-static so error.cc can call it from elaborateText. Not declared in
3837
// driver.h because the source-buffer parameter is only useful to the test
3938
// helper.
40-
std::optional<Graph> elaborateImpl(utl::Logger* logger,
41-
const std::vector<std::string>& args,
42-
sta::dbSta* sta,
43-
std::optional<std::string> buffer)
39+
std::unique_ptr<Graph> elaborateImpl(utl::Logger* logger,
40+
const std::vector<std::string>& args,
41+
sta::dbSta* sta,
42+
std::optional<std::string> buffer)
4443
{
4544
slang::driver::Driver driver;
4645
driver.addStandardArgs();
@@ -66,17 +65,17 @@ std::optional<Graph> elaborateImpl(utl::Logger* logger,
6665

6766
if (!driver.parseCommandLine(static_cast<int>(c_args.size()),
6867
const_cast<char**>(c_args.data()))) {
69-
return std::nullopt;
68+
return nullptr;
7069
}
7170

7271
fixup_options(settings, driver);
7372
if (!driver.processOptions()) {
74-
return std::nullopt;
73+
return nullptr;
7574
}
7675
catch_forbidden_options(driver);
7776

7877
if (!driver.parseAllSources()) {
79-
return std::nullopt;
78+
return nullptr;
8079
}
8180

8281
auto compilation = driver.createCompilation();
@@ -91,12 +90,12 @@ std::optional<Graph> elaborateImpl(utl::Logger* logger,
9190

9291
if (driver.diagEngine.getNumErrors()) {
9392
(void) driver.reportDiagnostics(/*quiet=*/false);
94-
return std::nullopt;
93+
return nullptr;
9594
}
9695

9796
if (settings.ast_compilation_only.value_or(false)) {
9897
(void) driver.reportDiagnostics(/*quiet=*/false);
99-
return std::nullopt;
98+
return nullptr;
10099
}
101100

102101
// We require exactly one top-level instance.
@@ -127,7 +126,7 @@ std::optional<Graph> elaborateImpl(utl::Logger* logger,
127126
slang::Diagnostics diags;
128127
diags.append_range(netlist.issued_diagnostics);
129128
diags.sort(driver.sourceManager);
130-
for (int j = 0; j < (int) diags.size(); j++) {
129+
for (int j = 0; j < diags.size(); j++) {
131130
if (j > 0 && diags[j] == diags[j - 1]) {
132131
continue;
133132
}
@@ -136,7 +135,7 @@ std::optional<Graph> elaborateImpl(utl::Logger* logger,
136135
}
137136

138137
if (!driver.reportDiagnostics(/*quiet=*/false)) {
139-
return std::nullopt;
138+
return nullptr;
140139
}
141140

142141
// Extract the graph from the top netlist's backend.
@@ -145,9 +144,9 @@ std::optional<Graph> elaborateImpl(utl::Logger* logger,
145144
return std::move(builder->graph_);
146145
}
147146

148-
std::optional<Graph> elaborate(utl::Logger* logger,
149-
const std::vector<std::string>& args,
150-
sta::dbSta* sta)
147+
std::unique_ptr<Graph> elaborate(utl::Logger* logger,
148+
const std::vector<std::string>& args,
149+
sta::dbSta* sta)
151150
{
152151
return elaborateImpl(logger, args, sta, {});
153152
}

src/syn/src/elab/driver.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99
#pragma once
1010

11-
#include <optional>
11+
#include <memory>
1212
#include <string>
1313
#include <vector>
1414

@@ -28,10 +28,10 @@ namespace syn {
2828
// Arguments are passed through to slang's command-line parser
2929
// (file paths, -I, --top, defines, etc.).
3030
// If sta is non-null, Liberty cell definitions are imported as blackboxes.
31-
std::optional<Graph> elaborate(utl::Logger* logger,
32-
const std::vector<std::string>& args,
33-
sta::dbSta* sta = nullptr);
34-
std::optional<Graph> elaborateText(const std::string& source,
35-
const std::vector<std::string>& args = {});
31+
std::unique_ptr<Graph> elaborate(utl::Logger* logger,
32+
const std::vector<std::string>& args,
33+
sta::dbSta* sta = nullptr);
34+
std::unique_ptr<Graph> elaborateText(const std::string& source,
35+
const std::vector<std::string>& args = {});
3636

3737
} // namespace syn

src/syn/src/elab/error.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// - slang_frontend::reportError (calls Logger::error)
1111
// - syn::elaborateText (default-constructs a utl::Logger)
1212

13+
#include <memory>
1314
#include <optional>
1415
#include <string>
1516
#include <string_view>
@@ -22,13 +23,13 @@
2223
namespace syn {
2324

2425
// Defined in driver.cc.
25-
std::optional<Graph> elaborateImpl(utl::Logger* logger,
26-
const std::vector<std::string>& args,
27-
sta::dbSta* sta,
28-
std::optional<std::string> buffer);
26+
std::unique_ptr<Graph> elaborateImpl(utl::Logger* logger,
27+
const std::vector<std::string>& args,
28+
sta::dbSta* sta,
29+
std::optional<std::string> buffer);
2930

30-
std::optional<Graph> elaborateText(const std::string& source,
31-
const std::vector<std::string>& args)
31+
std::unique_ptr<Graph> elaborateText(const std::string& source,
32+
const std::vector<std::string>& args)
3233
{
3334
utl::Logger logger;
3435
return elaborateImpl(&logger, args, nullptr, source);

src/syn/src/flow/abc.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "syn/ir/Graph.h"
1515
#include "syn/ir/Instance.h"
1616
#include "syn/ir/Net.h"
17+
#include "syn/synthesis.h"
1718
#include "utl/Logger.h"
1819

1920
// ABC headers are already compiled within namespace abc by the build system.

src/syn/src/flow/bitblast.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ struct BitblastedOperation
320320
// Stages 2..levels-1 (Kogge-Stone on odd indices only).
321321
for (int i = 1; i < levels; i++) {
322322
uint32_t stride = 1u << i;
323-
for (int j = (int) n - 1; j >= (int) stride; j--) {
323+
for (int j = (int) n - 1; j >= stride; j--) {
324324
if (j % 2 == 1) {
325325
Literal new_g = OR(g[j], AND(p[j], g[j - stride]));
326326
Literal new_p = AND(p[j], p[j - stride]);
@@ -594,7 +594,7 @@ struct BitblastedOperation
594594
Literal product = AND(a_bits[j], b_bits[k]);
595595

596596
if ((k == b_len - 1 || j == a_len - 1)
597-
&& !(k == b_len - 1 && j == a_len - 1)) {
597+
&& (k != b_len - 1 || j != a_len - 1)) {
598598
product = !product;
599599
corrections[j + k]--;
600600
}

src/syn/src/flow/combinational_mapper.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static Truth6 fexprEval(sta::FuncExpr* fexpr,
6666
case Op::port: {
6767
// Find the index of this port in inputs
6868
int in_idx;
69-
for (in_idx = 0; in_idx < (int) inputs.size(); in_idx++) {
69+
for (in_idx = 0; in_idx < inputs.size(); in_idx++) {
7070
if (inputs[in_idx] == fexpr->port()) {
7171
break;
7272
}
@@ -677,8 +677,8 @@ void Mapping::prepareMatches(const int npriority_cuts,
677677
int psSlot = 0;
678678
ClassMatch* matchBuf = allocMatches(nmatches_max);
679679

680-
for (int i = -1; i < (int) cache[n1->fid].ps.size(); i++) {
681-
for (int j = -1; j < (int) cache[n2->fid].ps.size(); j++) {
680+
for (int i = -1; i < cache[n1->fid].ps.size(); i++) {
681+
for (int j = -1; j < cache[n2->fid].ps.size(); j++) {
682682
Net* n1Cut = ((i == -1) ? t1 : cache[n1->fid].ps[i].cut);
683683
Net* n2Cut = ((j == -1) ? t2 : cache[n2->fid].ps[j].cut);
684684
int n1CutLen = (i == -1) ? 1 : cutLen(n1Cut);

src/syn/src/flow/constant_fold.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
// Copyright (c) 2026, The OpenROAD Authors
33

4+
#include "constant_fold.h"
5+
6+
#include <cassert>
47
#include <cstdint>
5-
#include <iostream>
68
#include <optional>
79
#include <utility>
810
#include <vector>
@@ -82,7 +84,7 @@ static int log2exact(uint64_t val)
8284
return __builtin_ctzll(val);
8385
}
8486

85-
void foldCombinationals(Graph& g)
87+
static void foldCombinationals(Graph& g)
8688
{
8789
std::vector<Net> new_output;
8890
g.forEachInstance([&](const Instance* inst) {
@@ -422,7 +424,7 @@ void foldCombinationals(Graph& g)
422424
}
423425
if (shift >= 0) {
424426
for (uint32_t i = 0; i < width; i++) {
425-
if ((int) i < shift) {
427+
if (i < shift) {
426428
new_output[i] = stripBuffers(g, op->a()[i]);
427429
} else {
428430
new_output[i] = Net::zero();
@@ -463,7 +465,7 @@ static BundleView sliceDff(Graph& g,
463465
original->clearValue().slice(base, width));
464466
}
465467

466-
bool foldSequentials(Graph& g)
468+
static bool foldSequentials(Graph& g)
467469
{
468470
// --- Flop optimization: replace DFF bits with constants ---
469471
//

0 commit comments

Comments
 (0)