Skip to content

Commit c78799e

Browse files
committed
adds helper function
1 parent 6bf3852 commit c78799e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,18 @@ static cir::CIRCallOpInterface emitCallLikeOp(
551551
extraFnAttrs);
552552
}
553553

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+
554566
RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &CallInfo,
555567
const CIRGenCallee &Callee,
556568
ReturnValueSlot ReturnValue,
@@ -890,19 +902,15 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &CallInfo,
890902
assert(Results.size() <= 1 && "multiple returns NYI");
891903
assert(Results[0].getType() == RetCIRTy && "Bitcast support NYI");
892904

893-
auto reg = builder.getBlock()->getParent();
894-
if (reg != theCall->getParentRegion()) {
905+
auto region = builder.getBlock()->getParent();
906+
if (region != theCall->getParentRegion()) {
895907
Address DestPtr = ReturnValue.getValue();
896908

897909
if (!DestPtr.isValid())
898910
DestPtr = CreateMemTemp(RetTy, callLoc, "tmp");
899911

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);
906914
}
907915

908916
return RValue::get(Results[0]);

0 commit comments

Comments
 (0)