@@ -551,6 +551,18 @@ static cir::CIRCallOpInterface emitCallLikeOp(
551
551
extraFnAttrs);
552
552
}
553
553
554
+ static RValue getRValueThroughMemory (mlir::Location loc,
555
+ CIRGenBuilderTy &builder,
556
+ mlir::Value val,
557
+ Address addr) {
558
+ auto ip = builder.saveInsertionPoint ();
559
+ builder.setInsertionPointAfterValue (val);
560
+ builder.createStore (loc, val, addr);
561
+ builder.restoreInsertionPoint (ip);
562
+ auto load = builder.createLoad (loc, addr);
563
+ return RValue::get (load);
564
+ }
565
+
554
566
RValue CIRGenFunction::emitCall (const CIRGenFunctionInfo &CallInfo,
555
567
const CIRGenCallee &Callee,
556
568
ReturnValueSlot ReturnValue,
@@ -890,19 +902,15 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &CallInfo,
890
902
assert (Results.size () <= 1 && " multiple returns NYI" );
891
903
assert (Results[0 ].getType () == RetCIRTy && " Bitcast support NYI" );
892
904
893
- auto reg = builder.getBlock ()->getParent ();
894
- if (reg != theCall->getParentRegion ()) {
905
+ auto region = builder.getBlock ()->getParent ();
906
+ if (region != theCall->getParentRegion ()) {
895
907
Address DestPtr = ReturnValue.getValue ();
896
908
897
909
if (!DestPtr.isValid ())
898
910
DestPtr = CreateMemTemp (RetTy, callLoc, " tmp" );
899
911
900
- auto ip = builder.saveInsertionPoint ();
901
- builder.setInsertionPointAfter (theCall);
902
- builder.createStore (callLoc, Results[0 ], DestPtr);
903
- builder.restoreInsertionPoint (ip);
904
- auto load = builder.createLoad (callLoc, DestPtr);
905
- return RValue::get (load);
912
+ return getRValueThroughMemory (callLoc, builder, Results[0 ],
913
+ DestPtr);
906
914
}
907
915
908
916
return RValue::get (Results[0 ]);
0 commit comments