Skip to content

Commit 4d3c32d

Browse files
committed
[AddressLowering] NFC: Added print.
Allow in-IR tests to print to stdout.
1 parent 4ac34a4 commit 4d3c32d

File tree

2 files changed

+41
-26
lines changed

2 files changed

+41
-26
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -433,51 +433,58 @@ void ValueStorageMap::replaceValue(SILValue oldValue, SILValue newValue) {
433433
}
434434

435435
#ifndef NDEBUG
436-
void ValueStorage::dump() const {
437-
llvm::dbgs() << "projectedStorageID: " << projectedStorageID << "\n";
438-
llvm::dbgs() << "projectedOperandNum: " << projectedOperandNum << "\n";
439-
llvm::dbgs() << "isDefProjection: " << isDefProjection << "\n";
440-
llvm::dbgs() << "isUseProjection: " << isUseProjection << "\n";
441-
llvm::dbgs() << "isRewritten: " << isRewritten << "\n";
442-
llvm::dbgs() << "initializes: " << initializes << "\n";
436+
void ValueStorage::print(llvm::raw_ostream &OS) const {
437+
OS << "projectedStorageID: " << projectedStorageID << "\n";
438+
OS << "projectedOperandNum: " << projectedOperandNum << "\n";
439+
OS << "isDefProjection: " << isDefProjection << "\n";
440+
OS << "isUseProjection: " << isUseProjection << "\n";
441+
OS << "isRewritten: " << isRewritten << "\n";
442+
OS << "initializes: " << initializes << "\n";
443443
}
444-
void ValueStorageMap::ValueStoragePair::dump() const {
445-
llvm::dbgs() << "value: ";
446-
value->dump();
447-
llvm::dbgs() << "address: ";
444+
void ValueStorage::dump() const { print(llvm::dbgs()); }
445+
void ValueStorageMap::ValueStoragePair::print(llvm::raw_ostream &OS) const {
446+
OS << "value: ";
447+
value->print(OS);
448+
OS << "address: ";
448449
if (storage.storageAddress)
449-
storage.storageAddress->dump();
450+
storage.storageAddress->print(OS);
450451
else
451-
llvm::dbgs() << "UNKNOWN!\n";
452-
storage.dump();
452+
OS << "UNKNOWN!\n";
453+
storage.print(OS);
453454
}
454-
void ValueStorageMap::dumpProjections(SILValue value) const {
455+
void ValueStorageMap::ValueStoragePair::dump() const { print(llvm::dbgs()); }
456+
void ValueStorageMap::printProjections(SILValue value,
457+
llvm::raw_ostream &OS) const {
455458
for (auto *pair : getProjections(value)) {
456-
pair->dump();
459+
pair->print(OS);
457460
}
458461
}
459-
void ValueStorageMap::dump() const {
460-
llvm::dbgs() << "ValueStorageMap:\n";
462+
void ValueStorageMap::dumpProjections(SILValue value) const {
463+
printProjections(value, llvm::dbgs());
464+
}
465+
void ValueStorageMap::print(llvm::raw_ostream &OS) const {
466+
OS << "ValueStorageMap:\n";
461467
for (unsigned ordinal : indices(valueVector)) {
462468
auto &valStoragePair = valueVector[ordinal];
463-
llvm::dbgs() << "value: ";
464-
valStoragePair.value->dump();
469+
OS << "value: ";
470+
valStoragePair.value->print(OS);
465471
auto &storage = valStoragePair.storage;
466472
if (storage.isUseProjection) {
467-
llvm::dbgs() << " use projection: ";
473+
OS << " use projection: ";
468474
if (!storage.isRewritten)
469-
valueVector[storage.projectedStorageID].value->dump();
475+
valueVector[storage.projectedStorageID].value->print(OS);
470476
} else if (storage.isDefProjection) {
471-
llvm::dbgs() << " def projection: ";
477+
OS << " def projection: ";
472478
if (!storage.isRewritten)
473-
valueVector[storage.projectedStorageID].value->dump();
479+
valueVector[storage.projectedStorageID].value->print(OS);
474480
}
475481
if (storage.storageAddress) {
476-
llvm::dbgs() << " storage: ";
477-
storage.storageAddress->dump();
482+
OS << " storage: ";
483+
storage.storageAddress->print(OS);
478484
}
479485
}
480486
}
487+
void ValueStorageMap::dump() const { print(llvm::dbgs()); }
481488
#endif
482489

483490
//===----------------------------------------------------------------------===//

lib/SILOptimizer/Mandatory/AddressLowering.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#include "llvm/ADT/DenseMap.h"
1818
#include "llvm/ADT/STLExtras.h"
1919

20+
namespace llvm {
21+
class raw_ostream;
22+
}
23+
2024
namespace swift {
2125

2226
/// Track an opaque value's storage. An opaque value is a SILValue with
@@ -199,6 +203,7 @@ struct ValueStorage {
199203
}
200204

201205
#ifndef NDEBUG
206+
void print(llvm::raw_ostream &OS) const;
202207
void dump() const;
203208
#endif
204209
};
@@ -215,6 +220,7 @@ class ValueStorageMap {
215220
ValueStorage storage;
216221
ValueStoragePair(SILValue v, ValueStorage s) : value(v), storage(s) {}
217222
#ifndef NDEBUG
223+
void print(llvm::raw_ostream &OS) const;
218224
void dump() const;
219225
#endif
220226
};
@@ -396,7 +402,9 @@ class ValueStorageMap {
396402
bool isComposingUseProjection(Operand *oper) const;
397403

398404
#ifndef NDEBUG
405+
void printProjections(SILValue value, llvm::raw_ostream &OS) const;
399406
void dumpProjections(SILValue value) const;
407+
void print(llvm::raw_ostream &OS) const;
400408
void dump() const;
401409
#endif
402410
};

0 commit comments

Comments
 (0)