[PyTorch] Reapply D25687465: Devirtualize TensorImpl::dim() with macro (#50290)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/50290
This was reverted because it landed after D24772023 (https://github.com/pytorch/pytorch/commit/b73c01859863892476b65aef071064633a97ed5d), which
changed the implementation of `dim()`, without rebasing on top of it,
and thus broke the build.
ghstack-source-id: 119608505
Test Plan: CI
Reviewed By: ezyang
Differential Revision: D25852810
fbshipit-source-id: 9735a095d539a3a6dc530b7b3bb758d4872d05a8