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 "llvm/ADT/SmallVector.h"
21#include <optional>
22
23namespace mlir {
24namespace acc {
25
26/// Get the data layout for an operation.
27///
28/// Attempts to get the data layout from the operation or its parent module.
29/// If `allowDefault` is true (default), a default data layout may be
30/// constructed when no explicit data layout spec is found.
31///
32/// \param op The operation to get the data layout for.
33/// \param allowDefault If true, allow returning a default data layout.
34/// \return The data layout if available, std::nullopt otherwise.
35std::optional<DataLayout> getDataLayout(Operation *op,
36 bool allowDefault = true);
37
38/// Build an `acc.compute_region` operation by cloning a source region.
39///
40/// Creates a new `acc.compute_region` with the given launch arguments and
41/// origin string, then clones the operations from `regionToClone` into its
42/// body. Launch operands should be `acc.par_width` results (`index`); the
43/// region entry block gets matching `index` block arguments first, then
44/// arguments for each `ins` operand. Multi-block regions are wrapped with
45/// `scf.execute_region`.
46///
47/// The `mapping` is used and updated during cloning, allowing callers to
48/// track value correspondences. Optional `output`, `kernelFuncName`,
49/// `kernelModuleName`, and `stream` arguments are forwarded to the op.
50///
51/// When `inputArgsToMap` is non-empty, it is used as the key set for the
52/// clone mapping (instead of `inputArgs`). Use this when cloning a region
53/// that references one set of values (e.g. the source function's args) while
54/// the op's operands are another set (e.g. the current block's args).
55/// `inputArgsToMap` must have the same size as `inputArgs` when provided.
56ComputeRegionOp buildComputeRegion(Location loc, ValueRange launchArgs,
57 ValueRange inputArgs, llvm::StringRef origin,
58 Region &regionToClone,
59 RewriterBase &rewriter, IRMapping &mapping,
60 ValueRange output = {},
61 FlatSymbolRefAttr kernelFuncName = {},
62 FlatSymbolRefAttr kernelModuleName = {},
63 Value stream = {},
64 ValueRange inputArgsToMap = {});
65
66/// Insert \p parDim into \p parDims while preserving dimension ordering. If the
67/// dimension is already present, this is a no-op.
68void insertParDim(llvm::SmallVector<GPUParallelDimAttr> &parDims,
69 GPUParallelDimAttr parDim);
70
71/// Remove \p parDim from \p parDims if present.
72void removeParDim(llvm::SmallVector<GPUParallelDimAttr> &parDims,
73 GPUParallelDimAttr parDim);
74
75/// Obtain the parallel dimensions carried by \p op, if any.
76GPUParallelDimsAttr getParDimsAttr(Operation *op);
77
78/// Return whether \p op carries parallel dimensions.
79bool hasParDimsAttr(Operation *op);
80
81/// Return whether \p op carries sequential parallel dimensions.
82bool hasSeqParDims(Operation *op);
83
84/// Set parallel dimensions on \p op.
85void setParDimsAttr(Operation *op, GPUParallelDimsAttr attr);
86
87/// Update parallel dimensions on \p op.
88void updateParDimsAttr(Operation *op, GPUParallelDimsAttr attr);
89
90/// Copy parallel dimensions from \p from to \p to.
91void copyParDimsAttr(Operation *from, Operation *to);
92
93} // namespace acc
94} // namespace mlir
95
96#endif // MLIR_DIALECT_OPENACC_OPENACCUTILSCG_H_
GPUParallelDimsAttr getParDimsAttr(Operation *op)
Obtain the parallel dimensions carried by op, if any.
std::optional< DataLayout > getDataLayout(Operation *op, bool allowDefault=true)
Get the data layout for an operation.
void insertParDim(llvm::SmallVector< GPUParallelDimAttr > &parDims, GPUParallelDimAttr parDim)
Insert parDim into parDims while preserving dimension ordering.
bool hasParDimsAttr(Operation *op)
Return whether op carries parallel dimensions.
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.
void updateParDimsAttr(Operation *op, GPUParallelDimsAttr attr)
Update parallel dimensions on op.
bool hasSeqParDims(Operation *op)
Return whether op carries sequential parallel dimensions.
void copyParDimsAttr(Operation *from, Operation *to)
Copy parallel dimensions from from to to.
void removeParDim(llvm::SmallVector< GPUParallelDimAttr > &parDims, GPUParallelDimAttr parDim)
Remove parDim from parDims if present.
void setParDimsAttr(Operation *op, GPUParallelDimsAttr attr)
Set parallel dimensions on op.
Include the generated interface declarations.