43
43
using namespace swift ;
44
44
using namespace Lowering ;
45
45
46
+ // Necessary to straightforwardly write SIL tests that exercise
47
+ // OpaqueValueTypeLowering (and MoveOnlyOpaqueValueTypeLowering): the tests can
48
+ // be written as though opaque values were enabled to begin but have since been
49
+ // lowered out of.
50
+ llvm::cl::opt<bool > TypeLoweringForceOpaqueValueLowering (
51
+ " type-lowering-force-opaque-value-lowering" , llvm::cl::init(false ),
52
+ llvm::cl::desc(" Force TypeLowering to behave as if building with opaque "
53
+ " values enabled" ));
54
+
46
55
namespace {
47
56
// / A CRTP type visitor for deciding whether the metatype for a type
48
57
// / is a singleton type, i.e. whether there can only ever be one
@@ -1941,7 +1950,12 @@ namespace {
1941
1950
void emitCopyInto (SILBuilder &B, SILLocation loc,
1942
1951
SILValue src, SILValue dest, IsTake_t isTake,
1943
1952
IsInitialization_t isInit) const override {
1944
- llvm_unreachable (" copy into" );
1953
+ if (B.getModule ().useLoweredAddresses ()) {
1954
+ B.createCopyAddr (loc, src, dest, isTake, isInit);
1955
+ } else {
1956
+ SILValue value = emitLoadOfCopy (B, loc, src, isTake);
1957
+ emitStoreOfCopy (B, loc, value, dest, isInit);
1958
+ }
1945
1959
}
1946
1960
1947
1961
// OpaqueValue store cannot be decoupled from a destroy because it is not
@@ -2066,7 +2080,8 @@ namespace {
2066
2080
2067
2081
TypeLowering *handleMoveOnlyAddressOnly (CanType type,
2068
2082
RecursiveProperties properties) {
2069
- if (!TC.Context .SILOpts .EnableSILOpaqueValues ) {
2083
+ if (!TC.Context .SILOpts .EnableSILOpaqueValues &&
2084
+ !TypeLoweringForceOpaqueValueLowering) {
2070
2085
auto silType = SILType::getPrimitiveAddressType (type);
2071
2086
return new (TC)
2072
2087
MoveOnlyAddressOnlyTypeLowering (silType, properties, Expansion);
@@ -2084,7 +2099,8 @@ namespace {
2084
2099
2085
2100
TypeLowering *handleAddressOnly (CanType type,
2086
2101
RecursiveProperties properties) {
2087
- if (!TC.Context .SILOpts .EnableSILOpaqueValues ) {
2102
+ if (!TC.Context .SILOpts .EnableSILOpaqueValues &&
2103
+ !TypeLoweringForceOpaqueValueLowering) {
2088
2104
auto silType = SILType::getPrimitiveAddressType (type);
2089
2105
return new (TC) AddressOnlyTypeLowering (silType, properties,
2090
2106
Expansion);
0 commit comments