tensorflow/compiler/mlir/tensorflow/analysis/side_effect_analysis.cc
// If the return value for `func_op` at `return_index` is a pass-through of an
// argument of this function, returns the argument index; otherwise, returns -1.
If the return value for `func_op` at `return_index` is a pass-through of an
argument of this function, returns the argument index; otherwise, returns -1.
If the return value for ` func_op ` at ` return_index ` is a pass - through of an argument of this function returns the argument index ; otherwise returns - 1 .
int64_t FindPassthroughArgumentForReturnValue(int64_t return_index,
                                              FuncOp func_op) {
  auto value =
      func_op.getBody().front().getTerminator()->getOperand(return_index);
  assert(mlir::getElementTypeOrSelf(value.getType()).isa<TF::ResourceType>());
  int64_t arg_index = -1;
  auto try_parse_arg_index = [&arg_index](Value v) {
    auto resource_arg = v.dyn_cast<BlockArgument>();
    if (resource_arg) arg_index = resource_arg.getArgNumber();
    return arg_index;
  };
  while (try_parse_arg_index(value) == -1) {
    auto op = value.getDefiningOp();
    assert(op);
    int64_t res_num = value.cast<OpResult>().getResultNumber();
    if (auto graph = llvm::dyn_cast<tf_executor::GraphOp>(op)) {
      value = graph.GetFetch().getOperand(res_num);
    } else if (auto island = llvm::dyn_cast<tf_executor::IslandOp>(op)) {
      value = island.GetYield().getOperand(res_num);
    } else if (llvm::isa<TF::IdentityNOp>(op) ||
               llvm::isa<TF::IdentityOp>(op)) {
      value = op->getOperand(res_num);
    } else {
      return -1;
    }
  }
  return arg_index;
}
int64_t FindPassthroughArgumentForReturnValue ( int64_t return_index , FuncOp func_op ) { auto value = func_op . getBody ( ) . front ( ) . getTerminator ( ) -> getOperand ( return_index ) ; assert ( mlir :: getElementTypeOrSelf ( value . getType ( ) ) . isa < TF :: ResourceType > ( ) ) ; int64_t arg_index = -1 ; auto try_parse_arg_index = [ & arg_index ] ( Value v ) { auto resource_arg = v . dyn_cast < BlockArgument > ( ) ; if ( resource_arg ) arg_index = resource_arg . getArgNumber ( ) ; return arg_index ; } ; while ( try_parse_arg_index ( value ) == -1 ) { auto op = value . getDefiningOp ( ) ; assert ( op ) ; int64_t res_num = value . cast < OpResult > ( ) . getResultNumber ( ) ; if ( auto graph = llvm :: dyn_cast < tf_executor :: GraphOp > ( op ) ) { value = graph . GetFetch ( ) . getOperand ( res_num ) ; } else if ( auto island = llvm :: dyn_cast < tf_executor :: IslandOp > ( op ) ) { value = island . GetYield ( ) . getOperand ( res_num ) ; } else if ( llvm :: isa < TF :: IdentityNOp > ( op ) || llvm :: isa < TF :: IdentityOp > ( op ) ) { value = op -> getOperand ( res_num ) ; } else { return -1 ; } } return arg_index ; }
If the return value for `func_op` at `return_index` is a pass-through of an
argument of this function, returns the argument index; otherwise, returns -1.
If the return value for ` func_op ` at ` return_index ` is a pass - through of an argument of this function returns the argument index ; otherwise returns - 1 .