MLIR  17.0.0git
SCF.h
Go to the documentation of this file.
1 //===- SCFOps.h - Structured Control Flow -----------------------*- 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 structured control flow operations.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_DIALECT_SCF_SCF_H
14 #define MLIR_DIALECT_SCF_SCF_H
15 
17 #include "mlir/IR/Builders.h"
18 #include "mlir/IR/BuiltinTypes.h"
26 
27 namespace mlir {
28 namespace scf {
29 void buildTerminatedBody(OpBuilder &builder, Location loc);
30 } // namespace scf
31 } // namespace mlir
32 
33 #include "mlir/Dialect/SCF/IR/SCFOpsDialect.h.inc"
34 
35 #define GET_OP_CLASSES
36 #include "mlir/Dialect/SCF/IR/SCFOps.h.inc"
37 
38 namespace mlir {
39 namespace scf {
40 
41 // Insert `loop.yield` at the end of the only region's only block if it
42 // does not have a terminator already. If a new `loop.yield` is inserted,
43 // the location is specified by `loc`. If the region is empty, insert a new
44 // block first.
45 void ensureLoopTerminator(Region &region, Builder &builder, Location loc);
46 
47 /// Returns the loop parent of an induction variable. If the provided value is
48 /// not an induction variable, then return nullptr.
50 
51 /// Returns the parallel loop parent of an induction variable. If the provided
52 /// value is not an induction variable, then return nullptr.
54 
55 /// Returns the ForeachThreadOp parent of an thread index variable.
56 /// If the provided value is not a thread index variable, then return nullptr.
57 ForeachThreadOp getForeachThreadOpThreadIndexOwner(Value val);
58 
59 /// Return true if ops a and b (or their ancestors) are in mutually exclusive
60 /// regions/blocks of an IfOp.
61 // TODO: Consider moving this functionality to RegionBranchOpInterface.
63 
64 /// An owning vector of values, handy to return from functions.
67 struct LoopNest {
70 };
71 
72 /// Creates a perfect nest of "for" loops, i.e. all loops but the innermost
73 /// contain only another loop and a terminator. The lower, upper bounds and
74 /// steps are provided as `lbs`, `ubs` and `steps`, which are expected to be of
75 /// the same size. `iterArgs` points to the initial values of the loop iteration
76 /// arguments, which will be forwarded through the nest to the innermost loop.
77 /// The body of the loop is populated using `bodyBuilder`, which accepts an
78 /// ordered list of induction variables of all loops, followed by a list of
79 /// iteration arguments of the innermost loop, in the same order as provided to
80 /// `iterArgs`. This function is expected to return as many values as
81 /// `iterArgs`, of the same type and in the same order, that will be treated as
82 /// yielded from the loop body and forwarded back through the loop nest. If the
83 /// function is not provided, the loop nest is not expected to have iteration
84 /// arguments, the body of the innermost loop will be left empty, containing
85 /// only the zero-operand terminator. Returns the LoopNest containing the list
86 /// of perfectly nest scf::ForOp build during the call.
87 /// If bound arrays are empty, the body builder will be called
88 /// once to construct the IR outside of the loop with an empty list of induction
89 /// variables.
91  OpBuilder &builder, Location loc, ValueRange lbs, ValueRange ubs,
92  ValueRange steps, ValueRange iterArgs,
94  bodyBuilder = nullptr);
95 
96 /// A convenience version for building loop nests without iteration arguments
97 /// (like for reductions). Does not take the initial value of reductions or
98 /// expect the body building functions to return their current value.
99 /// The built nested scf::For are captured in `capturedLoops` when non-null.
101  ValueRange ubs, ValueRange steps,
103  bodyBuilder = nullptr);
104 
105 } // namespace scf
106 } // namespace mlir
107 #endif // MLIR_DIALECT_SCF_SCF_H
This class is a general helper class for creating context-global objects like types,...
Definition: Builders.h:50
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:63
This class helps build Operations.
Definition: Builders.h:199
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:75
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition: Region.h:26
This class provides an abstraction over the different types of ranges over Values.
Definition: ValueRange.h:350
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition: Value.h:93
ParallelOp getParallelForInductionVarOwner(Value val)
Returns the parallel loop parent of an induction variable.
Definition: SCF.cpp:2496
SmallVector< scf::ForOp > LoopVector
Definition: SCF.h:66
void buildTerminatedBody(OpBuilder &builder, Location loc)
Default callback for IfOp builders. Inserts a yield without arguments.
Definition: SCF.cpp:77
LoopNest buildLoopNest(OpBuilder &builder, Location loc, ValueRange lbs, ValueRange ubs, ValueRange steps, ValueRange iterArgs, function_ref< ValueVector(OpBuilder &, Location, ValueRange, ValueRange)> bodyBuilder=nullptr)
Creates a perfect nest of "for" loops, i.e.
Definition: SCF.cpp:526
bool insideMutuallyExclusiveBranches(Operation *a, Operation *b)
Return true if ops a and b (or their ancestors) are in mutually exclusive regions/blocks of an IfOp.
Definition: SCF.cpp:1446
ForOp getForInductionVarOwner(Value val)
Returns the loop parent of an induction variable.
void ensureLoopTerminator(Region &region, Builder &builder, Location loc)
SmallVector< Value > ValueVector
An owning vector of values, handy to return from functions.
Definition: SCF.h:65
ForeachThreadOp getForeachThreadOpThreadIndexOwner(Value val)
Returns the ForeachThreadOp parent of an thread index variable.
Definition: SCF.cpp:1331
Include the generated interface declarations.
ValueVector results
Definition: SCF.h:69
LoopVector loops
Definition: SCF.h:68