MLIR 23.0.0git
OpenACCUtilsLoop.h
Go to the documentation of this file.
1//===- OpenACCUtilsLoop.h - OpenACC Loop 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// Utilities for converting OpenACC loop operations.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_OPENACC_OPENACCUTILSLOOP_H_
14#define MLIR_DIALECT_OPENACC_OPENACCUTILSLOOP_H_
15
18#include "mlir/IR/IRMapping.h"
19
20namespace mlir {
21namespace acc {
22
23/// Clone an ACC region into a destination block at the given insertion point.
24/// Requires a single-block source region. Maps block arguments and optional
25/// result replacement: values in resultsToReplace are replaced with the
26/// operands of the cloned region's acc.yield (1:1). Erases acc.yield/terminator
27/// and merges blocks. Returns (replacement values, insertion point after
28/// clone).
29std::pair<llvm::SmallVector<Value>, Block::iterator>
30cloneACCRegionInto(Region *src, Block *dest, Block::iterator inlinePoint,
31 IRMapping &mapping, ValueRange resultsToReplace);
32
33/// Wrap a multi-block region in an scf.execute_region.
34/// Clones the given region into a new scf.execute_region. Replaces acc.yield
35/// with scf.yield; when convertFuncReturn is true, also replaces func.return
36/// with scf.yield. Use this to convert unstructured control flow (e.g. multiple
37/// blocks with branches) into a single SCF region.
38/// @param region The region to wrap (cloned into the execute_region; not
39/// modified).
40/// @param mapping IR mapping for the clone; updated with block and value
41/// mappings.
42/// @param loc Location for the created execute_region op.
43/// @param rewriter RewriterBase for creating and erasing operations.
44/// @param convertFuncReturn When true, replace func.return with scf.yield in
45/// addition to acc.yield. Default is false.
46/// @return The created scf.execute_region operation, or nullptr if any replaced
47/// terminator has operands (results not yet supported).
48scf::ExecuteRegionOp
49wrapMultiBlockRegionWithSCFExecuteRegion(Region &region, IRMapping &mapping,
50 Location loc, RewriterBase &rewriter,
51 bool convertFuncReturn = false);
52/// Convert a structured acc.loop to scf.for.
53/// The loop arguments are converted to index type. If enableCollapse is true,
54/// nested loops are collapsed into a single loop.
55/// @param loopOp The acc.loop operation to convert (must not be unstructured)
56/// @param rewriter RewriterBase for creating operations
57/// @param enableCollapse Whether to collapse nested loops into one
58/// @return The created scf.for operation or nullptr on creation error.
59/// An InFlightDiagnostic is emitted on creation error.
60scf::ForOp convertACCLoopToSCFFor(LoopOp loopOp, RewriterBase &rewriter,
61 bool enableCollapse);
62
63/// Convert acc.loop to scf.parallel.
64/// The loop induction variables are converted to index types.
65/// @param loopOp The acc.loop operation to convert
66/// @param rewriter RewriterBase for creating and erasing operations
67/// @return The created scf.parallel operation or nullptr on creation error.
68/// An InFlightDiagnostic is emitted on creation error.
69scf::ParallelOp convertACCLoopToSCFParallel(LoopOp loopOp,
70 RewriterBase &rewriter);
71
72/// Convert an unstructured acc.loop to scf.execute_region.
73/// @param loopOp The acc.loop operation to convert (must be unstructured)
74/// @param rewriter RewriterBase for creating and erasing operations
75/// @return The created scf.execute_region operation or nullptr on creation
76/// error. An InFlightDiagnostic is emitted on creation error.
77scf::ExecuteRegionOp
79 RewriterBase &rewriter);
80
81} // namespace acc
82} // namespace mlir
83
84#endif // MLIR_DIALECT_OPENACC_OPENACCUTILSLOOP_H_
OpListType::iterator iterator
Definition Block.h:150
scf::ExecuteRegionOp wrapMultiBlockRegionWithSCFExecuteRegion(Region &region, IRMapping &mapping, Location loc, RewriterBase &rewriter, bool convertFuncReturn=false)
Wrap a multi-block region in an scf.execute_region.
scf::ParallelOp convertACCLoopToSCFParallel(LoopOp loopOp, RewriterBase &rewriter)
Convert acc.loop to scf.parallel.
scf::ExecuteRegionOp convertUnstructuredACCLoopToSCFExecuteRegion(LoopOp loopOp, RewriterBase &rewriter)
Convert an unstructured acc.loop to scf.execute_region.
std::pair< llvm::SmallVector< Value >, Block::iterator > cloneACCRegionInto(Region *src, Block *dest, Block::iterator inlinePoint, IRMapping &mapping, ValueRange resultsToReplace)
Clone an ACC region into a destination block at the given insertion point.
scf::ForOp convertACCLoopToSCFFor(LoopOp loopOp, RewriterBase &rewriter, bool enableCollapse)
Convert a structured acc.loop to scf.for.
Include the generated interface declarations.