tensorflow/compiler/mlir/xla/transforms/legalize_tf_communication.cc
// Rewrites a `mhlo.if` op to receive and forward a `mhlo.token`. As If op does
// not have any operands other than the predicate, hence we implicitly capture
// the parent token. Also we use the same implicit token for use in the If op's
// regions.
Rewrites a `mhlo.if` op to receive and forward a `mhlo.token`. As If op does
not have any operands other than the predicate, hence we implicitly capture
the parent token. Also we use the same implicit token for use in the If op's
regions.
Rewrites a ` mhlo . if ` op to receive and forward a ` mhlo . token ` . As If op does not have any operands other than the predicate hence we implicitly capture the parent token . Also we use the same implicit token for use in the If op ' s regions .
void RewriteRegionIfOp(OpBuilder& builder, IfOp region_if,
                       SmallVectorImpl<OpVisitorState>& ops_to_visit,
                       Value token) {
  llvm::SmallDenseMap<Value, Value> rewritten_operands;
  auto new_result_types =
      GetTypeWithToken(builder, llvm::to_vector(region_if.getResultTypes()),
                       true);
  auto new_if = builder.create<IfOp>(region_if.getLoc(), new_result_types,
                                     region_if.pred());
  new_if.true_branch().takeBody(region_if.true_branch());
  new_if.false_branch().takeBody(region_if.false_branch());
  SmallVector<Value> old_if_results = region_if.getResults();
  SmallVector<Value> new_if_results = new_if.getResults();
  ReplaceWithTupleResult(builder, old_if_results, new_if_results,
                         true);
  region_if.erase();
  ops_to_visit.push_back({0, token, new_if});
}
void RewriteRegionIfOp ( OpBuilder & builder , IfOp region_if , SmallVectorImpl < OpVisitorState > & ops_to_visit , Value token ) { llvm :: SmallDenseMap < Value , Value > rewritten_operands ; auto new_result_types = GetTypeWithToken ( builder , llvm :: to_vector ( region_if . getResultTypes ( ) ) , true ) ; auto new_if = builder . create < IfOp > ( region_if . getLoc ( ) , new_result_types , region_if . pred ( ) ) ; new_if . true_branch ( ) . takeBody ( region_if . true_branch ( ) ) ; new_if . false_branch ( ) . takeBody ( region_if . false_branch ( ) ) ; SmallVector < Value > old_if_results = region_if . getResults ( ) ; SmallVector < Value > new_if_results = new_if . getResults ( ) ; ReplaceWithTupleResult ( builder , old_if_results , new_if_results , true ) ; region_if . erase ( ) ; ops_to_visit . push_back ( { 0 , token , new_if } ) ; }
Rewrites a `mhlo.if` op to receive and forward a `mhlo.token`.
Rewrites a ` mhlo . if ` op to receive and forward a ` mhlo . token ` .
/*flatten_tuple=*/ // Create new `mhlo.if` op with extra token operands and result. // Move all regions from the old `mhlo.if` op to its replacement. // Forward result from old `mhlo.if` with replacement. /*flatten_tuple=*/ // auto new_token = new_if_results[new_if_results.size() - 1]; // Next op to visit. The replacement is visited but at its first region. // The new region use the same implicit token used by the If op. /*region_idx=*/