Skip to content

Commit 9b654f9

Browse files
committed
Avoid code duplication
1 parent a9f13b7 commit 9b654f9

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -712,20 +712,16 @@ static void threadPrivatizeVars(lower::AbstractConverter &converter,
712712
}
713713
}
714714

715-
static mlir::Operation *
716-
createAndSetPrivatizedLoopVar(lower::AbstractConverter &converter,
717-
mlir::Location loc, mlir::Value indexVal,
718-
const semantics::Symbol *sym) {
715+
static mlir::Operation *setLoopVar(lower::AbstractConverter &converter,
716+
mlir::Location loc, mlir::Value indexVal,
717+
const semantics::Symbol *sym) {
719718
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
719+
720720
mlir::OpBuilder::InsertPoint insPt = firOpBuilder.saveInsertionPoint();
721721
firOpBuilder.setInsertionPointToStart(firOpBuilder.getAllocaBlock());
722-
723722
mlir::Type tempTy = converter.genType(*sym);
724-
725-
assert(converter.isPresentShallowLookup(*sym) &&
726-
"Expected symbol to be in symbol table.");
727-
728723
firOpBuilder.restoreInsertionPoint(insPt);
724+
729725
mlir::Value cvtVal = firOpBuilder.createConvert(loc, tempTy, indexVal);
730726
hlfir::Entity lhs{converter.getSymbolAddress(*sym)};
731727

@@ -736,6 +732,15 @@ createAndSetPrivatizedLoopVar(lower::AbstractConverter &converter,
736732
return storeOp;
737733
}
738734

735+
static mlir::Operation *
736+
createAndSetPrivatizedLoopVar(lower::AbstractConverter &converter,
737+
mlir::Location loc, mlir::Value indexVal,
738+
const semantics::Symbol *sym) {
739+
assert(converter.isPresentShallowLookup(*sym) &&
740+
"Expected symbol to be in symbol table.");
741+
return setLoopVar(converter, loc, indexVal, sym);
742+
}
743+
739744
// This helper function implements the functionality of "promoting" non-CPTR
740745
// arguments of use_device_ptr to use_device_addr arguments (automagic
741746
// conversion of use_device_ptr -> use_device_addr in these cases). The way we
@@ -2198,17 +2203,8 @@ genCanonicalLoopOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
21982203
mlir::Value userVal =
21992204
firOpBuilder.create<mlir::arith::AddIOp>(loc, loopLBVar, scaled);
22002205

2201-
mlir::OpBuilder::InsertPoint insPt = firOpBuilder.saveInsertionPoint();
2202-
firOpBuilder.setInsertionPointToStart(firOpBuilder.getAllocaBlock());
2203-
mlir::Type tempTy = converter.genType(*iv);
2204-
firOpBuilder.restoreInsertionPoint(insPt);
2205-
22062206
// Write loop value to loop variable
2207-
mlir::Value cvtVal = firOpBuilder.createConvert(loc, tempTy, userVal);
2208-
hlfir::Entity lhs{converter.getSymbolAddress(*iv)};
2209-
lhs = hlfir::derefPointersAndAllocatables(loc, firOpBuilder, lhs);
2210-
mlir::Operation *storeOp =
2211-
hlfir::AssignOp::create(firOpBuilder, loc, cvtVal, lhs);
2207+
mlir::Operation *storeOp = setLoopVar(converter, loc, userVal, iv);
22122208

22132209
firOpBuilder.setInsertionPointAfter(storeOp);
22142210
return {iv};

0 commit comments

Comments
 (0)