mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Make SILInstruction no longer a subclass of ValueBase and
introduce a common superclass, SILNode. This is in preparation for allowing instructions to have multiple results. It is also a somewhat more elegant representation for instructions that have zero results. Instructions that are known to have exactly one result inherit from a class, SingleValueInstruction, that subclasses both ValueBase and SILInstruction. Some care must be taken when working with SILNode pointers and testing for equality; please see the comment on SILNode for more information. A number of SIL passes needed to be updated in order to handle this new distinction between SIL values and SIL instructions. Note that the SIL parser is now stricter about not trying to assign a result value from an instruction (like 'return' or 'strong_retain') that does not produce any.
This commit is contained in:
@@ -112,27 +112,52 @@ bool swift::ArraySemanticsCall::isValidSignature() {
|
||||
}
|
||||
|
||||
/// Match array semantic calls.
|
||||
swift::ArraySemanticsCall::ArraySemanticsCall(ValueBase *V,
|
||||
StringRef SemanticStr,
|
||||
bool MatchPartialName) {
|
||||
if (auto *AI = dyn_cast<ApplyInst>(V))
|
||||
if (auto *Fn = AI->getReferencedFunction())
|
||||
if ((MatchPartialName &&
|
||||
Fn->hasSemanticsAttrThatStartsWith(SemanticStr)) ||
|
||||
(!MatchPartialName && Fn->hasSemanticsAttr(SemanticStr))) {
|
||||
SemanticsCall = AI;
|
||||
// Need a 'self' argument otherwise this is not a semantic call that
|
||||
// we recognize.
|
||||
if (getKind() < ArrayCallKind::kArrayInit && !hasSelf())
|
||||
SemanticsCall = nullptr;
|
||||
swift::ArraySemanticsCall::ArraySemanticsCall(SILValue V,
|
||||
StringRef semanticName,
|
||||
bool matchPartialName)
|
||||
: SemanticsCall(nullptr) {
|
||||
if (auto AI = dyn_cast<ApplyInst>(V))
|
||||
initialize(AI, semanticName, matchPartialName);
|
||||
}
|
||||
|
||||
// A arguments must be passed reference count neutral except for self.
|
||||
if (SemanticsCall && !isValidSignature())
|
||||
SemanticsCall = nullptr;
|
||||
return;
|
||||
}
|
||||
// Otherwise, this is not the semantic call we are looking for.
|
||||
SemanticsCall = nullptr;
|
||||
/// Match array semantic calls.
|
||||
swift::ArraySemanticsCall::ArraySemanticsCall(SILInstruction *I,
|
||||
StringRef semanticName,
|
||||
bool matchPartialName)
|
||||
: SemanticsCall(nullptr) {
|
||||
if (auto AI = dyn_cast<ApplyInst>(I))
|
||||
initialize(AI, semanticName, matchPartialName);
|
||||
}
|
||||
|
||||
/// Match array semantic calls.
|
||||
swift::ArraySemanticsCall::ArraySemanticsCall(ApplyInst *AI,
|
||||
StringRef semanticName,
|
||||
bool matchPartialName)
|
||||
: SemanticsCall(nullptr) {
|
||||
initialize(AI, semanticName, matchPartialName);
|
||||
}
|
||||
|
||||
void ArraySemanticsCall::initialize(ApplyInst *AI, StringRef semanticName,
|
||||
bool matchPartialName) {
|
||||
auto *fn = AI->getReferencedFunction();
|
||||
if (!fn)
|
||||
return;
|
||||
|
||||
if (!(matchPartialName
|
||||
? fn->hasSemanticsAttrThatStartsWith(semanticName)
|
||||
: fn->hasSemanticsAttr(semanticName)))
|
||||
return;
|
||||
|
||||
SemanticsCall = AI;
|
||||
|
||||
// Need a 'self' argument otherwise this is not a semantic call that
|
||||
// we recognize.
|
||||
if (getKind() < ArrayCallKind::kArrayInit && !hasSelf())
|
||||
SemanticsCall = nullptr;
|
||||
|
||||
// A arguments must be passed reference count neutral except for self.
|
||||
if (SemanticsCall && !isValidSignature())
|
||||
SemanticsCall = nullptr;
|
||||
}
|
||||
|
||||
/// Determine which kind of array semantics call this is.
|
||||
@@ -347,7 +372,7 @@ static SILValue copyArrayLoad(SILValue ArrayStructValue,
|
||||
InsertPt = Inst;
|
||||
}
|
||||
|
||||
return LI->clone(InsertBefore);
|
||||
return cast<LoadInst>(LI->clone(InsertBefore));
|
||||
}
|
||||
|
||||
static ApplyInst *hoistOrCopyCall(ApplyInst *AI, SILInstruction *InsertBefore,
|
||||
|
||||
Reference in New Issue
Block a user