Skip to content

Commit 11dd0e4

Browse files
committed
[NFC] SIL: Typed debug_value's wasMoved.
Help avoid errors with boolean flags by using the new UsesMoveableValueDebugInfo_t.
1 parent e10d595 commit 11dd0e4

10 files changed

+67
-61
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,15 +1053,15 @@ class SILBuilder {
10531053
MarkFunctionEscapeInst::create(getSILDebugLocation(Loc), vars, getFunction()));
10541054
}
10551055

1056-
DebugValueInst *createDebugValue(SILLocation Loc, SILValue src,
1057-
SILDebugVariable Var,
1058-
bool poisonRefs = false,
1059-
bool wasMoved = false,
1060-
bool trace = false);
1061-
DebugValueInst *createDebugValueAddr(SILLocation Loc, SILValue src,
1062-
SILDebugVariable Var,
1063-
bool wasMoved = false,
1064-
bool trace = false);
1056+
DebugValueInst *createDebugValue(
1057+
SILLocation Loc, SILValue src, SILDebugVariable Var,
1058+
bool poisonRefs = false,
1059+
UsesMoveableValueDebugInfo_t wasMoved = DoesNotUseMoveableValueDebugInfo,
1060+
bool trace = false);
1061+
DebugValueInst *createDebugValueAddr(
1062+
SILLocation Loc, SILValue src, SILDebugVariable Var,
1063+
UsesMoveableValueDebugInfo_t wasMoved = DoesNotUseMoveableValueDebugInfo,
1064+
bool trace = false);
10651065

10661066
DebugStepInst *createDebugStep(SILLocation Loc) {
10671067
return insert(new (getModule()) DebugStepInst(getSILDebugLocation(Loc)));

include/swift/SIL/SILInstruction.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,8 +2476,9 @@ class AllocBoxInst final
24762476
(bool)UsesMoveableValueDebugInfo;
24772477
}
24782478

2479-
bool usesMoveableValueDebugInfo() const {
2480-
return sharedUInt8().AllocBoxInst.usesMoveableValueDebugInfo;
2479+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo() const {
2480+
return UsesMoveableValueDebugInfo_t(
2481+
sharedUInt8().AllocBoxInst.usesMoveableValueDebugInfo);
24812482
}
24822483
};
24832484

@@ -5256,15 +5257,17 @@ class DebugValueInst final
52565257
USE_SHARED_UINT8;
52575258

52585259
DebugValueInst(SILDebugLocation DebugLoc, SILValue Operand,
5259-
SILDebugVariable Var, bool poisonRefs, bool operandWasMoved,
5260-
bool trace);
5260+
SILDebugVariable Var, bool poisonRefs,
5261+
UsesMoveableValueDebugInfo_t operandWasMoved, bool trace);
52615262
static DebugValueInst *create(SILDebugLocation DebugLoc, SILValue Operand,
52625263
SILModule &M, SILDebugVariable Var,
5263-
bool poisonRefs, bool operandWasMoved,
5264+
bool poisonRefs,
5265+
UsesMoveableValueDebugInfo_t operandWasMoved,
52645266
bool trace);
52655267
static DebugValueInst *createAddr(SILDebugLocation DebugLoc, SILValue Operand,
52665268
SILModule &M, SILDebugVariable Var,
5267-
bool operandWasMoved, bool trace);
5269+
UsesMoveableValueDebugInfo_t wasMoved,
5270+
bool trace);
52685271

52695272
SIL_DEBUG_VAR_SUPPLEMENT_TRAILING_OBJS_IMPL()
52705273

@@ -5273,15 +5276,17 @@ class DebugValueInst final
52735276
public:
52745277
/// Sets a bool that states this debug_value is supposed to use the
52755278
void setUsesMoveableValueDebugInfo() {
5276-
sharedUInt8().DebugValueInst.usesMoveableValueDebugInfo = true;
5279+
sharedUInt8().DebugValueInst.usesMoveableValueDebugInfo =
5280+
(bool)UsesMoveableValueDebugInfo;
52775281
}
52785282

