1*0b57cec5SDimitry Andric//===-- X86InstrControl.td - Control Flow Instructions -----*- tablegen -*-===// 2*0b57cec5SDimitry Andric// 3*0b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric// 7*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric// 9*0b57cec5SDimitry Andric// This file describes the X86 jump, return, call, and related instructions. 10*0b57cec5SDimitry Andric// 11*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 12*0b57cec5SDimitry Andric 13*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 14*0b57cec5SDimitry Andric// Control Flow Instructions. 15*0b57cec5SDimitry Andric// 16*0b57cec5SDimitry Andric 17*0b57cec5SDimitry Andric// Return instructions. 18*0b57cec5SDimitry Andric// 19*0b57cec5SDimitry Andric// The X86retflag return instructions are variadic because we may add ST0 and 20*0b57cec5SDimitry Andric// ST1 arguments when returning values on the x87 stack. 21*0b57cec5SDimitry Andriclet isTerminator = 1, isReturn = 1, isBarrier = 1, 22*0b57cec5SDimitry Andric hasCtrlDep = 1, FPForm = SpecialFP, SchedRW = [WriteJumpLd] in { 23*0b57cec5SDimitry Andric def RETL : I <0xC3, RawFrm, (outs), (ins variable_ops), 24*0b57cec5SDimitry Andric "ret{l}", []>, OpSize32, Requires<[Not64BitMode]>; 25*0b57cec5SDimitry Andric def RETQ : I <0xC3, RawFrm, (outs), (ins variable_ops), 26*0b57cec5SDimitry Andric "ret{q}", []>, OpSize32, Requires<[In64BitMode]>; 27*0b57cec5SDimitry Andric def RETW : I <0xC3, RawFrm, (outs), (ins), 28*0b57cec5SDimitry Andric "ret{w}", []>, OpSize16; 29*0b57cec5SDimitry Andric def RETIL : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops), 30*0b57cec5SDimitry Andric "ret{l}\t$amt", []>, OpSize32, Requires<[Not64BitMode]>; 31*0b57cec5SDimitry Andric def RETIQ : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops), 32*0b57cec5SDimitry Andric "ret{q}\t$amt", []>, OpSize32, Requires<[In64BitMode]>; 33*0b57cec5SDimitry Andric def RETIW : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt), 34*0b57cec5SDimitry Andric "ret{w}\t$amt", []>, OpSize16; 35*0b57cec5SDimitry Andric def LRETL : I <0xCB, RawFrm, (outs), (ins), 36*0b57cec5SDimitry Andric "{l}ret{l|f}", []>, OpSize32; 37*0b57cec5SDimitry Andric def LRETQ : RI <0xCB, RawFrm, (outs), (ins), 38*0b57cec5SDimitry Andric "{l}ret{|f}q", []>, Requires<[In64BitMode]>; 39*0b57cec5SDimitry Andric def LRETW : I <0xCB, RawFrm, (outs), (ins), 40*0b57cec5SDimitry Andric "{l}ret{w|f}", []>, OpSize16; 41*0b57cec5SDimitry Andric def LRETIL : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt), 42*0b57cec5SDimitry Andric "{l}ret{l|f}\t$amt", []>, OpSize32; 43*0b57cec5SDimitry Andric def LRETIQ : RIi16<0xCA, RawFrm, (outs), (ins i16imm:$amt), 44*0b57cec5SDimitry Andric "{l}ret{|f}q\t$amt", []>, Requires<[In64BitMode]>; 45*0b57cec5SDimitry Andric def LRETIW : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt), 46*0b57cec5SDimitry Andric "{l}ret{w|f}\t$amt", []>, OpSize16; 47*0b57cec5SDimitry Andric 48*0b57cec5SDimitry Andric // The machine return from interrupt instruction, but sometimes we need to 49*0b57cec5SDimitry Andric // perform a post-epilogue stack adjustment. Codegen emits the pseudo form 50*0b57cec5SDimitry Andric // which expands to include an SP adjustment if necessary. 51*0b57cec5SDimitry Andric def IRET16 : I <0xcf, RawFrm, (outs), (ins), "iret{w}", []>, 52*0b57cec5SDimitry Andric OpSize16; 53*0b57cec5SDimitry Andric def IRET32 : I <0xcf, RawFrm, (outs), (ins), "iret{l|d}", []>, OpSize32; 54*0b57cec5SDimitry Andric def IRET64 : RI <0xcf, RawFrm, (outs), (ins), "iretq", []>, Requires<[In64BitMode]>; 55*0b57cec5SDimitry Andric let isCodeGenOnly = 1 in 56*0b57cec5SDimitry Andric def IRET : PseudoI<(outs), (ins i32imm:$adj), [(X86iret timm:$adj)]>; 57*0b57cec5SDimitry Andric def RET : PseudoI<(outs), (ins i32imm:$adj, variable_ops), [(X86retflag timm:$adj)]>; 58*0b57cec5SDimitry Andric} 59*0b57cec5SDimitry Andric 60*0b57cec5SDimitry Andric// Unconditional branches. 61*0b57cec5SDimitry Andriclet isBarrier = 1, isBranch = 1, isTerminator = 1, SchedRW = [WriteJump] in { 62*0b57cec5SDimitry Andric def JMP_1 : Ii8PCRel<0xEB, RawFrm, (outs), (ins brtarget8:$dst), 63*0b57cec5SDimitry Andric "jmp\t$dst", [(br bb:$dst)]>; 64*0b57cec5SDimitry Andric let hasSideEffects = 0, isCodeGenOnly = 1, ForceDisassemble = 1 in { 65*0b57cec5SDimitry Andric def JMP_2 : Ii16PCRel<0xE9, RawFrm, (outs), (ins brtarget16:$dst), 66*0b57cec5SDimitry Andric "jmp\t$dst", []>, OpSize16; 67*0b57cec5SDimitry Andric def JMP_4 : Ii32PCRel<0xE9, RawFrm, (outs), (ins brtarget32:$dst), 68*0b57cec5SDimitry Andric "jmp\t$dst", []>, OpSize32; 69*0b57cec5SDimitry Andric } 70*0b57cec5SDimitry Andric} 71*0b57cec5SDimitry Andric 72*0b57cec5SDimitry Andric// Conditional Branches. 73*0b57cec5SDimitry Andriclet isBranch = 1, isTerminator = 1, Uses = [EFLAGS], SchedRW = [WriteJump], 74*0b57cec5SDimitry Andric isCodeGenOnly = 1, ForceDisassemble = 1 in { 75*0b57cec5SDimitry Andric def JCC_1 : Ii8PCRel <0x70, AddCCFrm, (outs), 76*0b57cec5SDimitry Andric (ins brtarget8:$dst, ccode:$cond), 77*0b57cec5SDimitry Andric "j${cond}\t$dst", 78*0b57cec5SDimitry Andric [(X86brcond bb:$dst, imm:$cond, EFLAGS)]>; 79*0b57cec5SDimitry Andric let hasSideEffects = 0 in { 80*0b57cec5SDimitry Andric def JCC_2 : Ii16PCRel<0x80, AddCCFrm, (outs), 81*0b57cec5SDimitry Andric (ins brtarget16:$dst, ccode:$cond), 82*0b57cec5SDimitry Andric "j${cond}\t$dst", 83*0b57cec5SDimitry Andric []>, OpSize16, TB; 84*0b57cec5SDimitry Andric def JCC_4 : Ii32PCRel<0x80, AddCCFrm, (outs), 85*0b57cec5SDimitry Andric (ins brtarget32:$dst, ccode:$cond), 86*0b57cec5SDimitry Andric "j${cond}\t$dst", 87*0b57cec5SDimitry Andric []>, TB, OpSize32; 88*0b57cec5SDimitry Andric } 89*0b57cec5SDimitry Andric} 90*0b57cec5SDimitry Andric 91*0b57cec5SDimitry Andricdef : InstAlias<"jo\t$dst", (JCC_1 brtarget8:$dst, 0), 0>; 92*0b57cec5SDimitry Andricdef : InstAlias<"jno\t$dst", (JCC_1 brtarget8:$dst, 1), 0>; 93*0b57cec5SDimitry Andricdef : InstAlias<"jb\t$dst", (JCC_1 brtarget8:$dst, 2), 0>; 94*0b57cec5SDimitry Andricdef : InstAlias<"jae\t$dst", (JCC_1 brtarget8:$dst, 3), 0>; 95*0b57cec5SDimitry Andricdef : InstAlias<"je\t$dst", (JCC_1 brtarget8:$dst, 4), 0>; 96*0b57cec5SDimitry Andricdef : InstAlias<"jne\t$dst", (JCC_1 brtarget8:$dst, 5), 0>; 97*0b57cec5SDimitry Andricdef : InstAlias<"jbe\t$dst", (JCC_1 brtarget8:$dst, 6), 0>; 98*0b57cec5SDimitry Andricdef : InstAlias<"ja\t$dst", (JCC_1 brtarget8:$dst, 7), 0>; 99*0b57cec5SDimitry Andricdef : InstAlias<"js\t$dst", (JCC_1 brtarget8:$dst, 8), 0>; 100*0b57cec5SDimitry Andricdef : InstAlias<"jns\t$dst", (JCC_1 brtarget8:$dst, 9), 0>; 101*0b57cec5SDimitry Andricdef : InstAlias<"jp\t$dst", (JCC_1 brtarget8:$dst, 10), 0>; 102*0b57cec5SDimitry Andricdef : InstAlias<"jnp\t$dst", (JCC_1 brtarget8:$dst, 11), 0>; 103*0b57cec5SDimitry Andricdef : InstAlias<"jl\t$dst", (JCC_1 brtarget8:$dst, 12), 0>; 104*0b57cec5SDimitry Andricdef : InstAlias<"jge\t$dst", (JCC_1 brtarget8:$dst, 13), 0>; 105*0b57cec5SDimitry Andricdef : InstAlias<"jle\t$dst", (JCC_1 brtarget8:$dst, 14), 0>; 106*0b57cec5SDimitry Andricdef : InstAlias<"jg\t$dst", (JCC_1 brtarget8:$dst, 15), 0>; 107*0b57cec5SDimitry Andric 108*0b57cec5SDimitry Andric// jcx/jecx/jrcx instructions. 109*0b57cec5SDimitry Andriclet isBranch = 1, isTerminator = 1, hasSideEffects = 0, SchedRW = [WriteJump] in { 110*0b57cec5SDimitry Andric // These are the 32-bit versions of this instruction for the asmparser. In 111*0b57cec5SDimitry Andric // 32-bit mode, the address size prefix is jcxz and the unprefixed version is 112*0b57cec5SDimitry Andric // jecxz. 113*0b57cec5SDimitry Andric let Uses = [CX] in 114*0b57cec5SDimitry Andric def JCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst), 115*0b57cec5SDimitry Andric "jcxz\t$dst", []>, AdSize16, Requires<[Not64BitMode]>; 116*0b57cec5SDimitry Andric let Uses = [ECX] in 117*0b57cec5SDimitry Andric def JECXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst), 118*0b57cec5SDimitry Andric "jecxz\t$dst", []>, AdSize32; 119*0b57cec5SDimitry Andric 120*0b57cec5SDimitry Andric let Uses = [RCX] in 121*0b57cec5SDimitry Andric def JRCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst), 122*0b57cec5SDimitry Andric "jrcxz\t$dst", []>, AdSize64, Requires<[In64BitMode]>; 123*0b57cec5SDimitry Andric} 124*0b57cec5SDimitry Andric 125*0b57cec5SDimitry Andric// Indirect branches 126*0b57cec5SDimitry Andriclet isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in { 127*0b57cec5SDimitry Andric def JMP16r : I<0xFF, MRM4r, (outs), (ins GR16:$dst), "jmp{w}\t{*}$dst", 128*0b57cec5SDimitry Andric [(brind GR16:$dst)]>, Requires<[Not64BitMode]>, 129*0b57cec5SDimitry Andric OpSize16, Sched<[WriteJump]>; 130*0b57cec5SDimitry Andric def JMP16m : I<0xFF, MRM4m, (outs), (ins i16mem:$dst), "jmp{w}\t{*}$dst", 131*0b57cec5SDimitry Andric [(brind (loadi16 addr:$dst))]>, Requires<[Not64BitMode]>, 132*0b57cec5SDimitry Andric OpSize16, Sched<[WriteJumpLd]>; 133*0b57cec5SDimitry Andric 134*0b57cec5SDimitry Andric def JMP32r : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst", 135*0b57cec5SDimitry Andric [(brind GR32:$dst)]>, Requires<[Not64BitMode]>, 136*0b57cec5SDimitry Andric OpSize32, Sched<[WriteJump]>; 137*0b57cec5SDimitry Andric def JMP32m : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst", 138*0b57cec5SDimitry Andric [(brind (loadi32 addr:$dst))]>, Requires<[Not64BitMode]>, 139*0b57cec5SDimitry Andric OpSize32, Sched<[WriteJumpLd]>; 140*0b57cec5SDimitry Andric 141*0b57cec5SDimitry Andric def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst", 142*0b57cec5SDimitry Andric [(brind GR64:$dst)]>, Requires<[In64BitMode]>, 143*0b57cec5SDimitry Andric Sched<[WriteJump]>; 144*0b57cec5SDimitry Andric def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst", 145*0b57cec5SDimitry Andric [(brind (loadi64 addr:$dst))]>, Requires<[In64BitMode]>, 146*0b57cec5SDimitry Andric Sched<[WriteJumpLd]>; 147*0b57cec5SDimitry Andric 148*0b57cec5SDimitry Andric // Non-tracking jumps for IBT, use with caution. 149*0b57cec5SDimitry Andric let isCodeGenOnly = 1 in { 150*0b57cec5SDimitry Andric def JMP16r_NT : I<0xFF, MRM4r, (outs), (ins GR16 : $dst), "jmp{w}\t{*}$dst", 151*0b57cec5SDimitry Andric [(X86NoTrackBrind GR16 : $dst)]>, Requires<[Not64BitMode]>, 152*0b57cec5SDimitry Andric OpSize16, Sched<[WriteJump]>, NOTRACK; 153*0b57cec5SDimitry Andric 154*0b57cec5SDimitry Andric def JMP16m_NT : I<0xFF, MRM4m, (outs), (ins i16mem : $dst), "jmp{w}\t{*}$dst", 155*0b57cec5SDimitry Andric [(X86NoTrackBrind (loadi16 addr : $dst))]>, 156*0b57cec5SDimitry Andric Requires<[Not64BitMode]>, OpSize16, Sched<[WriteJumpLd]>, 157*0b57cec5SDimitry Andric NOTRACK; 158*0b57cec5SDimitry Andric 159*0b57cec5SDimitry Andric def JMP32r_NT : I<0xFF, MRM4r, (outs), (ins GR32 : $dst), "jmp{l}\t{*}$dst", 160*0b57cec5SDimitry Andric [(X86NoTrackBrind GR32 : $dst)]>, Requires<[Not64BitMode]>, 161*0b57cec5SDimitry Andric OpSize32, Sched<[WriteJump]>, NOTRACK; 162*0b57cec5SDimitry Andric def JMP32m_NT : I<0xFF, MRM4m, (outs), (ins i32mem : $dst), "jmp{l}\t{*}$dst", 163*0b57cec5SDimitry Andric [(X86NoTrackBrind (loadi32 addr : $dst))]>, 164*0b57cec5SDimitry Andric Requires<[Not64BitMode]>, OpSize32, Sched<[WriteJumpLd]>, 165*0b57cec5SDimitry Andric NOTRACK; 166*0b57cec5SDimitry Andric 167*0b57cec5SDimitry Andric def JMP64r_NT : I<0xFF, MRM4r, (outs), (ins GR64 : $dst), "jmp{q}\t{*}$dst", 168*0b57cec5SDimitry Andric [(X86NoTrackBrind GR64 : $dst)]>, Requires<[In64BitMode]>, 169*0b57cec5SDimitry Andric Sched<[WriteJump]>, NOTRACK; 170*0b57cec5SDimitry Andric def JMP64m_NT : I<0xFF, MRM4m, (outs), (ins i64mem : $dst), "jmp{q}\t{*}$dst", 171*0b57cec5SDimitry Andric [(X86NoTrackBrind(loadi64 addr : $dst))]>, 172*0b57cec5SDimitry Andric Requires<[In64BitMode]>, Sched<[WriteJumpLd]>, NOTRACK; 173*0b57cec5SDimitry Andric } 174*0b57cec5SDimitry Andric 175*0b57cec5SDimitry Andric let Predicates = [Not64BitMode], AsmVariantName = "att" in { 176*0b57cec5SDimitry Andric def FARJMP16i : Iseg16<0xEA, RawFrmImm16, (outs), 177*0b57cec5SDimitry Andric (ins i16imm:$off, i16imm:$seg), 178*0b57cec5SDimitry Andric "ljmp{w}\t$seg, $off", []>, 179*0b57cec5SDimitry Andric OpSize16, Sched<[WriteJump]>; 180*0b57cec5SDimitry Andric def FARJMP32i : Iseg32<0xEA, RawFrmImm16, (outs), 181*0b57cec5SDimitry Andric (ins i32imm:$off, i16imm:$seg), 182*0b57cec5SDimitry Andric "ljmp{l}\t$seg, $off", []>, 183*0b57cec5SDimitry Andric OpSize32, Sched<[WriteJump]>; 184*0b57cec5SDimitry Andric } 185*0b57cec5SDimitry Andric def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaquemem:$dst), 186*0b57cec5SDimitry Andric "ljmp{q}\t{*}$dst", []>, Sched<[WriteJump]>, Requires<[In64BitMode]>; 187*0b57cec5SDimitry Andric 188*0b57cec5SDimitry Andric let AsmVariantName = "att" in 189*0b57cec5SDimitry Andric def FARJMP16m : I<0xFF, MRM5m, (outs), (ins opaquemem:$dst), 190*0b57cec5SDimitry Andric "ljmp{w}\t{*}$dst", []>, OpSize16, Sched<[WriteJumpLd]>; 191*0b57cec5SDimitry Andric def FARJMP32m : I<0xFF, MRM5m, (outs), (ins opaquemem:$dst), 192*0b57cec5SDimitry Andric "{l}jmp{l}\t{*}$dst", []>, OpSize32, Sched<[WriteJumpLd]>; 193*0b57cec5SDimitry Andric} 194*0b57cec5SDimitry Andric 195*0b57cec5SDimitry Andric// Loop instructions 196*0b57cec5SDimitry Andriclet SchedRW = [WriteJump] in { 197*0b57cec5SDimitry Andricdef LOOP : Ii8PCRel<0xE2, RawFrm, (outs), (ins brtarget8:$dst), "loop\t$dst", []>; 198*0b57cec5SDimitry Andricdef LOOPE : Ii8PCRel<0xE1, RawFrm, (outs), (ins brtarget8:$dst), "loope\t$dst", []>; 199*0b57cec5SDimitry Andricdef LOOPNE : Ii8PCRel<0xE0, RawFrm, (outs), (ins brtarget8:$dst), "loopne\t$dst", []>; 200*0b57cec5SDimitry Andric} 201*0b57cec5SDimitry Andric 202*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 203*0b57cec5SDimitry Andric// Call Instructions... 204*0b57cec5SDimitry Andric// 205*0b57cec5SDimitry Andriclet isCall = 1 in 206*0b57cec5SDimitry Andric // All calls clobber the non-callee saved registers. ESP is marked as 207*0b57cec5SDimitry Andric // a use to prevent stack-pointer assignments that appear immediately 208*0b57cec5SDimitry Andric // before calls from potentially appearing dead. Uses for argument 209*0b57cec5SDimitry Andric // registers are added manually. 210*0b57cec5SDimitry Andric let Uses = [ESP, SSP] in { 211*0b57cec5SDimitry Andric def CALLpcrel32 : Ii32PCRel<0xE8, RawFrm, 212*0b57cec5SDimitry Andric (outs), (ins i32imm_pcrel:$dst), 213*0b57cec5SDimitry Andric "call{l}\t$dst", []>, OpSize32, 214*0b57cec5SDimitry Andric Requires<[Not64BitMode]>, Sched<[WriteJump]>; 215*0b57cec5SDimitry Andric let hasSideEffects = 0 in 216*0b57cec5SDimitry Andric def CALLpcrel16 : Ii16PCRel<0xE8, RawFrm, 217*0b57cec5SDimitry Andric (outs), (ins i16imm_pcrel:$dst), 218*0b57cec5SDimitry Andric "call{w}\t$dst", []>, OpSize16, 219*0b57cec5SDimitry Andric Sched<[WriteJump]>; 220*0b57cec5SDimitry Andric def CALL16r : I<0xFF, MRM2r, (outs), (ins GR16:$dst), 221*0b57cec5SDimitry Andric "call{w}\t{*}$dst", [(X86call GR16:$dst)]>, 222*0b57cec5SDimitry Andric OpSize16, Requires<[Not64BitMode]>, Sched<[WriteJump]>; 223*0b57cec5SDimitry Andric def CALL16m : I<0xFF, MRM2m, (outs), (ins i16mem:$dst), 224*0b57cec5SDimitry Andric "call{w}\t{*}$dst", [(X86call (loadi16 addr:$dst))]>, 225*0b57cec5SDimitry Andric OpSize16, Requires<[Not64BitMode,FavorMemIndirectCall]>, 226*0b57cec5SDimitry Andric Sched<[WriteJumpLd]>; 227*0b57cec5SDimitry Andric def CALL32r : I<0xFF, MRM2r, (outs), (ins GR32:$dst), 228*0b57cec5SDimitry Andric "call{l}\t{*}$dst", [(X86call GR32:$dst)]>, OpSize32, 229*0b57cec5SDimitry Andric Requires<[Not64BitMode,NotUseRetpolineIndirectCalls]>, 230*0b57cec5SDimitry Andric Sched<[WriteJump]>; 231*0b57cec5SDimitry Andric def CALL32m : I<0xFF, MRM2m, (outs), (ins i32mem:$dst), 232*0b57cec5SDimitry Andric "call{l}\t{*}$dst", [(X86call (loadi32 addr:$dst))]>, 233*0b57cec5SDimitry Andric OpSize32, 234*0b57cec5SDimitry Andric Requires<[Not64BitMode,FavorMemIndirectCall, 235*0b57cec5SDimitry Andric NotUseRetpolineIndirectCalls]>, 236*0b57cec5SDimitry Andric Sched<[WriteJumpLd]>; 237*0b57cec5SDimitry Andric 238*0b57cec5SDimitry Andric // Non-tracking calls for IBT, use with caution. 239*0b57cec5SDimitry Andric let isCodeGenOnly = 1 in { 240*0b57cec5SDimitry Andric def CALL16r_NT : I<0xFF, MRM2r, (outs), (ins GR16 : $dst), 241*0b57cec5SDimitry Andric "call{w}\t{*}$dst",[(X86NoTrackCall GR16 : $dst)]>, 242*0b57cec5SDimitry Andric OpSize16, Requires<[Not64BitMode]>, Sched<[WriteJump]>, NOTRACK; 243*0b57cec5SDimitry Andric def CALL16m_NT : I<0xFF, MRM2m, (outs), (ins i16mem : $dst), 244*0b57cec5SDimitry Andric "call{w}\t{*}$dst",[(X86NoTrackCall(loadi16 addr : $dst))]>, 245*0b57cec5SDimitry Andric OpSize16, Requires<[Not64BitMode,FavorMemIndirectCall]>, 246*0b57cec5SDimitry Andric Sched<[WriteJumpLd]>, NOTRACK; 247*0b57cec5SDimitry Andric def CALL32r_NT : I<0xFF, MRM2r, (outs), (ins GR32 : $dst), 248*0b57cec5SDimitry Andric "call{l}\t{*}$dst",[(X86NoTrackCall GR32 : $dst)]>, 249*0b57cec5SDimitry Andric OpSize32, Requires<[Not64BitMode]>, Sched<[WriteJump]>, NOTRACK; 250*0b57cec5SDimitry Andric def CALL32m_NT : I<0xFF, MRM2m, (outs), (ins i32mem : $dst), 251*0b57cec5SDimitry Andric "call{l}\t{*}$dst",[(X86NoTrackCall(loadi32 addr : $dst))]>, 252*0b57cec5SDimitry Andric OpSize32, Requires<[Not64BitMode,FavorMemIndirectCall]>, 253*0b57cec5SDimitry Andric Sched<[WriteJumpLd]>, NOTRACK; 254*0b57cec5SDimitry Andric } 255*0b57cec5SDimitry Andric 256*0b57cec5SDimitry Andric let Predicates = [Not64BitMode], AsmVariantName = "att" in { 257*0b57cec5SDimitry Andric def FARCALL16i : Iseg16<0x9A, RawFrmImm16, (outs), 258*0b57cec5SDimitry Andric (ins i16imm:$off, i16imm:$seg), 259*0b57cec5SDimitry Andric "lcall{w}\t$seg, $off", []>, 260*0b57cec5SDimitry Andric OpSize16, Sched<[WriteJump]>; 261*0b57cec5SDimitry Andric def FARCALL32i : Iseg32<0x9A, RawFrmImm16, (outs), 262*0b57cec5SDimitry Andric (ins i32imm:$off, i16imm:$seg), 263*0b57cec5SDimitry Andric "lcall{l}\t$seg, $off", []>, 264*0b57cec5SDimitry Andric OpSize32, Sched<[WriteJump]>; 265*0b57cec5SDimitry Andric } 266*0b57cec5SDimitry Andric 267*0b57cec5SDimitry Andric def FARCALL16m : I<0xFF, MRM3m, (outs), (ins opaquemem:$dst), 268*0b57cec5SDimitry Andric "lcall{w}\t{*}$dst", []>, OpSize16, Sched<[WriteJumpLd]>; 269*0b57cec5SDimitry Andric def FARCALL32m : I<0xFF, MRM3m, (outs), (ins opaquemem:$dst), 270*0b57cec5SDimitry Andric "{l}call{l}\t{*}$dst", []>, OpSize32, Sched<[WriteJumpLd]>; 271*0b57cec5SDimitry Andric } 272*0b57cec5SDimitry Andric 273*0b57cec5SDimitry Andric 274*0b57cec5SDimitry Andric// Tail call stuff. 275*0b57cec5SDimitry Andriclet isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, 276*0b57cec5SDimitry Andric isCodeGenOnly = 1, SchedRW = [WriteJumpLd] in 277*0b57cec5SDimitry Andric let Uses = [ESP, SSP] in { 278*0b57cec5SDimitry Andric def TCRETURNdi : PseudoI<(outs), 279*0b57cec5SDimitry Andric (ins i32imm_pcrel:$dst, i32imm:$offset), []>, NotMemoryFoldable; 280*0b57cec5SDimitry Andric def TCRETURNri : PseudoI<(outs), 281*0b57cec5SDimitry Andric (ins ptr_rc_tailcall:$dst, i32imm:$offset), []>, NotMemoryFoldable; 282*0b57cec5SDimitry Andric let mayLoad = 1 in 283*0b57cec5SDimitry Andric def TCRETURNmi : PseudoI<(outs), 284*0b57cec5SDimitry Andric (ins i32mem_TC:$dst, i32imm:$offset), []>; 285*0b57cec5SDimitry Andric 286*0b57cec5SDimitry Andric // FIXME: The should be pseudo instructions that are lowered when going to 287*0b57cec5SDimitry Andric // mcinst. 288*0b57cec5SDimitry Andric def TAILJMPd : Ii32PCRel<0xE9, RawFrm, (outs), 289*0b57cec5SDimitry Andric (ins i32imm_pcrel:$dst), "jmp\t$dst", []>; 290*0b57cec5SDimitry Andric 291*0b57cec5SDimitry Andric def TAILJMPr : I<0xFF, MRM4r, (outs), (ins ptr_rc_tailcall:$dst), 292*0b57cec5SDimitry Andric "", []>; // FIXME: Remove encoding when JIT is dead. 293*0b57cec5SDimitry Andric let mayLoad = 1 in 294*0b57cec5SDimitry Andric def TAILJMPm : I<0xFF, MRM4m, (outs), (ins i32mem_TC:$dst), 295*0b57cec5SDimitry Andric "jmp{l}\t{*}$dst", []>; 296*0b57cec5SDimitry Andric} 297*0b57cec5SDimitry Andric 298*0b57cec5SDimitry Andric// Conditional tail calls are similar to the above, but they are branches 299*0b57cec5SDimitry Andric// rather than barriers, and they use EFLAGS. 300*0b57cec5SDimitry Andriclet isCall = 1, isTerminator = 1, isReturn = 1, isBranch = 1, 301*0b57cec5SDimitry Andric isCodeGenOnly = 1, SchedRW = [WriteJumpLd] in 302*0b57cec5SDimitry Andric let Uses = [ESP, EFLAGS, SSP] in { 303*0b57cec5SDimitry Andric def TCRETURNdicc : PseudoI<(outs), 304*0b57cec5SDimitry Andric (ins i32imm_pcrel:$dst, i32imm:$offset, i32imm:$cond), []>; 305*0b57cec5SDimitry Andric 306*0b57cec5SDimitry Andric // This gets substituted to a conditional jump instruction in MC lowering. 307*0b57cec5SDimitry Andric def TAILJMPd_CC : Ii32PCRel<0x80, RawFrm, (outs), 308*0b57cec5SDimitry Andric (ins i32imm_pcrel:$dst, i32imm:$cond), "", []>; 309*0b57cec5SDimitry Andric} 310*0b57cec5SDimitry Andric 311*0b57cec5SDimitry Andric 312*0b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 313*0b57cec5SDimitry Andric// Call Instructions... 314*0b57cec5SDimitry Andric// 315*0b57cec5SDimitry Andric 316*0b57cec5SDimitry Andric// RSP is marked as a use to prevent stack-pointer assignments that appear 317*0b57cec5SDimitry Andric// immediately before calls from potentially appearing dead. Uses for argument 318*0b57cec5SDimitry Andric// registers are added manually. 319*0b57cec5SDimitry Andriclet isCall = 1, Uses = [RSP, SSP], SchedRW = [WriteJump] in { 320*0b57cec5SDimitry Andric // NOTE: this pattern doesn't match "X86call imm", because we do not know 321*0b57cec5SDimitry Andric // that the offset between an arbitrary immediate and the call will fit in 322*0b57cec5SDimitry Andric // the 32-bit pcrel field that we have. 323*0b57cec5SDimitry Andric def CALL64pcrel32 : Ii32PCRel<0xE8, RawFrm, 324*0b57cec5SDimitry Andric (outs), (ins i64i32imm_pcrel:$dst), 325*0b57cec5SDimitry Andric "call{q}\t$dst", []>, OpSize32, 326*0b57cec5SDimitry Andric Requires<[In64BitMode]>; 327*0b57cec5SDimitry Andric def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst), 328*0b57cec5SDimitry Andric "call{q}\t{*}$dst", [(X86call GR64:$dst)]>, 329*0b57cec5SDimitry Andric Requires<[In64BitMode,NotUseRetpolineIndirectCalls]>; 330*0b57cec5SDimitry Andric def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst), 331*0b57cec5SDimitry Andric "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))]>, 332*0b57cec5SDimitry Andric Requires<[In64BitMode,FavorMemIndirectCall, 333*0b57cec5SDimitry Andric NotUseRetpolineIndirectCalls]>; 334*0b57cec5SDimitry Andric 335*0b57cec5SDimitry Andric // Non-tracking calls for IBT, use with caution. 336*0b57cec5SDimitry Andric let isCodeGenOnly = 1 in { 337*0b57cec5SDimitry Andric def CALL64r_NT : I<0xFF, MRM2r, (outs), (ins GR64 : $dst), 338*0b57cec5SDimitry Andric "call{q}\t{*}$dst",[(X86NoTrackCall GR64 : $dst)]>, 339*0b57cec5SDimitry Andric Requires<[In64BitMode]>, NOTRACK; 340*0b57cec5SDimitry Andric def CALL64m_NT : I<0xFF, MRM2m, (outs), (ins i64mem : $dst), 341*0b57cec5SDimitry Andric "call{q}\t{*}$dst", 342*0b57cec5SDimitry Andric [(X86NoTrackCall(loadi64 addr : $dst))]>, 343*0b57cec5SDimitry Andric Requires<[In64BitMode,FavorMemIndirectCall]>, NOTRACK; 344*0b57cec5SDimitry Andric } 345*0b57cec5SDimitry Andric 346*0b57cec5SDimitry Andric def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaquemem:$dst), 347*0b57cec5SDimitry Andric "lcall{q}\t{*}$dst", []>; 348*0b57cec5SDimitry Andric} 349*0b57cec5SDimitry Andric 350*0b57cec5SDimitry Andriclet isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1, 351*0b57cec5SDimitry Andric isCodeGenOnly = 1, Uses = [RSP, SSP], SchedRW = [WriteJump] in { 352*0b57cec5SDimitry Andric def TCRETURNdi64 : PseudoI<(outs), 353*0b57cec5SDimitry Andric (ins i64i32imm_pcrel:$dst, i32imm:$offset), 354*0b57cec5SDimitry Andric []>; 355*0b57cec5SDimitry Andric def TCRETURNri64 : PseudoI<(outs), 356*0b57cec5SDimitry Andric (ins ptr_rc_tailcall:$dst, i32imm:$offset), []>, NotMemoryFoldable; 357*0b57cec5SDimitry Andric let mayLoad = 1 in 358*0b57cec5SDimitry Andric def TCRETURNmi64 : PseudoI<(outs), 359*0b57cec5SDimitry Andric (ins i64mem_TC:$dst, i32imm:$offset), []>, NotMemoryFoldable; 360*0b57cec5SDimitry Andric 361*0b57cec5SDimitry Andric def TAILJMPd64 : Ii32PCRel<0xE9, RawFrm, (outs), (ins i64i32imm_pcrel:$dst), 362*0b57cec5SDimitry Andric "jmp\t$dst", []>; 363*0b57cec5SDimitry Andric 364*0b57cec5SDimitry Andric def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins ptr_rc_tailcall:$dst), 365*0b57cec5SDimitry Andric "jmp{q}\t{*}$dst", []>; 366*0b57cec5SDimitry Andric 367*0b57cec5SDimitry Andric let mayLoad = 1 in 368*0b57cec5SDimitry Andric def TAILJMPm64 : I<0xFF, MRM4m, (outs), (ins i64mem_TC:$dst), 369*0b57cec5SDimitry Andric "jmp{q}\t{*}$dst", []>; 370*0b57cec5SDimitry Andric 371*0b57cec5SDimitry Andric // Win64 wants indirect jumps leaving the function to have a REX_W prefix. 372*0b57cec5SDimitry Andric let hasREX_WPrefix = 1 in { 373*0b57cec5SDimitry Andric def TAILJMPr64_REX : I<0xFF, MRM4r, (outs), (ins ptr_rc_tailcall:$dst), 374*0b57cec5SDimitry Andric "rex64 jmp{q}\t{*}$dst", []>; 375*0b57cec5SDimitry Andric 376*0b57cec5SDimitry Andric let mayLoad = 1 in 377*0b57cec5SDimitry Andric def TAILJMPm64_REX : I<0xFF, MRM4m, (outs), (ins i64mem_TC:$dst), 378*0b57cec5SDimitry Andric "rex64 jmp{q}\t{*}$dst", []>; 379*0b57cec5SDimitry Andric } 380*0b57cec5SDimitry Andric} 381*0b57cec5SDimitry Andric 382*0b57cec5SDimitry Andriclet isPseudo = 1, isCall = 1, isCodeGenOnly = 1, 383*0b57cec5SDimitry Andric Uses = [RSP, SSP], 384*0b57cec5SDimitry Andric usesCustomInserter = 1, 385*0b57cec5SDimitry Andric SchedRW = [WriteJump] in { 386*0b57cec5SDimitry Andric def RETPOLINE_CALL32 : 387*0b57cec5SDimitry Andric PseudoI<(outs), (ins GR32:$dst), [(X86call GR32:$dst)]>, 388*0b57cec5SDimitry Andric Requires<[Not64BitMode,UseRetpolineIndirectCalls]>; 389*0b57cec5SDimitry Andric 390*0b57cec5SDimitry Andric def RETPOLINE_CALL64 : 391*0b57cec5SDimitry Andric PseudoI<(outs), (ins GR64:$dst), [(X86call GR64:$dst)]>, 392*0b57cec5SDimitry Andric Requires<[In64BitMode,UseRetpolineIndirectCalls]>; 393*0b57cec5SDimitry Andric 394*0b57cec5SDimitry Andric // Retpoline variant of indirect tail calls. 395*0b57cec5SDimitry Andric let isTerminator = 1, isReturn = 1, isBarrier = 1 in { 396*0b57cec5SDimitry Andric def RETPOLINE_TCRETURN64 : 397*0b57cec5SDimitry Andric PseudoI<(outs), (ins GR64:$dst, i32imm:$offset), []>; 398*0b57cec5SDimitry Andric def RETPOLINE_TCRETURN32 : 399*0b57cec5SDimitry Andric PseudoI<(outs), (ins GR32:$dst, i32imm:$offset), []>; 400*0b57cec5SDimitry Andric } 401*0b57cec5SDimitry Andric} 402*0b57cec5SDimitry Andric 403*0b57cec5SDimitry Andric// Conditional tail calls are similar to the above, but they are branches 404*0b57cec5SDimitry Andric// rather than barriers, and they use EFLAGS. 405*0b57cec5SDimitry Andriclet isCall = 1, isTerminator = 1, isReturn = 1, isBranch = 1, 406*0b57cec5SDimitry Andric isCodeGenOnly = 1, SchedRW = [WriteJumpLd] in 407*0b57cec5SDimitry Andric let Uses = [RSP, EFLAGS, SSP] in { 408*0b57cec5SDimitry Andric def TCRETURNdi64cc : PseudoI<(outs), 409*0b57cec5SDimitry Andric (ins i64i32imm_pcrel:$dst, i32imm:$offset, 410*0b57cec5SDimitry Andric i32imm:$cond), []>; 411*0b57cec5SDimitry Andric 412*0b57cec5SDimitry Andric // This gets substituted to a conditional jump instruction in MC lowering. 413*0b57cec5SDimitry Andric def TAILJMPd64_CC : Ii32PCRel<0x80, RawFrm, (outs), 414*0b57cec5SDimitry Andric (ins i64i32imm_pcrel:$dst, i32imm:$cond), "", []>; 415*0b57cec5SDimitry Andric} 416