Skip to content

Commit f9a4057

Browse files
committed
Add FortranUtils libarary.
1 parent 04ef4d6 commit f9a4057

File tree

11 files changed

+109
-61
lines changed

11 files changed

+109
-61
lines changed

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "flang/Semantics/symbol.h"
1313

14-
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
1514
#include "mlir/IR/Builders.h"
1615
#include "mlir/IR/Value.h"
1716

@@ -73,20 +72,6 @@ struct EntryBlockArgs {
7372
/// \param [in] region - Empty region in which to create the entry block.
7473
mlir::Block *genEntryBlock(
7574
mlir::OpBuilder &builder, const EntryBlockArgs &args, mlir::Region &region);
76-
77-
/// Create an `omp.map.info` op. Parameters other than the ones documented below
78-
/// correspond to operation arguments in the OpenMPOps.td file, see op docs for
79-
/// more details.
80-
///
81-
/// \param [in] builder - MLIR operation builder.
82-
/// \param [in] loc - Source location of the created op.
83-
mlir::omp::MapInfoOp createMapInfoOp(mlir::OpBuilder &builder,
84-
mlir::Location loc, mlir::Value baseAddr, mlir::Value varPtrPtr,
85-
llvm::StringRef name, llvm::ArrayRef<mlir::Value> bounds,
86-
llvm::ArrayRef<mlir::Value> members, mlir::ArrayAttr membersIndex,
87-
uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType,
88-
mlir::Type retTy, bool partialMap = false,
89-
mlir::FlatSymbolRefAttr mapperId = mlir::FlatSymbolRefAttr());
9075
} // namespace Fortran::common::openmp
9176

9277
#endif // FORTRAN_SUPPORT_OPENMP_UTILS_H_

flang/include/flang/Utils/OpenMP.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 Fortran::utils::openmp {
15+
// TODO We can probably move the stuff inside `Support/OpenMP-utils.h/.cpp` here
16+
// as well.
17+
18+
/// Create an `omp.map.info` op. Parameters other than the ones documented below
19+
/// correspond to operation arguments in the OpenMPOps.td file, see op docs for
20+
/// more details.
21+
///
22+
/// \param [in] builder - MLIR operation builder.
23+
/// \param [in] loc - Source location of the created op.
24+
mlir::omp::MapInfoOp createMapInfoOp(mlir::OpBuilder &builder,
25+
mlir::Location loc, mlir::Value baseAddr, mlir::Value varPtrPtr,
26+
llvm::StringRef name, llvm::ArrayRef<mlir::Value> bounds,
27+
llvm::ArrayRef<mlir::Value> members, mlir::ArrayAttr membersIndex,
28+
uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType,
29+
mlir::Type retTy, bool partialMap = false,
30+
mlir::FlatSymbolRefAttr mapperId = mlir::FlatSymbolRefAttr());
31+
} // namespace Fortran::utils::openmp
32+
33+
#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

