|
MLIR 24.0.0git
|
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"#include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"#include "mlir/Dialect/Arith/IR/Arith.h"#include "mlir/Dialect/Bufferization/IR/BufferDeallocationOpInterface.h"#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"#include "mlir/Dialect/UB/IR/UBOps.h"#include "mlir/IR/AffineExpr.h"#include "mlir/IR/AffineMap.h"#include "mlir/IR/Builders.h"#include "mlir/IR/BuiltinTypes.h"#include "mlir/IR/IRMapping.h"#include "mlir/IR/Matchers.h"#include "mlir/IR/OpImplementation.h"#include "mlir/IR/PatternMatch.h"#include "mlir/IR/TypeUtilities.h"#include "mlir/IR/Value.h"#include "mlir/Transforms/InliningUtils.h"#include "llvm/ADT/STLExtras.h"#include <numeric>#include "mlir/Dialect/ControlFlow/IR/ControlFlowOpsDialect.cpp.inc"#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.cpp.inc"Go to the source code of this file.
Macros | |
| #define | GET_OP_CLASSES |
Functions | |
| static LogicalResult | collapseBranch (Block *&successor, ValueRange &successorOperands, SmallVectorImpl< Value > &argStorage) |
| Given a successor, try to collapse it to a new destination if it only contains a passthrough unconditional branch. | |
| static LogicalResult | simplifyBrToBlockWithSinglePred (BranchOp op, PatternRewriter &rewriter) |
| Simplify a branch to a block that has a single predecessor. | |
| static LogicalResult | simplifyPassThroughBr (BranchOp op, PatternRewriter &rewriter) |
| br ^bb1 ^bb1 br ^bbN(...) | |
| static LogicalResult | simplifyUniformBlockArgs (Block *dest, PatternRewriter &rewriter) |
| If all incoming values for a block argument from all predecessors are the same SSA value, replace uses of the block argument with that value. | |
| static ParseResult | parseSwitchOpCases (OpAsmParser &parser, Type &flagType, Block *&defaultDestination, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &defaultOperands, SmallVectorImpl< Type > &defaultOperandTypes, DenseIntElementsAttr &caseValues, SmallVectorImpl< Block * > &caseDestinations, SmallVectorImpl< SmallVector< OpAsmParser::UnresolvedOperand > > &caseOperands, SmallVectorImpl< SmallVector< Type > > &caseOperandTypes) |
| <cases> ::= default : bb-id (( ssa-use-and-type-list ))? | |
| static void | printSwitchOpCases (OpAsmPrinter &p, SwitchOp op, Type flagType, Block *defaultDestination, OperandRange defaultOperands, TypeRange defaultOperandTypes, DenseIntElementsAttr caseValues, SuccessorRange caseDestinations, OperandRangeRange caseOperands, const TypeRangeRange &caseOperandTypes) |
| static LogicalResult | simplifySwitchWithOnlyDefault (SwitchOp op, PatternRewriter &rewriter) |
| switch flag : i32, [ default: ^bb1 ] -> br ^bb1 | |
| static LogicalResult | dropSwitchCasesThatMatchDefault (SwitchOp op, PatternRewriter &rewriter) |
| switch flag : i32, [ default: ^bb1, 42: ^bb1, 43: ^bb2 ] -> switch flag : i32, [ default: ^bb1, 43: ^bb2 ] | |
| static LogicalResult | dropUnreachableSwitchCases (SwitchOp op, PatternRewriter &rewriter) |
| Drop cases whose destination block contains only ub.unreachable. | |
| static void | foldSwitch (SwitchOp op, PatternRewriter &rewriter, const APInt &caseValue) |
| Helper for folding a switch with a constant value. | |
| static LogicalResult | simplifyConstSwitchValue (SwitchOp op, PatternRewriter &rewriter) |
| switch c_42 : i32, [ default: ^bb1, 42: ^bb2, 43: ^bb3 ] -> br ^bb2 | |
| static LogicalResult | simplifyPassThroughSwitch (SwitchOp op, PatternRewriter &rewriter) |
| switch c_42 : i32, [ default: ^bb1, 42: ^bb2, ] ^bb2: br ^bb3 -> switch c_42 : i32, [ default: ^bb1, 42: ^bb3, ] | |
| static LogicalResult | simplifySwitchFromSwitchOnSameCondition (SwitchOp op, PatternRewriter &rewriter) |
| switch flag : i32, [ default: ^bb1, 42: ^bb2, ] ^bb2: switch flag : i32, [ default: ^bb3, 42: ^bb4 ] -> switch flag : i32, [ default: ^bb1, 42: ^bb2, ] ^bb2: br ^bb4 | |
| static LogicalResult | simplifySwitchFromDefaultSwitchOnSameCondition (SwitchOp op, PatternRewriter &rewriter) |
| switch flag : i32, [ default: ^bb1, 42: ^bb2 ] ^bb1: switch flag : i32, [ default: ^bb3, 42: ^bb4, 43: ^bb5 ] -> switch flag : i32, [ default: ^bb1, 42: ^bb2, ] ^bb1: switch flag : i32, [ default: ^bb3, 43: ^bb5 ] | |
| #define GET_OP_CLASSES |
Definition at line 1125 of file ControlFlowOps.cpp.
|
static |
Given a successor, try to collapse it to a new destination if it only contains a passthrough unconditional branch.
If the successor is collapsable, successor and successorOperands are updated to reference the new destination and values. argStorage is used as storage if operands to the collapsed successor need to be remapped. It must outlive uses of successorOperands.
Definition at line 102 of file ControlFlowOps.cpp.
References mlir::Block::args_empty(), mlir::Block::begin(), mlir::Block::end(), mlir::BlockArgument::getArgNumber(), mlir::Block::getArguments(), mlir::BlockArgument::getOwner(), mlir::Block::getTerminator(), mlir::Operation::getUsers(), and success().
Referenced by simplifyPassThroughBr(), and simplifyPassThroughSwitch().
|
static |
switch flag : i32, [ default: ^bb1, 42: ^bb1, 43: ^bb2 ] -> switch flag : i32, [ default: ^bb1, 43: ^bb2 ]
Definition at line 797 of file ControlFlowOps.cpp.
References mlir::RewriterBase::replaceOpWithNewOp(), and success().
|
static |
Drop cases whose destination block contains only ub.unreachable.
If the default destination is unreachable, the last remaining case becomes the new default destination, or the switch is replaced by ub.unreachable if no case remains. switch flag : i32, [ default: ^bb1, 42: ^bb2, 43: ^bb3 ] ^bb3: ub.unreachable -> switch flag : i32, [ default: ^bb1, 42: ^bb2 ]
Definition at line 840 of file ControlFlowOps.cpp.
References mlir::RewriterBase::replaceOpWithNewOp(), and success().
|
static |
Helper for folding a switch with a constant value.
switch c_42 : i32, [ default: ^bb1 , 42: ^bb2, 43: ^bb3 ] -> br ^bb2
Definition at line 892 of file ControlFlowOps.cpp.
References mlir::RewriterBase::replaceOpWithNewOp().
Referenced by simplifyConstSwitchValue(), and simplifySwitchFromSwitchOnSameCondition().
|
static |
<cases> ::= default : bb-id (( ssa-use-and-type-list ))?
( , integer : bb-id (( ssa-use-and-type-list ))? )*
Definition at line 629 of file ControlFlowOps.cpp.
References mlir::AsmParser::emitError(), mlir::DenseIntElementsAttr::get(), mlir::AsmParser::getCurrentLocation(), mlir::Type::getIntOrFloatBitWidth(), mlir::AsmParser::None, mlir::AsmParser::parseColon(), mlir::AsmParser::parseColonTypeList(), mlir::AsmParser::parseInteger(), mlir::AsmParser::parseKeyword(), mlir::OpAsmParser::parseOperandList(), mlir::AsmParser::parseOptionalComma(), mlir::AsmParser::parseOptionalLParen(), mlir::AsmParser::parseRParen(), mlir::OpAsmParser::parseSuccessor(), and success().
|
static |
Definition at line 686 of file ControlFlowOps.cpp.
References mlir::AsmPrinter::printNewline(), and mlir::OpAsmPrinter::printSuccessorAndUseList().
|
static |
Simplify a branch to a block that has a single predecessor.
This effectively merges the two blocks.
Definition at line 158 of file ControlFlowOps.cpp.
References mlir::RewriterBase::eraseOp(), mlir::Block::getPredecessors(), mlir::RewriterBase::mergeBlocks(), and success().
|
static |
switch c_42 : i32, [ default: ^bb1, 42: ^bb2, 43: ^bb3 ] -> br ^bb2
Definition at line 913 of file ControlFlowOps.cpp.
References foldSwitch(), mlir::m_ConstantInt(), mlir::matchPattern(), and success().
|
static |
br ^bb1 ^bb1 br ^bbN(...)
-> br ^bbN(...)
Definition at line 186 of file ControlFlowOps.cpp.
References collapseBranch(), mlir::RewriterBase::replaceOpWithNewOp(), and success().
|
static |
switch c_42 : i32, [ default: ^bb1, 42: ^bb2, ] ^bb2: br ^bb3 -> switch c_42 : i32, [ default: ^bb1, 42: ^bb3, ]
Definition at line 934 of file ControlFlowOps.cpp.
References collapseBranch(), mlir::RewriterBase::replaceOpWithNewOp(), and success().
|
static |
switch flag : i32, [ default: ^bb1, 42: ^bb2 ] ^bb1: switch flag : i32, [ default: ^bb3, 42: ^bb4, 43: ^bb5 ] -> switch flag : i32, [ default: ^bb1, 42: ^bb2, ] ^bb1: switch flag : i32, [ default: ^bb3, 43: ^bb5 ]
Definition at line 1059 of file ControlFlowOps.cpp.
References mlir::Block::getSinglePredecessor(), mlir::Block::getTerminator(), mlir::RewriterBase::replaceOpWithNewOp(), and success().
|
static |
switch flag : i32, [ default: ^bb1, 42: ^bb2, ] ^bb2: switch flag : i32, [ default: ^bb3, 42: ^bb4 ] -> switch flag : i32, [ default: ^bb1, 42: ^bb2, ] ^bb2: br ^bb4
and
switch flag : i32, [ default: ^bb1, 42: ^bb2, ] ^bb2: switch flag : i32, [ default: ^bb3, 43: ^bb4 ] -> switch flag : i32, [ default: ^bb1, 42: ^bb2, ] ^bb2: br ^bb3
Definition at line 1007 of file ControlFlowOps.cpp.
References foldSwitch(), mlir::Block::getSinglePredecessor(), mlir::Block::getTerminator(), mlir::RewriterBase::replaceOpWithNewOp(), and success().
|
static |
switch flag : i32, [ default: ^bb1 ] -> br ^bb1
Definition at line 776 of file ControlFlowOps.cpp.
References mlir::RewriterBase::replaceOpWithNewOp(), and success().
|
static |
If all incoming values for a block argument from all predecessors are the same SSA value, replace uses of the block argument with that value.
This allows the block argument to be removed by dead code elimination.
c = arith.constant 0 : i32 cf.br ^bb1(c : i32) // pred 1 cf.br ^bb1(c : i32) // pred 2 ^bb1(arg0: i32): use(arg0) -> ^bb1(arg0: i32): use(c) // arg0 has no uses and can be removed
Definition at line 216 of file ControlFlowOps.cpp.
References mlir::Block::getArguments(), mlir::Block::getPredecessors(), mlir::Block::hasNoPredecessors(), mlir::RewriterBase::replaceAllUsesWith(), and success().