gallivm: more preparations for ORC jit support
This series of patches just refactors a bunch of things in the gallivm code to better prepare to support orc jit.
It splits some code out, and refactors others so it can be reused from the ORC jit support code.