Skip to content

Commit 6e50329

Browse files
committedApr 21, 2013
remove the cleanups list from CallEmission and ManagedValue, along with the machinery for adding Cleanups.
Swift SVN r4840
1 parent e3d6a48 commit 6e50329

9 files changed

+11
-158
lines changed
 

‎lib/IRGen/CallEmission.h

-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ class CallEmission {
3838
/// The builtin/special arguments to pass to the call.
3939
llvm::SmallVector<llvm::Value*, 8> Args;
4040

41-
/// The cleanups to deactivate when we make a call.
42-
llvm::SmallVector<CleanupsDepth, 8> Cleanups;
43-
4441
/// The function we're going to call.
4542
Callee CurCallee;
4643

‎lib/IRGen/Cleanup.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ class Cleanup {
3030
unsigned AllocatedSize;
3131
unsigned State : 2;
3232

33-
friend Cleanup &IRGenFunction::initCleanup(Cleanup &, size_t, CleanupState);
34-
protected:
33+
protected:
3534
Cleanup() {}
3635
virtual ~Cleanup() {}
37-
// The fields are initialized by IRGenFunction::initCleanup.
3836

3937
public:
4038
/// Return the allocated size of this object. This is required by

‎lib/IRGen/Explosion.h

+4-15
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,24 @@ namespace irgen {
3333
/// cleanup.
3434
class ManagedValue {
3535
llvm::Value *Value;
36-
CleanupsDepth Cleanup;
3736

3837
public:
3938
ManagedValue() = default;
4039
explicit ManagedValue(llvm::Value *value)
41-
: Value(value), Cleanup(CleanupsDepth::invalid()) {}
40+
: Value(value) {}
4241
ManagedValue(llvm::Value *value, CleanupsDepth cleanup)
43-
: Value(value), Cleanup(cleanup) {}
42+
: Value(value) {}
4443

4544
llvm::Value *getUnmanagedValue() const {
46-
assert(!hasCleanup());
4745
return getValue();
4846
}
4947
llvm::Value *getValue() const { return Value; }
5048

51-
bool hasCleanup() const { return Cleanup.isValid(); }
52-
CleanupsDepth getCleanup() const { return Cleanup; }
53-
49+
bool hasCleanup() const { return false; }
50+
5451
/// Forward this value, deactivating the cleanup and returning the
5552
/// underlying value.
5653
llvm::Value *forward(IRGenFunction &IGF) {
57-
if (hasCleanup())
58-
IGF.setCleanupState(getCleanup(), CleanupState::Dead);
59-
return getValue();
60-
}
61-
62-
/// Split this value into its underlying value and, if present, its cleanup.
63-
llvm::Value *split(llvm::SmallVectorImpl<CleanupsDepth> &cleanups) {
64-
if (hasCleanup()) cleanups.push_back(getCleanup());
6554
return getValue();
6655
}
6756
};

‎lib/IRGen/GenControl.cpp

-42
Original file line numberDiff line numberDiff line change
@@ -82,47 +82,5 @@ llvm::CallSite IRGenFunction::emitInvoke(llvm::CallingConv::ID convention,
8282
//****************************************************************************//
8383

8484

85-
86-
/// Remove all the dead cleanups on the top of the cleanup stack.
87-
static void popAndEmitTopDeadCleanups(IRGenFunction &IGF,
88-
DiverseStackImpl<Cleanup> &stack,
89-
CleanupsDepth end) {
90-
stack.checkIterator(end);
91-
92-
while (stack.stable_begin() != end && stack.begin()->isDead()) {
93-
assert(!stack.empty());
94-
95-
// We might get better results popping them all at once.
96-
stack.pop();
97-
stack.checkIterator(end);
98-
}
99-
}
100-
101-
/// Leave a scope, with all its cleanups.
102-
void IRGenFunction::endScope(CleanupsDepth depth) {
103-
Cleanups.checkIterator(depth);
104-
105-
popAndEmitTopDeadCleanups(*this, Cleanups, InnermostScope);
106-
}
107-
108-
109-
/// Initialize a just-pushed cleanup.
110-
Cleanup &IRGenFunction::initCleanup(Cleanup &cleanup, size_t allocSize,
111-
CleanupState state) {
112-
cleanup.AllocatedSize = allocSize;
113-
cleanup.State = unsigned(state);
114-
115-
return cleanup;
116-
}
117-
118-
/// Change the state of a cleanup.
119-
void IRGenFunction::setCleanupState(CleanupsDepth depth,
120-
CleanupState newState) {
121-
}
122-
123-
void IRGenFunction::setCleanupState(Cleanup &cleanup, CleanupState newState) {
124-
cleanup.setState(newState);
125-
}
126-
12785
// Anchor the Cleanup v-table in this translation unit.
12886
void Cleanup::_anchor() {}

‎lib/IRGen/GenFunc.cpp

+2-18
Original file line numberDiff line numberDiff line change
@@ -1254,11 +1254,6 @@ llvm::CallSite CallEmission::emitCallSite(bool hasIndirectResult) {
12541254
assert(!EmittedCall);
12551255
EmittedCall = true;
12561256

1257-
// Deactivate all the cleanups.
1258-
for (auto cleanup : Cleanups)
1259-
IGF.setCleanupState(cleanup, CleanupState::Dead);
1260-
Cleanups.clear();
1261-
12621257
// Determine the calling convention.
12631258
// FIXME: collect attributes in the CallEmission.
12641259
auto cc = expandAbstractCC(IGF.IGM, getCallee().getConvention());
@@ -1374,8 +1369,6 @@ void CallEmission::emitToExplosion(Explosion &out) {
13741369
// Otherwise, we need to load. Do a take-load and deactivate the cleanup.
13751370
} else {
13761371
substResultTI.loadAsTake(IGF, temp, out);
1377-
if (cleanup.isValid())
1378-
IGF.setCleanupState(cleanup, CleanupState::Dead);
13791372
}
13801373
return;
13811374
}
@@ -1419,7 +1412,6 @@ void CallEmission::emitToExplosion(Explosion &out) {
14191412
CallEmission::CallEmission(CallEmission &&other)
14201413
: IGF(other.IGF),
14211414
Args(std::move(other.Args)),
1422-
Cleanups(std::move(other.Cleanups)),
14231415
CurCallee(std::move(other.CurCallee)),
14241416
CurOrigType(other.CurOrigType),
14251417
RemainingArgsForCallee(other.RemainingArgsForCallee),
@@ -1458,13 +1450,10 @@ void CallEmission::setFromCallee() {
14581450
Args.set_size(numArgs);
14591451
LastArgWritten = numArgs;
14601452

1461-
// We should not have any cleanups at this point.
1462-
assert(Cleanups.empty());
1463-
14641453
// Add the data pointer if we have one.
14651454
if (CurCallee.hasDataPointer()) {
14661455
assert(LastArgWritten > 0);
1467-
Args[--LastArgWritten] = CurCallee.getDataPointer(IGF).split(Cleanups);
1456+
Args[--LastArgWritten] = CurCallee.getDataPointer(IGF).getValue();
14681457
}
14691458
}
14701459

@@ -1645,7 +1634,7 @@ void CallEmission::addArg(Explosion &arg) {
16451634
auto value = values[i];
16461635
// The default rule is that arguments are consumed, in which case
16471636
// we need to deactivate cleanups when making the call.
1648-
*argIterator++ = value.split(Cleanups);
1637+
*argIterator++ = value.getValue();
16491638
}
16501639

16511640
LastArgWritten = newLastArgWritten;
@@ -1862,11 +1851,6 @@ bool IRGenFunction::emitBranchToReturnBB() {
18621851

18631852
/// Emit the epilogue for the function.
18641853
void IRGenFunction::emitEpilogue() {
1865-
// Leave the cleanups created for the parameters if we've got a full
1866-
// prologue.
1867-
if (CurPrologue != Prologue::Bare)
1868-
endScope(Cleanups.stable_end());
1869-
18701854
// Destroy the alloca insertion point.
18711855
AllocaIP->eraseFromParent();
18721856

‎lib/IRGen/GenInit.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -160,22 +160,10 @@ OwnedAddress FixedTypeInfo::allocate(IRGenFunction &IGF, Initialization &init,
160160
return addr;
161161
}
162162

163-
static void maybeSetCleanupState(IRGenFunction &IGF,
164-
CleanupsDepth maybeCleanup,
165-
CleanupState newState) {
166-
if (maybeCleanup.isValid())
167-
IGF.setCleanupState(maybeCleanup, newState);
168-
}
169163

170164
/// Mark that a value has reached its initialization point.
171165
void Initialization::markInitialized(IRGenFunction &IGF,
172166
InitializedObject object) {
173167
auto it = Records.find(object.Opaque);
174168
assert(it != Records.end());
175-
176-
// Deactivate the dealloc cleanup.
177-
maybeSetCleanupState(IGF, it->second.DeallocCleanup, CleanupState::Dead);
178-
179-
// Activate the destroy cleanup.
180-
maybeSetCleanupState(IGF, it->second.DestroyCleanup, CleanupState::Active);
181169
}

‎lib/IRGen/GenPoly.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ namespace {
392392
auto addr = IGF.Builder.CreateBitCast(inValue.getValue(),
393393
IGF.IGM.OpaquePtrTy,
394394
"substitution.reinterpret");
395-
Out.add(ManagedValue(addr, inValue.getCleanup()));
395+
Out.add(ManagedValue(addr));
396396
return;
397397
}
398398

@@ -470,7 +470,7 @@ namespace {
470470
auto origValue =
471471
IGF.Builder.CreateBitCast(substValue, origPtrTy,
472472
substValue->getName() + ".reinterpret");
473-
Out.add(ManagedValue(origValue, substMV.getCleanup()));
473+
Out.add(ManagedValue(origValue));
474474
}
475475

476476
void visitMetaTypeType(MetaTypeType *origTy, MetaTypeType *substTy) {
@@ -554,15 +554,13 @@ namespace {
554554
// If the substituted type is still a single indirect value,
555555
// just pass it on without reinterpretation.
556556
if (IGF.IGM.isSingleIndirectValue(substTy, In.getKind())) {
557-
Out.add(ManagedValue(inAddr, inValue.getCleanup()));
557+
Out.add(ManagedValue(inAddr));
558558
return;
559559
}
560560

561561
// Otherwise, load as a take and then kill the cleanup attached
562562
// to the archetype value.
563563
substTI.loadAsTake(IGF, substTI.getAddressForPointer(inAddr), Out);
564-
if (inValue.hasCleanup())
565-
IGF.setCleanupState(inValue.getCleanup(), CleanupState::Dead);
566564
}
567565

568566
void visitArrayType(ArrayType *origTy, ArrayType *substTy) {
@@ -616,7 +614,7 @@ namespace {
616614
auto substValue =
617615
IGF.Builder.CreateBitCast(origValue, substPtrTy,
618616
origValue->getName() + ".reinterpret");
619-
Out.add(ManagedValue(substValue, origMV.getCleanup()));
617+
Out.add(ManagedValue(substValue));
620618
}
621619

622620
void visitMetaTypeType(MetaTypeType *origTy, MetaTypeType *substTy) {

‎lib/IRGen/IRGenFunction.h

-58
Original file line numberDiff line numberDiff line change
@@ -137,66 +137,11 @@ class IRGenFunction {
137137
//--- Control flow -------------------------------------------------------------
138138
public:
139139

140-
/// Push a new cleanup in the current scope.
141-
template <class T, class... A>
142-
T &pushCleanup(A &&... args) {
143-
return pushCleanupInState<T, A...>(CleanupState::Active,
144-
::std::forward<A>(args)...);
145-
}
146-
147-
/// Push a new cleanup in the current scope.
148-
template <class T, class... A>
149-
T &pushCleanupInState(CleanupState state, A &&... args) {
150-
assert(state != CleanupState::Dead);
151-
152-
#ifndef NDEBUG
153-
CleanupsDepth oldTop = Cleanups.stable_begin();
154-
#endif
155-
156-
T &cleanup = Cleanups.push<T, A...>(::std::forward<A>(args)...);
157-
T &result = static_cast<T&>(initCleanup(cleanup, sizeof(T), state));
158-
159-
#ifndef NDEBUG
160-
auto newTop = Cleanups.begin(); ++newTop;
161-
assert(newTop == Cleanups.find(oldTop));
162-
#endif
163-
return result;
164-
}
165-
166-
/// Push a new cleanup which is expected to be destroyed at the end
167-
/// of the current full-expression.
168-
///
169-
/// The relevant property here is that full-expression cleanups may
170-
/// not be dominated by the locations in which they're active in a
171-
/// full-expression expression.
172-
template <class T, class... A>
173-
T &pushFullExprCleanup(A &&... args) {
174-
assert(!isConditionallyEvaluated());
175-
return pushCleanup<T, A...>(::std::forward<A>(args)...);
176-
}
177-
178-
template <class T, class... A>
179-
T &pushFullExprCleanupInState(CleanupState state, A &&... args) {
180-
assert(!isConditionallyEvaluated());
181-
return pushCleanupInState<T, A...>(state, ::std::forward<A>(args)...);
182-
}
183-
184140
/// Return a stable reference to the current cleanup.
185141
CleanupsDepth getCleanupsDepth() const {
186142
return Cleanups.stable_begin();
187143
}
188144

189-
/// Set the state of the cleanup at the given depth.
190-
/// The transition must be non-trivial and legal.
191-
void setCleanupState(CleanupsDepth depth, CleanupState state);
192-
193-
Cleanup &findCleanup(CleanupsDepth depth) {
194-
assert(depth != Cleanups.stable_end());
195-
return *Cleanups.find(depth);
196-
}
197-
198-
void endScope(CleanupsDepth depth);
199-
200145
void enterDestroyCleanup(Address addr, const TypeInfo &addrTI,
201146
Explosion &out);
202147

@@ -219,10 +164,7 @@ class IRGenFunction {
219164
llvm::Instruction *JumpDestSlot;
220165
CleanupsDepth InnermostScope;
221166

222-
friend class Cleanup; // just so that it can befriend initCleanup
223167
friend class Scope;
224-
Cleanup &initCleanup(Cleanup &cleanup, size_t allocSize, CleanupState state);
225-
void setCleanupState(Cleanup &cleanup, CleanupState state);
226168

227169
//--- Function prologue and epilogue -------------------------------------------
228170
public:

‎lib/IRGen/Scope.h

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class Scope {
3636
assert(IGF.InnermostScope == Depth && "popping scopes out of order");
3737

3838
IGF.InnermostScope = SavedInnermostScope;
39-
IGF.endScope(Depth);
4039
IGF.Cleanups.checkIterator(IGF.InnermostScope);
4140

4241
assert(IGF.ScopedLocalTypeData.size() >= SavedLocalTypeDataDepth);

0 commit comments

Comments
 (0)
Please sign in to comment.