Skip to content

Commit 5888ed7

Browse files
committed
[PrunedLiveness] Added copy constructor.
It's useful to be able to form a second copy of liveness which is differently pruned by having more instructions added to it, e.g..
1 parent 71b11b6 commit 5888ed7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

include/swift/SIL/PrunedLiveness.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,17 @@ class PrunedLiveBlocks {
198198
assert(!discoveredBlocks || discoveredBlocks->empty());
199199
}
200200

201+
PrunedLiveBlocks(PrunedLiveBlocks const &other,
202+
SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr)
203+
: liveBlocks(other.liveBlocks.getFunction(), 2),
204+
discoveredBlocks(discoveredBlocks) {
205+
assert(!discoveredBlocks || other.discoveredBlocks);
206+
for (auto &block : *other.liveBlocks.getFunction()) {
207+
liveBlocks.set(&block, other.liveBlocks.get(&block));
208+
}
209+
initializedFlag = other.initializedFlag;
210+
}
211+
201212
bool isInitialized() const { return initializedFlag; }
202213

203214
void initializeDiscoveredBlocks(
@@ -361,6 +372,10 @@ class PrunedLiveness {
361372
SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr)
362373
: liveBlocks(function, discoveredBlocks) {}
363374

375+
PrunedLiveness(PrunedLiveness const &other,
376+
SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr)
377+
: liveBlocks(other.liveBlocks, discoveredBlocks), users(other.users) {}
378+
364379
bool isInitialized() const { return liveBlocks.isInitialized(); }
365380

366381
bool empty() const { return users.empty(); }
@@ -529,6 +544,10 @@ class PrunedLiveRange : public PrunedLiveness {
529544
SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr)
530545
: PrunedLiveness(function, discoveredBlocks) {}
531546

547+
PrunedLiveRange(PrunedLiveRange const &other,
548+
SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr)
549+
: PrunedLiveness(other, discoveredBlocks) {}
550+
532551
LiveRangeSummary recursivelyUpdateForDef(SILValue initialDef,
533552
ValueSet &visited,
534553
SILValue value);
@@ -626,6 +645,14 @@ class SSAPrunedLiveness : public PrunedLiveRange<SSAPrunedLiveness> {
626645
SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr)
627646
: PrunedLiveRange(function, discoveredBlocks) {}
628647

648+
SSAPrunedLiveness(
649+
SSAPrunedLiveness const &other,
650+
SmallVectorImpl<SILBasicBlock *> *discoveredBlocks = nullptr)
651+
: PrunedLiveRange(other, discoveredBlocks) {
652+
def = other.def;
653+
defInst = other.defInst;
654+
}
655+
629656
SILValue getDef() const { return def; }
630657

631658
void initializeDef(SILValue def) {

0 commit comments

Comments
 (0)