Skip to content

Commit df65bd5

Browse files
committed
clang format
1 parent 5b30d3d commit df65bd5

File tree

4 files changed

+67
-67
lines changed

4 files changed

+67
-67
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,14 +2670,15 @@ genTeamsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
26702670
queue, item, clauseOps);
26712671
}
26722672

2673-
static mlir::omp::WorkdistributeOp
2674-
genWorkdistributeOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
2675-
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
2676-
mlir::Location loc, const ConstructQueue &queue,
2677-
ConstructQueue::const_iterator item) {
2673+
static mlir::omp::WorkdistributeOp genWorkdistributeOp(
2674+
lower::AbstractConverter &converter, lower::SymMap &symTable,
2675+
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
2676+
mlir::Location loc, const ConstructQueue &queue,
2677+
ConstructQueue::const_iterator item) {
26782678
return genOpWithBody<mlir::omp::WorkdistributeOp>(
2679-
OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval,
2680-
llvm::omp::Directive::OMPD_workdistribute), queue, item);
2679+
OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval,
2680+
llvm::omp::Directive::OMPD_workdistribute),
2681+
queue, item);
26812682
}
26822683

26832684
//===----------------------------------------------------------------------===//
@@ -3946,7 +3947,8 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
39463947
llvm::omp::getOpenMPDirectiveName(dir, version) + ")");
39473948
}
39483949
case llvm::omp::Directive::OMPD_workdistribute:
3949-
newOp = genWorkdistributeOp(converter, symTable, semaCtx, eval, loc, queue, item);
3950+
newOp = genWorkdistributeOp(converter, symTable, semaCtx, eval, loc, queue,
3951+
item);
39503952
break;
39513953
case llvm::omp::Directive::OMPD_workshare:
39523954
newOp = genWorkshareOp(converter, symTable, stmtCtx, semaCtx, eval, loc,

flang/lib/Optimizer/OpenMP/LowerWorkdistribute.cpp

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
#include "flang/Optimizer/Dialect/FIRDialect.h"
1515
#include "flang/Optimizer/Dialect/FIROps.h"
1616
#include "flang/Optimizer/Dialect/FIRType.h"
17-
#include "flang/Optimizer/Transforms/Passes.h"
1817
#include "flang/Optimizer/HLFIR/Passes.h"
1918
#include "flang/Optimizer/OpenMP/Utils.h"
19+
#include "flang/Optimizer/Transforms/Passes.h"
2020
#include "mlir/Analysis/SliceAnalysis.h"
2121
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
2222
#include "mlir/IR/Builders.h"
2323
#include "mlir/IR/Value.h"
2424
#include "mlir/Transforms/DialectConversion.h"
2525
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
26+
#include "mlir/Transforms/RegionUtils.h"
2627
#include <mlir/Dialect/Arith/IR/Arith.h>
2728
#include <mlir/Dialect/LLVMIR/LLVMTypes.h>
2829
#include <mlir/Dialect/Utils/IndexingUtils.h>
@@ -33,7 +34,6 @@
3334
#include <mlir/IR/PatternMatch.h>
3435
#include <mlir/Interfaces/SideEffectInterfaces.h>
3536
#include <mlir/Support/LLVM.h>
36-
#include "mlir/Transforms/RegionUtils.h"
3737
#include <optional>
3838
#include <variant>
3939

@@ -66,30 +66,30 @@ static T getPerfectlyNested(Operation *op) {
6666
/// This is the single source of truth about whether we should parallelize an
6767
/// operation nested in an omp.workdistribute region.
6868
static bool shouldParallelize(Operation *op) {
69-
// Currently we cannot parallelize operations with results that have uses
70-
if (llvm::any_of(op->getResults(),
71-
[](OpResult v) -> bool { return !v.use_empty(); }))
69+
// Currently we cannot parallelize operations with results that have uses
70+
if (llvm::any_of(op->getResults(),
71+
[](OpResult v) -> bool { return !v.use_empty(); }))
72+
return false;
73+
// We will parallelize unordered loops - these come from array syntax
74+
if (auto loop = dyn_cast<fir::DoLoopOp>(op)) {
75+
auto unordered = loop.getUnordered();
76+
if (!unordered)
7277
return false;
73-
// We will parallelize unordered loops - these come from array syntax
74-
if (auto loop = dyn_cast<fir::DoLoopOp>(op)) {
75-
auto unordered = loop.getUnordered();
76-
if (!unordered)
77-
return false;
78-
return *unordered;
79-
}
80-
if (auto callOp = dyn_cast<fir::CallOp>(op)) {
81-
auto callee = callOp.getCallee();
82-
if (!callee)
83-
return false;
84-
auto *func = op->getParentOfType<ModuleOp>().lookupSymbol(*callee);
85-
// TODO need to insert a check here whether it is a call we can actually
86-
// parallelize currently
87-
if (func->getAttr(fir::FIROpsDialect::getFirRuntimeAttrName()))
88-
return true;
78+
return *unordered;
79+
}
80+
if (auto callOp = dyn_cast<fir::CallOp>(op)) {
81+
auto callee = callOp.getCallee();
82+
if (!callee)
8983
return false;
90-
}
91-
// We cannot parallise anything else
84+
auto *func = op->getParentOfType<ModuleOp>().lookupSymbol(*callee);
85+
// TODO need to insert a check here whether it is a call we can actually
86+
// parallelize currently
87+
if (func->getAttr(fir::FIROpsDialect::getFirRuntimeAttrName()))
88+
return true;
9289
return false;
90+
}
91+
// We cannot parallise anything else
92+
return false;
9393
}
9494

9595
/// If B() and D() are parallelizable,
@@ -120,12 +120,10 @@ static bool shouldParallelize(Operation *op) {
120120
/// }
121121
/// E()
122122

123-
struct FissionWorkdistribute
124-
: public OpRewritePattern<omp::WorkdistributeOp> {
123+
struct FissionWorkdistribute : public OpRewritePattern<omp::WorkdistributeOp> {
125124
using OpRewritePattern::OpRewritePattern;
126-
LogicalResult
127-
matchAndRewrite(omp::WorkdistributeOp workdistribute,
128-
PatternRewriter &rewriter) const override {
125+
LogicalResult matchAndRewrite(omp::WorkdistributeOp workdistribute,
126+
PatternRewriter &rewriter) const override {
129127
auto loc = workdistribute->getLoc();
130128
auto teams = dyn_cast<omp::TeamsOp>(workdistribute->getParentOp());
131129
if (!teams) {
@@ -185,7 +183,7 @@ struct FissionWorkdistribute
185183
auto newWorkdistribute = rewriter.create<omp::WorkdistributeOp>(loc);
186184
rewriter.create<omp::TerminatorOp>(loc);
187185
rewriter.createBlock(&newWorkdistribute.getRegion(),
188-
newWorkdistribute.getRegion().begin(), {}, {});
186+
newWorkdistribute.getRegion().begin(), {}, {});
189187
auto *cloned = rewriter.clone(*parallelize);
190188
rewriter.replaceOp(parallelize, cloned);
191189
rewriter.create<omp::TerminatorOp>(loc);
@@ -197,8 +195,7 @@ struct FissionWorkdistribute
197195
};
198196

199197
static void
200-
genLoopNestClauseOps(mlir::Location loc,
201-
mlir::PatternRewriter &rewriter,
198+
genLoopNestClauseOps(mlir::Location loc, mlir::PatternRewriter &rewriter,
202199
fir::DoLoopOp loop,
203200
mlir::omp::LoopNestOperands &loopNestClauseOps) {
204201
assert(loopNestClauseOps.loopLowerBounds.empty() &&
@@ -209,10 +206,8 @@ genLoopNestClauseOps(mlir::Location loc,
209206
loopNestClauseOps.loopInclusive = rewriter.getUnitAttr();
210207
}
211208

212-
static void
213-
genWsLoopOp(mlir::PatternRewriter &rewriter,
214-
fir::DoLoopOp doLoop,
215-
const mlir::omp::LoopNestOperands &clauseOps) {
209+
static void genWsLoopOp(mlir::PatternRewriter &rewriter, fir::DoLoopOp doLoop,
210+
const mlir::omp::LoopNestOperands &clauseOps) {
216211

217212
auto wsloopOp = rewriter.create<mlir::omp::WsloopOp>(doLoop.getLoc());
218213
rewriter.createBlock(&wsloopOp.getRegion());
@@ -236,7 +231,7 @@ genWsLoopOp(mlir::PatternRewriter &rewriter,
236231
return;
237232
}
238233

239-
/// If fir.do_loop id present inside teams workdistribute
234+
/// If fir.do_loop is present inside teams workdistribute
240235
///
241236
/// omp.teams {
242237
/// omp.workdistribute {
@@ -246,7 +241,7 @@ genWsLoopOp(mlir::PatternRewriter &rewriter,
246241
/// }
247242
/// }
248243
///
249-
/// Then, its lowered to
244+
/// Then, its lowered to
250245
///
251246
/// omp.teams {
252247
/// omp.workdistribute {
@@ -277,7 +272,8 @@ struct TeamsWorkdistributeLowering : public OpRewritePattern<omp::TeamsOp> {
277272

278273
auto parallelOp = rewriter.create<mlir::omp::ParallelOp>(teamsLoc);
279274
rewriter.createBlock(&parallelOp.getRegion());
280-
rewriter.setInsertionPoint(rewriter.create<mlir::omp::TerminatorOp>(doLoop.getLoc()));
275+
rewriter.setInsertionPoint(
276+
rewriter.create<mlir::omp::TerminatorOp>(doLoop.getLoc()));
281277

282278
mlir::omp::LoopNestOperands loopNestClauseOps;
283279
genLoopNestClauseOps(doLoop.getLoc(), rewriter, doLoop,
@@ -292,7 +288,6 @@ struct TeamsWorkdistributeLowering : public OpRewritePattern<omp::TeamsOp> {
292288
}
293289
};
294290

295-
296291
/// If A() and B () are present inside teams workdistribute
297292
///
298293
/// omp.teams {
@@ -311,17 +306,17 @@ struct TeamsWorkdistributeLowering : public OpRewritePattern<omp::TeamsOp> {
311306
struct TeamsWorkdistributeToSingle : public OpRewritePattern<omp::TeamsOp> {
312307
using OpRewritePattern::OpRewritePattern;
313308
LogicalResult matchAndRewrite(omp::TeamsOp teamsOp,
314-
PatternRewriter &rewriter) const override {
315-
auto workdistributeOp = getPerfectlyNested<omp::WorkdistributeOp>(teamsOp);
316-
if (!workdistributeOp) {
317-
LLVM_DEBUG(llvm::dbgs() << DEBUG_TYPE << " No workdistribute nested\n");
318-
return failure();
319-
}
320-
Block *workdistributeBlock = &workdistributeOp.getRegion().front();
321-
rewriter.eraseOp(workdistributeBlock->getTerminator());
322-
rewriter.inlineBlockBefore(workdistributeBlock, teamsOp);
323-
rewriter.eraseOp(teamsOp);
324-
return success();
309+
PatternRewriter &rewriter) const override {
310+
auto workdistributeOp = getPerfectlyNested<omp::WorkdistributeOp>(teamsOp);
311+
if (!workdistributeOp) {
312+
LLVM_DEBUG(llvm::dbgs() << DEBUG_TYPE << " No workdistribute nested\n");
313+
return failure();
314+
}
315+
Block *workdistributeBlock = &workdistributeOp.getRegion().front();
316+
rewriter.eraseOp(workdistributeBlock->getTerminator());
317+
rewriter.inlineBlockBefore(workdistributeBlock, teamsOp);
318+
rewriter.eraseOp(teamsOp);
319+
return success();
325320
}
326321
};
327322

@@ -332,26 +327,27 @@ class LowerWorkdistributePass
332327
MLIRContext &context = getContext();
333328
GreedyRewriteConfig config;
334329
// prevent the pattern driver form merging blocks
335-
config.setRegionSimplificationLevel(
336-
GreedySimplifyRegionLevel::Disabled);
337-
330+
config.setRegionSimplificationLevel(GreedySimplifyRegionLevel::Disabled);
331+
338332
Operation *op = getOperation();
339333
{
340334
RewritePatternSet patterns(&context);
341-
patterns.insert<FissionWorkdistribute, TeamsWorkdistributeLowering>(&context);
335+
patterns.insert<FissionWorkdistribute, TeamsWorkdistributeLowering>(
336+
&context);
342337
if (failed(applyPatternsGreedily(op, std::move(patterns), config))) {
343338
emitError(op->getLoc(), DEBUG_TYPE " pass failed\n");
344339
signalPassFailure();
345340
}
346341
}
347342
{
348343
RewritePatternSet patterns(&context);
349-
patterns.insert<TeamsWorkdistributeLowering, TeamsWorkdistributeToSingle>(&context);
344+
patterns.insert<TeamsWorkdistributeLowering, TeamsWorkdistributeToSingle>(
345+
&context);
350346
if (failed(applyPatternsGreedily(op, std::move(patterns), config))) {
351347
emitError(op->getLoc(), DEBUG_TYPE " pass failed\n");
352348
signalPassFailure();
353349
}
354350
}
355351
}
356352
};
357-
}
353+
} // namespace

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,12 +1344,14 @@ TYPE_PARSER(
13441344
"SINGLE" >> pure(llvm::omp::Directive::OMPD_single),
13451345
"TARGET DATA" >> pure(llvm::omp::Directive::OMPD_target_data),
13461346
"TARGET PARALLEL" >> pure(llvm::omp::Directive::OMPD_target_parallel),
1347-
"TARGET TEAMS WORKDISTRIBUTE" >> pure(llvm::omp::Directive::OMPD_target_teams_workdistribute),
1347+
"TARGET TEAMS WORKDISTRIBUTE" >>
1348+
pure(llvm::omp::Directive::OMPD_target_teams_workdistribute),
13481349
"TARGET TEAMS" >> pure(llvm::omp::Directive::OMPD_target_teams),
13491350
"TARGET" >> pure(llvm::omp::Directive::OMPD_target),
13501351
"TASK"_id >> pure(llvm::omp::Directive::OMPD_task),
13511352
"TASKGROUP" >> pure(llvm::omp::Directive::OMPD_taskgroup),
1352-
"TEAMS WORKDISTRIBUTE" >> pure(llvm::omp::Directive::OMPD_teams_workdistribute),
1353+
"TEAMS WORKDISTRIBUTE" >>
1354+
pure(llvm::omp::Directive::OMPD_teams_workdistribute),
13531355
"TEAMS" >> pure(llvm::omp::Directive::OMPD_teams),
13541356
"WORKSHARE" >> pure(llvm::omp::Directive::OMPD_workshare),
13551357
"WORKDISTRIBUTE" >> pure(llvm::omp::Directive::OMPD_workdistribute))))

flang/test/Transforms/OpenMP/lower-workdistribute-doloop.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ func.func @x(%lb : index, %ub : index, %step : index, %b : i1, %addr : !fir.ref<
2525
omp.terminator
2626
}
2727
return
28-
}
28+
}

0 commit comments

Comments
 (0)