blob: e1e6eea59884af438b061e264b902a92da3a3489 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- X86InstrControl.td - Control Flow Instructions -----*- tablegen -*-===//
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +00006//
Chris Lattnerae33f5d2010-10-05 06:04:14 +00007//===----------------------------------------------------------------------===//
8//
9// This file describes the X86 jump, return, call, and related instructions.
10//
11//===----------------------------------------------------------------------===//
12
13//===----------------------------------------------------------------------===//
14// Control Flow Instructions.
15//
16
17// Return instructions.
Jakob Stoklund Olesenb50cf8b2012-08-24 20:52:44 +000018//
19// The X86retflag return instructions are variadic because we may add ST0 and
20// ST1 arguments when returning values on the x87 stack.
Chris Lattnerae33f5d2010-10-05 06:04:14 +000021let isTerminator = 1, isReturn = 1, isBarrier = 1,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +000022 hasCtrlDep = 1, FPForm = SpecialFP, SchedRW = [WriteJumpLd] in {
David Woodhouse79dd5052014-01-08 12:58:07 +000023 def RETL : I <0xC3, RawFrm, (outs), (ins variable_ops),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000024 "ret{l}", []>, OpSize32, Requires<[Not64BitMode]>;
David Woodhouse79dd5052014-01-08 12:58:07 +000025 def RETQ : I <0xC3, RawFrm, (outs), (ins variable_ops),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000026 "ret{q}", []>, OpSize32, Requires<[In64BitMode]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +000027 def RETW : I <0xC3, RawFrm, (outs), (ins),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000028 "ret{w}", []>, OpSize16;
David Woodhouse4e033b02014-01-13 14:05:59 +000029 def RETIL : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000030 "ret{l}\t$amt", []>, OpSize32, Requires<[Not64BitMode]>;
David Woodhouse4e033b02014-01-13 14:05:59 +000031 def RETIQ : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000032 "ret{q}\t$amt", []>, OpSize32, Requires<[In64BitMode]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +000033 def RETIW : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000034 "ret{w}\t$amt", []>, OpSize16;
Chris Lattner87cf7f72010-11-12 18:54:56 +000035 def LRETL : I <0xCB, RawFrm, (outs), (ins),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000036 "{l}ret{l|f}", []>, OpSize32;
David Woodhouse4e033b02014-01-13 14:05:59 +000037 def LRETQ : RI <0xCB, RawFrm, (outs), (ins),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000038 "{l}ret{|f}q", []>, Requires<[In64BitMode]>;
Charles Davis74c282b2012-04-11 01:10:53 +000039 def LRETW : I <0xCB, RawFrm, (outs), (ins),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000040 "{l}ret{w|f}", []>, OpSize16;
David Woodhouse4e033b02014-01-13 14:05:59 +000041 def LRETIL : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000042 "{l}ret{l|f}\t$amt", []>, OpSize32;
David Woodhouse4e033b02014-01-13 14:05:59 +000043 def LRETIQ : RIi16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000044 "{l}ret{|f}q\t$amt", []>, Requires<[In64BitMode]>;
Kevin Enderbyb9783dd2010-10-18 17:04:36 +000045 def LRETIW : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000046 "{l}ret{w|f}\t$amt", []>, OpSize16;
Amjad Aboud60b5e1b2015-12-21 14:07:14 +000047
48 // The machine return from interrupt instruction, but sometimes we need to
49 // perform a post-epilogue stack adjustment. Codegen emits the pseudo form
50 // which expands to include an SP adjustment if necessary.
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000051 def IRET16 : I <0xcf, RawFrm, (outs), (ins), "iret{w}", []>,
Amjad Aboud60b5e1b2015-12-21 14:07:14 +000052 OpSize16;
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000053 def IRET32 : I <0xcf, RawFrm, (outs), (ins), "iret{l|d}", []>, OpSize32;
54 def IRET64 : RI <0xcf, RawFrm, (outs), (ins), "iretq", []>, Requires<[In64BitMode]>;
Amjad Aboud60b5e1b2015-12-21 14:07:14 +000055 let isCodeGenOnly = 1 in
David Majnemerd2f767d2016-03-04 22:56:17 +000056 def IRET : PseudoI<(outs), (ins i32imm:$adj), [(X86iret timm:$adj)]>;
57 def RET : PseudoI<(outs), (ins i32imm:$adj, variable_ops), [(X86retflag timm:$adj)]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +000058}
59
60// Unconditional branches.
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +000061let isBarrier = 1, isBranch = 1, isTerminator = 1, SchedRW = [WriteJump] in {
Chris Lattnerae33f5d2010-10-05 06:04:14 +000062 def JMP_1 : Ii8PCRel<0xEB, RawFrm, (outs), (ins brtarget8:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000063 "jmp\t$dst", [(br bb:$dst)]>;
Craig Topper0f2c4ac2015-01-06 04:23:57 +000064 let hasSideEffects = 0, isCodeGenOnly = 1, ForceDisassemble = 1 in {
Craig Topper63944542015-01-06 08:59:30 +000065 def JMP_2 : Ii16PCRel<0xE9, RawFrm, (outs), (ins brtarget16:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000066 "jmp\t$dst", []>, OpSize16;
Craig Topper63944542015-01-06 08:59:30 +000067 def JMP_4 : Ii32PCRel<0xE9, RawFrm, (outs), (ins brtarget32:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +000068 "jmp\t$dst", []>, OpSize32;
Craig Topper49758aa2015-01-06 04:23:53 +000069 }
Chris Lattnerae33f5d2010-10-05 06:04:14 +000070}
71
72// Conditional Branches.
Craig Topper80aa2292019-04-05 19:28:09 +000073let isBranch = 1, isTerminator = 1, Uses = [EFLAGS], SchedRW = [WriteJump],
74 isCodeGenOnly = 1, ForceDisassemble = 1 in {
75 def JCC_1 : Ii8PCRel <0x70, AddCCFrm, (outs),
76 (ins brtarget8:$dst, ccode:$cond),
77 "j${cond}\t$dst",
Craig Toppere3c21632019-09-23 19:48:20 +000078 [(X86brcond bb:$dst, timm:$cond, EFLAGS)]>;
Craig Topper80aa2292019-04-05 19:28:09 +000079 let hasSideEffects = 0 in {
80 def JCC_2 : Ii16PCRel<0x80, AddCCFrm, (outs),
81 (ins brtarget16:$dst, ccode:$cond),
82 "j${cond}\t$dst",
83 []>, OpSize16, TB;
84 def JCC_4 : Ii32PCRel<0x80, AddCCFrm, (outs),
85 (ins brtarget32:$dst, ccode:$cond),
86 "j${cond}\t$dst",
87 []>, TB, OpSize32;
Chris Lattnerae33f5d2010-10-05 06:04:14 +000088 }
89}
90
Craig Topper80aa2292019-04-05 19:28:09 +000091def : InstAlias<"jo\t$dst", (JCC_1 brtarget8:$dst, 0), 0>;
92def : InstAlias<"jno\t$dst", (JCC_1 brtarget8:$dst, 1), 0>;
93def : InstAlias<"jb\t$dst", (JCC_1 brtarget8:$dst, 2), 0>;
94def : InstAlias<"jae\t$dst", (JCC_1 brtarget8:$dst, 3), 0>;
95def : InstAlias<"je\t$dst", (JCC_1 brtarget8:$dst, 4), 0>;
96def : InstAlias<"jne\t$dst", (JCC_1 brtarget8:$dst, 5), 0>;
97def : InstAlias<"jbe\t$dst", (JCC_1 brtarget8:$dst, 6), 0>;
98def : InstAlias<"ja\t$dst", (JCC_1 brtarget8:$dst, 7), 0>;
99def : InstAlias<"js\t$dst", (JCC_1 brtarget8:$dst, 8), 0>;
100def : InstAlias<"jns\t$dst", (JCC_1 brtarget8:$dst, 9), 0>;
101def : InstAlias<"jp\t$dst", (JCC_1 brtarget8:$dst, 10), 0>;
102def : InstAlias<"jnp\t$dst", (JCC_1 brtarget8:$dst, 11), 0>;
103def : InstAlias<"jl\t$dst", (JCC_1 brtarget8:$dst, 12), 0>;
104def : InstAlias<"jge\t$dst", (JCC_1 brtarget8:$dst, 13), 0>;
105def : InstAlias<"jle\t$dst", (JCC_1 brtarget8:$dst, 14), 0>;
106def : InstAlias<"jg\t$dst", (JCC_1 brtarget8:$dst, 15), 0>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000107
108// jcx/jecx/jrcx instructions.
Craig Topper8a1028f2013-09-03 03:56:17 +0000109let isBranch = 1, isTerminator = 1, hasSideEffects = 0, SchedRW = [WriteJump] in {
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000110 // These are the 32-bit versions of this instruction for the asmparser. In
111 // 32-bit mode, the address size prefix is jcxz and the unprefixed version is
112 // jecxz.
113 let Uses = [CX] in
114 def JCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000115 "jcxz\t$dst", []>, AdSize16, Requires<[Not64BitMode]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000116 let Uses = [ECX] in
Craig Topper055845f2015-01-02 07:02:25 +0000117 def JECXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000118 "jecxz\t$dst", []>, AdSize32;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000119
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000120 let Uses = [RCX] in
121 def JRCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000122 "jrcxz\t$dst", []>, AdSize64, Requires<[In64BitMode]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000123}
124
125// Indirect branches
126let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
David Woodhousefd460162014-01-08 12:57:49 +0000127 def JMP16r : I<0xFF, MRM4r, (outs), (ins GR16:$dst), "jmp{w}\t{*}$dst",
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000128 [(brind GR16:$dst)]>, Requires<[Not64BitMode]>,
129 OpSize16, Sched<[WriteJump]>;
David Woodhousefd460162014-01-08 12:57:49 +0000130 def JMP16m : I<0xFF, MRM4m, (outs), (ins i16mem:$dst), "jmp{w}\t{*}$dst",
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000131 [(brind (loadi16 addr:$dst))]>, Requires<[Not64BitMode]>,
132 OpSize16, Sched<[WriteJumpLd]>;
David Woodhousefd460162014-01-08 12:57:49 +0000133
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000134 def JMP32r : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst",
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000135 [(brind GR32:$dst)]>, Requires<[Not64BitMode]>,
136 OpSize32, Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000137 def JMP32m : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst",
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000138 [(brind (loadi32 addr:$dst))]>, Requires<[Not64BitMode]>,
139 OpSize32, Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000140
141 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000142 [(brind GR64:$dst)]>, Requires<[In64BitMode]>,
143 Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000144 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000145 [(brind (loadi64 addr:$dst))]>, Requires<[In64BitMode]>,
146 Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000147
Craig Topperfc1f08c2019-08-27 17:24:23 +0000148 // Win64 wants indirect jumps leaving the function to have a REX_W prefix.
149 // These are switched from TAILJMPr/m64_REX in MCInstLower.
150 let isCodeGenOnly = 1, hasREX_WPrefix = 1 in {
151 def JMP64r_REX : I<0xFF, MRM4r, (outs), (ins GR64:$dst),
152 "rex64 jmp{q}\t{*}$dst", []>, Sched<[WriteJump]>;
153 let mayLoad = 1 in
154 def JMP64m_REX : I<0xFF, MRM4m, (outs), (ins i64mem:$dst),
155 "rex64 jmp{q}\t{*}$dst", []>, Sched<[WriteJumpLd]>;
156
157 }
158
Alexander Ivchenko5c547422018-05-18 11:58:25 +0000159 // Non-tracking jumps for IBT, use with caution.
160 let isCodeGenOnly = 1 in {
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000161 def JMP16r_NT : I<0xFF, MRM4r, (outs), (ins GR16 : $dst), "jmp{w}\t{*}$dst",
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000162 [(X86NoTrackBrind GR16 : $dst)]>, Requires<[Not64BitMode]>,
163 OpSize16, Sched<[WriteJump]>, NOTRACK;
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000164
165 def JMP16m_NT : I<0xFF, MRM4m, (outs), (ins i16mem : $dst), "jmp{w}\t{*}$dst",
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000166 [(X86NoTrackBrind (loadi16 addr : $dst))]>,
167 Requires<[Not64BitMode]>, OpSize16, Sched<[WriteJumpLd]>,
168 NOTRACK;
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000169
170 def JMP32r_NT : I<0xFF, MRM4r, (outs), (ins GR32 : $dst), "jmp{l}\t{*}$dst",
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000171 [(X86NoTrackBrind GR32 : $dst)]>, Requires<[Not64BitMode]>,
172 OpSize32, Sched<[WriteJump]>, NOTRACK;
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000173 def JMP32m_NT : I<0xFF, MRM4m, (outs), (ins i32mem : $dst), "jmp{l}\t{*}$dst",
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000174 [(X86NoTrackBrind (loadi32 addr : $dst))]>,
175 Requires<[Not64BitMode]>, OpSize32, Sched<[WriteJumpLd]>,
176 NOTRACK;
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000177
178 def JMP64r_NT : I<0xFF, MRM4r, (outs), (ins GR64 : $dst), "jmp{q}\t{*}$dst",
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000179 [(X86NoTrackBrind GR64 : $dst)]>, Requires<[In64BitMode]>,
180 Sched<[WriteJump]>, NOTRACK;
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000181 def JMP64m_NT : I<0xFF, MRM4m, (outs), (ins i64mem : $dst), "jmp{q}\t{*}$dst",
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000182 [(X86NoTrackBrind(loadi64 addr : $dst))]>,
183 Requires<[In64BitMode]>, Sched<[WriteJumpLd]>, NOTRACK;
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000184 }
185
Craig Topper429ae3d2018-04-30 06:21:21 +0000186 let Predicates = [Not64BitMode], AsmVariantName = "att" in {
Craig Topper35545fa2014-12-20 07:43:27 +0000187 def FARJMP16i : Iseg16<0xEA, RawFrmImm16, (outs),
188 (ins i16imm:$off, i16imm:$seg),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000189 "ljmp{w}\t$seg, $off", []>,
190 OpSize16, Sched<[WriteJump]>;
Craig Topper35545fa2014-12-20 07:43:27 +0000191 def FARJMP32i : Iseg32<0xEA, RawFrmImm16, (outs),
192 (ins i32imm:$off, i16imm:$seg),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000193 "ljmp{l}\t$seg, $off", []>,
194 OpSize32, Sched<[WriteJump]>;
Craig Topper35545fa2014-12-20 07:43:27 +0000195 }
Craig Topper33dc01d2018-05-01 04:42:00 +0000196 def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaquemem:$dst),
Craig Topper5a4c8802018-04-30 06:21:24 +0000197 "ljmp{q}\t{*}$dst", []>, Sched<[WriteJump]>, Requires<[In64BitMode]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000198
Craig Topperd94002c2018-04-30 06:21:23 +0000199 let AsmVariantName = "att" in
Craig Topper33dc01d2018-05-01 04:42:00 +0000200 def FARJMP16m : I<0xFF, MRM5m, (outs), (ins opaquemem:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000201 "ljmp{w}\t{*}$dst", []>, OpSize16, Sched<[WriteJumpLd]>;
Craig Topper33dc01d2018-05-01 04:42:00 +0000202 def FARJMP32m : I<0xFF, MRM5m, (outs), (ins opaquemem:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000203 "{l}jmp{l}\t{*}$dst", []>, OpSize32, Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000204}
205
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000206// Loop instructions
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000207let SchedRW = [WriteJump] in {
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000208def LOOP : Ii8PCRel<0xE2, RawFrm, (outs), (ins brtarget8:$dst), "loop\t$dst", []>;
209def LOOPE : Ii8PCRel<0xE1, RawFrm, (outs), (ins brtarget8:$dst), "loope\t$dst", []>;
210def LOOPNE : Ii8PCRel<0xE0, RawFrm, (outs), (ins brtarget8:$dst), "loopne\t$dst", []>;
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000211}
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000212
213//===----------------------------------------------------------------------===//
214// Call Instructions...
215//
216let isCall = 1 in
217 // All calls clobber the non-callee saved registers. ESP is marked as
218 // a use to prevent stack-pointer assignments that appear immediately
219 // before calls from potentially appearing dead. Uses for argument
220 // registers are added manually.
Oren Ben Simhonfa582b02017-11-26 13:02:45 +0000221 let Uses = [ESP, SSP] in {
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000222 def CALLpcrel32 : Ii32PCRel<0xE8, RawFrm,
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000223 (outs), (ins i32imm_pcrel:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000224 "call{l}\t$dst", []>, OpSize32,
Eric Christopherc0a5aae2013-12-20 02:04:49 +0000225 Requires<[Not64BitMode]>, Sched<[WriteJump]>;
Craig Topper23fd6952014-12-21 20:05:06 +0000226 let hasSideEffects = 0 in
227 def CALLpcrel16 : Ii16PCRel<0xE8, RawFrm,
228 (outs), (ins i16imm_pcrel:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000229 "call{w}\t$dst", []>, OpSize16,
Craig Topper23fd6952014-12-21 20:05:06 +0000230 Sched<[WriteJump]>;
David Woodhousefd460162014-01-08 12:57:49 +0000231 def CALL16r : I<0xFF, MRM2r, (outs), (ins GR16:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000232 "call{w}\t{*}$dst", [(X86call GR16:$dst)]>,
Craig Topperfa6298a2014-02-02 09:25:09 +0000233 OpSize16, Requires<[Not64BitMode]>, Sched<[WriteJump]>;
David Woodhousefd460162014-01-08 12:57:49 +0000234 def CALL16m : I<0xFF, MRM2m, (outs), (ins i16mem:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000235 "call{w}\t{*}$dst", [(X86call (loadi16 addr:$dst))]>,
236 OpSize16, Requires<[Not64BitMode,FavorMemIndirectCall]>,
237 Sched<[WriteJumpLd]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000238 def CALL32r : I<0xFF, MRM2r, (outs), (ins GR32:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000239 "call{l}\t{*}$dst", [(X86call GR32:$dst)]>, OpSize32,
Chandler Carruthae0cafe2018-08-23 06:06:38 +0000240 Requires<[Not64BitMode,NotUseRetpolineIndirectCalls]>,
241 Sched<[WriteJump]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000242 def CALL32m : I<0xFF, MRM2m, (outs), (ins i32mem:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000243 "call{l}\t{*}$dst", [(X86call (loadi32 addr:$dst))]>,
244 OpSize32,
Chandler Carruthae0cafe2018-08-23 06:06:38 +0000245 Requires<[Not64BitMode,FavorMemIndirectCall,
246 NotUseRetpolineIndirectCalls]>,
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000247 Sched<[WriteJumpLd]>;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000248
Alexander Ivchenko5c547422018-05-18 11:58:25 +0000249 // Non-tracking calls for IBT, use with caution.
250 let isCodeGenOnly = 1 in {
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000251 def CALL16r_NT : I<0xFF, MRM2r, (outs), (ins GR16 : $dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000252 "call{w}\t{*}$dst",[(X86NoTrackCall GR16 : $dst)]>,
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000253 OpSize16, Requires<[Not64BitMode]>, Sched<[WriteJump]>, NOTRACK;
254 def CALL16m_NT : I<0xFF, MRM2m, (outs), (ins i16mem : $dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000255 "call{w}\t{*}$dst",[(X86NoTrackCall(loadi16 addr : $dst))]>,
256 OpSize16, Requires<[Not64BitMode,FavorMemIndirectCall]>,
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000257 Sched<[WriteJumpLd]>, NOTRACK;
258 def CALL32r_NT : I<0xFF, MRM2r, (outs), (ins GR32 : $dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000259 "call{l}\t{*}$dst",[(X86NoTrackCall GR32 : $dst)]>,
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000260 OpSize32, Requires<[Not64BitMode]>, Sched<[WriteJump]>, NOTRACK;
261 def CALL32m_NT : I<0xFF, MRM2m, (outs), (ins i32mem : $dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000262 "call{l}\t{*}$dst",[(X86NoTrackCall(loadi32 addr : $dst))]>,
263 OpSize32, Requires<[Not64BitMode,FavorMemIndirectCall]>,
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000264 Sched<[WriteJumpLd]>, NOTRACK;
265 }
266
Craig Topper429ae3d2018-04-30 06:21:21 +0000267 let Predicates = [Not64BitMode], AsmVariantName = "att" in {
Craig Topper35545fa2014-12-20 07:43:27 +0000268 def FARCALL16i : Iseg16<0x9A, RawFrmImm16, (outs),
269 (ins i16imm:$off, i16imm:$seg),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000270 "lcall{w}\t$seg, $off", []>,
271 OpSize16, Sched<[WriteJump]>;
Craig Topper35545fa2014-12-20 07:43:27 +0000272 def FARCALL32i : Iseg32<0x9A, RawFrmImm16, (outs),
273 (ins i32imm:$off, i16imm:$seg),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000274 "lcall{l}\t$seg, $off", []>,
275 OpSize32, Sched<[WriteJump]>;
Craig Topper35545fa2014-12-20 07:43:27 +0000276 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000277
Craig Topper33dc01d2018-05-01 04:42:00 +0000278 def FARCALL16m : I<0xFF, MRM3m, (outs), (ins opaquemem:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000279 "lcall{w}\t{*}$dst", []>, OpSize16, Sched<[WriteJumpLd]>;
Craig Topper33dc01d2018-05-01 04:42:00 +0000280 def FARCALL32m : I<0xFF, MRM3m, (outs), (ins opaquemem:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000281 "{l}call{l}\t{*}$dst", []>, OpSize32, Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000282 }
283
284
285// Tail call stuff.
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000286let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
Craig Topper78e65072019-08-21 23:17:52 +0000287 isCodeGenOnly = 1, Uses = [ESP, SSP] in {
288 def TCRETURNdi : PseudoI<(outs), (ins i32imm_pcrel:$dst, i32imm:$offset),
289 []>, Sched<[WriteJump]>, NotMemoryFoldable;
290 def TCRETURNri : PseudoI<(outs), (ins ptr_rc_tailcall:$dst, i32imm:$offset),
291 []>, Sched<[WriteJump]>, NotMemoryFoldable;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000292 let mayLoad = 1 in
Craig Topper78e65072019-08-21 23:17:52 +0000293 def TCRETURNmi : PseudoI<(outs), (ins i32mem_TC:$dst, i32imm:$offset),
294 []>, Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000295
Craig Topperfc1f08c2019-08-27 17:24:23 +0000296 def TAILJMPd : PseudoI<(outs), (ins i32imm_pcrel:$dst),
297 []>, Sched<[WriteJump]>;
Hans Wennborg75e25f62016-09-07 17:52:14 +0000298
Craig Topperfc1f08c2019-08-27 17:24:23 +0000299 def TAILJMPr : PseudoI<(outs), (ins ptr_rc_tailcall:$dst),
300 []>, Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000301 let mayLoad = 1 in
Craig Topperfc1f08c2019-08-27 17:24:23 +0000302 def TAILJMPm : PseudoI<(outs), (ins i32mem_TC:$dst),
303 []>, Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000304}
305
Hans Wennborga4686012017-02-16 00:04:05 +0000306// Conditional tail calls are similar to the above, but they are branches
307// rather than barriers, and they use EFLAGS.
308let isCall = 1, isTerminator = 1, isReturn = 1, isBranch = 1,
Craig Topper78e65072019-08-21 23:17:52 +0000309 isCodeGenOnly = 1, SchedRW = [WriteJump] in
Oren Ben Simhonfa582b02017-11-26 13:02:45 +0000310 let Uses = [ESP, EFLAGS, SSP] in {
Hans Wennborga4686012017-02-16 00:04:05 +0000311 def TCRETURNdicc : PseudoI<(outs),
312 (ins i32imm_pcrel:$dst, i32imm:$offset, i32imm:$cond), []>;
313
314 // This gets substituted to a conditional jump instruction in MC lowering.
Craig Topperfc1f08c2019-08-27 17:24:23 +0000315 def TAILJMPd_CC : PseudoI<(outs), (ins i32imm_pcrel:$dst, i32imm:$cond), []>;
Hans Wennborga4686012017-02-16 00:04:05 +0000316}
317
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000318
319//===----------------------------------------------------------------------===//
320// Call Instructions...
321//
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000322
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000323// RSP is marked as a use to prevent stack-pointer assignments that appear
324// immediately before calls from potentially appearing dead. Uses for argument
325// registers are added manually.
Oren Ben Simhonfa582b02017-11-26 13:02:45 +0000326let isCall = 1, Uses = [RSP, SSP], SchedRW = [WriteJump] in {
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000327 // NOTE: this pattern doesn't match "X86call imm", because we do not know
328 // that the offset between an arbitrary immediate and the call will fit in
329 // the 32-bit pcrel field that we have.
330 def CALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000331 (outs), (ins i64i32imm_pcrel:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000332 "call{q}\t$dst", []>, OpSize32,
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000333 Requires<[In64BitMode]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000334 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000335 "call{q}\t{*}$dst", [(X86call GR64:$dst)]>,
Chandler Carruthae0cafe2018-08-23 06:06:38 +0000336 Requires<[In64BitMode,NotUseRetpolineIndirectCalls]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000337 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000338 "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
Chandler Carruthc58f2162018-01-22 22:05:25 +0000339 Requires<[In64BitMode,FavorMemIndirectCall,
Chandler Carruthae0cafe2018-08-23 06:06:38 +0000340 NotUseRetpolineIndirectCalls]>;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000341
Alexander Ivchenko5c547422018-05-18 11:58:25 +0000342 // Non-tracking calls for IBT, use with caution.
343 let isCodeGenOnly = 1 in {
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000344 def CALL64r_NT : I<0xFF, MRM2r, (outs), (ins GR64 : $dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000345 "call{q}\t{*}$dst",[(X86NoTrackCall GR64 : $dst)]>,
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000346 Requires<[In64BitMode]>, NOTRACK;
347 def CALL64m_NT : I<0xFF, MRM2m, (outs), (ins i64mem : $dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000348 "call{q}\t{*}$dst",
349 [(X86NoTrackCall(loadi64 addr : $dst))]>,
350 Requires<[In64BitMode,FavorMemIndirectCall]>, NOTRACK;
Oren Ben Simhonfdd72fd2018-03-17 13:29:46 +0000351 }
352
Craig Topper33dc01d2018-05-01 04:42:00 +0000353 def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaquemem:$dst),
Simon Pilgrim0cd0fbd2018-04-12 12:09:24 +0000354 "lcall{q}\t{*}$dst", []>;
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000355}
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000356
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000357let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
Craig Topper78e65072019-08-21 23:17:52 +0000358 isCodeGenOnly = 1, Uses = [RSP, SSP] in {
Hans Wennborg6ecf6192016-09-09 22:37:27 +0000359 def TCRETURNdi64 : PseudoI<(outs),
Craig Topper78e65072019-08-21 23:17:52 +0000360 (ins i64i32imm_pcrel:$dst, i32imm:$offset),
361 []>, Sched<[WriteJump]>;
Hans Wennborg6ecf6192016-09-09 22:37:27 +0000362 def TCRETURNri64 : PseudoI<(outs),
Craig Topper78e65072019-08-21 23:17:52 +0000363 (ins ptr_rc_tailcall:$dst, i32imm:$offset),
364 []>, Sched<[WriteJump]>, NotMemoryFoldable;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000365 let mayLoad = 1 in
Hans Wennborg6ecf6192016-09-09 22:37:27 +0000366 def TCRETURNmi64 : PseudoI<(outs),
Craig Topper78e65072019-08-21 23:17:52 +0000367 (ins i64mem_TC:$dst, i32imm:$offset),
368 []>, Sched<[WriteJumpLd]>, NotMemoryFoldable;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000369
Craig Topperfc1f08c2019-08-27 17:24:23 +0000370 def TAILJMPd64 : PseudoI<(outs), (ins i64i32imm_pcrel:$dst),
371 []>, Sched<[WriteJump]>;
Hans Wennborg6ecf6192016-09-09 22:37:27 +0000372
Craig Topperfc1f08c2019-08-27 17:24:23 +0000373 def TAILJMPr64 : PseudoI<(outs), (ins ptr_rc_tailcall:$dst),
374 []>, Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000375
376 let mayLoad = 1 in
Craig Topperfc1f08c2019-08-27 17:24:23 +0000377 def TAILJMPm64 : PseudoI<(outs), (ins i64mem_TC:$dst),
378 []>, Sched<[WriteJumpLd]>;
Reid Klecknera580b6e2015-01-30 21:03:31 +0000379
Hans Wennborgc39ef772016-09-08 23:35:10 +0000380 // Win64 wants indirect jumps leaving the function to have a REX_W prefix.
Reid Klecknera580b6e2015-01-30 21:03:31 +0000381 let hasREX_WPrefix = 1 in {
Craig Topperfc1f08c2019-08-27 17:24:23 +0000382 def TAILJMPr64_REX : PseudoI<(outs), (ins ptr_rc_tailcall:$dst),
383 []>, Sched<[WriteJump]>;
Reid Klecknera580b6e2015-01-30 21:03:31 +0000384
385 let mayLoad = 1 in
Craig Topperfc1f08c2019-08-27 17:24:23 +0000386 def TAILJMPm64_REX : PseudoI<(outs), (ins i64mem_TC:$dst),
387 []>, Sched<[WriteJumpLd]>;
Reid Klecknera580b6e2015-01-30 21:03:31 +0000388 }
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000389}
Hans Wennborga4686012017-02-16 00:04:05 +0000390
Chandler Carruthc58f2162018-01-22 22:05:25 +0000391let isPseudo = 1, isCall = 1, isCodeGenOnly = 1,
392 Uses = [RSP, SSP],
393 usesCustomInserter = 1,
394 SchedRW = [WriteJump] in {
395 def RETPOLINE_CALL32 :
396 PseudoI<(outs), (ins GR32:$dst), [(X86call GR32:$dst)]>,
Chandler Carruthae0cafe2018-08-23 06:06:38 +0000397 Requires<[Not64BitMode,UseRetpolineIndirectCalls]>;
Chandler Carruthc58f2162018-01-22 22:05:25 +0000398
399 def RETPOLINE_CALL64 :
400 PseudoI<(outs), (ins GR64:$dst), [(X86call GR64:$dst)]>,
Chandler Carruthae0cafe2018-08-23 06:06:38 +0000401 Requires<[In64BitMode,UseRetpolineIndirectCalls]>;
Chandler Carruthc58f2162018-01-22 22:05:25 +0000402
403 // Retpoline variant of indirect tail calls.
404 let isTerminator = 1, isReturn = 1, isBarrier = 1 in {
405 def RETPOLINE_TCRETURN64 :
406 PseudoI<(outs), (ins GR64:$dst, i32imm:$offset), []>;
407 def RETPOLINE_TCRETURN32 :
408 PseudoI<(outs), (ins GR32:$dst, i32imm:$offset), []>;
409 }
410}
411
Hans Wennborga4686012017-02-16 00:04:05 +0000412// Conditional tail calls are similar to the above, but they are branches
413// rather than barriers, and they use EFLAGS.
414let isCall = 1, isTerminator = 1, isReturn = 1, isBranch = 1,
Craig Topper78e65072019-08-21 23:17:52 +0000415 isCodeGenOnly = 1, SchedRW = [WriteJump] in
Oren Ben Simhonfa582b02017-11-26 13:02:45 +0000416 let Uses = [RSP, EFLAGS, SSP] in {
Hans Wennborga4686012017-02-16 00:04:05 +0000417 def TCRETURNdi64cc : PseudoI<(outs),
418 (ins i64i32imm_pcrel:$dst, i32imm:$offset,
419 i32imm:$cond), []>;
420
421 // This gets substituted to a conditional jump instruction in MC lowering.
Craig Topperfc1f08c2019-08-27 17:24:23 +0000422 def TAILJMPd64_CC : PseudoI<(outs),
423 (ins i64i32imm_pcrel:$dst, i32imm:$cond), []>;
Hans Wennborga4686012017-02-16 00:04:05 +0000424}