@@ -780,7 +780,7 @@ static void allocByValReductionVars(
780
780
llvm::Value *var = builder.CreateAlloca (
781
781
moduleTranslation.convertType (reductionDecls[i].getType ()));
782
782
moduleTranslation.mapValue (args[i], var);
783
- privateReductionVariables. push_back ( var) ;
783
+ privateReductionVariables[i] = var;
784
784
reductionVariableMap.try_emplace (loop.getReductionVars ()[i], var);
785
785
}
786
786
}
@@ -911,7 +911,8 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
911
911
llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
912
912
findAllocaInsertPoint (builder, moduleTranslation);
913
913
914
- SmallVector<llvm::Value *> privateReductionVariables;
914
+ SmallVector<llvm::Value *> privateReductionVariables (
915
+ wsloopOp.getNumReductionVars ());
915
916
DenseMap<Value, llvm::Value *> reductionVariableMap;
916
917
allocByValReductionVars (wsloopOp, builder, moduleTranslation, allocaIP,
917
918
reductionDecls, privateReductionVariables,
@@ -942,7 +943,7 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
942
943
// ptr
943
944
builder.CreateStore (phis[0 ], var);
944
945
945
- privateReductionVariables. push_back ( var) ;
946
+ privateReductionVariables[i] = var;
946
947
moduleTranslation.mapValue (reductionArgs[i], phis[0 ]);
947
948
reductionVariableMap.try_emplace (wsloopOp.getReductionVars ()[i], phis[0 ]);
948
949
} else {
@@ -1140,7 +1141,8 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
1140
1141
// Collect reduction declarations
1141
1142
SmallVector<omp::DeclareReductionOp> reductionDecls;
1142
1143
collectReductionDecls (opInst, reductionDecls);
1143
- SmallVector<llvm::Value *> privateReductionVariables;
1144
+ SmallVector<llvm::Value *> privateReductionVariables (
1145
+ opInst.getNumReductionVars ());
1144
1146
1145
1147
auto bodyGenCB = [&](InsertPointTy allocaIP, InsertPointTy codeGenIP) {
1146
1148
// Allocate reduction vars
@@ -1159,15 +1161,14 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
1159
1161
allocaIP =
1160
1162
InsertPointTy (allocaIP.getBlock (),
1161
1163
allocaIP.getBlock ()->getTerminator ()->getIterator ());
1162
- SmallVector<llvm::Value *> byRefVars;
1163
- if (isByRef ) {
1164
- for ( unsigned i = 0 ; i < opInst. getNumReductionVars (); ++i ) {
1164
+ SmallVector<llvm::Value *> byRefVars (opInst. getNumReductionVars ()) ;
1165
+ for ( unsigned i = 0 ; i < opInst. getNumReductionVars (); ++i ) {
1166
+ if (isByRef[i] ) {
1165
1167
// Allocate reduction variable (which is a pointer to the real reduciton
1166
1168
// variable allocated in the inlined region)
1167
- byRefVars. push_back ( builder.CreateAlloca (
1168
- moduleTranslation.convertType (reductionDecls[i].getType ()))) ;
1169
+ byRefVars[i] = builder.CreateAlloca (
1170
+ moduleTranslation.convertType (reductionDecls[i].getType ()));
1169
1171
}
1170
-
1171
1172
}
1172
1173
1173
1174
for (unsigned i = 0 ; i < opInst.getNumReductionVars (); ++i) {
@@ -1184,12 +1185,12 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
1184
1185
" reduction neutral element declaration region" );
1185
1186
builder.SetInsertPoint (initBlock->getTerminator ());
1186
1187
1187
- if (isByRef) {
1188
+ if (isByRef[i] ) {
1188
1189
// Store the result of the inlined region to the allocated reduction var
1189
1190
// ptr
1190
1191
builder.CreateStore (phis[0 ], byRefVars[i]);
1191
1192
1192
- privateReductionVariables. push_back ( byRefVars[i]) ;
1193
+ privateReductionVariables[i] = byRefVars[i];
1193
1194
moduleTranslation.mapValue (reductionArgs[i], phis[0 ]);
1194
1195
reductionVariableMap.try_emplace (opInst.getReductionVars ()[i], phis[0 ]);
1195
1196
} else {
0 commit comments