Skip to content

[NFC] Shortened SIL [init] flag. #61749

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 1 commit into from
Oct 27, 2022
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
2 changes: 1 addition & 1 deletion docs/DifferentiableProgrammingImplementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ sil hidden [ossa] @$s4main7genericyxxlF : $@convention(thin) <T> (@in_guaranteed
// %1 // users: %3, %2
bb0(%0 : $*T, %1 : $*T):
debug_value_addr %1 : $*T, let, name "x", argno 1 // id: %2
copy_addr %1 to [initialization] %0 : $*T // id: %3
copy_addr %1 to [init] %0 : $*T // id: %3
%4 = tuple () // user: %5
return %4 : $() // id: %5
} // end sil function '$s4main7genericyxxlF'
Expand Down
26 changes: 13 additions & 13 deletions docs/SIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4169,7 +4169,7 @@ assign_by_wrapper

sil-instruction ::= 'assign_by_wrapper' sil-operand 'to' mode? sil-operand ',' 'init' sil-operand ',' 'set' sil-operand

mode ::= '[initialization]' | '[assign]' | '[assign_wrapped_value]'
mode ::= '[init]' | '[assign]' | '[assign_wrapped_value]'

assign_by_wrapper %0 : $S to %1 : $*T, init %2 : $F, set %3 : $G
// $S can be a value or address type
Expand Down Expand Up @@ -4286,9 +4286,9 @@ copy_addr
::

sil-instruction ::= 'copy_addr' '[take]'? sil-value
'to' '[initialization]'? sil-operand
'to' '[init]'? sil-operand

copy_addr [take] %0 to [initialization] %1 : $*T
copy_addr [take] %0 to [init] %1 : $*T
// %0 and %1 must be of the same $*T address type

Loads the value at address ``%0`` from memory and assigns a copy of it back into
Expand All @@ -4307,11 +4307,11 @@ is equivalent to::

except that ``copy_addr`` may be used even if ``%0`` is of an address-only
type. The ``copy_addr`` may be given one or both of the ``[take]`` or
``[initialization]`` attributes:
``[init]`` attributes:

* ``[take]`` destroys the value at the source address in the course of the
copy.
* ``[initialization]`` indicates that the destination address is uninitialized.
* ``[init]`` indicates that the destination address is uninitialized.
Without the attribute, the destination address is treated as already
initialized, and the existing value will be destroyed before the new value
is stored.
Expand All @@ -4329,15 +4329,15 @@ operations::
store %new to %1 : $*T

// copy-initialization
copy_addr %0 to [initialization] %1 : $*T
copy_addr %0 to [init] %1 : $*T
// is equivalent to:
%new = load %0 : $*T
strong_retain %new : $T
// no load/release of %old!
store %new to %1 : $*T

// take-initialization
copy_addr [take] %0 to [initialization] %1 : $*T
copy_addr [take] %0 to [init] %1 : $*T
// is equivalent to:
%new = load %0 : $*T
// no retain of %new!
Expand All @@ -4355,9 +4355,9 @@ explicit_copy_addr
::

sil-instruction ::= 'explicit_copy_addr' '[take]'? sil-value
'to' '[initialization]'? sil-operand
'to' '[init]'? sil-operand

explicit_copy_addr [take] %0 to [initialization] %1 : $*T
explicit_copy_addr [take] %0 to [init] %1 : $*T
// %0 and %1 must be of the same $*T address type

This instruction is exactly the same as `copy_addr`_ except that it has special
Expand Down Expand Up @@ -4789,14 +4789,14 @@ store_weak

::

sil-instruction ::= 'store_weak' sil-value 'to' '[initialization]'? sil-operand
sil-instruction ::= 'store_weak' sil-value 'to' '[init]'? sil-operand

store_weak %0 to [initialization] %1 : $*@sil_weak Optional<T>
store_weak %0 to [init] %1 : $*@sil_weak Optional<T>
// $T must be an optional wrapping a reference type

Initializes or reassigns a weak reference. The operand may be ``nil``.

If ``[initialization]`` is given, the weak reference must currently either be
If ``[init]`` is given, the weak reference must currently either be
uninitialized or destroyed. If it is not given, the weak reference must
currently be initialized. After the evaluation:

