• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- Utils.h - SCF dialect 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 header file defines prototypes for various SCF utilities.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_DIALECT_SCF_UTILS_H_
14 #define MLIR_DIALECT_SCF_UTILS_H_
15 
16 #include "mlir/Support/LLVM.h"
17 
18 namespace mlir {
19 class FuncOp;
20 class OpBuilder;
21 class ValueRange;
22 
23 namespace scf {
24 class IfOp;
25 class ForOp;
26 class ParallelOp;
27 } // end namespace scf
28 
29 /// Create a clone of `loop` with `newIterOperands` added as new initialization
30 /// values and `newYieldedValues` added as new yielded values. The returned
31 /// ForOp has `newYieldedValues.size()` new result values.  The `loop` induction
32 /// variable and `newIterOperands` are remapped to the new induction variable
33 /// and the new entry block arguments respectively.
34 ///
35 /// Additionally, if `replaceLoopResults` is true, all uses of
36 /// `loop.getResults()` are replaced with the first `loop.getNumResults()`
37 /// return values respectively. This additional replacement is provided as a
38 /// convenience to update the consumers of `loop`, in the case e.g. when `loop`
39 /// is soon to be deleted.
40 ///
41 /// Return the cloned loop.
42 ///
43 /// This convenience function is useful to factorize common mechanisms related
44 /// to hoisting roundtrips to memory into yields. It does not perform any
45 /// legality checks.
46 ///
47 /// Prerequisite: `newYieldedValues.size() == newYieldedValues.size()`.
48 scf::ForOp cloneWithNewYields(OpBuilder &b, scf::ForOp loop,
49                               ValueRange newIterOperands,
50                               ValueRange newYieldedValues,
51                               bool replaceLoopResults = true);
52 
53 /// Outline the then and/or else regions of `ifOp` as follows:
54 ///  - if `thenFn` is not null, `thenFnName` must be specified and the `then`
55 ///    region is inlined into a new FuncOp that is captured by the pointer.
56 ///  - if `elseFn` is not null, `elseFnName` must be specified and the `else`
57 ///    region is inlined into a new FuncOp that is captured by the pointer.
58 void outlineIfOp(OpBuilder &b, scf::IfOp ifOp, FuncOp *thenFn,
59                  StringRef thenFnName, FuncOp *elseFn, StringRef elseFnName);
60 } // end namespace mlir
61 #endif // MLIR_DIALECT_SCF_UTILS_H_
62