Skip to content

Commit 6a2f3c9

Browse files
authored
Merge pull request #66608 from meg-gupta/removeselectvalue
Remove select_value SIL instruction
2 parents dc69f14 + 5d401fb commit 6a2f3c9

36 files changed

+7
-1056
lines changed

docs/SIL.rst

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,8 +3475,6 @@ A value ``%1`` is said to be *value-dependent* on a value ``%0`` if:
34753475
with ``tuple_extract``, ``struct_extract``, ``unchecked_enum_data``,
34763476
``select_enum``, or ``select_enum_addr``.
34773477

3478-
- ``%1`` is the result of ``select_value`` and ``%0`` is one of the cases.
3479-
34803478
- ``%1`` is a basic block parameter and ``%0`` is the corresponding
34813479
argument from a branch to that block.
34823480

@@ -7949,45 +7947,6 @@ block. If there is a ``default`` basic block, control is transferred to it if
79497947
the value does not match any of the ``case`` values. It is undefined behavior
79507948
if the value does not match any cases and no ``default`` branch is provided.
79517949

7952-
select_value
7953-
````````````
7954-
::
7955-
7956-
sil-instruction ::= 'select_value' sil-operand sil-select-value-case*
7957-
(',' 'default' sil-value)?
7958-
':' sil-type
7959-
sil-select-value-case ::= 'case' sil-value ':' sil-value
7960-
7961-
7962-
%n = select_value %0 : $U, \
7963-
case %c1: %r1, \
7964-
case %c2: %r2, /* ... */ \
7965-
default %r3 : $T
7966-
7967-
// $U must be a builtin type. Only integers types are supported currently.
7968-
// c1, c2, etc must be of type $U
7969-
// %r1, %r2, %r3, etc. must have type $T
7970-
// %n has type $T
7971-
7972-
Selects one of the "case" or "default" operands based on the case of a
7973-
value. This is equivalent to a trivial `switch_value`_ branch sequence::
7974-
7975-
entry:
7976-
switch_value %0 : $U, \
7977-
case %c1: bb1, \
7978-
case %c2: bb2, /* ... */ \
7979-
default bb_default
7980-
bb1:
7981-
br cont(%r1 : $T) // value for %c1
7982-
bb2:
7983-
br cont(%r2 : $T) // value for %c2
7984-
bb_default:
7985-
br cont(%r3 : $T) // value for default
7986-
cont(%n : $T):
7987-
// use argument %n
7988-
7989-
but turns the control flow dependency into a data flow dependency.
7990-
79917950
switch_enum
79927951
```````````
79937952
::

include/swift/SIL/SILBuilder.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,14 +1730,6 @@ class SILBuilder {
17301730
getModule(), CaseCounts, DefaultCount));
17311731
}
17321732

1733-
SelectValueInst *createSelectValue(
1734-
SILLocation Loc, SILValue Operand, SILType Ty, SILValue DefaultResult,
1735-
ArrayRef<std::pair<SILValue, SILValue>> CaseValuesAndResult) {
1736-
return insert(SelectValueInst::create(getSILDebugLocation(Loc), Operand, Ty,
1737-
DefaultResult, CaseValuesAndResult,
1738-
getModule()));
1739-
}
1740-
17411733
TupleExtractInst *createTupleExtract(SILLocation Loc, SILValue Operand,
17421734
unsigned FieldNo, SILType ResultTy) {
17431735
return createTupleExtract(Loc, Operand, FieldNo, ResultTy,

include/swift/SIL/SILCloner.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3251,24 +3251,6 @@ SILCloner<ImplClass>::visitSelectEnumAddrInst(SelectEnumAddrInst *Inst) {
32513251
CaseResults));
32523252
}
32533253

3254-
template<typename ImplClass>
3255-
void
3256-
SILCloner<ImplClass>::visitSelectValueInst(SelectValueInst *Inst) {
3257-
SILValue DefaultResult;
3258-
if (Inst->hasDefault())
3259-
DefaultResult = getOpValue(Inst->getDefaultResult());
3260-
SmallVector<std::pair<SILValue, SILValue>, 8> CaseResults;
3261-
for (unsigned i = 0, e = Inst->getNumCases(); i != e; ++i)
3262-
CaseResults.push_back(std::make_pair(getOpValue(Inst->getCase(i).first),
3263-
getOpValue(Inst->getCase(i).second)));
3264-
3265-
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
3266-
recordClonedInstruction(
3267-
Inst, getBuilder().createSelectValue(
3268-
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand()),
3269-
getOpType(Inst->getType()), DefaultResult, CaseResults));
3270-
}
3271-
32723254
template <typename ImplClass>
32733255
void SILCloner<ImplClass>::visitDynamicMethodBranchInst(
32743256
DynamicMethodBranchInst *Inst) {

include/swift/SIL/SILInstruction.h

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,6 @@ FirstArgOwnershipForwardingSingleValueInst::classof(SILInstructionKind kind) {
13921392
case SILInstructionKind::ObjectInst:
13931393
case SILInstructionKind::EnumInst:
13941394
case SILInstructionKind::UncheckedEnumDataInst:
1395-
case SILInstructionKind::SelectValueInst:
13961395
case SILInstructionKind::OpenExistentialRefInst:
13971396
case SILInstructionKind::InitExistentialRefInst:
13981397
case SILInstructionKind::MarkDependenceInst:
@@ -6659,8 +6658,8 @@ class UncheckedTakeEnumDataAddrInst
66596658
}
66606659
};
66616660

6662-
// Abstract base class of all select instructions like select_enum,
6663-
// select_value, etc. The template parameter represents a type of case values
6661+
// Abstract base class of all select instructions like select_enum.
6662+
// The template parameter represents a type of case values
66646663
// to be compared with the operand of a select instruction.
66656664
//
66666665
// Subclasses must provide tail allocated storage.
@@ -6878,50 +6877,6 @@ class SelectEnumAddrInst final
68786877
ProfileCounter DefaultCount);
68796878
};
68806879

6881-
/// Select on a value of a builtin integer type.
6882-
///
6883-
/// There is 'the' operand, followed by pairs of operands for each case,
6884-
/// followed by an optional default operand.
6885-
class SelectValueInst final
6886-
: public InstructionBaseWithTrailingOperands<
6887-
SILInstructionKind::SelectValueInst, SelectValueInst,
6888-
SelectInstBase<SelectValueInst, SILValue, SingleValueInstruction>> {
6889-
friend SILBuilder;
6890-
6891-
SelectValueInst(SILDebugLocation DebugLoc, SILValue Operand, SILType Type,
6892-
SILValue DefaultResult,
6893-
ArrayRef<SILValue> CaseValuesAndResults);
6894-
6895-
static SelectValueInst *
6896-
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Type,
6897-
SILValue DefaultValue,
6898-
ArrayRef<std::pair<SILValue, SILValue>> CaseValues, SILModule &M);
6899-
6900-
public:
6901-
std::pair<SILValue, SILValue>
6902-
getCase(unsigned i) const {
6903-
auto cases = getAllOperands().slice(1);
6904-
return {cases[i*2].get(), cases[i*2+1].get()};
6905-
}
6906-
6907-
unsigned getNumCases() const {
6908-
// Ignore the first non-case operand.
6909-
auto count = getAllOperands().size() - 1;
6910-
// This implicitly ignore the optional default operand.
6911-
return count / 2;
6912-
}
6913-
6914-
bool hasDefault() const {
6915-
// If the operand count is even, then we have a default value.
6916-
return (getAllOperands().size() & 1) == 0;
6917-
}
6918-
6919-
SILValue getDefaultResult() const {
6920-
assert(hasDefault() && "doesn't have a default");
6921-
return getAllOperands().back().get();
6922-
}
6923-
};
6924-
69256880
/// MetatypeInst - Represents the production of an instance of a given metatype
69266881
/// named statically.
69276882
class MetatypeInst final

include/swift/SIL/SILNodes.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,6 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
609609
SingleValueInstruction, None, DoesNotRelease)
610610
SINGLE_VALUE_INST(SelectEnumAddrInst, select_enum_addr,
611611
SingleValueInstruction, MayRead, DoesNotRelease)
612-
SINGLE_VALUE_INST(SelectValueInst, select_value,
613-
SingleValueInstruction, None, DoesNotRelease)
614612

615613
// Protocol and Protocol Composition Types
616614
SINGLE_VALUE_INST(InitExistentialAddrInst, init_existential_addr,

lib/IRGen/IRGenSIL.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,6 @@ class IRGenSILFunction :
13001300
void visitInitEnumDataAddrInst(InitEnumDataAddrInst *i);
13011301
void visitSelectEnumInst(SelectEnumInst *i);
13021302
void visitSelectEnumAddrInst(SelectEnumAddrInst *i);
1303-
void visitSelectValueInst(SelectValueInst *i);
13041303
void visitUncheckedEnumDataInst(UncheckedEnumDataInst *i);
13051304
void visitUncheckedTakeEnumDataAddrInst(UncheckedTakeEnumDataAddrInst *i);
13061305
void visitInjectEnumAddrInst(InjectEnumAddrInst *i);
@@ -4658,27 +4657,6 @@ void IRGenSILFunction::visitSelectEnumAddrInst(SelectEnumAddrInst *inst) {
46584657
// emitBBMapForSelectEnum set up a phi node to receive the result.
46594658
Builder.SetInsertPoint(contBB);
46604659
}
4661-
4662-
setLoweredValue(inst,
4663-
getLoweredValueForSelect(*this, result, inst));
4664-
}
4665-
4666-
void IRGenSILFunction::visitSelectValueInst(SelectValueInst *inst) {
4667-
Explosion value = getLoweredExplosion(inst->getOperand());
4668-
4669-
// Map the SIL dest bbs to their LLVM bbs.
4670-
SmallVector<std::pair<SILValue, llvm::BasicBlock*>, 4> dests;
4671-
llvm::BasicBlock *defaultDest;
4672-
Explosion result;
4673-
auto *contBB = emitBBMapForSelect(*this, result, dests, defaultDest, inst);
4674-
4675-
// Emit the dispatch.
4676-
emitSwitchValueDispatch(*this, inst->getOperand()->getType(), value, dests,
4677-
defaultDest);
4678-
4679-
// emitBBMapForSelectEnum set up a continuation block and phi nodes to
4680-
// receive the result.
4681-
Builder.SetInsertPoint(contBB);
46824660

46834661
setLoweredValue(inst,
46844662
getLoweredValueForSelect(*this, result, inst));

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,6 @@ OPERAND_OWNERSHIP(TrivialUse, PointerToAddress)
188188
OPERAND_OWNERSHIP(TrivialUse, ProjectBlockStorage)
189189
OPERAND_OWNERSHIP(TrivialUse, RawPointerToRef)
190190
OPERAND_OWNERSHIP(TrivialUse, SelectEnumAddr)
191-
// select_value is only supported for integer types currently.
192-
OPERAND_OWNERSHIP(TrivialUse, SelectValue)
193191
OPERAND_OWNERSHIP(TrivialUse, StructElementAddr)
194192
OPERAND_OWNERSHIP(TrivialUse, SwitchEnumAddr)
195193
OPERAND_OWNERSHIP(TrivialUse, SwitchValue)

lib/SIL/IR/SILInstruction.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -688,25 +688,6 @@ namespace {
688688
return visitSelectEnumInstBase(RHS);
689689
}
690690

691-
bool visitSelectValueInst(const SelectValueInst *RHS) {
692-
// Check that the instructions match cases in the same order.
693-
auto *X = cast<SelectValueInst>(LHS);
694-
695-
if (X->getNumCases() != RHS->getNumCases())
696-
return false;
697-
if (X->hasDefault() != RHS->hasDefault())
698-
return false;
699-
700-
for (unsigned i = 0, e = X->getNumCases(); i < e; ++i) {
701-
if (X->getCase(i).first != RHS->getCase(i).first)
702-
return false;
703-
if (X->getCase(i).second != RHS->getCase(i).second)
704-
return false;
705-
}
706-
707-
return true;
708-
}
709-
710691
// Conversion instructions.
711692
// All of these just return true as they have already had their
712693
// operands and types checked

lib/SIL/IR/SILInstructions.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,35 +1975,6 @@ SwitchValueInst *SwitchValueInst::create(
19751975
return ::new (buf) SwitchValueInst(Loc, Operand, DefaultBB, Cases, BBs);
19761976
}
19771977

1978-
SelectValueInst::SelectValueInst(SILDebugLocation DebugLoc, SILValue Operand,
1979-
SILType Type, SILValue DefaultResult,
1980-
ArrayRef<SILValue> CaseValuesAndResults)
1981-
: InstructionBaseWithTrailingOperands(Operand, CaseValuesAndResults,
1982-
DebugLoc, Type) {}
1983-
1984-
SelectValueInst *
1985-
SelectValueInst::create(SILDebugLocation Loc, SILValue Operand, SILType Type,
1986-
SILValue DefaultResult,
1987-
ArrayRef<std::pair<SILValue, SILValue>> CaseValues,
1988-
SILModule &M) {
1989-
// Allocate enough room for the instruction with tail-allocated data for all
1990-
// the case values and the SILSuccessor arrays. There are `CaseBBs.size()`
1991-
// SILValues and `CaseBBs.size() + (DefaultBB ? 1 : 0)` successors.
1992-
SmallVector<SILValue, 8> CaseValuesAndResults;
1993-
for (auto pair : CaseValues) {
1994-
CaseValuesAndResults.push_back(pair.first);
1995-
CaseValuesAndResults.push_back(pair.second);
1996-
}
1997-
1998-
if ((bool)DefaultResult)
1999-
CaseValuesAndResults.push_back(DefaultResult);
2000-
2001-
auto Size = totalSizeToAlloc<swift::Operand>(CaseValuesAndResults.size() + 1);
2002-
auto Buf = M.allocateInst(Size, alignof(SelectValueInst));
2003-
return ::new (Buf)
2004-
SelectValueInst(Loc, Operand, Type, DefaultResult, CaseValuesAndResults);
2005-
}
2006-
20071978
template <typename SELECT_ENUM_INST>
20081979
SELECT_ENUM_INST *SelectEnumInstBase::createSelectEnum(
20091980
SILDebugLocation Loc, SILValue Operand, SILType Ty, SILValue DefaultValue,

lib/SIL/IR/SILPrinter.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,21 +2712,6 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
27122712
printSelectEnumInst(SEI);
27132713
}
27142714

2715-
void visitSelectValueInst(SelectValueInst *SVI) {
2716-
*this << getIDAndType(SVI->getOperand());
2717-
2718-
for (unsigned i = 0, e = SVI->getNumCases(); i < e; ++i) {
2719-
SILValue casevalue;
2720-
SILValue result;
2721-
std::tie(casevalue, result) = SVI->getCase(i);
2722-
*this << ", case " << Ctx.getID(casevalue) << ": " << Ctx.getID(result);
2723-
}
2724-
if (SVI->hasDefault())
2725-
*this << ", default " << Ctx.getID(SVI->getDefaultResult());
2726-
2727-
*this << " : " << SVI->getType();
2728-
}
2729-
27302715
void visitDynamicMethodBranchInst(DynamicMethodBranchInst *DMBI) {
27312716
*this << getIDAndType(DMBI->getOperand()) << ", " << DMBI->getMember()
27322717
<< ", " << Ctx.getID(DMBI->getHasMethodBB()) << ", "

lib/SIL/IR/ValueOwnership.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ CONSTANT_OWNERSHIP_INST(None, RefElementAddr)
134134
CONSTANT_OWNERSHIP_INST(None, RefTailAddr)
135135
CONSTANT_OWNERSHIP_INST(None, RefToRawPointer)
136136
CONSTANT_OWNERSHIP_INST(None, SelectEnumAddr)
137-
CONSTANT_OWNERSHIP_INST(None, SelectValue)
138137
CONSTANT_OWNERSHIP_INST(None, StringLiteral)
139138
CONSTANT_OWNERSHIP_INST(None, StructElementAddr)
140139
CONSTANT_OWNERSHIP_INST(None, SuperMethod)

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6098,66 +6098,6 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
60986098
ResultVal = B.createSwitchValue(InstLoc, Val, DefaultBB, CaseBBs);
60996099
break;
61006100
}
6101-
case SILInstructionKind::SelectValueInst: {
6102-
if (parseTypedValueRef(Val, B))
6103-
return true;
6104-
6105-
SmallVector<std::pair<UnresolvedValueName, UnresolvedValueName>, 4>
6106-
CaseValueAndResultNames;
6107-
Optional<UnresolvedValueName> DefaultResultName;
6108-
while (P.consumeIf(tok::comma)) {
6109-
Identifier BBName;
6110-
SourceLoc BBLoc;
6111-
// Parse 'default' sil-value.
6112-
UnresolvedValueName tmp;
6113-
if (P.consumeIf(tok::kw_default)) {
6114-
if (parseValueName(tmp))
6115-
return true;
6116-
DefaultResultName = tmp;
6117-
break;
6118-
}
6119-
6120-
// Parse 'case' sil-decl-ref ':' sil-value.
6121-
if (P.consumeIf(tok::kw_case)) {
6122-
UnresolvedValueName casevalue;
6123-
parseValueName(casevalue);
6124-
P.parseToken(tok::colon, diag::expected_tok_in_sil_instr, ":");
6125-
parseValueName(tmp);
6126-
CaseValueAndResultNames.push_back(std::make_pair(casevalue, tmp));
6127-
continue;
6128-
}
6129-
6130-
P.diagnose(P.Tok, diag::expected_tok_in_sil_instr, "case or default");
6131-
return true;
6132-
}
6133-
6134-
if (!DefaultResultName) {
6135-
P.diagnose(P.Tok, diag::expected_tok_in_sil_instr, "default");
6136-
return true;
6137-
}
6138-
6139-
// Parse the type of the result operands.
6140-
SILType ResultType;
6141-
if (P.parseToken(tok::colon, diag::expected_tok_in_sil_instr, ":") ||
6142-
parseSILType(ResultType) || parseSILDebugLocation(InstLoc, B))
6143-
return true;
6144-
6145-
// Resolve the results.
6146-
SmallVector<std::pair<SILValue, SILValue>, 4> CaseValues;
6147-
SILValue DefaultValue;
6148-
if (DefaultResultName)
6149-
DefaultValue =
6150-
getLocalValue(*DefaultResultName, ResultType, InstLoc, B);
6151-
SILType ValType = Val->getType();
6152-
for (auto &caseName : CaseValueAndResultNames)
6153-
CaseValues.push_back(std::make_pair(
6154-
getLocalValue(caseName.first, ValType, InstLoc, B),
6155-
getLocalValue(caseName.second, ResultType, InstLoc, B)));
6156-
6157-
ResultVal = B.createSelectValue(InstLoc, Val, ResultType, DefaultValue,
6158-
CaseValues);
6159-
break;
6160-
}
61616101
case SILInstructionKind::DeinitExistentialAddrInst: {
61626102
if (parseTypedValueRef(Val, B) || parseSILDebugLocation(InstLoc, B))
61636103
return true;

lib/SIL/Utils/InstructionUtils.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
512512
case SILInstructionKind::UncheckedTakeEnumDataAddrInst:
513513
case SILInstructionKind::SelectEnumInst:
514514
case SILInstructionKind::SelectEnumAddrInst:
515-
case SILInstructionKind::SelectValueInst:
516515
case SILInstructionKind::OpenExistentialMetatypeInst:
517516
case SILInstructionKind::OpenExistentialBoxInst:
518517
case SILInstructionKind::OpenExistentialValueInst:

0 commit comments

Comments
 (0)