Skip to content

Commit d630b6d

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. (cherry picked from commit 1fbc930)
1 parent 629aa83 commit d630b6d

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
@@ -47,8 +47,6 @@ using namespace swift::PartitionPrimitives;
4747
using namespace swift::PatternMatch;
4848
using namespace swift::regionanalysisimpl;
4949

50-
#ifndef NDEBUG
51-
5250
bool swift::regionanalysisimpl::AbortOnUnknownPatternMatchError = false;
5351

5452
static llvm::cl::opt<bool, true> AbortOnUnknownPatternMatchErrorCmdLine(
@@ -59,8 +57,6 @@ static llvm::cl::opt<bool, true> AbortOnUnknownPatternMatchErrorCmdLine(
5957
llvm::cl::location(
6058
swift::regionanalysisimpl::AbortOnUnknownPatternMatchError));
6159

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

783780
unsigned bit = getBitForValue(underlyingValue);
784781
auto &state = blockData[op->getParentBlock()];
@@ -898,8 +895,8 @@ void PartialApplyReachabilityDataflow::propagateReachability() {
898895
}
899896
}
900897

901-
LLVM_DEBUG(llvm::dbgs() << "Propagating Captures Result!\n";
902-
print(llvm::dbgs()));
898+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Propagating Captures Result!\n";
899+
print(llvm::dbgs()));
903900
}
904901

