blob: 7295cf1b8d5e35b39ca41eb0eab2bf6ef87c8f3a [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),
25 "ret{l}",
26 [(X86retflag 0)], IIC_RET>, OpSize16, Requires<[Not64BitMode]>;
27 def RETQ : I <0xC3, RawFrm, (outs), (ins variable_ops),
28 "ret{q}",
29 [(X86retflag 0)], IIC_RET>, 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}",
32 [], IIC_RET>, OpSize;
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",
David Woodhouse4e033b02014-01-13 14:05:59 +000035 [(X86retflag timm:$amt)], IIC_RET_IMM>, OpSize16,
36 Requires<[Not64BitMode]>;
37 def RETIQ : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
38 "ret{q}\t$amt",
39 [(X86retflag timm:$amt)], IIC_RET_IMM>,
40 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",
Andrew Trick8523b162012-02-01 23:20:51 +000043 [], IIC_RET_IMM>, OpSize;
Chris Lattner87cf7f72010-11-12 18:54:56 +000044 def LRETL : I <0xCB, RawFrm, (outs), (ins),
David Woodhouse956965c2014-01-08 12:57:40 +000045 "{l}ret{l|f}", [], IIC_RET>, OpSize16;
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),
49 "{l}ret{w|f}", [], IIC_RET>, OpSize;
David Woodhouse4e033b02014-01-13 14:05:59 +000050 def LRETIL : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
David Woodhouse956965c2014-01-08 12:57:40 +000051 "{l}ret{l|f}\t$amt", [], IIC_RET>, OpSize16;
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),
Charles Davis74c282b2012-04-11 01:10:53 +000055 "{l}ret{w|f}\t$amt", [], IIC_RET>, OpSize;
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_4 : Ii32PCRel<0xE9, RawFrm, (outs), (ins brtarget:$dst),
David Woodhouse956965c2014-01-08 12:57:40 +000061 "jmp\t$dst", [(br bb:$dst)], IIC_JMP_REL>, OpSize16;
David Woodhouse9785f5122014-01-08 12:58:36 +000062 def JMP_2 : Ii16PCRel<0xE9, RawFrm, (outs), (ins brtarget:$dst),
63 "jmp\t$dst", [(br bb:$dst)], IIC_JMP_REL>, OpSize,
64 Requires<[In16BitMode]>;
Craig Topper8a1028f2013-09-03 03:56:17 +000065 let hasSideEffects = 0 in
Chris Lattnerae33f5d2010-10-05 06:04:14 +000066 def JMP_1 : Ii8PCRel<0xEB, RawFrm, (outs), (ins brtarget8:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +000067 "jmp\t$dst", [], IIC_JMP_REL>;
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 Topper8a1028f2013-09-03 03:56:17 +000073 let hasSideEffects = 0 in
Andrew Trick8523b162012-02-01 23:20:51 +000074 def _1 : Ii8PCRel <opc1, RawFrm, (outs), (ins brtarget8:$dst), asm, [],
75 IIC_Jcc>;
David Woodhouse9785f5122014-01-08 12:58:36 +000076 def _2 : Ii16PCRel<opc4, RawFrm, (outs), (ins brtarget:$dst), asm,
77 [(X86brcond bb:$dst, Cond, EFLAGS)], IIC_Jcc>, OpSize,
78 TB, Requires<[In16BitMode]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +000079 def _4 : Ii32PCRel<opc4, RawFrm, (outs), (ins brtarget:$dst), asm,
David Woodhouse956965c2014-01-08 12:57:40 +000080 [(X86brcond bb:$dst, Cond, EFLAGS)], IIC_Jcc>, TB,
81 OpSize16;
Chris Lattnerae33f5d2010-10-05 06:04:14 +000082 }
83}
84
85defm JO : ICBr<0x70, 0x80, "jo\t$dst" , X86_COND_O>;
86defm JNO : ICBr<0x71, 0x81, "jno\t$dst" , X86_COND_NO>;
87defm JB : ICBr<0x72, 0x82, "jb\t$dst" , X86_COND_B>;
88defm JAE : ICBr<0x73, 0x83, "jae\t$dst", X86_COND_AE>;
89defm JE : ICBr<0x74, 0x84, "je\t$dst" , X86_COND_E>;
90defm JNE : ICBr<0x75, 0x85, "jne\t$dst", X86_COND_NE>;
91defm JBE : ICBr<0x76, 0x86, "jbe\t$dst", X86_COND_BE>;
92defm JA : ICBr<0x77, 0x87, "ja\t$dst" , X86_COND_A>;
93defm JS : ICBr<0x78, 0x88, "js\t$dst" , X86_COND_S>;
94defm JNS : ICBr<0x79, 0x89, "jns\t$dst", X86_COND_NS>;
95defm JP : ICBr<0x7A, 0x8A, "jp\t$dst" , X86_COND_P>;
96defm JNP : ICBr<0x7B, 0x8B, "jnp\t$dst", X86_COND_NP>;
97defm JL : ICBr<0x7C, 0x8C, "jl\t$dst" , X86_COND_L>;
98defm JGE : ICBr<0x7D, 0x8D, "jge\t$dst", X86_COND_GE>;
99defm JLE : ICBr<0x7E, 0x8E, "jle\t$dst", X86_COND_LE>;
100defm JG : ICBr<0x7F, 0x8F, "jg\t$dst" , X86_COND_G>;
101
102// jcx/jecx/jrcx instructions.
Craig Topper8a1028f2013-09-03 03:56:17 +0000103let isBranch = 1, isTerminator = 1, hasSideEffects = 0, SchedRW = [WriteJump] in {
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000104 // These are the 32-bit versions of this instruction for the asmparser. In
105 // 32-bit mode, the address size prefix is jcxz and the unprefixed version is
106 // jecxz.
107 let Uses = [CX] in
108 def JCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
Eric Christopherc0a5aae2013-12-20 02:04:49 +0000109 "jcxz\t$dst", [], IIC_JCXZ>, AdSize, Requires<[Not64BitMode]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000110 let Uses = [ECX] in
111 def JECXZ_32 : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
Eric Christopherc0a5aae2013-12-20 02:04:49 +0000112 "jecxz\t$dst", [], IIC_JCXZ>, Requires<[Not64BitMode]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000113
114 // J*CXZ instruction: 64-bit versions of this instruction for the asmparser.
115 // In 64-bit mode, the address size prefix is jecxz and the unprefixed version
116 // is jrcxz.
117 let Uses = [ECX] in
118 def JECXZ_64 : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000119 "jecxz\t$dst", [], IIC_JCXZ>, AdSize, Requires<[In64BitMode]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000120 let Uses = [RCX] in
121 def JRCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000122 "jrcxz\t$dst", [], IIC_JCXZ>, 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",
128 [(brind GR16:$dst)], IIC_JMP_REG>, Requires<[Not64BitMode]>,
129 OpSize, Sched<[WriteJump]>;
130 def JMP16m : I<0xFF, MRM4m, (outs), (ins i16mem:$dst), "jmp{w}\t{*}$dst",
131 [(brind (loadi16 addr:$dst))], IIC_JMP_MEM>,
132 Requires<[Not64BitMode]>, OpSize, Sched<[WriteJumpLd]>;
133
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000134 def JMP32r : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst",
Eric Christopherc0a5aae2013-12-20 02:04:49 +0000135 [(brind GR32:$dst)], IIC_JMP_REG>, Requires<[Not64BitMode]>,
David Woodhouse956965c2014-01-08 12:57:40 +0000136 OpSize16, Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000137 def JMP32m : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst",
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000138 [(brind (loadi32 addr:$dst))], IIC_JMP_MEM>,
David Woodhouse956965c2014-01-08 12:57:40 +0000139 Requires<[Not64BitMode]>, OpSize16, Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000140
141 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000142 [(brind GR64:$dst)], IIC_JMP_REG>, 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",
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000145 [(brind (loadi64 addr:$dst))], IIC_JMP_MEM>,
146 Requires<[In64BitMode]>, Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000147
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000148 def FARJMP16i : Iseg16<0xEA, RawFrmImm16, (outs),
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000149 (ins i16imm:$off, i16imm:$seg),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000150 "ljmp{w}\t{$seg, $off|$off, $seg}", [],
151 IIC_JMP_FAR_PTR>, OpSize, Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000152 def FARJMP32i : Iseg32<0xEA, RawFrmImm16, (outs),
153 (ins i32imm:$off, i16imm:$seg),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000154 "ljmp{l}\t{$seg, $off|$off, $seg}", [],
David Woodhouse956965c2014-01-08 12:57:40 +0000155 IIC_JMP_FAR_PTR>, OpSize16, Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000156 def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaque80mem:$dst),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000157 "ljmp{q}\t{*}$dst", [], IIC_JMP_FAR_MEM>,
158 Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000159
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000160 def FARJMP16m : I<0xFF, MRM5m, (outs), (ins opaque32mem:$dst),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000161 "ljmp{w}\t{*}$dst", [], IIC_JMP_FAR_MEM>, OpSize,
162 Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000163 def FARJMP32m : I<0xFF, MRM5m, (outs), (ins opaque48mem:$dst),
David Woodhouse956965c2014-01-08 12:57:40 +0000164 "ljmp{l}\t{*}$dst", [], IIC_JMP_FAR_MEM>, OpSize16,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000165 Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000166}
167
168
169// Loop instructions
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000170let SchedRW = [WriteJump] in {
Andrew Trick8523b162012-02-01 23:20:51 +0000171def LOOP : Ii8PCRel<0xE2, RawFrm, (outs), (ins brtarget8:$dst), "loop\t$dst", [], IIC_LOOP>;
172def LOOPE : Ii8PCRel<0xE1, RawFrm, (outs), (ins brtarget8:$dst), "loope\t$dst", [], IIC_LOOPE>;
173def LOOPNE : Ii8PCRel<0xE0, RawFrm, (outs), (ins brtarget8:$dst), "loopne\t$dst", [], IIC_LOOPNE>;
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000174}
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000175
176//===----------------------------------------------------------------------===//
177// Call Instructions...
178//
179let isCall = 1 in
180 // All calls clobber the non-callee saved registers. ESP is marked as
181 // a use to prevent stack-pointer assignments that appear immediately
182 // before calls from potentially appearing dead. Uses for argument
183 // registers are added manually.
Jakob Stoklund Olesen8a450cb2012-02-16 00:02:50 +0000184 let Uses = [ESP] in {
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000185 def CALLpcrel32 : Ii32PCRel<0xE8, RawFrm,
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000186 (outs), (ins i32imm_pcrel:$dst),
David Woodhouse956965c2014-01-08 12:57:40 +0000187 "call{l}\t$dst", [], IIC_CALL_RI>, OpSize16,
Eric Christopherc0a5aae2013-12-20 02:04:49 +0000188 Requires<[Not64BitMode]>, Sched<[WriteJump]>;
David Woodhouse70ced3e2014-01-20 12:02:40 +0000189 def CALLpcrel16 : Ii16PCRel<0xE8, RawFrm,
190 (outs), (ins i16imm_pcrel:$dst),
191 "call{w}\t$dst", [], IIC_CALL_RI>, OpSize,
192 Sched<[WriteJump]>;
David Woodhousefd460162014-01-08 12:57:49 +0000193 def CALL16r : I<0xFF, MRM2r, (outs), (ins GR16:$dst),
194 "call{w}\t{*}$dst", [(X86call GR16:$dst)], IIC_CALL_RI>,
195 OpSize, Requires<[Not64BitMode]>, Sched<[WriteJump]>;
196 def CALL16m : I<0xFF, MRM2m, (outs), (ins i16mem:$dst),
197 "call{w}\t{*}$dst", [(X86call (loadi16 addr:$dst))],
198 IIC_CALL_MEM>, OpSize,
199 Requires<[Not64BitMode,FavorMemIndirectCall]>,
200 Sched<[WriteJumpLd]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000201 def CALL32r : I<0xFF, MRM2r, (outs), (ins GR32:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000202 "call{l}\t{*}$dst", [(X86call GR32:$dst)], IIC_CALL_RI>,
David Woodhouse956965c2014-01-08 12:57:40 +0000203 OpSize16, Requires<[Not64BitMode]>, Sched<[WriteJump]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000204 def CALL32m : I<0xFF, MRM2m, (outs), (ins i32mem:$dst),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000205 "call{l}\t{*}$dst", [(X86call (loadi32 addr:$dst))],
David Woodhouse956965c2014-01-08 12:57:40 +0000206 IIC_CALL_MEM>, OpSize16,
Eric Christopherc0a5aae2013-12-20 02:04:49 +0000207 Requires<[Not64BitMode,FavorMemIndirectCall]>,
Michael Liao96b42602013-03-28 23:13:21 +0000208 Sched<[WriteJumpLd]>;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000209
210 def FARCALL16i : Iseg16<0x9A, RawFrmImm16, (outs),
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000211 (ins i16imm:$off, i16imm:$seg),
Andrew Trick8523b162012-02-01 23:20:51 +0000212 "lcall{w}\t{$seg, $off|$off, $seg}", [],
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000213 IIC_CALL_FAR_PTR>, OpSize, Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000214 def FARCALL32i : Iseg32<0x9A, RawFrmImm16, (outs),
215 (ins i32imm:$off, i16imm:$seg),
Andrew Trick8523b162012-02-01 23:20:51 +0000216 "lcall{l}\t{$seg, $off|$off, $seg}", [],
David Woodhouse956965c2014-01-08 12:57:40 +0000217 IIC_CALL_FAR_PTR>, OpSize16, Sched<[WriteJump]>;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000218
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000219 def FARCALL16m : I<0xFF, MRM3m, (outs), (ins opaque32mem:$dst),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000220 "lcall{w}\t{*}$dst", [], IIC_CALL_FAR_MEM>, OpSize,
221 Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000222 def FARCALL32m : I<0xFF, MRM3m, (outs), (ins opaque48mem:$dst),
David Woodhouse956965c2014-01-08 12:57:40 +0000223 "lcall{l}\t{*}$dst", [], IIC_CALL_FAR_MEM>, OpSize16,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000224 Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000225 }
226
227
228// Tail call stuff.
229
230let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000231 isCodeGenOnly = 1, SchedRW = [WriteJumpLd] in
Jakob Stoklund Olesen8a450cb2012-02-16 00:02:50 +0000232 let Uses = [ESP] in {
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000233 def TCRETURNdi : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000234 (ins i32imm_pcrel:$dst, i32imm:$offset), []>;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000235 def TCRETURNri : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000236 (ins ptr_rc_tailcall:$dst, i32imm:$offset), []>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000237 let mayLoad = 1 in
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000238 def TCRETURNmi : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000239 (ins i32mem_TC:$dst, i32imm:$offset), []>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000240
241 // FIXME: The should be pseudo instructions that are lowered when going to
242 // mcinst.
243 def TAILJMPd : Ii32PCRel<0xE9, RawFrm, (outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000244 (ins i32imm_pcrel:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000245 "jmp\t$dst # TAILCALL",
246 [], IIC_JMP_REL>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000247 def TAILJMPr : I<0xFF, MRM4r, (outs), (ins ptr_rc_tailcall:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000248 "", [], IIC_JMP_REG>; // FIXME: Remove encoding when JIT is dead.
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000249 let mayLoad = 1 in
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000250 def TAILJMPm : I<0xFF, MRM4m, (outs), (ins i32mem_TC:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000251 "jmp{l}\t{*}$dst # TAILCALL", [], IIC_JMP_MEM>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000252}
253
254
255//===----------------------------------------------------------------------===//
256// Call Instructions...
257//
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000258
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000259// RSP is marked as a use to prevent stack-pointer assignments that appear
260// immediately before calls from potentially appearing dead. Uses for argument
261// registers are added manually.
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000262let isCall = 1, Uses = [RSP], SchedRW = [WriteJump] in {
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000263 // NOTE: this pattern doesn't match "X86call imm", because we do not know
264 // that the offset between an arbitrary immediate and the call will fit in
265 // the 32-bit pcrel field that we have.
266 def CALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000267 (outs), (ins i64i32imm_pcrel:$dst),
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000268 "call{q}\t$dst", [], IIC_CALL_RI>,
269 Requires<[In64BitMode]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000270 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst),
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000271 "call{q}\t{*}$dst", [(X86call GR64:$dst)],
272 IIC_CALL_RI>,
273 Requires<[In64BitMode]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000274 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst),
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000275 "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))],
276 IIC_CALL_MEM>,
Michael Liao96b42602013-03-28 23:13:21 +0000277 Requires<[In64BitMode,FavorMemIndirectCall]>;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000278
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000279 def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaque80mem:$dst),
280 "lcall{q}\t{*}$dst", [], IIC_CALL_FAR_MEM>;
281}
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000282
NAKAMURA Takumi521eb7c2011-03-24 07:07:00 +0000283let isCall = 1, isCodeGenOnly = 1 in
284 // __chkstk(MSVC): clobber R10, R11 and EFLAGS.
285 // ___chkstk(Mingw64): clobber R10, R11, RAX and EFLAGS, and update RSP.
286 let Defs = [RAX, R10, R11, RSP, EFLAGS],
287 Uses = [RSP] in {
288 def W64ALLOCA : Ii32PCRel<0xE8, RawFrm,
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000289 (outs), (ins i64i32imm_pcrel:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000290 "call{q}\t$dst", [], IIC_CALL_RI>,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000291 Requires<[IsWin64]>, Sched<[WriteJump]>;
NAKAMURA Takumi521eb7c2011-03-24 07:07:00 +0000292 }
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000293
294let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000295 isCodeGenOnly = 1, Uses = [RSP], usesCustomInserter = 1,
296 SchedRW = [WriteJump] in {
Eric Christophera8706582010-11-30 21:37:36 +0000297 def TCRETURNdi64 : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000298 (ins i64i32imm_pcrel:$dst, i32imm:$offset),
Eric Christophera8706582010-11-30 21:37:36 +0000299 []>;
300 def TCRETURNri64 : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000301 (ins ptr_rc_tailcall:$dst, i32imm:$offset), []>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000302 let mayLoad = 1 in
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000303 def TCRETURNmi64 : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000304 (ins i64mem_TC:$dst, i32imm:$offset), []>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000305
306 def TAILJMPd64 : Ii32PCRel<0xE9, RawFrm, (outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000307 (ins i64i32imm_pcrel:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000308 "jmp\t$dst # TAILCALL", [], IIC_JMP_REL>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000309 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins ptr_rc_tailcall:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000310 "jmp{q}\t{*}$dst # TAILCALL", [], IIC_JMP_MEM>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000311
312 let mayLoad = 1 in
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000313 def TAILJMPm64 : I<0xFF, MRM4m, (outs), (ins i64mem_TC:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000314 "jmp{q}\t{*}$dst # TAILCALL", [], IIC_JMP_MEM>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000315}