MLIR 24.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/// leading operands of the cloned region's acc.yield (1:1). Erases
27/// acc.yield/terminator and merges blocks. Returns all yielded values,
28/// including any values not used as replacements, and the insertion point after
29/// the clone.
30std::pair<llvm::SmallVector<Value>, Block::iterator>
31cloneACCRegionInto(Region *src, Block *dest, Block::iterator inlinePoint,
32 IRMapping &mapping, ValueRange resultsToReplace);
33
34/// Wrap a multi-block region in an scf.execute_region.
35/// Clones the given region into a new scf.execute_region. Terminators with no
36/// successors (i.e., region exit points) are replaced with scf.yield. Use this
37/// to convert unstructured control flow (e.g. multiple blocks with branches)
38/// into a single SCF region.
39/// @param region The region to wrap (cloned into the execute_region; not
40/// modified).
41/// @param mapping IR mapping for the clone; updated with block and value
42/// mappings.
43/// @param loc Location for the created execute_region op.
44/// @param rewriter RewriterBase for creating and erasing operations.
45/// @return The created scf.execute_region operation.
46scf::ExecuteRegionOp
47wrapMultiBlockRegionWithSCFExecuteRegion(Region &region, IRMapping &mapping,
48 Location loc, RewriterBase &rewriter);
49
50/// Convert a structured acc.loop to scf.for.
51/// The loop arguments are converted to index type. If enableCollapse is true,
52/// nested loops are collapsed into a single loop.
53/// @param loopOp The acc.loop operation to convert (must not be unstructured)
54/// @param rewriter RewriterBase for creating operations
55/// @param enableCollapse Whether to collapse nested loops into one
56/// @return The created scf.for operation or nullptr on creation error.
57/// An InFlightDiagnostic is emitted on creation error.
58scf::ForOp convertACCLoopToSCFFor(LoopOp loopOp, RewriterBase &rewriter,
59 bool enableCollapse);
60
61/// Convert acc.loop to scf.parallel.
62/// The loop induction variables are converted to index types.
63/// @param loopOp The acc.loop operation to convert
64/// @param rewriter RewriterBase for creating and erasing operations
65/// @return The created scf.parallel operation or nullptr on creation error.
66/// An InFlightDiagnostic is emitted on creation error.
67scf::ParallelOp convertACCLoopToSCFParallel(LoopOp loopOp,
68 RewriterBase &rewriter);
69
70/// Convert an unstructured acc.loop to scf.execute_region.
71/// @param loopOp The acc.loop operation to convert (must be unstructured)
72/// @param rewriter RewriterBase for creating and erasing operations
73/// @return The created scf.execute_region operation or nullptr on creation
74/// error. An InFlightDiagnostic is emitted on creation error.
75scf::ExecuteRegionOp
77 RewriterBase &rewriter);
78
79/// Calculate trip count for a loop: (ub - lb + step) / step.
80/// If \p inclusiveUpperbound is false, subtracts 1 from \p ub first.
81/// Operands are cast to index type.
82Value calculateTripCount(OpBuilder &b, Location loc, Value lb, Value ub,
83 Value step, bool inclusiveUpperbound);
84
85/// Normalize IV uses after converting to normalized loop form (lb=0, step=1).
86/// Replaces uses of \p iv with `iv * origStep + origLB`.
87void normalizeIVUses(OpBuilder &b, Location loc, Value iv, Value origLB,
88 Value origStep);
89
90/// Record on a collapsed loop how many original loops were folded into it.
91void setCollapseCountAttr(Operation *op, uint64_t count);
92
93/// Number of original loops collapsed into op, or 1 when op carries no
94/// collapse_count attribute.
95uint64_t getCollapseCount(Operation *op);
96
97} // namespace acc
98} // namespace mlir
99
100#endif // MLIR_DIALECT_OPENACC_OPENACCUTILSLOOP_H_
b
Return true if permutation is a valid permutation of the outer_dims_perm (case OuterOrInnerPerm::Oute...
OpListType::iterator iterator
Definition Block.h:164
uint64_t getCollapseCount(Operation *op)
Number of original loops collapsed into op, or 1 when op carries no collapse_count attribute.
void setCollapseCountAttr(Operation *op, uint64_t count)
Record on a collapsed loop how many original loops were folded into it.
Value calculateTripCount(OpBuilder &b, Location loc, Value lb, Value ub, Value step, bool inclusiveUpperbound)
Calculate trip count for a loop: (ub - lb + step) / step.
scf::ParallelOp convertACCLoopToSCFParallel(LoopOp loopOp, RewriterBase &rewriter)
Convert acc.loop to scf.parallel.
scf::ExecuteRegionOp wrapMultiBlockRegionWithSCFExecuteRegion(Region &region, IRMapping &mapping, Location loc, RewriterBase &rewriter)
Wrap a multi-block region in an scf.execute_region.
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.
void normalizeIVUses(OpBuilder &b, Location loc, Value iv, Value origLB, Value origStep)
Normalize IV uses after converting to normalized loop form (lb=0, step=1).
scf::ForOp convertACCLoopToSCFFor(LoopOp loopOp, RewriterBase &rewriter, bool enableCollapse)
Convert a structured acc.loop to scf.for.
Include the generated interface declarations.