Skip to content

Commit b2d93ae

Browse files
authored
Merge pull request #10771 from The-OpenROAD-Project-staging/syn-fix-sliceDff-uar
syn: fix stack-use-after-return in constant fold sliceDff, revised
2 parents 81dbd6b + 060af12 commit b2d93ae

3 files changed

Lines changed: 30 additions & 17 deletions

File tree

src/syn/src/ir/Bundle.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ Bundle::Bundle(BundleView bv) : tag_(kEmpty), width_(0), net_(Net::zero())
2525
net_ = bv[0];
2626
return;
2727
}
28+
29+
if (bv.isGuaranteedConsecutive()) {
30+
tag_ = kConsecutive;
31+
width_ = bv.width();
32+
net_ = bv[0];
33+
return;
34+
}
35+
2836
std::vector<Net> nets;
2937
nets.reserve(bv.width());
3038
for (uint32_t i = 0; i < bv.width(); i++) {

src/syn/src/ir/Bundle.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,21 @@ class Bundle
149149
class BundleView
150150
{
151151
public:
152-
BundleView(Net net) : net_(net), Bundle_(nullptr), offset_(0), width_(1) {}
152+
BundleView(Net net) : net_(net), bundle_(nullptr), offset_(0), width_(1) {}
153153

154154
BundleView(const Bundle& Bundle)
155-
: net_(Net::zero()), Bundle_(&Bundle), offset_(0), width_(Bundle.width())
155+
: net_(Net::zero()), bundle_(&Bundle), offset_(0), width_(Bundle.width())
156156
{
157157
}
158158

159159
BundleView(const Bundle& Bundle, uint32_t offset, uint32_t len)
160-
: net_(Net::zero()), Bundle_(&Bundle), offset_(offset), width_(len)
160+
: net_(Net::zero()), bundle_(&Bundle), offset_(offset), width_(len)
161161
{
162162
}
163163

164164
// Consecutive nets starting at base.
165165
BundleView(Net base, uint32_t len)
166-
: net_(base), Bundle_(nullptr), offset_(0), width_(len)
166+
: net_(base), bundle_(nullptr), offset_(0), width_(len)
167167
{
168168
}
169169

@@ -182,8 +182,8 @@ class BundleView
182182

183183
Net operator[](uint32_t i) const
184184
{
185-
if (Bundle_) {
186-
return (*Bundle_)[offset_ + i];
185+
if (bundle_) {
186+
return (*bundle_)[offset_ + i];
187187
}
188188
return Net(net_.id_ + i);
189189
}
@@ -211,8 +211,8 @@ class BundleView
211211

212212
BundleView slice(uint32_t offset, uint32_t len) const
213213
{
214-
if (Bundle_) {
215-
return BundleView(*Bundle_, offset_ + offset, len);
214+
if (bundle_) {
215+
return BundleView(*bundle_, offset_ + offset, len);
216216
}
217217
if (len == 0) {
218218
return BundleView(Net::zero(), nullptr, 0, 0);
@@ -222,14 +222,19 @@ class BundleView
222222

223223
bool isConst() const;
224224

225+
protected:
226+
// For optimized construction of Bundle from BundleView
227+
bool isGuaranteedConsecutive() const { return bundle_ == nullptr; }
228+
friend class Bundle;
229+
225230
private:
226231
BundleView(Net net, const Bundle* Bundle, uint32_t offset, uint32_t len)
227-
: net_(net), Bundle_(Bundle), offset_(offset), width_(len)
232+
: net_(net), bundle_(Bundle), offset_(offset), width_(len)
228233
{
229234
}
230235

231236
Net net_;
232-
const Bundle* Bundle_;
237+
const Bundle* bundle_;
233238
uint32_t offset_;
234239
uint32_t width_;
235240
};

src/syn/src/ir/Graph.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class Graph
4949
Graph& operator=(const Graph&) = delete;
5050

5151
// Add an instance to the graph.
52-
// Returns the output Bundle.
52+
// Returns the output BundleView.
5353
template <typename T, typename... Args>
54-
Bundle add(Args&&... args);
54+
BundleView add(Args&&... args);
5555

5656
// Resolve a Net to its owning Instance and bit offset.
5757
std::pair<const Instance*, uint32_t> resolve(Net net) const;
@@ -345,7 +345,7 @@ class Graph
345345
};
346346

347347
template <typename T, typename... Args>
348-
Bundle Graph::add(Args&&... args)
348+
BundleView Graph::add(Args&&... args)
349349
{
350350
size_t inst_size;
351351
if constexpr (requires { T::plan(args...); }) {
@@ -376,9 +376,9 @@ Bundle Graph::add(Args&&... args)
376376
for (uint32_t i = 1; i < output_width; ++i) {
377377
new (table_.pointer(id + i)) PlaceholderEntry(inst, i);
378378
}
379-
return Bundle(Net(id), output_width);
379+
return BundleView(Net(id), output_width);
380380
}
381-
return Bundle(Net(id));
381+
return BundleView(Net(id));
382382
}
383383

384384
// Heap path: allocate and construct on heap.
@@ -401,9 +401,9 @@ Bundle Graph::add(Args&&... args)
401401
}
402402

403403
if (output_width > 1) {
404-
return Bundle(Net(first), output_width);
404+
return BundleView(Net(first), output_width);
405405
}
406-
return Bundle(Net(first));
406+
return BundleView(Net(first));
407407
}
408408

409409
// Dump.cc

0 commit comments

Comments
 (0)