Skip to content

Commit cfeb4b1

Browse files
authored
Merge pull request #8128 from gottesmm/small_standardization_gardening
2 parents 5da7e50 + 16c67f5 commit cfeb4b1

File tree

5 files changed

+153
-155
lines changed

5 files changed

+153
-155
lines changed

lib/SILGen/Cleanup.cpp

Lines changed: 81 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "Cleanup.h"
1414
#include "SILGenFunction.h"
15+
1516
using namespace swift;
1617
using namespace Lowering;
1718

@@ -28,34 +29,34 @@ namespace {
2829
/// A CleanupBuffer is a location to which to temporarily copy a
2930
/// cleanup.
3031
class CleanupBuffer {
31-
SmallVector<char, sizeof(Cleanup) + 10 * sizeof(void*)> Data;
32-
32+
SmallVector<char, sizeof(Cleanup) + 10 * sizeof(void *)> data;
33+
3334
public:
3435
CleanupBuffer(const Cleanup &cleanup) {
3536
size_t size = cleanup.allocated_size();
36-
Data.set_size(size);
37-
memcpy(Data.data(), reinterpret_cast<const void*>(&cleanup), size);
37+
data.set_size(size);
38+
memcpy(data.data(), reinterpret_cast<const void *>(&cleanup), size);
3839
}
39-
40-
Cleanup &getCopy() { return *reinterpret_cast<Cleanup*>(Data.data()); }
40+
41+
Cleanup &getCopy() { return *reinterpret_cast<Cleanup *>(data.data()); }
4142
};
4243
} // end anonymous namespace
4344

