1 //===-- X86InstrControl.td - Control Flow Instructions -----*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the X86 jump, return, call, and related instructions.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // Control Flow Instructions.
18 // Return instructions.
20 // The X86retflag return instructions are variadic because we may add ST0 and
21 // ST1 arguments when returning values on the x87 stack.
22 let isTerminator = 1, isReturn = 1, isBarrier = 1,
23 hasCtrlDep = 1, FPForm = SpecialFP in {
24 def RET : I <0xC3, RawFrm, (outs), (ins variable_ops),
26 [(X86retflag 0)], IIC_RET>;
27 def RETW : I <0xC3, RawFrm, (outs), (ins),
30 def RETI : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
32 [(X86retflag timm:$amt)], IIC_RET_IMM>;
33 def RETIW : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt),
35 [], IIC_RET_IMM>, OpSize;
36 def LRETL : I <0xCB, RawFrm, (outs), (ins),
37 "{l}ret{l|f}", [], IIC_RET>;
38 def LRETW : I <0xCB, RawFrm, (outs), (ins),
39 "{l}ret{w|f}", [], IIC_RET>, OpSize;
40 def LRETQ : RI <0xCB, RawFrm, (outs), (ins),
41 "{l}ret{q|f}", [], IIC_RET>;
42 def LRETI : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
43 "{l}ret{l|f}\t$amt", [], IIC_RET>;
44 def LRETIW : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
45 "{l}ret{w|f}\t$amt", [], IIC_RET>, OpSize;
48 // Unconditional branches.
49 let isBarrier = 1, isBranch = 1, isTerminator = 1 in {
50 def JMP_4 : Ii32PCRel<0xE9, RawFrm, (outs), (ins brtarget:$dst),
51 "jmp\t$dst", [(br bb:$dst)], IIC_JMP_REL>;
52 def JMP_1 : Ii8PCRel<0xEB, RawFrm, (outs), (ins brtarget8:$dst),
53 "jmp\t$dst", [], IIC_JMP_REL>;
54 // FIXME : Intel syntax for JMP64pcrel32 such that it is not ambiguious
56 def JMP64pcrel32 : I<0xE9, RawFrm, (outs), (ins brtarget:$dst),
57 "jmpq\t$dst", [], IIC_JMP_REL>;
60 // Conditional Branches.
61 let isBranch = 1, isTerminator = 1, Uses = [EFLAGS] in {
62 multiclass ICBr<bits<8> opc1, bits<8> opc4, string asm, PatFrag Cond> {
63 def _1 : Ii8PCRel <opc1, RawFrm, (outs), (ins brtarget8:$dst), asm, [],
65 def _4 : Ii32PCRel<opc4, RawFrm, (outs), (ins brtarget:$dst), asm,
66 [(X86brcond bb:$dst, Cond, EFLAGS)], IIC_Jcc>, TB;
70 defm JO : ICBr<0x70, 0x80, "jo\t$dst" , X86_COND_O>;
71 defm JNO : ICBr<0x71, 0x81, "jno\t$dst" , X86_COND_NO>;
72 defm JB : ICBr<0x72, 0x82, "jb\t$dst" , X86_COND_B>;
73 defm JAE : ICBr<0x73, 0x83, "jae\t$dst", X86_COND_AE>;
74 defm JE : ICBr<0x74, 0x84, "je\t$dst" , X86_COND_E>;
75 defm JNE : ICBr<0x75, 0x85, "jne\t$dst", X86_COND_NE>;
76 defm JBE : ICBr<0x76, 0x86, "jbe\t$dst", X86_COND_BE>;
77 defm JA : ICBr<0x77, 0x87, "ja\t$dst" , X86_COND_A>;
78 defm JS : ICBr<0x78, 0x88, "js\t$dst" , X86_COND_S>;
79 defm JNS : ICBr<0x79, 0x89, "jns\t$dst", X86_COND_NS>;
80 defm JP : ICBr<0x7A, 0x8A, "jp\t$dst" , X86_COND_P>;
81 defm JNP : ICBr<0x7B, 0x8B, "jnp\t$dst", X86_COND_NP>;
82 defm JL : ICBr<0x7C, 0x8C, "jl\t$dst" , X86_COND_L>;
83 defm JGE : ICBr<0x7D, 0x8D, "jge\t$dst", X86_COND_GE>;
84 defm JLE : ICBr<0x7E, 0x8E, "jle\t$dst", X86_COND_LE>;
85 defm JG : ICBr<0x7F, 0x8F, "jg\t$dst" , X86_COND_G>;
87 // jcx/jecx/jrcx instructions.
88 let isBranch = 1, isTerminator = 1 in {
89 // These are the 32-bit versions of this instruction for the asmparser. In
90 // 32-bit mode, the address size prefix is jcxz and the unprefixed version is
93 def JCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
94 "jcxz\t$dst", [], IIC_JCXZ>, AdSize, Requires<[In32BitMode]>;
96 def JECXZ_32 : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
97 "jecxz\t$dst", [], IIC_JCXZ>, Requires<[In32BitMode]>;
99 // J*CXZ instruction: 64-bit versions of this instruction for the asmparser.
100 // In 64-bit mode, the address size prefix is jecxz and the unprefixed version
103 def JECXZ_64 : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
104 "jecxz\t$dst", [], IIC_JCXZ>, AdSize, Requires<[In64BitMode]>;
106 def JRCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
107 "jrcxz\t$dst", [], IIC_JCXZ>, Requires<[In64BitMode]>;
111 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
112 def JMP32r : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst",
113 [(brind GR32:$dst)], IIC_JMP_REG>, Requires<[In32BitMode]>;
114 def JMP32m : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst",
115 [(brind (loadi32 addr:$dst))], IIC_JMP_MEM>, Requires<[In32BitMode]>;
117 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
118 [(brind GR64:$dst)], IIC_JMP_REG>, Requires<[In64BitMode]>;
119 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
120 [(brind (loadi64 addr:$dst))], IIC_JMP_MEM>, Requires<[In64BitMode]>;
122 def FARJMP16i : Iseg16<0xEA, RawFrmImm16, (outs),
123 (ins i16imm:$off, i16imm:$seg),
124 "ljmp{w}\t{$seg, $off|$off, $seg}", [], IIC_JMP_FAR_PTR>, OpSize;
125 def FARJMP32i : Iseg32<0xEA, RawFrmImm16, (outs),
126 (ins i32imm:$off, i16imm:$seg),
127 "ljmp{l}\t{$seg, $off|$off, $seg}", [], IIC_JMP_FAR_PTR>;
128 def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaque80mem:$dst),
129 "ljmp{q}\t{*}$dst", [], IIC_JMP_FAR_MEM>;
131 def FARJMP16m : I<0xFF, MRM5m, (outs), (ins opaque32mem:$dst),
132 "ljmp{w}\t{*}$dst", [], IIC_JMP_FAR_MEM>, OpSize;
133 def FARJMP32m : I<0xFF, MRM5m, (outs), (ins opaque48mem:$dst),
134 "ljmp{l}\t{*}$dst", [], IIC_JMP_FAR_MEM>;
140 def LOOP : Ii8PCRel<0xE2, RawFrm, (outs), (ins brtarget8:$dst), "loop\t$dst", [], IIC_LOOP>;
141 def LOOPE : Ii8PCRel<0xE1, RawFrm, (outs), (ins brtarget8:$dst), "loope\t$dst", [], IIC_LOOPE>;
142 def LOOPNE : Ii8PCRel<0xE0, RawFrm, (outs), (ins brtarget8:$dst), "loopne\t$dst", [], IIC_LOOPNE>;
144 //===----------------------------------------------------------------------===//
145 // Call Instructions...
148 // All calls clobber the non-callee saved registers. ESP is marked as
149 // a use to prevent stack-pointer assignments that appear immediately
150 // before calls from potentially appearing dead. Uses for argument
151 // registers are added manually.
152 let Uses = [ESP] in {
153 def CALLpcrel32 : Ii32PCRel<0xE8, RawFrm,
154 (outs), (ins i32imm_pcrel:$dst),
155 "call{l}\t$dst", [], IIC_CALL_RI>, Requires<[In32BitMode]>;
156 def CALL32r : I<0xFF, MRM2r, (outs), (ins GR32:$dst),
157 "call{l}\t{*}$dst", [(X86call GR32:$dst)], IIC_CALL_RI>,
158 Requires<[In32BitMode]>;
159 def CALL32m : I<0xFF, MRM2m, (outs), (ins i32mem:$dst),
160 "call{l}\t{*}$dst", [(X86call (loadi32 addr:$dst))], IIC_CALL_MEM>,
161 Requires<[In32BitMode]>;
163 def FARCALL16i : Iseg16<0x9A, RawFrmImm16, (outs),
164 (ins i16imm:$off, i16imm:$seg),
165 "lcall{w}\t{$seg, $off|$off, $seg}", [],
166 IIC_CALL_FAR_PTR>, OpSize;
167 def FARCALL32i : Iseg32<0x9A, RawFrmImm16, (outs),
168 (ins i32imm:$off, i16imm:$seg),
169 "lcall{l}\t{$seg, $off|$off, $seg}", [],
172 def FARCALL16m : I<0xFF, MRM3m, (outs), (ins opaque32mem:$dst),
173 "lcall{w}\t{*}$dst", [], IIC_CALL_FAR_MEM>, OpSize;
174 def FARCALL32m : I<0xFF, MRM3m, (outs), (ins opaque48mem:$dst),
175 "lcall{l}\t{*}$dst", [], IIC_CALL_FAR_MEM>;
177 // callw for 16 bit code for the assembler.
178 let isAsmParserOnly = 1 in
179 def CALLpcrel16 : Ii16PCRel<0xE8, RawFrm,
180 (outs), (ins i16imm_pcrel:$dst),
181 "callw\t$dst", []>, OpSize;
187 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
189 let Uses = [ESP] in {
190 def TCRETURNdi : PseudoI<(outs),
191 (ins i32imm_pcrel:$dst, i32imm:$offset), []>;
192 def TCRETURNri : PseudoI<(outs),
193 (ins ptr_rc_tailcall:$dst, i32imm:$offset), []>;
195 def TCRETURNmi : PseudoI<(outs),
196 (ins i32mem_TC:$dst, i32imm:$offset), []>;
198 // FIXME: The should be pseudo instructions that are lowered when going to
200 def TAILJMPd : Ii32PCRel<0xE9, RawFrm, (outs),
201 (ins i32imm_pcrel:$dst),
202 "jmp\t$dst # TAILCALL",
204 def TAILJMPr : I<0xFF, MRM4r, (outs), (ins ptr_rc_tailcall:$dst),
205 "", [], IIC_JMP_REG>; // FIXME: Remove encoding when JIT is dead.
207 def TAILJMPm : I<0xFF, MRM4m, (outs), (ins i32mem_TC:$dst),
208 "jmp{l}\t{*}$dst # TAILCALL", [], IIC_JMP_MEM>;
212 //===----------------------------------------------------------------------===//
213 // Call Instructions...
216 // RSP is marked as a use to prevent stack-pointer assignments that appear
217 // immediately before calls from potentially appearing dead. Uses for argument
218 // registers are added manually.
219 let isCall = 1, Uses = [RSP] in {
220 // NOTE: this pattern doesn't match "X86call imm", because we do not know
221 // that the offset between an arbitrary immediate and the call will fit in
222 // the 32-bit pcrel field that we have.
223 def CALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
224 (outs), (ins i64i32imm_pcrel:$dst),
225 "call{q}\t$dst", [], IIC_CALL_RI>,
226 Requires<[In64BitMode]>;
227 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst),
228 "call{q}\t{*}$dst", [(X86call GR64:$dst)],
230 Requires<[In64BitMode]>;
231 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst),
232 "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))],
234 Requires<[In64BitMode]>;
236 def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaque80mem:$dst),
237 "lcall{q}\t{*}$dst", [], IIC_CALL_FAR_MEM>;
240 let isCall = 1, isCodeGenOnly = 1 in
241 // __chkstk(MSVC): clobber R10, R11 and EFLAGS.
242 // ___chkstk(Mingw64): clobber R10, R11, RAX and EFLAGS, and update RSP.
243 let Defs = [RAX, R10, R11, RSP, EFLAGS],
245 def W64ALLOCA : Ii32PCRel<0xE8, RawFrm,
246 (outs), (ins i64i32imm_pcrel:$dst),
247 "call{q}\t$dst", [], IIC_CALL_RI>,
251 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
254 usesCustomInserter = 1 in {
255 def TCRETURNdi64 : PseudoI<(outs),
256 (ins i64i32imm_pcrel:$dst, i32imm:$offset),
258 def TCRETURNri64 : PseudoI<(outs),
259 (ins ptr_rc_tailcall:$dst, i32imm:$offset), []>;
261 def TCRETURNmi64 : PseudoI<(outs),
262 (ins i64mem_TC:$dst, i32imm:$offset), []>;
264 def TAILJMPd64 : Ii32PCRel<0xE9, RawFrm, (outs),
265 (ins i64i32imm_pcrel:$dst),
266 "jmp\t$dst # TAILCALL", [], IIC_JMP_REL>;
267 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins ptr_rc_tailcall:$dst),
268 "jmp{q}\t{*}$dst # TAILCALL", [], IIC_JMP_MEM>;
271 def TAILJMPm64 : I<0xFF, MRM4m, (outs), (ins i64mem_TC:$dst),
272 "jmp{q}\t{*}$dst # TAILCALL", [], IIC_JMP_MEM>;