Expand Down Expand Up @@ -6019,7 +6019,7 @@ an `inject_enum_addr`_ instruction::
entry(%0 : $*AddressOnlyEnum, %1 : $*AddressOnlyType):
// Store the data argument for the case.
%2 = init_enum_data_addr %0 : $*AddressOnlyEnum, #AddressOnlyEnum.HasData!enumelt
copy_addr [take] %2 to [initialization] %1 : $*AddressOnlyType
copy_addr [take] %2 to [init] %1 : $*AddressOnlyType
// Inject the tag.
inject_enum_addr %0 : $*AddressOnlyEnum, #AddressOnlyEnum.HasData!enumelt
return
Expand Down
2 changes: 1 addition & 1 deletion docs/proposals/InoutCOWOptimization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ To work with opaque types, ``copy_addr`` must also be able to perform an
an original value. This can be an additional attribute on the source, mutually
exclusive with ``[take]``::

copy_addr [inout] %a to [initialization] %b
copy_addr [inout] %a to [init] %b

This implies that value witness tables will need witnesses for
inout-initialization and inout-reassignment.
Expand Down
8 changes: 4 additions & 4 deletions lib/SIL/IR/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
case AssignByWrapperInst::Unknown:
break;
case AssignByWrapperInst::Initialization:
*this << "[initialization] ";
*this << "[init] ";
break;
case AssignByWrapperInst::Assign:
*this << "[assign] ";
Expand Down Expand Up @@ -1771,7 +1771,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
void visitStore##Name##Inst(Store##Name##Inst *SI) { \
*this << Ctx.getID(SI->getSrc()) << " to "; \
if (SI->isInitializationOfDest()) \
*this << "[initialization] "; \
*this << "[init] "; \
*this << getIDAndType(SI->getDest()); \
}
#include "swift/AST/ReferenceStorage.def"
Expand All @@ -1781,7 +1781,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
*this << "[take] ";
*this << Ctx.getID(CI->getSrc()) << " to ";
if (CI->isInitializationOfDest())
*this << "[initialization] ";
*this << "[init] ";
*this << getIDAndType(CI->getDest());
}

Expand All @@ -1790,7 +1790,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
*this << "[take] ";
*this << Ctx.getID(CI->getSrc()) << " to ";
if (CI->isInitializationOfDest())
*this << "[initialization] ";
*this << "[init] ";
*this << getIDAndType(CI->getDest());
}

