Skip to content

Commit e923c69

Browse files
committed
R3: Addressing review comments
1 parent a8fb6bd commit e923c69

File tree

3 files changed

+42
-34
lines changed

3 files changed

+42
-34
lines changed

llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3901,8 +3901,9 @@ class CanonicalLoopInfo {
39013901
};
39023902

39033903
/// ScanInfo holds the information to assist in lowering of Scan reduction.
3904-
/// Before lowering, body of the for loop specifying scan reduction is expected
3905-
/// to have the following structure
3904+
/// Before lowering, the body of the for loop specifying scan reduction is
3905+
/// expected to have the following structure
3906+
///
39063907
/// Loop Body Entry
39073908
/// |
39083909
/// Code before the scan directive
@@ -3943,30 +3944,38 @@ class CanonicalLoopInfo {
39433944
/// Temporary buffer allocations are done in `ScanLoopInit` block before the
39443945
/// lowering of for-loop. The results are copied back to reduction variable in
39453946
/// `ScanLoopFinish` block.
3946-
39473947
class ScanInfo {
39483948
public:
39493949
/// Dominates the body of the loop before scan directive
39503950
llvm::BasicBlock *OMPBeforeScanBlock = nullptr;
3951+
39513952
/// Dominates the body of the loop before scan directive
39523953
llvm::BasicBlock *OMPAfterScanBlock = nullptr;
3954+
39533955
/// Controls the flow to before or after scan blocks
39543956
llvm::BasicBlock *OMPScanDispatch = nullptr;
3957+
39553958
/// Exit block of loop body
39563959
llvm::BasicBlock *OMPScanLoopExit = nullptr;
3960+
39573961
/// Block before loop body where scan initializations are done
39583962
llvm::BasicBlock *OMPScanInit = nullptr;
3963+
39593964
/// Block after loop body where scan finalizations are done
39603965
llvm::BasicBlock *OMPScanFinish = nullptr;
3966+
39613967
/// If true, it indicates Input phase is lowered; else it indicates
39623968
/// ScanPhase is lowered
39633969
bool OMPFirstScanLoop = false;
3970+
39643971
/// Maps the private reduction variable to the pointer of the temporary
39653972
/// buffer
39663973
llvm::SmallDenseMap<llvm::Value *, llvm::Value *> *ScanBuffPtrs;
3974+
39673975
/// Keeps track of value of iteration variable for input/scan loop to be
39683976
/// used for Scan directive lowering
39693977
llvm::Value *IV;
3978+
39703979
/// Stores the span of canonical loop being lowered to be used for temporary
39713980
/// buffer allocation or Finalization.
39723981
llvm::Value *Span;

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4238,14 +4238,14 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitScanReduction(
42384238
Builder.SetInsertPoint(LoopBB);
42394239

42404240
PHINode *Counter = Builder.CreatePHI(Builder.getInt32Ty(), 2);
4241-
//// size pow2k = 1;
4241+
// size pow2k = 1;
42424242
PHINode *Pow2K = Builder.CreatePHI(Builder.getInt32Ty(), 2);
42434243
Counter->addIncoming(llvm::ConstantInt::get(Builder.getInt32Ty(), 0),
42444244
InputBB);
42454245
Pow2K->addIncoming(llvm::ConstantInt::get(Builder.getInt32Ty(), 1),
42464246
InputBB);
4247-
//// for (size i = n - 1; i >= 2 ^ k; --i)
4248-
//// tmp[i] op= tmp[i-pow2k];
4247+
// for (size i = n - 1; i >= 2 ^ k; --i)
4248+
// tmp[i] op= tmp[i-pow2k];
42494249
llvm::BasicBlock *InnerLoopBB =
42504250
BasicBlock::Create(CurFn->getContext(), "omp.inner.log.scan.body");
42514251
llvm::BasicBlock *InnerExitBB =
@@ -4254,7 +4254,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitScanReduction(
42544254
Builder.CreateCondBr(CmpI, InnerLoopBB, InnerExitBB);
42554255
emitBlock(InnerLoopBB, CurFn);
42564256
Builder.SetInsertPoint(InnerLoopBB);
4257-
auto *IVal = Builder.CreatePHI(Builder.getInt32Ty(), 2);
4257+
PHINode *IVal = Builder.CreatePHI(Builder.getInt32Ty(), 2);
42584258
IVal->addIncoming(NMin1, LoopBB);
42594259
for (ReductionInfo RedInfo : ReductionInfos) {
42604260
Value *ReductionVal = RedInfo.PrivateVariable;
@@ -4329,9 +4329,9 @@ Error OpenMPIRBuilder::emitScanBasedDirectiveIR(
43294329
// buffer[i] = red;
43304330
// }
43314331
ScanRedInfo->OMPFirstScanLoop = true;
4332-
auto Result = InputLoopGen();
4333-
if (Result)
4334-
return Result;
4332+
Error Err = InputLoopGen();
4333+
if (Err)
4334+
return Err;
43354335
}
43364336
{
43374337
// Emit loop with scan phase:
@@ -4340,9 +4340,9 @@ Error OpenMPIRBuilder::emitScanBasedDirectiveIR(
43404340
// <scan phase>;
43414341
// }
43424342
ScanRedInfo->OMPFirstScanLoop = false;
4343-
auto Result = ScanLoopGen(Builder.saveIP());
4344-
if (Result)
4345-
return Result;
4343+
Error Err = ScanLoopGen(Builder.saveIP());
4344+
if (Err)
4345+
return Err;
43464346
}
43474347
return Error::success();
43484348
}
@@ -4499,17 +4499,17 @@ OpenMPIRBuilder::createCanonicalScanLoops(
44994499
};
45004500

45014501
const auto &&InputLoopGen = [&]() -> Error {
4502-
auto LoopInfo = createCanonicalLoop(Builder.saveIP(), BodyGen, Start, Stop,
4503-
Step, IsSigned, InclusiveStop,
4504-
ComputeIP, Name, true, ScanRedInfo);
4502+
Expected<CanonicalLoopInfo *> LoopInfo = createCanonicalLoop(
4503+
Builder.saveIP(), BodyGen, Start, Stop, Step, IsSigned, InclusiveStop,
4504+
ComputeIP, Name, true, ScanRedInfo);
45054505
if (!LoopInfo)
45064506
return LoopInfo.takeError();
45074507
Result.push_back(*LoopInfo);
45084508
Builder.restoreIP((*LoopInfo)->getAfterIP());
45094509
return Error::success();
45104510
};
45114511
const auto &&ScanLoopGen = [&](LocationDescription Loc) -> Error {
4512-
auto LoopInfo =
4512+
Expected<CanonicalLoopInfo *> LoopInfo =
45134513
createCanonicalLoop(Loc, BodyGen, Start, Stop, Step, IsSigned,
45144514
InclusiveStop, ComputeIP, Name, true, ScanRedInfo);
45154515
if (!LoopInfo)

llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
//===- llvm/unittest/IR/OpenMPIRBuilderTest.cpp - OpenMPIRBuilder tests ---===//
32
//
43
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -5473,22 +5472,22 @@ TEST_F(OpenMPIRBuilderTest, ScanReduction) {
54735472
unsigned NumLog = 0;
54745473
unsigned NumCeil = 0;
54755474
for (Instruction &I : instructions(F)) {
5476-
if (isa<CallInst>(I)) {
5477-
CallInst *Call = dyn_cast<CallInst>(&I);
5478-
auto Name = Call->getCalledFunction()->getName();
5479-
if (Name.equals_insensitive("malloc")) {
5480-
NumMallocs += 1;
5481-
} else if (Name.equals_insensitive("free")) {
5482-
NumFrees += 1;
5483-
} else if (Name.equals_insensitive("__kmpc_masked")) {
5484-
NumMasked += 1;
5485-
} else if (Name.equals_insensitive("__kmpc_end_masked")) {
5486-
NumEndMasked += 1;
5487-
} else if (Name.equals_insensitive("llvm.log2.f64")) {
5488-
NumLog += 1;
5489-
} else if (Name.equals_insensitive("llvm.ceil.f64")) {
5490-
NumCeil += 1;
5491-
}
5475+
if (!isa<CallInst>(I))
5476+
continue;
5477+
CallInst *Call = dyn_cast<CallInst>(&I);
5478+
StringRef Name = Call->getCalledFunction()->getName();
5479+
if (Name.equals_insensitive("malloc")) {
5480+
NumMallocs += 1;
5481+
} else if (Name.equals_insensitive("free")) {
5482+
NumFrees += 1;
5483+
} else if (Name.equals_insensitive("__kmpc_masked")) {
5484+
NumMasked += 1;
5485+
} else if (Name.equals_insensitive("__kmpc_end_masked")) {
5486+
NumEndMasked += 1;
5487+
} else if (Name.equals_insensitive("llvm.log2.f64")) {
5488+
NumLog += 1;
5489+
} else if (Name.equals_insensitive("llvm.ceil.f64")) {
5490+
NumCeil += 1;
54925491
}
54935492
}
54945493
EXPECT_EQ(NumBodiesGenerated, 2U);

0 commit comments

Comments
 (0)