Skip to content

Commit 535d84e

Browse files
Fix bugs
1 parent 98719af commit 535d84e

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ static void allocByValReductionVars(
780780
llvm::Value *var = builder.CreateAlloca(
781781
moduleTranslation.convertType(reductionDecls[i].getType()));
782782
moduleTranslation.mapValue(args[i], var);
783-
privateReductionVariables.push_back(var);
783+
privateReductionVariables[i] = var;
784784
reductionVariableMap.try_emplace(loop.getReductionVars()[i], var);
785785
}
786786
}
@@ -911,7 +911,8 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
911911
llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
912912
findAllocaInsertPoint(builder, moduleTranslation);
913913

914-
SmallVector<llvm::Value *> privateReductionVariables;
914+
SmallVector<llvm::Value *> privateReductionVariables(
915+
wsloopOp.getNumReductionVars());
915916
DenseMap<Value, llvm::Value *> reductionVariableMap;
916917
allocByValReductionVars(wsloopOp, builder, moduleTranslation, allocaIP,
917918
reductionDecls, privateReductionVariables,
@@ -942,7 +943,7 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder,
942943
// ptr
943944
builder.CreateStore(phis[0], var);
944945

945-
privateReductionVariables.push_back(var);
946+
privateReductionVariables[i] = var;
946947
moduleTranslation.mapValue(reductionArgs[i], phis[0]);
947948
reductionVariableMap.try_emplace(wsloopOp.getReductionVars()[i], phis[0]);
948949
} else {
@@ -1140,7 +1141,8 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
11401141
// Collect reduction declarations
11411142
SmallVector<omp::DeclareReductionOp> reductionDecls;
11421143
collectReductionDecls(opInst, reductionDecls);
1143-
SmallVector<llvm::Value *> privateReductionVariables;
1144+
SmallVector<llvm::Value *> privateReductionVariables(
1145+
opInst.getNumReductionVars());
11441146

11451147
auto bodyGenCB = [&](InsertPointTy allocaIP, InsertPointTy codeGenIP) {
11461148
// Allocate reduction vars
@@ -1159,15 +1161,14 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
11591161
allocaIP =
11601162
InsertPointTy(allocaIP.getBlock(),
11611163
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]) {
11651167
// Allocate reduction variable (which is a pointer to the real reduciton
11661168
// 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()));
11691171
}
1170-
11711172
}
11721173

11731174
for (unsigned i = 0; i < opInst.getNumReductionVars(); ++i) {
@@ -1184,12 +1185,12 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
11841185
"reduction neutral element declaration region");
11851186
builder.SetInsertPoint(initBlock->getTerminator());
11861187

1187-
if (isByRef) {
1188+
if (isByRef[i]) {
11881189
// Store the result of the inlined region to the allocated reduction var
11891190
// ptr
11901191
builder.CreateStore(phis[0], byRefVars[i]);
11911192

1192-
privateReductionVariables.push_back(byRefVars[i]);
1193+
privateReductionVariables[i] = byRefVars[i];
11931194
moduleTranslation.mapValue(reductionArgs[i], phis[0]);
11941195
reductionVariableMap.try_emplace(opInst.getReductionVars()[i], phis[0]);
11951196
} else {

0 commit comments

Comments
 (0)