Expand Down
8 changes: 4 additions & 4 deletions lib/SIL/Parser/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2241,7 +2241,7 @@ static bool parseAssignByWrapperMode(AssignByWrapperInst::Mode &Result,
// Then try to parse one of our other initialization kinds. We do not support
// parsing unknown here so we use that as our fail value.
auto Tmp = llvm::StringSwitch<AssignByWrapperInst::Mode>(Str)
.Case("initialization", AssignByWrapperInst::Initialization)
.Case("init", AssignByWrapperInst::Initialization)
.Case("assign", AssignByWrapperInst::Assign)
.Case("assign_wrapped_value", AssignByWrapperInst::AssignWrappedValue)
.Default(AssignByWrapperInst::Unknown);
Expand Down Expand Up @@ -4403,7 +4403,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
if (parseValueName(from) ||
parseSILIdentifier(toToken, toLoc, diag::expected_tok_in_sil_instr,
"to") ||
(isRefStorage && parseSILOptional(isInit, *this, "initialization")) ||
(isRefStorage && parseSILOptional(isInit, *this, "init")) ||
parseTypedValueRef(addrVal, addrLoc, B) ||
parseSILDebugLocation(InstLoc, B))
return true;
Expand Down Expand Up @@ -5011,7 +5011,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
if (parseSILOptional(IsTake, *this, "take") || parseValueName(SrcLName) ||
parseSILIdentifier(ToToken, ToLoc, diag::expected_tok_in_sil_instr,
"to") ||
parseSILOptional(IsInit, *this, "initialization") ||
parseSILOptional(IsInit, *this, "init") ||
parseTypedValueRef(DestLVal, DestLoc, B) ||
parseSILDebugLocation(InstLoc, B))
return true;
Expand Down Expand Up @@ -5041,7 +5041,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
if (parseSILOptional(IsTake, *this, "take") || parseValueName(SrcLName) ||
parseSILIdentifier(ToToken, ToLoc, diag::expected_tok_in_sil_instr,
"to") ||
parseSILOptional(IsInit, *this, "initialization") ||
parseSILOptional(IsInit, *this, "init") ||
parseTypedValueRef(DestLVal, DestLoc, B) ||
parseSILDebugLocation(InstLoc, B))
return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Differentiation/PullbackCloner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2289,7 +2289,7 @@ void PullbackCloner::Implementation::accumulateAdjointForOptional(
// #Optional.some!enumelt
auto *enumAddr = builder.createInitEnumDataAddr(
pbLoc, optArgBuf, someEltDecl, wrappedTanType.getAddressType());
// copy_addr %wrappedAdjoint to [initialization] %enumAddr
// copy_addr %wrappedAdjoint to [init] %enumAddr
builder.createCopyAddr(pbLoc, wrappedAdjoint, enumAddr, IsNotTake,
IsInitialization);
// inject_enum_addr %optArgBuf : $*Optional<T.TangentVector>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void ExistentialSpecializerCloner::cloneArguments(
/// bb0(%0 : $*T):
/// %3 = alloc_stack $P
/// %4 = init_existential_addr %3 : $*P, $T
/// copy_addr [take] %0 to [initialization] %4 : $*T
/// copy_addr [take] %0 to [init] %4 : $*T
/// %7 = open_existential_addr immutable_access %3 : $*P to
/// $*@opened P
auto *ASI =
Expand Down
6 changes: 3 additions & 3 deletions lib/SILOptimizer/Mandatory/AddressLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1581,9 +1581,9 @@ namespace {
// br bb3(val0, val1)
// bb2:
// temp = alloc_stack
// copy_addr [take] addr0 to [initialization] temp
// copy_addr [take] addr1 to [initialization] addr0
// copy_addr [take] temp to [initialization] addr1
// copy_addr [take] addr0 to [init] temp
// copy_addr [take] addr1 to [init] addr0
// copy_addr [take] temp to [init] addr1
// dealloc_stack temp
// br bb3(val1, val1)
// bb3(phi0, phi1):
Expand Down
10 changes: 5 additions & 5 deletions lib/SILOptimizer/Transforms/CopyForwarding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// Useless copies of address-only types look like this:
//
// %copy = alloc_stack $T
// copy_addr %arg to [initialization] %copy : $*T
// copy_addr %arg to [init] %copy : $*T
// %ret = apply %callee<T>(%copy) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
// dealloc_stack %copy : $*T
// destroy_addr %arg : $*T
Expand Down Expand Up @@ -927,7 +927,7 @@ static DeallocStackInst *getSingleDealloc(AllocStackInst *ASI) {
/// %copy = alloc_stack $T
/// ...
/// CurrentBlock:
/// copy_addr %arg to [initialization] %copy : $*T
/// copy_addr %arg to [init] %copy : $*T
/// ...
/// %ret = apply %callee<T>(%copy) : $@convention(thin) <τ_0_0> (@in τ_0_0) -> ()
/// \endcode
Expand Down Expand Up @@ -1252,7 +1252,7 @@ void CopyForwarding::forwardCopiesOf(SILValue Def, SILFunction *F) {
/// %2 = alloc_stack $T
/// ... // arbitrary control flow, but no other uses of %0
/// bbN:
/// copy_addr [take] %2 to [initialization] %0 : $*T
/// copy_addr [take] %2 to [init] %0 : $*T
/// ... // no writes
/// return
static bool canNRVO(CopyAddrInst *CopyInst) {
Expand All @@ -1264,7 +1264,7 @@ static bool canNRVO(CopyAddrInst *CopyInst) {
// bb0(%in : $*T, %out : $T):
// %local = alloc_stack $T
// store %in to %local : $*T
// copy_addr %local to [initialization] %out : $*T
// copy_addr %local to [init] %out : $*T
if (!CopyInst->isTakeOfSrc())
return false;

Expand Down Expand Up @@ -1350,7 +1350,7 @@ class CopyForwardingPass : public SILFunctionTransform
// %ref = load %objaddr : $*AnyObject
// %alloc2 = alloc_stack $ObjWrapper
// # The in-memory reference is destroyed before retaining the loaded ref.
// copy_addr [take] %alloc1 to [initialization] %alloc2 : $*ObjWrapper
// copy_addr [take] %alloc1 to [init] %alloc2 : $*ObjWrapper
// retain_value %ref : $AnyObject
// destroy_addr %alloc2 : $*ObjWrapper
if (!getFunction()->hasOwnership())
Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Transforms/SILLowerAggregateInstrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static bool shouldExpandShim(SILFunction *fn, SILType type) {
/// strong_release %old : $T
/// store %new to %1 : $*T
///
/// copy_addr %0 to [initialization] %1 : $*T
/// copy_addr %0 to [init] %1 : $*T
/// ->
/// %new = load [copy] %0 : $*T
/// store %new to [init] %1 : $*T
Expand All @@ -97,7 +97,7 @@ static bool shouldExpandShim(SILFunction *fn, SILType type) {
/// // no load/release of %old!
/// store %new to %1 : $*T
///
/// copy_addr [take] %0 to [initialization] %1 : $*T
/// copy_addr [take] %0 to [init] %1 : $*T
/// ->
/// %new = load [take] %0 : $*T
/// store %new to [init] %1 : $*T
Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Transforms/SSADestroyHoisting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ void SSADestroyHoisting::run() {
// instruction into
//
// destroy_addr
// copy_addr to [initialization]
// copy_addr to [init]
//
// sequences to create still more destroy_addrs to hoist.
//
Expand Down
10 changes: 5 additions & 5 deletions lib/SILOptimizer/Transforms/TempRValueElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace {
/// are emitted as copies...
///
/// %temp = alloc_stack $T
/// copy_addr %src to [initialization] %temp : $*T
/// copy_addr %src to [init] %temp : $*T
/// // no writes to %src or %temp
/// destroy_addr %temp : $*T
/// dealloc_stack %temp : $*T
Expand All @@ -70,7 +70,7 @@ namespace {
/// a simple form of redundant-load-elimination (RLE).
///
/// %temp = alloc_stack $T
/// store %src to [initialization] %temp : $*T
/// store %src to [init] %temp : $*T
/// // no writes to %temp
/// %v = load [take] %temp : $*T
/// dealloc_stack %temp : $*T
Expand Down Expand Up @@ -379,7 +379,7 @@ SILInstruction *TempRValueOptPass::getLastUseWhileSourceIsNotModified(
/// of the temporary. For example:
///
/// %a = begin_access %src
/// copy_addr %a to [initialization] %temp : $*T
/// copy_addr %a to [init] %temp : $*T
/// end_access %a
/// use %temp
///
Expand Down Expand Up @@ -586,8 +586,8 @@ void TempRValueOptPass::tryOptimizeCopyIntoTemp(CopyAddrInst *copyInst) {
// re-initialized by exactly this instruction.
// This is a corner case, but can happen if lastLoadInst is a copy_addr.
// Example:
// copy_addr [take] %copySrc to [initialization] %tempObj // copyInst
// copy_addr [take] %tempObj to [initialization] %copySrc // lastLoadInst
// copy_addr [take] %copySrc to [init] %tempObj // copyInst
// copy_addr [take] %tempObj to [init] %copySrc // lastLoadInst
if (needToInsertDestroy && lastLoadInst != copyInst &&
!isa<DestroyAddrInst>(lastLoadInst) &&
aa->mayWriteToMemory(lastLoadInst, copySrc))
Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Utils/ConstExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1531,9 +1531,9 @@ ConstExprFunctionState::initializeAddressFromSingleWriter(SILValue addr) {
// Try finding a writer among the users of `teai`. For example:
// %179 = alloc_stack $(Int32, Int32, Int32, Int32)
// %183 = tuple_element_addr %179 : $*(Int32, Int32, Int32, Int32), 3
// copy_addr %114 to [initialization] %183 : $*Int32
// copy_addr %114 to [init] %183 : $*Int32
// %191 = tuple_element_addr %179 : $*(Int32, Int32, Int32, Int32), 3
// copy_addr [take] %191 to [initialization] %178 : $*Int32
// copy_addr [take] %191 to [init] %178 : $*Int32
//
// The workflow is: when const-evaluating %178, we const-evaluate %191,
// which in turn triggers const-evaluating %179, thereby enter this
Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Utils/Existential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using namespace swift;
/// %5 = alloc_ref $SomeC
/// store %5 to %4 : $*SomeC
/// %8 = alloc_stack $SomeP
/// copy_addr %3 to [initialization] %8 : $*SomeP
/// copy_addr %3 to [init] %8 : $*SomeP
/// %10 = apply %9(%3) : $@convention(thin) (@in_guaranteed SomeP)
/// Assumptions: Insn is a direct user of GAI (e.g., copy_addr or
/// apply pattern shown above) and that a valid init_existential_addr
Expand Down
2 changes: 1 addition & 1 deletion test/AutoDiff/SIL/sil_differentiability_witness.sil
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ sil_differentiability_witness [reverse] [parameters 0] [results 0] @foo : $@conv

sil hidden [ossa] @generic : $@convention(thin) <T> (@in_guaranteed T, Float) -> @out T {
bb0(%0 : $*T, %1 : $*T, %2 : $Float):
copy_addr %1 to [initialization] %0 : $*T
copy_addr %1 to [init] %0 : $*T
%void = tuple ()
return %void : $()
}
Expand Down
2 changes: 1 addition & 1 deletion test/AutoDiff/SILGen/autodiff_builtins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func applyDerivative_f1_vjp<T: AdditiveArithmetic & Differentiable>(t0: T) -> (T
// CHECK: [[D_RESULT_BUFFER_0_FOR_LOAD:%.*]] = tuple_element_addr [[D_RESULT_BUFFER]] : ${{.*}}, 0
// CHECK: [[D_RESULT_BUFFER_1_FOR_LOAD:%.*]] = tuple_element_addr [[D_RESULT_BUFFER]] : ${{.*}}, 1
// CHECK: [[PULLBACK:%.*]] = load [take] [[D_RESULT_BUFFER_1_FOR_LOAD]]
// CHECK: copy_addr [take] [[D_RESULT_BUFFER_0_FOR_LOAD]] to [initialization] [[ORIG_RESULT_OUT_PARAM]]
// CHECK: copy_addr [take] [[D_RESULT_BUFFER_0_FOR_LOAD]] to [init] [[ORIG_RESULT_OUT_PARAM]]
// CHECK: return [[PULLBACK]]

struct ExamplePullbackStruct<T: Differentiable> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func enum_addr_notactive<T>(_ e: AddressOnlyEnum<T>, _ x: Float) -> Float {
// CHECK-SIL-LABEL: sil hidden [ossa] @enum_addr_notactivelTJrUSpSr : $@convention(thin) <τ_0_0> (@in_guaranteed AddressOnlyEnum<τ_0_0>, Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) {
// CHECK-SIL: bb0([[ENUM_ARG:%.*]] : $*AddressOnlyEnum<τ_0_0>, [[X_ARG:%.*]] : $Float):
// CHECK-SIL: [[ENUM_ADDR:%.*]] = alloc_stack $AddressOnlyEnum<τ_0_0>
// CHECK-SIL: copy_addr [[ENUM_ARG]] to [initialization] [[ENUM_ADDR]] : $*AddressOnlyEnum<τ_0_0>
// CHECK-SIL: copy_addr [[ENUM_ARG]] to [init] [[ENUM_ADDR]] : $*AddressOnlyEnum<τ_0_0>
// CHECK-SIL: [[BB0_PB_STRUCT:%.*]] = struct $_AD__enum_addr_notactive_bb0__PB__src_0_wrt_1_l<τ_0_0> ()
// CHECK-SIL: switch_enum_addr [[ENUM_ADDR]] : $*AddressOnlyEnum<τ_0_0>, case #AddressOnlyEnum.none!enumelt: bb1, case #AddressOnlyEnum.some!enumelt: bb2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ bb0(%0 : $*T):
// CHECK: bb0([[ARG:%.*]] : $*T):
// CHECK: [[ORIG_FN:%.*]] = witness_method $T, #Protocol.method
// CHECK: [[ARGCOPY1:%.*]] = alloc_stack $T
// CHECK: copy_addr [[ARG]] to [initialization] [[ARGCOPY1]] : $*T
// CHECK: copy_addr [[ARG]] to [init] [[ARGCOPY1]] : $*T
// CHECK: [[ARGCOPY2:%.*]] = alloc_stack $T
// CHECK: copy_addr [[ARG]] to [initialization] [[ARGCOPY2]] : $*T
// CHECK: copy_addr [[ARG]] to [init] [[ARGCOPY2]] : $*T
// CHECK: [[ORIG_FN_PARTIALLY_APPLIED:%.*]] = partial_apply [callee_guaranteed] [[ORIG_FN]]<T>([[ARG]])
// CHECK: [[JVP_FN:%.*]] = witness_method $T, #Protocol.method!jvp.SU
// CHECK: [[JVP_FN_PARTIALLY_APPLIED:%.*]] = partial_apply [callee_guaranteed] [[JVP_FN]]<T>([[ARGCOPY1]])
Expand Down
Loading