Skip to content

Commit 5af2663

Browse files
committed
Textualize assign init kind
Rename [assign] to [reassign] fix some tests AssignOwnershipQualifier formatting moar formatting
1 parent fcd6a8a commit 5af2663

19 files changed

+289
-130
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,11 @@ class SILBuilder {
812812
getSILDebugLocation(loc), buffer, enforcement, aborted, fromBuiltin));
813813
}
814814

815-
AssignInst *createAssign(SILLocation Loc, SILValue Src, SILValue DestAddr) {
815+
AssignInst *createAssign(SILLocation Loc, SILValue Src, SILValue DestAddr,
816+
AssignOwnershipQualifier Qualifier) {
816817
return insert(new (getModule())
817-
AssignInst(getSILDebugLocation(Loc), Src, DestAddr));
818+
AssignInst(getSILDebugLocation(Loc), Src, DestAddr,
819+
Qualifier));
818820
}
819821

820822
StoreBorrowInst *createStoreBorrow(SILLocation Loc, SILValue Src,

include/swift/SIL/SILCloner.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,8 @@ void SILCloner<ImplClass>::visitAssignInst(AssignInst *Inst) {
12001200
recordClonedInstruction(
12011201
Inst, getBuilder().createAssign(getOpLocation(Inst->getLoc()),
12021202
getOpValue(Inst->getSrc()),
1203-
getOpValue(Inst->getDest())));
1203+
getOpValue(Inst->getDest()),
1204+
Inst->getOwnershipQualifier()));
12041205
}
12051206

12061207
template<typename ImplClass>

include/swift/SIL/SILInstruction.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3603,21 +3603,24 @@ class EndUnpairedAccessInst
36033603
}
36043604
};
36053605

