Skip to content

Commit 4526e88

Browse files
Xin TongXin Tong
authored andcommitted
Revert "Track dependencies of SIL instructions on opened archetypes which they use"
This reverts commit 8ef8bb4. Broke swift_tools-RA_stdlib-RD_test-no_device and soem others
1 parent 3dfa2ce commit 4526e88

29 files changed

+283
-1568
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 30 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "swift/SIL/SILDebugScope.h"
1717
#include "swift/SIL/SILFunction.h"
1818
#include "swift/SIL/SILModule.h"
19-
#include "swift/SIL/SILOpenedArchetypesTracker.h"
2019
#include "llvm/ADT/PointerUnion.h"
2120
#include "llvm/ADT/StringExtras.h"
2221

@@ -41,16 +40,6 @@ class SILBuilder {
4140
/// recorded in this list.
4241
SmallVectorImpl<SILInstruction *> *InsertedInstrs = nullptr;
4342

44-
/// An immutable view on the set of available opened archetypes.
45-
/// It is passed down to SILInstruction constructors and create
46-
/// methods.
47-
SILOpenedArchetypesState OpenedArchetypes;
48-
49-
/// Maps opened archetypes to their definitions. If provided,
50-
/// can be used by the builder. It is supposed to be used
51-
/// only by SILGen or SIL deserializers.
52-
SILOpenedArchetypesTracker *OpenedArchetypesTracker = nullptr;
53-
5443
public:
5544
SILBuilder(SILFunction &F) : F(F), BB(0) {}
5645

@@ -86,19 +75,6 @@ class SILBuilder {
8675
return F.getModule().getTypeLowering(T);
8776
}
8877

89-
void setOpenedArchetypesTracker(SILOpenedArchetypesTracker *Tracker) {
90-
this->OpenedArchetypesTracker = Tracker;
91-
this->OpenedArchetypes.setOpenedArchetypesTracker(OpenedArchetypesTracker);
92-
}
93-
94-
SILOpenedArchetypesTracker *getOpenedArchetypesTracker() const {
95-
return OpenedArchetypesTracker;
96-
}
97-
98-
SILOpenedArchetypesState &getOpenedArchetypes() {
99-
return OpenedArchetypes;
100-
}
101-
10278
void setCurrentDebugScope(const SILDebugScope *DS) { CurDebugScope = DS; }
10379
const SILDebugScope *getCurrentDebugScope() const { return CurDebugScope; }
10480

@@ -285,8 +261,7 @@ class SILBuilder {
285261
SILType Result, ArrayRef<Substitution> Subs,
286262
ArrayRef<SILValue> Args, bool isNonThrowing) {
287263
return insert(ApplyInst::create(getSILDebugLocation(Loc), Fn, SubstFnTy,
288-
Result, Subs, Args, isNonThrowing, F,
289-
OpenedArchetypes));
264+
Result, Subs, Args, isNonThrowing, F));
290265
}
291266

292267
ApplyInst *createApply(SILLocation Loc, SILValue Fn, ArrayRef<SILValue> Args,
@@ -303,18 +278,16 @@ class SILBuilder {
303278
SILBasicBlock *errorBB) {
304279
return insertTerminator(TryApplyInst::create(getSILDebugLocation(Loc),
305280
fn, substFnTy, subs, args,
306-
normalBB, errorBB, F,
307-
OpenedArchetypes));
281+
normalBB, errorBB, F));
308282
}
309283

310284
PartialApplyInst *createPartialApply(SILLocation Loc, SILValue Fn,
311285
SILType SubstFnTy,
312286
ArrayRef<Substitution> Subs,
313287
ArrayRef<SILValue> Args,
314288
SILType ClosureTy) {
315-
return insert(PartialApplyInst::create(getSILDebugLocation(Loc), Fn,
316-
SubstFnTy, Subs, Args, ClosureTy, F,
317-
OpenedArchetypes));
289+
return insert(PartialApplyInst::create(
290+
getSILDebugLocation(Loc), Fn, SubstFnTy, Subs, Args, ClosureTy, F));
318291
}
319292

