Skip to content

Commit ea57903

Browse files
authored
Merge pull request #1434 from swiftwasm/master
[pull] swiftwasm from master
2 parents 5a824de + 00b3473 commit ea57903

File tree

73 files changed

+4059
-2321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+4059
-2321
lines changed

docs/SIL.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5148,6 +5148,21 @@ unchecked_bitwise_cast
51485148
Bitwise copies an object of type ``A`` into a new object of type ``B``
51495149
of the same size or smaller.
51505150

5151+
unchecked_value_cast
5152+
````````````````````
5153+
::
5154+
5155+
sil-instruction ::= 'unchecked_value_cast' sil-operand 'to' sil-type
5156+
5157+
%1 = unchecked_value_cast %0 : $A to $B
5158+
5159+
Bitwise copies an object of type ``A`` into a new layout-compatible object of
5160+
type ``B`` of the same size.
5161+
5162+
This instruction is assumed to forward a fixed ownership (set upon its
5163+
construction) and lowers to 'unchecked_bitwise_cast' in non-ossa code. This
5164+
causes the cast to lose its guarantee of layout-compatibility.
5165+
51515166
ref_to_raw_pointer
51525167
``````````````````
51535168
::

include/swift/SIL/SILBuilder.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,12 @@ class SILBuilder {
11021102
getSILDebugLocation(Loc), Op, Ty, getFunction(), C.OpenedArchetypes));
11031103
}
11041104

1105+
UncheckedValueCastInst *createUncheckedValueCast(SILLocation Loc, SILValue Op,
1106+
SILType Ty) {
1107+
return insert(UncheckedValueCastInst::create(
1108+
getSILDebugLocation(Loc), Op, Ty, getFunction(), C.OpenedArchetypes));
1109+
}
1110+
11051111
RefToBridgeObjectInst *createRefToBridgeObject(SILLocation Loc, SILValue Ref,
11061112
SILValue Bits) {
11071113
auto Ty = SILType::getBridgeObjectType(getASTContext());
@@ -1847,7 +1853,18 @@ class SILBuilder {
18471853
// Unchecked cast helpers
18481854
//===--------------------------------------------------------------------===//
18491855

1850-
// Create the appropriate cast instruction based on result type.
1856+
/// Create the appropriate cast instruction based on result type.
1857+
///
1858+
/// NOTE: We allow for non-layout compatible casts that shrink the underlying
1859+
/// type we are bit casting!
1860+
SingleValueInstruction *
1861+
createUncheckedReinterpretCast(SILLocation Loc, SILValue Op, SILType Ty);
1862+
1863+
/// Create an appropriate cast instruction based on result type.
1864+
///
1865+
/// NOTE: This assumes that the input and the result cast are layout
1866+
/// compatible. Reduces to createUncheckedReinterpretCast when ownership is
1867+
/// disabled.
18511868
SingleValueInstruction *createUncheckedBitCast(SILLocation Loc, SILValue Op,
18521869
SILType Ty);
18531870

include/swift/SIL/SILCloner.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,16 @@ visitUncheckedBitwiseCastInst(UncheckedBitwiseCastInst *Inst) {
15381538
getOpType(Inst->getType())));
15391539
}
15401540

1541+
template <typename ImplClass>
1542+
void SILCloner<ImplClass>::visitUncheckedValueCastInst(
1543+
UncheckedValueCastInst *Inst) {
1544+
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
1545+
recordClonedInstruction(Inst, getBuilder().createUncheckedValueCast(
1546+
getOpLocation(Inst->getLoc()),
1547+
getOpValue(Inst->getOperand()),
1548+
getOpType(Inst->getType())));
1549+
}
1550+
15411551
template<typename ImplClass>
15421552
void
15431553
SILCloner<ImplClass>::

include/swift/SIL/SILInstruction.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4576,6 +4576,23 @@ class UncheckedBitwiseCastInst final
45764576
SILFunction &F, SILOpenedArchetypesState &OpenedArchetypes);
45774577
};
45784578

4579+
/// Bitwise copy a value into another value of the same size.
4580+
class UncheckedValueCastInst final
4581+
: public UnaryInstructionWithTypeDependentOperandsBase<
4582+
SILInstructionKind::UncheckedValueCastInst, UncheckedValueCastInst,
4583+
OwnershipForwardingConversionInst> {
4584+
friend SILBuilder;
4585+
4586+
UncheckedValueCastInst(SILDebugLocation DebugLoc, SILValue Operand,
4587+
ArrayRef<SILValue> TypeDependentOperands, SILType Ty)
4588+
: UnaryInstructionWithTypeDependentOperandsBase(
4589+
DebugLoc, Operand, TypeDependentOperands, Ty,
4590+
Operand.getOwnershipKind()) {}
4591+
static UncheckedValueCastInst *
4592+
create(SILDebugLocation DebugLoc, SILValue Operand, SILType Ty,
4593+
SILFunction &F, SILOpenedArchetypesState &OpenedArchetypes);
4594+
};
4595+
45794596
/// Build a Builtin.BridgeObject from a heap object reference by bitwise-or-ing
45804597
/// in bits from a word.
45814598
class RefToBridgeObjectInst

include/swift/SIL/SILNodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
500500
ConversionInst, None, DoesNotRelease)
501501
SINGLE_VALUE_INST(UncheckedBitwiseCastInst, unchecked_bitwise_cast,
502502
ConversionInst, None, DoesNotRelease)
503+
SINGLE_VALUE_INST(UncheckedValueCastInst, unchecked_value_cast,
504+
ConversionInst, None, DoesNotRelease)
503505
SINGLE_VALUE_INST(RefToRawPointerInst, ref_to_raw_pointer,
504506
ConversionInst, None, DoesNotRelease)
505507
SINGLE_VALUE_INST(RawPointerToRefInst, raw_pointer_to_ref,

include/swift/SILOptimizer/Differentiation/ADContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ ADContext::emitNondifferentiabilityError(SourceLoc loc,
357357
return diagnose(loc, diag::autodiff_when_differentiating_function_call);
358358
}
359359
}
360-
llvm_unreachable("invalid invoker");
360+
llvm_unreachable("Invalid invoker kind"); // silences MSVC C4715
361361
}
362362

363363
} // end namespace autodiff

0 commit comments

Comments
 (0)