Skip to content

Commit 5324100

Browse files
committed
Fix some SILArgument infrastructure for pack results.
Getting this right convinces the memory verifier to not complain about untouched empty pack result arguments, which should be innocuous.
1 parent cc5854b commit 5324100

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

include/swift/SIL/SILArgument.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,6 @@ class SILPhiArgument;
2828
class SILUndef;
2929
class TermInst;
3030

31-
// Map an argument index onto a SILArgumentConvention.
32-
inline SILArgumentConvention
33-
SILFunctionConventions::getSILArgumentConvention(unsigned index) const {
34-
assert(index <= getNumSILArguments());
35-
if (index < getNumIndirectSILResults()) {
36-
assert(silConv.loweredAddresses);
37-
return SILArgumentConvention::Indirect_Out;
38-
} else {
39-
auto param = funcTy->getParameters()[index - getNumIndirectSILResults()];
40-
return SILArgumentConvention(param.getConvention());
41-
}
42-
}
43-
4431
struct SILArgumentKind {
4532
enum innerty : std::underlying_type<ValueKind>::type {
4633
#define ARGUMENT(ID, PARENT) ID = unsigned(SILNodeKind::ID),

include/swift/SIL/SILArgumentConvention.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,28 @@ struct SILArgumentConvention {
164164
}
165165
llvm_unreachable("covered switch isn't covered?!");
166166
}
167+
168+
/// Returns true if \p Value is an indirect-out parameter.
169+
bool isIndirectOutParameter() {
170+
switch (Value) {
171+
case SILArgumentConvention::Indirect_Out:
172+
case SILArgumentConvention::Pack_Out:
173+
return true;
174+
175+
case SILArgumentConvention::Indirect_In:
176+
case SILArgumentConvention::Indirect_In_Guaranteed:
177+
case SILArgumentConvention::Indirect_Inout:
178+
case SILArgumentConvention::Indirect_InoutAliasable:
179+
case SILArgumentConvention::Direct_Unowned:
180+
case SILArgumentConvention::Direct_Guaranteed:
181+
case SILArgumentConvention::Direct_Owned:
182+
case SILArgumentConvention::Pack_Inout:
183+
case SILArgumentConvention::Pack_Owned:
184+
case SILArgumentConvention::Pack_Guaranteed:
185+
return false;
186+
}
187+
llvm_unreachable("covered switch isn't covered?!");
188+
}
167189
};
168190

169191
} // namespace swift

lib/SIL/IR/SILArgument.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,42 @@ SILParameterInfo SILFunctionArgument::getKnownParameterInfo() const {
7575
return getFunction()->getConventions().getParamInfoForSILArg(getIndex());
7676
}
7777

78+
SILArgumentConvention
79+
SILFunctionConventions::getSILArgumentConvention(unsigned index) const {
80+
assert(index < getNumSILArguments());
81+
82+
// If the argument is a parameter, index into the parameters.
83+
if (index >= getNumIndirectSILResults()) {
84+
auto param = funcTy->getParameters()[index - getNumIndirectSILResults()];
85+
return SILArgumentConvention(param.getConvention());
86+
}
87+
88+
// If it's an indirect result, it could be either Pack_Out or
89+
// Indirect_Out.
90+
91+
// Handle the common case of a function with no pack results.
92+
if (funcTy->getNumPackResults() == 0) {
93+
assert(silConv.loweredAddresses);
94+
return SILArgumentConvention::Indirect_Out;
95+
}
96+
97+
// Otherwise, we need to index into the indirect results to figure out
98+
// whether the result is a pack or not, and unfortunately that is not a
99+
// linear algorithm.
100+
for (auto result : getIndirectSILResults()) {
101+
if (index == 0) {
102+
if (result.getConvention() == ResultConvention::Indirect) {
103+
assert(silConv.loweredAddresses);
104+
return SILArgumentConvention::Indirect_Out;
105+
} else {
106+
assert(result.getConvention() == ResultConvention::Pack);
107+
return SILArgumentConvention::Pack_Out;
108+
}
109+
}
110+
index--;
111+
}
112+
llvm_unreachable("mismatch with getNumIndirectSILResults()?");
113+
}
78114

79115
//===----------------------------------------------------------------------===//
80116
// SILBlockArgument

0 commit comments

Comments
 (0)