905902
void PartialApplyReachabilityDataflow::print(llvm::raw_ostream &os) const {
@@ -1176,9 +1173,11 @@ struct PartitionOpBuilder {
11761173

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

@@ -1433,9 +1432,10 @@ class PartitionOpTranslator {
14331432
RegionAnalysisValueMap &valueMap;
14341433

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

14401440
for (auto &block : *function) {
14411441
for (auto &inst : block) {
@@ -1461,7 +1461,7 @@ class PartitionOpTranslator {
14611461
isNonSendableType(val->getType())) {
14621462
auto trackVal = getTrackableValue(val, true);
14631463
(void)trackVal;
1464-
LLVM_DEBUG(trackVal.print(llvm::dbgs()));
1464+
REGIONBASEDISOLATION_LOG(trackVal.print(llvm::dbgs()));
14651465
continue;
14661466
}
14671467
if (auto *pbi = dyn_cast<ProjectBoxInst>(val)) {
@@ -1489,10 +1489,10 @@ class PartitionOpTranslator {
14891489
builder.translator = this;
14901490
gatherFlowInsensitiveInformationBeforeDataflow();
14911491

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

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

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

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

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

23872391
auto computeOpKind = [&]() -> TranslationSemantics {
23882392
switch (inst->getKind()) {
@@ -2394,7 +2398,7 @@ class PartitionOpTranslator {
23942398
};
23952399

23962400
auto kind = computeOpKind();
2397-
LLVM_DEBUG(llvm::dbgs() << " Semantics: " << kind << '\n');
2401+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Semantics: " << kind << '\n');
23982402
switch (kind) {
23992403
case TranslationSemantics::Ignored:
24002404
return;
@@ -3167,7 +3171,8 @@ PartitionOpTranslator::visitRefElementAddrInst(RefElementAddrInst *reai) {
31673171
// And the field is a let... then ignore it. We know that we cannot race on
31683172
// any writes to the field.
31693173
if (reai->getField()->isLet()) {
3170-
LLVM_DEBUG(llvm::dbgs() << " Found a let! Not tracking!\n");
3174+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
3175+
<< " Found a let! Not tracking!\n");
31713176
return TranslationSemantics::Ignored;
31723177
}
31733178

@@ -3186,7 +3191,7 @@ PartitionOpTranslator::visitRefTailAddrInst(RefTailAddrInst *reai) {
31863191
// And our ref_tail_addr is immutable... we can ignore the access since we
31873192
// cannot race against a write to any of these fields.
31883193
if (reai->isImmutable()) {
3189-
LLVM_DEBUG(
3194+
REGIONBASEDISOLATION_LOG(
31903195
llvm::dbgs()
31913196
<< " Found an immutable Sendable ref_tail_addr! Not tracking!\n");
31923197
return TranslationSemantics::Ignored;
@@ -3323,14 +3328,14 @@ bool BlockPartitionState::recomputeExitFromEntry(
33233328
// will be surpressed. will be suppressed
33243329
eval.apply(partitionOp);
33253330
}
3326-
LLVM_DEBUG(llvm::dbgs() << " Working Partition: ";
3327-
workingPartition.print(llvm::dbgs()));
3331+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Working Partition: ";
3332+
workingPartition.print(llvm::dbgs()));
33283333
bool exitUpdated = !Partition::equals(exitPartition, workingPartition);
33293334
exitPartition = workingPartition;
3330-
LLVM_DEBUG(llvm::dbgs() << " Exit Partition: ";
3331-
exitPartition.print(llvm::dbgs()));
3332-
LLVM_DEBUG(llvm::dbgs() << " Updated Partition: "
3333-
<< (exitUpdated ? "yes\n" : "no\n"));
3335+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Exit Partition: ";
3336+
exitPartition.print(llvm::dbgs()));
3337+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Updated Partition: "
3338+
<< (exitUpdated ? "yes\n" : "no\n"));
33343339
return exitUpdated;
33353340
}
33363341

@@ -3386,7 +3391,8 @@ static bool canComputeRegionsForFunction(SILFunction *fn) {
33863391
}
33873392

33883393
if (!fn->hasOwnership()) {
3389-
LLVM_DEBUG(llvm::dbgs() << "Only runs on Ownership SSA, skipping!\n");
3394+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
3395+
<< "Only runs on Ownership SSA, skipping!\n");
33903396
return false;
33913397
}
33923398

@@ -3450,9 +3456,10 @@ void RegionAnalysisFunctionInfo::runDataflow() {
34503456
assert(!solved && "solve should only be called once");
34513457
solved = true;
34523458

3453-
LLVM_DEBUG(llvm::dbgs() << SEP_STR << "Performing Dataflow!\n" << SEP_STR);
3454-
LLVM_DEBUG(llvm::dbgs() << "Values!\n";
3455-
translator->getValueMap().print(llvm::dbgs()));
3459+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << SEP_STR << "Performing Dataflow!\n"
3460+
<< SEP_STR);
3461+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Values!\n";
3462+
translator->getValueMap().print(llvm::dbgs()));
34563463

34573464
bool anyNeedUpdate = true;
34583465
while (anyNeedUpdate) {
@@ -3462,9 +3469,11 @@ void RegionAnalysisFunctionInfo::runDataflow() {
34623469
auto &blockState = (*blockStates)[block];
34633470
blockState.isLive = true;
34643471

3465-
LLVM_DEBUG(llvm::dbgs() << "Block: bb" << block->getDebugID() << "\n");
3472+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
3473+
<< "Block: bb" << block->getDebugID() << "\n");
34663474
if (!blockState.needsUpdate) {
3467-
LLVM_DEBUG(llvm::dbgs() << " Doesn't need update! Skipping!\n");
3475+
REGIONBASEDISOLATION_LOG(llvm::dbgs()
3476+
<< " Doesn't need update! Skipping!\n");
34683477
continue;
34693478
}
34703479

@@ -3474,7 +3483,7 @@ void RegionAnalysisFunctionInfo::runDataflow() {
34743483
// Compute the new entry partition to this block.
34753484
Partition newEntryPartition = blockState.entryPartition;
34763485

3477-
LLVM_DEBUG(llvm::dbgs() << " Visiting Preds!\n");
3486+
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Visiting Preds!\n");
34783487

34793488
// This loop computes the union of the exit partitions of all
34803489
// predecessors of this block
@@ -3483,9 +3492,9 @@ void RegionAnalysisFunctionInfo::runDataflow() {
34833492

34843493
// Predecessors that have not been reached yet will have an empty pred
34853494
// state... so just merge them all. Also our initial value of
3486-
LLVM_DEBUG(llvm::dbgs()
3487-
<< " Pred. bb" << predBlock->getDebugID() << ": ";
3488-
predState.exitPartition.print(llvm::dbgs()));
3495+
REGIONBASEDISOLATION_LOG(
3496+
llvm::dbgs() << " Pred. bb" << predBlock->getDebugID() << ": ";
3497+
predState.exitPartition.print(llvm::dbgs()));
34893498
newEntryPartition =
34903499
Partition::join(newEntryPartition, predState.exitPartition);
34913500
}

0 commit comments

Comments
 (0)