Skip to content

Commit 225b6e8

Browse files
committed
[ownership] Add dumper/print methods for various OwnershipUtils.h helper structs.
1 parent 44796c4 commit 225b6e8

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,12 @@ struct BorrowScopeOperandKind {
236236
}
237237

238238
void print(llvm::raw_ostream &os) const;
239-
SWIFT_DEBUG_DUMP;
239+
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
240240
};
241241

242+
llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
243+
BorrowScopeOperandKind kind);
244+
242245
/// An operand whose user instruction introduces a new borrow scope for the
243246
/// operand's value. The value of the operand must be considered as implicitly
244247
/// borrowed until the user's corresponding end scope instruction.
@@ -278,6 +281,9 @@ struct BorrowScopeOperand {
278281
llvm_unreachable("Covered switch isn't covered");
279282
}
280283

284+
void print(llvm::raw_ostream &os) const;
285+
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
286+
281287
private:
282288
/// Internal constructor for failable static constructor. Please do not expand
283289
/// its usage since it assumes the code passed in is well formed.
@@ -286,7 +292,7 @@ struct BorrowScopeOperand {
286292
};
287293

288294
llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
289-
BorrowScopeOperandKind kind);
295+
const BorrowScopeOperand &operand);
290296

291297
struct BorrowScopeIntroducingValueKind {
292298
using UnderlyingKindTy = std::underlying_type<ValueKind>::type;
@@ -336,7 +342,7 @@ struct BorrowScopeIntroducingValueKind {
336342
}
337343

338344
void print(llvm::raw_ostream &os) const;
339-
SWIFT_DEBUG_DUMP;
345+
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
340346
};
341347

342348
llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
@@ -419,6 +425,9 @@ struct BorrowScopeIntroducingValue {
419425
SmallPtrSetImpl<SILBasicBlock *> &visitedBlocks,
420426
DeadEndBlocks &deadEndBlocks) const;
421427

428+
void print(llvm::raw_ostream &os) const;
429+
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
430+
422431
private:
423432
/// Internal constructor for failable static constructor. Please do not expand
424433
/// its usage since it assumes the code passed in is well formed.
@@ -427,6 +436,9 @@ struct BorrowScopeIntroducingValue {
427436
: kind(kind), value(value) {}
428437
};
429438

439+
llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
440+
const BorrowScopeIntroducingValue &value);
441+
430442
/// Look up through the def-use chain of \p inputValue, recording any "borrow"
431443
/// introducing values that we find into \p out. If at any point, we find a
432444
/// point in the chain we do not understand, we bail and return false. If we are

lib/SIL/OwnershipUtils.cpp

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,41 @@ bool swift::isOwnershipForwardingInst(SILInstruction *i) {
8787
return isOwnershipForwardingValueKind(SILNodeKind(i->getKind()));
8888
}
8989

90+
//===----------------------------------------------------------------------===//
91+
// Borrow Scope Operand
92+
//===----------------------------------------------------------------------===//
93+
94+
void BorrowScopeOperandKind::print(llvm::raw_ostream &os) const {
95+
switch (value) {
96+
case Kind::BeginBorrow:
97+
os << "BeginBorrow";
98+
return;
99+
case Kind::BeginApply:
100+
os << "BeginApply";
101+
return;
102+
}
103+
llvm_unreachable("Covered switch isn't covered?!");
104+
}
105+
106+
llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &os,
107+
BorrowScopeOperandKind kind) {
108+
kind.print(os);
109+
return os;
110+
}
111+
112+
void BorrowScopeOperand::print(llvm::raw_ostream &os) const {
113+
os << "BorrowScopeOperand:\n"
114+
"Kind: " << kind << "\n"
115+
"Value: " << op->get()
116+
<< "User: " << op->getUser();
117+
}
118+
119+
llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &os,
120+
const BorrowScopeOperand &operand) {
121+
operand.print(os);
122+
return os;
123+
}
124+
90125
//===----------------------------------------------------------------------===//
91126
// Borrow Introducers
92127
//===----------------------------------------------------------------------===//
@@ -106,12 +141,6 @@ void BorrowScopeIntroducingValueKind::print(llvm::raw_ostream &os) const {
106141
llvm_unreachable("Covered switch isn't covered?!");
107142
}
108143

109-
void BorrowScopeIntroducingValueKind::dump() const {
110-
#ifndef NDEBUG
111-
print(llvm::dbgs());
112-
#endif
113-
}
114-
115144
void BorrowScopeIntroducingValue::getLocalScopeEndingInstructions(
116145
SmallVectorImpl<SILInstruction *> &scopeEndingInsts) const {
117146
assert(isLocalScope() && "Should only call this given a local scope");
@@ -206,6 +235,12 @@ llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &os,
206235
return os;
207236
}
208237

238+
llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &os,
239+
const BorrowScopeIntroducingValue &value) {
240+
value.print(os);
241+
return os;
242+
}
243+
209244
bool BorrowScopeIntroducingValue::areInstructionsWithinScope(
210245
ArrayRef<SILInstruction *> instructions,
211246
SmallVectorImpl<SILInstruction *> &scratchSpace,

0 commit comments

Comments
 (0)