Skip to content

Commit 4a30957

Browse files
committed
[sil] Rename [moved] flag on debug_value/alloc_stack to moveable_value_debuginfo.
This is in preparation for wiring up debug info support for noncopyable values. Originally this flag name made sense since it was set when we performed consume operator checking. Now I am going to use it for noncopyable types as well. I think the new name uses_moveable_value_debuginfo actually describes what the flag is supposed to do, tell IRGen that the value may be moved since it needs to use moveable value debug info emission.
1 parent a563db6 commit 4a30957

19 files changed

+163
-144
lines changed

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ public struct Builder {
8484
}
8585

8686
public func createAllocStack(_ type: Type, hasDynamicLifetime: Bool = false,
87-
isLexical: Bool = false, wasMoved: Bool = false) -> AllocStackInst {
87+
isLexical: Bool = false,
88+
usesMoveableValueDebugInfo: Bool = false) -> AllocStackInst {
8889
let dr = SILBuilder_createAllocStack(bridged, type.bridged, hasDynamicLifetime ? 1 : 0,
89-
isLexical ? 1 : 0, wasMoved ? 1 : 0)
90+
isLexical ? 1 : 0, usesMoveableValueDebugInfo ? 1 : 0)
9091
return notifyNew(dr.getAs(AllocStackInst.self))
9192
}
9293

