tensorflow/compiler/mlir/quantization/tensorflow/utils/lift_as_function_call_utils.cc
// Finds ops in the paths from arguments to results. The ops is listed in an
// order that the former ops shouldn't have any dependencies on the later ones.
Finds ops in the paths from arguments to results. The ops is listed in an
order that the former ops shouldn't have any dependencies on the later ones.
Finds ops in the paths from arguments to results . The ops is listed in an order that the former ops shouldn ' t have any dependencies on the later ones .
llvm::SmallVector<Operation *> FindOpsFromArgumentsToResults(
    const llvm::SmallVector<Value> &arguments,
    const llvm::SmallVector<Value> &results) {
  std::queue<Value> value_queue;
  for (Value result : results) {
    value_queue.push(result);
  }
  absl::flat_hash_set<mlir::detail::ValueImpl *> argument_set;
  for (Value argument : arguments) {
    argument_set.insert(argument.getImpl());
  }
  std::stack<Operation *> op_stack;
  while (!value_queue.empty()) {
    Value current_value = value_queue.front();
    value_queue.pop();
    Operation *defining_node = current_value.getDefiningOp();
    if (defining_node == nullptr) continue;
    op_stack.push(defining_node);
    for (const auto &arg : defining_node->getOperands()) {
      if (!argument_set.contains(arg.getImpl())) {
        value_queue.push(arg);
      }
    }
  }
  llvm::SmallVector<Operation *> sorted_ops;
  absl::flat_hash_set<Operation *> unique_ops;
  while (!op_stack.empty()) {
    Operation *current_op = op_stack.top();
    op_stack.pop();
    if (unique_ops.contains(current_op)) continue;
    sorted_ops.push_back(current_op);
    unique_ops.insert(current_op);
  }
  return sorted_ops;
}
llvm :: SmallVector < Operation * > FindOpsFromArgumentsToResults ( const llvm :: SmallVector < Value > & arguments , const llvm :: SmallVector < Value > & results ) { std :: queue < Value > value_queue ; for ( Value result : results ) { value_queue . push ( result ) ; } absl :: flat_hash_set < mlir :: detail :: ValueImpl * > argument_set ; for ( Value argument : arguments ) { argument_set . insert ( argument . getImpl ( ) ) ; } std :: stack < Operation * > op_stack ; while ( ! value_queue . empty ( ) ) { Value current_value = value_queue . front ( ) ; value_queue . pop ( ) ; Operation * defining_node = current_value . getDefiningOp ( ) ; if ( defining_node == nullptr ) continue ; op_stack . push ( defining_node ) ; for ( const auto & arg : defining_node -> getOperands ( ) ) { if ( ! argument_set . contains ( arg . getImpl ( ) ) ) { value_queue . push ( arg ) ; } } } llvm :: SmallVector < Operation * > sorted_ops ; absl :: flat_hash_set < Operation * > unique_ops ; while ( ! op_stack . empty ( ) ) { Operation * current_op = op_stack . top ( ) ; op_stack . pop ( ) ; if ( unique_ops . contains ( current_op ) ) continue ; sorted_ops . push_back ( current_op ) ; unique_ops . insert ( current_op ) ; } return sorted_ops ; }
Finds ops in the paths from arguments to results.
Finds ops in the paths from arguments to results .
// Searching for ops from results to arguments. Duplicate ops in the op stack // are intentional in order to make sure the op on the top of the stack // doesn't depends on any ops below it. // Remove duplicate ops from the op stack.