xref: /freebsd/contrib/llvm-project/llvm/lib/Target/X86/X86InstrControl.td (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
10b57cec5SDimitry Andric//===-- X86InstrControl.td - Control Flow Instructions -----*- tablegen -*-===//
20b57cec5SDimitry Andric//
30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric//
70b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric//
90b57cec5SDimitry Andric// This file describes the X86 jump, return, call, and related instructions.
100b57cec5SDimitry Andric//
110b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
140b57cec5SDimitry Andric//  Control Flow Instructions.
150b57cec5SDimitry Andric//
160b57cec5SDimitry Andric
170b57cec5SDimitry Andric// Return instructions.
180b57cec5SDimitry Andric//
190b57cec5SDimitry Andric// The X86retflag return instructions are variadic because we may add ST0 and
200b57cec5SDimitry Andric// ST1 arguments when returning values on the x87 stack.
210b57cec5SDimitry Andriclet isTerminator = 1, isReturn = 1, isBarrier = 1,
220b57cec5SDimitry Andric    hasCtrlDep = 1, FPForm = SpecialFP, SchedRW = [WriteJumpLd] in {
230b57cec5SDimitry Andric  def RETL   : I   <0xC3, RawFrm, (outs), (ins variable_ops),
240b57cec5SDimitry Andric                    "ret{l}", []>, OpSize32, Requires<[Not64BitMode]>;
250b57cec5SDimitry Andric  def RETQ   : I   <0xC3, RawFrm, (outs), (ins variable_ops),
260b57cec5SDimitry Andric                    "ret{q}", []>, OpSize32, Requires<[In64BitMode]>;
270b57cec5SDimitry Andric  def RETW   : I   <0xC3, RawFrm, (outs), (ins),
280b57cec5SDimitry Andric                    "ret{w}", []>, OpSize16;
290b57cec5SDimitry Andric  def RETIL  : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
300b57cec5SDimitry Andric                    "ret{l}\t$amt", []>, OpSize32, Requires<[Not64BitMode]>;
310b57cec5SDimitry Andric  def RETIQ  : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
320b57cec5SDimitry Andric                    "ret{q}\t$amt", []>, OpSize32, Requires<[In64BitMode]>;
330b57cec5SDimitry Andric  def RETIW  : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt),
340b57cec5SDimitry Andric                    "ret{w}\t$amt", []>, OpSize16;
350b57cec5SDimitry Andric  def LRETL  : I   <0xCB, RawFrm, (outs), (ins),
360b57cec5SDimitry Andric                    "{l}ret{l|f}", []>, OpSize32;
370b57cec5SDimitry Andric  def LRETQ  : RI  <0xCB, RawFrm, (outs), (ins),
380b57cec5SDimitry Andric                    "{l}ret{|f}q", []>, Requires<[In64BitMode]>;
390b57cec5SDimitry Andric  def LRETW  : I   <0xCB, RawFrm, (outs), (ins),
400b57cec5SDimitry Andric                    "{l}ret{w|f}", []>, OpSize16;
410b57cec5SDimitry Andric  def LRETIL : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
420b57cec5SDimitry Andric                    "{l}ret{l|f}\t$amt", []>, OpSize32;
430b57cec5SDimitry Andric  def LRETIQ : RIi16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
440b57cec5SDimitry Andric                    "{l}ret{|f}q\t$amt", []>, Requires<[In64BitMode]>;
450b57cec5SDimitry Andric  def LRETIW : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
460b57cec5SDimitry Andric                    "{l}ret{w|f}\t$amt", []>, OpSize16;
470b57cec5SDimitry Andric
480b57cec5SDimitry Andric  // The machine return from interrupt instruction, but sometimes we need to
490b57cec5SDimitry Andric  // perform a post-epilogue stack adjustment. Codegen emits the pseudo form
500b57cec5SDimitry Andric  // which expands to include an SP adjustment if necessary.
510b57cec5SDimitry Andric  def IRET16 : I   <0xcf, RawFrm, (outs), (ins), "iret{w}", []>,
520b57cec5SDimitry Andric               OpSize16;
530b57cec5SDimitry Andric  def IRET32 : I   <0xcf, RawFrm, (outs), (ins), "iret{l|d}", []>, OpSize32;
540b57cec5SDimitry Andric  def IRET64 : RI  <0xcf, RawFrm, (outs), (ins), "iretq", []>, Requires<[In64BitMode]>;
550b57cec5SDimitry Andric  let isCodeGenOnly = 1 in
560b57cec5SDimitry Andric  def IRET : PseudoI<(outs), (ins i32imm:$adj), [(X86iret timm:$adj)]>;
570b57cec5SDimitry Andric  def RET  : PseudoI<(outs), (ins i32imm:$adj, variable_ops), [(X86retflag timm:$adj)]>;
580b57cec5SDimitry Andric}
590b57cec5SDimitry Andric
600b57cec5SDimitry Andric// Unconditional branches.
610b57cec5SDimitry Andriclet isBarrier = 1, isBranch = 1, isTerminator = 1, SchedRW = [WriteJump] in {
620b57cec5SDimitry Andric  def JMP_1 : Ii8PCRel<0xEB, RawFrm, (outs), (ins brtarget8:$dst),
630b57cec5SDimitry Andric                       "jmp\t$dst", [(br bb:$dst)]>;
640b57cec5SDimitry Andric  let hasSideEffects = 0, isCodeGenOnly = 1, ForceDisassemble = 1 in {
650b57cec5SDimitry Andric    def JMP_2 : Ii16PCRel<0xE9, RawFrm, (outs), (ins brtarget16:$dst),
660b57cec5SDimitry Andric                          "jmp\t$dst", []>, OpSize16;
670b57cec5SDimitry Andric    def JMP_4 : Ii32PCRel<0xE9, RawFrm, (outs), (ins brtarget32:$dst),
680b57cec5SDimitry Andric                          "jmp\t$dst", []>, OpSize32;
690b57cec5SDimitry Andric  }
700b57cec5SDimitry Andric}
710b57cec5SDimitry Andric
720b57cec5SDimitry Andric// Conditional Branches.
730b57cec5SDimitry Andriclet isBranch = 1, isTerminator = 1, Uses = [EFLAGS], SchedRW = [WriteJump],
740b57cec5SDimitry Andric    isCodeGenOnly = 1, ForceDisassemble = 1 in {
750b57cec5SDimitry Andric  def JCC_1 : Ii8PCRel <0x70, AddCCFrm, (outs),
760b57cec5SDimitry Andric                        (ins brtarget8:$dst, ccode:$cond),
770b57cec5SDimitry Andric                        "j${cond}\t$dst",
788bcb0991SDimitry Andric                        [(X86brcond bb:$dst, timm:$cond, EFLAGS)]>;
790b57cec5SDimitry Andric  let hasSideEffects = 0 in {
800b57cec5SDimitry Andric    def JCC_2 : Ii16PCRel<0x80, AddCCFrm, (outs),
810b57cec5SDimitry Andric                          (ins brtarget16:$dst, ccode:$cond),
820b57cec5SDimitry Andric                          "j${cond}\t$dst",
830b57cec5SDimitry Andric                          []>, OpSize16, TB;
840b57cec5SDimitry Andric    def JCC_4 : Ii32PCRel<0x80, AddCCFrm, (outs),
850b57cec5SDimitry Andric                          (ins brtarget32:$dst, ccode:$cond),
860b57cec5SDimitry Andric                          "j${cond}\t$dst",
870b57cec5SDimitry Andric                          []>, TB, OpSize32;
880b57cec5SDimitry Andric  }
890b57cec5SDimitry Andric}
900b57cec5SDimitry Andric
910b57cec5SDimitry Andricdef : InstAlias<"jo\t$dst",  (JCC_1 brtarget8:$dst,  0), 0>;
920b57cec5SDimitry Andricdef : InstAlias<"jno\t$dst", (JCC_1 brtarget8:$dst,  1), 0>;
930b57cec5SDimitry Andricdef : InstAlias<"jb\t$dst",  (JCC_1 brtarget8:$dst,  2), 0>;
940b57cec5SDimitry Andricdef : InstAlias<"jae\t$dst", (JCC_1 brtarget8:$dst,  3), 0>;
950b57cec5SDimitry Andricdef : InstAlias<"je\t$dst",  (JCC_1 brtarget8:$dst,  4), 0>;
960b57cec5SDimitry Andricdef : InstAlias<"jne\t$dst", (JCC_1 brtarget8:$dst,  5), 0>;
970b57cec5SDimitry Andricdef : InstAlias<"jbe\t$dst", (JCC_1 brtarget8:$dst,  6), 0>;
980b57cec5SDimitry Andricdef : InstAlias<"ja\t$dst",  (JCC_1 brtarget8:$dst,  7), 0>;
990b57cec5SDimitry Andricdef : InstAlias<"js\t$dst",  (JCC_1 brtarget8:$dst,  8), 0>;
1000b57cec5SDimitry Andricdef : InstAlias<"jns\t$dst", (JCC_1 brtarget8:$dst,  9), 0>;
1010b57cec5SDimitry Andricdef : InstAlias<"jp\t$dst",  (JCC_1 brtarget8:$dst, 10), 0>;
1020b57cec5SDimitry Andricdef : InstAlias<"jnp\t$dst", (JCC_1 brtarget8:$dst, 11), 0>;
1030b57cec5SDimitry Andricdef : InstAlias<"jl\t$dst",  (JCC_1 brtarget8:$dst, 12), 0>;
1040b57cec5SDimitry Andricdef : InstAlias<"jge\t$dst", (JCC_1 brtarget8:$dst, 13), 0>;
1050b57cec5SDimitry Andricdef : InstAlias<"jle\t$dst", (JCC_1 brtarget8:$dst, 14), 0>;
1060b57cec5SDimitry Andricdef : InstAlias<"jg\t$dst",  (JCC_1 brtarget8:$dst, 15), 0>;
1070b57cec5SDimitry Andric
1080b57cec5SDimitry Andric// jcx/jecx/jrcx instructions.
1090b57cec5SDimitry Andriclet isBranch = 1, isTerminator = 1, hasSideEffects = 0, SchedRW = [WriteJump] in {
1100b57cec5SDimitry Andric  // These are the 32-bit versions of this instruction for the asmparser.  In
1110b57cec5SDimitry Andric  // 32-bit mode, the address size prefix is jcxz and the unprefixed version is
1120b57cec5SDimitry Andric  // jecxz.
1130b57cec5SDimitry Andric  let Uses = [CX] in
1140b57cec5SDimitry Andric    def JCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
1150b57cec5SDimitry Andric                        "jcxz\t$dst", []>, AdSize16, Requires<[Not64BitMode]>;
1160b57cec5SDimitry Andric  let Uses = [ECX] in
1170b57cec5SDimitry Andric    def JECXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
1180b57cec5SDimitry Andric                        "jecxz\t$dst", []>, AdSize32;
1190b57cec5SDimitry Andric
1200b57cec5SDimitry Andric  let Uses = [RCX] in
1210b57cec5SDimitry Andric    def JRCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
1220b57cec5SDimitry Andric                         "jrcxz\t$dst", []>, AdSize64, Requires<[In64BitMode]>;
1230b57cec5SDimitry Andric}
1240b57cec5SDimitry Andric
1250b57cec5SDimitry Andric// Indirect branches
1260b57cec5SDimitry Andriclet isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
1270b57cec5SDimitry Andric  def JMP16r     : I<0xFF, MRM4r, (outs), (ins GR16:$dst), "jmp{w}\t{*}$dst",
1280b57cec5SDimitry Andric                     [(brind GR16:$dst)]>, Requires<[Not64BitMode]>,
1290b57cec5SDimitry Andric                     OpSize16, Sched<[WriteJump]>;
1300b57cec5SDimitry Andric  def JMP16m     : I<0xFF, MRM4m, (outs), (ins i16mem:$dst), "jmp{w}\t{*}$dst",
1310b57cec5SDimitry Andric                     [(brind (loadi16 addr:$dst))]>, Requires<[Not64BitMode]>,
1320b57cec5SDimitry Andric                     OpSize16, Sched<[WriteJumpLd]>;
1330b57cec5SDimitry Andric
1340b57cec5SDimitry Andric  def JMP32r     : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst",
1350b57cec5SDimitry Andric                     [(brind GR32:$dst)]>, Requires<[Not64BitMode]>,
1360b57cec5SDimitry Andric                     OpSize32, Sched<[WriteJump]>;
1370b57cec5SDimitry Andric  def JMP32m     : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst",
1380b57cec5SDimitry Andric                     [(brind (loadi32 addr:$dst))]>, Requires<[Not64BitMode]>,
1390b57cec5SDimitry Andric                     OpSize32, Sched<[WriteJumpLd]>;
1400b57cec5SDimitry Andric
1410b57cec5SDimitry Andric  def JMP64r     : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
1420b57cec5SDimitry Andric                     [(brind GR64:$dst)]>, Requires<[In64BitMode]>,
1430b57cec5SDimitry Andric                     Sched<[WriteJump]>;
1440b57cec5SDimitry Andric  def JMP64m     : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
1450b57cec5SDimitry Andric                     [(brind (loadi64 addr:$dst))]>, Requires<[In64BitMode]>,
1460b57cec5SDimitry Andric                     Sched<[WriteJumpLd]>;
1470b57cec5SDimitry Andric
1488bcb0991SDimitry Andric  // Win64 wants indirect jumps leaving the function to have a REX_W prefix.
1498bcb0991SDimitry Andric  // These are switched from TAILJMPr/m64_REX in MCInstLower.
1508bcb0991SDimitry Andric  let isCodeGenOnly = 1, hasREX_WPrefix = 1 in {
1518bcb0991SDimitry Andric    def JMP64r_REX : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
1528bcb0991SDimitry Andric                       "rex64 jmp{q}\t{*}$dst", []>, Sched<[WriteJump]>;
1538bcb0991SDimitry Andric    let mayLoad = 1 in
1548bcb0991SDimitry Andric    def JMP64m_REX : I<0xFF, MRM4m, (outs), (ins i64mem:$dst),
1558bcb0991SDimitry Andric                       "rex64 jmp{q}\t{*}$dst", []>, Sched<[WriteJumpLd]>;
1568bcb0991SDimitry Andric
1578bcb0991SDimitry Andric  }
1588bcb0991SDimitry Andric
1590b57cec5SDimitry Andric  // Non-tracking jumps for IBT, use with caution.
1600b57cec5SDimitry Andric  let isCodeGenOnly = 1 in {
1610b57cec5SDimitry Andric    def JMP16r_NT : I<0xFF, MRM4r, (outs), (ins GR16 : $dst), "jmp{w}\t{*}$dst",
1620b57cec5SDimitry Andric                      [(X86NoTrackBrind GR16 : $dst)]>, Requires<[Not64BitMode]>,
1630b57cec5SDimitry Andric                      OpSize16, Sched<[WriteJump]>, NOTRACK;
1640b57cec5SDimitry Andric
1650b57cec5SDimitry Andric    def JMP16m_NT : I<0xFF, MRM4m, (outs), (ins i16mem : $dst), "jmp{w}\t{*}$dst",
1660b57cec5SDimitry Andric                      [(X86NoTrackBrind (loadi16 addr : $dst))]>,
1670b57cec5SDimitry Andric                      Requires<[Not64BitMode]>, OpSize16, Sched<[WriteJumpLd]>,
1680b57cec5SDimitry Andric                      NOTRACK;
1690b57cec5SDimitry Andric
1700b57cec5SDimitry Andric    def JMP32r_NT : I<0xFF, MRM4r, (outs), (ins GR32 : $dst), "jmp{l}\t{*}$dst",
1710b57cec5SDimitry Andric                      [(X86NoTrackBrind GR32 : $dst)]>, Requires<[Not64BitMode]>,
1720b57cec5SDimitry Andric                      OpSize32, Sched<[WriteJump]>, NOTRACK;
1730b57cec5SDimitry Andric    def JMP32m_NT : I<0xFF, MRM4m, (outs), (ins i32mem : $dst), "jmp{l}\t{*}$dst",
1740b57cec5SDimitry Andric                      [(X86NoTrackBrind (loadi32 addr : $dst))]>,
1750b57cec5SDimitry Andric                      Requires<[Not64BitMode]>, OpSize32, Sched<[WriteJumpLd]>,
1760b57cec5SDimitry Andric                      NOTRACK;
1770b57cec5SDimitry Andric
1780b57cec5SDimitry Andric    def JMP64r_NT : I<0xFF, MRM4r, (outs), (ins GR64 : $dst), "jmp{q}\t{*}$dst",
1790b57cec5SDimitry Andric                      [(X86NoTrackBrind GR64 : $dst)]>, Requires<[In64BitMode]>,
1800b57cec5SDimitry Andric                      Sched<[WriteJump]>, NOTRACK;
1810b57cec5SDimitry Andric    def JMP64m_NT : I<0xFF, MRM4m, (outs), (ins i64mem : $dst), "jmp{q}\t{*}$dst",
1820b57cec5SDimitry Andric                      [(X86NoTrackBrind(loadi64 addr : $dst))]>,
1830b57cec5SDimitry Andric                      Requires<[In64BitMode]>, Sched<[WriteJumpLd]>, NOTRACK;
1840b57cec5SDimitry Andric  }
1850b57cec5SDimitry Andric
1860b57cec5SDimitry Andric  let Predicates = [Not64BitMode], AsmVariantName = "att" in {
1870b57cec5SDimitry Andric    def FARJMP16i  : Iseg16<0xEA, RawFrmImm16, (outs),
1880b57cec5SDimitry Andric                            (ins i16imm:$off, i16imm:$seg),
1890b57cec5SDimitry Andric                            "ljmp{w}\t$seg, $off", []>,
1900b57cec5SDimitry Andric                            OpSize16, Sched<[WriteJump]>;
1910b57cec5SDimitry Andric    def FARJMP32i  : Iseg32<0xEA, RawFrmImm16, (outs),
1920b57cec5SDimitry Andric                            (ins i32imm:$off, i16imm:$seg),
1930b57cec5SDimitry Andric                            "ljmp{l}\t$seg, $off", []>,
1940b57cec5SDimitry Andric                            OpSize32, Sched<[WriteJump]>;
1950b57cec5SDimitry Andric  }
196*5ffd83dbSDimitry Andric  let mayLoad = 1 in {
197*5ffd83dbSDimitry Andric    def FARJMP64m  : RI<0xFF, MRM5m, (outs), (ins opaquemem:$dst),
1980b57cec5SDimitry Andric                        "ljmp{q}\t{*}$dst", []>, Sched<[WriteJump]>, Requires<[In64BitMode]>;
1990b57cec5SDimitry Andric
2000b57cec5SDimitry Andric    let AsmVariantName = "att" in
2010b57cec5SDimitry Andric    def FARJMP16m  : I<0xFF, MRM5m, (outs), (ins opaquemem:$dst),
2020b57cec5SDimitry Andric                       "ljmp{w}\t{*}$dst", []>, OpSize16, Sched<[WriteJumpLd]>;
2030b57cec5SDimitry Andric    def FARJMP32m  : I<0xFF, MRM5m, (outs), (ins opaquemem:$dst),
2040b57cec5SDimitry Andric                       "{l}jmp{l}\t{*}$dst", []>, OpSize32, Sched<[WriteJumpLd]>;
2050b57cec5SDimitry Andric  }
206*5ffd83dbSDimitry Andric}
2070b57cec5SDimitry Andric
2080b57cec5SDimitry Andric// Loop instructions
2090b57cec5SDimitry Andriclet SchedRW = [WriteJump] in {
2100b57cec5SDimitry Andricdef LOOP   : Ii8PCRel<0xE2, RawFrm, (outs), (ins brtarget8:$dst), "loop\t$dst", []>;
2110b57cec5SDimitry Andricdef LOOPE  : Ii8PCRel<0xE1, RawFrm, (outs), (ins brtarget8:$dst), "loope\t$dst", []>;
2120b57cec5SDimitry Andricdef LOOPNE : Ii8PCRel<0xE0, RawFrm, (outs), (ins brtarget8:$dst), "loopne\t$dst", []>;
2130b57cec5SDimitry Andric}
2140b57cec5SDimitry Andric
2150b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
2160b57cec5SDimitry Andric//  Call Instructions...
2170b57cec5SDimitry Andric//
2180b57cec5SDimitry Andriclet isCall = 1 in
2190b57cec5SDimitry Andric  // All calls clobber the non-callee saved registers. ESP is marked as
2200b57cec5SDimitry Andric  // a use to prevent stack-pointer assignments that appear immediately
2210b57cec5SDimitry Andric  // before calls from potentially appearing dead. Uses for argument
2220b57cec5SDimitry Andric  // registers are added manually.
2230b57cec5SDimitry Andric  let Uses = [ESP, SSP] in {
2240b57cec5SDimitry Andric    def CALLpcrel32 : Ii32PCRel<0xE8, RawFrm,
225480093f4SDimitry Andric                           (outs), (ins i32imm_brtarget:$dst),
2260b57cec5SDimitry Andric                           "call{l}\t$dst", []>, OpSize32,
2270b57cec5SDimitry Andric                      Requires<[Not64BitMode]>, Sched<[WriteJump]>;
2280b57cec5SDimitry Andric    let hasSideEffects = 0 in
2290b57cec5SDimitry Andric      def CALLpcrel16 : Ii16PCRel<0xE8, RawFrm,
230480093f4SDimitry Andric                             (outs), (ins i16imm_brtarget:$dst),
2310b57cec5SDimitry Andric                             "call{w}\t$dst", []>, OpSize16,
2320b57cec5SDimitry Andric                        Sched<[WriteJump]>;
2330b57cec5SDimitry Andric    def CALL16r     : I<0xFF, MRM2r, (outs), (ins GR16:$dst),
2340b57cec5SDimitry Andric                        "call{w}\t{*}$dst", [(X86call GR16:$dst)]>,
2350b57cec5SDimitry Andric                      OpSize16, Requires<[Not64BitMode]>, Sched<[WriteJump]>;
2360b57cec5SDimitry Andric    def CALL16m     : I<0xFF, MRM2m, (outs), (ins i16mem:$dst),
2370b57cec5SDimitry Andric                        "call{w}\t{*}$dst", [(X86call (loadi16 addr:$dst))]>,
2380b57cec5SDimitry Andric                        OpSize16, Requires<[Not64BitMode,FavorMemIndirectCall]>,
2390b57cec5SDimitry Andric                        Sched<[WriteJumpLd]>;
2400b57cec5SDimitry Andric    def CALL32r     : I<0xFF, MRM2r, (outs), (ins GR32:$dst),
2410b57cec5SDimitry Andric                        "call{l}\t{*}$dst", [(X86call GR32:$dst)]>, OpSize32,
2420946e70aSDimitry Andric                        Requires<[Not64BitMode,NotUseIndirectThunkCalls]>,
2430b57cec5SDimitry Andric                        Sched<[WriteJump]>;
2440b57cec5SDimitry Andric    def CALL32m     : I<0xFF, MRM2m, (outs), (ins i32mem:$dst),
2450b57cec5SDimitry Andric                        "call{l}\t{*}$dst", [(X86call (loadi32 addr:$dst))]>,
2460b57cec5SDimitry Andric                        OpSize32,
2470b57cec5SDimitry Andric                        Requires<[Not64BitMode,FavorMemIndirectCall,
2480946e70aSDimitry Andric                                  NotUseIndirectThunkCalls]>,
2490b57cec5SDimitry Andric                        Sched<[WriteJumpLd]>;
2500b57cec5SDimitry Andric
2510b57cec5SDimitry Andric    // Non-tracking calls for IBT, use with caution.
2520b57cec5SDimitry Andric    let isCodeGenOnly = 1 in {
2530b57cec5SDimitry Andric      def CALL16r_NT : I<0xFF, MRM2r, (outs), (ins GR16 : $dst),
2540b57cec5SDimitry Andric                        "call{w}\t{*}$dst",[(X86NoTrackCall GR16 : $dst)]>,
2550b57cec5SDimitry Andric                        OpSize16, Requires<[Not64BitMode]>, Sched<[WriteJump]>, NOTRACK;
2560b57cec5SDimitry Andric      def CALL16m_NT : I<0xFF, MRM2m, (outs), (ins i16mem : $dst),
2570b57cec5SDimitry Andric                        "call{w}\t{*}$dst",[(X86NoTrackCall(loadi16 addr : $dst))]>,
2580b57cec5SDimitry Andric                        OpSize16, Requires<[Not64BitMode,FavorMemIndirectCall]>,
2590b57cec5SDimitry Andric                        Sched<[WriteJumpLd]>, NOTRACK;
2600b57cec5SDimitry Andric      def CALL32r_NT : I<0xFF, MRM2r, (outs), (ins GR32 : $dst),
2610b57cec5SDimitry Andric                        "call{l}\t{*}$dst",[(X86NoTrackCall GR32 : $dst)]>,
2620b57cec5SDimitry Andric                        OpSize32, Requires<[Not64BitMode]>, Sched<[WriteJump]>, NOTRACK;
2630b57cec5SDimitry Andric      def CALL32m_NT : I<0xFF, MRM2m, (outs), (ins i32mem : $dst),
2640b57cec5SDimitry Andric                        "call{l}\t{*}$dst",[(X86NoTrackCall(loadi32 addr : $dst))]>,
2650b57cec5SDimitry Andric                        OpSize32, Requires<[Not64BitMode,FavorMemIndirectCall]>,
2660b57cec5SDimitry Andric                        Sched<[WriteJumpLd]>, NOTRACK;
2670b57cec5SDimitry Andric    }
2680b57cec5SDimitry Andric
2690b57cec5SDimitry Andric    let Predicates = [Not64BitMode], AsmVariantName = "att" in {
2700b57cec5SDimitry Andric      def FARCALL16i  : Iseg16<0x9A, RawFrmImm16, (outs),
2710b57cec5SDimitry Andric                               (ins i16imm:$off, i16imm:$seg),
2720b57cec5SDimitry Andric                               "lcall{w}\t$seg, $off", []>,
2730b57cec5SDimitry Andric                               OpSize16, Sched<[WriteJump]>;
2740b57cec5SDimitry Andric      def FARCALL32i  : Iseg32<0x9A, RawFrmImm16, (outs),
2750b57cec5SDimitry Andric                               (ins i32imm:$off, i16imm:$seg),
2760b57cec5SDimitry Andric                               "lcall{l}\t$seg, $off", []>,
2770b57cec5SDimitry Andric                               OpSize32, Sched<[WriteJump]>;
2780b57cec5SDimitry Andric    }
2790b57cec5SDimitry Andric
280*5ffd83dbSDimitry Andric    let mayLoad = 1 in {
2810b57cec5SDimitry Andric      def FARCALL16m  : I<0xFF, MRM3m, (outs), (ins opaquemem:$dst),
2820b57cec5SDimitry Andric                          "lcall{w}\t{*}$dst", []>, OpSize16, Sched<[WriteJumpLd]>;
2830b57cec5SDimitry Andric      def FARCALL32m  : I<0xFF, MRM3m, (outs), (ins opaquemem:$dst),
2840b57cec5SDimitry Andric                          "{l}call{l}\t{*}$dst", []>, OpSize32, Sched<[WriteJumpLd]>;
2850b57cec5SDimitry Andric    }
286*5ffd83dbSDimitry Andric  }
2870b57cec5SDimitry Andric
2880b57cec5SDimitry Andric
2890b57cec5SDimitry Andric// Tail call stuff.
2900b57cec5SDimitry Andriclet isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
2918bcb0991SDimitry Andric    isCodeGenOnly = 1, Uses = [ESP, SSP] in {
292480093f4SDimitry Andric  def TCRETURNdi : PseudoI<(outs), (ins i32imm_brtarget:$dst, i32imm:$offset),
2938bcb0991SDimitry Andric                           []>, Sched<[WriteJump]>, NotMemoryFoldable;
2948bcb0991SDimitry Andric  def TCRETURNri : PseudoI<(outs), (ins ptr_rc_tailcall:$dst, i32imm:$offset),
2958bcb0991SDimitry Andric                           []>, Sched<[WriteJump]>, NotMemoryFoldable;
2960b57cec5SDimitry Andric  let mayLoad = 1 in
2978bcb0991SDimitry Andric  def TCRETURNmi : PseudoI<(outs), (ins i32mem_TC:$dst, i32imm:$offset),
2988bcb0991SDimitry Andric                           []>, Sched<[WriteJumpLd]>;
2990b57cec5SDimitry Andric
300480093f4SDimitry Andric  def TAILJMPd : PseudoI<(outs), (ins i32imm_brtarget:$dst),
3018bcb0991SDimitry Andric                         []>, Sched<[WriteJump]>;
3020b57cec5SDimitry Andric
3038bcb0991SDimitry Andric  def TAILJMPr : PseudoI<(outs), (ins ptr_rc_tailcall:$dst),
3048bcb0991SDimitry Andric                         []>, Sched<[WriteJump]>;
3050b57cec5SDimitry Andric  let mayLoad = 1 in
3068bcb0991SDimitry Andric  def TAILJMPm : PseudoI<(outs), (ins i32mem_TC:$dst),
3078bcb0991SDimitry Andric                         []>, Sched<[WriteJumpLd]>;
3080b57cec5SDimitry Andric}
3090b57cec5SDimitry Andric
3100b57cec5SDimitry Andric// Conditional tail calls are similar to the above, but they are branches
3110b57cec5SDimitry Andric// rather than barriers, and they use EFLAGS.
3120b57cec5SDimitry Andriclet isCall = 1, isTerminator = 1, isReturn = 1, isBranch = 1,
3138bcb0991SDimitry Andric    isCodeGenOnly = 1, SchedRW = [WriteJump] in
3140b57cec5SDimitry Andric  let Uses = [ESP, EFLAGS, SSP] in {
3150b57cec5SDimitry Andric  def TCRETURNdicc : PseudoI<(outs),
316480093f4SDimitry Andric                     (ins i32imm_brtarget:$dst, i32imm:$offset, i32imm:$cond),
317480093f4SDimitry Andric                     []>;
3180b57cec5SDimitry Andric
3190b57cec5SDimitry Andric  // This gets substituted to a conditional jump instruction in MC lowering.
320480093f4SDimitry Andric  def TAILJMPd_CC : PseudoI<(outs), (ins i32imm_brtarget:$dst, i32imm:$cond), []>;
3210b57cec5SDimitry Andric}
3220b57cec5SDimitry Andric
3230b57cec5SDimitry Andric
3240b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
3250b57cec5SDimitry Andric//  Call Instructions...
3260b57cec5SDimitry Andric//
3270b57cec5SDimitry Andric
3280b57cec5SDimitry Andric// RSP is marked as a use to prevent stack-pointer assignments that appear
3290b57cec5SDimitry Andric// immediately before calls from potentially appearing dead. Uses for argument
3300b57cec5SDimitry Andric// registers are added manually.
3310b57cec5SDimitry Andriclet isCall = 1, Uses = [RSP, SSP], SchedRW = [WriteJump] in {
3320b57cec5SDimitry Andric  // NOTE: this pattern doesn't match "X86call imm", because we do not know
3330b57cec5SDimitry Andric  // that the offset between an arbitrary immediate and the call will fit in
3340b57cec5SDimitry Andric  // the 32-bit pcrel field that we have.
3350b57cec5SDimitry Andric  def CALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
336480093f4SDimitry Andric                        (outs), (ins i64i32imm_brtarget:$dst),
3370b57cec5SDimitry Andric                        "call{q}\t$dst", []>, OpSize32,
3380b57cec5SDimitry Andric                      Requires<[In64BitMode]>;
3390b57cec5SDimitry Andric  def CALL64r       : I<0xFF, MRM2r, (outs), (ins GR64:$dst),
3400b57cec5SDimitry Andric                        "call{q}\t{*}$dst", [(X86call GR64:$dst)]>,
3410946e70aSDimitry Andric                      Requires<[In64BitMode,NotUseIndirectThunkCalls]>;
3420b57cec5SDimitry Andric  def CALL64m       : I<0xFF, MRM2m, (outs), (ins i64mem:$dst),
3430b57cec5SDimitry Andric                        "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
3440b57cec5SDimitry Andric                      Requires<[In64BitMode,FavorMemIndirectCall,
3450946e70aSDimitry Andric                                NotUseIndirectThunkCalls]>;
3460b57cec5SDimitry Andric
3470b57cec5SDimitry Andric  // Non-tracking calls for IBT, use with caution.
3480b57cec5SDimitry Andric  let isCodeGenOnly = 1 in {
3490b57cec5SDimitry Andric    def CALL64r_NT : I<0xFF, MRM2r, (outs), (ins GR64 : $dst),
3500b57cec5SDimitry Andric                      "call{q}\t{*}$dst",[(X86NoTrackCall GR64 : $dst)]>,
3510b57cec5SDimitry Andric                      Requires<[In64BitMode]>, NOTRACK;
3520b57cec5SDimitry Andric    def CALL64m_NT : I<0xFF, MRM2m, (outs), (ins i64mem : $dst),
3530b57cec5SDimitry Andric                       "call{q}\t{*}$dst",
3540b57cec5SDimitry Andric                       [(X86NoTrackCall(loadi64 addr : $dst))]>,
3550b57cec5SDimitry Andric                       Requires<[In64BitMode,FavorMemIndirectCall]>, NOTRACK;
3560b57cec5SDimitry Andric  }
3570b57cec5SDimitry Andric
358*5ffd83dbSDimitry Andric  let mayLoad = 1 in
359*5ffd83dbSDimitry Andric  def FARCALL64m  : RI<0xFF, MRM3m, (outs), (ins opaquemem:$dst),
3600b57cec5SDimitry Andric                       "lcall{q}\t{*}$dst", []>;
3610b57cec5SDimitry Andric}
3620b57cec5SDimitry Andric
3630b57cec5SDimitry Andriclet isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
3648bcb0991SDimitry Andric    isCodeGenOnly = 1, Uses = [RSP, SSP] in {
3650b57cec5SDimitry Andric  def TCRETURNdi64   : PseudoI<(outs),
366480093f4SDimitry Andric                               (ins i64i32imm_brtarget:$dst, i32imm:$offset),
3678bcb0991SDimitry Andric                               []>, Sched<[WriteJump]>;
3680b57cec5SDimitry Andric  def TCRETURNri64   : PseudoI<(outs),
3698bcb0991SDimitry Andric                               (ins ptr_rc_tailcall:$dst, i32imm:$offset),
3708bcb0991SDimitry Andric                               []>, Sched<[WriteJump]>, NotMemoryFoldable;
3710b57cec5SDimitry Andric  let mayLoad = 1 in
3720b57cec5SDimitry Andric  def TCRETURNmi64   : PseudoI<(outs),
3738bcb0991SDimitry Andric                               (ins i64mem_TC:$dst, i32imm:$offset),
3748bcb0991SDimitry Andric                               []>, Sched<[WriteJumpLd]>, NotMemoryFoldable;
3750b57cec5SDimitry Andric
376480093f4SDimitry Andric  def TAILJMPd64 : PseudoI<(outs), (ins i64i32imm_brtarget:$dst),
3778bcb0991SDimitry Andric                           []>, Sched<[WriteJump]>;
3780b57cec5SDimitry Andric
3798bcb0991SDimitry Andric  def TAILJMPr64 : PseudoI<(outs), (ins ptr_rc_tailcall:$dst),
3808bcb0991SDimitry Andric                           []>, Sched<[WriteJump]>;
3810b57cec5SDimitry Andric
3820b57cec5SDimitry Andric  let mayLoad = 1 in
3838bcb0991SDimitry Andric  def TAILJMPm64 : PseudoI<(outs), (ins i64mem_TC:$dst),
3848bcb0991SDimitry Andric                           []>, Sched<[WriteJumpLd]>;
3850b57cec5SDimitry Andric
3860b57cec5SDimitry Andric  // Win64 wants indirect jumps leaving the function to have a REX_W prefix.
3870b57cec5SDimitry Andric  let hasREX_WPrefix = 1 in {
3888bcb0991SDimitry Andric    def TAILJMPr64_REX : PseudoI<(outs), (ins ptr_rc_tailcall:$dst),
3898bcb0991SDimitry Andric                                 []>, Sched<[WriteJump]>;
3900b57cec5SDimitry Andric
3910b57cec5SDimitry Andric    let mayLoad = 1 in
3928bcb0991SDimitry Andric    def TAILJMPm64_REX : PseudoI<(outs), (ins i64mem_TC:$dst),
3938bcb0991SDimitry Andric                                 []>, Sched<[WriteJumpLd]>;
3940b57cec5SDimitry Andric  }
3950b57cec5SDimitry Andric}
3960b57cec5SDimitry Andric
3970b57cec5SDimitry Andriclet isPseudo = 1, isCall = 1, isCodeGenOnly = 1,
3980b57cec5SDimitry Andric    Uses = [RSP, SSP],
3990b57cec5SDimitry Andric    usesCustomInserter = 1,
4000b57cec5SDimitry Andric    SchedRW = [WriteJump] in {
4010946e70aSDimitry Andric  def INDIRECT_THUNK_CALL32 :
4020b57cec5SDimitry Andric    PseudoI<(outs), (ins GR32:$dst), [(X86call GR32:$dst)]>,
4030946e70aSDimitry Andric            Requires<[Not64BitMode,UseIndirectThunkCalls]>;
4040b57cec5SDimitry Andric
4050946e70aSDimitry Andric  def INDIRECT_THUNK_CALL64 :
4060b57cec5SDimitry Andric    PseudoI<(outs), (ins GR64:$dst), [(X86call GR64:$dst)]>,
4070946e70aSDimitry Andric            Requires<[In64BitMode,UseIndirectThunkCalls]>;
4080b57cec5SDimitry Andric
4090946e70aSDimitry Andric  // Indirect thunk variant of indirect tail calls.
4100b57cec5SDimitry Andric  let isTerminator = 1, isReturn = 1, isBarrier = 1 in {
4110946e70aSDimitry Andric    def INDIRECT_THUNK_TCRETURN64 :
4120b57cec5SDimitry Andric      PseudoI<(outs), (ins GR64:$dst, i32imm:$offset), []>;
4130946e70aSDimitry Andric    def INDIRECT_THUNK_TCRETURN32 :
4140b57cec5SDimitry Andric      PseudoI<(outs), (ins GR32:$dst, i32imm:$offset), []>;
4150b57cec5SDimitry Andric  }
4160b57cec5SDimitry Andric}
4170b57cec5SDimitry Andric
4180b57cec5SDimitry Andric// Conditional tail calls are similar to the above, but they are branches
4190b57cec5SDimitry Andric// rather than barriers, and they use EFLAGS.
4200b57cec5SDimitry Andriclet isCall = 1, isTerminator = 1, isReturn = 1, isBranch = 1,
4218bcb0991SDimitry Andric    isCodeGenOnly = 1, SchedRW = [WriteJump] in
4220b57cec5SDimitry Andric  let Uses = [RSP, EFLAGS, SSP] in {
4230b57cec5SDimitry Andric  def TCRETURNdi64cc : PseudoI<(outs),
424480093f4SDimitry Andric                           (ins i64i32imm_brtarget:$dst, i32imm:$offset,
4250b57cec5SDimitry Andric                            i32imm:$cond), []>;
4260b57cec5SDimitry Andric
4270b57cec5SDimitry Andric  // This gets substituted to a conditional jump instruction in MC lowering.
4288bcb0991SDimitry Andric  def TAILJMPd64_CC : PseudoI<(outs),
429480093f4SDimitry Andric                              (ins i64i32imm_brtarget:$dst, i32imm:$cond), []>;
4300b57cec5SDimitry Andric}
431