[JIT][to_backend] Move code that is not related to the user-facing API out of `jit/backends/backend.h` (#38567)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/38431
**Test Plan**
```
python test/test_jit.py TestBackends
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/38567
Test Plan:
```
python test/test_jit.py TestBackends
```
Differential Revision: D21598950
Pulled By: jansel
fbshipit-source-id: 794436cf351f28ded9c3e13fbcf173aee6c33d42