tensorflow/compiler/mlir/xla/transforms/legalize_tf_communication.cc
// Rewrites an `mhlo.if` op or its region. If `region_idx` is not set, the op
// operands and results are rewritten. If `region_idx` is set, region
// `region_idx` is rewritten to take in and return an additional token. Returns
// true if the op or its region was rewritten.
Rewrites an `mhlo.if` op or its region. If `region_idx` is not set, the op
operands and results are rewritten. If `region_idx` is set, region
`region_idx` is rewritten to take in and return an additional token. Returns
true if the op or its region was rewritten.
Rewrites an ` mhlo . if ` op or its region . If ` region_idx ` is not set the op operands and results are rewritten . If ` region_idx ` is set region ` region_idx ` is rewritten to take in and return an additional token . Returns true if the op or its region was rewritten .
bool ProcessRegionIfOp(OpBuilder& builder, IfOp region_if,
                       Optional<unsigned> region_idx,
                       SmallVectorImpl<OpVisitorState>& ops_to_visit,
                       const llvm::SmallPtrSetImpl<Block*>& control_flow_blocks,
                       Value token) {
  builder.setInsertionPoint(region_if);
  if (!region_idx) {
    RewriteRegionIfOp(builder, region_if, ops_to_visit, token);
    return true;
  }
  if (*region_idx < region_if.getNumRegions()) {
    RewriteControlFlowOpRegion(builder, region_if, *region_idx,
                               {token.getType()}, ops_to_visit,
                               control_flow_blocks, token);
    ReplaceBlockArgumentsWithImplicitOperands(region_if.getOperation(),
                                              *region_idx, token);
    auto next_visitor_state = ops_to_visit.back();
    next_visitor_state.token = token;
    ops_to_visit.pop_back();
    ops_to_visit.push_back(next_visitor_state);
    return true;
  }
  return false;
}
bool ProcessRegionIfOp ( OpBuilder & builder , IfOp region_if , Optional < unsigned > region_idx , SmallVectorImpl < OpVisitorState > & ops_to_visit , const llvm :: SmallPtrSetImpl < Block * > & control_flow_blocks , Value token ) { builder . setInsertionPoint ( region_if ) ; if ( ! region_idx ) { RewriteRegionIfOp ( builder , region_if , ops_to_visit , token ) ; return true ; } if ( * region_idx < region_if . getNumRegions ( ) ) { RewriteControlFlowOpRegion ( builder , region_if , * region_idx , { token . getType ( ) } , ops_to_visit , control_flow_blocks , token ) ; ReplaceBlockArgumentsWithImplicitOperands ( region_if . getOperation ( ) , * region_idx , token ) ; auto next_visitor_state = ops_to_visit . back ( ) ; next_visitor_state . token = token ; ops_to_visit . pop_back ( ) ; ops_to_visit . push_back ( next_visitor_state ) ; return true ; } return false ; }
Rewrites an `mhlo.if` op or its region.
Rewrites an ` mhlo . if ` op or its region .
// For the region-blocks of If op, we create a dummy token argument. Later // we replace that block-argument's uses with the same (implicitly captured) // token 'token', used for If op, and erase the argument. // Note that 'RewriteControlFlowOpRegion' sets the token, used for the first // operation of region_idx'th region, to the dummy block-argument. As we // erase that argument, we also need to make sure that the token used for // the next operation is set to 'token'.