Skip to content

[sil] Add support for multiple value instructions by adding MultipleValueInstruction{,Result}. #12285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions docs/SIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,11 @@ Basic Blocks
sil-label ::= sil-identifier ('(' sil-argument (',' sil-argument)* ')')? ':'
sil-argument ::= sil-value-name ':' sil-type

sil-instruction-def ::= (sil-value-name '=')? sil-instruction
(',' sil-loc)? (',' sil-scope-ref)?
sil-instruction-result ::= sil-value-name
sil-instruction-result ::= '(' (sil-value-name (',' sil-value-name)*)? ')'
sil-instruction-source-info ::= (',' sil-scope-ref)? (',' sil-loc)?
sil-instruction-def ::=
(sil-instruction-result '=')? sil-instruction sil-instruction-source-info

A function body consists of one or more basic blocks that correspond
to the nodes of the function's control flow graph. Each basic block
Expand Down Expand Up @@ -3506,6 +3509,19 @@ tuple_element_addr
Given the address of a tuple in memory, derives the
address of an element within that value.

destructure_tuple
`````````````````

::

sil-instruction ::= 'destructure_tuple' sil-operand

(%elt1, ..., %eltn) = destructure_tuple %0 : $(Elt1Ty, ..., EltNTy)
// %0 must be a tuple of type $(Elt1Ty, ..., EltNTy)
// %eltN must have the type $EltNTy

Given a tuple value, split the value into its constituent elements.

struct
``````
::
Expand Down Expand Up @@ -3547,6 +3563,19 @@ struct_element_addr
Given the address of a struct value in memory, derives the address of a
physical field within the value.

destructure_struct
``````````````````

::

sil-instruction ::= 'destructure_struct' sil-operand

(%elt1, ..., %eltn) = destructure_struct %0 : $S
// %0 must be a struct of type $S
// %eltN must have the same type as the Nth field of $S

Given a struct, split the struct into its constituant fields.

object
``````
::
Expand Down
3 changes: 2 additions & 1 deletion include/swift/SIL/SILArgument.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ class SILArgument : public ValueBase {
explicit SILArgument(ValueKind SubClassKind, SILType Ty,
ValueOwnershipKind OwnershipKind,
const ValueDecl *D = nullptr)
: ValueBase(SubClassKind, Ty), ParentBB(nullptr), Decl(D), OwnershipKind(OwnershipKind) {}
: ValueBase(SubClassKind, Ty, IsRepresentative::Yes), ParentBB(nullptr),
Decl(D), OwnershipKind(OwnershipKind) {}
void setParent(SILBasicBlock *P) { ParentBB = P; }

friend SILBasicBlock;
Expand Down
12 changes: 12 additions & 0 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,18 @@ class SILBuilder {
Ref, ResultTy));
}

DestructureStructInst *createDestructureStruct(SILLocation Loc,
SILValue Operand) {
return insert(DestructureStructInst::create(
getModule(), getSILDebugLocation(Loc), Operand));
}

DestructureTupleInst *createDestructureTuple(SILLocation Loc,
SILValue Operand) {
return insert(DestructureTupleInst::create(
getModule(), getSILDebugLocation(Loc), Operand));
}

ClassMethodInst *createClassMethod(SILLocation Loc, SILValue Operand,
SILDeclRef Member, SILType MethodTy) {
return insert(new (getModule()) ClassMethodInst(
Expand Down
25 changes: 22 additions & 3 deletions include/swift/SIL/SILCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -1518,9 +1518,28 @@ SILCloner<ImplClass>::visitRefTailAddrInst(RefTailAddrInst *Inst) {
getOpType(Inst->getType())));
}

template<typename ImplClass>
void
SILCloner<ImplClass>::visitClassMethodInst(ClassMethodInst *Inst) {
template <typename ImplClass>
void SILCloner<ImplClass>::visitDestructureStructInst(
DestructureStructInst *Inst) {
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
doPostProcess(
Inst,
getBuilder().createDestructureStruct(getOpLocation(Inst->getLoc()),
getOpValue(Inst->getOperand())));
}

template <typename ImplClass>
void SILCloner<ImplClass>::visitDestructureTupleInst(
DestructureTupleInst *Inst) {
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
doPostProcess(
Inst,
getBuilder().createDestructureTuple(getOpLocation(Inst->getLoc()),
getOpValue(Inst->getOperand())));
}

template <typename ImplClass>
void SILCloner<ImplClass>::visitClassMethodInst(ClassMethodInst *Inst) {
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
doPostProcess(Inst,
getBuilder().createClassMethod(getOpLocation(Inst->getLoc()),
Expand Down
Loading