52795283
/// True if this debug_value is on an SSA value that was moved.
52805284
///
52815285
/// IRGen uses this information to determine if we should use llvm.dbg.addr or
52825286
/// llvm.dbg.declare.
5283-
bool usesMoveableValueDebugInfo() const {
5284-
return sharedUInt8().DebugValueInst.usesMoveableValueDebugInfo;
5287+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo() const {
5288+
return UsesMoveableValueDebugInfo_t(
5289+
sharedUInt8().DebugValueInst.usesMoveableValueDebugInfo);
52855290
}
52865291

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

lib/SIL/IR/SILBuilder.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ void SILBuilder::emitDestructureValueOperation(
631631
DebugValueInst *SILBuilder::createDebugValue(SILLocation Loc, SILValue src,
632632
SILDebugVariable Var,
633633
bool poisonRefs,
634-
bool operandWasMoved,
634+
UsesMoveableValueDebugInfo_t moved,
635635
bool trace) {
636636
if (shouldDropVariable(Var, Loc))
637637
return nullptr;
@@ -640,15 +640,14 @@ DebugValueInst *SILBuilder::createDebugValue(SILLocation Loc, SILValue src,
640640

641641
// Debug location overrides cannot apply to debug value instructions.
642642
DebugLocOverrideRAII LocOverride{*this, std::nullopt};
643-
return insert(DebugValueInst::create(getSILDebugLocation(Loc, true), src,
644-
getModule(),
645-
*substituteAnonymousArgs(Name, Var, Loc),
646-
poisonRefs, operandWasMoved, trace));
643+
return insert(DebugValueInst::create(
644+
getSILDebugLocation(Loc, true), src, getModule(),
645+
*substituteAnonymousArgs(Name, Var, Loc), poisonRefs, moved, trace));
647646
}
648647

649-
DebugValueInst *SILBuilder::createDebugValueAddr(SILLocation Loc, SILValue src,
650-
SILDebugVariable Var,
651-
bool wasMoved, bool trace) {
648+
DebugValueInst *SILBuilder::createDebugValueAddr(
649+
SILLocation Loc, SILValue src, SILDebugVariable Var,
650+
UsesMoveableValueDebugInfo_t moved, bool trace) {
652651
if (shouldDropVariable(Var, Loc))
653652
return nullptr;
654653

@@ -658,7 +657,7 @@ DebugValueInst *SILBuilder::createDebugValueAddr(SILLocation Loc, SILValue src,
658657
DebugLocOverrideRAII LocOverride{*this, std::nullopt};
659658
return insert(DebugValueInst::createAddr(
660659
getSILDebugLocation(Loc, true), src, getModule(),
661-
*substituteAnonymousArgs(Name, Var, Loc), wasMoved, trace));
660+
*substituteAnonymousArgs(Name, Var, Loc), moved, trace));
662661
}
663662

664663
void SILBuilder::emitScopedBorrowOperation(SILLocation loc, SILValue original,

lib/SIL/IR/SILInstructions.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,10 @@ SILType AllocBoxInst::getAddressType() const {
436436
.getAddressType();
437437
}
438438

439-
DebugValueInst::DebugValueInst(SILDebugLocation DebugLoc, SILValue Operand,
440-
SILDebugVariable Var, bool poisonRefs,
441-
bool usesMoveableValueDebugInfo, bool trace)
439+
DebugValueInst::DebugValueInst(
440+
SILDebugLocation DebugLoc, SILValue Operand, SILDebugVariable Var,
441+
bool poisonRefs, UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo,
442+
bool trace)
442443
: UnaryInstructionBase(DebugLoc, Operand),
443444
SILDebugVariableSupplement(Var.DIExpr.getNumElements(),
444445
Var.Type.has_value(), Var.Loc.has_value(),
@@ -458,16 +459,17 @@ DebugValueInst::DebugValueInst(SILDebugLocation DebugLoc, SILValue Operand,
458459
DebugValueInst *DebugValueInst::create(SILDebugLocation DebugLoc,
459460
SILValue Operand, SILModule &M,
460461
SILDebugVariable Var, bool poisonRefs,
461-
bool wasMoved, bool trace) {
462+
UsesMoveableValueDebugInfo_t wasMoved,
463+
bool trace) {
462464
void *buf = allocateDebugVarCarryingInst<DebugValueInst>(M, Var);
463465
return ::new (buf)
464466
DebugValueInst(DebugLoc, Operand, Var, poisonRefs, wasMoved, trace);
465467
}
466468

467-
DebugValueInst *DebugValueInst::createAddr(SILDebugLocation DebugLoc,
468-
SILValue Operand, SILModule &M,
469-
SILDebugVariable Var,
470-
bool wasMoved, bool trace) {
469+
DebugValueInst *
470+
DebugValueInst::createAddr(SILDebugLocation DebugLoc, SILValue Operand,
471+
SILModule &M, SILDebugVariable Var,
472+
UsesMoveableValueDebugInfo_t wasMoved, bool trace) {
471473
// For alloc_stack, debug_value is used to annotate the associated
472474
// memory location, so we shouldn't attach op_deref.
473475
if (!isa<AllocStackInst>(Operand))

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3387,7 +3387,8 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
33873387
case SILInstructionKind::DebugValueInst: {
33883388
bool poisonRefs = false;
33893389
bool hasTrace = false;
3390-
bool usesMoveableValueDebugInfo = false;
3390+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo =
3391+
DoesNotUseMoveableValueDebugInfo;
33913392
SILDebugVariable VarInfo;
33923393

33933394
// Allow for poison and moved to be in either order.
@@ -3399,7 +3400,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
33993400
else if (attributeName == "trace")
34003401
hasTrace = true;
34013402
else if (attributeName == "moveable_value_debuginfo")
3402-
usesMoveableValueDebugInfo = true;
3403+
usesMoveableValueDebugInfo = UsesMoveableValueDebugInfo;
34033404
else {
34043405
P.diagnose(attributeLoc, diag::sil_invalid_attribute_for_instruction,
34053406
attributeName, "debug_value");
@@ -3414,7 +3415,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
34143415
assert(!poisonRefs && "debug_value w/ address value does not support poison");
34153416

34163417
if (Val->getType().isMoveOnly())
3417-
usesMoveableValueDebugInfo = true;
3418+
usesMoveableValueDebugInfo = UsesMoveableValueDebugInfo;
34183419

34193420
ResultVal = B.createDebugValue(InstLoc, Val, VarInfo, poisonRefs,
34203421
usesMoveableValueDebugInfo, hasTrace);

lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableAddressesChecker.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,10 +1507,9 @@ bool DataflowState::cleanupAllDestroyAddr(
15071507
SILBuilderWithScope dbgValueInsertBuilder(dvi);
15081508
dbgValueInsertBuilder.setCurrentDebugScope(
15091509
addressDebugInst->getDebugScope());
1510-
dbgValueInsertBuilder.createDebugValue((*addressDebugInst)->getLoc(),
1511-
SILUndef::get(address),
1512-
*varInfo, false,
1513-
/*was moved*/ true);
1510+
dbgValueInsertBuilder.createDebugValue(
1511+
(*addressDebugInst)->getLoc(), SILUndef::get(address), *varInfo,
1512+
false, UsesMoveableValueDebugInfo);
15141513
}
15151514
}
15161515
useState.destroys.insert(dvi);
@@ -1551,7 +1550,7 @@ bool DataflowState::cleanupAllDestroyAddr(
15511550
reinitBuilder.setCurrentDebugScope(addressDebugInst->getDebugScope());
15521551
reinitBuilder.createDebugValue((*addressDebugInst)->getLoc(), address,
15531552
*varInfo, false,
1554-
/*was moved*/ true);
1553+
UsesMoveableValueDebugInfo);
15551554
}
15561555
}
15571556
madeChange = true;
@@ -1792,9 +1791,9 @@ bool DataflowState::process(
17921791
if (auto varInfo = addressDebugInst.getVarInfo()) {
17931792
SILBuilderWithScope undefBuilder(builder);
17941793
undefBuilder.setCurrentDebugScope(addressDebugInst->getDebugScope());
1795-
undefBuilder.createDebugValue(addressDebugInst->getLoc(),
1796-
SILUndef::get(address), *varInfo,
1797-
false /*poison*/, true /*was moved*/);
1794+
undefBuilder.createDebugValue(
1795+
addressDebugInst->getLoc(), SILUndef::get(address), *varInfo,
1796+
false /*poison*/, UsesMoveableValueDebugInfo);
17981797
}
17991798
}
18001799

@@ -2090,7 +2089,7 @@ bool ConsumeOperatorCopyableAddressesChecker::performSingleBasicBlockAnalysis(
20902089
undefBuilder.setCurrentDebugScope(addressDebugInst->getDebugScope());
20912090
undefBuilder.createDebugValue(addressDebugInst->getLoc(),
20922091
SILUndef::get(address), *varInfo, false,
2093-
/*was moved*/ true);
2092+
UsesMoveableValueDebugInfo);
20942093
}
20952094
addressDebugInst.markAsMoved();
20962095
}
@@ -2199,7 +2198,7 @@ bool ConsumeOperatorCopyableAddressesChecker::performSingleBasicBlockAnalysis(
21992198
undefBuilder.setCurrentDebugScope(addressDebugInst->getDebugScope());
22002199
undefBuilder.createDebugValue(addressDebugInst->getLoc(),
22012200
SILUndef::get(address), *varInfo, false,
2202-
/*was moved*/ true);
2201+
UsesMoveableValueDebugInfo);
22032202
}
22042203
{
22052204
// Make sure at the reinit point to create a new debug value after the
@@ -2209,7 +2208,7 @@ bool ConsumeOperatorCopyableAddressesChecker::performSingleBasicBlockAnalysis(
22092208
reinitBuilder.setCurrentDebugScope(addressDebugInst->getDebugScope());
22102209
reinitBuilder.createDebugValue(addressDebugInst->getLoc(), address,
22112210
*varInfo, false,
2212-
/*was moved*/ true);
2211+
UsesMoveableValueDebugInfo);
22132212
}
22142213
}
22152214
addressDebugInst.markAsMoved();
@@ -2249,7 +2248,7 @@ bool ConsumeOperatorCopyableAddressesChecker::performSingleBasicBlockAnalysis(
22492248
undefBuilder.setCurrentDebugScope(addressDebugInst->getDebugScope());
22502249
undefBuilder.createDebugValue(addressDebugInst->getLoc(),
22512250
SILUndef::get(address), *varInfo, false,
2252-
/*was moved*/ true);
2251+
UsesMoveableValueDebugInfo);
22532252
}
22542253
addressDebugInst.markAsMoved();
22552254
}

lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableValuesChecker.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,9 @@ bool ConsumeOperatorCopyableValuesChecker::check() {
492492
// scope as our original so that the backend treats them as
493493
// referring to the same "debug entity".
494494
builder.setCurrentDebugScope(dbgVarInst->getDebugScope());
495-
builder.createDebugValue(dbgVarInst->getLoc(),
496-
SILUndef::get(mvi->getOperand()), *varInfo,
497-
false /*poison*/, true /*moved*/);
495+
builder.createDebugValue(
496+
dbgVarInst->getLoc(), SILUndef::get(mvi->getOperand()),
497+
*varInfo, false /*poison*/, UsesMoveableValueDebugInfo);
498498
}
499499
}
500500
foundMove = true;

