 [ BLR ] jit-return jit-define
 
 ! ! ! Polymorphic inline caches
+
+! Don't touch r6 here; it's used to pass the tail call site
+! address for tail PICs
 
 ! Load a value from a stack position
 [

    ! if(get(cache) == class)
    6 3 0 LWZ
    6 0 4 CMP
    5 BNE
    ! megamorphic_cache_hits++
    0 4 LOAD32 rc-absolute-ppc-2/2 rt-megamorphic-cache-hits jit-rel
    5 4 0 LWZ

: xt-save ( -- n ) stack-frame 2 bootstrap-cells - ;

[
    0 3 LOAD32 rc-absolute-ppc-2/2 rt-immediate jit-rel
    11 3 profile-count-offset LWZ
    11 11 1 tag-fixnum ADDI
    11 3 profile-count-offset STW
    11 3 word-code-offset LWZ
    11 11 compiled-header-size ADDI
    11 MTCTR
    BCTR
] jit-profiling jit-define

[
    0 3 LOAD32 rc-absolute-ppc-2/2 rt-this jit-rel
    0 MFLR
    1 1 stack-frame SUBI
    3 1 xt-save STW
    stack-frame 3 LI
    3 1 next-save STW
    0 1 lr-save stack-frame + STW
] jit-prolog jit-define

[
    0 3 LOAD32 rc-absolute-ppc-2/2 rt-immediate jit-rel
    3 ds-reg 4 STWU
] jit-push-immediate jit-define

[
    0 3 LOAD32 rc-absolute-ppc-2/2 rt-stack-chain jit-rel
    4 3 0 LWZ
    1 4 0 STW
    0 3 LOAD32 rc-absolute-ppc-2/2 rt-primitive jit-rel
    3 MTCTR
    BCTR
] jit-primitive jit-define

[ 0 BL rc-relative-ppc-3 rt-xt-pic jit-rel ] jit-word-call jit-define

[
    0 6 LOAD32 rc-absolute-ppc-2/2 rt-here jit-rel
    0 B rc-relative-ppc-3 rt-xt-pic-tail jit-rel
] jit-word-jump jit-define

[ 0 B rc-relative-ppc-3 rt-xt jit-rel ] jit-word-special jit-define

[
    3 ds-reg 0 LWZ
