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:
@@ -141,7 +141,8 @@ getFinalReleases(SILValue Box,
|
||||
// If we have a copy value or a mark_uninitialized, add its uses to the work
|
||||
// list and continue.
|
||||
if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User)) {
|
||||
copy(User->getUses(), std::back_inserter(Worklist));
|
||||
copy(cast<SingleValueInstruction>(User)->getUses(),
|
||||
std::back_inserter(Worklist));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -212,8 +213,8 @@ static bool partialApplyEscapes(SILValue V, bool examineApply) {
|
||||
// If we have a copy_value, the copy value does not cause an escape, but its
|
||||
// uses might do so... so add the copy_value's uses to the worklist and
|
||||
// continue.
|
||||
if (isa<CopyValueInst>(User)) {
|
||||
copy(User->getUses(), std::back_inserter(Worklist));
|
||||
if (auto CVI = dyn_cast<CopyValueInst>(User)) {
|
||||
copy(CVI->getUses(), std::back_inserter(Worklist));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -385,7 +386,8 @@ static SILInstruction* findUnexpectedBoxUse(SILValue Box,
|
||||
// If our user instruction is a copy_value or a marked_uninitialized, visit
|
||||
// the users recursively.
|
||||
if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User)) {
|
||||
copy(User->getUses(), std::back_inserter(Worklist));
|
||||
copy(cast<SingleValueInstruction>(User)->getUses(),
|
||||
std::back_inserter(Worklist));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -514,11 +516,11 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
|
||||
|
||||
// Look through any mark_uninitialized, copy_values.
|
||||
if (isa<MarkUninitializedInst>(User) || isa<CopyValueInst>(User)) {
|
||||
transform(User->getUses(), std::back_inserter(Worklist),
|
||||
auto Inst = cast<SingleValueInstruction>(User);
|
||||
transform(Inst->getUses(), std::back_inserter(Worklist),
|
||||
[](Operand *Op) -> SILInstruction * { return Op->getUser(); });
|
||||
User->replaceAllUsesWith(
|
||||
SILUndef::get(User->getType(), User->getModule()));
|
||||
User->eraseFromParent();
|
||||
Inst->replaceAllUsesWithUndef();
|
||||
Inst->eraseFromParent();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -538,7 +540,7 @@ namespace {
|
||||
/// promoting some of its box parameters to stack addresses.
|
||||
class PromotedParamCloner : public SILClonerWithScopes<PromotedParamCloner> {
|
||||
public:
|
||||
friend class SILVisitor<PromotedParamCloner>;
|
||||
friend class SILInstructionVisitor<PromotedParamCloner>;
|
||||
friend class SILCloner<PromotedParamCloner>;
|
||||
|
||||
PromotedParamCloner(SILFunction *Orig, IsSerialized_t Serialized,
|
||||
@@ -811,7 +813,7 @@ specializePartialApply(PartialApplyInst *PartialApply,
|
||||
// address because we've proven we can keep this value on the stack. The
|
||||
// partial_apply had ownership of this box so we must now release it
|
||||
// explicitly when the partial_apply is released.
|
||||
SILInstruction *Box = cast<SILInstruction>(O.get());
|
||||
auto *Box = cast<SingleValueInstruction>(O.get());
|
||||
assert((isa<AllocBoxInst>(Box) || isa<CopyValueInst>(Box)) &&
|
||||
"Expected either an alloc box or a copy of an alloc box");
|
||||
SILBuilder B(Box);
|
||||
|
||||
Reference in New Issue
Block a user