Skip to content

Commit fe6d456

Browse files
committed
ARCSequenceOpts: Improve debug print
1 parent bf7c03b commit fe6d456

9 files changed

+114
-2
lines changed

lib/SILOptimizer/ARC/ARCBBState.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,34 @@ void ARCBBState::initPredTopDown(ARCBBState &PredBBState) {
137137
PtrToTopDownState = PredBBState.PtrToTopDownState;
138138
}
139139

140+
void ARCBBState::dumpBottomUpState() {
141+
for (auto state : getBottomupStates()) {
142+
if (!state.hasValue())
143+
continue;
144+
auto elem = state.getValue();
145+
if (!elem.first)
146+
continue;
147+
llvm::dbgs() << "SILValue: ";
148+
elem.first->dump();
149+
llvm::dbgs() << "RefCountState: ";
150+
elem.second.dump();
151+
}
152+
}
153+
154+
void ARCBBState::dumpTopDownState() {
155+
for (auto state : getTopDownStates()) {
156+
if (!state.hasValue())
157+
continue;
158+
auto elem = state.getValue();
159+
if (!elem.first)
160+
continue;
161+
llvm::dbgs() << "SILValue: ";
162+
elem.first->dump();
163+
llvm::dbgs() << "RefCountState: ";
164+
elem.second.dump();
165+
}
166+
}
167+
140168
//===----------------------------------------------------------------------===//
141169
// ARCBBStateInfo
142170
//===----------------------------------------------------------------------===//

lib/SILOptimizer/ARC/ARCBBState.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ class ARCSequenceDataflowEvaluator::ARCBBState {
137137
/// BB. Used to create an initial state before we merge in other
138138
/// predecessors. This is currently a stub.
139139
void initPredTopDown(ARCBBState &PredBB);
140+
141+
void dumpBottomUpState();
142+
void dumpTopDownState();
140143
};
141144

