Skip to content

Commit 1fbc930

Browse files
committed
[region-isolation] Make logging and debug tooling appear in non-asserts builds.
This will just help me to more quickly triage without needing to compile an asserts compiler.
1 parent 2a6c662 commit 1fbc930

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
}

0 commit comments

Comments
 (0)