blob: 6ab961f04ecf4122d3ab9ffd75e25105dec880c6 [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//
Chris Lattnerae33f5d2010-10-05 06:04:14 +00003// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +00007//
Chris Lattnerae33f5d2010-10-05 06:04:14 +00008//===----------------------------------------------------------------------===//
9//
10// This file describes the X86 jump, return, call, and related instructions.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// Control Flow Instructions.
16//
17
18// Return instructions.
Jakob Stoklund Olesenb50cf8b2012-08-24 20:52:44 +000019//
20// The X86retflag return instructions are variadic because we may add ST0 and
21// ST1 arguments when returning values on the x87 stack.
Chris Lattnerae33f5d2010-10-05 06:04:14 +000022let isTerminator = 1, isReturn = 1, isBarrier = 1,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +000023 hasCtrlDep = 1, FPForm = SpecialFP, SchedRW = [WriteJumpLd] in {
David Woodhouse79dd5052014-01-08 12:58:07 +000024 def RETL : I <0xC3, RawFrm, (outs), (ins variable_ops),
Craig Topper6872fd32014-02-18 08:18:29 +000025 "ret{l}", [(X86retflag 0)], IIC_RET>, OpSize32,
26 Requires<[Not64BitMode]>;
David Woodhouse79dd5052014-01-08 12:58:07 +000027 def RETQ : I <0xC3, RawFrm, (outs), (ins variable_ops),
Craig Topper6872fd32014-02-18 08:18:29 +000028 "ret{q}", [(X86retflag 0)], IIC_RET>, OpSize32,
29 Requires<[In64BitMode]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +000030 def RETW : I <0xC3, RawFrm, (outs), (ins),
Charles Davis74c282b2012-04-11 01:10:53 +000031 "ret{w}",
Craig Topperfa6298a2014-02-02 09:25:09 +000032 [], IIC_RET>, OpSize16;
David Woodhouse4e033b02014-01-13 14:05:59 +000033 def RETIL : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
David Woodhouse79dd5052014-01-08 12:58:07 +000034 "ret{l}\t$amt",
Craig Topperfa6298a2014-02-02 09:25:09 +000035 [(X86retflag timm:$amt)], IIC_RET_IMM>, OpSize32,
David Woodhouse4e033b02014-01-13 14:05:59 +000036 Requires<[Not64BitMode]>;
37 def RETIQ : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
38 "ret{q}\t$amt",
Craig Topper6872fd32014-02-18 08:18:29 +000039 [(X86retflag timm:$amt)], IIC_RET_IMM>, OpSize32,
David Woodhouse4e033b02014-01-13 14:05:59 +000040 Requires<[In64BitMode]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +000041 def RETIW : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt),
Charles Davis74c282b2012-04-11 01:10:53 +000042 "ret{w}\t$amt",
Craig Topperfa6298a2014-02-02 09:25:09 +000043 [], IIC_RET_IMM>, OpSize16;
Chris Lattner87cf7f72010-11-12 18:54:56 +000044 def LRETL : I <0xCB, RawFrm, (outs), (ins),
Craig Topperfa6298a2014-02-02 09:25:09 +000045 "{l}ret{l|f}", [], IIC_RET>, OpSize32;
David Woodhouse4e033b02014-01-13 14:05:59 +000046 def LRETQ : RI <0xCB, RawFrm, (outs), (ins),
47 "{l}ret{|f}q", [], IIC_RET>, Requires<[In64BitMode]>;
Charles Davis74c282b2012-04-11 01:10:53 +000048 def LRETW : I <0xCB, RawFrm, (outs), (ins),
Craig Topperfa6298a2014-02-02 09:25:09 +000049 "{l}ret{w|f}", [], IIC_RET>, OpSize16;
David Woodhouse4e033b02014-01-13 14:05:59 +000050 def LRETIL : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
Craig Topperfa6298a2014-02-02 09:25:09 +000051 "{l}ret{l|f}\t$amt", [], IIC_RET>, OpSize32;
David Woodhouse4e033b02014-01-13 14:05:59 +000052 def LRETIQ : RIi16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
53 "{l}ret{|f}q\t$amt", [], IIC_RET>, Requires<[In64BitMode]>;
Kevin Enderbyb9783dd2010-10-18 17:04:36 +000054 def LRETIW : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
Craig Topperfa6298a2014-02-02 09:25:09 +000055 "{l}ret{w|f}\t$amt", [], IIC_RET>, OpSize16;
Chris Lattnerae33f5d2010-10-05 06:04:14 +000056}
57
58// Unconditional branches.
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +000059let isBarrier = 1, isBranch = 1, isTerminator = 1, SchedRW = [WriteJump] in {
Chris Lattnerae33f5d2010-10-05 06:04:14 +000060 def JMP_1 : Ii8PCRel<0xEB, RawFrm, (outs), (ins brtarget8:$dst),
Craig Topper49758aa2015-01-06 04:23:53 +000061 "jmp\t$dst", [(br bb:$dst)], IIC_JMP_REL>;
Craig Topper0f2c4ac2015-01-06 04:23:57 +000062 let hasSideEffects = 0, isCodeGenOnly = 1, ForceDisassemble = 1 in {
Craig Topper63944542015-01-06 08:59:30 +000063 def JMP_2 : Ii16PCRel<0xE9, RawFrm, (outs), (ins brtarget16:$dst),
Craig Topper49758aa2015-01-06 04:23:53 +000064 "jmp\t$dst", [], IIC_JMP_REL>, OpSize16;
Craig Topper63944542015-01-06 08:59:30 +000065 def JMP_4 : Ii32PCRel<0xE9, RawFrm, (outs), (ins brtarget32:$dst),
Craig Topper49758aa2015-01-06 04:23:53 +000066 "jmp\t$dst", [], IIC_JMP_REL>, OpSize32;
67 }
Chris Lattnerae33f5d2010-10-05 06:04:14 +000068}
69
70// Conditional Branches.
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +000071let isBranch = 1, isTerminator = 1, Uses = [EFLAGS], SchedRW = [WriteJump] in {
Chris Lattnerae33f5d2010-10-05 06:04:14 +000072 multiclass ICBr<bits<8> opc1, bits<8> opc4, string asm, PatFrag Cond> {
Craig Topper49758aa2015-01-06 04:23:53 +000073 def _1 : Ii8PCRel <opc1, RawFrm, (outs), (ins brtarget8:$dst), asm,
74 [(X86brcond bb:$dst, Cond, EFLAGS)], IIC_Jcc>;
Craig Topper0f2c4ac2015-01-06 04:23:57 +000075 let hasSideEffects = 0, isCodeGenOnly = 1, ForceDisassemble = 1 in {
Craig Topper63944542015-01-06 08:59:30 +000076 def _2 : Ii16PCRel<opc4, RawFrm, (outs), (ins brtarget16:$dst), asm,
Craig Topper49758aa2015-01-06 04:23:53 +000077 [], IIC_Jcc>, OpSize16, TB;
Craig Topper63944542015-01-06 08:59:30 +000078 def _4 : Ii32PCRel<opc4, RawFrm, (outs), (ins brtarget32:$dst), asm,
Craig Topper49758aa2015-01-06 04:23:53 +000079 [], IIC_Jcc>, TB, OpSize32;
80 }
Chris Lattnerae33f5d2010-10-05 06:04:14 +000081 }
82}
83
84defm JO : ICBr<0x70, 0x80, "jo\t$dst" , X86_COND_O>;
Craig Topper49758aa2015-01-06 04:23:53 +000085defm JNO : ICBr<0x71, 0x81, "jno\t$dst", X86_COND_NO>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +000086defm JB : ICBr<0x72, 0x82, "jb\t$dst" , X86_COND_B>;
87defm JAE : ICBr<0x73, 0x83, "jae\t$dst", X86_COND_AE>;
88defm JE : ICBr<0x74, 0x84, "je\t$dst" , X86_COND_E>;
89defm JNE : ICBr<0x75, 0x85, "jne\t$dst", X86_COND_NE>;
90defm JBE : ICBr<0x76, 0x86, "jbe\t$dst", X86_COND_BE>;
91defm JA : ICBr<0x77, 0x87, "ja\t$dst" , X86_COND_A>;
92defm JS : ICBr<0x78, 0x88, "js\t$dst" , X86_COND_S>;
93defm JNS : ICBr<0x79, 0x89, "jns\t$dst", X86_COND_NS>;
94defm JP : ICBr<0x7A, 0x8A, "jp\t$dst" , X86_COND_P>;
95defm JNP : ICBr<0x7B, 0x8B, "jnp\t$dst", X86_COND_NP>;
96defm JL : ICBr<0x7C, 0x8C, "jl\t$dst" , X86_COND_L>;
97defm JGE : ICBr<0x7D, 0x8D, "jge\t$dst", X86_COND_GE>;
98defm JLE : ICBr<0x7E, 0x8E, "jle\t$dst", X86_COND_LE>;
99defm JG : ICBr<0x7F, 0x8F, "jg\t$dst" , X86_COND_G>;
100
101// jcx/jecx/jrcx instructions.
Craig Topper8a1028f2013-09-03 03:56:17 +0000102let isBranch = 1, isTerminator = 1, hasSideEffects = 0, SchedRW = [WriteJump] in {
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000103 // These are the 32-bit versions of this instruction for the asmparser. In
104 // 32-bit mode, the address size prefix is jcxz and the unprefixed version is
105 // jecxz.
106 let Uses = [CX] in
107 def JCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
Craig Topper055845f2015-01-02 07:02:25 +0000108 "jcxz\t$dst", [], IIC_JCXZ>, AdSize16;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000109 let Uses = [ECX] in
Craig Topper055845f2015-01-02 07:02:25 +0000110 def JECXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
111 "jecxz\t$dst", [], IIC_JCXZ>, AdSize32;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000112
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000113 let Uses = [RCX] in
114 def JRCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
Craig Topper055845f2015-01-02 07:02:25 +0000115 "jrcxz\t$dst", [], IIC_JCXZ>, AdSize64;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000116}
117
118// Indirect branches
119let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
David Woodhousefd460162014-01-08 12:57:49 +0000120 def JMP16r : I<0xFF, MRM4r, (outs), (ins GR16:$dst), "jmp{w}\t{*}$dst",
121 [(brind GR16:$dst)], IIC_JMP_REG>, Requires<[Not64BitMode]>,
Craig Topperfa6298a2014-02-02 09:25:09 +0000122 OpSize16, Sched<[WriteJump]>;
David Woodhousefd460162014-01-08 12:57:49 +0000123 def JMP16m : I<0xFF, MRM4m, (outs), (ins i16mem:$dst), "jmp{w}\t{*}$dst",
124 [(brind (loadi16 addr:$dst))], IIC_JMP_MEM>,
Craig Topperfa6298a2014-02-02 09:25:09 +0000125 Requires<[Not64BitMode]>, OpSize16, Sched<[WriteJumpLd]>;
David Woodhousefd460162014-01-08 12:57:49 +0000126
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000127 def JMP32r : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst",
Eric Christopherc0a5aae2013-12-20 02:04:49 +0000128 [(brind GR32:$dst)], IIC_JMP_REG>, Requires<[Not64BitMode]>,
Craig Topperfa6298a2014-02-02 09:25:09 +0000129 OpSize32, Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000130 def JMP32m : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst",
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000131 [(brind (loadi32 addr:$dst))], IIC_JMP_MEM>,
Craig Topperfa6298a2014-02-02 09:25:09 +0000132 Requires<[Not64BitMode]>, OpSize32, Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000133
134 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000135 [(brind GR64:$dst)], IIC_JMP_REG>, Requires<[In64BitMode]>,
136 Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000137 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000138 [(brind (loadi64 addr:$dst))], IIC_JMP_MEM>,
139 Requires<[In64BitMode]>, Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000140
Craig Topper35545fa2014-12-20 07:43:27 +0000141 let Predicates = [Not64BitMode] in {
142 def FARJMP16i : Iseg16<0xEA, RawFrmImm16, (outs),
143 (ins i16imm:$off, i16imm:$seg),
Craig Topper35640802014-12-20 23:05:52 +0000144 "ljmp{w}\t$seg, $off", [],
Craig Topper35545fa2014-12-20 07:43:27 +0000145 IIC_JMP_FAR_PTR>, OpSize16, Sched<[WriteJump]>;
146 def FARJMP32i : Iseg32<0xEA, RawFrmImm16, (outs),
147 (ins i32imm:$off, i16imm:$seg),
Craig Topper35640802014-12-20 23:05:52 +0000148 "ljmp{l}\t$seg, $off", [],
Craig Topper35545fa2014-12-20 07:43:27 +0000149 IIC_JMP_FAR_PTR>, OpSize32, Sched<[WriteJump]>;
150 }
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000151 def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaque80mem:$dst),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000152 "ljmp{q}\t{*}$dst", [], IIC_JMP_FAR_MEM>,
153 Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000154
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000155 def FARJMP16m : I<0xFF, MRM5m, (outs), (ins opaque32mem:$dst),
Craig Topperfa6298a2014-02-02 09:25:09 +0000156 "ljmp{w}\t{*}$dst", [], IIC_JMP_FAR_MEM>, OpSize16,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000157 Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000158 def FARJMP32m : I<0xFF, MRM5m, (outs), (ins opaque48mem:$dst),
Craig Topperfa6298a2014-02-02 09:25:09 +0000159 "ljmp{l}\t{*}$dst", [], IIC_JMP_FAR_MEM>, OpSize32,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000160 Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000161}
162
163
164// Loop instructions
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000165let SchedRW = [WriteJump] in {
Andrew Trick8523b162012-02-01 23:20:51 +0000166def LOOP : Ii8PCRel<0xE2, RawFrm, (outs), (ins brtarget8:$dst), "loop\t$dst", [], IIC_LOOP>;
167def LOOPE : Ii8PCRel<0xE1, RawFrm, (outs), (ins brtarget8:$dst), "loope\t$dst", [], IIC_LOOPE>;
168def LOOPNE : Ii8PCRel<0xE0, RawFrm, (outs), (ins brtarget8:$dst), "loopne\t$dst", [], IIC_LOOPNE>;
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000169}
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000170
171//===----------------------------------------------------------------------===//
172// Call Instructions...
173//
174let isCall = 1 in
175 // All calls clobber the non-callee saved registers. ESP is marked as
176 // a use to prevent stack-pointer assignments that appear immediately
177 // before calls from potentially appearing dead. Uses for argument
178 // registers are added manually.
Jakob Stoklund Olesen8a450cb2012-02-16 00:02:50 +0000179 let Uses = [ESP] in {
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000180 def CALLpcrel32 : Ii32PCRel<0xE8, RawFrm,
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000181 (outs), (ins i32imm_pcrel:$dst),
Craig Topperfa6298a2014-02-02 09:25:09 +0000182 "call{l}\t$dst", [], IIC_CALL_RI>, OpSize32,
Eric Christopherc0a5aae2013-12-20 02:04:49 +0000183 Requires<[Not64BitMode]>, Sched<[WriteJump]>;
Craig Topper23fd6952014-12-21 20:05:06 +0000184 let hasSideEffects = 0 in
185 def CALLpcrel16 : Ii16PCRel<0xE8, RawFrm,
186 (outs), (ins i16imm_pcrel:$dst),
187 "call{w}\t$dst", [], IIC_CALL_RI>, OpSize16,
188 Sched<[WriteJump]>;
David Woodhousefd460162014-01-08 12:57:49 +0000189 def CALL16r : I<0xFF, MRM2r, (outs), (ins GR16:$dst),
190 "call{w}\t{*}$dst", [(X86call GR16:$dst)], IIC_CALL_RI>,
Craig Topperfa6298a2014-02-02 09:25:09 +0000191 OpSize16, Requires<[Not64BitMode]>, Sched<[WriteJump]>;
David Woodhousefd460162014-01-08 12:57:49 +0000192 def CALL16m : I<0xFF, MRM2m, (outs), (ins i16mem:$dst),
193 "call{w}\t{*}$dst", [(X86call (loadi16 addr:$dst))],
Craig Topperfa6298a2014-02-02 09:25:09 +0000194 IIC_CALL_MEM>, OpSize16,
David Woodhousefd460162014-01-08 12:57:49 +0000195 Requires<[Not64BitMode,FavorMemIndirectCall]>,
196 Sched<[WriteJumpLd]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000197 def CALL32r : I<0xFF, MRM2r, (outs), (ins GR32:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000198 "call{l}\t{*}$dst", [(X86call GR32:$dst)], IIC_CALL_RI>,
Craig Topperfa6298a2014-02-02 09:25:09 +0000199 OpSize32, Requires<[Not64BitMode]>, Sched<[WriteJump]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000200 def CALL32m : I<0xFF, MRM2m, (outs), (ins i32mem:$dst),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000201 "call{l}\t{*}$dst", [(X86call (loadi32 addr:$dst))],
Craig Topperfa6298a2014-02-02 09:25:09 +0000202 IIC_CALL_MEM>, OpSize32,
Eric Christopherc0a5aae2013-12-20 02:04:49 +0000203 Requires<[Not64BitMode,FavorMemIndirectCall]>,
Michael Liao96b42602013-03-28 23:13:21 +0000204 Sched<[WriteJumpLd]>;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000205
Craig Topper35545fa2014-12-20 07:43:27 +0000206 let Predicates = [Not64BitMode] in {
207 def FARCALL16i : Iseg16<0x9A, RawFrmImm16, (outs),
208 (ins i16imm:$off, i16imm:$seg),
Craig Topper35640802014-12-20 23:05:52 +0000209 "lcall{w}\t$seg, $off", [],
Craig Topper35545fa2014-12-20 07:43:27 +0000210 IIC_CALL_FAR_PTR>, OpSize16, Sched<[WriteJump]>;
211 def FARCALL32i : Iseg32<0x9A, RawFrmImm16, (outs),
212 (ins i32imm:$off, i16imm:$seg),
Craig Topper35640802014-12-20 23:05:52 +0000213 "lcall{l}\t$seg, $off", [],
Craig Topper35545fa2014-12-20 07:43:27 +0000214 IIC_CALL_FAR_PTR>, OpSize32, Sched<[WriteJump]>;
215 }
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000216
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000217 def FARCALL16m : I<0xFF, MRM3m, (outs), (ins opaque32mem:$dst),
Craig Topperfa6298a2014-02-02 09:25:09 +0000218 "lcall{w}\t{*}$dst", [], IIC_CALL_FAR_MEM>, OpSize16,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000219 Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000220 def FARCALL32m : I<0xFF, MRM3m, (outs), (ins opaque48mem:$dst),
Craig Topperfa6298a2014-02-02 09:25:09 +0000221 "lcall{l}\t{*}$dst", [], IIC_CALL_FAR_MEM>, OpSize32,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000222 Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000223 }
224
225
226// Tail call stuff.
227
228let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000229 isCodeGenOnly = 1, SchedRW = [WriteJumpLd] in
Jakob Stoklund Olesen8a450cb2012-02-16 00:02:50 +0000230 let Uses = [ESP] in {
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000231 def TCRETURNdi : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000232 (ins i32imm_pcrel:$dst, i32imm:$offset), []>;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000233 def TCRETURNri : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000234 (ins ptr_rc_tailcall:$dst, i32imm:$offset), []>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000235 let mayLoad = 1 in
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000236 def TCRETURNmi : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000237 (ins i32mem_TC:$dst, i32imm:$offset), []>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000238
239 // FIXME: The should be pseudo instructions that are lowered when going to
240 // mcinst.
241 def TAILJMPd : Ii32PCRel<0xE9, RawFrm, (outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000242 (ins i32imm_pcrel:$dst),
Reid Klecknera580b6e2015-01-30 21:03:31 +0000243 "jmp\t$dst",
Andrew Trick8523b162012-02-01 23:20:51 +0000244 [], IIC_JMP_REL>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000245 def TAILJMPr : I<0xFF, MRM4r, (outs), (ins ptr_rc_tailcall:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000246 "", [], IIC_JMP_REG>; // FIXME: Remove encoding when JIT is dead.
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000247 let mayLoad = 1 in
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000248 def TAILJMPm : I<0xFF, MRM4m, (outs), (ins i32mem_TC:$dst),
Reid Klecknera580b6e2015-01-30 21:03:31 +0000249 "jmp{l}\t{*}$dst", [], IIC_JMP_MEM>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000250}
251
252
253//===----------------------------------------------------------------------===//
254// Call Instructions...
255//
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000256
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000257// RSP is marked as a use to prevent stack-pointer assignments that appear
258// immediately before calls from potentially appearing dead. Uses for argument
259// registers are added manually.
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000260let isCall = 1, Uses = [RSP], SchedRW = [WriteJump] in {
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000261 // NOTE: this pattern doesn't match "X86call imm", because we do not know
262 // that the offset between an arbitrary immediate and the call will fit in
263 // the 32-bit pcrel field that we have.
264 def CALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000265 (outs), (ins i64i32imm_pcrel:$dst),
Craig Topper6872fd32014-02-18 08:18:29 +0000266 "call{q}\t$dst", [], IIC_CALL_RI>, OpSize32,
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000267 Requires<[In64BitMode]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000268 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst),
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000269 "call{q}\t{*}$dst", [(X86call GR64:$dst)],
270 IIC_CALL_RI>,
271 Requires<[In64BitMode]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000272 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst),
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000273 "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))],
274 IIC_CALL_MEM>,
Michael Liao96b42602013-03-28 23:13:21 +0000275 Requires<[In64BitMode,FavorMemIndirectCall]>;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000276
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000277 def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaque80mem:$dst),
278 "lcall{q}\t{*}$dst", [], IIC_CALL_FAR_MEM>;
279}
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000280
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000281let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000282 isCodeGenOnly = 1, Uses = [RSP], usesCustomInserter = 1,
283 SchedRW = [WriteJump] in {
Eric Christophera8706582010-11-30 21:37:36 +0000284 def TCRETURNdi64 : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000285 (ins i64i32imm_pcrel:$dst, i32imm:$offset),
Eric Christophera8706582010-11-30 21:37:36 +0000286 []>;
287 def TCRETURNri64 : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000288 (ins ptr_rc_tailcall:$dst, i32imm:$offset), []>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000289 let mayLoad = 1 in
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000290 def TCRETURNmi64 : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000291 (ins i64mem_TC:$dst, i32imm:$offset), []>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000292
Reid Klecknera580b6e2015-01-30 21:03:31 +0000293 def TAILJMPd64 : Ii32PCRel<0xE9, RawFrm, (outs), (ins i64i32imm_pcrel:$dst),
294 "jmp\t$dst", [], IIC_JMP_REL>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000295 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins ptr_rc_tailcall:$dst),
Reid Klecknera580b6e2015-01-30 21:03:31 +0000296 "jmp{q}\t{*}$dst", [], IIC_JMP_MEM>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000297
298 let mayLoad = 1 in
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000299 def TAILJMPm64 : I<0xFF, MRM4m, (outs), (ins i64mem_TC:$dst),
Reid Klecknera580b6e2015-01-30 21:03:31 +0000300 "jmp{q}\t{*}$dst", [], IIC_JMP_MEM>;
301
302 // Win64 wants jumps leaving the function to have a REX_W prefix.
303 let hasREX_WPrefix = 1 in {
304 def TAILJMPd64_REX : Ii32PCRel<0xE9, RawFrm, (outs),
305 (ins i64i32imm_pcrel:$dst),
306 "rex64 jmp\t$dst", [], IIC_JMP_REL>;
307 def TAILJMPr64_REX : I<0xFF, MRM4r, (outs), (ins ptr_rc_tailcall:$dst),
308 "rex64 jmp{q}\t{*}$dst", [], IIC_JMP_MEM>;
309
310 let mayLoad = 1 in
311 def TAILJMPm64_REX : I<0xFF, MRM4m, (outs), (ins i64mem_TC:$dst),
312 "rex64 jmp{q}\t{*}$dst", [], IIC_JMP_MEM>;
313 }
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000314}