Skip to content

Commit d0de3a9

Browse files
authored
Merge pull request #70439 from meg-gupta/debugmsgs
[NFC] Add some debug logging to optimizer passes
2 parents bd433ff + 8cb2086 commit d0de3a9

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,12 @@ class LoopUnrolling : public SILFunctionTransform {
488488
auto *Fun = getFunction();
489489
SILLoopInfo *LoopInfo = PM->getAnalysis<SILLoopAnalysis>()->get(Fun);
490490

491+
LLVM_DEBUG(llvm::dbgs() << "Loop Unroll running on function : "
492+
<< Fun->getName() << "\n");
493+
491494
// Collect innermost loops.
492495
SmallVector<SILLoop *, 16> InnermostLoops;
496+
493497
for (auto *Loop : *LoopInfo) {
494498
SmallVector<SILLoop *, 8> Worklist;
495499
Worklist.push_back(Loop);
@@ -503,11 +507,10 @@ class LoopUnrolling : public SILFunctionTransform {
503507
}
504508
}
505509

506-
if (InnermostLoops.empty())
510+
if (InnermostLoops.empty()) {
511+
LLVM_DEBUG(llvm::dbgs() << "No innermost loops\n");
507512
return;
508-
509-
LLVM_DEBUG(llvm::dbgs() << "Loop Unroll running on function : "
510-
<< Fun->getName() << "\n");
513+
}
511514

512515
// Try to unroll innermost loops.
513516
for (auto *Loop : InnermostLoops)

lib/SILOptimizer/SILCombiner/SILCombine.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@ bool SILCombiner::doOneIteration(SILFunction &F, unsigned Iteration) {
420420
MadeChange = true;
421421
continue;
422422
}
423+
#ifndef NDEBUG
424+
std::string OrigIStr;
425+
#endif
426+
LLVM_DEBUG(llvm::raw_string_ostream SS(OrigIStr); I->print(SS);
427+
OrigIStr = SS.str(););
428+
LLVM_DEBUG(llvm::dbgs() << "SC: Visiting: " << OrigIStr << '\n');
423429

424430
// Canonicalize the instruction.
425431
if (scCanonicalize.tryCanonicalize(I)) {
@@ -456,13 +462,6 @@ bool SILCombiner::doOneIteration(SILFunction &F, unsigned Iteration) {
456462
// Then begin... SILCombine.
457463
Builder.setInsertionPoint(I);
458464

459-
#ifndef NDEBUG
460-
std::string OrigIStr;
461-
#endif
462-
LLVM_DEBUG(llvm::raw_string_ostream SS(OrigIStr); I->print(SS);
463-
OrigIStr = SS.str(););
464-
LLVM_DEBUG(llvm::dbgs() << "SC: Visiting: " << OrigIStr << '\n');
465-
466465
SILInstruction *currentInst = I;
467466
if (SILInstruction *Result = visit(I)) {
468467
++NumCombined;

lib/SILOptimizer/SemanticARC/CopyValueOpts.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ using namespace swift::semanticarc;
6969
// TODO: This needs a better name.
7070
bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(
7171
CopyValueInst *cvi) {
72+
LLVM_DEBUG(llvm::dbgs() << "Looking at ");
73+
LLVM_DEBUG(cvi->dump());
74+
7275
// All mandatory copy optimization is handled by CanonicalizeOSSALifetime,
7376
// which knows how to preserve lifetimes for debugging.
7477
if (ctx.onlyMandatoryOpts)
@@ -82,8 +85,11 @@ bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(
8285
//
8386
// NOTE: We can get multiple introducers if our copy_value's operand
8487
// value runs through a phi or an aggregate forming instruction.
85-
if (!getAllBorrowIntroducingValues(cvi->getOperand(), borrowScopeIntroducers))
88+
if (!getAllBorrowIntroducingValues(cvi->getOperand(),
89+
borrowScopeIntroducers)) {
90+
LLVM_DEBUG(llvm::dbgs() << "Did not find all borrow introducers\n");
8691
return false;
92+
}
8793

8894
// Then go over all of our uses and see if the value returned by our copy
8995
// value forms a dead live range or a live range that would be dead if it was
@@ -96,6 +102,7 @@ bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(
96102
lr.hasUnknownConsumingUse(ctx.assumingAtFixedPoint);
97103
if (hasUnknownConsumingUseState ==
98104
OwnershipLiveRange::HasConsumingUse_t::Yes) {
105+
LLVM_DEBUG(llvm::dbgs() << "Found unknown consuming uses\n");
99106
return false;
100107
}
101108

@@ -192,6 +199,8 @@ bool SemanticARCOptVisitor::performGuaranteedCopyValueOptimization(
192199
return !borrowScope.areUsesWithinExtendedScope(
193200
lr.getAllConsumingUses(), nullptr);
194201
})) {
202+
LLVM_DEBUG(llvm::dbgs() << "copy_value is extending borrow introducer "
203+
"lifetime, bailing out\n");
195204
return false;
196205
}
197206
}

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,8 @@ bool SILPerformanceInliner::inlineCallsIntoFunction(SILFunction *Caller) {
11161116
if (!Caller->shouldOptimize())
11171117
return false;
11181118

1119+
LLVM_DEBUG(llvm::dbgs() << "Inlining calls into " << Caller->getName()
1120+
<< "\n");
11191121
// First step: collect all the functions we want to inline. We
11201122
// don't change anything yet so that the dominator information
11211123
// remains valid.
@@ -1143,6 +1145,8 @@ bool SILPerformanceInliner::inlineCallsIntoFunction(SILFunction *Caller) {
11431145
// ownership... do not inline. The two modes are incompatible, so skip this
11441146
// apply site for now.
11451147
if (!Callee->hasOwnership() && Caller->hasOwnership()) {
1148+
LLVM_DEBUG(llvm::dbgs()
1149+
<< "Not inlining non-ossa " << Caller->getName() << "\n");
11461150
continue;
11471151
}
11481152

0 commit comments

Comments
 (0)