MLIR

Multi-Level IR Compiler Framework

'cf' Dialect

This dialect contains low-level, i.e. non-region based, control flow constructs. These constructs generally represent control flow directly on SSA blocks of a control flow graph.

Operations 

source

cf.assert (cf::AssertOp) 

Assert operation with message attribute

Syntax:

operation ::= `cf.assert` $arg `,` $msg attr-dict

Assert operation at runtime with single boolean operand and an error message attribute. If the argument is true this operation has no effect. Otherwise, the program execution will abort. The provided error message may be used by a runtime to propagate the error to the user.

Example:

cf.assert %b, "Expected ... to be true"

Interfaces: MemoryEffectOpInterface

Attributes: 

AttributeMLIR TypeDescription
msg::mlir::StringAttrstring attribute

Operands: 

OperandDescription
arg1-bit signless integer

cf.br (cf::BranchOp) 

Branch operation

Syntax:

operation ::= `cf.br` $dest (`(` $destOperands^ `:` type($destOperands) `)`)? attr-dict

The cf.br operation represents a direct branch operation to a given block. The operands of this operation are forwarded to the successor block, and the number and type of the operands must match the arguments of the target block.

Example:

^bb2:
  %2 = call @someFn()
  cf.br ^bb3(%2 : tensor<*xf32>)
^bb3(%3: tensor<*xf32>):

Traits: AlwaysSpeculatableImplTrait, Terminator

Interfaces: BranchOpInterface, ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
destOperandsvariadic of any type

Successors: 

SuccessorDescription
destany successor

cf.cond_br (cf::CondBranchOp) 

Conditional branch operation

Syntax:

operation ::= `cf.cond_br` $condition `,`
              $trueDest (`(` $trueDestOperands^ `:` type($trueDestOperands) `)`)? `,`
              $falseDest (`(` $falseDestOperands^ `:` type($falseDestOperands) `)`)?
              attr-dict

The cf.cond_br terminator operation represents a conditional branch on a boolean (1-bit integer) value. If the bit is set, then the first destination is jumped to; if it is false, the second destination is chosen. The count and types of operands must align with the arguments in the corresponding target blocks.

The MLIR conditional branch operation is not allowed to target the entry block for a region. The two destinations of the conditional branch operation are allowed to be the same.

The following example illustrates a function with a conditional branch operation that targets the same block.

Example:

func.func @select(%a: i32, %b: i32, %flag: i1) -> i32 {
  // Both targets are the same, operands differ
  cf.cond_br %flag, ^bb1(%a : i32), ^bb1(%b : i32)

^bb1(%x : i32) :
  return %x : i32
}

Traits: AlwaysSpeculatableImplTrait, AttrSizedOperandSegments, Terminator

Interfaces: BranchOpInterface, ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
condition1-bit signless integer
trueDestOperandsvariadic of any type
falseDestOperandsvariadic of any type

Successors: 

SuccessorDescription
trueDestany successor
falseDestany successor

cf.switch (cf::SwitchOp) 

Switch operation

Syntax:

operation ::= `cf.switch` $flag `:` type($flag) `,` `[` `\n`
              custom<SwitchOpCases>(ref(type($flag)),$defaultDestination,
              $defaultOperands,
              type($defaultOperands),
              $case_values,
              $caseDestinations,
              $caseOperands,
              type($caseOperands))
              `]`
              attr-dict

The cf.switch terminator operation represents a switch on a signless integer value. If the flag matches one of the specified cases, then the corresponding destination is jumped to. If the flag does not match any of the cases, the default destination is jumped to. The count and types of operands must align with the arguments in the corresponding target blocks.

Example:

cf.switch %flag : i32, [
  default: ^bb1(%a : i32),
  42: ^bb1(%b : i32),
  43: ^bb3(%c : i32)
]

Traits: AlwaysSpeculatableImplTrait, AttrSizedOperandSegments, Terminator

Interfaces: BranchOpInterface, ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
case_values::mlir::DenseIntElementsAttrinteger elements attribute
case_operand_segments::mlir::DenseI32ArrayAttri32 dense array attribute

Operands: 

OperandDescription
flaginteger
defaultOperandsvariadic of any type
caseOperandsvariadic of any type

Successors: 

SuccessorDescription
defaultDestinationany successor
caseDestinationsany successor