Skip to content

Commit 81d738b

Browse files
committed
---
yaml --- r: 345903 b: refs/heads/master c: c74ceec h: refs/heads/master i: 345901: 6eb1121 345899: 6fd955b 345895: 0ce99b1 345887: 5c03d1d
1 parent d16f758 commit 81d738b

File tree

5 files changed

+285
-120
lines changed

5 files changed

+285
-120
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 5d7cb677f125bb6b96dc675e9d9c6696462ec48d
2+
refs/heads/master: c74ceecc7fcb46dfd1fe2ae451b71c1ef15dc8f0
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/SIL/OwnershipUtils.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,12 @@ bool isGuaranteedForwardingValueKind(SILNodeKind kind);
114114

115115
bool isGuaranteedForwardingValue(SILValue value);
116116

117+
bool isOwnershipForwardingInst(SILInstruction *i);
118+
117119
bool isGuaranteedForwardingInst(SILInstruction *i);
118120

119-
bool isOwnershipForwardingInst(SILInstruction *i);
121+
bool getUnderlyingBorrowIntroducers(SILValue inputValue,
122+
SmallVectorImpl<SILValue> &out);
120123

121124
} // namespace swift
122125

trunk/lib/SIL/OwnershipUtils.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "swift/SIL/OwnershipUtils.h"
14+
#include "swift/SIL/SILArgument.h"
1415
#include "swift/SIL/SILInstruction.h"
1516

1617
using namespace swift;
@@ -75,3 +76,38 @@ bool swift::isGuaranteedForwardingInst(SILInstruction *i) {
7576
bool swift::isOwnershipForwardingInst(SILInstruction *i) {
7677
return isOwnershipForwardingValueKind(SILNodeKind(i->getKind()));
7778
}
79+
80+
bool swift::getUnderlyingBorrowIntroducers(SILValue inputValue,
81+
SmallVectorImpl<SILValue> &out) {
82+
SmallVector<SILValue, 32> worklist;
83+
worklist.emplace_back(inputValue);
84+
85+
while (!worklist.empty()) {
86+
SILValue v = worklist.pop_back_val();
87+
88+
// First check if v is an introducer. If so, stash it and continue.
89+
if (isa<SILFunctionArgument>(v) || isa<LoadBorrowInst>(v) ||
90+
isa<BeginBorrowInst>(v)) {
91+
out.push_back(v);
92+
continue;
93+
}
94+
95+
// Otherwise if v is an ownership forwarding value, add its defining
96+
// instruction
97+
if (isGuaranteedForwardingValue(v)) {
98+
auto *i = v->getDefiningInstruction();
99+
assert(i);
100+
transform(i->getAllOperands(), std::back_inserter(worklist),
101+
[](const Operand &op) -> SILValue { return op.get(); });
102+
continue;
103+
}
104+
105+
// If v produces any ownership, then we can ignore it. Otherwise, we need to
106+
// return false since this is an introducer we do not understand.
107+
if (v.getOwnershipKind() != ValueOwnershipKind::Any &&
108+
v.getOwnershipKind() != ValueOwnershipKind::Trivial)
109+
return false;
110+
}
111+
112+
return true;
113+
}

0 commit comments

Comments
 (0)