SIGN IN SIGN UP

Introduce add_tensor_like consuming ValueRef (#2835)

Summary:
Pull Request resolved: https://github.com/pytorch/executorch/pull/2835

From SS-JIA:
> we should always make sure to store references produced from `graph.get_val()` only after any calls to `graph.add_*()` (i.e. modifications to the values list) are made. This is because `graph.values_`, being a `std::vector`, will reallocate with more space and move its contents if the current allocation is not sufficient. This means that if you store a reference then call `graph.add_*()` then the underlying resource the reference points to may have been moved.

We can guard against this behavior by passing a `ValueRef` directly, and never having to declare a variable of types `ValueRef&/TensorRef&` in the caller's scope. An example is shown in `Staging.cpp`.

ghstack-source-id: 221721758
exported-using-ghexport
bypass-github-export-checks

Reviewed By: SS-JIA

Differential Revision: D55703483

fbshipit-source-id: 330976df2ba8467dd028d79741eceb17ae8c2d43
J
Jorge Pineda committed
9630f9d45cf8566b56986e0b124d65e83a2b5ce5
Parent: 7f1fa70
Committed by Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com> on 4/9/2024, 4:36:32 PM