Skip to content

Commit ddad2a7

Browse files
committed
[SIL] InitAccessors: Reference a field that assign_or_init is associated with
The field removes the need to dig through init accessor reference to find what stored properties and handled by the instruction.
1 parent 1a9c2e6 commit ddad2a7

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,13 +956,15 @@ class SILBuilder {
956956
}
957957

958958
AssignOrInitInst *createAssignOrInit(SILLocation Loc,
959+
VarDecl *Property,
959960
SILValue Self,
960961
SILValue Src,
961962
SILValue Initializer,
962963
SILValue Setter,
963964
AssignOrInitInst::Mode Mode) {
964-
return insert(new (getModule()) AssignOrInitInst(
965-
getSILDebugLocation(Loc), Self, Src, Initializer, Setter, Mode));
965+
return insert(new (getModule())
966+
AssignOrInitInst(getSILDebugLocation(Loc), Property, Self,
967+
Src, Initializer, Setter, Mode));
966968
}
967969

968970
StoreBorrowInst *createStoreBorrow(SILLocation Loc, SILValue Src,

include/swift/SIL/SILCloner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,7 @@ void SILCloner<ImplClass>::visitAssignOrInitInst(AssignOrInitInst *Inst) {
13561356
recordClonedInstruction(
13571357
Inst, getBuilder().createAssignOrInit(
13581358
getOpLocation(Inst->getLoc()),
1359+
Inst->getProperty(),
13591360
getOpValue(Inst->getSelf()),
13601361
getOpValue(Inst->getSrc()),
13611362
getOpValue(Inst->getInitializer()),

include/swift/SIL/SILInstruction.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4820,6 +4820,9 @@ class AssignOrInitInst
48204820

48214821
FixedOperandList<4> Operands;
48224822

4823+
/// Property the init accessor is associated with.
4824+
VarDecl *Property;
4825+
48234826
/// Marks all of the properties in `initializes(...)` list that
48244827
/// have been initialized before this intruction to help Raw SIL
48254828
/// lowering to emit destroys.
@@ -4838,10 +4841,12 @@ class AssignOrInitInst
48384841
};
48394842

48404843
private:
4841-
AssignOrInitInst(SILDebugLocation DebugLoc, SILValue Self, SILValue Src,
4842-
SILValue Initializer, SILValue Setter, Mode mode);
4844+
AssignOrInitInst(SILDebugLocation DebugLoc, VarDecl *P, SILValue Self,
4845+
SILValue Src, SILValue Initializer, SILValue Setter,
4846+
Mode mode);
48434847

48444848
public:
4849+
VarDecl *getProperty() const { return Property; }
48454850
SILValue getSelf() const { return Operands[0].get(); }
48464851
SILValue getSrc() const { return Operands[1].get(); }
48474852
SILValue getInitializer() const { return Operands[2].get(); }

lib/SIL/IR/SILInstructions.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,12 +1259,13 @@ AssignByWrapperInst::AssignByWrapperInst(SILDebugLocation Loc,
12591259
sharedUInt8().AssignByWrapperInst.mode = uint8_t(mode);
12601260
}
12611261

1262-
AssignOrInitInst::AssignOrInitInst(SILDebugLocation Loc, SILValue Self,
1263-
SILValue Src, SILValue Initializer,
1264-
SILValue Setter, AssignOrInitInst::Mode Mode)
1262+
AssignOrInitInst::AssignOrInitInst(SILDebugLocation Loc, VarDecl *P,
1263+
SILValue Self, SILValue Src,
1264+
SILValue Initializer, SILValue Setter,
1265+
AssignOrInitInst::Mode Mode)
12651266
: InstructionBase<SILInstructionKind::AssignOrInitInst,
12661267
NonValueInstruction>(Loc),
1267-
Operands(this, Self, Src, Initializer, Setter) {
1268+
Operands(this, Self, Src, Initializer, Setter), Property(P) {
12681269
assert(Initializer->getType().is<SILFunctionType>());
12691270
sharedUInt8().AssignOrInitInst.mode = uint8_t(Mode);
12701271
Assignments.resize(getNumInitializedProperties());
@@ -1291,23 +1292,11 @@ bool AssignOrInitInst::isPropertyAlreadyInitialized(unsigned propertyIdx) {
12911292
}
12921293

12931294
StringRef AssignOrInitInst::getPropertyName() const {
1294-
auto *accessor = getReferencedInitAccessor();
1295-
assert(accessor);
1296-
return cast<VarDecl>(accessor->getStorage())->getNameStr();
1295+
return Property->getNameStr();
12971296
}
12981297

12991298
AccessorDecl *AssignOrInitInst::getReferencedInitAccessor() const {
1300-
SILValue initRef = getInitializer();
1301-
SILFunction *accessorFn = nullptr;
1302-
1303-
if (auto *PAI = dyn_cast<PartialApplyInst>(initRef)) {
1304-
accessorFn = PAI->getReferencedFunctionOrNull();
1305-
} else {
1306-
accessorFn = cast<FunctionRefInst>(initRef)->getReferencedFunctionOrNull();
1307-
}
1308-
1309-
assert(accessorFn);
1310-
return dyn_cast_or_null<AccessorDecl>(accessorFn->getDeclContext());
1299+
return Property->getOpaqueAccessor(AccessorKind::Init);
13111300
}
13121301

13131302
unsigned AssignOrInitInst::getNumInitializedProperties() const {

lib/SILGen/SILGenFunction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,6 +1859,7 @@ void SILGenFunction::emitAssignOrInit(SILLocation loc, ManagedValue selfValue,
18591859
setterFRef = SILUndef::get(initFRef->getType(), F);
18601860
}
18611861

1862-
B.createAssignOrInit(loc, selfValue.getValue(), newValue.forward(*this),
1863-
initFRef, setterFRef, AssignOrInitInst::Unknown);
1862+
B.createAssignOrInit(loc, field, selfValue.getValue(),
1863+
newValue.forward(*this), initFRef, setterFRef,
1864+
AssignOrInitInst::Unknown);
18641865
}

0 commit comments

Comments
 (0)