@@ -1282,7 +1282,7 @@ void ClauseProcessor::processMapObjects(
12821282
auto location = mlir::NameLoc::get(
12831283
mlir::StringAttr::get(firOpBuilder.getContext(), asFortran.str()),
12841284
baseOp.getLoc());
1285-
mlir::omp::MapInfoOp mapOp = common::openmp::createMapInfoOp(
1285+
mlir::omp::MapInfoOp mapOp = utils::openmp::createMapInfoOp(
12861286
firOpBuilder, location, baseOp,
12871287
/*varPtrPtr=*/mlir::Value{}, asFortran.str(), bounds,
12881288
/*members=*/{}, /*membersIndex=*/mlir::ArrayAttr{},

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

flang/lib/Lower/OpenMP/Utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <flang/Parser/parse-tree.h>
2525
#include <flang/Parser/tools.h>
2626
#include <flang/Semantics/tools.h>
27-
#include <flang/Support/OpenMP-utils.h>
27+
#include <flang/Utils/OpenMP.h>
2828
#include <llvm/Support/CommandLine.h>
2929

3030
#include <iterator>
@@ -372,7 +372,7 @@ mlir::Value createParentSymAndGenIntermediateMaps(
372372

373373
// Create a map for the intermediate member and insert it and it's
374374
// indices into the parentMemberIndices list to track it.
375-
mlir::omp::MapInfoOp mapOp = common::openmp::createMapInfoOp(
375+
mlir::omp::MapInfoOp mapOp = utils::openmp::createMapInfoOp(
376376
firOpBuilder, clauseLocation, curValue,
377377
/*varPtrPtr=*/mlir::Value{}, asFortran,
378378
/*bounds=*/interimBounds,
@@ -532,7 +532,7 @@ void insertChildMapInfoIntoParent(
532532
converter.getCurrentLocation(), asFortran, bounds,
533533
treatIndexAsSection);
534534

535-
mlir::omp::MapInfoOp mapOp = common::openmp::createMapInfoOp(
535+
mlir::omp::MapInfoOp mapOp = utils::openmp::createMapInfoOp(
536536
firOpBuilder, info.rawInput.getLoc(), info.rawInput,
537537
/*varPtrPtr=*/mlir::Value(), asFortran.str(), bounds, members,
538538
firOpBuilder.create2DI64ArrayAttr(

flang/lib/Support/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,10 @@ add_flang_library(FortranSupport
5454
Version.cpp
5555
${version_inc}
5656

57-
DEPENDS
58-
FIRDialect
59-
60-
LINK_LIBS
61-
FIRDialect
62-
6357
LINK_COMPONENTS
6458
Support
6559

6660
MLIR_LIBS
6761
MLIRIR
6862
MLIRSupport
69-
MLIROpenMPDialect
7063
)

flang/lib/Support/OpenMP-utils.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "flang/Support/OpenMP-utils.h"
10-
#include "flang/Optimizer/Dialect/FIROps.h"
11-
#include "flang/Optimizer/Dialect/FIRType.h"
1210

13-
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
1411
#include "mlir/IR/OpDefinition.h"
1512

1613
namespace Fortran::common::openmp {
@@ -50,35 +47,4 @@ mlir::Block *genEntryBlock(mlir::OpBuilder &builder, const EntryBlockArgs &args,
5047

5148
return builder.createBlock(&region, {}, types, locs);
5249
}
53-
54-
mlir::omp::MapInfoOp createMapInfoOp(mlir::OpBuilder &builder,
55-
mlir::Location loc, mlir::Value baseAddr, mlir::Value varPtrPtr,
56-
llvm::StringRef name, llvm::ArrayRef<mlir::Value> bounds,
57-
llvm::ArrayRef<mlir::Value> members, mlir::ArrayAttr membersIndex,
58-
uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType,
59-
mlir::Type retTy, bool partialMap, mlir::FlatSymbolRefAttr mapperId) {
60-
61-
if (auto boxTy = llvm::dyn_cast<fir::BaseBoxType>(baseAddr.getType())) {
62-
baseAddr = fir::BoxAddrOp::create(builder, loc, baseAddr);
63-
retTy = baseAddr.getType();
64-
}
65-
66-
mlir::TypeAttr varType = mlir::TypeAttr::get(
67-
llvm::cast<mlir::omp::PointerLikeType>(retTy).getElementType());
68-
69-
// For types with unknown extents such as <2x?xi32> we discard the incomplete
70-
// type info and only retain the base type. The correct dimensions are later
71-
// recovered through the bounds info.
72-
if (auto seqType = llvm::dyn_cast<fir::SequenceType>(varType.getValue()))
73-
if (seqType.hasDynamicExtents())
74-
varType = mlir::TypeAttr::get(seqType.getEleTy());
75-
76-
mlir::omp::MapInfoOp op =
77-
mlir::omp::MapInfoOp::create(builder, loc, retTy, baseAddr, varType,
78-
builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
79-
builder.getAttr<mlir::omp::VariableCaptureKindAttr>(mapCaptureType),
80-
varPtrPtr, members, membersIndex, bounds, mapperId,
81-
builder.getStringAttr(name), builder.getBoolAttr(partialMap));
82-
return op;
83-
}
8450
} // namespace Fortran::common::openmp

flang/lib/Utils/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#===-- lib/Utils/CMakeLists.txt --------------------------------------------===#
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+
add_flang_library(FortranUtils
10+
OpenMP.cpp
11+
12+
DEPENDS
13+
FIRDialect
14+
15+
LINK_LIBS
16+
FIRDialect
17+
18+
MLIR_LIBS
19+
MLIROpenMPDialect
20+
)

0 commit comments

Comments
 (0)