blob: 1e420f8be9a9a0b3ab60915d3e534fc7f5ec9e7d [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;
Jakob Stoklund Olesenb50cf8b2012-08-24 20:52:44 +000033 def RETI : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
David Woodhouse79dd5052014-01-08 12:58:07 +000034 "ret{l}\t$amt",
David Woodhouse956965c2014-01-08 12:57:40 +000035 [(X86retflag timm:$amt)], IIC_RET_IMM>, OpSize16;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +000036 def RETIW : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt),
Charles Davis74c282b2012-04-11 01:10:53 +000037 "ret{w}\t$amt",
Andrew Trick8523b162012-02-01 23:20:51 +000038 [], IIC_RET_IMM>, OpSize;
Chris Lattner87cf7f72010-11-12 18:54:56 +000039 def LRETL : I <0xCB, RawFrm, (outs), (ins),
David Woodhouse956965c2014-01-08 12:57:40 +000040 "{l}ret{l|f}", [], IIC_RET>, OpSize16;
Charles Davis74c282b2012-04-11 01:10:53 +000041 def LRETW : I <0xCB, RawFrm, (outs), (ins),
42 "{l}ret{w|f}", [], IIC_RET>, OpSize;
Chris Lattner5b013b12010-11-12 17:41:20 +000043 def LRETQ : RI <0xCB, RawFrm, (outs), (ins),
Charles Davis74c282b2012-04-11 01:10:53 +000044 "{l}ret{q|f}", [], IIC_RET>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +000045 def LRETI : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
David Woodhouse956965c2014-01-08 12:57:40 +000046 "{l}ret{l|f}\t$amt", [], IIC_RET>, OpSize16;
Kevin Enderbyb9783dd2010-10-18 17:04:36 +000047 def LRETIW : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
Charles Davis74c282b2012-04-11 01:10:53 +000048 "{l}ret{w|f}\t$amt", [], IIC_RET>, OpSize;
Chris Lattnerae33f5d2010-10-05 06:04:14 +000049}
50
51// Unconditional branches.
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +000052let isBarrier = 1, isBranch = 1, isTerminator = 1, SchedRW = [WriteJump] in {
Chris Lattnerae33f5d2010-10-05 06:04:14 +000053 def JMP_4 : Ii32PCRel<0xE9, RawFrm, (outs), (ins brtarget:$dst),
David Woodhouse956965c2014-01-08 12:57:40 +000054 "jmp\t$dst", [(br bb:$dst)], IIC_JMP_REL>, OpSize16;
Craig Topper8a1028f2013-09-03 03:56:17 +000055 let hasSideEffects = 0 in
Chris Lattnerae33f5d2010-10-05 06:04:14 +000056 def JMP_1 : Ii8PCRel<0xEB, RawFrm, (outs), (ins brtarget8:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +000057 "jmp\t$dst", [], IIC_JMP_REL>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +000058}
59
60// Conditional Branches.
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +000061let isBranch = 1, isTerminator = 1, Uses = [EFLAGS], SchedRW = [WriteJump] in {
Chris Lattnerae33f5d2010-10-05 06:04:14 +000062 multiclass ICBr<bits<8> opc1, bits<8> opc4, string asm, PatFrag Cond> {
Craig Topper8a1028f2013-09-03 03:56:17 +000063 let hasSideEffects = 0 in
Andrew Trick8523b162012-02-01 23:20:51 +000064 def _1 : Ii8PCRel <opc1, RawFrm, (outs), (ins brtarget8:$dst), asm, [],
65 IIC_Jcc>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +000066 def _4 : Ii32PCRel<opc4, RawFrm, (outs), (ins brtarget:$dst), asm,
David Woodhouse956965c2014-01-08 12:57:40 +000067 [(X86brcond bb:$dst, Cond, EFLAGS)], IIC_Jcc>, TB,
68 OpSize16;
Chris Lattnerae33f5d2010-10-05 06:04:14 +000069 }
70}
71
72defm JO : ICBr<0x70, 0x80, "jo\t$dst" , X86_COND_O>;
73defm JNO : ICBr<0x71, 0x81, "jno\t$dst" , X86_COND_NO>;
74defm JB : ICBr<0x72, 0x82, "jb\t$dst" , X86_COND_B>;
75defm JAE : ICBr<0x73, 0x83, "jae\t$dst", X86_COND_AE>;
76defm JE : ICBr<0x74, 0x84, "je\t$dst" , X86_COND_E>;
77defm JNE : ICBr<0x75, 0x85, "jne\t$dst", X86_COND_NE>;
78defm JBE : ICBr<0x76, 0x86, "jbe\t$dst", X86_COND_BE>;
79defm JA : ICBr<0x77, 0x87, "ja\t$dst" , X86_COND_A>;
80defm JS : ICBr<0x78, 0x88, "js\t$dst" , X86_COND_S>;
81defm JNS : ICBr<0x79, 0x89, "jns\t$dst", X86_COND_NS>;
82defm JP : ICBr<0x7A, 0x8A, "jp\t$dst" , X86_COND_P>;
83defm JNP : ICBr<0x7B, 0x8B, "jnp\t$dst", X86_COND_NP>;
84defm JL : ICBr<0x7C, 0x8C, "jl\t$dst" , X86_COND_L>;
85defm JGE : ICBr<0x7D, 0x8D, "jge\t$dst", X86_COND_GE>;
86defm JLE : ICBr<0x7E, 0x8E, "jle\t$dst", X86_COND_LE>;
87defm JG : ICBr<0x7F, 0x8F, "jg\t$dst" , X86_COND_G>;
88
89// jcx/jecx/jrcx instructions.
Craig Topper8a1028f2013-09-03 03:56:17 +000090let isBranch = 1, isTerminator = 1, hasSideEffects = 0, SchedRW = [WriteJump] in {
Chris Lattnerae33f5d2010-10-05 06:04:14 +000091 // These are the 32-bit versions of this instruction for the asmparser. In
92 // 32-bit mode, the address size prefix is jcxz and the unprefixed version is
93 // jecxz.
94 let Uses = [CX] in
95 def JCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
Eric Christopherc0a5aae2013-12-20 02:04:49 +000096 "jcxz\t$dst", [], IIC_JCXZ>, AdSize, Requires<[Not64BitMode]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +000097 let Uses = [ECX] in
98 def JECXZ_32 : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
Eric Christopherc0a5aae2013-12-20 02:04:49 +000099 "jecxz\t$dst", [], IIC_JCXZ>, Requires<[Not64BitMode]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000100
101 // J*CXZ instruction: 64-bit versions of this instruction for the asmparser.
102 // In 64-bit mode, the address size prefix is jecxz and the unprefixed version
103 // is jrcxz.
104 let Uses = [ECX] in
105 def JECXZ_64 : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000106 "jecxz\t$dst", [], IIC_JCXZ>, AdSize, Requires<[In64BitMode]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000107 let Uses = [RCX] in
108 def JRCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000109 "jrcxz\t$dst", [], IIC_JCXZ>, Requires<[In64BitMode]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000110}
111
112// Indirect branches
113let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
David Woodhousefd460162014-01-08 12:57:49 +0000114 def JMP16r : I<0xFF, MRM4r, (outs), (ins GR16:$dst), "jmp{w}\t{*}$dst",
115 [(brind GR16:$dst)], IIC_JMP_REG>, Requires<[Not64BitMode]>,
116 OpSize, Sched<[WriteJump]>;
117 def JMP16m : I<0xFF, MRM4m, (outs), (ins i16mem:$dst), "jmp{w}\t{*}$dst",
118 [(brind (loadi16 addr:$dst))], IIC_JMP_MEM>,
119 Requires<[Not64BitMode]>, OpSize, Sched<[WriteJumpLd]>;
120
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000121 def JMP32r : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst",
Eric Christopherc0a5aae2013-12-20 02:04:49 +0000122 [(brind GR32:$dst)], IIC_JMP_REG>, Requires<[Not64BitMode]>,
David Woodhouse956965c2014-01-08 12:57:40 +0000123 OpSize16, Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000124 def JMP32m : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst",
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000125 [(brind (loadi32 addr:$dst))], IIC_JMP_MEM>,
David Woodhouse956965c2014-01-08 12:57:40 +0000126 Requires<[Not64BitMode]>, OpSize16, Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000127
128 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000129 [(brind GR64:$dst)], IIC_JMP_REG>, Requires<[In64BitMode]>,
130 Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000131 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000132 [(brind (loadi64 addr:$dst))], IIC_JMP_MEM>,
133 Requires<[In64BitMode]>, Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000134
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000135 def FARJMP16i : Iseg16<0xEA, RawFrmImm16, (outs),
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000136 (ins i16imm:$off, i16imm:$seg),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000137 "ljmp{w}\t{$seg, $off|$off, $seg}", [],
138 IIC_JMP_FAR_PTR>, OpSize, Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000139 def FARJMP32i : Iseg32<0xEA, RawFrmImm16, (outs),
140 (ins i32imm:$off, i16imm:$seg),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000141 "ljmp{l}\t{$seg, $off|$off, $seg}", [],
David Woodhouse956965c2014-01-08 12:57:40 +0000142 IIC_JMP_FAR_PTR>, OpSize16, Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000143 def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaque80mem:$dst),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000144 "ljmp{q}\t{*}$dst", [], IIC_JMP_FAR_MEM>,
145 Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000146
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000147 def FARJMP16m : I<0xFF, MRM5m, (outs), (ins opaque32mem:$dst),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000148 "ljmp{w}\t{*}$dst", [], IIC_JMP_FAR_MEM>, OpSize,
149 Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000150 def FARJMP32m : I<0xFF, MRM5m, (outs), (ins opaque48mem:$dst),
David Woodhouse956965c2014-01-08 12:57:40 +0000151 "ljmp{l}\t{*}$dst", [], IIC_JMP_FAR_MEM>, OpSize16,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000152 Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000153}
154
155
156// Loop instructions
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000157let SchedRW = [WriteJump] in {
Andrew Trick8523b162012-02-01 23:20:51 +0000158def LOOP : Ii8PCRel<0xE2, RawFrm, (outs), (ins brtarget8:$dst), "loop\t$dst", [], IIC_LOOP>;
159def LOOPE : Ii8PCRel<0xE1, RawFrm, (outs), (ins brtarget8:$dst), "loope\t$dst", [], IIC_LOOPE>;
160def LOOPNE : Ii8PCRel<0xE0, RawFrm, (outs), (ins brtarget8:$dst), "loopne\t$dst", [], IIC_LOOPNE>;
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000161}
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000162
163//===----------------------------------------------------------------------===//
164// Call Instructions...
165//
166let isCall = 1 in
167 // All calls clobber the non-callee saved registers. ESP is marked as
168 // a use to prevent stack-pointer assignments that appear immediately
169 // before calls from potentially appearing dead. Uses for argument
170 // registers are added manually.
Jakob Stoklund Olesen8a450cb2012-02-16 00:02:50 +0000171 let Uses = [ESP] in {
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000172 def CALLpcrel32 : Ii32PCRel<0xE8, RawFrm,
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000173 (outs), (ins i32imm_pcrel:$dst),
David Woodhouse956965c2014-01-08 12:57:40 +0000174 "call{l}\t$dst", [], IIC_CALL_RI>, OpSize16,
Eric Christopherc0a5aae2013-12-20 02:04:49 +0000175 Requires<[Not64BitMode]>, Sched<[WriteJump]>;
David Woodhousefd460162014-01-08 12:57:49 +0000176 def CALL16r : I<0xFF, MRM2r, (outs), (ins GR16:$dst),
177 "call{w}\t{*}$dst", [(X86call GR16:$dst)], IIC_CALL_RI>,
178 OpSize, Requires<[Not64BitMode]>, Sched<[WriteJump]>;
179 def CALL16m : I<0xFF, MRM2m, (outs), (ins i16mem:$dst),
180 "call{w}\t{*}$dst", [(X86call (loadi16 addr:$dst))],
181 IIC_CALL_MEM>, OpSize,
182 Requires<[Not64BitMode,FavorMemIndirectCall]>,
183 Sched<[WriteJumpLd]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000184 def CALL32r : I<0xFF, MRM2r, (outs), (ins GR32:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000185 "call{l}\t{*}$dst", [(X86call GR32:$dst)], IIC_CALL_RI>,
David Woodhouse956965c2014-01-08 12:57:40 +0000186 OpSize16, Requires<[Not64BitMode]>, Sched<[WriteJump]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000187 def CALL32m : I<0xFF, MRM2m, (outs), (ins i32mem:$dst),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000188 "call{l}\t{*}$dst", [(X86call (loadi32 addr:$dst))],
David Woodhouse956965c2014-01-08 12:57:40 +0000189 IIC_CALL_MEM>, OpSize16,
Eric Christopherc0a5aae2013-12-20 02:04:49 +0000190 Requires<[Not64BitMode,FavorMemIndirectCall]>,
Michael Liao96b42602013-03-28 23:13:21 +0000191 Sched<[WriteJumpLd]>;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000192
193 def FARCALL16i : Iseg16<0x9A, RawFrmImm16, (outs),
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000194 (ins i16imm:$off, i16imm:$seg),
Andrew Trick8523b162012-02-01 23:20:51 +0000195 "lcall{w}\t{$seg, $off|$off, $seg}", [],
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000196 IIC_CALL_FAR_PTR>, OpSize, Sched<[WriteJump]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000197 def FARCALL32i : Iseg32<0x9A, RawFrmImm16, (outs),
198 (ins i32imm:$off, i16imm:$seg),
Andrew Trick8523b162012-02-01 23:20:51 +0000199 "lcall{l}\t{$seg, $off|$off, $seg}", [],
David Woodhouse956965c2014-01-08 12:57:40 +0000200 IIC_CALL_FAR_PTR>, OpSize16, Sched<[WriteJump]>;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000201
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000202 def FARCALL16m : I<0xFF, MRM3m, (outs), (ins opaque32mem:$dst),
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000203 "lcall{w}\t{*}$dst", [], IIC_CALL_FAR_MEM>, OpSize,
204 Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000205 def FARCALL32m : I<0xFF, MRM3m, (outs), (ins opaque48mem:$dst),
David Woodhouse956965c2014-01-08 12:57:40 +0000206 "lcall{l}\t{*}$dst", [], IIC_CALL_FAR_MEM>, OpSize16,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000207 Sched<[WriteJumpLd]>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000208
209 // callw for 16 bit code for the assembler.
210 let isAsmParserOnly = 1 in
211 def CALLpcrel16 : Ii16PCRel<0xE8, RawFrm,
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000212 (outs), (ins i16imm_pcrel:$dst),
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000213 "callw\t$dst", []>, OpSize;
214 }
215
216
217// Tail call stuff.
218
219let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000220 isCodeGenOnly = 1, SchedRW = [WriteJumpLd] in
Jakob Stoklund Olesen8a450cb2012-02-16 00:02:50 +0000221 let Uses = [ESP] in {
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000222 def TCRETURNdi : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000223 (ins i32imm_pcrel:$dst, i32imm:$offset), []>;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000224 def TCRETURNri : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000225 (ins ptr_rc_tailcall:$dst, i32imm:$offset), []>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000226 let mayLoad = 1 in
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000227 def TCRETURNmi : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000228 (ins i32mem_TC:$dst, i32imm:$offset), []>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000229
230 // FIXME: The should be pseudo instructions that are lowered when going to
231 // mcinst.
232 def TAILJMPd : Ii32PCRel<0xE9, RawFrm, (outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000233 (ins i32imm_pcrel:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000234 "jmp\t$dst # TAILCALL",
235 [], IIC_JMP_REL>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000236 def TAILJMPr : I<0xFF, MRM4r, (outs), (ins ptr_rc_tailcall:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000237 "", [], IIC_JMP_REG>; // FIXME: Remove encoding when JIT is dead.
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000238 let mayLoad = 1 in
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000239 def TAILJMPm : I<0xFF, MRM4m, (outs), (ins i32mem_TC:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000240 "jmp{l}\t{*}$dst # TAILCALL", [], IIC_JMP_MEM>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000241}
242
243
244//===----------------------------------------------------------------------===//
245// Call Instructions...
246//
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000247
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000248// RSP is marked as a use to prevent stack-pointer assignments that appear
249// immediately before calls from potentially appearing dead. Uses for argument
250// registers are added manually.
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000251let isCall = 1, Uses = [RSP], SchedRW = [WriteJump] in {
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000252 // NOTE: this pattern doesn't match "X86call imm", because we do not know
253 // that the offset between an arbitrary immediate and the call will fit in
254 // the 32-bit pcrel field that we have.
255 def CALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000256 (outs), (ins i64i32imm_pcrel:$dst),
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000257 "call{q}\t$dst", [], IIC_CALL_RI>,
258 Requires<[In64BitMode]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000259 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst),
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000260 "call{q}\t{*}$dst", [(X86call GR64:$dst)],
261 IIC_CALL_RI>,
262 Requires<[In64BitMode]>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000263 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst),
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000264 "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))],
265 IIC_CALL_MEM>,
Michael Liao96b42602013-03-28 23:13:21 +0000266 Requires<[In64BitMode,FavorMemIndirectCall]>;
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000267
Jakob Stoklund Olesen97e31152012-02-16 17:56:02 +0000268 def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaque80mem:$dst),
269 "lcall{q}\t{*}$dst", [], IIC_CALL_FAR_MEM>;
270}
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000271
NAKAMURA Takumi521eb7c2011-03-24 07:07:00 +0000272let isCall = 1, isCodeGenOnly = 1 in
273 // __chkstk(MSVC): clobber R10, R11 and EFLAGS.
274 // ___chkstk(Mingw64): clobber R10, R11, RAX and EFLAGS, and update RSP.
275 let Defs = [RAX, R10, R11, RSP, EFLAGS],
276 Uses = [RSP] in {
277 def W64ALLOCA : Ii32PCRel<0xE8, RawFrm,
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000278 (outs), (ins i64i32imm_pcrel:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000279 "call{q}\t$dst", [], IIC_CALL_RI>,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000280 Requires<[IsWin64]>, Sched<[WriteJump]>;
NAKAMURA Takumi521eb7c2011-03-24 07:07:00 +0000281 }
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000282
283let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
Jakob Stoklund Olesend59419eb2013-03-26 18:24:17 +0000284 isCodeGenOnly = 1, Uses = [RSP], usesCustomInserter = 1,
285 SchedRW = [WriteJump] in {
Eric Christophera8706582010-11-30 21:37:36 +0000286 def TCRETURNdi64 : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000287 (ins i64i32imm_pcrel:$dst, i32imm:$offset),
Eric Christophera8706582010-11-30 21:37:36 +0000288 []>;
289 def TCRETURNri64 : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000290 (ins ptr_rc_tailcall:$dst, i32imm:$offset), []>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000291 let mayLoad = 1 in
NAKAMURA Takumi9d29eff2011-01-26 02:03:37 +0000292 def TCRETURNmi64 : PseudoI<(outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000293 (ins i64mem_TC:$dst, i32imm:$offset), []>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000294
295 def TAILJMPd64 : Ii32PCRel<0xE9, RawFrm, (outs),
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000296 (ins i64i32imm_pcrel:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000297 "jmp\t$dst # TAILCALL", [], IIC_JMP_REL>;
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000298 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins ptr_rc_tailcall:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000299 "jmp{q}\t{*}$dst # TAILCALL", [], IIC_JMP_MEM>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000300
301 let mayLoad = 1 in
Jakob Stoklund Olesend14101e2012-07-04 23:53:27 +0000302 def TAILJMPm64 : I<0xFF, MRM4m, (outs), (ins i64mem_TC:$dst),
Andrew Trick8523b162012-02-01 23:20:51 +0000303 "jmp{q}\t{*}$dst # TAILCALL", [], IIC_JMP_MEM>;
Chris Lattnerae33f5d2010-10-05 06:04:14 +0000304}