lib/SILOptimizer/Mandatory/DebugInfoCanonicalizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static SILInstruction *cloneDebugValue(DebugVarCarryingInst original,
7575
builder.setCurrentDebugScope(original->getDebugScope());
7676
return builder.createDebugValue(
7777
original->getLoc(), original.getOperandForDebugValueClone(),
78-
*original.getVarInfo(), false, true /*was moved*/);
78+
*original.getVarInfo(), false, UsesMoveableValueDebugInfo);
7979
}
8080

8181
static SILInstruction *cloneDebugValue(DebugVarCarryingInst original,
@@ -84,7 +84,7 @@ static SILInstruction *cloneDebugValue(DebugVarCarryingInst original,
8484
builder.setCurrentDebugScope(original->getDebugScope());
8585
return builder.createDebugValue(
8686
original->getLoc(), original.getOperandForDebugValueClone(),
87-
*original.getVarInfo(), false, true /*was moved*/);
87+
*original.getVarInfo(), false, UsesMoveableValueDebugInfo);
8888
}
8989

9090
//===----------------------------------------------------------------------===//

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ static void insertDebugValueBefore(SILInstruction *insertPt,
320320
}
321321
SILBuilderWithScope debugInfoBuilder(insertPt);
322322
debugInfoBuilder.setCurrentDebugScope(debugVar->getDebugScope());
323-
debugInfoBuilder.createDebugValue(debugVar->getLoc(), operand(),
324-
*varInfo, false, true);
323+
debugInfoBuilder.createDebugValue(debugVar->getLoc(), operand(), *varInfo,
324+
false, UsesMoveableValueDebugInfo);
325325
}
326326

