MLIR 23.0.0git
ControlFlowToSCF.h
Go to the documentation of this file.
1//===- ControlFlowToSCF.h - ControlFlow to SCF -------------*- 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// Define conversions from the ControlFlow dialect to the SCF dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_CONVERSION_CONTROLFLOWTOSCF_CONTROLFLOWTOSCF_H
14#define MLIR_CONVERSION_CONTROLFLOWTOSCF_CONTROLFLOWTOSCF_H
15
16#include <memory>
17
19
20namespace mlir {
21class Pass;
22
23/// Implementation of `CFGToSCFInterface` used to lift Control Flow Dialect
24/// operations to SCF Dialect operations.
26public:
27 /// Returns true only for `cf.cond_br` and `cf.switch`, the two multi-
28 /// successor ops this transformation knows how to convert.
30
31 /// Creates an `scf.if` op if `controlFlowCondOp` is a `cf.cond_br` op or
32 /// an `scf.index_switch` if `controlFlowCondOp` is a `cf.switch`.
33 /// Returns failure otherwise.
34 FailureOr<Operation *> createStructuredBranchRegionOp(
35 OpBuilder &builder, Operation *controlFlowCondOp, TypeRange resultTypes,
36 MutableArrayRef<Region> regions) override;
37
38 /// Creates an `scf.yield` op returning the given results.
40 Location loc, OpBuilder &builder, Operation *branchRegionOp,
41 Operation *replacedControlFlowOp, ValueRange results) override;
42
43 /// Creates an `scf.while` op. The loop body is made the before-region of the
44 /// while op and terminated with an `scf.condition` op. The after-region does
45 /// nothing but forward the iteration variables.
46 FailureOr<Operation *>
48 ValueRange loopVariablesInit, Value condition,
49 ValueRange loopVariablesNextIter,
50 Region &&loopBody) override;
51
52 /// Creates an `arith.constant` with an i32 attribute of the given value.
54 unsigned value) override;
55
56 /// Creates a `cf.switch` op with the given cases and flag.
57 void createCFGSwitchOp(Location loc, OpBuilder &builder, Value flag,
58 ArrayRef<unsigned> caseValues,
59 BlockRange caseDestinations,
60 ArrayRef<ValueRange> caseArguments, Block *defaultDest,
61 ValueRange defaultArgs) override;
62
63 /// Creates a `ub.poison` op of the given type.
64 Value getUndefValue(Location loc, OpBuilder &builder, Type type) override;
65
66 /// Creates a `func.return` op with poison for each of the return values of
67 /// the function. It is guaranteed to be directly within the function body.
68 /// TODO: This can be made independent of the `func` dialect once the UB
69 /// dialect has a `ub.unreachable` op.
70 FailureOr<Operation *> createUnreachableTerminator(Location loc,
71 OpBuilder &builder,
72 Region &region) override;
73};
74
75#define GEN_PASS_DECL_LIFTCONTROLFLOWTOSCFPASS
76#include "mlir/Conversion/Passes.h.inc"
77
78} // namespace mlir
79
80#endif // MLIR_CONVERSION_CONTROLFLOWTOSCF_CONTROLFLOWTOSCF_H
This class provides an abstraction over the different types of ranges over Blocks.
Block represents an ordered list of Operations.
Definition Block.h:33
Interface that should be implemented by any caller of transformCFGToSCF.
Definition CFGToSCF.h:28
Implementation of CFGToSCFInterface used to lift Control Flow Dialect operations to SCF Dialect opera...
FailureOr< Operation * > createUnreachableTerminator(Location loc, OpBuilder &builder, Region &region) override
Creates a func.return op with poison for each of the return values of the function.
LogicalResult createStructuredBranchRegionTerminatorOp(Location loc, OpBuilder &builder, Operation *branchRegionOp, Operation *replacedControlFlowOp, ValueRange results) override
Creates an scf.yield op returning the given results.
void createCFGSwitchOp(Location loc, OpBuilder &builder, Value flag, ArrayRef< unsigned > caseValues, BlockRange caseDestinations, ArrayRef< ValueRange > caseArguments, Block *defaultDest, ValueRange defaultArgs) override
Creates a cf.switch op with the given cases and flag.
FailureOr< Operation * > createStructuredDoWhileLoopOp(OpBuilder &builder, Operation *replacedOp, ValueRange loopVariablesInit, Value condition, ValueRange loopVariablesNextIter, Region &&loopBody) override
Creates an scf.while op.
bool canConvertMultiSuccessorBranchOp(Operation *op) override
Returns true only for cf.cond_br and cf.switch, the two multi- successor ops this transformation know...
Value getCFGSwitchValue(Location loc, OpBuilder &builder, unsigned value) override
Creates an arith.constant with an i32 attribute of the given value.
Value getUndefValue(Location loc, OpBuilder &builder, Type type) override
Creates a ub.poison op of the given type.
FailureOr< Operation * > createStructuredBranchRegionOp(OpBuilder &builder, Operation *controlFlowCondOp, TypeRange resultTypes, MutableArrayRef< Region > regions) override
Creates an scf.if op if controlFlowCondOp is a cf.cond_br op or an scf.index_switch if controlFlowCon...
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
This class helps build Operations.
Definition Builders.h:209
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
The abstract base pass class.
Definition Pass.h:52
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 various different ranges of value types.
Definition TypeRange.h:40
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:389
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
Include the generated interface declarations.