forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenMP-utils.cpp
47 lines (40 loc) · 1.81 KB
/
OpenMP-utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//===-- include/flang/Common/OpenMP-utils.cpp ------------------*- C++ -*-====//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "flang/Common/OpenMP-utils.h"
#include "mlir/IR/OpDefinition.h"
namespace Fortran::common::openmp {
mlir::Block *genEntryBlock(mlir::OpBuilder &builder, const EntryBlockArgs &args,
mlir::Region ®ion) {
assert(args.isValid() && "invalid args");
assert(region.empty() && "non-empty region");
llvm::SmallVector<mlir::Type> types;
llvm::SmallVector<mlir::Location> locs;
unsigned numVars = args.inReduction.vars.size() + args.map.vars.size() +
args.priv.vars.size() + args.reduction.vars.size() +
args.taskReduction.vars.size() + args.useDeviceAddr.vars.size() +
args.useDevicePtr.vars.size();
types.reserve(numVars);
locs.reserve(numVars);
auto extractTypeLoc = [&types, &locs](llvm::ArrayRef<mlir::Value> vals) {
llvm::transform(vals, std::back_inserter(types),
[](mlir::Value v) { return v.getType(); });
llvm::transform(vals, std::back_inserter(locs),
[](mlir::Value v) { return v.getLoc(); });
};
// Populate block arguments in clause name alphabetical order to match
// expected order by the BlockArgOpenMPOpInterface.
extractTypeLoc(args.inReduction.vars);
extractTypeLoc(args.map.vars);
extractTypeLoc(args.priv.vars);
extractTypeLoc(args.reduction.vars);
extractTypeLoc(args.taskReduction.vars);
extractTypeLoc(args.useDeviceAddr.vars);
extractTypeLoc(args.useDevicePtr.vars);
return builder.createBlock(®ion, {}, types, locs);
}
} // namespace Fortran::common::openmp