[XLA:GPU] Migrate while loop extraction to utility function.
[XLA:GPU] Migrate while loop extraction to utility function.

FUTURE_COPYBARA_INTEGRATE_REVIEW=https://github.com/openxla/xla/pull/12463 from ROCm:ci_fix_build_break_20240514 fd95e342a4e8de6c8348df3576510584a0020150