142145
class ARCSequenceDataflowEvaluator::ARCBBStateInfoHandle {

lib/SILOptimizer/ARC/GlobalARCSequenceDataflow.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,36 @@ ARCSequenceDataflowEvaluator::ARCSequenceDataflowEvaluator(
363363
bool ARCSequenceDataflowEvaluator::run(bool FreezeOwnedReleases) {
364364
bool NestingDetected = processBottomUp(FreezeOwnedReleases);
365365
NestingDetected |= processTopDown();
366+
367+
LLVM_DEBUG(
368+
llvm::dbgs() << "*** Bottom-Up and Top-Down analysis results ***\n");
369+
LLVM_DEBUG(dumpDataflowResults());
370+
366371
return NestingDetected;
367372
}
368373

374+
void ARCSequenceDataflowEvaluator::dumpDataflowResults() {
375+
llvm::dbgs() << "IncToDecStateMap:\n";
376+
for (auto it : IncToDecStateMap) {
377+
if (!it.hasValue())
378+
continue;
379+
auto instAndState = it.getValue();
380+
llvm::dbgs() << "Increment: ";
381+
instAndState.first->dump();
382+
instAndState.second.dump();
383+
}
384+
385+
llvm::dbgs() << "DecToIncStateMap:\n";
386+
for (auto it : DecToIncStateMap) {
387+
if (!it.hasValue())
388+
continue;
389+
auto instAndState = it.getValue();
390+
llvm::dbgs() << "Decrement: ";
391+
instAndState.first->dump();
392+
instAndState.second.dump();
393+
}
394+
}
395+
369396
// We put the destructor here so we don't need to expose the type of
370397
// BBStateInfo to the outside world.
371398
ARCSequenceDataflowEvaluator::~ARCSequenceDataflowEvaluator() = default;

lib/SILOptimizer/ARC/GlobalARCSequenceDataflow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class ARCSequenceDataflowEvaluator {
108108

109109
llvm::Optional<ARCBBStateInfoHandle> getBottomUpBBState(SILBasicBlock *BB);
110110
llvm::Optional<ARCBBStateInfoHandle> getTopDownBBState(SILBasicBlock *BB);
111+
112+
void dumpDataflowResults();
111113
};
112114

113115
} // end swift namespace

lib/SILOptimizer/ARC/GlobalLoopARCSequenceDataflow.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,38 @@ LoopARCSequenceDataflowEvaluator::~LoopARCSequenceDataflowEvaluator() {
252252
bool LoopARCSequenceDataflowEvaluator::runOnLoop(
253253
const LoopRegion *R, bool FreezeOwnedArgEpilogueReleases,
254254
bool RecomputePostDomReleases) {
255+
LLVM_DEBUG(llvm::dbgs() << "Run on region:\n");
256+
LLVM_DEBUG(R->dump(true));
255257
bool NestingDetected = processLoopBottomUp(R, FreezeOwnedArgEpilogueReleases);
256258
NestingDetected |= processLoopTopDown(R);
259+
LLVM_DEBUG(
260+
llvm::dbgs() << "*** Bottom-Up and Top-Down analysis results ***\n");
261+
LLVM_DEBUG(dumpDataflowResults());
257262
return NestingDetected;
258263
}
259264

265+
void LoopARCSequenceDataflowEvaluator::dumpDataflowResults() {
266+
llvm::dbgs() << "IncToDecStateMap:\n";
267+
for (auto it : IncToDecStateMap) {
268+
if (!it.hasValue())
269+
continue;
270+
auto instAndState = it.getValue();
271+
llvm::dbgs() << "Increment: ";
272+
instAndState.first->dump();
273+
instAndState.second.dump();
274+
}
275+
276+
llvm::dbgs() << "DecToIncStateMap:\n";
277+
for (auto it : DecToIncStateMap) {
278+
if (!it.hasValue())
279+
continue;
280+
auto instAndState = it.getValue();
281+
llvm::dbgs() << "Decrement: ";
282+
instAndState.first->dump();
283+
instAndState.second.dump();
284+
}
285+
}
286+
260287
void LoopARCSequenceDataflowEvaluator::summarizeLoop(
261288
const LoopRegion *R) {
262289
RegionStateInfo[R]->summarize(LRFI, RegionStateInfo);

lib/SILOptimizer/ARC/GlobalLoopARCSequenceDataflow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ class LoopARCSequenceDataflowEvaluator {
134134
bool processLoopTopDown(const LoopRegion *R);
135135
bool processLoopBottomUp(const LoopRegion *R,
136136
bool FreezeOwnedArgEpilogueReleases);
137+
138+
void dumpDataflowResults();
137139
};
138140

139141
} // end swift namespace

lib/SILOptimizer/ARC/RCStateTransition.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ class RCStateTransition {
126126
/// Returns a Range of Mutators. Asserts if this transition is not a mutator
127127
/// transition.
128128
mutator_range getMutators() const {
129-
assert(isMutator() && "This should never be called given mutators");
130129
return {Mutators->begin(), Mutators->end()};
131130
}
132131

lib/SILOptimizer/ARC/RefCountState.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,27 @@ void TopDownRefCountState::updateForDifferentLoopInst(
903903
// Printing Utilities
904904
//===----------------------------------------------------------------------===//
905905

906+
void BottomUpRefCountState::dump() {
907+
llvm::dbgs() << LatState << " "
908+
<< (isKnownSafe() ? "KnownSafe" : "NotKnownSafe") << " "
909+
<< (isCodeMotionSafe() ? "CodeMotionSafe" : "NotCodeMotionSafe")
910+
<< "\n";
911+
llvm::dbgs() << "Matching Instructions:\n";
912+
for (auto it : getInstructions()) {
913+
it->dump();
914+
}
915+
}
916+
void TopDownRefCountState::dump() {
917+
llvm::dbgs() << LatState << " "
918+
<< (isKnownSafe() ? "KnownSafe" : "NotKnownSafe") << " "
919+
<< (isCodeMotionSafe() ? "CodeMotionSafe" : "NotCodeMotionSafe")
920+
<< "\n";
921+
llvm::dbgs() << "Matching Instructions:\n";
922+
for (auto it : getInstructions()) {
923+
it->dump();
924+
}
925+
}
926+
906927
namespace llvm {
907928

908929
raw_ostream &operator<<(raw_ostream &OS,
@@ -938,5 +959,4 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
938959

939960
llvm_unreachable("Unhandled LatticeState in switch.");
940961
}
941-
942962
} // end namespace llvm

lib/SILOptimizer/ARC/RefCountState.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ class BottomUpRefCountState : public RefCountState {
212212
/// Uninitialize the current state.
213213
void clear();
214214

215+
void dump();
216+
215217
private:
216218
/// Return true if we *might* remove this instruction.
217219
///
@@ -354,6 +356,8 @@ class TopDownRefCountState : public RefCountState {
354356
/// succeed and false otherwise.
355357
bool merge(const TopDownRefCountState &Other);
356358

359+
void dump();
360+
357361
private:
358362
/// Can we guarantee that the given reference counted value has been modified?
359363
bool isRefCountStateModified() const;

0 commit comments

Comments
 (0)