@@ -3121,6 +3121,12 @@ bool MoveOnlyAddressCheckerPImpl::performSingleCheck(
3121
3121
// [copy] + begin_borrow for further processing. This just eliminates a case
3122
3122
// that the checker doesn't need to know about.
3123
3123
{
3124
+ LLVM_DEBUG (llvm::dbgs ()
3125
+ << " ===>>> Started CopiedLoadBorrowEliminationVisitor!\n " );
3126
+ SWIFT_DEFER {
3127
+ LLVM_DEBUG (llvm::dbgs ()
3128
+ << " ===<<< Finished CopiedLoadBorrowEliminationVisitor!\n " );
3129
+ };
3124
3130
CopiedLoadBorrowEliminationState state (markedAddress->getFunction ());
3125
3131
CopiedLoadBorrowEliminationVisitor copiedLoadBorrowEliminator (state);
3126
3132
if (AddressUseKind::Unknown ==
@@ -3142,12 +3148,20 @@ bool MoveOnlyAddressCheckerPImpl::performSingleCheck(
3142
3148
// SILGen will treat y as a separate rvalue from x and will create a temporary
3143
3149
// allocation. In contrast if we have a var, we treat x like an lvalue and
3144
3150
// just create GEPs appropriately.
3145
- if (eliminateTemporaryAllocationsFromLet (markedAddress)) {
3146
- LLVM_DEBUG (
3147
- llvm::dbgs ()
3148
- << " Succeeded in eliminating temporary allocations! Fn after:\n " ;
3149
- markedAddress->getFunction ()->dump ());
3150
- changed = true ;
3151
+ {
3152
+ LLVM_DEBUG (llvm::dbgs () << " ===>>> Trying to eliminate temporary "
3153
+ " allocations if we have a let!\n " );
3154
+ SWIFT_DEFER {
3155
+ LLVM_DEBUG (llvm::dbgs () << " ===<<< Completed eliminate temporary "
3156
+ " allocations if we have a let!\n " );
3157
+ };
3158
+ if (eliminateTemporaryAllocationsFromLet (markedAddress)) {
3159
+ LLVM_DEBUG (
3160
+ llvm::dbgs ()
3161
+ << " Succeeded in eliminating temporary allocations! Fn after:\n " ;
3162
+ markedAddress->getFunction ()->dump ());
3163
+ changed = true ;
3164
+ }
3151
3165
}
3152
3166
3153
3167
// Then gather all uses of our address by walking from def->uses. We use this
@@ -3156,10 +3170,21 @@ bool MoveOnlyAddressCheckerPImpl::performSingleCheck(
3156
3170
GatherUsesVisitor visitor (*this , addressUseState, markedAddress,
3157
3171
diagnosticEmitter);
3158
3172
SWIFT_DEFER { visitor.clear (); };
3159
- visitor.reset (markedAddress);
3160
- if (AddressUseKind::Unknown == std::move (visitor).walk (markedAddress)) {
3161
- LLVM_DEBUG (llvm::dbgs () << " Failed access path visit: " << *markedAddress);
3162
- return false ;
3173
+
3174
+ {
3175
+ LLVM_DEBUG (llvm::dbgs ()
3176
+ << " ===>>> Beginning main use gathering visitor!\n " );
3177
+ SWIFT_DEFER {
3178
+ LLVM_DEBUG (llvm::dbgs ()
3179
+ << " ===<<< Completed main use gathering visitor!\n " );
3180
+ };
3181
+
3182
+ visitor.reset (markedAddress);
3183
+ if (AddressUseKind::Unknown == std::move (visitor).walk (markedAddress)) {
3184
+ LLVM_DEBUG (llvm::dbgs ()
3185
+ << " Failed access path visit: " << *markedAddress);
3186
+ return false ;
3187
+ }
3163
3188
}
3164
3189
3165
3190
// If we found a load [copy] or copy_addr that requires multiple copies or an
@@ -3187,18 +3212,27 @@ bool MoveOnlyAddressCheckerPImpl::performSingleCheck(
3187
3212
// ===---
3188
3213
// Liveness Checking
3189
3214
//
3215
+
3190
3216
SmallVector<SILBasicBlock *, 32 > discoveredBlocks;
3191
3217
FieldSensitiveMultiDefPrunedLiveRange liveness (fn, markedAddress,
3192
3218
&discoveredBlocks);
3193
- addressUseState.initializeLiveness (liveness);
3194
3219
3195
- // Then compute the takes that are within the cumulative boundary of
3196
- // liveness that we have computed. If we find any, they are the errors ones.
3197
- GlobalLivenessChecker emitter (addressUseState, diagnosticEmitter, liveness);
3220
+ {
3221
+ LLVM_DEBUG (llvm::dbgs () << " ===>>> Performing liveness checking!\n " );
3222
+ SWIFT_DEFER {
3223
+ LLVM_DEBUG (llvm::dbgs () << " ===<<< Completed liveness checking!\n " );
3224
+ };
3198
3225
3199
- // If we had any errors, we do not want to modify the SIL... just bail.
3200
- if (emitter.compute ()) {
3201
- return true ;
3226
+ addressUseState.initializeLiveness (liveness);
3227
+
3228
+ // Then compute the takes that are within the cumulative boundary of
3229
+ // liveness that we have computed. If we find any, they are the errors ones.
3230
+ GlobalLivenessChecker emitter (addressUseState, diagnosticEmitter, liveness);
3231
+
3232
+ // If we had any errors, we do not want to modify the SIL... just bail.
3233
+ if (emitter.compute ()) {
3234
+ return true ;
3235
+ }
3202
3236
}
3203
3237
3204
3238
// ===
@@ -3242,15 +3276,40 @@ bool MoveOnlyAddressCheckerPImpl::performSingleCheck(
3242
3276
// MARK: Top Level Entrypoint
3243
3277
// ===----------------------------------------------------------------------===//
3244
3278
3279
+ #ifndef NDEBUG
3280
+ static llvm::cl::opt<uint64_t > NumTopLevelToProcess (
3281
+ " sil-move-only-address-checker-num-top-level-to-process" ,
3282
+ llvm::cl::desc (" Allows for bisecting on move introducer that causes an "
3283
+ " error. Only meant for debugging!" ),
3284
+ llvm::cl::init(UINT64_MAX));
3285
+ #endif
3286
+
3287
+ static llvm::cl::opt<bool > DumpSILBeforeRemovingMarkMustCheck (
3288
+ " sil-move-only-address-checker-dump-before-removing-mark-must-check" ,
3289
+ llvm::cl::desc (" When bisecting it is useful to dump the SIL before the "
3290
+ " rest of the checker removes mark_must_check. This lets one "
3291
+ " grab the SIL of a bad variable after all of the rest have "
3292
+ " been processed to work with further in sil-opt." ),
3293
+ llvm::cl::init(false ));
3294
+
3245
3295
bool MoveOnlyAddressChecker::check (
3246
3296
SmallSetVector<MarkMustCheckInst *, 32 > &moveIntroducersToProcess) {
3247
3297
assert (moveIntroducersToProcess.size () &&
3248
3298
" Must have checks to process to call this function" );
3249
3299
MoveOnlyAddressCheckerPImpl pimpl (fn, diagnosticEmitter, domTree, poa,
3250
3300
allocator);
3251
3301
3302
+ #ifndef NDEBUG
3303
+ static uint64_t numProcessed = 0 ;
3304
+ #endif
3252
3305
for (auto *markedValue : moveIntroducersToProcess) {
3253
- LLVM_DEBUG (llvm::dbgs () << " Visiting: " << *markedValue);
3306
+ #ifndef NDEBUG
3307
+ ++numProcessed;
3308
+ if (NumTopLevelToProcess <= numProcessed)
3309
+ break ;
3310
+ #endif
3311
+ LLVM_DEBUG (llvm::dbgs ()
3312
+ << " ======>>> Visiting top level: " << *markedValue);
3254
3313
3255
3314
// Perform our address check.
3256
3315
unsigned diagnosticEmittedByEarlierPassCount =
@@ -3271,5 +3330,10 @@ bool MoveOnlyAddressChecker::check(
3271
3330
}
3272
3331
}
3273
3332
3333
+ if (DumpSILBeforeRemovingMarkMustCheck) {
3334
+ LLVM_DEBUG (llvm::dbgs ()
3335
+ << " Dumping SIL before removing mark must checks!\n " ;
3336
+ fn->dump ());
3337
+ }
3274
3338
return pimpl.changed ;
3275
3339
}
0 commit comments