docs/SIL.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3745,7 +3745,10 @@ alloc_stack
37453745
```````````
37463746
::
37473747

3748-
sil-instruction ::= 'alloc_stack' '[dynamic_lifetime]'? '[lexical]'? '[moved]'? sil-type (',' debug-var-attr)*
3748+
sil-instruction ::= 'alloc_stack' alloc-stack-option* sil-type (',' debug-var-attr)*
3749+
alloc-stack-option ::= '[dynamic_lifetime]'
3750+
alloc-stack-option ::= '[lexical]'
3751+
alloc-stack-option ::= '[moveable_value_debuginfo]'
37493752

37503753
%1 = alloc_stack $T
37513754
// %1 has type $*T
@@ -3767,11 +3770,10 @@ This is the case, e.g. for conditionally initialized objects.
37673770
The optional ``lexical`` attribute specifies that the storage corresponds to a
37683771
local variable in the Swift source.
37693772

3770-
The optional ``moved`` attribute specifies that at the source level, the
3771-
variable associated with this alloc_stack was moved and furthermore that at the
3772-
SIL level it passed move operator checking. This means that one can not assume
3773-
that the value in the alloc_stack can be semantically valid over the entire
3774-
function frame when emitting debug info.
3773+
The optional ``moveable_value_debuginfo`` attribute specifies that when
3774+
emitting debug info, the code generator can not assume that the value in the
3775+
alloc_stack can be semantically valid over the entire function frame when
3776+
emitting debug info.
37753777

37763778
The memory is not retainable. To allocate a retainable box for a value
37773779
type, use ``alloc_box``.
@@ -4155,7 +4157,7 @@ debug_value
41554157

41564158
::
41574159

4158-
sil-instruction ::= debug_value '[poison]'? '[moved]'? '[trace]'? sil-operand (',' debug-var-attr)* advanced-debug-var-attr* (',' 'expr' debug-info-expr)?
4160+
sil-instruction ::= debug_value '[poison]'? '[moveable_value_debuginfo]'? '[trace]'? sil-operand (',' debug-var-attr)* advanced-debug-var-attr* (',' 'expr' debug-info-expr)?
41594161

41604162
debug_value %1 : $Int
41614163

@@ -4164,7 +4166,7 @@ specified operand. The declaration in question is identified by either the
41644166
SILLocation attached to the debug_value instruction or the SILLocation specified
41654167
in the advanced debug variable attributes.
41664168

4167-
If the '[moved]' flag is set, then one knows that the debug_value's operand is
4169+
If the '[moveable_value_debuginfo]' flag is set, then one knows that the debug_value's operand is
41684170
moved at some point of the program, so one can not model the debug_value using
41694171
constructs that assume that the value is live for the entire function (e.x.:
41704172
llvm.dbg.declare).

include/swift/SIL/DebugUtils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,10 @@ struct DebugVarCarryingInst : VarDeclCarryingInst {
460460
case Kind::Invalid:
461461
llvm_unreachable("Invalid?!");
462462
case Kind::DebugValue:
463-
cast<DebugValueInst>(**this)->markAsMoved();
463+
cast<DebugValueInst>(**this)->setUsesMoveableValueDebugInfo();
464464
break;
465465
case Kind::AllocStack:
466-
cast<AllocStackInst>(**this)->markAsMoved();
466+
cast<AllocStackInst>(**this)->markUsesMoveableValueDebugInfo();
467467
break;
468468
case Kind::AllocBox:
469469
llvm_unreachable("Not implemented");
@@ -476,9 +476,9 @@ struct DebugVarCarryingInst : VarDeclCarryingInst {
476476
case Kind::Invalid:
477477
llvm_unreachable("Invalid?!");
478478
case Kind::DebugValue:
479-
return cast<DebugValueInst>(**this)->getWasMoved();
479+
return cast<DebugValueInst>(**this)->getUsesMoveableValueDebugInfo();
480480
case Kind::AllocStack:
481-
return cast<AllocStackInst>(**this)->getWasMoved();
481+
return cast<AllocStackInst>(**this)->getUsesMoveableValueDebugInfo();
482482
case Kind::AllocBox:
483483
// We do not support moving alloc box today, so we always return false.
484484
return false;

include/swift/SIL/SILCloner.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,8 @@ SILCloner<ImplClass>::visitAllocStackInst(AllocStackInst *Inst) {
893893
}
894894
auto *NewInst = getBuilder().createAllocStack(
895895
Loc, getOpType(Inst->getElementType()), VarInfo,
896-
Inst->hasDynamicLifetime(), Inst->isLexical(), Inst->getWasMoved());
896+
Inst->hasDynamicLifetime(), Inst->isLexical(),
897+
Inst->getUsesMoveableValueDebugInfo());
897898
remapDebugVarInfo(DebugVarCarryingInst(NewInst));
898899
recordClonedInstruction(Inst, NewInst);
899900
}
@@ -1380,7 +1381,8 @@ SILCloner<ImplClass>::visitDebugValueInst(DebugValueInst *Inst) {
13801381
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
13811382
auto *NewInst = getBuilder().createDebugValue(
13821383
Inst->getLoc(), getOpValue(Inst->getOperand()), VarInfo,
1383-
Inst->poisonRefs(), Inst->getWasMoved(), Inst->hasTrace());
1384+
Inst->poisonRefs(), Inst->getUsesMoveableValueDebugInfo(),
1385+
Inst->hasTrace());
13841386
remapDebugVarInfo(DebugVarCarryingInst(NewInst));
13851387
recordClonedInstruction(Inst, NewInst);
13861388
}

include/swift/SIL/SILInstruction.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,12 +2094,12 @@ class AllocStackInst final
20942094
AllocStackInst(SILDebugLocation Loc, SILType elementType,
20952095
ArrayRef<SILValue> TypeDependentOperands, SILFunction &F,
20962096
Optional<SILDebugVariable> Var, bool hasDynamicLifetime,
2097-
bool isLexical, bool wasMoved);
2097+
bool isLexical, bool usesMoveableValueDebugInfo);
20982098

20992099
static AllocStackInst *create(SILDebugLocation Loc, SILType elementType,
21002100
SILFunction &F, Optional<SILDebugVariable> Var,
21012101
bool hasDynamicLifetime, bool isLexical,
2102-
bool wasMoved);
2102+
bool usesMoveableValueDebugInfo);
21032103

21042104
SIL_DEBUG_VAR_SUPPLEMENT_TRAILING_OBJS_IMPL()
21052105

@@ -2116,11 +2116,15 @@ class AllocStackInst final
21162116
}
21172117
}
21182118

2119-
void markAsMoved() { sharedUInt8().AllocStackInst.wasMoved = true; }
2119+
void markUsesMoveableValueDebugInfo() {
2120+
sharedUInt8().AllocStackInst.usesMoveableValueDebugInfo = true;
2121+
}
21202122

21212123
/// Set to true if this alloc_stack's memory location was passed to _move at
21222124
/// any point of the program.
2123-
bool getWasMoved() const { return sharedUInt8().AllocStackInst.wasMoved; }
2125+
bool getUsesMoveableValueDebugInfo() const {
2126+
return sharedUInt8().AllocStackInst.usesMoveableValueDebugInfo;
2127+
}
21242128

21252129
/// Set to true that this alloc_stack contains a value whose lifetime can not
21262130
/// be ascertained from uses.
@@ -5012,14 +5016,17 @@ class DebugValueInst final
50125016
size_t numTrailingObjects(OverloadToken<char>) const { return 1; }
50135017

50145018
public:
5015-
void markAsMoved() { sharedUInt8().DebugValueInst.operandWasMoved = true; }
5019+
/// Sets a bool that states this debug_value is supposed to use the
5020+
void setUsesMoveableValueDebugInfo() {
5021+
sharedUInt8().DebugValueInst.usesMoveableValueDebugInfo = true;
5022+
}
50165023

50175024
/// True if this debug_value is on an SSA value that was moved.
50185025
///
50195026
/// IRGen uses this information to determine if we should use llvm.dbg.addr or
50205027
/// llvm.dbg.declare.
5021-
bool getWasMoved() const {
5022-
return sharedUInt8().DebugValueInst.operandWasMoved;
5028+
bool getUsesMoveableValueDebugInfo() const {
5029+
return sharedUInt8().DebugValueInst.usesMoveableValueDebugInfo;
50235030
}
50245031

50255032
/// Return the underlying variable declaration that this denotes,

include/swift/SIL/SILNode.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ class alignas(8) SILNode :
174174
#define SHARED_TEMPLATE4_FIELD(T1, T2, T3, T4, I, ...) \
175175
class { template <T1, T2, T3, T4> friend class I; __VA_ARGS__; } I;
176176

177+
// clang-format off
177178
union SharedUInt8Fields {
178179
uint8_t opaque;
179180

@@ -203,15 +204,15 @@ class alignas(8) SILNode :
203204
SHARED_FIELD(BeginCOWMutationInst, bool native);
204205

205206
SHARED_FIELD(DebugValueInst, uint8_t
206-
poisonRefs : 1,
207-
operandWasMoved : 1,
208-
trace : 1);
207+
poisonRefs : 1,
208+
usesMoveableValueDebugInfo : 1,
209+
trace : 1);
209210

210211
SHARED_FIELD(AllocStackInst, uint8_t
211-
dynamicLifetime : 1,
212-
lexical : 1,
213-
wasMoved : 1,
214-
hasInvalidatedVarInfo : 1);
212+
dynamicLifetime : 1,
213+
lexical : 1,
214+
usesMoveableValueDebugInfo : 1,
215+
hasInvalidatedVarInfo : 1);
215216

216217
SHARED_FIELD(AllocRefInstBase, uint8_t
217218
objC : 1,
@@ -243,10 +244,12 @@ class alignas(8) SILNode :
243244

244245
// Do not use `_sharedUInt8_private` outside of SILNode.
245246
} _sharedUInt8_private;
247+
// clang-format on
246248

247249
static_assert(sizeof(SharedUInt8Fields) == sizeof(uint8_t),
248250
"A SILNode's shared uint8 field is too large");
249251

252+
// clang-format off
250253
union SharedUInt32Fields {
251254
uint32_t opaque;
252255

@@ -272,6 +275,7 @@ class alignas(8) SILNode :
272275

273276
// Do not use `_sharedUInt32_private` outside of SILNode.
274277
} _sharedUInt32_private;
278+
// clang-format on
275279

276280
static_assert(sizeof(SharedUInt32Fields) == sizeof(uint32_t),
277281
"A SILNode's shared uint32 field is too large");

lib/IRGen/AllocStackHoisting.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ class Partition {
113113
/// statistics to make sure that we haven't hurt debuggability by making the
114114
/// change.
115115
bool hasMovedElt() const {
116-
return llvm::any_of(Elts,
117-
[](AllocStackInst *asi) { return asi->getWasMoved(); });
116+
return llvm::any_of(Elts, [](AllocStackInst *asi) {
117+
return asi->getUsesMoveableValueDebugInfo();
118+
});
118119
}
119120
};
120121
} // end anonymous namespace
@@ -155,10 +156,10 @@ void moveAllocStackToBeginningOfBlock(
155156
if (auto varInfo = AS->getVarInfo()) {
156157
SILBuilderWithScope Builder(AS);
157158
auto *DVI = Builder.createDebugValue(AS->getLoc(), AS, *varInfo);
158-
DVI->markAsMoved();
159+
DVI->setUsesMoveableValueDebugInfo();
159160
DebugValueToBreakBlocksAt.push_back(DVI);
160161
AS->invalidateVarInfo();
161-
AS->markAsMoved();
162+
AS->markUsesMoveableValueDebugInfo();
162163
}
163164
}
164165
AS->moveFront(BB);
@@ -197,7 +198,7 @@ void Partition::assignStackLocation(
197198
SILBuilderWithScope Builder(AllocStack);
198199
auto *DVI = Builder.createDebugValue(AllocStack->getLoc(), AssignedLoc,
199200
*VarInfo);
200-
DVI->markAsMoved();
201+
DVI->setUsesMoveableValueDebugInfo();
201202
DebugValueToBreakBlocksAt.push_back(DVI);
202203
}
203204
}

lib/IRGen/IRGenSIL.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5087,7 +5087,7 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
50875087

50885088
// If we were not moved return early. If this SILUndef was moved, then we
50895089
// need to let it through so we can ensure the debug info invalidated.
5090-
if (!i->getWasMoved())
5090+
if (!i->getUsesMoveableValueDebugInfo())
50915091
return;
50925092
}
50935093
bool IsInCoro = InCoroContext(*CurSILFn, *i);
@@ -5138,18 +5138,18 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
51385138
if (IsAddrVal)
51395139
Copy.emplace_back(emitShadowCopyIfNeeded(
51405140
getLoweredAddress(SILVal).getAddress(), i->getDebugScope(), *VarInfo,
5141-
IsAnonymous, i->getWasMoved()));
5141+
IsAnonymous, i->getUsesMoveableValueDebugInfo()));
51425142
else
51435143
emitShadowCopyIfNeeded(SILVal, i->getDebugScope(), *VarInfo, IsAnonymous,
5144-
i->getWasMoved(), Copy);
5144+
i->getUsesMoveableValueDebugInfo(), Copy);
51455145

51465146
bindArchetypes(DbgTy.getType());
51475147
if (!IGM.DebugInfo)
51485148
return;
51495149

5150-
emitDebugVariableDeclaration(Copy, DbgTy, SILTy, i->getDebugScope(),
5151-
i->getLoc(), *VarInfo, Indirection,
5152-
AddrDbgInstrKind(i->getWasMoved()));
5150+
emitDebugVariableDeclaration(
5151+
Copy, DbgTy, SILTy, i->getDebugScope(), i->getLoc(), *VarInfo,
5152+
Indirection, AddrDbgInstrKind(i->getUsesMoveableValueDebugInfo()));
51535153
}
51545154

51555155
void IRGenSILFunction::visitDebugStepInst(DebugStepInst *i) {
@@ -5479,7 +5479,7 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
54795479
if (!Alloca->isStaticAlloca()) {
54805480
// Store the address of the dynamic alloca on the stack.
54815481
addr = emitShadowCopy(addr, DS, *VarInfo, IGM.getPointerAlignment(),
5482-
/*init*/ true, i->getWasMoved())
5482+
/*init*/ true, i->getUsesMoveableValueDebugInfo())
54835483
.getAddress();
54845484
Indirection =
54855485
InCoroContext(*CurSILFn, *i) ? CoroIndirectValue : IndirectValue;
@@ -5518,9 +5518,9 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
55185518

55195519
bindArchetypes(DbgTy.getType());
55205520
if (IGM.DebugInfo) {
5521-
emitDebugVariableDeclaration(addr, DbgTy, SILTy, DS, i->getLoc(), *VarInfo,
5522-
Indirection,
5523-
AddrDbgInstrKind(i->getWasMoved()));
5521+
emitDebugVariableDeclaration(
5522+
addr, DbgTy, SILTy, DS, i->getLoc(), *VarInfo, Indirection,
5523+
AddrDbgInstrKind(i->getUsesMoveableValueDebugInfo()));
55245524
}
55255525
}
55265526

lib/SIL/IR/SILInstructions.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ AllocStackInst::AllocStackInst(SILDebugLocation Loc, SILType elementType,
229229
ArrayRef<SILValue> TypeDependentOperands,
230230
SILFunction &F, Optional<SILDebugVariable> Var,
231231
bool hasDynamicLifetime, bool isLexical,
232-
bool wasMoved)
232+
bool usesMoveableValueDebugInfo)
233233
: InstructionBase(Loc, elementType.getAddressType()),
234234
SILDebugVariableSupplement(Var ? Var->DIExpr.getNumElements() : 0,
235235
Var ? Var->Type.has_value() : false,
@@ -240,20 +240,22 @@ AllocStackInst::AllocStackInst(SILDebugLocation Loc, SILType elementType,
240240
VarInfo(0) {
241241
sharedUInt8().AllocStackInst.dynamicLifetime = hasDynamicLifetime;
242242
sharedUInt8().AllocStackInst.lexical = isLexical;
243-
sharedUInt8().AllocStackInst.wasMoved = wasMoved;
243+
sharedUInt8().AllocStackInst.usesMoveableValueDebugInfo =
244+
usesMoveableValueDebugInfo;
244245
sharedUInt32().AllocStackInst.numOperands = TypeDependentOperands.size();
245246

246-
// VarInfo must be initialized after `sharedUInt32().AllocStackInst.numOperands`!
247-
// Otherwise the trailing object addresses are wrong.
248-
VarInfo = TailAllocatedDebugVariable(Var,
249-
getTrailingObjects<char>(),
250-
getTrailingObjects<SILType>(),
251-
getTrailingObjects<SILLocation>(),
252-
getTrailingObjects<const SILDebugScope *>(),
253-
getTrailingObjects<SILDIExprElement>());
247+
// VarInfo must be initialized after
248+
// `sharedUInt32().AllocStackInst.numOperands`! Otherwise the trailing object
249+
// addresses are wrong.
250+
VarInfo = TailAllocatedDebugVariable(
251+
Var, getTrailingObjects<char>(), getTrailingObjects<SILType>(),
252+
getTrailingObjects<SILLocation>(),
253+
getTrailingObjects<const SILDebugScope *>(),
254+
getTrailingObjects<SILDIExprElement>());
254255

255256
assert(sharedUInt32().AllocStackInst.numOperands ==
256-
TypeDependentOperands.size() && "Truncation");
257+
TypeDependentOperands.size() &&
258+
"Truncation");
257259
auto *VD = Loc.getLocation().getAsASTNode<VarDecl>();
258260
if (Var && VD) {
259261
VarInfo.setImplicit(VD->isImplicit() || VarInfo.isImplicit());
@@ -417,7 +419,7 @@ DebugValueInst::DebugValueInst(SILDebugLocation DebugLoc, SILValue Operand,
417419
VarInfo.setImplicit(VD->isImplicit() || VarInfo.isImplicit());
418420
setPoisonRefs(poisonRefs);
419421
if (wasMoved)
420-
markAsMoved();
422+
setUsesMoveableValueDebugInfo();
421423
setTrace(trace);
422424
}
423425

lib/SIL/IR/SILPrinter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,8 +1393,8 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
13931393
*this << "[dynamic_lifetime] ";
13941394
if (AVI->isLexical())
13951395
*this << "[lexical] ";
1396-
if (AVI->getWasMoved())
1397-
*this << "[moved] ";
1396+
if (AVI->getUsesMoveableValueDebugInfo())
1397+
*this << "[moveable_value_debuginfo] ";
13981398
*this << AVI->getElementType();
13991399
printDebugVar(AVI->getVarInfo(),
14001400
&AVI->getModule().getASTContext().SourceMgr);
@@ -1764,8 +1764,8 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
17641764
void visitDebugValueInst(DebugValueInst *DVI) {
17651765
if (DVI->poisonRefs())
17661766
*this << "[poison] ";
1767-
if (DVI->getWasMoved())
1768-
*this << "[moved] ";
1767+
if (DVI->getUsesMoveableValueDebugInfo())
1768+
*this << "[moveable_value_debuginfo] ";
17691769
if (DVI->hasTrace())
17701770
*this << "[trace] ";
17711771
*this << getIDAndType(DVI->getOperand());

0 commit comments

Comments
 (0)