MLIR  20.0.0git
Macros | Functions
ControlFlowOps.cpp File Reference
#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/IR/AffineExpr.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.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/APFloat.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/raw_ostream.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_LIST
 
#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. More...
 
static LogicalResult simplifyBrToBlockWithSinglePred (BranchOp op, PatternRewriter &rewriter)
 Simplify a branch to a block that has a single predecessor. More...
 
static LogicalResult simplifyPassThroughBr (BranchOp op, PatternRewriter &rewriter)
 br ^bb1 ^bb1 br ^bbN(...) More...
 
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 ))? ( , integer : bb-id (( ssa-use-and-type-list ))? )* More...
 
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 More...
 
static LogicalResult dropSwitchCasesThatMatchDefault (SwitchOp op, PatternRewriter &rewriter)
 switch flag : i32, [ default: ^bb1, 42: ^bb1, 43: ^bb2 ] -> switch flag : i32, [ default: ^bb1, 43: ^bb2 ] More...
 
static void foldSwitch (SwitchOp op, PatternRewriter &rewriter, const APInt &caseValue)
 Helper for folding a switch with a constant value. More...
 
static LogicalResult simplifyConstSwitchValue (SwitchOp op, PatternRewriter &rewriter)
 switch c_42 : i32, [ default: ^bb1, 42: ^bb2, 43: ^bb3 ] -> br ^bb2 More...
 
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, ] More...
 
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 More...
 
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 ] More...
 

Macro Definition Documentation

◆ GET_OP_CLASSES

#define GET_OP_CLASSES

Definition at line 918 of file ControlFlowOps.cpp.

◆ GET_OP_LIST

#define GET_OP_LIST

Function Documentation

◆ collapseBranch()

static LogicalResult collapseBranch ( Block *&  successor,
ValueRange successorOperands,
SmallVectorImpl< Value > &  argStorage 
)
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 109 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(), and mlir::Operation::getUsers().

Referenced by simplifyPassThroughBr(), and simplifyPassThroughSwitch().

◆ dropSwitchCasesThatMatchDefault()

static LogicalResult dropSwitchCasesThatMatchDefault ( SwitchOp  op,
PatternRewriter rewriter 
)
static

switch flag : i32, [ default: ^bb1, 42: ^bb1, 43: ^bb2 ] -> switch flag : i32, [ default: ^bb1, 43: ^bb2 ]

Definition at line 652 of file ControlFlowOps.cpp.

References mlir::detail::enumerate(), and mlir::RewriterBase::replaceOpWithNewOp().

◆ foldSwitch()

static void foldSwitch ( SwitchOp  op,
PatternRewriter rewriter,
const APInt &  caseValue 
)
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 687 of file ControlFlowOps.cpp.

References mlir::detail::enumerate(), and mlir::RewriterBase::replaceOpWithNewOp().

Referenced by simplifyConstSwitchValue(), and simplifySwitchFromSwitchOnSameCondition().

◆ parseSwitchOpCases()

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 
)
static

◆ printSwitchOpCases()

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

◆ simplifyBrToBlockWithSinglePred()

static LogicalResult simplifyBrToBlockWithSinglePred ( BranchOp  op,
PatternRewriter rewriter 
)
static

Simplify a branch to a block that has a single predecessor.

This effectively merges the two blocks.

Definition at line 155 of file ControlFlowOps.cpp.

References mlir::RewriterBase::eraseOp(), mlir::Block::getPredecessors(), and mlir::RewriterBase::mergeBlocks().

◆ simplifyConstSwitchValue()

static LogicalResult simplifyConstSwitchValue ( SwitchOp  op,
PatternRewriter rewriter 
)
static

switch c_42 : i32, [ default: ^bb1, 42: ^bb2, 43: ^bb3 ] -> br ^bb2

Definition at line 708 of file ControlFlowOps.cpp.

References foldSwitch(), mlir::m_ConstantInt(), and mlir::matchPattern().

◆ simplifyPassThroughBr()

static LogicalResult simplifyPassThroughBr ( BranchOp  op,
PatternRewriter rewriter 
)
static

br ^bb1 ^bb1 br ^bbN(...)

-> br ^bbN(...)

Definition at line 175 of file ControlFlowOps.cpp.

References collapseBranch(), and mlir::RewriterBase::replaceOpWithNewOp().

◆ simplifyPassThroughSwitch()

static LogicalResult simplifyPassThroughSwitch ( SwitchOp  op,
PatternRewriter rewriter 
)
static

switch c_42 : i32, [ default: ^bb1, 42: ^bb2, ] ^bb2: br ^bb3 -> switch c_42 : i32, [ default: ^bb1, 42: ^bb3, ]

Definition at line 729 of file ControlFlowOps.cpp.

References collapseBranch(), and mlir::RewriterBase::replaceOpWithNewOp().

◆ simplifySwitchFromDefaultSwitchOnSameCondition()

static LogicalResult simplifySwitchFromDefaultSwitchOnSameCondition ( SwitchOp  op,
PatternRewriter rewriter 
)
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 854 of file ControlFlowOps.cpp.

References mlir::detail::enumerate(), mlir::Block::getSinglePredecessor(), mlir::Block::getTerminator(), and mlir::RewriterBase::replaceOpWithNewOp().

◆ simplifySwitchFromSwitchOnSameCondition()

static LogicalResult simplifySwitchFromSwitchOnSameCondition ( SwitchOp  op,
PatternRewriter rewriter 
)
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 802 of file ControlFlowOps.cpp.

References foldSwitch(), mlir::Block::getSinglePredecessor(), mlir::Block::getTerminator(), and mlir::RewriterBase::replaceOpWithNewOp().

◆ simplifySwitchWithOnlyDefault()

static LogicalResult simplifySwitchWithOnlyDefault ( SwitchOp  op,
PatternRewriter rewriter 
)
static

switch flag : i32, [ default: ^bb1 ] -> br ^bb1

Definition at line 631 of file ControlFlowOps.cpp.

References mlir::RewriterBase::replaceOpWithNewOp().