Hi,<br><br>Can anyone tell me, is it possible to express in LLVM IR:<br>  - that, for a specific function, register allocator can use only limited set of registers? (specifically, cannot touch any registers that might contain parameters)<br>
  - that stack can't be touched? (or at least must balance on exit from thunk)<br>  - jump, not call, to another function leaving any received parameters unchanged in registers and on stack?<br><br>Thanks,<br>-- James Williams<br>
<br>Background:<br><br>I'm looking for some advice on implementing thunks required by my language's interface call mechanism. This is a fairly conventional arrangement where method selectors in interfaces are hashed to determine their index within a vtable and hash collisions are disambiguated at runtime by a thunk, which determines which method to call from a selector id passed as the first method parameter.<br>
<br>I'm currently using a single thunk (written in assembly) for all collisions that walks a table to determine what method to call. This works but it's inefficient and requires the a hand written thunk for each supported target.<br>
<br>I'd like to instead generate IR for a specific thunk for each vtable collisoin that does a binary search of possible selectors because this will avoid some pointer dereferences and an additional indirect call.<br>
<br>The problem is that a thunk may need to decide between methods with different signatures without disturbing parameters in registers and on the stack and then jump to, rather than call, another function:<br><br>interface X:<br>
  method A(a, b)<br><br>interface Y:<br>  method B(c, d, e)<br><br>class Z implements X, y:<br>  method A(a, b) ...<br>  method B(c, d, e) ...<br><br>X.A + Y.B happen to hash to same vtable index, say -3<br><br>This would require a thunk something like:<br>
<br>vtable[-3] = <br>  thunk_Z_AorB(selector_id, ...)<br>    // binary search for matching selector id:<br>    if selector_id <= selector_Z_A then<br>      Z.A(selector_id, ...)<br>    else<br>      Z.B(selector_id, ...)<br>
    fi<br><br>which would ideally would compile on x64 to something like:<br><br>thunk_Z_AorB:<br>  cmp $selector_Z_A, %rdi<br>  jle Z.A<br>  jmp Z.B <br><br><br>