xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/X86/X86InstrControl.td (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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//
1906c3fb27SDimitry Andric// The X86retglue 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 {
23349cc55cSDimitry Andric  def RET32  : I   <0xC3, RawFrm, (outs), (ins variable_ops),
240b57cec5SDimitry Andric                    "ret{l}", []>, OpSize32, Requires<[Not64BitMode]>;
25349cc55cSDimitry Andric  def RET64  : I   <0xC3, RawFrm, (outs), (ins variable_ops),
260b57cec5SDimitry Andric                    "ret{q}", []>, OpSize32, Requires<[In64BitMode]>;
27349cc55cSDimitry Andric  def RET16  : I   <0xC3, RawFrm, (outs), (ins),
280b57cec5SDimitry Andric                    "ret{w}", []>, OpSize16;
29349cc55cSDimitry Andric  def RETI32 : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
300b57cec5SDimitry Andric                    "ret{l}\t$amt", []>, OpSize32, Requires<[Not64BitMode]>;
31349cc55cSDimitry Andric  def RETI64 : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
320b57cec5SDimitry Andric                    "ret{q}\t$amt", []>, OpSize32, Requires<[In64BitMode]>;
33349cc55cSDimitry Andric  def RETI16 : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt),
340b57cec5SDimitry Andric                    "ret{w}\t$amt", []>, OpSize16;
35349cc55cSDimitry Andric  def LRET32 : I   <0xCB, RawFrm, (outs), (ins),
360b57cec5SDimitry Andric                    "{l}ret{l|f}", []>, OpSize32;
37349cc55cSDimitry Andric  def LRET64 : RI  <0xCB, RawFrm, (outs), (ins),
380b57cec5SDimitry Andric                    "{l}ret{|f}q", []>, Requires<[In64BitMode]>;
39349cc55cSDimitry Andric  def LRET16 : I   <0xCB, RawFrm, (outs), (ins),
400b57cec5SDimitry Andric                    "{l}ret{w|f}", []>, OpSize16;
41349cc55cSDimitry Andric  def LRETI32 : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
420b57cec5SDimitry Andric                     "{l}ret{l|f}\t$amt", []>, OpSize32;
43349cc55cSDimitry Andric  def LRETI64 : RIi16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
440b57cec5SDimitry Andric                      "{l}ret{|f}q\t$amt", []>, Requires<[In64BitMode]>;
45349cc55cSDimitry Andric  def LRETI16 : 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)]>;
5706c3fb27SDimitry Andric  def RET  : PseudoI<(outs), (ins i32imm:$adj, variable_ops), [(X86retglue 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 Andric// jcx/jecx/jrcx instructions.
920b57cec5SDimitry Andriclet isBranch = 1, isTerminator = 1, hasSideEffects = 0, SchedRW = [WriteJump] in {
930b57cec5SDimitry Andric  // These are the 32-bit versions of this instruction for the asmparser.  In
940b57cec5SDimitry Andric  // 32-bit mode, the address size prefix is jcxz and the unprefixed version is
950b57cec5SDimitry Andric  // jecxz.
960b57cec5SDimitry Andric  let Uses = [CX] in
970b57cec5SDimitry Andric    def JCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
980b57cec5SDimitry Andric                        "jcxz\t$dst", []>, AdSize16, Requires<[Not64BitMode]>;
990b57cec5SDimitry Andric  let Uses = [ECX] in
1000b57cec5SDimitry Andric    def JECXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
1010b57cec5SDimitry Andric                        "jecxz\t$dst", []>, AdSize32;
1020b57cec5SDimitry Andric
1030b57cec5SDimitry Andric  let Uses = [RCX] in
1040b57cec5SDimitry Andric    def JRCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
1050b57cec5SDimitry Andric                         "jrcxz\t$dst", []>, AdSize64, Requires<[In64BitMode]>;
1060b57cec5SDimitry Andric}
1070b57cec5SDimitry Andric
1080b57cec5SDimitry Andric// Indirect branches
1090b57cec5SDimitry Andriclet isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
1100b57cec5SDimitry Andric  def JMP16r     : I<0xFF, MRM4r, (outs), (ins GR16:$dst), "jmp{w}\t{*}$dst",
1110b57cec5SDimitry Andric                     [(brind GR16:$dst)]>, Requires<[Not64BitMode]>,
1120b57cec5SDimitry Andric                     OpSize16, Sched<[WriteJump]>;
1130b57cec5SDimitry Andric  def JMP16m     : I<0xFF, MRM4m, (outs), (ins i16mem:$dst), "jmp{w}\t{*}$dst",
1140b57cec5SDimitry Andric                     [(brind (loadi16 addr:$dst))]>, Requires<[Not64BitMode]>,
1150b57cec5SDimitry Andric                     OpSize16, Sched<[WriteJumpLd]>;
1160b57cec5SDimitry Andric
1170b57cec5SDimitry Andric  def JMP32r     : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst",
1180b57cec5SDimitry Andric                     [(brind GR32:$dst)]>, Requires<[Not64BitMode]>,
1190b57cec5SDimitry Andric                     OpSize32, Sched<[WriteJump]>;
1200b57cec5SDimitry Andric  def JMP32m     : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst",
1210b57cec5SDimitry Andric                     [(brind (loadi32 addr:$dst))]>, Requires<[Not64BitMode]>,
1220b57cec5SDimitry Andric                     OpSize32, Sched<[WriteJumpLd]>;
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andric  def JMP64r     : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
1250b57cec5SDimitry Andric                     [(brind GR64:$dst)]>, Requires<[In64BitMode]>,
1260b57cec5SDimitry Andric                     Sched<[WriteJump]>;
1270b57cec5SDimitry Andric  def JMP64m     : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
1280b57cec5SDimitry Andric                     [(brind (loadi64 addr:$dst))]>, Requires<[In64BitMode]>,
1290b57cec5SDimitry Andric                     Sched<[WriteJumpLd]>;
1300b57cec5SDimitry Andric
1318bcb0991SDimitry Andric  // Win64 wants indirect jumps leaving the function to have a REX_W prefix.
1328bcb0991SDimitry Andric  // These are switched from TAILJMPr/m64_REX in MCInstLower.
13381ad6265SDimitry Andric  let isCodeGenOnly = 1, hasREX_W = 1 in {
1348bcb0991SDimitry Andric    def JMP64r_REX : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
1358bcb0991SDimitry Andric                       "rex64 jmp{q}\t{*}$dst", []>, Sched<[WriteJump]>;
1368bcb0991SDimitry Andric    let mayLoad = 1 in
1378bcb0991SDimitry Andric    def JMP64m_REX : I<0xFF, MRM4m, (outs), (ins i64mem:$dst),
1388bcb0991SDimitry Andric                       "rex64 jmp{q}\t{*}$dst", []>, Sched<[WriteJumpLd]>;
1398bcb0991SDimitry Andric
1408bcb0991SDimitry Andric  }
1418bcb0991SDimitry Andric
1420b57cec5SDimitry Andric  // Non-tracking jumps for IBT, use with caution.
1430b57cec5SDimitry Andric  let isCodeGenOnly = 1 in {
1440b57cec5SDimitry Andric    def JMP16r_NT : I<0xFF, MRM4r, (outs), (ins GR16 : $dst), "jmp{w}\t{*}$dst",
1450b57cec5SDimitry Andric                      [(X86NoTrackBrind GR16 : $dst)]>, Requires<[Not64BitMode]>,
1460b57cec5SDimitry Andric                      OpSize16, Sched<[WriteJump]>, NOTRACK;
1470b57cec5SDimitry Andric
1480b57cec5SDimitry Andric    def JMP16m_NT : I<0xFF, MRM4m, (outs), (ins i16mem : $dst), "jmp{w}\t{*}$dst",
1490b57cec5SDimitry Andric                      [(X86NoTrackBrind (loadi16 addr : $dst))]>,
1500b57cec5SDimitry Andric                      Requires<[Not64BitMode]>, OpSize16, Sched<[WriteJumpLd]>,
1510b57cec5SDimitry Andric                      NOTRACK;
1520b57cec5SDimitry Andric
1530b57cec5SDimitry Andric    def JMP32r_NT : I<0xFF, MRM4r, (outs), (ins GR32 : $dst), "jmp{l}\t{*}$dst",
1540b57cec5SDimitry Andric                      [(X86NoTrackBrind GR32 : $dst)]>, Requires<[Not64BitMode]>,
1550b57cec5SDimitry Andric                      OpSize32, Sched<[WriteJump]>, NOTRACK;
1560b57cec5SDimitry Andric    def JMP32m_NT : I<0xFF, MRM4m, (outs), (ins i32mem : $dst), "jmp{l}\t{*}$dst",
1570b57cec5SDimitry Andric                      [(X86NoTrackBrind (loadi32 addr : $dst))]>,
1580b57cec5SDimitry Andric                      Requires<[Not64BitMode]>, OpSize32, Sched<[WriteJumpLd]>,
1590b57cec5SDimitry Andric                      NOTRACK;
1600b57cec5SDimitry Andric
1610b57cec5SDimitry Andric    def JMP64r_NT : I<0xFF, MRM4r, (outs), (ins GR64 : $dst), "jmp{q}\t{*}$dst",
1620b57cec5SDimitry Andric                      [(X86NoTrackBrind GR64 : $dst)]>, Requires<[In64BitMode]>,
1630b57cec5SDimitry Andric                      Sched<[WriteJump]>, NOTRACK;
1640b57cec5SDimitry Andric    def JMP64m_NT : I<0xFF, MRM4m, (outs), (ins i64mem : $dst), "jmp{q}\t{*}$dst",
1650b57cec5SDimitry Andric                      [(X86NoTrackBrind(loadi64 addr : $dst))]>,
1660b57cec5SDimitry Andric                      Requires<[In64BitMode]>, Sched<[WriteJumpLd]>, NOTRACK;
1670b57cec5SDimitry Andric  }
1680b57cec5SDimitry Andric
1690b57cec5SDimitry Andric  let Predicates = [Not64BitMode], AsmVariantName = "att" in {
1700b57cec5SDimitry Andric    def FARJMP32i  : Iseg32<0xEA, RawFrmImm16, (outs),
1710b57cec5SDimitry Andric                            (ins i32imm:$off, i16imm:$seg),
1720b57cec5SDimitry Andric                            "ljmp{l}\t$seg, $off", []>,
1730b57cec5SDimitry Andric                            OpSize32, Sched<[WriteJump]>;
174*0fca6ea1SDimitry Andric    def FARJMP16i  : Iseg16<0xEA, RawFrmImm16, (outs),
175*0fca6ea1SDimitry Andric                            (ins i16imm:$off, i16imm:$seg),
176*0fca6ea1SDimitry Andric                            "ljmp{w}\t$seg, $off", []>,
177*0fca6ea1SDimitry Andric                            OpSize16, Sched<[WriteJump]>;
1780b57cec5SDimitry Andric  }
1795ffd83dbSDimitry Andric  let mayLoad = 1 in {
1805ffd83dbSDimitry Andric    def FARJMP64m  : RI<0xFF, MRM5m, (outs), (ins opaquemem:$dst),
1810b57cec5SDimitry Andric                        "ljmp{q}\t{*}$dst", []>, Sched<[WriteJump]>, Requires<[In64BitMode]>;
1820b57cec5SDimitry Andric
183*0fca6ea1SDimitry Andric    def FARJMP32m  : I<0xFF, MRM5m, (outs), (ins opaquemem:$dst),
184*0fca6ea1SDimitry Andric                       "{l}jmp{l}\t{*}$dst", []>, OpSize32, Sched<[WriteJumpLd]>;
1850b57cec5SDimitry Andric    let AsmVariantName = "att" in
1860b57cec5SDimitry Andric    def FARJMP16m  : I<0xFF, MRM5m, (outs), (ins opaquemem:$dst),
1870b57cec5SDimitry Andric                       "ljmp{w}\t{*}$dst", []>, OpSize16, Sched<[WriteJumpLd]>;
1880b57cec5SDimitry Andric  }
1895ffd83dbSDimitry Andric}
1900b57cec5SDimitry Andric
1915f757f3fSDimitry Andricdef JMPABS64i : Ii64<0xA1, RawFrm, (outs), (ins i64imm:$dst), "jmpabs\t$dst", []>,
1925f757f3fSDimitry Andric                ExplicitREX2Prefix, Requires<[In64BitMode]>, Sched<[WriteJumpLd]>;
1935f757f3fSDimitry Andric
1940b57cec5SDimitry Andric// Loop instructions
195fe6060f1SDimitry Andriclet isBranch = 1, isTerminator = 1, SchedRW = [WriteJump] in {
1960b57cec5SDimitry Andricdef LOOP   : Ii8PCRel<0xE2, RawFrm, (outs), (ins brtarget8:$dst), "loop\t$dst", []>;
1970b57cec5SDimitry Andricdef LOOPE  : Ii8PCRel<0xE1, RawFrm, (outs), (ins brtarget8:$dst), "loope\t$dst", []>;
1980b57cec5SDimitry Andricdef LOOPNE : Ii8PCRel<0xE0, RawFrm, (outs), (ins brtarget8:$dst), "loopne\t$dst", []>;
1990b57cec5SDimitry Andric}
2000b57cec5SDimitry Andric
2010b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
2020b57cec5SDimitry Andric//  Call Instructions...
2030b57cec5SDimitry Andric//
2040b57cec5SDimitry Andriclet isCall = 1 in
2050b57cec5SDimitry Andric  // All calls clobber the non-callee saved registers. ESP is marked as
2060b57cec5SDimitry Andric  // a use to prevent stack-pointer assignments that appear immediately
2070b57cec5SDimitry Andric  // before calls from potentially appearing dead. Uses for argument
2080b57cec5SDimitry Andric  // registers are added manually.
2090b57cec5SDimitry Andric  let Uses = [ESP, SSP] in {
2100b57cec5SDimitry Andric    def CALLpcrel32 : Ii32PCRel<0xE8, RawFrm,
211480093f4SDimitry Andric                           (outs), (ins i32imm_brtarget:$dst),
2120b57cec5SDimitry Andric                           "call{l}\t$dst", []>, OpSize32,
2130b57cec5SDimitry Andric                      Requires<[Not64BitMode]>, Sched<[WriteJump]>;
2140b57cec5SDimitry Andric    let hasSideEffects = 0 in
2150b57cec5SDimitry Andric      def CALLpcrel16 : Ii16PCRel<0xE8, RawFrm,
216480093f4SDimitry Andric                             (outs), (ins i16imm_brtarget:$dst),
2170b57cec5SDimitry Andric                             "call{w}\t$dst", []>, OpSize16,
21806c3fb27SDimitry Andric                        Requires<[Not64BitMode]>, Sched<[WriteJump]>;
2190b57cec5SDimitry Andric    def CALL16r     : I<0xFF, MRM2r, (outs), (ins GR16:$dst),
2200b57cec5SDimitry Andric                        "call{w}\t{*}$dst", [(X86call GR16:$dst)]>,
2210b57cec5SDimitry Andric                      OpSize16, Requires<[Not64BitMode]>, Sched<[WriteJump]>;
2220b57cec5SDimitry Andric    def CALL16m     : I<0xFF, MRM2m, (outs), (ins i16mem:$dst),
2230b57cec5SDimitry Andric                        "call{w}\t{*}$dst", [(X86call (loadi16 addr:$dst))]>,
2240b57cec5SDimitry Andric                        OpSize16, Requires<[Not64BitMode,FavorMemIndirectCall]>,
2250b57cec5SDimitry Andric                        Sched<[WriteJumpLd]>;
2260b57cec5SDimitry Andric    def CALL32r     : I<0xFF, MRM2r, (outs), (ins GR32:$dst),
2270b57cec5SDimitry Andric                        "call{l}\t{*}$dst", [(X86call GR32:$dst)]>, OpSize32,
2280946e70aSDimitry Andric                        Requires<[Not64BitMode,NotUseIndirectThunkCalls]>,
2290b57cec5SDimitry Andric                        Sched<[WriteJump]>;
2300b57cec5SDimitry Andric    def CALL32m     : I<0xFF, MRM2m, (outs), (ins i32mem:$dst),
2310b57cec5SDimitry Andric                        "call{l}\t{*}$dst", [(X86call (loadi32 addr:$dst))]>,
2320b57cec5SDimitry Andric                        OpSize32,
2330b57cec5SDimitry Andric                        Requires<[Not64BitMode,FavorMemIndirectCall,
2340946e70aSDimitry Andric                                  NotUseIndirectThunkCalls]>,
2350b57cec5SDimitry Andric                        Sched<[WriteJumpLd]>;
2360b57cec5SDimitry Andric
2370b57cec5SDimitry Andric    // Non-tracking calls for IBT, use with caution.
2380b57cec5SDimitry Andric    let isCodeGenOnly = 1 in {
2390b57cec5SDimitry Andric      def CALL16r_NT : I<0xFF, MRM2r, (outs), (ins GR16 : $dst),
2400b57cec5SDimitry Andric                        "call{w}\t{*}$dst",[(X86NoTrackCall GR16 : $dst)]>,
2410b57cec5SDimitry Andric                        OpSize16, Requires<[Not64BitMode]>, Sched<[WriteJump]>, NOTRACK;
2420b57cec5SDimitry Andric      def CALL16m_NT : I<0xFF, MRM2m, (outs), (ins i16mem : $dst),
2430b57cec5SDimitry Andric                        "call{w}\t{*}$dst",[(X86NoTrackCall(loadi16 addr : $dst))]>,
2440b57cec5SDimitry Andric                        OpSize16, Requires<[Not64BitMode,FavorMemIndirectCall]>,
2450b57cec5SDimitry Andric                        Sched<[WriteJumpLd]>, NOTRACK;
2460b57cec5SDimitry Andric      def CALL32r_NT : I<0xFF, MRM2r, (outs), (ins GR32 : $dst),
2470b57cec5SDimitry Andric                        "call{l}\t{*}$dst",[(X86NoTrackCall GR32 : $dst)]>,
2480b57cec5SDimitry Andric                        OpSize32, Requires<[Not64BitMode]>, Sched<[WriteJump]>, NOTRACK;
2490b57cec5SDimitry Andric      def CALL32m_NT : I<0xFF, MRM2m, (outs), (ins i32mem : $dst),
2500b57cec5SDimitry Andric                        "call{l}\t{*}$dst",[(X86NoTrackCall(loadi32 addr : $dst))]>,
2510b57cec5SDimitry Andric                        OpSize32, Requires<[Not64BitMode,FavorMemIndirectCall]>,
2520b57cec5SDimitry Andric                        Sched<[WriteJumpLd]>, NOTRACK;
2530b57cec5SDimitry Andric    }
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andric    let Predicates = [Not64BitMode], AsmVariantName = "att" in {
2560b57cec5SDimitry Andric      def FARCALL32i  : Iseg32<0x9A, RawFrmImm16, (outs),
2570b57cec5SDimitry Andric                               (ins i32imm:$off, i16imm:$seg),
2580b57cec5SDimitry Andric                               "lcall{l}\t$seg, $off", []>,
2590b57cec5SDimitry Andric                               OpSize32, Sched<[WriteJump]>;
260*0fca6ea1SDimitry Andric      def FARCALL16i  : Iseg16<0x9A, RawFrmImm16, (outs),
261*0fca6ea1SDimitry Andric                               (ins i16imm:$off, i16imm:$seg),
262*0fca6ea1SDimitry Andric                               "lcall{w}\t$seg, $off", []>,
263*0fca6ea1SDimitry Andric                               OpSize16, Sched<[WriteJump]>;
2640b57cec5SDimitry Andric    }
2650b57cec5SDimitry Andric
2665ffd83dbSDimitry Andric    let mayLoad = 1 in {
2670b57cec5SDimitry Andric      def FARCALL32m  : I<0xFF, MRM3m, (outs), (ins opaquemem:$dst),
2680b57cec5SDimitry Andric                          "{l}call{l}\t{*}$dst", []>, OpSize32, Sched<[WriteJumpLd]>;
269*0fca6ea1SDimitry Andric      def FARCALL16m  : I<0xFF, MRM3m, (outs), (ins opaquemem:$dst),
270*0fca6ea1SDimitry Andric                          "lcall{w}\t{*}$dst", []>, OpSize16, Sched<[WriteJumpLd]>;
2710b57cec5SDimitry Andric    }
2725ffd83dbSDimitry Andric  }
2730b57cec5SDimitry Andric
2740b57cec5SDimitry Andric
2750b57cec5SDimitry Andric// Tail call stuff.
2760b57cec5SDimitry Andriclet isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
2778bcb0991SDimitry Andric    isCodeGenOnly = 1, Uses = [ESP, SSP] in {
278480093f4SDimitry Andric  def TCRETURNdi : PseudoI<(outs), (ins i32imm_brtarget:$dst, i32imm:$offset),
27906c3fb27SDimitry Andric                           []>, Sched<[WriteJump]>;
2808bcb0991SDimitry Andric  def TCRETURNri : PseudoI<(outs), (ins ptr_rc_tailcall:$dst, i32imm:$offset),
28106c3fb27SDimitry Andric                           []>, Sched<[WriteJump]>;
2820b57cec5SDimitry Andric  let mayLoad = 1 in
2838bcb0991SDimitry Andric  def TCRETURNmi : PseudoI<(outs), (ins i32mem_TC:$dst, i32imm:$offset),
2848bcb0991SDimitry Andric                           []>, Sched<[WriteJumpLd]>;
2850b57cec5SDimitry Andric
286480093f4SDimitry Andric  def TAILJMPd : PseudoI<(outs), (ins i32imm_brtarget:$dst),
2878bcb0991SDimitry Andric                         []>, Sched<[WriteJump]>;
2880b57cec5SDimitry Andric
2898bcb0991SDimitry Andric  def TAILJMPr : PseudoI<(outs), (ins ptr_rc_tailcall:$dst),
2908bcb0991SDimitry Andric                         []>, Sched<[WriteJump]>;
2910b57cec5SDimitry Andric  let mayLoad = 1 in
2928bcb0991SDimitry Andric  def TAILJMPm : PseudoI<(outs), (ins i32mem_TC:$dst),
2938bcb0991SDimitry Andric                         []>, Sched<[WriteJumpLd]>;
2940b57cec5SDimitry Andric}
2950b57cec5SDimitry Andric
2960b57cec5SDimitry Andric// Conditional tail calls are similar to the above, but they are branches
2970b57cec5SDimitry Andric// rather than barriers, and they use EFLAGS.
2980b57cec5SDimitry Andriclet isCall = 1, isTerminator = 1, isReturn = 1, isBranch = 1,
2998bcb0991SDimitry Andric    isCodeGenOnly = 1, SchedRW = [WriteJump] in
3000b57cec5SDimitry Andric  let Uses = [ESP, EFLAGS, SSP] in {
3010b57cec5SDimitry Andric  def TCRETURNdicc : PseudoI<(outs),
302480093f4SDimitry Andric                     (ins i32imm_brtarget:$dst, i32imm:$offset, i32imm:$cond),
303480093f4SDimitry Andric                     []>;
3040b57cec5SDimitry Andric
3050b57cec5SDimitry Andric  // This gets substituted to a conditional jump instruction in MC lowering.
306480093f4SDimitry Andric  def TAILJMPd_CC : PseudoI<(outs), (ins i32imm_brtarget:$dst, i32imm:$cond), []>;
3070b57cec5SDimitry Andric}
3080b57cec5SDimitry Andric
3090b57cec5SDimitry Andric
3100b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
3110b57cec5SDimitry Andric//  Call Instructions...
3120b57cec5SDimitry Andric//
3130b57cec5SDimitry Andric
3140b57cec5SDimitry Andric// RSP is marked as a use to prevent stack-pointer assignments that appear
3150b57cec5SDimitry Andric// immediately before calls from potentially appearing dead. Uses for argument
3160b57cec5SDimitry Andric// registers are added manually.
3170b57cec5SDimitry Andriclet isCall = 1, Uses = [RSP, SSP], SchedRW = [WriteJump] in {
3180b57cec5SDimitry Andric  // NOTE: this pattern doesn't match "X86call imm", because we do not know
3190b57cec5SDimitry Andric  // that the offset between an arbitrary immediate and the call will fit in
3200b57cec5SDimitry Andric  // the 32-bit pcrel field that we have.
3210b57cec5SDimitry Andric  def CALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
322480093f4SDimitry Andric                        (outs), (ins i64i32imm_brtarget:$dst),
3230b57cec5SDimitry Andric                        "call{q}\t$dst", []>, OpSize32,
3240b57cec5SDimitry Andric                      Requires<[In64BitMode]>;
3250b57cec5SDimitry Andric  def CALL64r       : I<0xFF, MRM2r, (outs), (ins GR64:$dst),
3260b57cec5SDimitry Andric                        "call{q}\t{*}$dst", [(X86call GR64:$dst)]>,
3270946e70aSDimitry Andric                      Requires<[In64BitMode,NotUseIndirectThunkCalls]>;
3280b57cec5SDimitry Andric  def CALL64m       : I<0xFF, MRM2m, (outs), (ins i64mem:$dst),
3290b57cec5SDimitry Andric                        "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
3300b57cec5SDimitry Andric                      Requires<[In64BitMode,FavorMemIndirectCall,
3310946e70aSDimitry Andric                                NotUseIndirectThunkCalls]>;
3320b57cec5SDimitry Andric
3330b57cec5SDimitry Andric  // Non-tracking calls for IBT, use with caution.
3340b57cec5SDimitry Andric  let isCodeGenOnly = 1 in {
3350b57cec5SDimitry Andric    def CALL64r_NT : I<0xFF, MRM2r, (outs), (ins GR64 : $dst),
3360b57cec5SDimitry Andric                      "call{q}\t{*}$dst",[(X86NoTrackCall GR64 : $dst)]>,
3370b57cec5SDimitry Andric                      Requires<[In64BitMode]>, NOTRACK;
3380b57cec5SDimitry Andric    def CALL64m_NT : I<0xFF, MRM2m, (outs), (ins i64mem : $dst),
3390b57cec5SDimitry Andric                       "call{q}\t{*}$dst",
3400b57cec5SDimitry Andric                       [(X86NoTrackCall(loadi64 addr : $dst))]>,
3410b57cec5SDimitry Andric                       Requires<[In64BitMode,FavorMemIndirectCall]>, NOTRACK;
3420b57cec5SDimitry Andric  }
3430b57cec5SDimitry Andric
3445ffd83dbSDimitry Andric  let mayLoad = 1 in
3455ffd83dbSDimitry Andric  def FARCALL64m  : RI<0xFF, MRM3m, (outs), (ins opaquemem:$dst),
3460b57cec5SDimitry Andric                       "lcall{q}\t{*}$dst", []>;
3470b57cec5SDimitry Andric}
3480b57cec5SDimitry Andric
3490b57cec5SDimitry Andriclet isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
3508bcb0991SDimitry Andric    isCodeGenOnly = 1, Uses = [RSP, SSP] in {
3510b57cec5SDimitry Andric  def TCRETURNdi64   : PseudoI<(outs),
352480093f4SDimitry Andric                               (ins i64i32imm_brtarget:$dst, i32imm:$offset),
3538bcb0991SDimitry Andric                               []>, Sched<[WriteJump]>;
3540b57cec5SDimitry Andric  def TCRETURNri64   : PseudoI<(outs),
3558bcb0991SDimitry Andric                               (ins ptr_rc_tailcall:$dst, i32imm:$offset),
35606c3fb27SDimitry Andric                               []>, Sched<[WriteJump]>;
3570b57cec5SDimitry Andric  let mayLoad = 1 in
3580b57cec5SDimitry Andric  def TCRETURNmi64   : PseudoI<(outs),
3598bcb0991SDimitry Andric                               (ins i64mem_TC:$dst, i32imm:$offset),
36006c3fb27SDimitry Andric                               []>, Sched<[WriteJumpLd]>;
3610b57cec5SDimitry Andric
362480093f4SDimitry Andric  def TAILJMPd64 : PseudoI<(outs), (ins i64i32imm_brtarget:$dst),
3638bcb0991SDimitry Andric                           []>, Sched<[WriteJump]>;
3640b57cec5SDimitry Andric
3658bcb0991SDimitry Andric  def TAILJMPr64 : PseudoI<(outs), (ins ptr_rc_tailcall:$dst),
3668bcb0991SDimitry Andric                           []>, Sched<[WriteJump]>;
3670b57cec5SDimitry Andric
3680b57cec5SDimitry Andric  let mayLoad = 1 in
3698bcb0991SDimitry Andric  def TAILJMPm64 : PseudoI<(outs), (ins i64mem_TC:$dst),
3708bcb0991SDimitry Andric                           []>, Sched<[WriteJumpLd]>;
3710b57cec5SDimitry Andric
3720b57cec5SDimitry Andric  // Win64 wants indirect jumps leaving the function to have a REX_W prefix.
37381ad6265SDimitry Andric  let hasREX_W = 1 in {
3748bcb0991SDimitry Andric    def TAILJMPr64_REX : PseudoI<(outs), (ins ptr_rc_tailcall:$dst),
3758bcb0991SDimitry Andric                                 []>, Sched<[WriteJump]>;
3760b57cec5SDimitry Andric
3770b57cec5SDimitry Andric    let mayLoad = 1 in
3788bcb0991SDimitry Andric    def TAILJMPm64_REX : PseudoI<(outs), (ins i64mem_TC:$dst),
3798bcb0991SDimitry Andric                                 []>, Sched<[WriteJumpLd]>;
3800b57cec5SDimitry Andric  }
3810b57cec5SDimitry Andric}
3820b57cec5SDimitry Andric
3830b57cec5SDimitry Andriclet isPseudo = 1, isCall = 1, isCodeGenOnly = 1,
3840b57cec5SDimitry Andric    Uses = [RSP, SSP],
3850b57cec5SDimitry Andric    usesCustomInserter = 1,
3860b57cec5SDimitry Andric    SchedRW = [WriteJump] in {
3870946e70aSDimitry Andric  def INDIRECT_THUNK_CALL32 :
3880b57cec5SDimitry Andric    PseudoI<(outs), (ins GR32:$dst), [(X86call GR32:$dst)]>,
3890946e70aSDimitry Andric            Requires<[Not64BitMode,UseIndirectThunkCalls]>;
3900b57cec5SDimitry Andric
3910946e70aSDimitry Andric  def INDIRECT_THUNK_CALL64 :
3920b57cec5SDimitry Andric    PseudoI<(outs), (ins GR64:$dst), [(X86call GR64:$dst)]>,
3930946e70aSDimitry Andric            Requires<[In64BitMode,UseIndirectThunkCalls]>;
3940b57cec5SDimitry Andric
3950946e70aSDimitry Andric  // Indirect thunk variant of indirect tail calls.
3960b57cec5SDimitry Andric  let isTerminator = 1, isReturn = 1, isBarrier = 1 in {
3970946e70aSDimitry Andric    def INDIRECT_THUNK_TCRETURN64 :
3980b57cec5SDimitry Andric      PseudoI<(outs), (ins GR64:$dst, i32imm:$offset), []>;
3990946e70aSDimitry Andric    def INDIRECT_THUNK_TCRETURN32 :
4000b57cec5SDimitry Andric      PseudoI<(outs), (ins GR32:$dst, i32imm:$offset), []>;
4010b57cec5SDimitry Andric  }
4020b57cec5SDimitry Andric}
4030b57cec5SDimitry Andric
404fe6060f1SDimitry Andriclet isPseudo = 1, isCall = 1, isCodeGenOnly = 1,
405fe6060f1SDimitry Andric    Uses = [RSP, SSP],
406fe6060f1SDimitry Andric    SchedRW = [WriteJump] in {
407fe6060f1SDimitry Andric  def CALL64m_RVMARKER :
408349cc55cSDimitry Andric     PseudoI<(outs), (ins i64imm:$rvfunc, i64mem:$dst), [(X86call_rvmarker tglobaladdr:$rvfunc, (loadi64 addr:$dst))]>,
409fe6060f1SDimitry Andric             Requires<[In64BitMode]>;
410fe6060f1SDimitry Andric
411fe6060f1SDimitry Andric  def CALL64r_RVMARKER :
412349cc55cSDimitry Andric    PseudoI<(outs), (ins i64imm:$rvfunc, GR64:$dst), [(X86call_rvmarker tglobaladdr:$rvfunc, GR64:$dst)]>,
413fe6060f1SDimitry Andric            Requires<[In64BitMode]>;
414fe6060f1SDimitry Andric
415fe6060f1SDimitry Andric  def CALL64pcrel32_RVMARKER :
416349cc55cSDimitry Andric    PseudoI<(outs), (ins i64imm:$rvfunc, i64i32imm_brtarget:$dst), []>,
417fe6060f1SDimitry Andric            Requires<[In64BitMode]>;
418fe6060f1SDimitry Andric}
419fe6060f1SDimitry Andric
4200b57cec5SDimitry Andric// Conditional tail calls are similar to the above, but they are branches
4210b57cec5SDimitry Andric// rather than barriers, and they use EFLAGS.
4220b57cec5SDimitry Andriclet isCall = 1, isTerminator = 1, isReturn = 1, isBranch = 1,
4238bcb0991SDimitry Andric    isCodeGenOnly = 1, SchedRW = [WriteJump] in
4240b57cec5SDimitry Andric  let Uses = [RSP, EFLAGS, SSP] in {
4250b57cec5SDimitry Andric  def TCRETURNdi64cc : PseudoI<(outs),
426480093f4SDimitry Andric                           (ins i64i32imm_brtarget:$dst, i32imm:$offset,
4270b57cec5SDimitry Andric                            i32imm:$cond), []>;
4280b57cec5SDimitry Andric
4290b57cec5SDimitry Andric  // This gets substituted to a conditional jump instruction in MC lowering.
4308bcb0991SDimitry Andric  def TAILJMPd64_CC : PseudoI<(outs),
431480093f4SDimitry Andric                              (ins i64i32imm_brtarget:$dst, i32imm:$cond), []>;
4320b57cec5SDimitry Andric}
433