@@ -916,49 +916,50 @@ static LogicalResult inlineReductionCleanup(
916
916
static LogicalResult
917
917
convertOmpWsloop (Operation &opInst, llvm::IRBuilderBase &builder,
918
918
LLVM::ModuleTranslation &moduleTranslation) {
919
- auto loop = cast<omp::WsloopOp>(opInst);
920
- const bool isByRef = loop.getByref ();
919
+ auto wsloopOp = cast<omp::WsloopOp>(opInst);
920
+ auto loopOp = cast<omp::LoopNestOp>(wsloopOp.getWrappedLoop ());
921
+ const bool isByRef = wsloopOp.getByref ();
922
+
921
923
// TODO: this should be in the op verifier instead.
922
- if (loop .getLowerBound ().empty ())
924
+ if (loopOp .getLowerBound ().empty ())
923
925
return failure ();
924
926
925
927
// Static is the default.
926
928
auto schedule =
927
- loop .getScheduleVal ().value_or (omp::ClauseScheduleKind::Static);
929
+ wsloopOp .getScheduleVal ().value_or (omp::ClauseScheduleKind::Static);
928
930
929
931
// Find the loop configuration.
930
- llvm::Value *step = moduleTranslation.lookupValue (loop .getStep ()[0 ]);
932
+ llvm::Value *step = moduleTranslation.lookupValue (loopOp .getStep ()[0 ]);
931
933
llvm::Type *ivType = step->getType ();
932
934
llvm::Value *chunk = nullptr ;
933
- if (loop .getScheduleChunkVar ()) {
935
+ if (wsloopOp .getScheduleChunkVar ()) {
934
936
llvm::Value *chunkVar =
935
- moduleTranslation.lookupValue (loop .getScheduleChunkVar ());
937
+ moduleTranslation.lookupValue (wsloopOp .getScheduleChunkVar ());
936
938
chunk = builder.CreateSExtOrTrunc (chunkVar, ivType);
937
939
}
938
940
939
941
SmallVector<omp::DeclareReductionOp> reductionDecls;
940
- collectReductionDecls (loop , reductionDecls);
942
+ collectReductionDecls (wsloopOp , reductionDecls);
941
943
llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
942
944
findAllocaInsertPoint (builder, moduleTranslation);
943
945
944
946
SmallVector<llvm::Value *> privateReductionVariables;
945
947
DenseMap<Value, llvm::Value *> reductionVariableMap;
946
948
if (!isByRef) {
947
- allocByValReductionVars (loop , builder, moduleTranslation, allocaIP,
949
+ allocByValReductionVars (wsloopOp , builder, moduleTranslation, allocaIP,
948
950
reductionDecls, privateReductionVariables,
949
951
reductionVariableMap);
950
952
}
951
953
952
954
// Before the loop, store the initial values of reductions into reduction
953
955
// variables. Although this could be done after allocas, we don't want to mess
954
956
// up with the alloca insertion point.
955
- MutableArrayRef<BlockArgument> reductionArgs =
956
- loop.getRegion ().getArguments ().take_back (loop.getNumReductionVars ());
957
- for (unsigned i = 0 ; i < loop.getNumReductionVars (); ++i) {
957
+ ArrayRef<BlockArgument> reductionArgs = wsloopOp.getRegion ().getArguments ();
958
+ for (unsigned i = 0 ; i < wsloopOp.getNumReductionVars (); ++i) {
958
959
SmallVector<llvm::Value *> phis;
959
960
960
961
// map block argument to initializer region
961
- mapInitializationArg (loop , moduleTranslation, reductionDecls, i);
962
+ mapInitializationArg (wsloopOp , moduleTranslation, reductionDecls, i);
962
963
963
964
if (failed (inlineConvertOmpRegions (reductionDecls[i].getInitializerRegion (),
964
965
" omp.reduction.neutral" , builder,
@@ -977,7 +978,7 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
977
978
978
979
privateReductionVariables.push_back (var);
979
980
moduleTranslation.mapValue (reductionArgs[i], phis[0 ]);
980
- reductionVariableMap.try_emplace (loop .getReductionVars ()[i], phis[0 ]);
981
+ reductionVariableMap.try_emplace (wsloopOp .getReductionVars ()[i], phis[0 ]);
981
982
} else {
982
983
// for by-ref case the store is inside of the reduction region
983
984
builder.CreateStore (phis[0 ], privateReductionVariables[i]);
@@ -1008,33 +1009,34 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
1008
1009
auto bodyGen = [&](llvm::OpenMPIRBuilder::InsertPointTy ip, llvm::Value *iv) {
1009
1010
// Make sure further conversions know about the induction variable.
1010
1011
moduleTranslation.mapValue (
1011
- loop .getRegion ().front ().getArgument (loopInfos.size ()), iv);
1012
+ loopOp .getRegion ().front ().getArgument (loopInfos.size ()), iv);
1012
1013
1013
1014
// Capture the body insertion point for use in nested loops. BodyIP of the
1014
1015
// CanonicalLoopInfo always points to the beginning of the entry block of
1015
1016
// the body.
1016
1017
bodyInsertPoints.push_back (ip);
1017
1018
1018
- if (loopInfos.size () != loop .getNumLoops () - 1 )
1019
+ if (loopInfos.size () != loopOp .getNumLoops () - 1 )
1019
1020
return ;
1020
1021
1021
1022
// Convert the body of the loop.
1022
1023
builder.restoreIP (ip);
1023
- convertOmpOpRegions (loop .getRegion (), " omp.wsloop.region" , builder,
1024
+ convertOmpOpRegions (loopOp .getRegion (), " omp.wsloop.region" , builder,
1024
1025
moduleTranslation, bodyGenStatus);
1025
1026
};
1026
1027
1027
1028
// Delegate actual loop construction to the OpenMP IRBuilder.
1028
- // TODO: this currently assumes Wsloop is semantically similar to SCF loop,
1029
- // i.e. it has a positive step, uses signed integer semantics. Reconsider
1030
- // this code when Wsloop clearly supports more cases.
1029
+ // TODO: this currently assumes omp.loop_nest is semantically similar to SCF
1030
+ // loop, i.e. it has a positive step, uses signed integer semantics.
1031
+ // Reconsider this code when the nested loop operation clearly supports more
1032
+ // cases.
1031
1033
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder ();
1032
- for (unsigned i = 0 , e = loop .getNumLoops (); i < e; ++i) {
1034
+ for (unsigned i = 0 , e = loopOp .getNumLoops (); i < e; ++i) {
1033
1035
llvm::Value *lowerBound =
1034
- moduleTranslation.lookupValue (loop .getLowerBound ()[i]);
1036
+ moduleTranslation.lookupValue (loopOp .getLowerBound ()[i]);
1035
1037
llvm::Value *upperBound =
1036
- moduleTranslation.lookupValue (loop .getUpperBound ()[i]);
1037
- llvm::Value *step = moduleTranslation.lookupValue (loop .getStep ()[i]);
1038
+ moduleTranslation.lookupValue (loopOp .getUpperBound ()[i]);
1039
+ llvm::Value *step = moduleTranslation.lookupValue (loopOp .getStep ()[i]);
1038
1040
1039
1041
// Make sure loop trip count are emitted in the preheader of the outermost
1040
1042
// loop at the latest so that they are all available for the new collapsed
@@ -1047,7 +1049,7 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
1047
1049
}
1048
1050
loopInfos.push_back (ompBuilder->createCanonicalLoop (
1049
1051
loc, bodyGen, lowerBound, upperBound, step,
1050
- /* IsSigned=*/ true , loop .getInclusive (), computeIP));
1052
+ /* IsSigned=*/ true , loopOp .getInclusive (), computeIP));
1051
1053
1052
1054
if (failed (bodyGenStatus))
1053
1055
return failure ();
@@ -1062,13 +1064,13 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
1062
1064
allocaIP = findAllocaInsertPoint (builder, moduleTranslation);
1063
1065
1064
1066
// TODO: Handle doacross loops when the ordered clause has a parameter.
1065
- bool isOrdered = loop .getOrderedVal ().has_value ();
1067
+ bool isOrdered = wsloopOp .getOrderedVal ().has_value ();
1066
1068
std::optional<omp::ScheduleModifier> scheduleModifier =
1067
- loop .getScheduleModifier ();
1068
- bool isSimd = loop .getSimdModifier ();
1069
+ wsloopOp .getScheduleModifier ();
1070
+ bool isSimd = wsloopOp .getSimdModifier ();
1069
1071
1070
1072
ompBuilder->applyWorkshareLoop (
1071
- ompLoc.DL , loopInfo, allocaIP, !loop .getNowait (),
1073
+ ompLoc.DL , loopInfo, allocaIP, !wsloopOp .getNowait (),
1072
1074
convertToScheduleKind (schedule), chunk, isSimd,
1073
1075
scheduleModifier == omp::ScheduleModifier::monotonic,
1074
1076
scheduleModifier == omp::ScheduleModifier::nonmonotonic, isOrdered);
@@ -1080,15 +1082,15 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
1080
1082
builder.restoreIP (afterIP);
1081
1083
1082
1084
// Process the reductions if required.
1083
- if (loop .getNumReductionVars () == 0 )
1085
+ if (wsloopOp .getNumReductionVars () == 0 )
1084
1086
return success ();
1085
1087
1086
1088
// Create the reduction generators. We need to own them here because
1087
1089
// ReductionInfo only accepts references to the generators.
1088
1090
SmallVector<OwningReductionGen> owningReductionGens;
1089
1091
SmallVector<OwningAtomicReductionGen> owningAtomicReductionGens;
1090
1092
SmallVector<llvm::OpenMPIRBuilder::ReductionInfo> reductionInfos;
1091
- collectReductionInfo (loop , builder, moduleTranslation, reductionDecls,
1093
+ collectReductionInfo (wsloopOp , builder, moduleTranslation, reductionDecls,
1092
1094
owningReductionGens, owningAtomicReductionGens,
1093
1095
privateReductionVariables, reductionInfos);
1094
1096
@@ -1099,9 +1101,9 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
1099
1101
builder.SetInsertPoint (tempTerminator);
1100
1102
llvm::OpenMPIRBuilder::InsertPointTy contInsertPoint =
1101
1103
ompBuilder->createReductions (builder.saveIP (), allocaIP, reductionInfos,
1102
- loop .getNowait (), isByRef);
1104
+ wsloopOp .getNowait (), isByRef);
1103
1105
if (!contInsertPoint.getBlock ())
1104
- return loop ->emitOpError () << " failed to convert reductions" ;
1106
+ return wsloopOp ->emitOpError () << " failed to convert reductions" ;
1105
1107
auto nextInsertionPoint =
1106
1108
ompBuilder->createBarrier (contInsertPoint, llvm::omp::OMPD_for);
1107
1109
tempTerminator->eraseFromParent ();
0 commit comments