Skip to content

Commit fb49c67

Browse files
authored
[clang][bytecode] Move Pointer::{Prev,Next} into BlockPointer (#151097)
They are only relevant for block pointers.
1 parent e50bd78 commit fb49c67

File tree

6 files changed

+34
-30
lines changed

6 files changed

+34
-30
lines changed

clang/lib/AST/ByteCode/Disasm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ LLVM_DUMP_METHOD void Block::dump(llvm::raw_ostream &OS) const {
531531
Desc->dump(OS);
532532
OS << ")\n";
533533
unsigned NPointers = 0;
534-
for (const Pointer *P = Pointers; P; P = P->Next) {
534+
for (const Pointer *P = Pointers; P; P = P->asBlockPointer().Next) {
535535
++NPointers;
536536
}
537537
OS << " EvalID: " << EvalID << '\n';

clang/lib/AST/ByteCode/DynamicAllocator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void DynamicAllocator::cleanup() {
2727
B->invokeDtor();
2828
if (B->hasPointers()) {
2929
while (B->Pointers) {
30-
Pointer *Next = B->Pointers->Next;
30+
Pointer *Next = B->Pointers->asBlockPointer().Next;
3131
B->Pointers->PointeeStorage.BS.Pointee = nullptr;
3232
B->Pointers = Next;
3333
}

clang/lib/AST/ByteCode/InterpBlock.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ void Block::addPointer(Pointer *P) {
2727
assert(!hasPointer(P));
2828
#endif
2929
if (Pointers)
30-
Pointers->Prev = P;
31-
P->Next = Pointers;
32-
P->Prev = nullptr;
30+
Pointers->PointeeStorage.BS.Prev = P;
31+
P->PointeeStorage.BS.Next = Pointers;
32+
P->PointeeStorage.BS.Prev = nullptr;
3333
Pointers = P;
3434
#ifndef NDEBUG
3535
assert(hasPointer(P));
@@ -48,13 +48,15 @@ void Block::removePointer(Pointer *P) {
4848
assert(hasPointer(P));
4949
#endif
5050

51+
BlockPointer &BP = P->PointeeStorage.BS;
52+
5153
if (Pointers == P)
52-
Pointers = P->Next;
54+
Pointers = BP.Next;
5355

54-
if (P->Prev)
55-
P->Prev->Next = P->Next;
56-
if (P->Next)
57-
P->Next->Prev = P->Prev;
56+
if (BP.Prev)
57+
BP.Prev->PointeeStorage.BS.Next = BP.Next;
58+
if (BP.Next)
59+
BP.Next->PointeeStorage.BS.Prev = BP.Prev;
5860
P->PointeeStorage.BS.Pointee = nullptr;
5961
#ifndef NDEBUG
6062
assert(!hasPointer(P));
@@ -68,7 +70,9 @@ void Block::cleanup() {
6870

6971
void Block::replacePointer(Pointer *Old, Pointer *New) {
7072
assert(Old);
73+
assert(Old->isBlockPointer());
7174
assert(New);
75+
assert(New->isBlockPointer());
7276
assert(Old != New);
7377
if (IsStatic) {
7478
assert(!Pointers);
@@ -78,17 +82,20 @@ void Block::replacePointer(Pointer *Old, Pointer *New) {
7882
assert(hasPointer(Old));
7983
#endif
8084

81-
if (Old->Prev)
82-
Old->Prev->Next = New;
83-
if (Old->Next)
84-
Old->Next->Prev = New;
85-
New->Prev = Old->Prev;
86-
New->Next = Old->Next;
85+
BlockPointer &OldBP = Old->PointeeStorage.BS;
86+
BlockPointer &NewBP = New->PointeeStorage.BS;
87+
88+
if (OldBP.Prev)
89+
OldBP.Prev->PointeeStorage.BS.Next = New;
90+
if (OldBP.Next)
91+
OldBP.Next->PointeeStorage.BS.Prev = New;
92+
NewBP.Prev = OldBP.Prev;
93+
NewBP.Next = OldBP.Next;
8794
if (Pointers == Old)
8895
Pointers = New;
8996

90-
Old->PointeeStorage.BS.Pointee = nullptr;
91-
New->PointeeStorage.BS.Pointee = this;
97+
OldBP.Pointee = nullptr;
98+
NewBP.Pointee = this;
9299
#ifndef NDEBUG
93100
assert(!hasPointer(Old));
94101
assert(hasPointer(New));
@@ -97,7 +104,7 @@ void Block::replacePointer(Pointer *Old, Pointer *New) {
97104

98105
#ifndef NDEBUG
99106
bool Block::hasPointer(const Pointer *P) const {
100-
for (const Pointer *C = Pointers; C; C = C->Next) {
107+
for (const Pointer *C = Pointers; C; C = C->asBlockPointer().Next) {
101108
if (C == P)
102109
return true;
103110
}
@@ -120,7 +127,7 @@ DeadBlock::DeadBlock(DeadBlock *&Root, Block *Blk)
120127

121128
// Transfer pointers.
122129
B.Pointers = Blk->Pointers;
123-
for (Pointer *P = Blk->Pointers; P; P = P->Next)
130+
for (Pointer *P = Blk->Pointers; P; P = P->asBlockPointer().Next)
124131
P->PointeeStorage.BS.Pointee = &B;
125132
Blk->Pointers = nullptr;
126133
}

clang/lib/AST/ByteCode/InterpState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void InterpState::cleanup() {
5252
// As a last resort, make sure all pointers still pointing to a dead block
5353
// don't point to it anymore.
5454
for (DeadBlock *DB = DeadBlocks; DB; DB = DB->Next) {
55-
for (Pointer *P = DB->B.Pointers; P; P = P->Next) {
55+
for (Pointer *P = DB->B.Pointers; P; P = P->asBlockPointer().Next) {
5656
P->PointeeStorage.BS.Pointee = nullptr;
5757
}
5858
}

clang/lib/AST/ByteCode/Pointer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Pointer::Pointer(Block *Pointee, unsigned Base, uint64_t Offset)
4242
: Offset(Offset), StorageKind(Storage::Block) {
4343
assert((Base == RootPtrMark || Base % alignof(void *) == 0) && "wrong base");
4444

45-
PointeeStorage.BS = {Pointee, Base};
45+
PointeeStorage.BS = {Pointee, Base, nullptr, nullptr};
4646

4747
if (Pointee)
4848
Pointee->addPointer(this);
@@ -89,7 +89,6 @@ Pointer &Pointer::operator=(const Pointer &P) {
8989

9090
if (P.isBlockPointer()) {
9191
PointeeStorage.BS = P.PointeeStorage.BS;
92-
PointeeStorage.BS.Pointee = P.PointeeStorage.BS.Pointee;
9392

9493
if (PointeeStorage.BS.Pointee)
9594
PointeeStorage.BS.Pointee->addPointer(this);
@@ -127,7 +126,6 @@ Pointer &Pointer::operator=(Pointer &&P) {
127126

128127
if (P.isBlockPointer()) {
129128
PointeeStorage.BS = P.PointeeStorage.BS;
130-
PointeeStorage.BS.Pointee = P.PointeeStorage.BS.Pointee;
131129

132130
if (PointeeStorage.BS.Pointee)
133131
PointeeStorage.BS.Pointee->addPointer(this);

clang/lib/AST/ByteCode/Pointer.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ struct BlockPointer {
3939
Block *Pointee;
4040
/// Start of the current subfield.
4141
unsigned Base;
42+
/// Previous link in the pointer chain.
43+
Pointer *Prev;
44+
/// Next link in the pointer chain.
45+
Pointer *Next;
4246
};
4347

4448
struct IntPointer {
@@ -832,15 +836,10 @@ class Pointer {
832836
/// Offset into the storage.
833837
uint64_t Offset = 0;
834838

835-
/// Previous link in the pointer chain.
836-
Pointer *Prev = nullptr;
837-
/// Next link in the pointer chain.
838-
Pointer *Next = nullptr;
839-
840839
Storage StorageKind = Storage::Int;
841840
union {
842-
BlockPointer BS;
843841
IntPointer Int;
842+
BlockPointer BS;
844843
FunctionPointer Fn;
845844
TypeidPointer Typeid;
846845
} PointeeStorage;

0 commit comments

Comments
 (0)