3606-
enum class PartialInitializationKind {
3606+
// *NOTE* When serializing, we can only represent up to 4 values here. If more
3607+
// qualifiers are added, SIL serialization must be updated.
3608+
enum class AssignOwnershipQualifier {
36073609
/// Unknown initialization method
36083610
Unknown,
36093611

36103612
/// The box contains a fully-initialized value.
3611-
IsNotInitialization,
3613+
Reassign,
36123614

36133615
/// The box contains a class instance that we own, but the instance has
36143616
/// not been initialized and should be freed with a special SIL
36153617
/// instruction made for this purpose.
3616-
IsReinitialization,
3618+
Reinit,
36173619

36183620
/// The box contains an undefined value that should be ignored.
3619-
IsInitialization,
3621+
Init,
36203622
};
3623+
static_assert(2 == SILNode::NumAssignOwnershipQualifierBits, "Size mismatch");
36213624

36223625
/// AssignInst - Represents an abstract assignment to a memory location, which
36233626
/// may either be an initialization or a store sequence. This is only valid in
@@ -3628,9 +3631,10 @@ class AssignInst
36283631
friend SILBuilder;
36293632

36303633
FixedOperandList<2> Operands;
3631-
PartialInitializationKind InitKind;
36323634

3633-
AssignInst(SILDebugLocation DebugLoc, SILValue Src, SILValue Dest);
3635+
AssignInst(SILDebugLocation DebugLoc, SILValue Src, SILValue Dest,
3636+
AssignOwnershipQualifier Qualifier =
3637+
AssignOwnershipQualifier::Unknown);
36343638

36353639
public:
36363640
enum {
@@ -3646,8 +3650,13 @@ class AssignInst
36463650
ArrayRef<Operand> getAllOperands() const { return Operands.asArray(); }
36473651
MutableArrayRef<Operand> getAllOperands() { return Operands.asArray(); }
36483652

3649-
PartialInitializationKind getInitKind() const { return InitKind; }
3650-
void setInitKind(PartialInitializationKind initKind) { InitKind = initKind; }
3653+
AssignOwnershipQualifier getOwnershipQualifier() const {
3654+
return AssignOwnershipQualifier(
3655+
SILInstruction::Bits.AssignInst.OwnershipQualifier);
3656+
}
3657+
void setOwnershipQualifier(AssignOwnershipQualifier qualifier) {
3658+
SILInstruction::Bits.AssignInst.OwnershipQualifier = unsigned(qualifier);
3659+
}
36513660
};
36523661

36533662
/// Indicates that a memory location is uninitialized at this point and needs to

include/swift/SIL/SILNode.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class alignas(8) SILNode {
9696
enum { NumVOKindBits = 3 };
9797
enum { NumStoreOwnershipQualifierBits = 2 };
9898
enum { NumLoadOwnershipQualifierBits = 2 };
99+
enum { NumAssignOwnershipQualifierBits = 2 };
99100
enum { NumSILAccessKindBits = 2 };
100101
enum { NumSILAccessEnforcementBits = 2 };
101102

@@ -280,6 +281,10 @@ class alignas(8) SILNode {
280281
NumLoadOwnershipQualifierBits,
281282
OwnershipQualifier : NumLoadOwnershipQualifierBits
282283
);
284+
SWIFT_INLINE_BITFIELD(AssignInst, NonValueInstruction,
285+
NumAssignOwnershipQualifierBits,
286+
OwnershipQualifier : NumAssignOwnershipQualifierBits
287+
);
283288

284289
SWIFT_INLINE_BITFIELD(UncheckedOwnershipConversionInst,SingleValueInstruction,
285290
NumVOKindBits,

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5252
/// describe what change you made. The content of this comment isn't important;
5353
/// it just ensures a conflict if two people change the module format.
5454
/// Don't worry about adhering to the 80-column limit for this line.
55-
const uint16_t SWIFTMODULE_VERSION_MINOR = 472; // Last change: partial_apply [stack]
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 473; // Last change: assign ownership qualifier
5656

5757
using DeclIDField = BCFixed<31>;
5858

lib/ParseSIL/ParseSIL.cpp

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,32 @@ static bool parseStoreOwnershipQualifier(StoreOwnershipQualifier &Result,
19561956
return false;
19571957
}
19581958

1959+
static bool parseAssignOwnershipQualifier(AssignOwnershipQualifier &Result,
1960+
SILParser &P) {
1961+
StringRef Str;
1962+
// If we do not parse '[' ... ']', we have unknown. Set value and return.
1963+
if (!parseSILOptional(Str, P)) {
1964+
Result = AssignOwnershipQualifier::Unknown;
1965+
return false;
1966+
}
1967+
1968+
// Then try to parse one of our other initialization kinds. We do not support
1969+
// parsing unknown here so we use that as our fail value.
1970+
auto Tmp = llvm::StringSwitch<AssignOwnershipQualifier>(Str)
1971+
.Case("reassign", AssignOwnershipQualifier::Reassign)
1972+
.Case("reinit", AssignOwnershipQualifier::Reinit)
1973+
.Case("init", AssignOwnershipQualifier::Init)
1974+
.Default(AssignOwnershipQualifier::Unknown);
1975+
1976+
// Thus return true (following the conventions in this file) if we fail.
1977+
if (Tmp == AssignOwnershipQualifier::Unknown)
1978+
return true;
1979+
1980+
// Otherwise, assign Result and return false.
1981+
Result = Tmp;
1982+
return false;
1983+
}
1984+
19591985
bool SILParser::parseSILDeclRef(SILDeclRef &Member, bool FnTypeRequired) {
19601986
SourceLoc TyLoc;
19611987
SmallVector<ValueDecl *, 4> values;
@@ -3448,18 +3474,25 @@ bool SILParser::parseSILInstruction(SILBuilder &B) {
34483474
break;
34493475
}
34503476

3477+
case SILInstructionKind::AssignInst:
34513478
case SILInstructionKind::StoreInst: {
34523479
UnresolvedValueName From;
34533480
SourceLoc ToLoc, AddrLoc;
34543481
Identifier ToToken;
34553482
SILValue AddrVal;
3456-
StoreOwnershipQualifier Qualifier;
3483+
StoreOwnershipQualifier StoreQualifier;
3484+
AssignOwnershipQualifier AssignQualifier;
3485+
bool IsStore = Opcode == SILInstructionKind::StoreInst;
3486+
bool IsAssign = Opcode == SILInstructionKind::AssignInst;
34573487
if (parseValueName(From) ||
34583488
parseSILIdentifier(ToToken, ToLoc, diag::expected_tok_in_sil_instr,
34593489
"to"))
34603490
return true;
34613491

3462-
if (parseStoreOwnershipQualifier(Qualifier, *this))
3492+
if (IsStore && parseStoreOwnershipQualifier(StoreQualifier, *this))
3493+
return true;
3494+
3495+
if (IsAssign && parseAssignOwnershipQualifier(AssignQualifier, *this))
34633496
return true;
34643497

34653498
if (parseTypedValueRef(AddrVal, AddrLoc, B) ||
@@ -3479,8 +3512,18 @@ bool SILParser::parseSILInstruction(SILBuilder &B) {
34793512

34803513
SILType ValType = AddrVal->getType().getObjectType();
34813514

3482-
ResultVal = B.createStore(InstLoc, getLocalValue(From, ValType, InstLoc, B),
3483-
AddrVal, Qualifier);
3515+
if (IsStore) {
3516+
ResultVal = B.createStore(InstLoc,
3517+
getLocalValue(From, ValType, InstLoc, B),
3518+
AddrVal, StoreQualifier);
3519+
} else {
3520+
assert(IsAssign);
3521+
3522+
ResultVal = B.createAssign(InstLoc,
3523+
getLocalValue(From, ValType, InstLoc, B),
3524+
AddrVal, AssignQualifier);
3525+
}
3526+
34843527
break;
34853528
}
34863529

@@ -3619,8 +3662,7 @@ bool SILParser::parseSILInstruction(SILBuilder &B) {
36193662
#define NEVER_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
36203663
case SILInstructionKind::Store##Name##Inst:
36213664
#include "swift/AST/ReferenceStorage.def"
3622-
case SILInstructionKind::StoreBorrowInst:
3623-
case SILInstructionKind::AssignInst: {
3665+
case SILInstructionKind::StoreBorrowInst: {
36243666
UnresolvedValueName from;
36253667
bool isRefStorage = false;
36263668
#define NEVER_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
@@ -3673,12 +3715,6 @@ bool SILParser::parseSILInstruction(SILBuilder &B) {
36733715
}
36743716
#include "swift/AST/ReferenceStorage.def"
36753717

3676-
SILType ValType = addrVal->getType().getObjectType();
3677-
3678-
assert(Opcode == SILInstructionKind::AssignInst);
3679-
ResultVal = B.createAssign(InstLoc,
3680-
getLocalValue(from, ValType, InstLoc, B),
3681-
addrVal);
36823718
break;
36833719
}
36843720
case SILInstructionKind::AllocStackInst:

lib/SIL/SILInstructions.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,11 @@ StringRef swift::getSILAccessEnforcementName(SILAccessEnforcement enforcement) {
812812
llvm_unreachable("bad access enforcement");
813813
}
814814

815-
AssignInst::AssignInst(SILDebugLocation Loc, SILValue Src, SILValue Dest)
816-
: InstructionBase(Loc), Operands(this, Src, Dest),
817-
InitKind(PartialInitializationKind::Unknown) {}
815+
AssignInst::AssignInst(SILDebugLocation Loc, SILValue Src, SILValue Dest,
816+
AssignOwnershipQualifier Qualifier)
817+
: InstructionBase(Loc), Operands(this, Src, Dest) {
818+
SILInstruction::Bits.AssignInst.OwnershipQualifier = unsigned(Qualifier);
819+
}
818820

819821
MarkFunctionEscapeInst *
820822
MarkFunctionEscapeInst::create(SILDebugLocation Loc,

lib/SIL/SILPrinter.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,22 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
12721272
}
12731273
}
12741274

1275+
void printAssignOwnershipQualifier(AssignOwnershipQualifier Qualifier) {
1276+
switch (Qualifier) {
1277+
case AssignOwnershipQualifier::Unknown:
1278+
return;
1279+
case AssignOwnershipQualifier::Init:
1280+
*this << "[init] ";
1281+
return;
1282+
case AssignOwnershipQualifier::Reassign:
1283+
*this << "[reassign] ";
1284+
return;
1285+
case AssignOwnershipQualifier::Reinit:
1286+
*this << "[reinit] ";
1287+
return;
1288+
}
1289+
}
1290+
12751291
void visitStoreInst(StoreInst *SI) {
12761292
*this << Ctx.getID(SI->getSrc()) << " to ";
12771293
printStoreOwnershipQualifier(SI->getOwnershipQualifier());
@@ -1288,7 +1304,9 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
12881304
}
12891305

12901306
void visitAssignInst(AssignInst *AI) {
1291-
*this << Ctx.getID(AI->getSrc()) << " to " << getIDAndType(AI->getDest());
1307+
*this << Ctx.getID(AI->getSrc()) << " to ";
1308+
printAssignOwnershipQualifier(AI->getOwnershipQualifier());
1309+
*this << getIDAndType(AI->getDest());
12921310
}
12931311

12941312
void visitMarkUninitializedInst(MarkUninitializedInst *MU) {

lib/SILGen/SILGenLValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3475,7 +3475,7 @@ static void emitUnloweredStoreOfCopy(SILGenBuilder &B, SILLocation loc,
34753475
if (isInit) {
34763476
B.emitStoreValueOperation(loc, value, addr, StoreOwnershipQualifier::Init);
34773477
} else {
3478-
B.createAssign(loc, value, addr);
3478+
B.createAssign(loc, value, addr, AssignOwnershipQualifier::Unknown);
34793479
}
34803480
}
34813481

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,8 @@ void ElementUseCollector::collectUses(SILValue Pointer, unsigned BaseEltNo) {
10291029
getScalarizedElements(AI->getOperand(0), ElementTmps, AI->getLoc(), B);
10301030

10311031
for (unsigned i = 0, e = ElementAddrs.size(); i != e; ++i)
1032-
B.createAssign(AI->getLoc(), ElementTmps[i], ElementAddrs[i]);
1032+
B.createAssign(AI->getLoc(), ElementTmps[i], ElementAddrs[i],
1033+
AssignOwnershipQualifier::Unknown);
10331034
AI->eraseFromParent();
10341035
continue;
10351036
}

0 commit comments

Comments
 (0)