Skip to content

Commit 244278c

Browse files
authored
[NFC][flang][OpenMP] Create FortranUtils lib and move creat eMapInfoOp to it (llvm#154483) (llvm#3762)
2 parents 2202f35 + 610ded4 commit 244278c

File tree

14 files changed

+243
-182
lines changed

14 files changed

+243
-182
lines changed

flang/include/flang/Support/OpenMP-utils.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,6 @@ struct EntryBlockArgs {
7878
mlir::Block *genEntryBlock(
7979
mlir::OpBuilder &builder, const EntryBlockArgs &args, mlir::Region &region);
8080

81-
mlir::omp::MapInfoOp createMapInfoOp(mlir::OpBuilder &builder,
82-
mlir::Location loc, mlir::Value baseAddr, mlir::Value varPtrPtr,
83-
llvm::StringRef name, llvm::ArrayRef<mlir::Value> bounds,
84-
llvm::ArrayRef<mlir::Value> members, mlir::ArrayAttr membersIndex,
85-
uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType,
86-
mlir::Type retTy, bool partialMap = false,
87-
mlir::FlatSymbolRefAttr mapperId = mlir::FlatSymbolRefAttr());
88-
89-
mlir::Value mapTemporaryValue(fir::FirOpBuilder &firOpBuilder,
90-
mlir::omp::TargetOp targetOp, mlir::Value val, llvm::StringRef name);
91-
92-
void cloneOrMapRegionOutsiders(
93-
fir::FirOpBuilder &firOpBuilder, mlir::omp::TargetOp targetOp);
94-
9581
// Returns true if the variable has a dynamic size and therefore requires
9682
// bounds operations to describe its extents.
9783
inline bool needsBoundsOps(mlir::Value var) {

flang/include/flang/Utils/OpenMP.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===-- include/flang/Utils/OpenMP.h ----------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef FORTRAN_UTILS_OPENMP_H_
10+
#define FORTRAN_UTILS_OPENMP_H_
11+
12+
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
13+
14+
namespace fir {
15+
class FirOpBuilder;
16+
} // namespace fir
17+
18+
namespace Fortran::utils::openmp {
19+
// TODO We can probably move the stuff inside `Support/OpenMP-utils.h/.cpp` here
20+
// as well.
21+
22+
/// Create an `omp.map.info` op. Parameters other than the ones documented below
23+
/// correspond to operation arguments in the OpenMPOps.td file, see op docs for
24+
/// more details.
25+
///
26+
/// \param [in] builder - MLIR operation builder.
27+
/// \param [in] loc - Source location of the created op.
28+
mlir::omp::MapInfoOp createMapInfoOp(mlir::OpBuilder &builder,
29+
mlir::Location loc, mlir::Value baseAddr, mlir::Value varPtrPtr,
30+
llvm::StringRef name, llvm::ArrayRef<mlir::Value> bounds,
31+
llvm::ArrayRef<mlir::Value> members, mlir::ArrayAttr membersIndex,
32+
uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType,
33+
mlir::Type retTy, bool partialMap = false,
34+
mlir::FlatSymbolRefAttr mapperId = mlir::FlatSymbolRefAttr());
35+
36+
mlir::Value mapTemporaryValue(fir::FirOpBuilder &firOpBuilder,
37+
mlir::omp::TargetOp targetOp, mlir::Value val, llvm::StringRef name);
38+
39+
void cloneOrMapRegionOutsiders(
40+
fir::FirOpBuilder &firOpBuilder, mlir::omp::TargetOp targetOp);
41+
} // namespace Fortran::utils::openmp
42+
43+
#endif // FORTRAN_UTILS_OPENMP_H_

flang/lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ add_subdirectory(Semantics)
66
add_subdirectory(Support)
77
add_subdirectory(Frontend)
88
add_subdirectory(FrontendTool)
9+
add_subdirectory(Utils)
910

1011
add_subdirectory(Optimizer)
1112

flang/lib/Lower/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ add_flang_library(FortranLower
6060
FortranParser
6161
FortranEvaluate
6262
FortranSemantics
63+
FortranUtils
6364

6465
LINK_COMPONENTS
6566
Support

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "flang/Lower/Support/ReductionProcessor.h"
2020
#include "flang/Parser/tools.h"
2121
#include "flang/Semantics/tools.h"
22-
#include "flang/Support/OpenMP-utils.h"
22+
#include "flang/Utils/OpenMP.h"
2323
#include "llvm/Frontend/OpenMP/OMP.h.inc"
2424
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
2525

@@ -1248,7 +1248,7 @@ void ClauseProcessor::processMapObjects(
12481248
auto location = mlir::NameLoc::get(
12491249
mlir::StringAttr::get(firOpBuilder.getContext(), asFortran.str()),
12501250
baseOp.getLoc());
1251-
mlir::omp::MapInfoOp mapOp = Fortran::common::openmp::createMapInfoOp(
1251+
mlir::omp::MapInfoOp mapOp = utils::openmp::createMapInfoOp(
12521252
firOpBuilder, location, baseOp,
12531253
/*varPtrPtr=*/mlir::Value{}, asFortran.str(), bounds,
12541254
/*members=*/{}, /*membersIndex=*/mlir::ArrayAttr{},

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
#include "ClauseProcessor.h"
1717
#include "DataSharingProcessor.h"
1818
#include "Decomposer.h"
19-
#include "flang/Lower/OpenMP/Utils.h"
2019
#include "flang/Common/idioms.h"
2120
#include "flang/Lower/Bridge.h"
2221
#include "flang/Lower/ConvertExpr.h"
2322
#include "flang/Lower/ConvertVariable.h"
2423
#include "flang/Lower/DirectivesCommon.h"
2524
#include "flang/Lower/OpenMP/Clauses.h"
25+
#include "flang/Lower/OpenMP/Utils.h"
2626
#include "flang/Lower/StatementContext.h"
2727
#include "flang/Lower/SymbolMap.h"
2828
#include "flang/Optimizer/Builder/BoxValue.h"
@@ -38,6 +38,7 @@
3838
#include "flang/Semantics/tools.h"
3939
#include "flang/Support/Flags.h"
4040
#include "flang/Support/OpenMP-utils.h"
41+
#include "flang/Utils/OpenMP.h"
4142
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
4243
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
4344
#include "mlir/Support/StateStack.h"
@@ -47,6 +48,7 @@
4748

4849
using namespace Fortran::lower::omp;
4950
using namespace Fortran::common::openmp;
51+
using namespace Fortran::utils::openmp;
5052

5153
//===----------------------------------------------------------------------===//
5254
// Code generation helper functions
@@ -1432,7 +1434,7 @@ static void genBodyOfTargetOp(
14321434
// If so, then either clone them as well if they are MemoryEffectFree, or else
14331435
// copy them to a new temporary and add them to the map and block_argument
14341436
// lists and replace their uses with the new temporary.
1435-
Fortran::common::openmp::cloneOrMapRegionOutsiders(firOpBuilder, targetOp);
1437+
cloneOrMapRegionOutsiders(firOpBuilder, targetOp);
14361438

14371439
// Insert dummy instruction to remember the insertion position. The
14381440
// marker will be deleted since there are not uses.

flang/lib/Lower/OpenMP/Utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <flang/Parser/parse-tree.h>
2929
#include <flang/Parser/tools.h>
3030
#include <flang/Semantics/tools.h>
31-
#include <flang/Support/OpenMP-utils.h>
31+
#include <flang/Utils/OpenMP.h>
3232
#include <llvm/Support/CommandLine.h>
3333
#include <mlir/Analysis/TopologicalSortUtils.h>
3434
#include <mlir/Dialect/Arith/IR/Arith.h>
@@ -405,7 +405,7 @@ mlir::Value createParentSymAndGenIntermediateMaps(
405405

406406
// Create a map for the intermediate member and insert it and it's
407407
// indices into the parentMemberIndices list to track it.
408-
mlir::omp::MapInfoOp mapOp = Fortran::common::openmp::createMapInfoOp(
408+
mlir::omp::MapInfoOp mapOp = utils::openmp::createMapInfoOp(
409409
firOpBuilder, clauseLocation, curValue,
410410
/*varPtrPtr=*/mlir::Value{}, asFortran,
411411
/*bounds=*/interimBounds,
@@ -564,7 +564,7 @@ void insertChildMapInfoIntoParent(
564564
converter.getCurrentLocation(), asFortran, bounds,
565565
treatIndexAsSection);
566566

567-
mlir::omp::MapInfoOp mapOp = Fortran::common::openmp::createMapInfoOp(
567+
mlir::omp::MapInfoOp mapOp = utils::openmp::createMapInfoOp(
568568
firOpBuilder, info.rawInput.getLoc(), info.rawInput,
569569
/*varPtrPtr=*/mlir::Value(), asFortran.str(), bounds, members,
570570
firOpBuilder.create2DI64ArrayAttr(

flang/lib/Optimizer/OpenMP/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ add_flang_library(FlangOpenMPTransforms
2727
FIRSupport
2828
FortranSupport
2929
HLFIRDialect
30+
FortranUtils
3031

3132
MLIR_DEPS
3233
${dialect_libs}

flang/lib/Optimizer/OpenMP/DoConcurrentConversion.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "flang/Optimizer/OpenMP/Passes.h"
1919
#include "flang/Optimizer/OpenMP/Utils.h"
2020
#include "flang/Support/OpenMP-utils.h"
21+
#include "flang/Utils/OpenMP.h"
2122
#include "mlir/Analysis/SliceAnalysis.h"
2223
#include "mlir/Dialect/Func/IR/FuncOps.h"
2324
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
@@ -631,7 +632,7 @@ class DoConcurrentConversion
631632
llvm::SmallVector<mlir::Value> boundsOps;
632633
genBoundsOps(builder, liveIn, rawAddr, boundsOps);
633634

634-
return Fortran::common::openmp::createMapInfoOp(
635+
return Fortran::utils::openmp::createMapInfoOp(
635636
builder, liveIn.getLoc(), rawAddr,
636637
/*varPtrPtr=*/{}, name.str(), boundsOps,
637638
/*members=*/{},
@@ -720,7 +721,7 @@ class DoConcurrentConversion
720721
// MemoryEffectFree, or else copy them to a new temporary and add them to
721722
// the map and block_argument lists and replace their uses with the new
722723
// temporary.
723-
Fortran::common::openmp::cloneOrMapRegionOutsiders(builder, targetOp);
724+
Fortran::utils::openmp::cloneOrMapRegionOutsiders(builder, targetOp);
724725
rewriter.setInsertionPoint(
725726
rewriter.create<mlir::omp::TerminatorOp>(targetOp.getLoc()));
726727

@@ -753,11 +754,11 @@ class DoConcurrentConversion
753754
llvm::zip_equal(targetShapeCreationInfo.startIndices,
754755
targetShapeCreationInfo.extents)) {
755756
shapeShiftOperands.push_back(
756-
Fortran::common::openmp::mapTemporaryValue(
757+
Fortran::utils::openmp::mapTemporaryValue(
757758
builder, targetOp, startIndex,
758759
liveInName + ".start_idx.dim" + std::to_string(shapeIdx)));
759760
shapeShiftOperands.push_back(
760-
Fortran::common::openmp::mapTemporaryValue(
761+
Fortran::utils::openmp::mapTemporaryValue(
761762
builder, targetOp, extent,
762763
liveInName + ".extent.dim" + std::to_string(shapeIdx)));
763764
++shapeIdx;
@@ -772,7 +773,7 @@ class DoConcurrentConversion
772773
llvm::SmallVector<mlir::Value> shapeOperands;
773774
size_t shapeIdx = 0;
774775
for (auto extent : targetShapeCreationInfo.extents) {
775-
shapeOperands.push_back(Fortran::common::openmp::mapTemporaryValue(
776+
shapeOperands.push_back(Fortran::utils::openmp::mapTemporaryValue(
776777
builder, targetOp, extent,
777778
liveInName + ".extent.dim" + std::to_string(shapeIdx)));
778779
++shapeIdx;

flang/lib/Optimizer/OpenMP/MapsForPrivatizedSymbols.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class MapsForPrivatizedSymbolsPass
5555
: public flangomp::impl::MapsForPrivatizedSymbolsPassBase<
5656
MapsForPrivatizedSymbolsPass> {
5757

58+
// TODO Use `createMapInfoOp` from `flang/Utils/OpenMP.h`.
5859
omp::MapInfoOp createMapInfo(Location loc, Value var,
5960
fir::FirOpBuilder &builder) {
6061
// Check if a value of type `type` can be passed to the kernel by value.

0 commit comments

Comments
 (0)