Skip to content

Commit a1d5304

Browse files
committed
Remove select_value SIL instruction
1 parent d3d345b commit a1d5304

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
@@ -1700,14 +1700,6 @@ class SILBuilder {
17001700
getModule(), CaseCounts, DefaultCount));
17011701
}
17021702

1703-
SelectValueInst *createSelectValue(
1704-
SILLocation Loc, SILValue Operand, SILType Ty, SILValue DefaultResult,
1705-
ArrayRef<std::pair<SILValue, SILValue>> CaseValuesAndResult) {
1706-
return insert(SelectValueInst::create(getSILDebugLocation(Loc), Operand, Ty,
1707-
DefaultResult, CaseValuesAndResult,
1708-
getModule()));
1709-
}
1710-
17111703
TupleExtractInst *createTupleExtract(SILLocation Loc, SILValue Operand,
17121704
unsigned FieldNo, SILType ResultTy) {
17131705
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
@@ -3213,24 +3213,6 @@ SILCloner<ImplClass>::visitSelectEnumAddrInst(SelectEnumAddrInst *Inst) {
32133213
CaseResults));
32143214
}
32153215

3216-
template<typename ImplClass>
3217-
void
3218-
SILCloner<ImplClass>::visitSelectValueInst(SelectValueInst *Inst) {
3219-
SILValue DefaultResult;
3220-
if (Inst->hasDefault())
3221-
DefaultResult = getOpValue(Inst->getDefaultResult());
3222-
SmallVector<std::pair<SILValue, SILValue>, 8> CaseResults;
3223-
for (unsigned i = 0, e = Inst->getNumCases(); i != e; ++i)
3224-
CaseResults.push_back(std::make_pair(getOpValue(Inst->getCase(i).first),
3225-
getOpValue(Inst->getCase(i).second)));
3226-
3227-
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
3228-
recordClonedInstruction(
3229-
Inst, getBuilder().createSelectValue(
3230-
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand()),
3231-
getOpType(Inst->getType()), DefaultResult, CaseResults));
3232-
}
3233-
32343216
template <typename ImplClass>
32353217
void SILCloner<ImplClass>::visitDynamicMethodBranchInst(
32363218
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:
@@ -6581,8 +6580,8 @@ class UncheckedTakeEnumDataAddrInst
65816580
}
65826581
};
65836582

6584-
// Abstract base class of all select instructions like select_enum,
6585-
// select_value, etc. The template parameter represents a type of case values
6583+
// Abstract base class of all select instructions like select_enum.
6584+
// The template parameter represents a type of case values
65866585
// to be compared with the operand of a select instruction.
65876586
//
65886587
// Subclasses must provide tail allocated storage.
@@ -6800,50 +6799,6 @@ class SelectEnumAddrInst final
68006799
ProfileCounter DefaultCount);
68016800
};
68026801

6803-
/// Select on a value of a builtin integer type.
6804-
///
6805-
/// There is 'the' operand, followed by pairs of operands for each case,
6806-
/// followed by an optional default operand.
6807-
class SelectValueInst final
6808-
: public InstructionBaseWithTrailingOperands<
6809-
SILInstructionKind::SelectValueInst, SelectValueInst,
6810-
SelectInstBase<SelectValueInst, SILValue, SingleValueInstruction>> {
6811-
friend SILBuilder;
6812-
6813-
SelectValueInst(SILDebugLocation DebugLoc, SILValue Operand, SILType Type,
6814-
SILValue DefaultResult,
6815-
ArrayRef<SILValue> CaseValuesAndResults);
6816-
6817-
static SelectValueInst *
6818-
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Type,
6819-
SILValue DefaultValue,
6820-
ArrayRef<std::pair<SILValue, SILValue>> CaseValues, SILModule &M);
6821-
6822-
public:
6823-
std::pair<SILValue, SILValue>
6824-
getCase(unsigned i) const {
6825-
auto cases = getAllOperands().slice(1);
6826-
return {cases[i*2].get(), cases[i*2+1].get()};
6827-
}
6828-
6829-
unsigned getNumCases() const {
6830-
// Ignore the first non-case operand.
6831-
auto count = getAllOperands().size() - 1;
6832-
// This implicitly ignore the optional default operand.
6833-
return count / 2;
6834-
}
6835-
6836-
bool hasDefault() const {
6837-
// If the operand count is even, then we have a default value.
6838-
return (getAllOperands().size() & 1) == 0;
6839-
}
6840-
6841-
SILValue getDefaultResult() const {
6842-
assert(hasDefault() && "doesn't have a default");
6843-
return getAllOperands().back().get();
6844-
}
6845-
};
6846-
68476802
/// MetatypeInst - Represents the production of an instance of a given metatype
68486803
/// named statically.
68496804
class MetatypeInst final

