Skip to content

Commit 4078157

Browse files
committed
SIL: change way how a SILInstruction is marked as deleted
Instead of setting the parent pointer to null, set the `lastInitializedBitfieldID` to -1. This allows to keep the parent block information, even when an instruction is removed from it's list.
1 parent 09252cc commit 4078157

File tree

9 files changed

+20
-17
lines changed

9 files changed

+20
-17
lines changed

include/swift/SIL/SILBasicBlock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public SwiftObjectHeader {
8585
/// DD and EEE are uninitialized
8686
///
8787
/// See also: SILBitfield::bitfieldID, SILFunction::currentBitfieldID.
88-
uint64_t lastInitializedBitfieldID = 0;
88+
int64_t lastInitializedBitfieldID = 0;
8989

9090
// Used by `BasicBlockBitfield`.
9191
unsigned getCustomBits() const { return customBits; }

include/swift/SIL/SILBitfield.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ template <class Impl, class T> class SILBitfield {
3030
/// that the bits of that block are not initialized yet.
3131
/// See also: SILBasicBlock::lastInitializedBitfieldID,
3232
/// SILFunction::currentBitfieldID
33-
uint64_t bitfieldID;
33+
int64_t bitfieldID;
3434

3535
short startBit;
3636
short endBit;

include/swift/SIL/SILFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class SILFunction
266266
/// A monotonically increasing ID which is incremented whenever a
267267
/// BasicBlockBitfield or NodeBitfield is constructed.
268268
/// For details see SILBitfield::bitfieldID;
269-
uint64_t currentBitfieldID = 1;
269+
int64_t currentBitfieldID = 1;
270270

271271
/// Unique identifier for vector indexing and deterministic sorting.
272272
/// May be reused when zombie functions are recovered.

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
391391

392392
/// Returns true if this instruction is removed from its function and
393393
/// scheduled to be deleted.
394-
bool isDeleted() const { return !ParentBB; }
394+
bool isDeleted() const { return asSILNode()->isMarkedAsDeleted(); }
395395

396396
enum class MemoryBehavior {
397397
None,
@@ -10138,7 +10138,6 @@ struct ilist_traits<::swift::SILInstruction> :
1013810138
}
1013910139

1014010140
void addNodeToList(SILInstruction *I);
10141-
void removeNodeFromList(SILInstruction *I);
1014210141
void transferNodesFromList(ilist_traits<SILInstruction> &L2,
1014310142
instr_iterator first, instr_iterator last);
1014410143

include/swift/SIL/SILNode.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,13 @@ class alignas(8) SILNode :
330330
/// -> AAA, BB and C are initialized,
331331
/// DD and EEE are uninitialized
332332
///
333+
/// If the ID is negative, it means that the node (in case it's an instruction)
334+
/// is deleted, i.e. it does not belong to the function anymore. Conceptually
335+
/// this results in setting all bitfields to zero, which e.g. "removes" the
336+
/// node from all NodeSets.
337+
///
333338
/// See also: SILBitfield::bitfieldID, SILFunction::currentBitfieldID.
334-
uint64_t lastInitializedBitfieldID = 0;
339+
int64_t lastInitializedBitfieldID = 0;
335340

336341
private:
337342
SwiftMetatype getSILNodeMetatype(SILNodeKind kind);
@@ -389,6 +394,12 @@ class alignas(8) SILNode :
389394
lastInitializedBitfieldID = 0;
390395
}
391396

397+
void markAsDeleted() {
398+
lastInitializedBitfieldID = -1;
399+
}
400+
401+
bool isMarkedAsDeleted() const { return lastInitializedBitfieldID < 0; }
402+
392403
static SILNode *instAsNode(SILInstruction *inst);
393404
static const SILNode *instAsNode(const SILInstruction *inst);
394405

lib/SIL/IR/SILBasicBlock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ void SILBasicBlock::erase(SILInstruction *I) {
103103
}
104104

105105
void SILBasicBlock::erase(SILInstruction *I, SILModule &module) {
106+
assert(!I->isDeleted() && "double delete of instruction");
106107
module.willDeleteInstruction(I);
107108
InstList.remove(I);
109+
I->asSILNode()->markAsDeleted();
108110
module.scheduleForDeletion(I);
109111
}
110112

@@ -113,13 +115,11 @@ void SILBasicBlock::moveInstruction(SILInstruction *inst,
113115
if (inst == beforeInst)
114116
return;
115117
inst->getParent()->InstList.remove(inst);
116-
inst->ParentBB = nullptr;
117118
beforeInst->getParent()->insert(beforeInst->getIterator(), inst);
118119
}
119120

120121
void SILBasicBlock::moveInstructionToFront(SILInstruction *inst) {
121122
inst->getParent()->InstList.remove(inst);
122-
inst->ParentBB = nullptr;
123123
push_front(inst);
124124
}
125125

lib/SIL/IR/SILInstruction.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,9 @@ SILBasicBlock *llvm::ilist_traits<SILInstruction>::getContainingBlock() {
6161

6262

6363
void llvm::ilist_traits<SILInstruction>::addNodeToList(SILInstruction *I) {
64-
assert(I->ParentBB == nullptr && "Already in a list!");
6564
I->ParentBB = getContainingBlock();
6665
}
6766

68-
void llvm::ilist_traits<SILInstruction>::removeNodeFromList(SILInstruction *I) {
69-
// When an instruction is removed from a BB, clear the parent pointer.
70-
I->ParentBB = nullptr;
71-
}
72-
7367
void llvm::ilist_traits<SILInstruction>::
7468
transferNodesFromList(llvm::ilist_traits<SILInstruction> &L2,
7569
instr_iterator first, instr_iterator last) {

lib/SIL/IR/SILModule.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ void SILModule::willDeleteInstruction(SILInstruction *I) {
276276
void SILModule::scheduleForDeletion(SILInstruction *I) {
277277
I->dropAllReferences();
278278
scheduledForDeletion.push_back(I);
279-
I->ParentBB = nullptr;
280279
}
281280

282281
void SILModule::flushDeletedInsts() {

unittests/SIL/SILBitfieldTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class BasicBlockBitfield;
2121

2222
struct SILFunction {
2323
BasicBlockBitfield *newestAliveBlockBitfield = nullptr;
24-
uint64_t currentBitfieldID = 1;
24+
int64_t currentBitfieldID = 1;
2525
};
2626

2727
struct SILBasicBlock {
2828
SILFunction *function;
2929
uint32_t customBits = 0;
30-
uint64_t lastInitializedBitfieldID = 0;
30+
int64_t lastInitializedBitfieldID = 0;
3131

3232
enum { numCustomBits = 32 };
3333

0 commit comments

Comments
 (0)