• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- Builders.h - MLIR Declarative Builder Classes ------------*- 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 // Provides intuitive composable interfaces for building structured MLIR
10 // snippets in a declarative fashion.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_DIALECT_SCF_EDSC_BUILDERS_H_
15 #define MLIR_DIALECT_SCF_EDSC_BUILDERS_H_
16 
17 #include "mlir/Dialect/SCF/SCF.h"
18 #include "mlir/EDSC/Builders.h"
19 #include "mlir/IR/Builders.h"
20 #include "mlir/IR/Types.h"
21 
22 namespace mlir {
23 namespace edsc {
24 
25 /// Adapters for building loop nests using the builder and the location stored
26 /// in ScopedContext. Actual builders are in scf::buildLoopNest.
27 scf::LoopNest loopNestBuilder(ValueRange lbs, ValueRange ubs,
28                                  ValueRange steps,
29                                  function_ref<void(ValueRange)> fun = nullptr);
30 scf::LoopNest loopNestBuilder(Value lb, Value ub, Value step,
31                                  function_ref<void(Value)> fun = nullptr);
32 scf::LoopNest loopNestBuilder(
33     Value lb, Value ub, Value step, ValueRange iterArgInitValues,
34     function_ref<scf::ValueVector(Value, ValueRange)> fun = nullptr);
35 scf::LoopNest loopNestBuilder(
36     ValueRange lbs, ValueRange ubs, ValueRange steps,
37     ValueRange iterArgInitValues,
38     function_ref<scf::ValueVector(ValueRange, ValueRange)> fun = nullptr);
39 
40 /// Adapters for building if conditions using the builder and the location
41 /// stored in ScopedContext. 'thenBody' is mandatory, 'elseBody' can be omitted
42 /// if the condition should not have an 'else' part.
43 /// When `ifOp` is specified, the scf::IfOp is captured. This is particularly
44 /// convenient for 0-result conditions.
45 ValueRange conditionBuilder(TypeRange results, Value condition,
46                             function_ref<scf::ValueVector()> thenBody,
47                             function_ref<scf::ValueVector()> elseBody = nullptr,
48                             scf::IfOp *ifOp = nullptr);
49 ValueRange conditionBuilder(Value condition, function_ref<void()> thenBody,
50                             function_ref<void()> elseBody = nullptr,
51                             scf::IfOp *ifOp = nullptr);
52 
53 } // namespace edsc
54 } // namespace mlir
55 
56 #endif // MLIR_DIALECT_SCF_EDSC_BUILDERS_H_
57