include/swift/SIL/SILNodes.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,6 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
595595
SingleValueInstruction, None, DoesNotRelease)
596596
SINGLE_VALUE_INST(SelectEnumAddrInst, select_enum_addr,
597597
SingleValueInstruction, MayRead, DoesNotRelease)
598-
SINGLE_VALUE_INST(SelectValueInst, select_value,
599-
SingleValueInstruction, None, DoesNotRelease)
600598

601599
// Protocol and Protocol Composition Types
602600
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
@@ -1284,7 +1284,6 @@ class IRGenSILFunction :
12841284
void visitInitEnumDataAddrInst(InitEnumDataAddrInst *i);
12851285
void visitSelectEnumInst(SelectEnumInst *i);
12861286
void visitSelectEnumAddrInst(SelectEnumAddrInst *i);
1287-
void visitSelectValueInst(SelectValueInst *i);
12881287
void visitUncheckedEnumDataInst(UncheckedEnumDataInst *i);
12891288
void visitUncheckedTakeEnumDataAddrInst(UncheckedTakeEnumDataAddrInst *i);
12901289
void visitInjectEnumAddrInst(InjectEnumAddrInst *i);
@@ -4637,27 +4636,6 @@ void IRGenSILFunction::visitSelectEnumAddrInst(SelectEnumAddrInst *inst) {
46374636
// emitBBMapForSelectEnum set up a phi node to receive the result.
46384637
Builder.SetInsertPoint(contBB);
46394638
}
4640-
4641-
setLoweredValue(inst,
4642-
getLoweredValueForSelect(*this, result, inst));
4643-
}
4644-
4645-
void IRGenSILFunction::visitSelectValueInst(SelectValueInst *inst) {
4646-
Explosion value = getLoweredExplosion(inst->getOperand());
4647-
4648-
// Map the SIL dest bbs to their LLVM bbs.
4649-
SmallVector<std::pair<SILValue, llvm::BasicBlock*>, 4> dests;
4650-
llvm::BasicBlock *defaultDest;
4651-
Explosion result;
4652-
auto *contBB = emitBBMapForSelect(*this, result, dests, defaultDest, inst);
4653-
4654-
// Emit the dispatch.
4655-
emitSwitchValueDispatch(*this, inst->getOperand()->getType(), value, dests,
4656-
defaultDest);
4657-
4658-
// emitBBMapForSelectEnum set up a continuation block and phi nodes to
4659-
// receive the result.
4660-
Builder.SetInsertPoint(contBB);
46614639

46624640
setLoweredValue(inst,
46634641
getLoweredValueForSelect(*this, result, inst));

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ OPERAND_OWNERSHIP(TrivialUse, PointerToAddress)
186186
OPERAND_OWNERSHIP(TrivialUse, ProjectBlockStorage)
187187
OPERAND_OWNERSHIP(TrivialUse, RawPointerToRef)
188188
OPERAND_OWNERSHIP(TrivialUse, SelectEnumAddr)
189-
// select_value is only supported for integer types currently.
190-
OPERAND_OWNERSHIP(TrivialUse, SelectValue)
191189
OPERAND_OWNERSHIP(TrivialUse, StructElementAddr)
192190
OPERAND_OWNERSHIP(TrivialUse, SwitchEnumAddr)
193191
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
@@ -1914,35 +1914,6 @@ SwitchValueInst *SwitchValueInst::create(
19141914
return ::new (buf) SwitchValueInst(Loc, Operand, DefaultBB, Cases, BBs);
19151915
}
19161916

1917-
SelectValueInst::SelectValueInst(SILDebugLocation DebugLoc, SILValue Operand,
1918-
SILType Type, SILValue DefaultResult,
1919-
ArrayRef<SILValue> CaseValuesAndResults)
1920-
: InstructionBaseWithTrailingOperands(Operand, CaseValuesAndResults,
1921-
DebugLoc, Type) {}
1922-
1923-
SelectValueInst *
1924-
SelectValueInst::create(SILDebugLocation Loc, SILValue Operand, SILType Type,
1925-
SILValue DefaultResult,
1926-
ArrayRef<std::pair<SILValue, SILValue>> CaseValues,
1927-
SILModule &M) {
1928-
// Allocate enough room for the instruction with tail-allocated data for all
1929-
// the case values and the SILSuccessor arrays. There are `CaseBBs.size()`
1930-
// SILValues and `CaseBBs.size() + (DefaultBB ? 1 : 0)` successors.
1931-
SmallVector<SILValue, 8> CaseValuesAndResults;
1932-
for (auto pair : CaseValues) {
1933-
CaseValuesAndResults.push_back(pair.first);
1934-
CaseValuesAndResults.push_back(pair.second);
1935-
}
1936-
1937-
if ((bool)DefaultResult)
1938-
CaseValuesAndResults.push_back(DefaultResult);
1939-
1940-
auto Size = totalSizeToAlloc<swift::Operand>(CaseValuesAndResults.size() + 1);
1941-
auto Buf = M.allocateInst(Size, alignof(SelectValueInst));
1942-
return ::new (Buf)
1943-
SelectValueInst(Loc, Operand, Type, DefaultResult, CaseValuesAndResults);
1944-
}
1945-
19461917
template <typename SELECT_ENUM_INST>
19471918
SELECT_ENUM_INST *SelectEnumInstBase::createSelectEnum(
19481919
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
@@ -2669,21 +2669,6 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
26692669
printSelectEnumInst(SEI);
26702670
}
26712671

2672-
void visitSelectValueInst(SelectValueInst *SVI) {
2673-
*this << getIDAndType(SVI->getOperand());
2674-
2675-
for (unsigned i = 0, e = SVI->getNumCases(); i < e; ++i) {
2676-
SILValue casevalue;
2677-
SILValue result;
2678-
std::tie(casevalue, result) = SVI->getCase(i);
2679-
*this << ", case " << Ctx.getID(casevalue) << ": " << Ctx.getID(result);
2680-
}
2681-
if (SVI->hasDefault())
2682-
*this << ", default " << Ctx.getID(SVI->getDefaultResult());
2683-
2684-
*this << " : " << SVI->getType();
2685-
}
2686-
26872672
void visitDynamicMethodBranchInst(DynamicMethodBranchInst *DMBI) {
26882673
*this << getIDAndType(DMBI->getOperand()) << ", " << DMBI->getMember()
26892674
<< ", " << Ctx.getID(DMBI->getHasMethodBB()) << ", "

lib/SIL/IR/ValueOwnership.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ CONSTANT_OWNERSHIP_INST(None, RefElementAddr)
132132
CONSTANT_OWNERSHIP_INST(None, RefTailAddr)
133133
CONSTANT_OWNERSHIP_INST(None, RefToRawPointer)
134134
CONSTANT_OWNERSHIP_INST(None, SelectEnumAddr)
135-
CONSTANT_OWNERSHIP_INST(None, SelectValue)
136135
CONSTANT_OWNERSHIP_INST(None, StringLiteral)
137136
CONSTANT_OWNERSHIP_INST(None, StructElementAddr)
138137
CONSTANT_OWNERSHIP_INST(None, SuperMethod)

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5908,66 +5908,6 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
59085908
ResultVal = B.createSwitchValue(InstLoc, Val, DefaultBB, CaseBBs);
59095909
break;
59105910
}
5911-
case SILInstructionKind::SelectValueInst: {
5912-
if (parseTypedValueRef(Val, B))
5913-
return true;
5914-
5915-
SmallVector<std::pair<UnresolvedValueName, UnresolvedValueName>, 4>
5916-
CaseValueAndResultNames;
5917-
Optional<UnresolvedValueName> DefaultResultName;
5918-
while (P.consumeIf(tok::comma)) {
5919-
Identifier BBName;
5920-
SourceLoc BBLoc;
5921-
// Parse 'default' sil-value.
5922-
UnresolvedValueName tmp;
5923-
if (P.consumeIf(tok::kw_default)) {
5924-
if (parseValueName(tmp))
5925-
return true;
5926-
DefaultResultName = tmp;
5927-
break;
5928-
}
5929-
5930-
// Parse 'case' sil-decl-ref ':' sil-value.
5931-
if (P.consumeIf(tok::kw_case)) {
5932-
UnresolvedValueName casevalue;
5933-
parseValueName(casevalue);
5934-
P.parseToken(tok::colon, diag::expected_tok_in_sil_instr, ":");
5935-
parseValueName(tmp);
5936-
CaseValueAndResultNames.push_back(std::make_pair(casevalue, tmp));
5937-
continue;
5938-
}
5939-
5940-
P.diagnose(P.Tok, diag::expected_tok_in_sil_instr, "case or default");
5941-
return true;
5942-
}
5943-
5944-
if (!DefaultResultName) {
5945-
P.diagnose(P.Tok, diag::expected_tok_in_sil_instr, "default");
5946-
return true;
5947-
}
5948-
5949-
// Parse the type of the result operands.
5950-
SILType ResultType;
5951-
if (P.parseToken(tok::colon, diag::expected_tok_in_sil_instr, ":") ||
5952-
parseSILType(ResultType) || parseSILDebugLocation(InstLoc, B))
5953-
return true;
5954-
5955-
// Resolve the results.
5956-
SmallVector<std::pair<SILValue, SILValue>, 4> CaseValues;
5957-
SILValue DefaultValue;
5958-
if (DefaultResultName)
5959-
DefaultValue =
5960-
getLocalValue(*DefaultResultName, ResultType, InstLoc, B);
5961-
SILType ValType = Val->getType();
5962-
for (auto &caseName : CaseValueAndResultNames)
5963-
CaseValues.push_back(std::make_pair(
5964-
getLocalValue(caseName.first, ValType, InstLoc, B),
5965-
getLocalValue(caseName.second, ResultType, InstLoc, B)));
5966-
5967-
ResultVal = B.createSelectValue(InstLoc, Val, ResultType, DefaultValue,
5968-
CaseValues);
5969-
break;
5970-
}
59715911
case SILInstructionKind::DeinitExistentialAddrInst: {
59725912
if (parseTypedValueRef(Val, B) || parseSILDebugLocation(InstLoc, B))
59735913
return true;

lib/SIL/Utils/InstructionUtils.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
466466
case SILInstructionKind::UncheckedTakeEnumDataAddrInst:
467467
case SILInstructionKind::SelectEnumInst:
468468
case SILInstructionKind::SelectEnumAddrInst:
469-
case SILInstructionKind::SelectValueInst:
470469
case SILInstructionKind::OpenExistentialMetatypeInst:
471470
case SILInstructionKind::OpenExistentialBoxInst:
472471
case SILInstructionKind::OpenExistentialValueInst:

0 commit comments

Comments
 (0)