327327
static void convertMemoryReinitToInitForm(SILInstruction *memInst,

lib/SILOptimizer/Mandatory/MovedAsyncVarDebugInfoPropagator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ cloneDebugValueMakeUndef(DebugVarCarryingInst original, SILBasicBlock *block) {
9696
auto *undef = SILUndef::get(original.getOperandForDebugValueClone());
9797
return builder.createDebugValue(original->getLoc(), undef,
9898
*original.getVarInfo(), false,
99-
true /*was moved*/);
99+
UsesMoveableValueDebugInfo);
100100
}
101101

102102
static DebugVarCarryingInst
@@ -107,7 +107,7 @@ cloneDebugValueMakeUndef(DebugVarCarryingInst original,
107107
auto *undef = SILUndef::get(original.getOperandForDebugValueClone());
108108
return builder.createDebugValue(original->getLoc(), undef,
109109
*original.getVarInfo(), false,
110-
true /*was moved*/);
110+
UsesMoveableValueDebugInfo);
111111
}
112112

113113
static SILInstruction *cloneDebugValue(DebugVarCarryingInst original,
@@ -119,7 +119,7 @@ static SILInstruction *cloneDebugValue(DebugVarCarryingInst original,
119119
builder.setCurrentDebugScope(original->getDebugScope());
120120
return builder.createDebugValue(
121121
original->getLoc(), original.getOperandForDebugValueClone(),
122-
*original.getVarInfo(), false, true /*was moved*/);
122+
*original.getVarInfo(), false, UsesMoveableValueDebugInfo);
123123
}
124124

125125
static SILInstruction *cloneDebugValue(DebugVarCarryingInst original,
@@ -131,7 +131,7 @@ static SILInstruction *cloneDebugValue(DebugVarCarryingInst original,
131131
builder.setCurrentDebugScope(original->getDebugScope());
132132
return builder.createDebugValue(
133133
original->getLoc(), original.getOperandForDebugValueClone(),
134-
*original.getVarInfo(), false, true /*was moved*/);
134+
*original.getVarInfo(), false, UsesMoveableValueDebugInfo);
135135
}
136136

137137
namespace {

0 commit comments

Comments
 (0)