320293
BuiltinInst *createBuiltin(SILLocation Loc, Identifier Name, SILType ResultTy,
@@ -553,8 +526,8 @@ class SILBuilder {
553526

554527
UncheckedRefCastInst *createUncheckedRefCast(SILLocation Loc, SILValue Op,
555528
SILType Ty) {
556-
return insert(UncheckedRefCastInst::create(getSILDebugLocation(Loc), Op, Ty,
557-
F, OpenedArchetypes));
529+
return insert(new (F.getModule()) UncheckedRefCastInst(
530+
getSILDebugLocation(Loc), Op, Ty));
558531
}
559532

560533
UncheckedRefCastAddrInst *
@@ -566,20 +539,20 @@ class SILBuilder {
566539

567540
UncheckedAddrCastInst *createUncheckedAddrCast(SILLocation Loc, SILValue Op,
568541
SILType Ty) {
569-
return insert(UncheckedAddrCastInst::create(getSILDebugLocation(Loc), Op,
570-
Ty, F, OpenedArchetypes));
542+
return insert(new (F.getModule()) UncheckedAddrCastInst(
543+
getSILDebugLocation(Loc), Op, Ty));
571544
}
572545

573546
UncheckedTrivialBitCastInst *
574547
createUncheckedTrivialBitCast(SILLocation Loc, SILValue Op, SILType Ty) {
575-
return insert(UncheckedTrivialBitCastInst::create(
576-
getSILDebugLocation(Loc), Op, Ty, F, OpenedArchetypes));
548+
return insert(new (F.getModule()) UncheckedTrivialBitCastInst(
549+
getSILDebugLocation(Loc), Op, Ty));
577550
}
578551

579552
UncheckedBitwiseCastInst *
580553
createUncheckedBitwiseCast(SILLocation Loc, SILValue Op, SILType Ty) {
581-
return insert(UncheckedBitwiseCastInst::create(getSILDebugLocation(Loc), Op,
582-
Ty, F, OpenedArchetypes));
554+
return insert(new (F.getModule()) UncheckedBitwiseCastInst(
555+
getSILDebugLocation(Loc), Op, Ty));
583556
}
584557

585558
RefToBridgeObjectInst *createRefToBridgeObject(SILLocation Loc, SILValue Ref,
@@ -675,8 +648,8 @@ class SILBuilder {
675648

676649
UnconditionalCheckedCastInst *
677650
createUnconditionalCheckedCast(SILLocation Loc, SILValue op, SILType destTy) {
678-
return insert(UnconditionalCheckedCastInst::create(
679-
getSILDebugLocation(Loc), op, destTy, F, OpenedArchetypes));
651+
return insert(new (F.getModule()) UnconditionalCheckedCastInst(
652+
getSILDebugLocation(Loc), op, destTy));
680653
}
681654

682655
UnconditionalCheckedCastAddrInst *createUnconditionalCheckedCastAddr(
@@ -923,10 +896,11 @@ class SILBuilder {
923896
WitnessMethodInst *createWitnessMethod(SILLocation Loc, CanType LookupTy,
924897
ProtocolConformanceRef Conformance,
925898
SILDeclRef Member, SILType MethodTy,
899+
SILValue OptionalOpenedExistential,
926900
bool Volatile = false) {
927901
return insert(WitnessMethodInst::create(
928902
getSILDebugLocation(Loc), LookupTy, Conformance, Member, MethodTy,
929-
&F, OpenedArchetypes, Volatile));
903+
&F, OptionalOpenedExistential, Volatile));
930904
}
931905

932906
DynamicMethodInst *createDynamicMethod(SILLocation Loc, SILValue Operand,
@@ -938,39 +912,27 @@ class SILBuilder {
938912

939913
OpenExistentialAddrInst *
940914
createOpenExistentialAddr(SILLocation Loc, SILValue Operand, SILType SelfTy) {
941-
auto *I = insert(new (F.getModule()) OpenExistentialAddrInst(
915+
return insert(new (F.getModule()) OpenExistentialAddrInst(
942916
getSILDebugLocation(Loc), Operand, SelfTy));
943-
if (OpenedArchetypesTracker)
944-
OpenedArchetypesTracker->registerOpenedArchetypes(I);
945-
return I;
946917
}
947918

948919
OpenExistentialMetatypeInst *createOpenExistentialMetatype(SILLocation Loc,
949920
SILValue operand,
950921
SILType selfTy) {
951-
auto *I = insert(new (F.getModule()) OpenExistentialMetatypeInst(
922+
return insert(new (F.getModule()) OpenExistentialMetatypeInst(
952923
getSILDebugLocation(Loc), operand, selfTy));
953-
if (OpenedArchetypesTracker)
954-
OpenedArchetypesTracker->registerOpenedArchetypes(I);
955-
return I;
956924
}
957925

958926
OpenExistentialRefInst *
959927
createOpenExistentialRef(SILLocation Loc, SILValue Operand, SILType Ty) {
960-
auto *I = insert(new (F.getModule()) OpenExistentialRefInst(
928+
return insert(new (F.getModule()) OpenExistentialRefInst(
961929
getSILDebugLocation(Loc), Operand, Ty));
962-
if (OpenedArchetypesTracker)
963-
OpenedArchetypesTracker->registerOpenedArchetypes(I);
964-
return I;
965930
}
966931

967932
OpenExistentialBoxInst *
968933
createOpenExistentialBox(SILLocation Loc, SILValue Operand, SILType Ty) {
969-
auto *I = insert(new (F.getModule()) OpenExistentialBoxInst(
934+
return insert(new (F.getModule()) OpenExistentialBoxInst(
970935
getSILDebugLocation(Loc), Operand, Ty));
971-
if (OpenedArchetypesTracker)
972-
OpenedArchetypesTracker->registerOpenedArchetypes(I);
973-
return I;
974936
}
975937

976938
InitExistentialAddrInst *
@@ -980,25 +942,25 @@ class SILBuilder {
980942
ArrayRef<ProtocolConformanceRef> Conformances) {
981943
return insert(InitExistentialAddrInst::create(
982944
getSILDebugLocation(Loc), Existential, FormalConcreteType,
983-
LoweredConcreteType, Conformances, &F, OpenedArchetypes));
945+
LoweredConcreteType, Conformances, &F));
984946
}
985947

986948
InitExistentialMetatypeInst *
987949
createInitExistentialMetatype(SILLocation Loc, SILValue metatype,
988950
SILType existentialType,
989951
ArrayRef<ProtocolConformanceRef> conformances) {
990952
return insert(InitExistentialMetatypeInst::create(
991-
getSILDebugLocation(Loc), existentialType, metatype, conformances, &F,
992-
OpenedArchetypes));
953+
getSILDebugLocation(Loc), existentialType, metatype, conformances,
954+
&F));
993955
}
994956

995957
InitExistentialRefInst *
996958
createInitExistentialRef(SILLocation Loc, SILType ExistentialType,
997959
CanType FormalConcreteType, SILValue Concrete,
998960
ArrayRef<ProtocolConformanceRef> Conformances) {
999961
return insert(InitExistentialRefInst::create(
1000-
getSILDebugLocation(Loc), ExistentialType, FormalConcreteType, Concrete,
1001-
Conformances, &F, OpenedArchetypes));
962+
getSILDebugLocation(Loc), ExistentialType, FormalConcreteType,
963+
Concrete, Conformances, &F));
1002964
}
1003965

1004966
DeinitExistentialAddrInst *createDeinitExistentialAddr(SILLocation Loc,
@@ -1030,8 +992,8 @@ class SILBuilder {
1030992
}
1031993

1032994
MetatypeInst *createMetatype(SILLocation Loc, SILType Metatype) {
1033-
return insert(MetatypeInst::create(getSILDebugLocation(Loc), Metatype,
1034-
&F, OpenedArchetypes));
995+
return insert(new (F.getModule())
996+
MetatypeInst(getSILDebugLocation(Loc), Metatype));
1035997
}
1036998

1037999
ObjCMetatypeToObjectInst *
@@ -1344,9 +1306,9 @@ class SILBuilder {
13441306
SILValue op, SILType destTy,
13451307
SILBasicBlock *successBB,
13461308
SILBasicBlock *failureBB) {
1347-
return insertTerminator(CheckedCastBranchInst::create(
1348-
getSILDebugLocation(Loc), isExact, op, destTy, successBB, failureBB, F,
1349-
OpenedArchetypes));
1309+
return insertTerminator(new (F.getModule()) CheckedCastBranchInst(
1310+
getSILDebugLocation(Loc), isExact, op, destTy, successBB,
1311+
failureBB));
13501312
}
13511313

13521314
CheckedCastAddrBranchInst *

include/swift/SIL/SILCloner.h

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#ifndef SWIFT_SIL_SILCLONER_H
1818
#define SWIFT_SIL_SILCLONER_H
1919

20-
#include "swift/SIL/SILOpenedArchetypesTracker.h"
2120
#include "swift/SIL/SILBuilder.h"
2221
#include "swift/SIL/SILDebugScope.h"
2322
#include "swift/SIL/SILVisitor.h"
@@ -40,19 +39,9 @@ class SILCloner : protected SILVisitor<ImplClass> {
4039
public:
4140
using SILVisitor<ImplClass>::asImpl;
4241

43-
explicit SILCloner(SILFunction &F,
44-
SILOpenedArchetypesTracker &OpenedArchetypesTracker)
45-
: Builder(F), InsertBeforeBB(nullptr),
46-
OpenedArchetypesTracker(OpenedArchetypesTracker) {
47-
Builder.setOpenedArchetypesTracker(&OpenedArchetypesTracker);
48-
}
49-
5042
explicit SILCloner(SILFunction &F)
51-
: Builder(F), InsertBeforeBB(nullptr),
52-
OpenedArchetypesTracker(F) {
53-
Builder.setOpenedArchetypesTracker(&OpenedArchetypesTracker);
54-
}
55-
43+
: Builder(F), InsertBeforeBB(nullptr) { }
44+
5645
/// Clients of SILCloner who want to know about any newly created
5746
/// instructions can install a SmallVector into the builder to collect them.
5847
void setTrackingList(SmallVectorImpl<SILInstruction*> *II) {
@@ -210,14 +199,6 @@ class SILCloner : protected SILVisitor<ImplClass> {
210199
void cleanUp(SILFunction *F);
211200

212201
public:
213-
void doPreProcess(SILInstruction *Orig) {
214-
// Extend the set of available opened archetypes by the opened archetypes
215-
// used by the instruction being cloned.
216-
auto OpenedArchetypeOperands = Orig->getOpenedArchetypeOperands();
217-
Builder.getOpenedArchetypes().addOpenedArchetypeOperands(
218-
OpenedArchetypeOperands);
219-
}
220-
221202
void doPostProcess(SILInstruction *Orig, SILInstruction *Cloned) {
222203
asImpl().postProcess(Orig, Cloned);
223204
assert((Orig->getDebugScope() ? Cloned->getDebugScope()!=nullptr : true) &&
@@ -236,8 +217,6 @@ class SILCloner : protected SILVisitor<ImplClass> {
236217
llvm::MapVector<SILBasicBlock*, SILBasicBlock*> BBMap;
237218

238219
TypeSubstitutionMap OpenedExistentialSubs;
239-
SILOpenedArchetypesTracker OpenedArchetypesTracker;
240-
241220
/// Set of basic blocks where unreachable was inserted.
242221
SmallPtrSet<SILBasicBlock *, 32> BlocksWithUnreachables;
243222
};
@@ -274,27 +253,8 @@ template<typename ImplClass>
274253
class SILClonerWithScopes : public SILCloner<ImplClass> {
275254
friend class SILCloner<ImplClass>;
276255
public:
277-
SILClonerWithScopes(SILFunction &To,
278-
SILOpenedArchetypesTracker &OpenedArchetypesTracker,
279-
bool Disable = false)
280-
: SILCloner<ImplClass>(To, OpenedArchetypesTracker) {
281-
282-
// We only want to do this when we generate cloned functions, not
283-
// when we inline.
284-
285-
// FIXME: This is due to having TypeSubstCloner inherit from
286-
// SILClonerWithScopes, and having TypeSubstCloner be used
287-
// both by passes that clone whole functions and ones that
288-
// inline functions.
289-
if (Disable)
290-
return;
291-
292-
scopeCloner.reset(new ScopeCloner(To));
293-
}
294-
295-
SILClonerWithScopes(SILFunction &To,
296-
bool Disable = false)
297-
: SILCloner<ImplClass>(To) {
256+
SILClonerWithScopes(SILFunction &To, bool Disable = false)
257+
: SILCloner<ImplClass>(To) {
298258

299259
// We only want to do this when we generate cloned functions, not
300260
// when we inline.
@@ -309,7 +269,6 @@ class SILClonerWithScopes : public SILCloner<ImplClass> {
309269
scopeCloner.reset(new ScopeCloner(To));
310270
}
311271

312-
313272
private:
314273
std::unique_ptr<ScopeCloner> scopeCloner;
315274
protected:
@@ -374,12 +333,8 @@ void
374333
SILCloner<ImplClass>::visitSILBasicBlock(SILBasicBlock* BB) {
375334
SILFunction &F = getBuilder().getFunction();
376335
// Iterate over and visit all instructions other than the terminator to clone.
377-
for (auto I = BB->begin(), E = --BB->end(); I != E; ++I) {
378-
// Update the set of available opened archetypes with the opned archetypes
379-
// used by the current instruction.
380-
doPreProcess(&*I);
336+
for (auto I = BB->begin(), E = --BB->end(); I != E; ++I)
381337
asImpl().visit(&*I);
382-
}
383338
// Iterate over successors to do the depth-first search.
384339
for (auto &Succ : BB->getSuccessors()) {
385340
auto BBI = BBMap.find(Succ);
@@ -1296,17 +1251,16 @@ template<typename ImplClass>
12961251
void
12971252
SILCloner<ImplClass>::visitWitnessMethodInst(WitnessMethodInst *Inst) {
12981253
auto conformance =
1299-
getOpConformance(Inst->getLookupType(), Inst->getConformance());
1300-
auto lookupType = Inst->getLookupType();
1301-
auto newLookupType = getOpASTType(lookupType);
1254+
getOpConformance(Inst->getLookupType(), Inst->getConformance());
13021255
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
13031256
doPostProcess(
13041257
Inst,
13051258
getBuilder()
13061259
.createWitnessMethod(
13071260
getOpLocation(Inst->getLoc()),
1308-
newLookupType, conformance,
1261+
getOpASTType(Inst->getLookupType()), conformance,
13091262
Inst->getMember(), getOpType(Inst->getType()),
1263+
Inst->hasOperand() ? getOpValue(Inst->getOperand()) : SILValue(),
13101264
Inst->isVolatile()));
13111265
}
13121266

0 commit comments

Comments
 (0)