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.
19 let isTerminator = 1, isReturn = 1, isBarrier = 1,
20 hasCtrlDep = 1, FPForm = SpecialFP in {
21 def RET : I <0xC3, RawFrm, (outs), (ins variable_ops),
24 def RETI : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
26 [(X86retflag timm:$amt)]>;
27 def RETIW : Ii16<0xC2, RawFrm, (outs), (ins i16imm:$amt, variable_ops),
29 [(X86retflag timm:$amt)]>, OpSize;
30 def LRET : I <0xCB, RawFrm, (outs), (ins),
32 def LRETI : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
34 def LRETIW : Ii16<0xCA, RawFrm, (outs), (ins i16imm:$amt),
35 "lretw\t$amt", []>, OpSize;
38 // Unconditional branches.
39 let isBarrier = 1, isBranch = 1, isTerminator = 1 in {
40 def JMP_4 : Ii32PCRel<0xE9, RawFrm, (outs), (ins brtarget:$dst),
41 "jmp\t$dst", [(br bb:$dst)]>;
42 def JMP_1 : Ii8PCRel<0xEB, RawFrm, (outs), (ins brtarget8:$dst),
44 def JMP64pcrel32 : I<0xE9, RawFrm, (outs), (ins brtarget:$dst),
48 // Conditional Branches.
49 let isBranch = 1, isTerminator = 1, Uses = [EFLAGS] in {
50 multiclass ICBr<bits<8> opc1, bits<8> opc4, string asm, PatFrag Cond> {
51 def _1 : Ii8PCRel <opc1, RawFrm, (outs), (ins brtarget8:$dst), asm, []>;
52 def _4 : Ii32PCRel<opc4, RawFrm, (outs), (ins brtarget:$dst), asm,
53 [(X86brcond bb:$dst, Cond, EFLAGS)]>, TB;
57 defm JO : ICBr<0x70, 0x80, "jo\t$dst" , X86_COND_O>;
58 defm JNO : ICBr<0x71, 0x81, "jno\t$dst" , X86_COND_NO>;
59 defm JB : ICBr<0x72, 0x82, "jb\t$dst" , X86_COND_B>;
60 defm JAE : ICBr<0x73, 0x83, "jae\t$dst", X86_COND_AE>;
61 defm JE : ICBr<0x74, 0x84, "je\t$dst" , X86_COND_E>;
62 defm JNE : ICBr<0x75, 0x85, "jne\t$dst", X86_COND_NE>;
63 defm JBE : ICBr<0x76, 0x86, "jbe\t$dst", X86_COND_BE>;
64 defm JA : ICBr<0x77, 0x87, "ja\t$dst" , X86_COND_A>;
65 defm JS : ICBr<0x78, 0x88, "js\t$dst" , X86_COND_S>;
66 defm JNS : ICBr<0x79, 0x89, "jns\t$dst", X86_COND_NS>;
67 defm JP : ICBr<0x7A, 0x8A, "jp\t$dst" , X86_COND_P>;
68 defm JNP : ICBr<0x7B, 0x8B, "jnp\t$dst", X86_COND_NP>;
69 defm JL : ICBr<0x7C, 0x8C, "jl\t$dst" , X86_COND_L>;
70 defm JGE : ICBr<0x7D, 0x8D, "jge\t$dst", X86_COND_GE>;
71 defm JLE : ICBr<0x7E, 0x8E, "jle\t$dst", X86_COND_LE>;
72 defm JG : ICBr<0x7F, 0x8F, "jg\t$dst" , X86_COND_G>;
74 // jcx/jecx/jrcx instructions.
75 let isAsmParserOnly = 1, isBranch = 1, isTerminator = 1 in {
76 // These are the 32-bit versions of this instruction for the asmparser. In
77 // 32-bit mode, the address size prefix is jcxz and the unprefixed version is
80 def JCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
81 "jcxz\t$dst", []>, AdSize, Requires<[In32BitMode]>;
83 def JECXZ_32 : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
84 "jecxz\t$dst", []>, Requires<[In32BitMode]>;
86 // J*CXZ instruction: 64-bit versions of this instruction for the asmparser.
87 // In 64-bit mode, the address size prefix is jecxz and the unprefixed version
90 def JECXZ_64 : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
91 "jecxz\t$dst", []>, AdSize, Requires<[In64BitMode]>;
93 def JRCXZ : Ii8PCRel<0xE3, RawFrm, (outs), (ins brtarget8:$dst),
94 "jrcxz\t$dst", []>, Requires<[In64BitMode]>;
98 let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in {
99 def JMP32r : I<0xFF, MRM4r, (outs), (ins GR32:$dst), "jmp{l}\t{*}$dst",
100 [(brind GR32:$dst)]>, Requires<[In32BitMode]>;
101 def JMP32m : I<0xFF, MRM4m, (outs), (ins i32mem:$dst), "jmp{l}\t{*}$dst",
102 [(brind (loadi32 addr:$dst))]>, Requires<[In32BitMode]>;
104 def JMP64r : I<0xFF, MRM4r, (outs), (ins GR64:$dst), "jmp{q}\t{*}$dst",
105 [(brind GR64:$dst)]>, Requires<[In64BitMode]>;
106 def JMP64m : I<0xFF, MRM4m, (outs), (ins i64mem:$dst), "jmp{q}\t{*}$dst",
107 [(brind (loadi64 addr:$dst))]>, Requires<[In64BitMode]>;
109 def FARJMP16i : Iseg16<0xEA, RawFrmImm16, (outs),
110 (ins i16imm:$off, i16imm:$seg),
111 "ljmp{w}\t{$seg, $off|$off, $seg}", []>, OpSize;
112 def FARJMP32i : Iseg32<0xEA, RawFrmImm16, (outs),
113 (ins i32imm:$off, i16imm:$seg),
114 "ljmp{l}\t{$seg, $off|$off, $seg}", []>;
115 def FARJMP64 : RI<0xFF, MRM5m, (outs), (ins opaque80mem:$dst),
116 "ljmp{q}\t{*}$dst", []>;
118 def FARJMP16m : I<0xFF, MRM5m, (outs), (ins opaque32mem:$dst),
119 "ljmp{w}\t{*}$dst", []>, OpSize;
120 def FARJMP32m : I<0xFF, MRM5m, (outs), (ins opaque48mem:$dst),
121 "ljmp{l}\t{*}$dst", []>;
127 def LOOP : Ii8PCRel<0xE2, RawFrm, (outs), (ins brtarget8:$dst), "loop\t$dst", []>;
128 def LOOPE : Ii8PCRel<0xE1, RawFrm, (outs), (ins brtarget8:$dst), "loope\t$dst", []>;
129 def LOOPNE : Ii8PCRel<0xE0, RawFrm, (outs), (ins brtarget8:$dst), "loopne\t$dst", []>;
131 //===----------------------------------------------------------------------===//
132 // Call Instructions...
135 // All calls clobber the non-callee saved registers. ESP is marked as
136 // a use to prevent stack-pointer assignments that appear immediately
137 // before calls from potentially appearing dead. Uses for argument
138 // registers are added manually.
139 let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
140 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
141 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
142 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
144 def CALLpcrel32 : Ii32PCRel<0xE8, RawFrm,
145 (outs), (ins i32imm_pcrel:$dst,variable_ops),
146 "call{l}\t$dst", []>, Requires<[In32BitMode]>;
147 def CALL32r : I<0xFF, MRM2r, (outs), (ins GR32:$dst, variable_ops),
148 "call{l}\t{*}$dst", [(X86call GR32:$dst)]>,
149 Requires<[In32BitMode]>;
150 def CALL32m : I<0xFF, MRM2m, (outs), (ins i32mem:$dst, variable_ops),
151 "call{l}\t{*}$dst", [(X86call (loadi32 addr:$dst))]>,
152 Requires<[In32BitMode]>;
154 def FARCALL16i : Iseg16<0x9A, RawFrmImm16, (outs),
155 (ins i16imm:$off, i16imm:$seg),
156 "lcall{w}\t{$seg, $off|$off, $seg}", []>, OpSize;
157 def FARCALL32i : Iseg32<0x9A, RawFrmImm16, (outs),
158 (ins i32imm:$off, i16imm:$seg),
159 "lcall{l}\t{$seg, $off|$off, $seg}", []>;
161 def FARCALL16m : I<0xFF, MRM3m, (outs), (ins opaque32mem:$dst),
162 "lcall{w}\t{*}$dst", []>, OpSize;
163 def FARCALL32m : I<0xFF, MRM3m, (outs), (ins opaque48mem:$dst),
164 "lcall{l}\t{*}$dst", []>;
166 // callw for 16 bit code for the assembler.
167 let isAsmParserOnly = 1 in
168 def CALLpcrel16 : Ii16PCRel<0xE8, RawFrm,
169 (outs), (ins i16imm_pcrel:$dst, variable_ops),
170 "callw\t$dst", []>, OpSize;
176 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
178 let Defs = [EAX, ECX, EDX, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0,
179 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
180 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
181 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
183 def TCRETURNdi : I<0, Pseudo, (outs),
184 (ins i32imm_pcrel:$dst, i32imm:$offset, variable_ops),
185 "#TC_RETURN $dst $offset", []>;
186 def TCRETURNri : I<0, Pseudo, (outs),
187 (ins GR32_TC:$dst, i32imm:$offset, variable_ops),
188 "#TC_RETURN $dst $offset", []>;
190 def TCRETURNmi : I<0, Pseudo, (outs),
191 (ins i32mem_TC:$dst, i32imm:$offset, variable_ops),
192 "#TC_RETURN $dst $offset", []>;
194 // FIXME: The should be pseudo instructions that are lowered when going to
196 def TAILJMPd : Ii32PCRel<0xE9, RawFrm, (outs),
197 (ins i32imm_pcrel:$dst, variable_ops),
198 "jmp\t$dst # TAILCALL",
200 def TAILJMPr : I<0xFF, MRM4r, (outs), (ins GR32_TC:$dst, variable_ops),
201 "", []>; // FIXME: Remove encoding when JIT is dead.
203 def TAILJMPm : I<0xFF, MRM4m, (outs), (ins i32mem_TC:$dst, variable_ops),
204 "jmp{l}\t{*}$dst # TAILCALL", []>;
208 //===----------------------------------------------------------------------===//
209 // Call Instructions...
212 // All calls clobber the non-callee saved registers. RSP is marked as
213 // a use to prevent stack-pointer assignments that appear immediately
214 // before calls from potentially appearing dead. Uses for argument
215 // registers are added manually.
216 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
217 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
218 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
219 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
220 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
223 // NOTE: this pattern doesn't match "X86call imm", because we do not know
224 // that the offset between an arbitrary immediate and the call will fit in
225 // the 32-bit pcrel field that we have.
226 def CALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
227 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
228 "call{q}\t$dst", []>,
229 Requires<[In64BitMode, NotWin64]>;
230 def CALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
231 "call{q}\t{*}$dst", [(X86call GR64:$dst)]>,
232 Requires<[In64BitMode, NotWin64]>;
233 def CALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst, variable_ops),
234 "call{q}\t{*}$dst", [(X86call (loadi64 addr:$dst))]>,
235 Requires<[In64BitMode, NotWin64]>;
237 def FARCALL64 : RI<0xFF, MRM3m, (outs), (ins opaque80mem:$dst),
238 "lcall{q}\t{*}$dst", []>;
241 // FIXME: We need to teach codegen about single list of call-clobbered
243 let isCall = 1, isCodeGenOnly = 1 in
244 // All calls clobber the non-callee saved registers. RSP is marked as
245 // a use to prevent stack-pointer assignments that appear immediately
246 // before calls from potentially appearing dead. Uses for argument
247 // registers are added manually.
248 let Defs = [RAX, RCX, RDX, R8, R9, R10, R11,
249 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
250 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
251 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, EFLAGS],
253 def WINCALL64pcrel32 : Ii32PCRel<0xE8, RawFrm,
254 (outs), (ins i64i32imm_pcrel:$dst, variable_ops),
255 "call{q}\t$dst", []>,
257 def WINCALL64r : I<0xFF, MRM2r, (outs), (ins GR64:$dst, variable_ops),
259 [(X86call GR64:$dst)]>, Requires<[IsWin64]>;
260 def WINCALL64m : I<0xFF, MRM2m, (outs), (ins i64mem:$dst,variable_ops),
262 [(X86call (loadi64 addr:$dst))]>,
267 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1,
269 let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11,
270 FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1,
271 MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7,
272 XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
273 XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
275 def TCRETURNdi64 : I<0, Pseudo, (outs),
276 (ins i64i32imm_pcrel:$dst, i32imm:$offset, variable_ops),
277 "#TC_RETURN $dst $offset", []>;
278 def TCRETURNri64 : I<0, Pseudo, (outs), (ins GR64_TC:$dst, i32imm:$offset,
280 "#TC_RETURN $dst $offset", []>;
282 def TCRETURNmi64 : I<0, Pseudo, (outs),
283 (ins i64mem_TC:$dst, i32imm:$offset, variable_ops),
284 "#TC_RETURN $dst $offset", []>;
286 def TAILJMPd64 : Ii32PCRel<0xE9, RawFrm, (outs),
287 (ins i64i32imm_pcrel:$dst, variable_ops),
288 "jmp\t$dst # TAILCALL", []>;
289 def TAILJMPr64 : I<0xFF, MRM4r, (outs), (ins GR64_TC:$dst, variable_ops),
290 "jmp{q}\t{*}$dst # TAILCALL", []>;
293 def TAILJMPm64 : I<0xFF, MRM4m, (outs), (ins i64mem_TC:$dst, variable_ops),
294 "jmp{q}\t{*}$dst # TAILCALL", []>;