ARM64: Switch Expansion Using Jump Table
authorKyungwoo Lee <kyulee@microsoft.com>
Thu, 12 May 2016 04:48:40 +0000 (21:48 -0700)
committerKyungwoo Lee <kyulee@microsoft.com>
Thu, 12 May 2016 17:23:07 +0000 (10:23 -0700)
commita0c6144d406f29d70005fbf7ebd8ac3bdfe3cc0d
tree11055a2e25c1473a6662520a41ae11b7e8e815a9
parent3e986665bf96e9acf7f07c3efd171cf98c9d0ca2
ARM64: Switch Expansion Using Jump Table

Fixes #3332
To validate various addressing in #4896, I just enable this.
Previously, we only allow a load operation to JIT data (`ldr` or
`IF_LARGELDC`).
For switch expansion, jump table is also recorded into JIT data.
In this case, we only get the address of jump table head, and
load the right entry after computing offset. So, basically `adr` or
`IF_LARGEADR` is used to not only load label within code but also refer to
the location of JIT data.
The typical code sequence for switch expansion is like this:

```
  adr     x8, [@RWD00]          // load address of jump table head
  ldr     w8, [x8, x0, LSL #2]  // load jump entry from table addr + x0 * 4
  adr     x9, [G_M56320_IG02]   // load address of current baisc block
  add     x8, x8, x9            // Add them to compute the final target
  br      x8                    // Indirectly jump to the target
```
src/jit/codegenarm64.cpp
src/jit/emit.cpp
src/jit/emitarm64.cpp
src/jit/emitarm64.h
src/jit/lower.cpp