4445
void CleanupManager::popTopDeadCleanups(CleanupsDepth end) {
45-
Stack.checkIterator(end);
46+
stack.checkIterator(end);
4647

47-
while (Stack.stable_begin() != end && Stack.begin()->isDead()) {
48-
assert(!Stack.empty());
49-
Stack.pop();
50-
Stack.checkIterator(end);
48+
while (stack.stable_begin() != end && stack.begin()->isDead()) {
49+
assert(!stack.empty());
50+
stack.pop();
51+
stack.checkIterator(end);
5152
}
5253
}
5354

54-
void CleanupManager::emitCleanups(CleanupsDepth depth, CleanupLocation l,
55+
void CleanupManager::emitCleanups(CleanupsDepth depth, CleanupLocation loc,
5556
bool popCleanups) {
56-
auto begin = Stack.stable_begin();
57+
auto begin = stack.stable_begin();
5758
while (begin != depth) {
58-
auto iter = Stack.find(begin);
59+
auto iter = stack.find(begin);
5960

6061
Cleanup &stackCleanup = *iter;
6162

@@ -65,78 +66,78 @@ void CleanupManager::emitCleanups(CleanupsDepth depth, CleanupLocation l,
6566
Cleanup &cleanup = buffer.getCopy();
6667

6768
// Advance stable iterator.
68-
begin = Stack.stabilize(++iter);
69+
begin = stack.stabilize(++iter);
6970

7071
// Pop now.
7172
if (popCleanups)
72-
Stack.pop();
73+
stack.pop();
7374

74-
if (cleanup.isActive() && Gen.B.hasValidInsertionPoint())
75-
cleanup.emit(Gen, l);
75+
if (cleanup.isActive() && SGF.B.hasValidInsertionPoint())
76+
cleanup.emit(SGF, loc);
7677

77-
Stack.checkIterator(begin);
78+
stack.checkIterator(begin);
7879
}
7980
}
8081

8182
/// Leave a scope, with all its cleanups.
82-
void CleanupManager::endScope(CleanupsDepth depth, CleanupLocation l) {
83-
Stack.checkIterator(depth);
84-
83+
void CleanupManager::endScope(CleanupsDepth depth, CleanupLocation loc) {
84+
stack.checkIterator(depth);
85+
8586
// FIXME: Thread a branch through the cleanups if there are any active
8687
// cleanups and we have a valid insertion point.
87-
88-
if (!::hasAnyActiveCleanups(Stack.begin(), Stack.find(depth))) {
88+
89+
if (!::hasAnyActiveCleanups(stack.begin(), stack.find(depth))) {
8990
return;
9091
}
9192

9293
// Iteratively mark cleanups dead and pop them.
9394
// Maybe we'd get better results if we marked them all dead in one shot?
94-
emitCleanups(depth, l);
95+
emitCleanups(depth, loc);
9596
}
9697

9798
bool CleanupManager::hasAnyActiveCleanups(CleanupsDepth from,
9899
CleanupsDepth to) {
99-
return ::hasAnyActiveCleanups(Stack.find(from), Stack.find(to));
100+
return ::hasAnyActiveCleanups(stack.find(from), stack.find(to));
100101
}
101102

102103
bool CleanupManager::hasAnyActiveCleanups(CleanupsDepth from) {
103-
return ::hasAnyActiveCleanups(Stack.begin(), Stack.find(from));
104+
return ::hasAnyActiveCleanups(stack.begin(), stack.find(from));
104105
}
105106

106107
/// emitBranchAndCleanups - Emit a branch to the given jump destination,
107108
/// threading out through any cleanups we might need to run. This does not
108109
/// pop the cleanup stack.
109-
void CleanupManager::emitBranchAndCleanups(JumpDest Dest,
110-
SILLocation BranchLoc,
111-
ArrayRef<SILValue> Args) {
112-
SILGenBuilder &B = Gen.getBuilder();
113-
assert(B.hasValidInsertionPoint() && "Emitting branch in invalid spot");
114-
emitCleanups(Dest.getDepth(), Dest.getCleanupLocation(), /*popCleanups=*/false);
115-
B.createBranch(BranchLoc, Dest.getBlock(), Args);
110+
void CleanupManager::emitBranchAndCleanups(JumpDest dest, SILLocation branchLoc,
111+
ArrayRef<SILValue> args) {
112+
SILGenBuilder &builder = SGF.getBuilder();
113+
assert(builder.hasValidInsertionPoint() && "Emitting branch in invalid spot");
114+
emitCleanups(dest.getDepth(), dest.getCleanupLocation(),
115+
/*popCleanups=*/false);
116+
builder.createBranch(branchLoc, dest.getBlock(), args);
116117
}
117118

118-
void CleanupManager::emitCleanupsForReturn(CleanupLocation Loc) {
119-
SILGenBuilder &B = Gen.getBuilder();
120-
assert(B.hasValidInsertionPoint() && "Emitting return in invalid spot");
121-
(void) B;
122-
emitCleanups(Stack.stable_end(), Loc, /*popCleanups=*/false);
119+
void CleanupManager::emitCleanupsForReturn(CleanupLocation loc) {
120+
SILGenBuilder &builder = SGF.getBuilder();
121+
assert(builder.hasValidInsertionPoint() && "Emitting return in invalid spot");
122+
(void)builder;
123+
emitCleanups(stack.stable_end(), loc, /*popCleanups=*/false);
123124
}
124125

125126
/// Emit a new block that jumps to the specified location and runs necessary
126127
/// cleanups based on its level. If there are no cleanups to run, this just
127128
/// returns the dest block.
128-
SILBasicBlock *CleanupManager::emitBlockForCleanups(JumpDest Dest,
129-
SILLocation BranchLoc,
130-
ArrayRef<SILValue> Args) {
129+
SILBasicBlock *CleanupManager::emitBlockForCleanups(JumpDest dest,
130+
SILLocation branchLoc,
131+
ArrayRef<SILValue> args) {
131132
// If there are no cleanups to run, just return the Dest block directly.
132-
if (!hasAnyActiveCleanups(Dest.getDepth()))
133-
return Dest.getBlock();
133+
if (!hasAnyActiveCleanups(dest.getDepth()))
134+
return dest.getBlock();
134135

135136
// Otherwise, create and emit a new block.
136-
auto *NewBB = Gen.createBasicBlock();
137-
SavedInsertionPoint IPRAII(Gen, NewBB);
138-
emitBranchAndCleanups(Dest, BranchLoc, Args);
139-
return NewBB;
137+
auto *newBlock = SGF.createBasicBlock();
138+
SavedInsertionPoint IPRAII(SGF, newBlock);
139+
emitBranchAndCleanups(dest, branchLoc, args);
140+
return newBlock;
140141
}
141142

142143

@@ -149,17 +150,17 @@ Cleanup &CleanupManager::initCleanup(Cleanup &cleanup,
149150
}
150151

151152
void CleanupManager::setCleanupState(CleanupsDepth depth, CleanupState state) {
152-
auto iter = Stack.find(depth);
153-
assert(iter != Stack.end() && "can't change end of cleanups stack");
153+
auto iter = stack.find(depth);
154+
assert(iter != stack.end() && "can't change end of cleanups stack");
154155
setCleanupState(*iter, state);
155-
156-
if (state == CleanupState::Dead && iter == Stack.begin())
157-
popTopDeadCleanups(InnermostScope);
156+
157+
if (state == CleanupState::Dead && iter == stack.begin())
158+
popTopDeadCleanups(innermostScope);
158159
}
159160

160161
void CleanupManager::forwardCleanup(CleanupsDepth handle) {
161-
auto iter = Stack.find(handle);
162-
assert(iter != Stack.end() && "can't change end of cleanups stack");
162+
auto iter = stack.find(handle);
163+
assert(iter != stack.end() && "can't change end of cleanups stack");
163164
Cleanup &cleanup = *iter;
164165
assert(cleanup.isActive() && "forwarding inactive or dead cleanup?");
165166

@@ -168,18 +169,18 @@ void CleanupManager::forwardCleanup(CleanupsDepth handle) {
168169
: CleanupState::Dormant);
169170
setCleanupState(cleanup, newState);
170171

171-
if (newState == CleanupState::Dead && iter == Stack.begin())
172-
popTopDeadCleanups(InnermostScope);
172+
if (newState == CleanupState::Dead && iter == stack.begin())
173+
popTopDeadCleanups(innermostScope);
173174
}
174175

175176
void CleanupManager::setCleanupState(Cleanup &cleanup, CleanupState state) {
176-
assert(Gen.B.hasValidInsertionPoint() &&
177+
assert(SGF.B.hasValidInsertionPoint() &&
177178
"changing cleanup state at invalid IP");
178179

179180
// Do the transition now to avoid doing it in N places below.
180181
CleanupState oldState = cleanup.getState();
181182
(void)oldState;
182-
cleanup.setState(Gen, state);
183+
cleanup.setState(SGF, state);
183184

184185
assert(state != oldState && "trivial cleanup state change");
185186
assert(oldState != CleanupState::Dead && "changing state of dead cleanup");
@@ -194,45 +195,46 @@ void CleanupStateRestorationScope::pushCleanupState(CleanupHandle handle,
194195
// Don't put the cleanup in a state we can't restore it from.
195196
assert(newState != CleanupState::Dead && "cannot restore cleanup from death");
196197

197-
auto iter = Cleanups.Stack.find(handle);
198-
assert(iter != Cleanups.Stack.end() && "can't change end of cleanups stack");
198+
auto iter = cleanups.stack.find(handle);
199+
assert(iter != cleanups.stack.end() && "can't change end of cleanups stack");
199200
Cleanup &cleanup = *iter;
200201
assert(cleanup.getState() != CleanupState::Dead &&
201202
"changing state of dead cleanup");
202203

203204
CleanupState oldState = cleanup.getState();
204-
cleanup.setState(Cleanups.Gen, newState);
205+
cleanup.setState(cleanups.SGF, newState);
205206

206-
SavedStates.push_back({handle, oldState});
207+
savedStates.push_back({handle, oldState});
207208
}
208209

209210
void
210211
CleanupStateRestorationScope::pushCurrentCleanupState(CleanupHandle handle) {
211-
auto iter = Cleanups.Stack.find(handle);
212-
assert(iter != Cleanups.Stack.end() && "can't change end of cleanups stack");
212+
auto iter = cleanups.stack.find(handle);
213+
assert(iter != cleanups.stack.end() && "can't change end of cleanups stack");
213214
Cleanup &cleanup = *iter;
214215
assert(cleanup.getState() != CleanupState::Dead &&
215216
"changing state of dead cleanup");
216217

217218
CleanupState oldState = cleanup.getState();
218-
SavedStates.push_back({handle, oldState});
219+
savedStates.push_back({handle, oldState});
219220
}
220221

221222
void CleanupStateRestorationScope::popImpl() {
222223
// Restore cleanup states in the opposite order in which we saved them.
223-
for (auto i = SavedStates.rbegin(), e = SavedStates.rend(); i != e; ++i) {
224+
for (auto i = savedStates.rbegin(), e = savedStates.rend(); i != e; ++i) {
224225
CleanupHandle handle = i->first;
225226
CleanupState stateToRestore = i->second;
226227

227-
auto iter = Cleanups.Stack.find(handle);
228-
assert(iter != Cleanups.Stack.end() && "can't change end of cleanups stack");
228+
auto iter = cleanups.stack.find(handle);
229+
assert(iter != cleanups.stack.end() &&
230+
"can't change end of cleanups stack");
229231
Cleanup &cleanup = *iter;
230232
assert(cleanup.getState() != CleanupState::Dead &&
231233
"changing state of dead cleanup");
232-
cleanup.setState(Cleanups.Gen, stateToRestore);
234+
cleanup.setState(cleanups.SGF, stateToRestore);
233235
}
234236

235-
SavedStates.clear();
237+
savedStates.clear();
236238
}
237239

238240
void CleanupStateRestorationScope::pop() && { popImpl(); }
@@ -255,22 +257,22 @@ llvm::raw_ostream &Lowering::operator<<(llvm::raw_ostream &os,
255257

256258
void CleanupManager::dump() const {
257259
#ifndef NDEBUG
258-
auto begin = Stack.stable_begin();
259-
auto end = Stack.stable_end();
260+
auto begin = stack.stable_begin();
261+
auto end = stack.stable_end();
260262
while (begin != end) {
261-
auto iter = Stack.find(begin);
263+
auto iter = stack.find(begin);
262264
const Cleanup &stackCleanup = *iter;
263265
llvm::errs() << "CLEANUP DEPTH: " << begin.getDepth() << "\n";
264-
stackCleanup.dump(Gen);
265-
begin = Stack.stabilize(++iter);
266-
Stack.checkIterator(begin);
266+
stackCleanup.dump(SGF);
267+
begin = stack.stabilize(++iter);
268+
stack.checkIterator(begin);
267269
}
268270
#endif
269271
}
270272

271273
void CleanupManager::dump(CleanupHandle handle) const {
272-
auto iter = Stack.find(handle);
274+
auto iter = stack.find(handle);
273275
const Cleanup &stackCleanup = *iter;
274276
llvm::errs() << "CLEANUP DEPTH: " << handle.getDepth() << "\n";
275-
stackCleanup.dump(Gen);
277+
stackCleanup.dump(SGF);
276278
}

0 commit comments

Comments
 (0)