|
19 | 19 | #include "LValue.h" |
20 | 20 | #include "RValue.h" |
21 | 21 | #include "ResultPlan.h" |
| 22 | +#include "SGFContext.h" |
22 | 23 | #include "SILGen.h" |
23 | 24 | #include "SILGenDynamicCast.h" |
24 | 25 | #include "SILGenFunctionBuilder.h" |
|
42 | 43 | #include "swift/Basic/type_traits.h" |
43 | 44 | #include "swift/SIL/DynamicCasts.h" |
44 | 45 | #include "swift/SIL/SILArgument.h" |
| 46 | +#include "swift/SIL/SILInstruction.h" |
45 | 47 | #include "swift/SIL/SILUndef.h" |
46 | 48 | #include "swift/SIL/TypeLowering.h" |
47 | 49 | #include "llvm/ADT/STLExtras.h" |
@@ -537,6 +539,7 @@ namespace { |
537 | 539 | LinearFunctionExtractOriginalExpr *E, SGFContext C); |
538 | 540 | RValue visitLinearToDifferentiableFunctionExpr( |
539 | 541 | LinearToDifferentiableFunctionExpr *E, SGFContext C); |
| 542 | + RValue visitMoveExpr(MoveExpr *E, SGFContext C); |
540 | 543 | }; |
541 | 544 | } // end anonymous namespace |
542 | 545 |
|
@@ -5848,6 +5851,39 @@ RValue RValueEmitter::visitErrorExpr(ErrorExpr *E, SGFContext C) { |
5848 | 5851 | llvm::report_fatal_error("Found an ErrorExpr but didn't emit an error?"); |
5849 | 5852 | } |
5850 | 5853 |
|
| 5854 | +RValue RValueEmitter::visitMoveExpr(MoveExpr *E, SGFContext C) { |
| 5855 | + auto *subExpr = cast<DeclRefExpr>(E->getSubExpr()); |
| 5856 | + auto subASTType = subExpr->getType()->getCanonicalType(); |
| 5857 | + |
| 5858 | + auto subType = SGF.getLoweredType(subASTType); |
| 5859 | + |
| 5860 | + if (subType.isLoadable(SGF.F)) { |
| 5861 | + auto mv = SGF.emitRValue(subExpr).getAsSingleValue(SGF, subExpr); |
| 5862 | + if (mv.getType().isTrivial(SGF.F)) |
| 5863 | + return RValue(SGF, {mv}, subType.getASTType()); |
| 5864 | + mv = SGF.B.createMoveValue(E, mv); |
| 5865 | + auto *movedValue = cast<MoveValueInst>(mv.getValue()); |
| 5866 | + movedValue->setAllowsDiagnostics(true /*set allows diagnostics*/); |
| 5867 | + return RValue(SGF, {mv}, subType.getASTType()); |
| 5868 | + } |
| 5869 | + |
| 5870 | + // If we aren't loadable, then create a temporary initialization and |
| 5871 | + // mark_unresolved_move into that. |
| 5872 | + std::unique_ptr<TemporaryInitialization> optTemp; |
| 5873 | + optTemp = SGF.emitTemporary(E, SGF.getTypeLowering(subType)); |
| 5874 | + SILValue toAddr = optTemp->getAddressForInPlaceInitialization(SGF, E); |
| 5875 | + assert(!isa<LValueType>(E->getType()->getCanonicalType()) && |
| 5876 | + "Shouldn't see an lvalue type here"); |
| 5877 | + |
| 5878 | + ManagedValue mv = |
| 5879 | + SGF.emitRValue(subExpr, SGFContext(SGFContext::AllowImmediatePlusZero)) |
| 5880 | + .getAsSingleValue(SGF, subExpr); |
| 5881 | + assert(mv.getType().isAddress()); |
| 5882 | + SGF.B.createMarkUnresolvedMoveAddr(subExpr, mv.getValue(), toAddr); |
| 5883 | + optTemp->finishInitialization(SGF); |
| 5884 | + return RValue(SGF, {optTemp->getManagedAddress()}, subType.getASTType()); |
| 5885 | +} |
| 5886 | + |
5851 | 5887 | RValue SILGenFunction::emitRValue(Expr *E, SGFContext C) { |
5852 | 5888 | assert(!E->getType()->hasLValueType() && |
5853 | 5889 | "l-values must be emitted with emitLValue"); |
|
0 commit comments