Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d263bf0

Browse files
authoredAug 7, 2024
Merge pull request #75760 from gottesmm/pr-d43ef71ddf97306ef50962d71b306ca6b7ce0b3d
[region-isolation] Make logging and debug tooling appear in non-asserts builds.
2 parents 5482b47 + 1fbc930 commit d263bf0

File tree

5 files changed

+180
-143
lines changed

5 files changed

+180
-143
lines changed
 

‎include/swift/SILOptimizer/Analysis/RegionAnalysis.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,12 @@ class RegionAnalysisValueMap;
2828

2929
namespace regionanalysisimpl {
3030

31-
#ifndef NDEBUG
3231
/// Global bool set only when asserts are enabled to ease debugging by causing
3332
/// unknown pattern errors to cause an assert so we drop into the debugger.
3433
extern bool AbortOnUnknownPatternMatchError;
35-
#endif
3634

3735
static inline bool shouldAbortOnUnknownPatternMatchError() {
38-
#ifndef NDEBUG
3936
return AbortOnUnknownPatternMatchError;
40-
#else
41-
return false;
42-
#endif
4337
}
4438

4539
using TransferringOperandSetFactory = Partition::TransferringOperandSetFactory;

‎include/swift/SILOptimizer/Utils/PartitionUtils.h‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,31 @@ namespace swift {
3636

3737
namespace PartitionPrimitives {
3838

39-
#ifndef NDEBUG
39+
extern bool REGIONBASEDISOLATION_ENABLE_LOGGING;
40+
41+
#ifdef REGIONBASEDISOLATION_LOG
42+
#error "REGIONBASEDISOLATION_LOG already defined?!"
43+
#endif
44+
45+
#define REGIONBASEDISOLATION_LOG(...) \
46+
do { \
47+
if (PartitionPrimitives::REGIONBASEDISOLATION_ENABLE_LOGGING) { \
48+
__VA_ARGS__; \
49+
} \
50+
} while (0);
51+
4052
extern bool REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING;
53+
54+
#ifdef REGIONBASEDISOLATION_VERBOSE_LOG
55+
#error "REGIONBASEDISOLATION_VERBOSE_LOG already defined?!"
56+
#endif
57+
4158
#define REGIONBASEDISOLATION_VERBOSE_LOG(...) \
4259
do { \
4360
if (PartitionPrimitives::REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING) { \
44-
LLVM_DEBUG(__VA_ARGS__); \
61+
__VA_ARGS__; \
4562
} \
4663
} while (0);
47-
#else
48-
#define REGIONBASEDISOLATION_VERBOSE_LOG(...)
49-
#endif
5064

5165
struct Element {
5266
unsigned num;

‎lib/SILOptimizer/Analysis/RegionAnalysis.cpp‎

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ using namespace swift::PartitionPrimitives;
4848
using namespace swift::PatternMatch;
4949
using namespace swift::regionanalysisimpl;
5050

51-
#ifndef NDEBUG
52-
5351
bool swift::regionanalysisimpl::AbortOnUnknownPatternMatchError = false;
5452

5553
static llvm::cl::opt<bool, true> AbortOnUnknownPatternMatchErrorCmdLine(
@@ -60,8 +58,6 @@ static llvm::cl::opt<bool, true> AbortOnUnknownPatternMatchErrorCmdLine(
6058
llvm::cl::location(
6159
swift::regionanalysisimpl::AbortOnUnknownPatternMatchError));
6260

63-
#endif
64-
6561
//===----------------------------------------------------------------------===//
6662
// MARK: Utilities
6763
//===----------------------------------------------------------------------===//
@@ -778,8 +774,9 @@ void PartialApplyReachabilityDataflow::add(Operand *op) {
778774
assert(!propagatedReachability &&
779775
"Cannot add more operands once reachability is computed");
780776
SILValue underlyingValue = getRootValue(op->get());
781-
LLVM_DEBUG(llvm::dbgs() << "PartialApplyReachability::add.\nValue: "
782-
<< underlyingValue << "User: " << *op->getUser());
777+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
778+
<< "PartialApplyReachability::add.\nValue: "
779+
<< underlyingValue << "User: " << *op->getUser());
783780

784781
unsigned bit = getBitForValue(underlyingValue);
785782
auto &state = blockData[op->getParentBlock()];
@@ -899,8 +896,8 @@ void PartialApplyReachabilityDataflow::propagateReachability() {
899896
}
900897
}
901898

902-
LLVM_DEBUG(llvm::dbgs() << "Propagating Captures Result!\n";
903-
print(llvm::dbgs()));
899+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Propagating Captures Result!\n";
900+
print(llvm::dbgs()));
904901
}
905902

906903
void PartialApplyReachabilityDataflow::print(llvm::raw_ostream &os) const {
@@ -1177,9 +1174,11 @@ struct PartitionOpBuilder {
11771174

11781175
Element srcID = lookupValueID(srcOperand->get());
11791176
if (lookupValueID(destValue) == srcID) {
1180-
LLVM_DEBUG(llvm::dbgs() << " Skipping assign since tgt and src have "
1181-
"the same representative.\n");
1182-
LLVM_DEBUG(llvm::dbgs() << " Rep ID: %%" << srcID.num << ".\n");
1177+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
1178+
<< " Skipping assign since tgt and src have "
1179+
"the same representative.\n");
1180+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
1181+
<< " Rep ID: %%" << srcID.num << ".\n");
11831182
return;
11841183
}
11851184

@@ -1434,9 +1433,10 @@ class PartitionOpTranslator {
14341433
RegionAnalysisValueMap &valueMap;
14351434

14361435
void gatherFlowInsensitiveInformationBeforeDataflow() {
1437-
LLVM_DEBUG(llvm::dbgs() << ">>> Performing pre-dataflow scan to gather "
1438-
"flow insensitive information "
1439-
<< function->getName() << ":\n");
1436+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
1437+
<< ">>> Performing pre-dataflow scan to gather "
1438+
"flow insensitive information "
1439+
<< function->getName() << ":\n");
14401440

14411441
for (auto &block : *function) {
14421442
for (auto &inst : block) {
@@ -1462,7 +1462,7 @@ class PartitionOpTranslator {
14621462
isNonSendableType(val->getType())) {
14631463
auto trackVal = getTrackableValue(val, true);
14641464
(void)trackVal;
1465-
LLVM_DEBUG(trackVal.print(llvm::dbgs()));
1465+
REGIONBASEDISOLATION_LOG(trackVal.print(llvm::dbgs()));
14661466
continue;
14671467
}
14681468
if (auto *pbi = dyn_cast<ProjectBoxInst>(val)) {
@@ -1490,10 +1490,10 @@ class PartitionOpTranslator {
14901490
builder.translator = this;
14911491
gatherFlowInsensitiveInformationBeforeDataflow();
14921492

1493-
LLVM_DEBUG(llvm::dbgs() << "Initializing Function Args:\n");
1493+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Initializing Function Args:\n");
14941494
auto functionArguments = function->getArguments();
14951495
if (functionArguments.empty()) {
1496-
LLVM_DEBUG(llvm::dbgs() << " None.\n");
1496+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " None.\n");
14971497
functionArgPartition = Partition::singleRegion(SILLocation::invalid(), {},
14981498
historyFactory.get());
14991499
return;
@@ -1510,19 +1510,20 @@ class PartitionOpTranslator {
15101510
// NOTE: We do not support today the ability to have multiple parameters
15111511
// transfer together as part of the same region.
15121512
if (isTransferrableFunctionArgument(cast<SILFunctionArgument>(arg))) {
1513-
LLVM_DEBUG(llvm::dbgs() << " %%" << state->getID()
1514-
<< " (transferring): " << *arg);
1513+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " %%" << state->getID()
1514+
<< " (transferring): " << *arg);
15151515
nonSendableSeparateIndices.push_back(state->getID());
15161516
continue;
15171517
}
15181518

15191519
// Otherwise, it is one of our merged parameters. Add it to the never
15201520
// transfer list and to the region join list.
1521-
LLVM_DEBUG(llvm::dbgs() << " %%" << state->getID() << ": ";
1522-
state->print(llvm::dbgs()); llvm::dbgs() << *arg);
1521+
REGIONBASEDISOLATION_LOG(
1522+
llvm::dbgs() << " %%" << state->getID() << ": ";
1523+
state->print(llvm::dbgs()); llvm::dbgs() << *arg);
15231524
nonSendableJoinedIndices.push_back(state->getID());
15241525
} else {
1525-
LLVM_DEBUG(llvm::dbgs() << " Sendable: " << *arg);
1526+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Sendable: " << *arg);
15261527
}
15271528
}
15281529

@@ -1665,7 +1666,7 @@ class PartitionOpTranslator {
16651666
// of our arguments (consider isolated to different actors) or with the
16661667
// isolationInfo we specified. Emit an unknown patten error.
16671668
if (!mergedInfo) {
1668-
LLVM_DEBUG(
1669+
REGIONBASEDISOLATION_LOG(
16691670
llvm::dbgs() << "Merge Failure!\n"
16701671
<< "Original Info: ";
16711672
if (originalMergedInfo)
@@ -1829,7 +1830,8 @@ class PartitionOpTranslator {
18291830
}
18301831

18311832
void translateSILPartialApplyAsyncLetBegin(PartialApplyInst *pai) {
1832-
LLVM_DEBUG(llvm::dbgs() << "Translating Async Let Begin Partial Apply!\n");
1833+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
1834+
<< "Translating Async Let Begin Partial Apply!\n");
18331835
// Grab our partial apply and transfer all of its non-sendable
18341836
// parameters. We do not merge the parameters since each individual capture
18351837
// of the async let at the program level is viewed as still being in
@@ -1858,7 +1860,8 @@ class PartitionOpTranslator {
18581860
void translateIsolatedPartialApply(PartialApplyInst *pai,
18591861
SILIsolationInfo actorIsolation) {
18601862
ApplySite applySite(pai);
1861-
LLVM_DEBUG(llvm::dbgs() << "Translating Isolated Partial Apply!\n");
1863+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
1864+
<< "Translating Isolated Partial Apply!\n");
18621865

18631866
// For each argument operand.
18641867
for (auto &op : applySite.getArgumentOperands()) {
@@ -2346,15 +2349,16 @@ class PartitionOpTranslator {
23462349
/// that define the block's dataflow.
23472350
void translateSILBasicBlock(SILBasicBlock *basicBlock,
23482351
std::vector<PartitionOp> &foundPartitionOps) {
2349-
LLVM_DEBUG(llvm::dbgs() << SEP_STR << "Compiling basic block for function "
2350-
<< basicBlock->getFunction()->getName() << ": ";
2351-
basicBlock->dumpID(); llvm::dbgs() << SEP_STR;
2352-
basicBlock->print(llvm::dbgs());
2353-
llvm::dbgs() << SEP_STR << "Results:\n";);
2352+
REGIONBASEDISOLATION_LOG(
2353+
llvm::dbgs() << SEP_STR << "Compiling basic block for function "
2354+
<< basicBlock->getFunction()->getName() << ": ";
2355+
basicBlock->dumpID(); llvm::dbgs() << SEP_STR;
2356+
basicBlock->print(llvm::dbgs());
2357+
llvm::dbgs() << SEP_STR << "Results:\n";);
23542358
// Translate each SIL instruction to the PartitionOps that it represents if
23552359
// any.
23562360
for (auto &instruction : *basicBlock) {
2357-
LLVM_DEBUG(llvm::dbgs() << "Visiting: " << instruction);
2361+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Visiting: " << instruction);
23582362
translateSILInstruction(&instruction);
23592363
copy(builder.currentInstPartitionOps,
23602364
std::back_inserter(foundPartitionOps));
@@ -2383,7 +2387,7 @@ class PartitionOpTranslator {
23832387
/// Top level switch that translates SIL instructions.
23842388
void translateSILInstruction(SILInstruction *inst) {
23852389
builder.reset(inst);
2386-
SWIFT_DEFER { LLVM_DEBUG(builder.print(llvm::dbgs())); };
2390+
SWIFT_DEFER { REGIONBASEDISOLATION_LOG(builder.print(llvm::dbgs())); };
23872391

23882392
auto computeOpKind = [&]() -> TranslationSemantics {
23892393
switch (inst->getKind()) {
@@ -2395,7 +2399,7 @@ class PartitionOpTranslator {
23952399
};
23962400

23972401
auto kind = computeOpKind();
2398-
LLVM_DEBUG(llvm::dbgs() << " Semantics: " << kind << '\n');
2402+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Semantics: " << kind << '\n');
23992403
switch (kind) {
24002404
case TranslationSemantics::Ignored:
24012405
return;
@@ -3170,7 +3174,8 @@ PartitionOpTranslator::visitRefElementAddrInst(RefElementAddrInst *reai) {
31703174
// And the field is a let... then ignore it. We know that we cannot race on
31713175
// any writes to the field.
31723176
if (reai->getField()->isLet()) {
3173-
LLVM_DEBUG(llvm::dbgs() << " Found a let! Not tracking!\n");
3177+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
3178+
<< " Found a let! Not tracking!\n");
31743179
return TranslationSemantics::Ignored;
31753180
}
31763181

@@ -3189,7 +3194,7 @@ PartitionOpTranslator::visitRefTailAddrInst(RefTailAddrInst *reai) {
31893194
// And our ref_tail_addr is immutable... we can ignore the access since we
31903195
// cannot race against a write to any of these fields.
31913196
if (reai->isImmutable()) {
3192-
LLVM_DEBUG(
3197+
REGIONBASEDISOLATION_LOG(
31933198
llvm::dbgs()
31943199
<< " Found an immutable Sendable ref_tail_addr! Not tracking!\n");
31953200
return TranslationSemantics::Ignored;
@@ -3326,14 +3331,14 @@ bool BlockPartitionState::recomputeExitFromEntry(
33263331
// will be surpressed. will be suppressed
33273332
eval.apply(partitionOp);
33283333
}
3329-
LLVM_DEBUG(llvm::dbgs() << " Working Partition: ";
3330-
workingPartition.print(llvm::dbgs()));
3334+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Working Partition: ";
3335+
workingPartition.print(llvm::dbgs()));
33313336
bool exitUpdated = !Partition::equals(exitPartition, workingPartition);
33323337
exitPartition = workingPartition;
3333-
LLVM_DEBUG(llvm::dbgs() << " Exit Partition: ";
3334-
exitPartition.print(llvm::dbgs()));
3335-
LLVM_DEBUG(llvm::dbgs() << " Updated Partition: "
3336-
<< (exitUpdated ? "yes\n" : "no\n"));
3338+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Exit Partition: ";
3339+
exitPartition.print(llvm::dbgs()));
3340+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Updated Partition: "
3341+
<< (exitUpdated ? "yes\n" : "no\n"));
33373342
return exitUpdated;
33383343
}
33393344

@@ -3389,7 +3394,8 @@ static bool canComputeRegionsForFunction(SILFunction *fn) {
33893394
}
33903395

33913396
if (!fn->hasOwnership()) {
3392-
LLVM_DEBUG(llvm::dbgs() << "Only runs on Ownership SSA, skipping!\n");
3397+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
3398+
<< "Only runs on Ownership SSA, skipping!\n");
33933399
return false;
33943400
}
33953401

@@ -3453,9 +3459,10 @@ void RegionAnalysisFunctionInfo::runDataflow() {
34533459
assert(!solved && "solve should only be called once");
34543460
solved = true;
34553461

3456-
LLVM_DEBUG(llvm::dbgs() << SEP_STR << "Performing Dataflow!\n" << SEP_STR);
3457-
LLVM_DEBUG(llvm::dbgs() << "Values!\n";
3458-
translator->getValueMap().print(llvm::dbgs()));
3462+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << SEP_STR << "Performing Dataflow!\n"
3463+
<< SEP_STR);
3464+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Values!\n";
3465+
translator->getValueMap().print(llvm::dbgs()));
34593466

34603467
bool anyNeedUpdate = true;
34613468
while (anyNeedUpdate) {
@@ -3465,9 +3472,11 @@ void RegionAnalysisFunctionInfo::runDataflow() {
34653472
auto &blockState = (*blockStates)[block];
34663473
blockState.isLive = true;
34673474

3468-
LLVM_DEBUG(llvm::dbgs() << "Block: bb" << block->getDebugID() << "\n");
3475+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
3476+
<< "Block: bb" << block->getDebugID() << "\n");
34693477
if (!blockState.needsUpdate) {
3470-
LLVM_DEBUG(llvm::dbgs() << " Doesn't need update! Skipping!\n");
3478+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
3479+
<< " Doesn't need update! Skipping!\n");
34713480
continue;
34723481
}
34733482

@@ -3477,7 +3486,7 @@ void RegionAnalysisFunctionInfo::runDataflow() {
34773486
// Compute the new entry partition to this block.
34783487
Partition newEntryPartition = blockState.entryPartition;
34793488

3480-
LLVM_DEBUG(llvm::dbgs() << " Visiting Preds!\n");
3489+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Visiting Preds!\n");
34813490

34823491
// This loop computes the union of the exit partitions of all
34833492
// predecessors of this block
@@ -3486,9 +3495,9 @@ void RegionAnalysisFunctionInfo::runDataflow() {
34863495

34873496
// Predecessors that have not been reached yet will have an empty pred
34883497
// state... so just merge them all. Also our initial value of
3489-
LLVM_DEBUG(llvm::dbgs()
3490-
<< " Pred. bb" << predBlock->getDebugID() << ": ";
3491-
predState.exitPartition.print(llvm::dbgs()));
3498+
REGIONBASEDISOLATION_LOG(
3499+
llvm::dbgs() << " Pred. bb" << predBlock->getDebugID() << ": ";
3500+
predState.exitPartition.print(llvm::dbgs()));
34923501
newEntryPartition =
34933502
Partition::join(newEntryPartition, predState.exitPartition);
34943503
}

‎lib/SILOptimizer/Mandatory/TransferNonSendable.cpp‎

Lines changed: 91 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ struct RequireLiveness {
326326
} // namespace
327327

328328
void RequireLiveness::processDefBlock() {
329-
LLVM_DEBUG(llvm::dbgs() << " Processing def block!\n");
329+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Processing def block!\n");
330330
// First walk from the beginning of the block to the transfer instruction to
331331
// see if we have any requires before our def. Once we find one, we can skip
332332
// the traversal and jump straight to the transfer.
@@ -335,8 +335,9 @@ void RequireLiveness::processDefBlock() {
335335
ii != ie; ++ii) {
336336
if (allRequires.contains(&*ii) && !firstRequireBeforeTransferInDefBlock) {
337337
firstRequireBeforeTransferInDefBlock = &*ii;
338-
LLVM_DEBUG(llvm::dbgs() << " Found transfer before def: "
339-
<< *firstRequireBeforeTransferInDefBlock);
338+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
339+
<< " Found transfer before def: "
340+
<< *firstRequireBeforeTransferInDefBlock);
340341
break;
341342
}
342343
}
@@ -353,7 +354,8 @@ void RequireLiveness::processDefBlock() {
353354
continue;
354355

355356
finalRequires.insert(&*ii);
356-
LLVM_DEBUG(llvm::dbgs() << " Found transfer after def: " << *ii);
357+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
358+
<< " Found transfer after def: " << *ii);
357359
return;
358360
}
359361
}
@@ -370,13 +372,14 @@ void RequireLiveness::processNonDefBlock(SILBasicBlock *block) {
370372

371373
template <typename Collection>
372374
void RequireLiveness::process(Collection requireInstList) {
373-
LLVM_DEBUG(llvm::dbgs() << "==> Performing Require Liveness for: "
374-
<< *transferInst);
375+
REGIONBASEDISOLATION_LOG(
376+
llvm::dbgs() << "==> Performing Require Liveness for: " << *transferInst);
375377

376378
// Then put all of our requires into our allRequires set.
377379
BasicBlockWorklist initializingWorklist(transferInst->getFunction());
378380
for (auto require : requireInstList) {
379-
LLVM_DEBUG(llvm::dbgs() << " Require Inst: " << **require);
381+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
382+
<< " Require Inst: " << **require);
380383
allRequires.insert(*require);
381384
initializingWorklist.pushIfNotVisited(require->getParent());
382385
}
@@ -388,19 +391,20 @@ void RequireLiveness::process(Collection requireInstList) {
388391
// If we found /any/ requries after the transferInst, we can bail early since
389392
// that is guaranteed to dominate all further requires.
390393
if (!finalRequires.empty()) {
391-
LLVM_DEBUG(
394+
REGIONBASEDISOLATION_LOG(
392395
llvm::dbgs()
393396
<< " Found transfer after def in def block! Exiting early!\n");
394397
return;
395398
}
396399

397-
LLVM_DEBUG(llvm::dbgs() << " Did not find transfer after def in def "
398-
"block! Walking blocks!\n");
400+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
401+
<< " Did not find transfer after def in def "
402+
"block! Walking blocks!\n");
399403

400404
// If we found a transfer in the def block before our def, add it to the block
401405
// state for the def.
402406
if (firstRequireBeforeTransferInDefBlock) {
403-
LLVM_DEBUG(
407+
REGIONBASEDISOLATION_LOG(
404408
llvm::dbgs()
405409
<< " Found a require before transfer! Adding to block state!\n");
406410
auto blockState = blockLivenessInfo.get(transferInst->getParent());
@@ -414,8 +418,9 @@ void RequireLiveness::process(Collection requireInstList) {
414418
for (auto &inst : *requireBlock) {
415419
if (!allRequires.contains(&inst))
416420
continue;
417-
LLVM_DEBUG(llvm::dbgs() << " Mapping Block bb"
418-
<< requireBlock->getDebugID() << " to: " << inst);
421+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Mapping Block bb"
422+
<< requireBlock->getDebugID()
423+
<< " to: " << inst);
419424
blockState.get()->setInst(generation, &inst);
420425
break;
421426
}
@@ -1193,13 +1198,15 @@ void TransferNonSendableImpl::emitUseAfterTransferDiagnostics() {
11931198
if (transferOpToRequireInstMultiMap.empty())
11941199
return;
11951200

1196-
LLVM_DEBUG(llvm::dbgs() << "Emitting use after transfer diagnostics.\n");
1201+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
1202+
<< "Emitting use after transfer diagnostics.\n");
11971203

11981204
for (auto [transferOp, requireInsts] :
11991205
transferOpToRequireInstMultiMap.getRange()) {
1200-
LLVM_DEBUG(llvm::dbgs()
1201-
<< "Transfer Op. Number: " << transferOp->getOperandNumber()
1202-
<< ". User: " << *transferOp->getUser());
1206+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
1207+
<< "Transfer Op. Number: "
1208+
<< transferOp->getOperandNumber()
1209+
<< ". User: " << *transferOp->getUser());
12031210

12041211
// Then look for our requires before we emit any error. We want to emit a
12051212
// single we don't understand error if we do not find the require.
@@ -1785,7 +1792,7 @@ void TransferNonSendableImpl::emitTransferredNonTransferrableDiagnostics() {
17851792
if (transferredNonTransferrableInfoList.empty())
17861793
return;
17871794

1788-
LLVM_DEBUG(
1795+
REGIONBASEDISOLATION_LOG(
17891796
llvm::dbgs() << "Emitting transfer non transferrable diagnostics.\n");
17901797

17911798
for (auto info : transferredNonTransferrableInfoList) {
@@ -2186,14 +2193,15 @@ struct DiagnosticEvaluator final
21862193
}
21872194

21882195
auto rep = info->getValueMap().getRepresentative(transferredVal);
2189-
LLVM_DEBUG(llvm::dbgs()
2190-
<< " Emitting Use After Transfer Error!\n"
2191-
<< " Transferring Inst: " << *transferringOp->getUser()
2192-
<< " Transferring Op Value: " << transferringOp->get()
2193-
<< " Require Inst: " << *partitionOp.getSourceInst()
2194-
<< " ID: %%" << transferredVal << "\n"
2195-
<< " Rep: " << *rep << " Transferring Op Num: "
2196-
<< transferringOp->getOperandNumber() << '\n');
2196+
REGIONBASEDISOLATION_LOG(
2197+
llvm::dbgs()
2198+
<< " Emitting Use After Transfer Error!\n"
2199+
<< " Transferring Inst: " << *transferringOp->getUser()
2200+
<< " Transferring Op Value: " << transferringOp->get()
2201+
<< " Require Inst: " << *partitionOp.getSourceInst()
2202+
<< " ID: %%" << transferredVal << "\n"
2203+
<< " Rep: " << *rep << " Transferring Op Num: "
2204+
<< transferringOp->getOperandNumber() << '\n');
21972205
transferOpToRequireInstMultiMap.insert(
21982206
transferringOp,
21992207
RequireInst::forUseAfterTransfer(partitionOp.getSourceInst()));
@@ -2202,14 +2210,14 @@ struct DiagnosticEvaluator final
22022210
void handleTransferNonTransferrable(
22032211
const PartitionOp &partitionOp, Element transferredVal,
22042212
SILDynamicMergedIsolationInfo isolationRegionInfo) const {
2205-
LLVM_DEBUG(llvm::dbgs()
2206-
<< " Emitting TransferNonTransferrable Error!\n"
2207-
<< " ID: %%" << transferredVal << "\n"
2208-
<< " Rep: "
2209-
<< *info->getValueMap().getRepresentative(transferredVal)
2210-
<< " Dynamic Isolation Region: ";
2211-
isolationRegionInfo.printForDiagnostics(llvm::dbgs());
2212-
llvm::dbgs() << '\n');
2213+
REGIONBASEDISOLATION_LOG(
2214+
llvm::dbgs() << " Emitting TransferNonTransferrable Error!\n"
2215+
<< " ID: %%" << transferredVal << "\n"
2216+
<< " Rep: "
2217+
<< *info->getValueMap().getRepresentative(transferredVal)
2218+
<< " Dynamic Isolation Region: ";
2219+
isolationRegionInfo.printForDiagnostics(llvm::dbgs());
2220+
llvm::dbgs() << '\n');
22132221
auto *self = const_cast<DiagnosticEvaluator *>(this);
22142222
auto nonTransferrableValue =
22152223
info->getValueMap().getRepresentative(transferredVal);
@@ -2221,15 +2229,15 @@ struct DiagnosticEvaluator final
22212229
void handleInOutSendingNotDisconnectedAtExitError(
22222230
const PartitionOp &partitionOp, Element inoutSendingVal,
22232231
SILDynamicMergedIsolationInfo isolationRegionInfo) const {
2224-
LLVM_DEBUG(llvm::dbgs()
2225-
<< " Emitting InOut Sending ActorIsolated at end of "
2226-
"Function Error!\n"
2227-
<< " ID: %%" << inoutSendingVal << "\n"
2228-
<< " Rep: "
2229-
<< *info->getValueMap().getRepresentative(inoutSendingVal)
2230-
<< " Dynamic Isolation Region: ";
2231-
isolationRegionInfo.printForDiagnostics(llvm::dbgs());
2232-
llvm::dbgs() << '\n');
2232+
REGIONBASEDISOLATION_LOG(
2233+
llvm::dbgs() << " Emitting InOut Sending ActorIsolated at end of "
2234+
"Function Error!\n"
2235+
<< " ID: %%" << inoutSendingVal << "\n"
2236+
<< " Rep: "
2237+
<< *info->getValueMap().getRepresentative(inoutSendingVal)
2238+
<< " Dynamic Isolation Region: ";
2239+
isolationRegionInfo.printForDiagnostics(llvm::dbgs());
2240+
llvm::dbgs() << '\n');
22332241
auto *self = const_cast<DiagnosticEvaluator *>(this);
22342242
auto nonTransferrableValue =
22352243
info->getValueMap().getRepresentative(inoutSendingVal);
@@ -2243,30 +2251,30 @@ struct DiagnosticEvaluator final
22432251
const PartitionOp &partitionOp, Element transferredVal,
22442252
Element actualNonTransferrableValue,
22452253
SILDynamicMergedIsolationInfo isolationRegionInfo) const {
2246-
LLVM_DEBUG(llvm::dbgs()
2247-
<< " Emitting TransferNonTransferrable Error!\n"
2248-
<< " ID: %%" << transferredVal << "\n"
2249-
<< " Rep: "
2250-
<< *info->getValueMap().getRepresentative(transferredVal)
2251-
<< " Dynamic Isolation Region: ";
2252-
isolationRegionInfo.printForDiagnostics(llvm::dbgs());
2253-
llvm::dbgs() << '\n');
2254+
REGIONBASEDISOLATION_LOG(
2255+
llvm::dbgs() << " Emitting TransferNonTransferrable Error!\n"
2256+
<< " ID: %%" << transferredVal << "\n"
2257+
<< " Rep: "
2258+
<< *info->getValueMap().getRepresentative(transferredVal)
2259+
<< " Dynamic Isolation Region: ";
2260+
isolationRegionInfo.printForDiagnostics(llvm::dbgs());
2261+
llvm::dbgs() << '\n');
22542262

22552263
auto *self = const_cast<DiagnosticEvaluator *>(this);
22562264
// If we have a non-actor introducing fake representative value, just use
22572265
// the value that actually introduced the actor isolation.
22582266
if (auto nonTransferrableValue = info->getValueMap().maybeGetRepresentative(
22592267
actualNonTransferrableValue)) {
2260-
LLVM_DEBUG(llvm::dbgs()
2261-
<< " ActualTransfer: " << nonTransferrableValue);
2268+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " ActualTransfer: "
2269+
<< nonTransferrableValue);
22622270
self->transferredNonTransferrable.emplace_back(partitionOp.getSourceOp(),
22632271
nonTransferrableValue,
22642272
isolationRegionInfo);
22652273
} else if (auto *nonTransferrableInst =
22662274
info->getValueMap().maybeGetActorIntroducingInst(
22672275
actualNonTransferrableValue)) {
2268-
LLVM_DEBUG(llvm::dbgs()
2269-
<< " ActualTransfer: " << *nonTransferrableInst);
2276+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " ActualTransfer: "
2277+
<< *nonTransferrableInst);
22702278
self->transferredNonTransferrable.emplace_back(
22712279
partitionOp.getSourceOp(), nonTransferrableInst, isolationRegionInfo);
22722280
} else {
@@ -2287,7 +2295,7 @@ struct DiagnosticEvaluator final
22872295
SILFunctionArgument *destValue, Element srcElement, SILValue srcValue,
22882296
SILDynamicMergedIsolationInfo srcIsolationRegionInfo) const {
22892297
auto srcRep = info->getValueMap().getRepresentativeValue(srcElement);
2290-
LLVM_DEBUG(
2298+
REGIONBASEDISOLATION_LOG(
22912299
llvm::dbgs()
22922300
<< " Emitting Error! Kind: Assign Isolated Into Sending Result!\n"
22932301
<< " Assign Inst: " << *partitionOp.getSourceInst()
@@ -2306,14 +2314,15 @@ struct DiagnosticEvaluator final
23062314
Element inoutSendingVal,
23072315
Operand *transferringOp) const {
23082316
auto rep = info->getValueMap().getRepresentative(inoutSendingVal);
2309-
LLVM_DEBUG(llvm::dbgs()
2310-
<< " Emitting InOut Not Reinitialized At End Of Function!\n"
2311-
<< " Transferring Inst: " << *transferringOp->getUser()
2312-
<< " Transferring Op Value: " << transferringOp->get()
2313-
<< " Require Inst: " << *partitionOp.getSourceInst()
2314-
<< " ID: %%" << inoutSendingVal << "\n"
2315-
<< " Rep: " << *rep << " Transferring Op Num: "
2316-
<< transferringOp->getOperandNumber() << '\n');
2317+
REGIONBASEDISOLATION_LOG(
2318+
llvm::dbgs()
2319+
<< " Emitting InOut Not Reinitialized At End Of Function!\n"
2320+
<< " Transferring Inst: " << *transferringOp->getUser()
2321+
<< " Transferring Op Value: " << transferringOp->get()
2322+
<< " Require Inst: " << *partitionOp.getSourceInst()
2323+
<< " ID: %%" << inoutSendingVal << "\n"
2324+
<< " Rep: " << *rep << " Transferring Op Num: "
2325+
<< transferringOp->getOperandNumber() << '\n');
23172326
transferOpToRequireInstMultiMap.insert(
23182327
transferringOp, RequireInst::forInOutReinitializationNeeded(
23192328
partitionOp.getSourceInst()));
@@ -2372,17 +2381,19 @@ struct DiagnosticEvaluator final
23722381

23732382
void TransferNonSendableImpl::runDiagnosticEvaluator() {
23742383
// Then for each block...
2375-
LLVM_DEBUG(llvm::dbgs() << "Walking blocks for diagnostics.\n");
2384+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Walking blocks for diagnostics.\n");
23762385
for (auto [block, blockState] : regionInfo->getRange()) {
2377-
LLVM_DEBUG(llvm::dbgs() << "|--> Block bb" << block.getDebugID() << "\n");
2386+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
2387+
<< "|--> Block bb" << block.getDebugID() << "\n");
23782388

23792389
if (!blockState.getLiveness()) {
2380-
LLVM_DEBUG(llvm::dbgs() << "Dead block... skipping!\n");
2390+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Dead block... skipping!\n");
23812391
continue;
23822392
}
23832393

2384-
LLVM_DEBUG(llvm::dbgs() << "Entry Partition: ";
2385-
blockState.getEntryPartition().print(llvm::dbgs()));
2394+
REGIONBASEDISOLATION_LOG(
2395+
llvm::dbgs() << "Entry Partition: ";
2396+
blockState.getEntryPartition().print(llvm::dbgs()));
23862397

23872398
// Grab its entry partition and setup an evaluator for the partition that
23882399
// has callbacks that emit diagnsotics...
@@ -2399,11 +2410,12 @@ void TransferNonSendableImpl::runDiagnosticEvaluator() {
23992410
eval.apply(partitionOp);
24002411
}
24012412

2402-
LLVM_DEBUG(llvm::dbgs() << "Exit Partition: ";
2403-
workingPartition.print(llvm::dbgs()));
2413+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Exit Partition: ";
2414+
workingPartition.print(llvm::dbgs()));
24042415
}
24052416

2406-
LLVM_DEBUG(llvm::dbgs() << "Finished walking blocks for diagnostics.\n");
2417+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
2418+
<< "Finished walking blocks for diagnostics.\n");
24072419

24082420
// Now that we have found all of our transferInsts/Requires emit errors.
24092421
transferOpToRequireInstMultiMap.setFrozen();
@@ -2418,8 +2430,8 @@ void TransferNonSendableImpl::runDiagnosticEvaluator() {
24182430
/// state.
24192431
void TransferNonSendableImpl::emitDiagnostics() {
24202432
auto *function = regionInfo->getFunction();
2421-
LLVM_DEBUG(llvm::dbgs() << "Emitting diagnostics for function "
2422-
<< function->getName() << "\n");
2433+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Emitting diagnostics for function "
2434+
<< function->getName() << "\n");
24232435

24242436
runDiagnosticEvaluator();
24252437
emitTransferredNonTransferrableDiagnostics();
@@ -2436,14 +2448,15 @@ class TransferNonSendable : public SILFunctionTransform {
24362448

24372449
auto *functionInfo = getAnalysis<RegionAnalysis>()->get(function);
24382450
if (!functionInfo->isSupportedFunction()) {
2439-
LLVM_DEBUG(llvm::dbgs() << "===> SKIPPING UNSUPPORTED FUNCTION: "
2440-
<< function->getName() << '\n');
2451+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
2452+
<< "===> SKIPPING UNSUPPORTED FUNCTION: "
2453+
<< function->getName() << '\n');
24412454

24422455
return;
24432456
}
24442457

2445-
LLVM_DEBUG(llvm::dbgs()
2446-
<< "===> PROCESSING: " << function->getName() << '\n');
2458+
REGIONBASEDISOLATION_LOG(
2459+
llvm::dbgs() << "===> PROCESSING: " << function->getName() << '\n');
24472460

24482461
TransferNonSendableImpl impl(functionInfo);
24492462
impl.emitDiagnostics();

‎lib/SILOptimizer/Utils/PartitionUtils.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ using namespace swift::PartitionPrimitives;
3131
// MARK: Logging
3232
//===----------------------------------------------------------------------===//
3333

34-
#ifndef NDEBUG
34+
bool swift::PartitionPrimitives::REGIONBASEDISOLATION_ENABLE_LOGGING;
35+
36+
static llvm::cl::opt<bool, true> // The parser
37+
RegionBasedIsolationLog(
38+
"sil-regionbasedisolation-log",
39+
llvm::cl::desc("Enable logging for SIL region based isolation "
40+
"diagnostics"),
41+
llvm::cl::Hidden,
42+
llvm::cl::location(
43+
swift::PartitionPrimitives::REGIONBASEDISOLATION_ENABLE_LOGGING));
3544

3645
bool swift::PartitionPrimitives::REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING;
3746

@@ -44,8 +53,6 @@ static llvm::cl::opt<bool, true> // The parser
4453
llvm::cl::location(swift::PartitionPrimitives::
4554
REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING));
4655

47-
#endif
48-
4956
//===----------------------------------------------------------------------===//
5057
// MARK: PartitionOp
5158
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)
Please sign in to comment.