1 | //===-- lib/Support/OpenMP-utils.cpp ----------------------------*- 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 | #include "flang/Support/OpenMP-utils.h" |
10 | |
11 | #include "mlir/IR/OpDefinition.h" |
12 | |
13 | namespace Fortran::common::openmp { |
14 | mlir::Block *genEntryBlock(mlir::OpBuilder &builder, const EntryBlockArgs &args, |
15 | mlir::Region ®ion) { |
16 | assert(args.isValid() && "invalid args" ); |
17 | assert(region.empty() && "non-empty region" ); |
18 | |
19 | llvm::SmallVector<mlir::Type> types; |
20 | llvm::SmallVector<mlir::Location> locs; |
21 | unsigned numVars = args.hasDeviceAddr.vars.size() + args.hostEvalVars.size() + |
22 | args.inReduction.vars.size() + args.map.vars.size() + |
23 | args.priv.vars.size() + args.reduction.vars.size() + |
24 | args.taskReduction.vars.size() + args.useDeviceAddr.vars.size() + |
25 | args.useDevicePtr.vars.size(); |
26 | types.reserve(numVars); |
27 | locs.reserve(numVars); |
28 | |
29 | auto = [&types, &locs](llvm::ArrayRef<mlir::Value> vals) { |
30 | llvm::transform(vals, std::back_inserter(types), |
31 | [](mlir::Value v) { return v.getType(); }); |
32 | llvm::transform(vals, std::back_inserter(locs), |
33 | [](mlir::Value v) { return v.getLoc(); }); |
34 | }; |
35 | |
36 | // Populate block arguments in clause name alphabetical order to match |
37 | // expected order by the BlockArgOpenMPOpInterface. |
38 | extractTypeLoc(args.hasDeviceAddr.vars); |
39 | extractTypeLoc(args.hostEvalVars); |
40 | extractTypeLoc(args.inReduction.vars); |
41 | extractTypeLoc(args.map.vars); |
42 | extractTypeLoc(args.priv.vars); |
43 | extractTypeLoc(args.reduction.vars); |
44 | extractTypeLoc(args.taskReduction.vars); |
45 | extractTypeLoc(args.useDeviceAddr.vars); |
46 | extractTypeLoc(args.useDevicePtr.vars); |
47 | |
48 | return builder.createBlock(®ion, {}, types, locs); |
49 | } |
50 | } // namespace Fortran::common::openmp |
51 | |