@@ -1399,13 +1399,14 @@ struct DataflowState {
1399
1399
closureConsumes(closureConsumes) {}
1400
1400
void init ();
1401
1401
bool process (
1402
- SILValue address,
1402
+ SILValue address, DebugVarCarryingInst addressDebugInst,
1403
1403
SmallBlotSetVector<SILInstruction *, 8 > &postDominatingConsumingUsers);
1404
1404
bool handleSingleBlockClosure (SILArgument *address,
1405
1405
ClosureOperandState &state);
1406
1406
bool cleanupAllDestroyAddr (
1407
- SILValue address, SILFunction *fn, SmallBitVector &destroyIndices,
1408
- SmallBitVector &reinitIndices, SmallBitVector &consumingClosureIndices,
1407
+ SILValue address, DebugVarCarryingInst addressDebugInst, SILFunction *fn,
1408
+ SmallBitVector &destroyIndices, SmallBitVector &reinitIndices,
1409
+ SmallBitVector &consumingClosureIndices,
1409
1410
BasicBlockSet &blocksVisitedWhenProcessingNewTakes,
1410
1411
BasicBlockSet &blocksWithMovesThatAreNowTakes,
1411
1412
SmallBlotSetVector<SILInstruction *, 8 > &postDominatingConsumingUsers);
@@ -1423,16 +1424,15 @@ struct DataflowState {
1423
1424
} // namespace
1424
1425
1425
1426
bool DataflowState::cleanupAllDestroyAddr (
1426
- SILValue address, SILFunction *fn, SmallBitVector &destroyIndices,
1427
- SmallBitVector &reinitIndices, SmallBitVector &consumingClosureIndices,
1427
+ SILValue address, DebugVarCarryingInst addressDebugInst, SILFunction *fn,
1428
+ SmallBitVector &destroyIndices, SmallBitVector &reinitIndices,
1429
+ SmallBitVector &consumingClosureIndices,
1428
1430
BasicBlockSet &blocksVisitedWhenProcessingNewTakes,
1429
1431
BasicBlockSet &blocksWithMovesThatAreNowTakes,
1430
1432
SmallBlotSetVector<SILInstruction *, 8 > &postDominatingConsumingUsers) {
1431
1433
bool madeChange = false ;
1432
1434
BasicBlockWorklist worklist (fn);
1433
1435
1434
- auto debugVarInst = DebugVarCarryingInst::getFromValue (address);
1435
-
1436
1436
LLVM_DEBUG (llvm::dbgs () << " Cleanup up destroy addr!\n " );
1437
1437
LLVM_DEBUG (llvm::dbgs () << " Visiting destroys!\n " );
1438
1438
LLVM_DEBUG (llvm::dbgs () << " Destroy Indices: " << destroyIndices << " \n " );
@@ -1537,12 +1537,13 @@ bool DataflowState::cleanupAllDestroyAddr(
1537
1537
convertMemoryReinitToInitForm (*reinit);
1538
1538
1539
1539
// Make sure to create a new debug_value for the reinit value.
1540
- if (debugVarInst ) {
1541
- if (auto varInfo = debugVarInst .getVarInfo ()) {
1540
+ if (addressDebugInst ) {
1541
+ if (auto varInfo = addressDebugInst .getVarInfo ()) {
1542
1542
SILBuilderWithScope reinitBuilder (*reinit);
1543
- reinitBuilder.setCurrentDebugScope (debugVarInst->getDebugScope ());
1544
- reinitBuilder.createDebugValue (debugVarInst.inst ->getLoc (), address,
1545
- *varInfo, false , /* was moved*/ true );
1543
+ reinitBuilder.setCurrentDebugScope (addressDebugInst->getDebugScope ());
1544
+ reinitBuilder.createDebugValue (
1545
+ addressDebugInst.inst ->getLoc (), address, *varInfo, false ,
1546
+ /* was moved*/ true );
1546
1547
}
1547
1548
}
1548
1549
madeChange = true ;
@@ -1583,7 +1584,7 @@ bool DataflowState::cleanupAllDestroyAddr(
1583
1584
}
1584
1585
1585
1586
bool DataflowState::process (
1586
- SILValue address,
1587
+ SILValue address, DebugVarCarryingInst addressDebugInst,
1587
1588
SmallBlotSetVector<SILInstruction *, 8 > &postDominatingConsumingUsers) {
1588
1589
SILFunction *fn = address->getFunction ();
1589
1590
assert (fn);
@@ -1612,6 +1613,7 @@ bool DataflowState::process(
1612
1613
BasicBlockSet blocksVisitedWhenProcessingNewTakes (fn);
1613
1614
BasicBlockSet blocksWithMovesThatAreNowTakes (fn);
1614
1615
bool convertedMarkMoveToTake = false ;
1616
+
1615
1617
for (auto *mvi : markMovesThatPropagateDownwards) {
1616
1618
bool emittedSingleDiagnostic = false ;
1617
1619
@@ -1777,13 +1779,13 @@ bool DataflowState::process(
1777
1779
1778
1780
// Now that we have processed all of our mark_moves, eliminate all of the
1779
1781
// destroy_addr and set our debug value as being moved.
1780
- if (auto debug = DebugVarCarryingInst::getFromValue (address) ) {
1781
- debug .markAsMoved ();
1782
- if (auto varInfo = debug .getVarInfo ()) {
1782
+ if (addressDebugInst ) {
1783
+ addressDebugInst .markAsMoved ();
1784
+ if (auto varInfo = addressDebugInst .getVarInfo ()) {
1783
1785
SILBuilderWithScope undefBuilder (builder);
1784
- undefBuilder.setCurrentDebugScope (debug ->getDebugScope ());
1786
+ undefBuilder.setCurrentDebugScope (addressDebugInst ->getDebugScope ());
1785
1787
undefBuilder.createDebugValue (
1786
- debug ->getLoc (),
1788
+ addressDebugInst ->getLoc (),
1787
1789
SILUndef::get (address->getType (), builder.getModule ()), *varInfo,
1788
1790
false /* poison*/ , true /* was moved*/ );
1789
1791
}
@@ -1806,8 +1808,8 @@ bool DataflowState::process(
1806
1808
// Now that we have processed all of our mark_moves, eliminate all of the
1807
1809
// destroy_addr.
1808
1810
madeChange |= cleanupAllDestroyAddr (
1809
- address, fn, getIndicesOfPairedDestroys (), getIndicesOfPairedReinits (),
1810
- getIndicesOfPairedConsumingClosureUses (),
1811
+ address, addressDebugInst, fn, getIndicesOfPairedDestroys (),
1812
+ getIndicesOfPairedReinits (), getIndicesOfPairedConsumingClosureUses (),
1811
1813
blocksVisitedWhenProcessingNewTakes, blocksWithMovesThatAreNowTakes,
1812
1814
postDominatingConsumingUsers);
1813
1815
@@ -1932,6 +1934,7 @@ struct MoveKillsCopyableAddressesChecker {
1932
1934
void emitDiagnosticForMove (SILValue borrowedValue,
1933
1935
StringRef borrowedValueName, MoveValueInst *mvi);
1934
1936
bool performSingleBasicBlockAnalysis (SILValue address,
1937
+ DebugVarCarryingInst addressDebugInst,
1935
1938
MarkUnresolvedMoveAddrInst *mvi);
1936
1939
1937
1940
ASTContext &getASTContext () const { return fn->getASTContext (); }
@@ -2049,7 +2052,8 @@ bool MoveKillsCopyableAddressesChecker::performClosureDataflow(
2049
2052
// case. Returns false if we visited all of the uses and seeded the UseState
2050
2053
// struct with the information needed to perform our interprocedural dataflow.
2051
2054
bool MoveKillsCopyableAddressesChecker::performSingleBasicBlockAnalysis (
2052
- SILValue address, MarkUnresolvedMoveAddrInst *mvi) {
2055
+ SILValue address, DebugVarCarryingInst addressDebugInst,
2056
+ MarkUnresolvedMoveAddrInst *mvi) {
2053
2057
// First scan downwards to make sure we are move out of this block.
2054
2058
auto &useState = dataflowState.useState ;
2055
2059
auto &applySiteToPromotedArgIndices =
@@ -2075,17 +2079,17 @@ bool MoveKillsCopyableAddressesChecker::performSingleBasicBlockAnalysis(
2075
2079
builder.createCopyAddr (mvi->getLoc (), mvi->getSrc (), mvi->getDest (), IsTake,
2076
2080
IsInitialization);
2077
2081
// Also, mark the alloc_stack as being moved at some point.
2078
- if (auto debug = DebugVarCarryingInst::getFromValue (address) ) {
2079
- if (auto varInfo = debug .getVarInfo ()) {
2082
+ if (addressDebugInst ) {
2083
+ if (auto varInfo = addressDebugInst .getVarInfo ()) {
2080
2084
SILBuilderWithScope undefBuilder (builder);
2081
- undefBuilder.setCurrentDebugScope (debug ->getDebugScope ());
2085
+ undefBuilder.setCurrentDebugScope (addressDebugInst ->getDebugScope ());
2082
2086
undefBuilder.createDebugValue (
2083
- debug ->getLoc (),
2087
+ addressDebugInst ->getLoc (),
2084
2088
SILUndef::get (address->getType (), builder.getModule ()), *varInfo,
2085
2089
false ,
2086
2090
/* was moved*/ true );
2087
2091
}
2088
- debug .markAsMoved ();
2092
+ addressDebugInst .markAsMoved ();
2089
2093
}
2090
2094
2091
2095
useState.destroys .erase (dvi);
@@ -2185,29 +2189,29 @@ bool MoveKillsCopyableAddressesChecker::performSingleBasicBlockAnalysis(
2185
2189
SILBuilderWithScope builder (mvi);
2186
2190
builder.createCopyAddr (mvi->getLoc (), mvi->getSrc (), mvi->getDest (), IsTake,
2187
2191
IsInitialization);
2188
- if (auto debug = DebugVarCarryingInst::getFromValue (address) ) {
2189
- if (auto varInfo = debug .getVarInfo ()) {
2192
+ if (addressDebugInst ) {
2193
+ if (auto varInfo = addressDebugInst .getVarInfo ()) {
2190
2194
{
2191
2195
SILBuilderWithScope undefBuilder (builder);
2192
- undefBuilder.setCurrentDebugScope (debug ->getDebugScope ());
2196
+ undefBuilder.setCurrentDebugScope (addressDebugInst ->getDebugScope ());
2193
2197
undefBuilder.createDebugValue (
2194
- debug ->getLoc (),
2198
+ addressDebugInst ->getLoc (),
2195
2199
SILUndef::get (address->getType (), builder.getModule ()), *varInfo,
2196
2200
false ,
2197
- /* was moved*/ true );
2201
+ /* was moved*/ true );
2198
2202
}
2199
2203
{
2200
2204
// Make sure at the reinit point to create a new debug value after the
2201
2205
// reinit instruction so we reshow the variable.
2202
2206
auto *next = interestingUser->getNextInstruction ();
2203
2207
SILBuilderWithScope reinitBuilder (next);
2204
- reinitBuilder.setCurrentDebugScope (debug ->getDebugScope ());
2205
- reinitBuilder.createDebugValue (debug ->getLoc (), address, *varInfo ,
2206
- false ,
2208
+ reinitBuilder.setCurrentDebugScope (addressDebugInst ->getDebugScope ());
2209
+ reinitBuilder.createDebugValue (addressDebugInst ->getLoc (),
2210
+ address, *varInfo, false ,
2207
2211
/* was moved*/ true );
2208
2212
}
2209
2213
}
2210
- debug .markAsMoved ();
2214
+ addressDebugInst .markAsMoved ();
2211
2215
}
2212
2216
mvi->eraseFromParent ();
2213
2217
return false ;
@@ -2238,17 +2242,17 @@ bool MoveKillsCopyableAddressesChecker::performSingleBasicBlockAnalysis(
2238
2242
LLVM_DEBUG (llvm::dbgs () << " Found apply site to clone: " << **fas);
2239
2243
LLVM_DEBUG (llvm::dbgs () << " BitVector: " ;
2240
2244
dumpBitVector (llvm::dbgs (), bitVector); llvm::dbgs () << ' \n ' );
2241
- if (auto debug = DebugVarCarryingInst::getFromValue (address) ) {
2242
- if (auto varInfo = debug .getVarInfo ()) {
2245
+ if (addressDebugInst ) {
2246
+ if (auto varInfo = addressDebugInst .getVarInfo ()) {
2243
2247
SILBuilderWithScope undefBuilder (builder);
2244
- undefBuilder.setCurrentDebugScope (debug ->getDebugScope ());
2248
+ undefBuilder.setCurrentDebugScope (addressDebugInst ->getDebugScope ());
2245
2249
undefBuilder.createDebugValue (
2246
- debug ->getLoc (),
2250
+ addressDebugInst ->getLoc (),
2247
2251
SILUndef::get (address->getType (), builder.getModule ()), *varInfo,
2248
2252
false ,
2249
2253
/* was moved*/ true );
2250
2254
}
2251
- debug .markAsMoved ();
2255
+ addressDebugInst .markAsMoved ();
2252
2256
}
2253
2257
mvi->eraseFromParent ();
2254
2258
return false ;
@@ -2337,9 +2341,21 @@ bool MoveKillsCopyableAddressesChecker::check(SILValue address) {
2337
2341
// routine also prepares the pass for running the multi-basic block
2338
2342
// diagnostic.
2339
2343
bool emittedSingleBBDiagnostic = false ;
2344
+
2345
+ // Before we process any moves, gather the debug inst associated with our
2346
+ // address.
2347
+ //
2348
+ // NOTE: The reason why we do this early is that we rely on our address
2349
+ // initially having a single DebugValueCarryingInst (either an alloc_stack
2350
+ // itself or a debug_value associated with an argument). If we do this while
2351
+ // processing, as we insert additional debug info we will cause this condition
2352
+ // to begin failing.
2353
+ auto addressDebugInst = DebugVarCarryingInst::getFromValue (address);
2354
+
2340
2355
for (auto *mvi : useState.markMoves ) {
2341
2356
LLVM_DEBUG (llvm::dbgs () << " Performing single block analysis on: " << *mvi);
2342
- emittedSingleBBDiagnostic |= performSingleBasicBlockAnalysis (address, mvi);
2357
+ emittedSingleBBDiagnostic |=
2358
+ performSingleBasicBlockAnalysis (address, addressDebugInst, mvi);
2343
2359
}
2344
2360
2345
2361
if (emittedSingleBBDiagnostic) {
@@ -2359,7 +2375,8 @@ bool MoveKillsCopyableAddressesChecker::check(SILValue address) {
2359
2375
// Ok, we need to perform global dataflow for one of our moves. Initialize our
2360
2376
// dataflow state engine and then run the dataflow itself.
2361
2377
dataflowState.init ();
2362
- bool result = dataflowState.process (address, closureConsumes);
2378
+ bool result = dataflowState.process (
2379
+ address, addressDebugInst, closureConsumes);
2363
2380
return result;
2364
2381
}
2365
2382
0 commit comments