diff --git a/include/swift/SILOptimizer/Analysis/RegionAnalysis.h b/include/swift/SILOptimizer/Analysis/RegionAnalysis.h index 12fd0c2cc42f4..ce34620c38766 100644 --- a/include/swift/SILOptimizer/Analysis/RegionAnalysis.h +++ b/include/swift/SILOptimizer/Analysis/RegionAnalysis.h @@ -28,18 +28,12 @@ class RegionAnalysisValueMap; namespace regionanalysisimpl { -#ifndef NDEBUG /// Global bool set only when asserts are enabled to ease debugging by causing /// unknown pattern errors to cause an assert so we drop into the debugger. extern bool AbortOnUnknownPatternMatchError; -#endif static inline bool shouldAbortOnUnknownPatternMatchError() { -#ifndef NDEBUG return AbortOnUnknownPatternMatchError; -#else - return false; -#endif } using TransferringOperandSetFactory = Partition::TransferringOperandSetFactory; diff --git a/include/swift/SILOptimizer/Utils/PartitionUtils.h b/include/swift/SILOptimizer/Utils/PartitionUtils.h index 8cac507bc068c..b1e0796619b70 100644 --- a/include/swift/SILOptimizer/Utils/PartitionUtils.h +++ b/include/swift/SILOptimizer/Utils/PartitionUtils.h @@ -36,17 +36,31 @@ namespace swift { namespace PartitionPrimitives { -#ifndef NDEBUG +extern bool REGIONBASEDISOLATION_ENABLE_LOGGING; + +#ifdef REGIONBASEDISOLATION_LOG +#error "REGIONBASEDISOLATION_LOG already defined?!" +#endif + +#define REGIONBASEDISOLATION_LOG(...) \ + do { \ + if (PartitionPrimitives::REGIONBASEDISOLATION_ENABLE_LOGGING) { \ + __VA_ARGS__; \ + } \ + } while (0); + extern bool REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING; + +#ifdef REGIONBASEDISOLATION_VERBOSE_LOG +#error "REGIONBASEDISOLATION_VERBOSE_LOG already defined?!" +#endif + #define REGIONBASEDISOLATION_VERBOSE_LOG(...) \ do { \ if (PartitionPrimitives::REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING) { \ - LLVM_DEBUG(__VA_ARGS__); \ + __VA_ARGS__; \ } \ } while (0); -#else -#define REGIONBASEDISOLATION_VERBOSE_LOG(...) -#endif struct Element { unsigned num; diff --git a/lib/SILOptimizer/Analysis/RegionAnalysis.cpp b/lib/SILOptimizer/Analysis/RegionAnalysis.cpp index 46a4b6fa42b2b..052bc6d99ff68 100644 --- a/lib/SILOptimizer/Analysis/RegionAnalysis.cpp +++ b/lib/SILOptimizer/Analysis/RegionAnalysis.cpp @@ -48,8 +48,6 @@ using namespace swift::PartitionPrimitives; using namespace swift::PatternMatch; using namespace swift::regionanalysisimpl; -#ifndef NDEBUG - bool swift::regionanalysisimpl::AbortOnUnknownPatternMatchError = false; static llvm::cl::opt AbortOnUnknownPatternMatchErrorCmdLine( @@ -60,8 +58,6 @@ static llvm::cl::opt AbortOnUnknownPatternMatchErrorCmdLine( llvm::cl::location( swift::regionanalysisimpl::AbortOnUnknownPatternMatchError)); -#endif - //===----------------------------------------------------------------------===// // MARK: Utilities //===----------------------------------------------------------------------===// @@ -778,8 +774,9 @@ void PartialApplyReachabilityDataflow::add(Operand *op) { assert(!propagatedReachability && "Cannot add more operands once reachability is computed"); SILValue underlyingValue = getRootValue(op->get()); - LLVM_DEBUG(llvm::dbgs() << "PartialApplyReachability::add.\nValue: " - << underlyingValue << "User: " << *op->getUser()); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << "PartialApplyReachability::add.\nValue: " + << underlyingValue << "User: " << *op->getUser()); unsigned bit = getBitForValue(underlyingValue); auto &state = blockData[op->getParentBlock()]; @@ -899,8 +896,8 @@ void PartialApplyReachabilityDataflow::propagateReachability() { } } - LLVM_DEBUG(llvm::dbgs() << "Propagating Captures Result!\n"; - print(llvm::dbgs())); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Propagating Captures Result!\n"; + print(llvm::dbgs())); } void PartialApplyReachabilityDataflow::print(llvm::raw_ostream &os) const { @@ -1177,9 +1174,11 @@ struct PartitionOpBuilder { Element srcID = lookupValueID(srcOperand->get()); if (lookupValueID(destValue) == srcID) { - LLVM_DEBUG(llvm::dbgs() << " Skipping assign since tgt and src have " - "the same representative.\n"); - LLVM_DEBUG(llvm::dbgs() << " Rep ID: %%" << srcID.num << ".\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << " Skipping assign since tgt and src have " + "the same representative.\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << " Rep ID: %%" << srcID.num << ".\n"); return; } @@ -1434,9 +1433,10 @@ class PartitionOpTranslator { RegionAnalysisValueMap &valueMap; void gatherFlowInsensitiveInformationBeforeDataflow() { - LLVM_DEBUG(llvm::dbgs() << ">>> Performing pre-dataflow scan to gather " - "flow insensitive information " - << function->getName() << ":\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << ">>> Performing pre-dataflow scan to gather " + "flow insensitive information " + << function->getName() << ":\n"); for (auto &block : *function) { for (auto &inst : block) { @@ -1462,7 +1462,7 @@ class PartitionOpTranslator { isNonSendableType(val->getType())) { auto trackVal = getTrackableValue(val, true); (void)trackVal; - LLVM_DEBUG(trackVal.print(llvm::dbgs())); + REGIONBASEDISOLATION_LOG(trackVal.print(llvm::dbgs())); continue; } if (auto *pbi = dyn_cast(val)) { @@ -1490,10 +1490,10 @@ class PartitionOpTranslator { builder.translator = this; gatherFlowInsensitiveInformationBeforeDataflow(); - LLVM_DEBUG(llvm::dbgs() << "Initializing Function Args:\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Initializing Function Args:\n"); auto functionArguments = function->getArguments(); if (functionArguments.empty()) { - LLVM_DEBUG(llvm::dbgs() << " None.\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << " None.\n"); functionArgPartition = Partition::singleRegion(SILLocation::invalid(), {}, historyFactory.get()); return; @@ -1510,19 +1510,20 @@ class PartitionOpTranslator { // NOTE: We do not support today the ability to have multiple parameters // transfer together as part of the same region. if (isTransferrableFunctionArgument(cast(arg))) { - LLVM_DEBUG(llvm::dbgs() << " %%" << state->getID() - << " (transferring): " << *arg); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << " %%" << state->getID() + << " (transferring): " << *arg); nonSendableSeparateIndices.push_back(state->getID()); continue; } // Otherwise, it is one of our merged parameters. Add it to the never // transfer list and to the region join list. - LLVM_DEBUG(llvm::dbgs() << " %%" << state->getID() << ": "; - state->print(llvm::dbgs()); llvm::dbgs() << *arg); + REGIONBASEDISOLATION_LOG( + llvm::dbgs() << " %%" << state->getID() << ": "; + state->print(llvm::dbgs()); llvm::dbgs() << *arg); nonSendableJoinedIndices.push_back(state->getID()); } else { - LLVM_DEBUG(llvm::dbgs() << " Sendable: " << *arg); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Sendable: " << *arg); } } @@ -1665,7 +1666,7 @@ class PartitionOpTranslator { // of our arguments (consider isolated to different actors) or with the // isolationInfo we specified. Emit an unknown patten error. if (!mergedInfo) { - LLVM_DEBUG( + REGIONBASEDISOLATION_LOG( llvm::dbgs() << "Merge Failure!\n" << "Original Info: "; if (originalMergedInfo) @@ -1829,7 +1830,8 @@ class PartitionOpTranslator { } void translateSILPartialApplyAsyncLetBegin(PartialApplyInst *pai) { - LLVM_DEBUG(llvm::dbgs() << "Translating Async Let Begin Partial Apply!\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << "Translating Async Let Begin Partial Apply!\n"); // Grab our partial apply and transfer all of its non-sendable // parameters. We do not merge the parameters since each individual capture // of the async let at the program level is viewed as still being in @@ -1858,7 +1860,8 @@ class PartitionOpTranslator { void translateIsolatedPartialApply(PartialApplyInst *pai, SILIsolationInfo actorIsolation) { ApplySite applySite(pai); - LLVM_DEBUG(llvm::dbgs() << "Translating Isolated Partial Apply!\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << "Translating Isolated Partial Apply!\n"); // For each argument operand. for (auto &op : applySite.getArgumentOperands()) { @@ -2346,15 +2349,16 @@ class PartitionOpTranslator { /// that define the block's dataflow. void translateSILBasicBlock(SILBasicBlock *basicBlock, std::vector &foundPartitionOps) { - LLVM_DEBUG(llvm::dbgs() << SEP_STR << "Compiling basic block for function " - << basicBlock->getFunction()->getName() << ": "; - basicBlock->dumpID(); llvm::dbgs() << SEP_STR; - basicBlock->print(llvm::dbgs()); - llvm::dbgs() << SEP_STR << "Results:\n";); + REGIONBASEDISOLATION_LOG( + llvm::dbgs() << SEP_STR << "Compiling basic block for function " + << basicBlock->getFunction()->getName() << ": "; + basicBlock->dumpID(); llvm::dbgs() << SEP_STR; + basicBlock->print(llvm::dbgs()); + llvm::dbgs() << SEP_STR << "Results:\n";); // Translate each SIL instruction to the PartitionOps that it represents if // any. for (auto &instruction : *basicBlock) { - LLVM_DEBUG(llvm::dbgs() << "Visiting: " << instruction); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Visiting: " << instruction); translateSILInstruction(&instruction); copy(builder.currentInstPartitionOps, std::back_inserter(foundPartitionOps)); @@ -2383,7 +2387,7 @@ class PartitionOpTranslator { /// Top level switch that translates SIL instructions. void translateSILInstruction(SILInstruction *inst) { builder.reset(inst); - SWIFT_DEFER { LLVM_DEBUG(builder.print(llvm::dbgs())); }; + SWIFT_DEFER { REGIONBASEDISOLATION_LOG(builder.print(llvm::dbgs())); }; auto computeOpKind = [&]() -> TranslationSemantics { switch (inst->getKind()) { @@ -2395,7 +2399,7 @@ class PartitionOpTranslator { }; auto kind = computeOpKind(); - LLVM_DEBUG(llvm::dbgs() << " Semantics: " << kind << '\n'); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Semantics: " << kind << '\n'); switch (kind) { case TranslationSemantics::Ignored: return; @@ -3170,7 +3174,8 @@ PartitionOpTranslator::visitRefElementAddrInst(RefElementAddrInst *reai) { // And the field is a let... then ignore it. We know that we cannot race on // any writes to the field. if (reai->getField()->isLet()) { - LLVM_DEBUG(llvm::dbgs() << " Found a let! Not tracking!\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << " Found a let! Not tracking!\n"); return TranslationSemantics::Ignored; } @@ -3189,7 +3194,7 @@ PartitionOpTranslator::visitRefTailAddrInst(RefTailAddrInst *reai) { // And our ref_tail_addr is immutable... we can ignore the access since we // cannot race against a write to any of these fields. if (reai->isImmutable()) { - LLVM_DEBUG( + REGIONBASEDISOLATION_LOG( llvm::dbgs() << " Found an immutable Sendable ref_tail_addr! Not tracking!\n"); return TranslationSemantics::Ignored; @@ -3326,14 +3331,14 @@ bool BlockPartitionState::recomputeExitFromEntry( // will be surpressed. will be suppressed eval.apply(partitionOp); } - LLVM_DEBUG(llvm::dbgs() << " Working Partition: "; - workingPartition.print(llvm::dbgs())); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Working Partition: "; + workingPartition.print(llvm::dbgs())); bool exitUpdated = !Partition::equals(exitPartition, workingPartition); exitPartition = workingPartition; - LLVM_DEBUG(llvm::dbgs() << " Exit Partition: "; - exitPartition.print(llvm::dbgs())); - LLVM_DEBUG(llvm::dbgs() << " Updated Partition: " - << (exitUpdated ? "yes\n" : "no\n")); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Exit Partition: "; + exitPartition.print(llvm::dbgs())); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Updated Partition: " + << (exitUpdated ? "yes\n" : "no\n")); return exitUpdated; } @@ -3389,7 +3394,8 @@ static bool canComputeRegionsForFunction(SILFunction *fn) { } if (!fn->hasOwnership()) { - LLVM_DEBUG(llvm::dbgs() << "Only runs on Ownership SSA, skipping!\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << "Only runs on Ownership SSA, skipping!\n"); return false; } @@ -3453,9 +3459,10 @@ void RegionAnalysisFunctionInfo::runDataflow() { assert(!solved && "solve should only be called once"); solved = true; - LLVM_DEBUG(llvm::dbgs() << SEP_STR << "Performing Dataflow!\n" << SEP_STR); - LLVM_DEBUG(llvm::dbgs() << "Values!\n"; - translator->getValueMap().print(llvm::dbgs())); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << SEP_STR << "Performing Dataflow!\n" + << SEP_STR); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Values!\n"; + translator->getValueMap().print(llvm::dbgs())); bool anyNeedUpdate = true; while (anyNeedUpdate) { @@ -3465,9 +3472,11 @@ void RegionAnalysisFunctionInfo::runDataflow() { auto &blockState = (*blockStates)[block]; blockState.isLive = true; - LLVM_DEBUG(llvm::dbgs() << "Block: bb" << block->getDebugID() << "\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << "Block: bb" << block->getDebugID() << "\n"); if (!blockState.needsUpdate) { - LLVM_DEBUG(llvm::dbgs() << " Doesn't need update! Skipping!\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << " Doesn't need update! Skipping!\n"); continue; } @@ -3477,7 +3486,7 @@ void RegionAnalysisFunctionInfo::runDataflow() { // Compute the new entry partition to this block. Partition newEntryPartition = blockState.entryPartition; - LLVM_DEBUG(llvm::dbgs() << " Visiting Preds!\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Visiting Preds!\n"); // This loop computes the union of the exit partitions of all // predecessors of this block @@ -3486,9 +3495,9 @@ void RegionAnalysisFunctionInfo::runDataflow() { // Predecessors that have not been reached yet will have an empty pred // state... so just merge them all. Also our initial value of - LLVM_DEBUG(llvm::dbgs() - << " Pred. bb" << predBlock->getDebugID() << ": "; - predState.exitPartition.print(llvm::dbgs())); + REGIONBASEDISOLATION_LOG( + llvm::dbgs() << " Pred. bb" << predBlock->getDebugID() << ": "; + predState.exitPartition.print(llvm::dbgs())); newEntryPartition = Partition::join(newEntryPartition, predState.exitPartition); } diff --git a/lib/SILOptimizer/Mandatory/TransferNonSendable.cpp b/lib/SILOptimizer/Mandatory/TransferNonSendable.cpp index 880529ca55764..0b8da0f2dde34 100644 --- a/lib/SILOptimizer/Mandatory/TransferNonSendable.cpp +++ b/lib/SILOptimizer/Mandatory/TransferNonSendable.cpp @@ -326,7 +326,7 @@ struct RequireLiveness { } // namespace void RequireLiveness::processDefBlock() { - LLVM_DEBUG(llvm::dbgs() << " Processing def block!\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Processing def block!\n"); // First walk from the beginning of the block to the transfer instruction to // see if we have any requires before our def. Once we find one, we can skip // the traversal and jump straight to the transfer. @@ -335,8 +335,9 @@ void RequireLiveness::processDefBlock() { ii != ie; ++ii) { if (allRequires.contains(&*ii) && !firstRequireBeforeTransferInDefBlock) { firstRequireBeforeTransferInDefBlock = &*ii; - LLVM_DEBUG(llvm::dbgs() << " Found transfer before def: " - << *firstRequireBeforeTransferInDefBlock); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << " Found transfer before def: " + << *firstRequireBeforeTransferInDefBlock); break; } } @@ -353,7 +354,8 @@ void RequireLiveness::processDefBlock() { continue; finalRequires.insert(&*ii); - LLVM_DEBUG(llvm::dbgs() << " Found transfer after def: " << *ii); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << " Found transfer after def: " << *ii); return; } } @@ -370,13 +372,14 @@ void RequireLiveness::processNonDefBlock(SILBasicBlock *block) { template void RequireLiveness::process(Collection requireInstList) { - LLVM_DEBUG(llvm::dbgs() << "==> Performing Require Liveness for: " - << *transferInst); + REGIONBASEDISOLATION_LOG( + llvm::dbgs() << "==> Performing Require Liveness for: " << *transferInst); // Then put all of our requires into our allRequires set. BasicBlockWorklist initializingWorklist(transferInst->getFunction()); for (auto require : requireInstList) { - LLVM_DEBUG(llvm::dbgs() << " Require Inst: " << **require); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << " Require Inst: " << **require); allRequires.insert(*require); initializingWorklist.pushIfNotVisited(require->getParent()); } @@ -388,19 +391,20 @@ void RequireLiveness::process(Collection requireInstList) { // If we found /any/ requries after the transferInst, we can bail early since // that is guaranteed to dominate all further requires. if (!finalRequires.empty()) { - LLVM_DEBUG( + REGIONBASEDISOLATION_LOG( llvm::dbgs() << " Found transfer after def in def block! Exiting early!\n"); return; } - LLVM_DEBUG(llvm::dbgs() << " Did not find transfer after def in def " - "block! Walking blocks!\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << " Did not find transfer after def in def " + "block! Walking blocks!\n"); // If we found a transfer in the def block before our def, add it to the block // state for the def. if (firstRequireBeforeTransferInDefBlock) { - LLVM_DEBUG( + REGIONBASEDISOLATION_LOG( llvm::dbgs() << " Found a require before transfer! Adding to block state!\n"); auto blockState = blockLivenessInfo.get(transferInst->getParent()); @@ -414,8 +418,9 @@ void RequireLiveness::process(Collection requireInstList) { for (auto &inst : *requireBlock) { if (!allRequires.contains(&inst)) continue; - LLVM_DEBUG(llvm::dbgs() << " Mapping Block bb" - << requireBlock->getDebugID() << " to: " << inst); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Mapping Block bb" + << requireBlock->getDebugID() + << " to: " << inst); blockState.get()->setInst(generation, &inst); break; } @@ -1193,13 +1198,15 @@ void TransferNonSendableImpl::emitUseAfterTransferDiagnostics() { if (transferOpToRequireInstMultiMap.empty()) return; - LLVM_DEBUG(llvm::dbgs() << "Emitting use after transfer diagnostics.\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << "Emitting use after transfer diagnostics.\n"); for (auto [transferOp, requireInsts] : transferOpToRequireInstMultiMap.getRange()) { - LLVM_DEBUG(llvm::dbgs() - << "Transfer Op. Number: " << transferOp->getOperandNumber() - << ". User: " << *transferOp->getUser()); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << "Transfer Op. Number: " + << transferOp->getOperandNumber() + << ". User: " << *transferOp->getUser()); // Then look for our requires before we emit any error. We want to emit a // single we don't understand error if we do not find the require. @@ -1785,7 +1792,7 @@ void TransferNonSendableImpl::emitTransferredNonTransferrableDiagnostics() { if (transferredNonTransferrableInfoList.empty()) return; - LLVM_DEBUG( + REGIONBASEDISOLATION_LOG( llvm::dbgs() << "Emitting transfer non transferrable diagnostics.\n"); for (auto info : transferredNonTransferrableInfoList) { @@ -2186,14 +2193,15 @@ struct DiagnosticEvaluator final } auto rep = info->getValueMap().getRepresentative(transferredVal); - LLVM_DEBUG(llvm::dbgs() - << " Emitting Use After Transfer Error!\n" - << " Transferring Inst: " << *transferringOp->getUser() - << " Transferring Op Value: " << transferringOp->get() - << " Require Inst: " << *partitionOp.getSourceInst() - << " ID: %%" << transferredVal << "\n" - << " Rep: " << *rep << " Transferring Op Num: " - << transferringOp->getOperandNumber() << '\n'); + REGIONBASEDISOLATION_LOG( + llvm::dbgs() + << " Emitting Use After Transfer Error!\n" + << " Transferring Inst: " << *transferringOp->getUser() + << " Transferring Op Value: " << transferringOp->get() + << " Require Inst: " << *partitionOp.getSourceInst() + << " ID: %%" << transferredVal << "\n" + << " Rep: " << *rep << " Transferring Op Num: " + << transferringOp->getOperandNumber() << '\n'); transferOpToRequireInstMultiMap.insert( transferringOp, RequireInst::forUseAfterTransfer(partitionOp.getSourceInst())); @@ -2202,14 +2210,14 @@ struct DiagnosticEvaluator final void handleTransferNonTransferrable( const PartitionOp &partitionOp, Element transferredVal, SILDynamicMergedIsolationInfo isolationRegionInfo) const { - LLVM_DEBUG(llvm::dbgs() - << " Emitting TransferNonTransferrable Error!\n" - << " ID: %%" << transferredVal << "\n" - << " Rep: " - << *info->getValueMap().getRepresentative(transferredVal) - << " Dynamic Isolation Region: "; - isolationRegionInfo.printForDiagnostics(llvm::dbgs()); - llvm::dbgs() << '\n'); + REGIONBASEDISOLATION_LOG( + llvm::dbgs() << " Emitting TransferNonTransferrable Error!\n" + << " ID: %%" << transferredVal << "\n" + << " Rep: " + << *info->getValueMap().getRepresentative(transferredVal) + << " Dynamic Isolation Region: "; + isolationRegionInfo.printForDiagnostics(llvm::dbgs()); + llvm::dbgs() << '\n'); auto *self = const_cast(this); auto nonTransferrableValue = info->getValueMap().getRepresentative(transferredVal); @@ -2221,15 +2229,15 @@ struct DiagnosticEvaluator final void handleInOutSendingNotDisconnectedAtExitError( const PartitionOp &partitionOp, Element inoutSendingVal, SILDynamicMergedIsolationInfo isolationRegionInfo) const { - LLVM_DEBUG(llvm::dbgs() - << " Emitting InOut Sending ActorIsolated at end of " - "Function Error!\n" - << " ID: %%" << inoutSendingVal << "\n" - << " Rep: " - << *info->getValueMap().getRepresentative(inoutSendingVal) - << " Dynamic Isolation Region: "; - isolationRegionInfo.printForDiagnostics(llvm::dbgs()); - llvm::dbgs() << '\n'); + REGIONBASEDISOLATION_LOG( + llvm::dbgs() << " Emitting InOut Sending ActorIsolated at end of " + "Function Error!\n" + << " ID: %%" << inoutSendingVal << "\n" + << " Rep: " + << *info->getValueMap().getRepresentative(inoutSendingVal) + << " Dynamic Isolation Region: "; + isolationRegionInfo.printForDiagnostics(llvm::dbgs()); + llvm::dbgs() << '\n'); auto *self = const_cast(this); auto nonTransferrableValue = info->getValueMap().getRepresentative(inoutSendingVal); @@ -2243,30 +2251,30 @@ struct DiagnosticEvaluator final const PartitionOp &partitionOp, Element transferredVal, Element actualNonTransferrableValue, SILDynamicMergedIsolationInfo isolationRegionInfo) const { - LLVM_DEBUG(llvm::dbgs() - << " Emitting TransferNonTransferrable Error!\n" - << " ID: %%" << transferredVal << "\n" - << " Rep: " - << *info->getValueMap().getRepresentative(transferredVal) - << " Dynamic Isolation Region: "; - isolationRegionInfo.printForDiagnostics(llvm::dbgs()); - llvm::dbgs() << '\n'); + REGIONBASEDISOLATION_LOG( + llvm::dbgs() << " Emitting TransferNonTransferrable Error!\n" + << " ID: %%" << transferredVal << "\n" + << " Rep: " + << *info->getValueMap().getRepresentative(transferredVal) + << " Dynamic Isolation Region: "; + isolationRegionInfo.printForDiagnostics(llvm::dbgs()); + llvm::dbgs() << '\n'); auto *self = const_cast(this); // If we have a non-actor introducing fake representative value, just use // the value that actually introduced the actor isolation. if (auto nonTransferrableValue = info->getValueMap().maybeGetRepresentative( actualNonTransferrableValue)) { - LLVM_DEBUG(llvm::dbgs() - << " ActualTransfer: " << nonTransferrableValue); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << " ActualTransfer: " + << nonTransferrableValue); self->transferredNonTransferrable.emplace_back(partitionOp.getSourceOp(), nonTransferrableValue, isolationRegionInfo); } else if (auto *nonTransferrableInst = info->getValueMap().maybeGetActorIntroducingInst( actualNonTransferrableValue)) { - LLVM_DEBUG(llvm::dbgs() - << " ActualTransfer: " << *nonTransferrableInst); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << " ActualTransfer: " + << *nonTransferrableInst); self->transferredNonTransferrable.emplace_back( partitionOp.getSourceOp(), nonTransferrableInst, isolationRegionInfo); } else { @@ -2287,7 +2295,7 @@ struct DiagnosticEvaluator final SILFunctionArgument *destValue, Element srcElement, SILValue srcValue, SILDynamicMergedIsolationInfo srcIsolationRegionInfo) const { auto srcRep = info->getValueMap().getRepresentativeValue(srcElement); - LLVM_DEBUG( + REGIONBASEDISOLATION_LOG( llvm::dbgs() << " Emitting Error! Kind: Assign Isolated Into Sending Result!\n" << " Assign Inst: " << *partitionOp.getSourceInst() @@ -2306,14 +2314,15 @@ struct DiagnosticEvaluator final Element inoutSendingVal, Operand *transferringOp) const { auto rep = info->getValueMap().getRepresentative(inoutSendingVal); - LLVM_DEBUG(llvm::dbgs() - << " Emitting InOut Not Reinitialized At End Of Function!\n" - << " Transferring Inst: " << *transferringOp->getUser() - << " Transferring Op Value: " << transferringOp->get() - << " Require Inst: " << *partitionOp.getSourceInst() - << " ID: %%" << inoutSendingVal << "\n" - << " Rep: " << *rep << " Transferring Op Num: " - << transferringOp->getOperandNumber() << '\n'); + REGIONBASEDISOLATION_LOG( + llvm::dbgs() + << " Emitting InOut Not Reinitialized At End Of Function!\n" + << " Transferring Inst: " << *transferringOp->getUser() + << " Transferring Op Value: " << transferringOp->get() + << " Require Inst: " << *partitionOp.getSourceInst() + << " ID: %%" << inoutSendingVal << "\n" + << " Rep: " << *rep << " Transferring Op Num: " + << transferringOp->getOperandNumber() << '\n'); transferOpToRequireInstMultiMap.insert( transferringOp, RequireInst::forInOutReinitializationNeeded( partitionOp.getSourceInst())); @@ -2372,17 +2381,19 @@ struct DiagnosticEvaluator final void TransferNonSendableImpl::runDiagnosticEvaluator() { // Then for each block... - LLVM_DEBUG(llvm::dbgs() << "Walking blocks for diagnostics.\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Walking blocks for diagnostics.\n"); for (auto [block, blockState] : regionInfo->getRange()) { - LLVM_DEBUG(llvm::dbgs() << "|--> Block bb" << block.getDebugID() << "\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << "|--> Block bb" << block.getDebugID() << "\n"); if (!blockState.getLiveness()) { - LLVM_DEBUG(llvm::dbgs() << "Dead block... skipping!\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Dead block... skipping!\n"); continue; } - LLVM_DEBUG(llvm::dbgs() << "Entry Partition: "; - blockState.getEntryPartition().print(llvm::dbgs())); + REGIONBASEDISOLATION_LOG( + llvm::dbgs() << "Entry Partition: "; + blockState.getEntryPartition().print(llvm::dbgs())); // Grab its entry partition and setup an evaluator for the partition that // has callbacks that emit diagnsotics... @@ -2399,11 +2410,12 @@ void TransferNonSendableImpl::runDiagnosticEvaluator() { eval.apply(partitionOp); } - LLVM_DEBUG(llvm::dbgs() << "Exit Partition: "; - workingPartition.print(llvm::dbgs())); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Exit Partition: "; + workingPartition.print(llvm::dbgs())); } - LLVM_DEBUG(llvm::dbgs() << "Finished walking blocks for diagnostics.\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << "Finished walking blocks for diagnostics.\n"); // Now that we have found all of our transferInsts/Requires emit errors. transferOpToRequireInstMultiMap.setFrozen(); @@ -2418,8 +2430,8 @@ void TransferNonSendableImpl::runDiagnosticEvaluator() { /// state. void TransferNonSendableImpl::emitDiagnostics() { auto *function = regionInfo->getFunction(); - LLVM_DEBUG(llvm::dbgs() << "Emitting diagnostics for function " - << function->getName() << "\n"); + REGIONBASEDISOLATION_LOG(llvm::dbgs() << "Emitting diagnostics for function " + << function->getName() << "\n"); runDiagnosticEvaluator(); emitTransferredNonTransferrableDiagnostics(); @@ -2436,14 +2448,15 @@ class TransferNonSendable : public SILFunctionTransform { auto *functionInfo = getAnalysis()->get(function); if (!functionInfo->isSupportedFunction()) { - LLVM_DEBUG(llvm::dbgs() << "===> SKIPPING UNSUPPORTED FUNCTION: " - << function->getName() << '\n'); + REGIONBASEDISOLATION_LOG(llvm::dbgs() + << "===> SKIPPING UNSUPPORTED FUNCTION: " + << function->getName() << '\n'); return; } - LLVM_DEBUG(llvm::dbgs() - << "===> PROCESSING: " << function->getName() << '\n'); + REGIONBASEDISOLATION_LOG( + llvm::dbgs() << "===> PROCESSING: " << function->getName() << '\n'); TransferNonSendableImpl impl(functionInfo); impl.emitDiagnostics(); diff --git a/lib/SILOptimizer/Utils/PartitionUtils.cpp b/lib/SILOptimizer/Utils/PartitionUtils.cpp index 7ed6f9090ecf0..db60f3b37ff4e 100644 --- a/lib/SILOptimizer/Utils/PartitionUtils.cpp +++ b/lib/SILOptimizer/Utils/PartitionUtils.cpp @@ -31,7 +31,16 @@ using namespace swift::PartitionPrimitives; // MARK: Logging //===----------------------------------------------------------------------===// -#ifndef NDEBUG +bool swift::PartitionPrimitives::REGIONBASEDISOLATION_ENABLE_LOGGING; + +static llvm::cl::opt // The parser + RegionBasedIsolationLog( + "sil-regionbasedisolation-log", + llvm::cl::desc("Enable logging for SIL region based isolation " + "diagnostics"), + llvm::cl::Hidden, + llvm::cl::location( + swift::PartitionPrimitives::REGIONBASEDISOLATION_ENABLE_LOGGING)); bool swift::PartitionPrimitives::REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING; @@ -44,8 +53,6 @@ static llvm::cl::opt // The parser llvm::cl::location(swift::PartitionPrimitives:: REGIONBASEDISOLATION_ENABLE_VERBOSE_LOGGING)); -#endif - //===----------------------------------------------------------------------===// // MARK: PartitionOp //===----------------------------------------------------------------------===//