MLIR 23.0.0git
OpenACCUtilsCG.h
Go to the documentation of this file.
1//===- OpenACCUtilsCG.h - OpenACC Code Generation Utilities -----*- 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// This file defines utility functions for OpenACC code generation, including
10// data layout and type-related utilities.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_DIALECT_OPENACC_OPENACCUTILSCG_H_
15#define MLIR_DIALECT_OPENACC_OPENACCUTILSCG_H_
16
18#include "mlir/IR/IRMapping.h"
20#include <optional>
21
22namespace mlir {
23namespace acc {
24
25/// Get the data layout for an operation.
26///
27/// Attempts to get the data layout from the operation or its parent module.
28/// If `allowDefault` is true (default), a default data layout may be
29/// constructed when no explicit data layout spec is found.
30///
31/// \param op The operation to get the data layout for.
32/// \param allowDefault If true, allow returning a default data layout.
33/// \return The data layout if available, std::nullopt otherwise.
34std::optional<DataLayout> getDataLayout(Operation *op,
35 bool allowDefault = true);
36
37/// Build an `acc.compute_region` operation by cloning a source region.
38///
39/// Creates a new `acc.compute_region` with the given launch arguments and
40/// origin string, then clones the operations from `regionToClone` into its
41/// body. Launch operands should be `acc.par_width` results (`index`); the
42/// region entry block gets matching `index` block arguments first, then
43/// arguments for each `ins` operand. Multi-block regions are wrapped with
44/// `scf.execute_region`.
45///
46/// The `mapping` is used and updated during cloning, allowing callers to
47/// track value correspondences. Optional `output`, `kernelFuncName`,
48/// `kernelModuleName`, and `stream` arguments are forwarded to the op.
49///
50/// When `inputArgsToMap` is non-empty, it is used as the key set for the
51/// clone mapping (instead of `inputArgs`). Use this when cloning a region
52/// that references one set of values (e.g. the source function's args) while
53/// the op's operands are another set (e.g. the current block's args).
54/// `inputArgsToMap` must have the same size as `inputArgs` when provided.
55ComputeRegionOp buildComputeRegion(Location loc, ValueRange launchArgs,
56 ValueRange inputArgs, llvm::StringRef origin,
57 Region &regionToClone,
58 RewriterBase &rewriter, IRMapping &mapping,
59 ValueRange output = {},
60 FlatSymbolRefAttr kernelFuncName = {},
61 FlatSymbolRefAttr kernelModuleName = {},
62 Value stream = {},
63 ValueRange inputArgsToMap = {});
64
65} // namespace acc
66} // namespace mlir
67
68#endif // MLIR_DIALECT_OPENACC_OPENACCUTILSCG_H_
std::optional< DataLayout > getDataLayout(Operation *op, bool allowDefault=true)
Get the data layout for an operation.
ComputeRegionOp buildComputeRegion(Location loc, ValueRange launchArgs, ValueRange inputArgs, llvm::StringRef origin, Region &regionToClone, RewriterBase &rewriter, IRMapping &mapping, ValueRange output={}, FlatSymbolRefAttr kernelFuncName={}, FlatSymbolRefAttr kernelModuleName={}, Value stream={}, ValueRange inputArgsToMap={})
Build an acc.compute_region operation by cloning a source region.
Include the generated interface declarations.