LLVM 20.0.0git
X86RegisterInfo.cpp
Go to the documentation of this file.
1//===-- X86RegisterInfo.cpp - X86 Register Information --------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the X86 implementation of the TargetRegisterInfo class.
10// This file is responsible for the frame pointer elimination optimization
11// on X86.
12//
13//===----------------------------------------------------------------------===//
14
15#include "X86RegisterInfo.h"
17#include "X86FrameLowering.h"
19#include "X86Subtarget.h"
20#include "llvm/ADT/BitVector.h"
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/SmallSet.h"
33#include "llvm/IR/Constants.h"
34#include "llvm/IR/Function.h"
35#include "llvm/IR/Type.h"
36#include "llvm/MC/MCContext.h"
41
42using namespace llvm;
43
44#define GET_REGINFO_TARGET_DESC
45#include "X86GenRegisterInfo.inc"
46
47static cl::opt<bool>
48EnableBasePointer("x86-use-base-pointer", cl::Hidden, cl::init(true),
49 cl::desc("Enable use of a base pointer for complex stack frames"));
50
51static cl::opt<bool>
52 DisableRegAllocNDDHints("x86-disable-regalloc-hints-for-ndd", cl::Hidden,
53 cl::init(false),
54 cl::desc("Disable two address hints for register "
55 "allocation"));
56
58 : X86GenRegisterInfo((TT.isArch64Bit() ? X86::RIP : X86::EIP),
59 X86_MC::getDwarfRegFlavour(TT, false),
60 X86_MC::getDwarfRegFlavour(TT, true),
61 (TT.isArch64Bit() ? X86::RIP : X86::EIP)) {
63
64 // Cache some information.
65 Is64Bit = TT.isArch64Bit();
66 IsWin64 = Is64Bit && TT.isOSWindows();
67
68 // Use a callee-saved register as the base pointer. These registers must
69 // not conflict with any ABI requirements. For example, in 32-bit mode PIC
70 // requires GOT in the EBX register before function calls via PLT GOT pointer.
71 if (Is64Bit) {
72 SlotSize = 8;
73 // This matches the simplified 32-bit pointer code in the data layout
74 // computation.
75 // FIXME: Should use the data layout?
76 bool Use64BitReg = !TT.isX32();
77 StackPtr = Use64BitReg ? X86::RSP : X86::ESP;
78 FramePtr = Use64BitReg ? X86::RBP : X86::EBP;
79 BasePtr = Use64BitReg ? X86::RBX : X86::EBX;
80 } else {
81 SlotSize = 4;
82 StackPtr = X86::ESP;
83 FramePtr = X86::EBP;
84 BasePtr = X86::ESI;
85 }
86}
87
88int
90 return getEncodingValue(i);
91}
92
95 unsigned Idx) const {
96 // The sub_8bit sub-register index is more constrained in 32-bit mode.
97 // It behaves just like the sub_8bit_hi index.
98 if (!Is64Bit && Idx == X86::sub_8bit)
99 Idx = X86::sub_8bit_hi;
100
101 // Forward to TableGen's default version.
102 return X86GenRegisterInfo::getSubClassWithSubReg(RC, Idx);
103}
104
107 const TargetRegisterClass *B,
108 unsigned SubIdx) const {
109 // The sub_8bit sub-register index is more constrained in 32-bit mode.
110 if (!Is64Bit && SubIdx == X86::sub_8bit) {
111 A = X86GenRegisterInfo::getSubClassWithSubReg(A, X86::sub_8bit_hi);
112 if (!A)
113 return nullptr;
114 }
115 return X86GenRegisterInfo::getMatchingSuperRegClass(A, B, SubIdx);
116}
117
120 const MachineFunction &MF) const {
121 // Don't allow super-classes of GR8_NOREX. This class is only used after
122 // extracting sub_8bit_hi sub-registers. The H sub-registers cannot be copied
123 // to the full GR8 register class in 64-bit mode, so we cannot allow the
124 // reigster class inflation.
125 //
126 // The GR8_NOREX class is always used in a way that won't be constrained to a
127 // sub-class, so sub-classes like GR8_ABCD_L are allowed to expand to the
128 // full GR8 class.
129 if (RC == &X86::GR8_NOREXRegClass)
130 return RC;
131
132 const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
133
134 const TargetRegisterClass *Super = RC;
136 do {
137 switch (Super->getID()) {
138 case X86::FR32RegClassID:
139 case X86::FR64RegClassID:
140 // If AVX-512 isn't supported we should only inflate to these classes.
141 if (!Subtarget.hasAVX512() &&
142 getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
143 return Super;
144 break;
145 case X86::VR128RegClassID:
146 case X86::VR256RegClassID:
147 // If VLX isn't supported we should only inflate to these classes.
148 if (!Subtarget.hasVLX() &&
149 getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
150 return Super;
151 break;
152 case X86::VR128XRegClassID:
153 case X86::VR256XRegClassID:
154 // If VLX isn't support we shouldn't inflate to these classes.
155 if (Subtarget.hasVLX() &&
156 getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
157 return Super;
158 break;
159 case X86::FR32XRegClassID:
160 case X86::FR64XRegClassID:
161 // If AVX-512 isn't support we shouldn't inflate to these classes.
162 if (Subtarget.hasAVX512() &&
163 getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
164 return Super;
165 break;
166 case X86::GR8RegClassID:
167 case X86::GR16RegClassID:
168 case X86::GR32RegClassID:
169 case X86::GR64RegClassID:
170 case X86::GR8_NOREX2RegClassID:
171 case X86::GR16_NOREX2RegClassID:
172 case X86::GR32_NOREX2RegClassID:
173 case X86::GR64_NOREX2RegClassID:
174 case X86::RFP32RegClassID:
175 case X86::RFP64RegClassID:
176 case X86::RFP80RegClassID:
177 case X86::VR512_0_15RegClassID:
178 case X86::VR512RegClassID:
179 // Don't return a super-class that would shrink the spill size.
180 // That can happen with the vector and float classes.
181 if (getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
182 return Super;
183 }
184 Super = *I++;
185 } while (Super);
186 return RC;
187}
188
191 unsigned Kind) const {
192 const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
193 switch (Kind) {
194 default: llvm_unreachable("Unexpected Kind in getPointerRegClass!");
195 case 0: // Normal GPRs.
196 if (Subtarget.isTarget64BitLP64())
197 return &X86::GR64RegClass;
198 // If the target is 64bit but we have been told to use 32bit addresses,
199 // we can still use 64-bit register as long as we know the high bits
200 // are zeros.
201 // Reflect that in the returned register class.
202 if (Is64Bit) {
203 // When the target also allows 64-bit frame pointer and we do have a
204 // frame, this is fine to use it for the address accesses as well.
205 const X86FrameLowering *TFI = getFrameLowering(MF);
206 return TFI->hasFP(MF) && TFI->Uses64BitFramePtr
207 ? &X86::LOW32_ADDR_ACCESS_RBPRegClass
208 : &X86::LOW32_ADDR_ACCESSRegClass;
209 }
210 return &X86::GR32RegClass;
211 case 1: // Normal GPRs except the stack pointer (for encoding reasons).
212 if (Subtarget.isTarget64BitLP64())
213 return &X86::GR64_NOSPRegClass;
214 // NOSP does not contain RIP, so no special case here.
215 return &X86::GR32_NOSPRegClass;
216 case 2: // NOREX GPRs.
217 if (Subtarget.isTarget64BitLP64())
218 return &X86::GR64_NOREXRegClass;
219 return &X86::GR32_NOREXRegClass;
220 case 3: // NOREX GPRs except the stack pointer (for encoding reasons).
221 if (Subtarget.isTarget64BitLP64())
222 return &X86::GR64_NOREX_NOSPRegClass;
223 // NOSP does not contain RIP, so no special case here.
224 return &X86::GR32_NOREX_NOSPRegClass;
225 case 4: // Available for tailcall (not callee-saved GPRs).
226 return getGPRsForTailCall(MF);
227 }
228}
229
231 unsigned DefSubReg,
232 const TargetRegisterClass *SrcRC,
233 unsigned SrcSubReg) const {
234 // Prevent rewriting a copy where the destination size is larger than the
235 // input size. See PR41619.
236 // FIXME: Should this be factored into the base implementation somehow.
237 if (DefRC->hasSuperClassEq(&X86::GR64RegClass) && DefSubReg == 0 &&
238 SrcRC->hasSuperClassEq(&X86::GR64RegClass) && SrcSubReg == X86::sub_32bit)
239 return false;
240
241 return TargetRegisterInfo::shouldRewriteCopySrc(DefRC, DefSubReg,
242 SrcRC, SrcSubReg);
243}
244
247 const Function &F = MF.getFunction();
248 if (IsWin64 || (F.getCallingConv() == CallingConv::Win64))
249 return &X86::GR64_TCW64RegClass;
250 else if (Is64Bit)
251 return &X86::GR64_TCRegClass;
252
253 bool hasHipeCC = (F.getCallingConv() == CallingConv::HiPE);
254 if (hasHipeCC)
255 return &X86::GR32RegClass;
256 return &X86::GR32_TCRegClass;
257}
258
261 if (RC == &X86::CCRRegClass) {
262 if (Is64Bit)
263 return &X86::GR64RegClass;
264 else
265 return &X86::GR32RegClass;
266 }
267 return RC;
268}
269
270unsigned
272 MachineFunction &MF) const {
273 const X86FrameLowering *TFI = getFrameLowering(MF);
274
275 unsigned FPDiff = TFI->hasFP(MF) ? 1 : 0;
276 switch (RC->getID()) {
277 default:
278 return 0;
279 case X86::GR32RegClassID:
280 return 4 - FPDiff;
281 case X86::GR64RegClassID:
282 return 12 - FPDiff;
283 case X86::VR128RegClassID:
284 return Is64Bit ? 10 : 4;
285 case X86::VR64RegClassID:
286 return 4;
287 }
288}
289
290const MCPhysReg *
292 assert(MF && "MachineFunction required");
293
294 const X86Subtarget &Subtarget = MF->getSubtarget<X86Subtarget>();
295 const Function &F = MF->getFunction();
296 bool HasSSE = Subtarget.hasSSE1();
297 bool HasAVX = Subtarget.hasAVX();
298 bool HasAVX512 = Subtarget.hasAVX512();
299 bool CallsEHReturn = MF->callsEHReturn();
300
301 CallingConv::ID CC = F.getCallingConv();
302
303 // If attribute NoCallerSavedRegisters exists then we set X86_INTR calling
304 // convention because it has the CSR list.
305 if (MF->getFunction().hasFnAttribute("no_caller_saved_registers"))
307
308 // If atribute specified, override the CSRs normally specified by the
309 // calling convention and use the empty set instead.
310 if (MF->getFunction().hasFnAttribute("no_callee_saved_registers"))
311 return CSR_NoRegs_SaveList;
312
313 switch (CC) {
314 case CallingConv::GHC:
316 return CSR_NoRegs_SaveList;
318 if (HasAVX)
319 return CSR_64_AllRegs_AVX_SaveList;
320 return CSR_64_AllRegs_SaveList;
322 return IsWin64 ? CSR_Win64_RT_MostRegs_SaveList
323 : CSR_64_RT_MostRegs_SaveList;
325 if (HasAVX)
326 return CSR_64_RT_AllRegs_AVX_SaveList;
327 return CSR_64_RT_AllRegs_SaveList;
329 return CSR_64_NoneRegs_SaveList;
331 if (Is64Bit)
332 return MF->getInfo<X86MachineFunctionInfo>()->isSplitCSR() ?
333 CSR_64_CXX_TLS_Darwin_PE_SaveList : CSR_64_TLS_Darwin_SaveList;
334 break;
336 if (HasAVX512 && IsWin64)
337 return CSR_Win64_Intel_OCL_BI_AVX512_SaveList;
338 if (HasAVX512 && Is64Bit)
339 return CSR_64_Intel_OCL_BI_AVX512_SaveList;
340 if (HasAVX && IsWin64)
341 return CSR_Win64_Intel_OCL_BI_AVX_SaveList;
342 if (HasAVX && Is64Bit)
343 return CSR_64_Intel_OCL_BI_AVX_SaveList;
344 if (!HasAVX && !IsWin64 && Is64Bit)
345 return CSR_64_Intel_OCL_BI_SaveList;
346 break;
347 }
349 if (Is64Bit) {
350 if (IsWin64) {
351 return (HasSSE ? CSR_Win64_RegCall_SaveList :
352 CSR_Win64_RegCall_NoSSE_SaveList);
353 } else {
354 return (HasSSE ? CSR_SysV64_RegCall_SaveList :
355 CSR_SysV64_RegCall_NoSSE_SaveList);
356 }
357 } else {
358 return (HasSSE ? CSR_32_RegCall_SaveList :
359 CSR_32_RegCall_NoSSE_SaveList);
360 }
362 assert(!Is64Bit && "CFGuard check mechanism only used on 32-bit X86");
363 return (HasSSE ? CSR_Win32_CFGuard_Check_SaveList
364 : CSR_Win32_CFGuard_Check_NoSSE_SaveList);
366 if (Is64Bit)
367 return CSR_64_MostRegs_SaveList;
368 break;
370 if (!HasSSE)
371 return CSR_Win64_NoSSE_SaveList;
372 return CSR_Win64_SaveList;
374 if (!Is64Bit)
375 return CSR_32_SaveList;
376 return IsWin64 ? CSR_Win64_SwiftTail_SaveList : CSR_64_SwiftTail_SaveList;
378 if (CallsEHReturn)
379 return CSR_64EHRet_SaveList;
380 return CSR_64_SaveList;
382 if (Is64Bit) {
383 if (HasAVX512)
384 return CSR_64_AllRegs_AVX512_SaveList;
385 if (HasAVX)
386 return CSR_64_AllRegs_AVX_SaveList;
387 if (HasSSE)
388 return CSR_64_AllRegs_SaveList;
389 return CSR_64_AllRegs_NoSSE_SaveList;
390 } else {
391 if (HasAVX512)
392 return CSR_32_AllRegs_AVX512_SaveList;
393 if (HasAVX)
394 return CSR_32_AllRegs_AVX_SaveList;
395 if (HasSSE)
396 return CSR_32_AllRegs_SSE_SaveList;
397 return CSR_32_AllRegs_SaveList;
398 }
399 default:
400 break;
401 }
402
403 if (Is64Bit) {
404 bool IsSwiftCC = Subtarget.getTargetLowering()->supportSwiftError() &&
405 F.getAttributes().hasAttrSomewhere(Attribute::SwiftError);
406 if (IsSwiftCC)
407 return IsWin64 ? CSR_Win64_SwiftError_SaveList
408 : CSR_64_SwiftError_SaveList;
409
410 if (IsWin64)
411 return HasSSE ? CSR_Win64_SaveList : CSR_Win64_NoSSE_SaveList;
412 if (CallsEHReturn)
413 return CSR_64EHRet_SaveList;
414 return CSR_64_SaveList;
415 }
416
417 return CallsEHReturn ? CSR_32EHRet_SaveList : CSR_32_SaveList;
418}
419
421 const MachineFunction *MF) const {
422 assert(MF && "Invalid MachineFunction pointer.");
425 return CSR_64_CXX_TLS_Darwin_ViaCopy_SaveList;
426 return nullptr;
427}
428
429const uint32_t *
431 CallingConv::ID CC) const {
432 const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
433 bool HasSSE = Subtarget.hasSSE1();
434 bool HasAVX = Subtarget.hasAVX();
435 bool HasAVX512 = Subtarget.hasAVX512();
436
437 switch (CC) {
438 case CallingConv::GHC:
440 return CSR_NoRegs_RegMask;
442 if (HasAVX)
443 return CSR_64_AllRegs_AVX_RegMask;
444 return CSR_64_AllRegs_RegMask;
446 return IsWin64 ? CSR_Win64_RT_MostRegs_RegMask : CSR_64_RT_MostRegs_RegMask;
448 if (HasAVX)
449 return CSR_64_RT_AllRegs_AVX_RegMask;
450 return CSR_64_RT_AllRegs_RegMask;
452 return CSR_64_NoneRegs_RegMask;
454 if (Is64Bit)
455 return CSR_64_TLS_Darwin_RegMask;
456 break;
458 if (HasAVX512 && IsWin64)
459 return CSR_Win64_Intel_OCL_BI_AVX512_RegMask;
460 if (HasAVX512 && Is64Bit)
461 return CSR_64_Intel_OCL_BI_AVX512_RegMask;
462 if (HasAVX && IsWin64)
463 return CSR_Win64_Intel_OCL_BI_AVX_RegMask;
464 if (HasAVX && Is64Bit)
465 return CSR_64_Intel_OCL_BI_AVX_RegMask;
466 if (!HasAVX && !IsWin64 && Is64Bit)
467 return CSR_64_Intel_OCL_BI_RegMask;
468 break;
469 }
471 if (Is64Bit) {
472 if (IsWin64) {
473 return (HasSSE ? CSR_Win64_RegCall_RegMask :
474 CSR_Win64_RegCall_NoSSE_RegMask);
475 } else {
476 return (HasSSE ? CSR_SysV64_RegCall_RegMask :
477 CSR_SysV64_RegCall_NoSSE_RegMask);
478 }
479 } else {
480 return (HasSSE ? CSR_32_RegCall_RegMask :
481 CSR_32_RegCall_NoSSE_RegMask);
482 }
484 assert(!Is64Bit && "CFGuard check mechanism only used on 32-bit X86");
485 return (HasSSE ? CSR_Win32_CFGuard_Check_RegMask
486 : CSR_Win32_CFGuard_Check_NoSSE_RegMask);
488 if (Is64Bit)
489 return CSR_64_MostRegs_RegMask;
490 break;
492 return CSR_Win64_RegMask;
494 if (!Is64Bit)
495 return CSR_32_RegMask;
496 return IsWin64 ? CSR_Win64_SwiftTail_RegMask : CSR_64_SwiftTail_RegMask;
498 return CSR_64_RegMask;
500 if (Is64Bit) {
501 if (HasAVX512)
502 return CSR_64_AllRegs_AVX512_RegMask;
503 if (HasAVX)
504 return CSR_64_AllRegs_AVX_RegMask;
505 if (HasSSE)
506 return CSR_64_AllRegs_RegMask;
507 return CSR_64_AllRegs_NoSSE_RegMask;
508 } else {
509 if (HasAVX512)
510 return CSR_32_AllRegs_AVX512_RegMask;
511 if (HasAVX)
512 return CSR_32_AllRegs_AVX_RegMask;
513 if (HasSSE)
514 return CSR_32_AllRegs_SSE_RegMask;
515 return CSR_32_AllRegs_RegMask;
516 }
517 default:
518 break;
519 }
520
521 // Unlike getCalleeSavedRegs(), we don't have MMI so we can't check
522 // callsEHReturn().
523 if (Is64Bit) {
524 const Function &F = MF.getFunction();
525 bool IsSwiftCC = Subtarget.getTargetLowering()->supportSwiftError() &&
526 F.getAttributes().hasAttrSomewhere(Attribute::SwiftError);
527 if (IsSwiftCC)
528 return IsWin64 ? CSR_Win64_SwiftError_RegMask : CSR_64_SwiftError_RegMask;
529
530 return IsWin64 ? CSR_Win64_RegMask : CSR_64_RegMask;
531 }
532
533 return CSR_32_RegMask;
534}
535
536const uint32_t*
538 return CSR_NoRegs_RegMask;
539}
540
542 return CSR_64_TLS_Darwin_RegMask;
543}
544
546 BitVector Reserved(getNumRegs());
547 const X86FrameLowering *TFI = getFrameLowering(MF);
548
549 // Set the floating point control register as reserved.
550 Reserved.set(X86::FPCW);
551
552 // Set the floating point status register as reserved.
553 Reserved.set(X86::FPSW);
554
555 // Set the SIMD floating point control register as reserved.
556 Reserved.set(X86::MXCSR);
557
558 // Set the stack-pointer register and its aliases as reserved.
559 for (const MCPhysReg &SubReg : subregs_inclusive(X86::RSP))
560 Reserved.set(SubReg);
561
562 // Set the Shadow Stack Pointer as reserved.
563 Reserved.set(X86::SSP);
564
565 // Set the instruction pointer register and its aliases as reserved.
566 for (const MCPhysReg &SubReg : subregs_inclusive(X86::RIP))
567 Reserved.set(SubReg);
568
569 // Set the frame-pointer register and its aliases as reserved if needed.
570 if (TFI->hasFP(MF)) {
573 SMLoc(),
574 "Frame pointer clobbered by function invoke is not supported.");
575
576 for (const MCPhysReg &SubReg : subregs_inclusive(X86::RBP))
577 Reserved.set(SubReg);
578 }
579
580 // Set the base-pointer register and its aliases as reserved if needed.
581 if (hasBasePointer(MF)) {
584 "Stack realignment in presence of dynamic "
585 "allocas is not supported with "
586 "this calling convention.");
587
589 for (const MCPhysReg &SubReg : subregs_inclusive(BasePtr))
590 Reserved.set(SubReg);
591 }
592
593 // Mark the segment registers as reserved.
594 Reserved.set(X86::CS);
595 Reserved.set(X86::SS);
596 Reserved.set(X86::DS);
597 Reserved.set(X86::ES);
598 Reserved.set(X86::FS);
599 Reserved.set(X86::GS);
600
601 // Mark the floating point stack registers as reserved.
602 for (unsigned n = 0; n != 8; ++n)
603 Reserved.set(X86::ST0 + n);
604
605 // Reserve the registers that only exist in 64-bit mode.
606 if (!Is64Bit) {
607 // These 8-bit registers are part of the x86-64 extension even though their
608 // super-registers are old 32-bits.
609 Reserved.set(X86::SIL);
610 Reserved.set(X86::DIL);
611 Reserved.set(X86::BPL);
612 Reserved.set(X86::SPL);
613 Reserved.set(X86::SIH);
614 Reserved.set(X86::DIH);
615 Reserved.set(X86::BPH);
616 Reserved.set(X86::SPH);
617
618 for (unsigned n = 0; n != 8; ++n) {
619 // R8, R9, ...
620 for (MCRegAliasIterator AI(X86::R8 + n, this, true); AI.isValid(); ++AI)
621 Reserved.set(*AI);
622
623 // XMM8, XMM9, ...
624 for (MCRegAliasIterator AI(X86::XMM8 + n, this, true); AI.isValid(); ++AI)
625 Reserved.set(*AI);
626 }
627 }
628 if (!Is64Bit || !MF.getSubtarget<X86Subtarget>().hasAVX512()) {
629 for (unsigned n = 0; n != 16; ++n) {
630 for (MCRegAliasIterator AI(X86::XMM16 + n, this, true); AI.isValid();
631 ++AI)
632 Reserved.set(*AI);
633 }
634 }
635
636 // Reserve the extended general purpose registers.
637 if (!Is64Bit || !MF.getSubtarget<X86Subtarget>().hasEGPR())
638 Reserved.set(X86::R16, X86::R31WH + 1);
639
641 for (MCRegAliasIterator AI(X86::R14, this, true); AI.isValid(); ++AI)
642 Reserved.set(*AI);
643 for (MCRegAliasIterator AI(X86::R15, this, true); AI.isValid(); ++AI)
644 Reserved.set(*AI);
645 }
646
647 assert(checkAllSuperRegsMarked(Reserved,
648 {X86::SIL, X86::DIL, X86::BPL, X86::SPL,
649 X86::SIH, X86::DIH, X86::BPH, X86::SPH}));
650 return Reserved;
651}
652
654 // All existing Intel CPUs that support AMX support AVX512 and all existing
655 // Intel CPUs that support APX support AMX. AVX512 implies AVX.
656 //
657 // We enumerate the registers in X86GenRegisterInfo.inc in this order:
658 //
659 // Registers before AVX512,
660 // AVX512 registers (X/YMM16-31, ZMM0-31, K registers)
661 // AMX registers (TMM)
662 // APX registers (R16-R31)
663 //
664 // and try to return the minimum number of registers supported by the target.
665 static_assert((X86::R15WH + 1 == X86::YMM0) && (X86::YMM15 + 1 == X86::K0) &&
666 (X86::K6_K7 + 1 == X86::TMMCFG) &&
667 (X86::TMM7 + 1 == X86::R16) &&
668 (X86::R31WH + 1 == X86::NUM_TARGET_REGS),
669 "Register number may be incorrect");
670
671 const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
672 if (ST.hasEGPR())
673 return X86::NUM_TARGET_REGS;
674 if (ST.hasAMXTILE())
675 return X86::TMM7 + 1;
676 if (ST.hasAVX512())
677 return X86::K6_K7 + 1;
678 if (ST.hasAVX())
679 return X86::YMM15 + 1;
680 return X86::R15WH + 1;
681}
682
684 MCRegister Reg) const {
685 const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
686 const TargetRegisterInfo &TRI = *ST.getRegisterInfo();
687 auto IsSubReg = [&](MCRegister RegA, MCRegister RegB) {
688 return TRI.isSuperOrSubRegisterEq(RegA, RegB);
689 };
690
691 if (!ST.is64Bit())
692 return llvm::any_of(
693 SmallVector<MCRegister>{X86::EAX, X86::ECX, X86::EDX},
694 [&](MCRegister &RegA) { return IsSubReg(RegA, Reg); }) ||
695 (ST.hasMMX() && X86::VR64RegClass.contains(Reg));
696
698
699 if (CC == CallingConv::X86_64_SysV && IsSubReg(X86::RAX, Reg))
700 return true;
701
702 if (llvm::any_of(
703 SmallVector<MCRegister>{X86::RDX, X86::RCX, X86::R8, X86::R9},
704 [&](MCRegister &RegA) { return IsSubReg(RegA, Reg); }))
705 return true;
706
707 if (CC != CallingConv::Win64 &&
708 llvm::any_of(SmallVector<MCRegister>{X86::RDI, X86::RSI},
709 [&](MCRegister &RegA) { return IsSubReg(RegA, Reg); }))
710 return true;
711
712 if (ST.hasSSE1() &&
713 llvm::any_of(SmallVector<MCRegister>{X86::XMM0, X86::XMM1, X86::XMM2,
714 X86::XMM3, X86::XMM4, X86::XMM5,
715 X86::XMM6, X86::XMM7},
716 [&](MCRegister &RegA) { return IsSubReg(RegA, Reg); }))
717 return true;
718
719 return X86GenRegisterInfo::isArgumentRegister(MF, Reg);
720}
721
723 MCRegister PhysReg) const {
724 const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
725 const TargetRegisterInfo &TRI = *ST.getRegisterInfo();
726
727 // Stack pointer.
728 if (TRI.isSuperOrSubRegisterEq(X86::RSP, PhysReg))
729 return true;
730
731 // Don't use the frame pointer if it's being used.
732 const X86FrameLowering &TFI = *getFrameLowering(MF);
733 if (TFI.hasFP(MF) && TRI.isSuperOrSubRegisterEq(X86::RBP, PhysReg))
734 return true;
735
736 return X86GenRegisterInfo::isFixedRegister(MF, PhysReg);
737}
738
740 return RC->getID() == X86::TILERegClassID;
741}
742
744 // Check if the EFLAGS register is marked as live-out. This shouldn't happen,
745 // because the calling convention defines the EFLAGS register as NOT
746 // preserved.
747 //
748 // Unfortunatelly the EFLAGS show up as live-out after branch folding. Adding
749 // an assert to track this and clear the register afterwards to avoid
750 // unnecessary crashes during release builds.
751 assert(!(Mask[X86::EFLAGS / 32] & (1U << (X86::EFLAGS % 32))) &&
752 "EFLAGS are not live-out from a patchpoint.");
753
754 // Also clean other registers that don't need preserving (IP).
755 for (auto Reg : {X86::EFLAGS, X86::RIP, X86::EIP, X86::IP})
756 Mask[Reg / 32] &= ~(1U << (Reg % 32));
757}
758
759//===----------------------------------------------------------------------===//
760// Stack Frame Processing methods
761//===----------------------------------------------------------------------===//
762
763static bool CantUseSP(const MachineFrameInfo &MFI) {
764 return MFI.hasVarSizedObjects() || MFI.hasOpaqueSPAdjustment();
765}
766
769 // We have a virtual register to reference argument, and don't need base
770 // pointer.
771 if (X86FI->getStackPtrSaveMI() != nullptr)
772 return false;
773
774 if (X86FI->hasPreallocatedCall())
775 return true;
776
777 const MachineFrameInfo &MFI = MF.getFrameInfo();
778
780 return false;
781
782 // When we need stack realignment, we can't address the stack from the frame
783 // pointer. When we have dynamic allocas or stack-adjusting inline asm, we
784 // can't address variables from the stack pointer. MS inline asm can
785 // reference locals while also adjusting the stack pointer. When we can't
786 // use both the SP and the FP, we need a separate base pointer register.
787 bool CantUseFP = hasStackRealignment(MF);
788 return CantUseFP && CantUseSP(MFI);
789}
790
793 return false;
794
795 const MachineFrameInfo &MFI = MF.getFrameInfo();
796 const MachineRegisterInfo *MRI = &MF.getRegInfo();
797
798 // Stack realignment requires a frame pointer. If we already started
799 // register allocation with frame pointer elimination, it is too late now.
800 if (!MRI->canReserveReg(FramePtr))
801 return false;
802
803 // If a base pointer is necessary. Check that it isn't too late to reserve
804 // it.
805 if (CantUseSP(MFI))
806 return MRI->canReserveReg(BasePtr);
807 return true;
808}
809
812 return true;
813
814 return !Is64Bit && MF.getFunction().getCallingConv() == CallingConv::X86_INTR;
815}
816
817// tryOptimizeLEAtoMOV - helper function that tries to replace a LEA instruction
818// of the form 'lea (%esp), %ebx' --> 'mov %esp, %ebx'.
819// TODO: In this case we should be really trying first to entirely eliminate
820// this instruction which is a plain copy.
822 MachineInstr &MI = *II;
823 unsigned Opc = II->getOpcode();
824 // Check if this is a LEA of the form 'lea (%esp), %ebx'
825 if ((Opc != X86::LEA32r && Opc != X86::LEA64r && Opc != X86::LEA64_32r) ||
826 MI.getOperand(2).getImm() != 1 ||
827 MI.getOperand(3).getReg() != X86::NoRegister ||
828 MI.getOperand(4).getImm() != 0 ||
829 MI.getOperand(5).getReg() != X86::NoRegister)
830 return false;
831 Register BasePtr = MI.getOperand(1).getReg();
832 // In X32 mode, ensure the base-pointer is a 32-bit operand, so the LEA will
833 // be replaced with a 32-bit operand MOV which will zero extend the upper
834 // 32-bits of the super register.
835 if (Opc == X86::LEA64_32r)
836 BasePtr = getX86SubSuperRegister(BasePtr, 32);
837 Register NewDestReg = MI.getOperand(0).getReg();
838 const X86InstrInfo *TII =
839 MI.getParent()->getParent()->getSubtarget<X86Subtarget>().getInstrInfo();
840 TII->copyPhysReg(*MI.getParent(), II, MI.getDebugLoc(), NewDestReg, BasePtr,
841 MI.getOperand(1).isKill());
842 MI.eraseFromParent();
843 return true;
844}
845
847 switch (MI.getOpcode()) {
848 case X86::CATCHRET:
849 case X86::CLEANUPRET:
850 return true;
851 default:
852 return false;
853 }
854 llvm_unreachable("impossible");
855}
856
858 unsigned FIOperandNum,
859 Register BaseReg,
860 int FIOffset) const {
861 MachineInstr &MI = *II;
862 unsigned Opc = MI.getOpcode();
863 if (Opc == TargetOpcode::LOCAL_ESCAPE) {
864 MachineOperand &FI = MI.getOperand(FIOperandNum);
865 FI.ChangeToImmediate(FIOffset);
866 return;
867 }
868
869 MI.getOperand(FIOperandNum).ChangeToRegister(BaseReg, false);
870
871 // The frame index format for stackmaps and patchpoints is different from the
872 // X86 format. It only has a FI and an offset.
873 if (Opc == TargetOpcode::STACKMAP || Opc == TargetOpcode::PATCHPOINT) {
874 assert(BasePtr == FramePtr && "Expected the FP as base register");
875 int64_t Offset = MI.getOperand(FIOperandNum + 1).getImm() + FIOffset;
876 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
877 return;
878 }
879
880 if (MI.getOperand(FIOperandNum + 3).isImm()) {
881 // Offset is a 32-bit integer.
882 int Imm = (int)(MI.getOperand(FIOperandNum + 3).getImm());
883 int Offset = FIOffset + Imm;
884 assert((!Is64Bit || isInt<32>((long long)FIOffset + Imm)) &&
885 "Requesting 64-bit offset in 32-bit immediate!");
886 if (Offset != 0)
887 MI.getOperand(FIOperandNum + 3).ChangeToImmediate(Offset);
888 } else {
889 // Offset is symbolic. This is extremely rare.
891 FIOffset + (uint64_t)MI.getOperand(FIOperandNum + 3).getOffset();
892 MI.getOperand(FIOperandNum + 3).setOffset(Offset);
893 }
894}
895
896bool
898 int SPAdj, unsigned FIOperandNum,
899 RegScavenger *RS) const {
900 MachineInstr &MI = *II;
901 MachineBasicBlock &MBB = *MI.getParent();
904 bool IsEHFuncletEpilogue = MBBI == MBB.end() ? false
906 const X86FrameLowering *TFI = getFrameLowering(MF);
907 int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
908
909 // Determine base register and offset.
910 int64_t FIOffset;
911 Register BasePtr;
912 if (MI.isReturn()) {
913 assert((!hasStackRealignment(MF) ||
914 MF.getFrameInfo().isFixedObjectIndex(FrameIndex)) &&
915 "Return instruction can only reference SP relative frame objects");
916 FIOffset =
917 TFI->getFrameIndexReferenceSP(MF, FrameIndex, BasePtr, 0).getFixed();
918 } else if (TFI->Is64Bit && (MBB.isEHFuncletEntry() || IsEHFuncletEpilogue)) {
919 FIOffset = TFI->getWin64EHFrameIndexRef(MF, FrameIndex, BasePtr);
920 } else {
921 FIOffset = TFI->getFrameIndexReference(MF, FrameIndex, BasePtr).getFixed();
922 }
923
924 // LOCAL_ESCAPE uses a single offset, with no register. It only works in the
925 // simple FP case, and doesn't work with stack realignment. On 32-bit, the
926 // offset is from the traditional base pointer location. On 64-bit, the
927 // offset is from the SP at the end of the prologue, not the FP location. This
928 // matches the behavior of llvm.frameaddress.
929 unsigned Opc = MI.getOpcode();
930 if (Opc == TargetOpcode::LOCAL_ESCAPE) {
931 MachineOperand &FI = MI.getOperand(FIOperandNum);
932 FI.ChangeToImmediate(FIOffset);
933 return false;
934 }
935
936 // For LEA64_32r when BasePtr is 32-bits (X32) we can use full-size 64-bit
937 // register as source operand, semantic is the same and destination is
938 // 32-bits. It saves one byte per lea in code since 0x67 prefix is avoided.
939 // Don't change BasePtr since it is used later for stack adjustment.
940 Register MachineBasePtr = BasePtr;
941 if (Opc == X86::LEA64_32r && X86::GR32RegClass.contains(BasePtr))
942 MachineBasePtr = getX86SubSuperRegister(BasePtr, 64);
943
944 // This must be part of a four operand memory reference. Replace the
945 // FrameIndex with base register. Add an offset to the offset.
946 MI.getOperand(FIOperandNum).ChangeToRegister(MachineBasePtr, false);
947
948 if (BasePtr == StackPtr)
949 FIOffset += SPAdj;
950
951 // The frame index format for stackmaps and patchpoints is different from the
952 // X86 format. It only has a FI and an offset.
953 if (Opc == TargetOpcode::STACKMAP || Opc == TargetOpcode::PATCHPOINT) {
954 assert(BasePtr == FramePtr && "Expected the FP as base register");
955 int64_t Offset = MI.getOperand(FIOperandNum + 1).getImm() + FIOffset;
956 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
957 return false;
958 }
959
960 if (MI.getOperand(FIOperandNum+3).isImm()) {
961 int64_t Imm = MI.getOperand(FIOperandNum + 3).getImm();
962 int64_t Offset = FIOffset + Imm;
963 bool FitsIn32Bits = isInt<32>(Offset);
964 // If the offset will not fit in a 32-bit displacement,
965 // then for 64-bit targets, scavenge a register to hold it.
966 // Otherwise, for 32-bit targets, this is a bug!
967 if (Is64Bit && !FitsIn32Bits) {
968 assert(RS && "RegisterScavenger was NULL");
969 const X86InstrInfo *TII = MF.getSubtarget<X86Subtarget>().getInstrInfo();
970 const DebugLoc &DL = MI.getDebugLoc();
971
973 RS->backward(std::next(II));
974
975 Register ScratchReg = RS->scavengeRegisterBackwards(
976 X86::GR64RegClass, II, /*RestoreAfter=*/false, /*SPAdj=*/0,
977 /*AllowSpill=*/true);
978 assert(ScratchReg != 0 && "scratch reg was 0");
979 RS->setRegUsed(ScratchReg);
980
981 BuildMI(MBB, II, DL, TII->get(X86::MOV64ri), ScratchReg).addImm(Offset);
982
983 MI.getOperand(FIOperandNum + 3).setImm(0);
984 MI.getOperand(FIOperandNum + 2).setReg(ScratchReg);
985
986 return false;
987 }
988 assert((Is64Bit || FitsIn32Bits) &&
989 "Requesting 64-bit offset in 32-bit immediate!");
990 if (Offset != 0 || !tryOptimizeLEAtoMOV(II))
991 MI.getOperand(FIOperandNum + 3).ChangeToImmediate(Offset);
992 } else {
993 // Offset is symbolic. This is extremely rare.
994 uint64_t Offset = FIOffset +
995 (uint64_t)MI.getOperand(FIOperandNum+3).getOffset();
996 MI.getOperand(FIOperandNum + 3).setOffset(Offset);
997 }
998 return false;
999}
1000
1003 const MachineFunction *MF = MBB.getParent();
1004 if (MF->callsEHReturn())
1005 return 0;
1006
1007 const TargetRegisterClass &AvailableRegs = *getGPRsForTailCall(*MF);
1008
1009 if (MBBI == MBB.end())
1010 return 0;
1011
1012 switch (MBBI->getOpcode()) {
1013 default:
1014 return 0;
1015 case TargetOpcode::PATCHABLE_RET:
1016 case X86::RET:
1017 case X86::RET32:
1018 case X86::RET64:
1019 case X86::RETI32:
1020 case X86::RETI64:
1021 case X86::TCRETURNdi:
1022 case X86::TCRETURNri:
1023 case X86::TCRETURNmi:
1024 case X86::TCRETURNdi64:
1025 case X86::TCRETURNri64:
1026 case X86::TCRETURNmi64:
1027 case X86::EH_RETURN:
1028 case X86::EH_RETURN64: {
1030 for (MachineOperand &MO : MBBI->operands()) {
1031 if (!MO.isReg() || MO.isDef())
1032 continue;
1033 Register Reg = MO.getReg();
1034 if (!Reg)
1035 continue;
1036 for (MCRegAliasIterator AI(Reg, this, true); AI.isValid(); ++AI)
1037 Uses.insert(*AI);
1038 }
1039
1040 for (auto CS : AvailableRegs)
1041 if (!Uses.count(CS) && CS != X86::RIP && CS != X86::RSP && CS != X86::ESP)
1042 return CS;
1043 }
1044 }
1045
1046 return 0;
1047}
1048
1050 const X86FrameLowering *TFI = getFrameLowering(MF);
1051 return TFI->hasFP(MF) ? FramePtr : StackPtr;
1052}
1053
1054unsigned
1056 const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
1057 Register FrameReg = getFrameRegister(MF);
1058 if (Subtarget.isTarget64BitILP32())
1059 FrameReg = getX86SubSuperRegister(FrameReg, 32);
1060 return FrameReg;
1061}
1062
1063unsigned
1065 const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
1066 Register StackReg = getStackRegister();
1067 if (Subtarget.isTarget64BitILP32())
1068 StackReg = getX86SubSuperRegister(StackReg, 32);
1069 return StackReg;
1070}
1071
1073 const MachineRegisterInfo *MRI) {
1074 if (VRM->hasShape(VirtReg))
1075 return VRM->getShape(VirtReg);
1076
1077 const MachineOperand &Def = *MRI->def_begin(VirtReg);
1078 MachineInstr *MI = const_cast<MachineInstr *>(Def.getParent());
1079 unsigned OpCode = MI->getOpcode();
1080 switch (OpCode) {
1081 default:
1082 llvm_unreachable("Unexpected machine instruction on tile register!");
1083 break;
1084 case X86::COPY: {
1085 Register SrcReg = MI->getOperand(1).getReg();
1086 ShapeT Shape = getTileShape(SrcReg, VRM, MRI);
1087 VRM->assignVirt2Shape(VirtReg, Shape);
1088 return Shape;
1089 }
1090 // We only collect the tile shape that is defined.
1091 case X86::PTILELOADDV:
1092 case X86::PTILELOADDT1V:
1093 case X86::PTDPBSSDV:
1094 case X86::PTDPBSUDV:
1095 case X86::PTDPBUSDV:
1096 case X86::PTDPBUUDV:
1097 case X86::PTILEZEROV:
1098 case X86::PTDPBF16PSV:
1099 case X86::PTDPFP16PSV:
1100 case X86::PTCMMIMFP16PSV:
1101 case X86::PTCMMRLFP16PSV:
1102 MachineOperand &MO1 = MI->getOperand(1);
1103 MachineOperand &MO2 = MI->getOperand(2);
1104 ShapeT Shape(&MO1, &MO2, MRI);
1105 VRM->assignVirt2Shape(VirtReg, Shape);
1106 return Shape;
1107 }
1108}
1109
1111 ArrayRef<MCPhysReg> Order,
1113 const MachineFunction &MF,
1114 const VirtRegMap *VRM,
1115 const LiveRegMatrix *Matrix) const {
1116 const MachineRegisterInfo *MRI = &MF.getRegInfo();
1117 const TargetRegisterClass &RC = *MRI->getRegClass(VirtReg);
1118 bool BaseImplRetVal = TargetRegisterInfo::getRegAllocationHints(
1119 VirtReg, Order, Hints, MF, VRM, Matrix);
1120 const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
1121 const TargetRegisterInfo &TRI = *ST.getRegisterInfo();
1122
1123 unsigned ID = RC.getID();
1124
1125 if (!VRM)
1126 return BaseImplRetVal;
1127
1128 if (ID != X86::TILERegClassID) {
1129 if (DisableRegAllocNDDHints || !ST.hasNDD() ||
1130 !TRI.isGeneralPurposeRegisterClass(&RC))
1131 return BaseImplRetVal;
1132
1133 // Add any two address hints after any copy hints.
1134 SmallSet<unsigned, 4> TwoAddrHints;
1135
1136 auto TryAddNDDHint = [&](const MachineOperand &MO) {
1137 Register Reg = MO.getReg();
1138 Register PhysReg =
1139 Register::isPhysicalRegister(Reg) ? Reg : Register(VRM->getPhys(Reg));
1140 if (PhysReg && !MRI->isReserved(PhysReg) && !is_contained(Hints, PhysReg))
1141 TwoAddrHints.insert(PhysReg);
1142 };
1143
1144 // NDD instructions is compressible when Op0 is allocated to the same
1145 // physic register as Op1 (or Op2 if it's commutable).
1146 for (auto &MO : MRI->reg_nodbg_operands(VirtReg)) {
1147 const MachineInstr &MI = *MO.getParent();
1148 if (!X86::getNonNDVariant(MI.getOpcode()))
1149 continue;
1150 unsigned OpIdx = MI.getOperandNo(&MO);
1151 if (OpIdx == 0) {
1152 assert(MI.getOperand(1).isReg());
1153 TryAddNDDHint(MI.getOperand(1));
1154 if (MI.isCommutable()) {
1155 assert(MI.getOperand(2).isReg());
1156 TryAddNDDHint(MI.getOperand(2));
1157 }
1158 } else if (OpIdx == 1) {
1159 TryAddNDDHint(MI.getOperand(0));
1160 } else if (MI.isCommutable() && OpIdx == 2) {
1161 TryAddNDDHint(MI.getOperand(0));
1162 }
1163 }
1164
1165 for (MCPhysReg OrderReg : Order)
1166 if (TwoAddrHints.count(OrderReg))
1167 Hints.push_back(OrderReg);
1168
1169 return BaseImplRetVal;
1170 }
1171
1172 ShapeT VirtShape = getTileShape(VirtReg, const_cast<VirtRegMap *>(VRM), MRI);
1173 auto AddHint = [&](MCPhysReg PhysReg) {
1174 Register VReg = Matrix->getOneVReg(PhysReg);
1175 if (VReg == MCRegister::NoRegister) { // Not allocated yet
1176 Hints.push_back(PhysReg);
1177 return;
1178 }
1179 ShapeT PhysShape = getTileShape(VReg, const_cast<VirtRegMap *>(VRM), MRI);
1180 if (PhysShape == VirtShape)
1181 Hints.push_back(PhysReg);
1182 };
1183
1184 SmallSet<MCPhysReg, 4> CopyHints;
1185 CopyHints.insert(Hints.begin(), Hints.end());
1186 Hints.clear();
1187 for (auto Hint : CopyHints) {
1188 if (RC.contains(Hint) && !MRI->isReserved(Hint))
1189 AddHint(Hint);
1190 }
1191 for (MCPhysReg PhysReg : Order) {
1192 if (!CopyHints.count(PhysReg) && RC.contains(PhysReg) &&
1193 !MRI->isReserved(PhysReg))
1194 AddHint(PhysReg);
1195 }
1196
1197#define DEBUG_TYPE "tile-hint"
1198 LLVM_DEBUG({
1199 dbgs() << "Hints for virtual register " << format_hex(VirtReg, 8) << "\n";
1200 for (auto Hint : Hints) {
1201 dbgs() << "tmm" << Hint << ",";
1202 }
1203 dbgs() << "\n";
1204 });
1205#undef DEBUG_TYPE
1206
1207 return true;
1208}
unsigned SubReg
unsigned const MachineRegisterInfo * MRI
static bool isFuncletReturnInstr(const MachineInstr &MI)
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
basic Basic Alias true
This file implements the BitVector class.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
#define LLVM_DEBUG(X)
Definition: Debug.h:101
Rewrite Partial Register Uses
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
Live Register Matrix
static cl::opt< bool > EnableBasePointer("m68k-use-base-pointer", cl::Hidden, cl::init(true), cl::desc("Enable use of a base pointer for complex stack frames"))
static bool CantUseSP(const MachineFrameInfo &MFI)
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned const TargetRegisterInfo * TRI
uint64_t IntrinsicInst * II
This file declares the machine register scavenger class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallSet class.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition: Value.cpp:469
static cl::opt< bool > EnableBasePointer("x86-use-base-pointer", cl::Hidden, cl::init(true), cl::desc("Enable use of a base pointer for complex stack frames"))
static bool tryOptimizeLEAtoMOV(MachineBasicBlock::iterator II)
static cl::opt< bool > DisableRegAllocNDDHints("x86-disable-regalloc-hints-for-ndd", cl::Hidden, cl::init(false), cl::desc("Disable two address hints for register " "allocation"))
static ShapeT getTileShape(Register VirtReg, VirtRegMap *VRM, const MachineRegisterInfo *MRI)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
A debug info location.
Definition: DebugLoc.h:33
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:281
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.cpp:743
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, MCRegister DestReg, MCRegister SrcReg, bool KillSrc) const override
Emit instructions to copy a pair of physical registers.
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:1068
MCRegAliasIterator enumerates all registers aliasing Reg.
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
static constexpr unsigned NoRegister
Definition: MCRegister.h:52
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
bool hasOpaqueSPAdjustment() const
Returns true if the function contains opaque dynamic stack adjustments.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MCContext & getContext() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Representation of each machine instruction.
Definition: MachineInstr.h:69
MachineOperand class - Representation of each machine instruction operand.
void ChangeToImmediate(int64_t ImmVal, unsigned TargetFlags=0)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
void enterBasicBlockEnd(MachineBasicBlock &MBB)
Start tracking liveness from the end of basic block MBB.
void setRegUsed(Register Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Tell the scavenger a register is used.
void backward()
Update internal register state and move MBB iterator backwards.
Register scavengeRegisterBackwards(const TargetRegisterClass &RC, MachineBasicBlock::iterator To, bool RestoreAfter, int SPAdj, bool AllowSpill=true)
Make a register of the specific register class available from the current position backwards to the p...
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Definition: Register.h:65
Represents a location in source code.
Definition: SMLoc.h:23
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:135
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition: SmallSet.h:166
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:179
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
static StackOffset getFixed(int64_t Fixed)
Definition: TypeSize.h:42
const TargetRegisterClass *const * sc_iterator
unsigned getID() const
Return the register class ID number.
bool contains(Register Reg) const
Return true if the specified register is included in this register class.
sc_iterator getSuperClasses() const
Returns a NULL-terminated list of super-classes.
bool hasSuperClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual bool canRealignStack(const MachineFunction &MF) const
True if the stack can be realigned for the target.
virtual bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const
virtual bool shouldRealignStack(const MachineFunction &MF) const
True if storage within the function requires the stack pointer to be aligned more than the normal cal...
virtual bool getRegAllocationHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallVectorImpl< MCPhysReg > &Hints, const MachineFunction &MF, const VirtRegMap *VRM=nullptr, const LiveRegMatrix *Matrix=nullptr) const
Get a list of 'hint' registers that the register allocator should try first when allocating a physica...
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool hasShape(Register virtReg) const
Definition: VirtRegMap.h:116
ShapeT getShape(Register virtReg) const
Definition: VirtRegMap.h:120
MCRegister getPhys(Register virtReg) const
returns the physical register mapped to the specified virtual register
Definition: VirtRegMap.h:105
void assignVirt2Shape(Register virtReg, ShapeT shape)
Definition: VirtRegMap.h:125
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register.
StackOffset getFrameIndexReferenceSP(const MachineFunction &MF, int FI, Register &SPReg, int Adjustment) const
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
bool Is64Bit
Is64Bit implies that x86_64 instructions are available.
bool Uses64BitFramePtr
True if the 64-bit frame or stack pointer should be used.
int getWin64EHFrameIndexRef(const MachineFunction &MF, int FI, Register &SPReg) const
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
MachineInstr * getStackPtrSaveMI() const
const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const override
getPointerRegClass - Returns a TargetRegisterClass used for pointer values.
unsigned getPtrSizedFrameRegister(const MachineFunction &MF) const
bool hasBasePointer(const MachineFunction &MF) const
const MCPhysReg * getCalleeSavedRegsViaCopy(const MachineFunction *MF) const
const TargetRegisterClass * getGPRsForTailCall(const MachineFunction &MF) const
getGPRsForTailCall - Returns a register class with registers that can be used in forming tail calls.
bool canRealignStack(const MachineFunction &MF) const override
BitVector getReservedRegs(const MachineFunction &MF) const override
getReservedRegs - Returns a bitset indexed by physical register number indicating if a register is a ...
bool shouldRealignStack(const MachineFunction &MF) const override
unsigned getNumSupportedRegs(const MachineFunction &MF) const override
Return the number of registers for the function.
Register getFrameRegister(const MachineFunction &MF) const override
unsigned findDeadCallerSavedReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI) const
findDeadCallerSavedReg - Return a caller-saved register that isn't live when it reaches the "return" ...
const uint32_t * getDarwinTLSCallPreservedMask() const
bool isTileRegisterClass(const TargetRegisterClass *RC) const
Return true if it is tile register class.
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const override
bool isArgumentRegister(const MachineFunction &MF, MCRegister Reg) const override
isArgumentReg - Returns true if Reg can be used as an argument to a function.
Register getStackRegister() const
const TargetRegisterClass * getLargestLegalSuperClass(const TargetRegisterClass *RC, const MachineFunction &MF) const override
const TargetRegisterClass * getMatchingSuperRegClass(const TargetRegisterClass *A, const TargetRegisterClass *B, unsigned Idx) const override
getMatchingSuperRegClass - Return a subclass of the specified register class A so that each register ...
unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const override
unsigned getPtrSizedStackRegister(const MachineFunction &MF) const
int getSEHRegNum(unsigned i) const
bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const override
const TargetRegisterClass * getCrossCopyRegClass(const TargetRegisterClass *RC) const override
getCrossCopyRegClass - Returns a legal register class to copy a register in the specified class to or...
X86RegisterInfo(const Triple &TT)
Register getBaseRegister() const
bool getRegAllocationHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallVectorImpl< MCPhysReg > &Hints, const MachineFunction &MF, const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const override
void eliminateFrameIndex(MachineBasicBlock::iterator II, unsigned FIOperandNum, Register BaseReg, int FIOffset) const
const uint32_t * getNoPreservedMask() const override
bool isFixedRegister(const MachineFunction &MF, MCRegister PhysReg) const override
Returns true if PhysReg is a fixed register.
const TargetRegisterClass * getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const override
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
getCalleeSavedRegs - Return a null-terminated list of all of the callee-save registers on this target...
void adjustStackMapLiveOutMask(uint32_t *Mask) const override
bool hasSSE1() const
Definition: X86Subtarget.h:193
const X86TargetLowering * getTargetLowering() const override
Definition: X86Subtarget.h:118
bool isTarget64BitILP32() const
Is this x86_64 with the ILP32 programming model (x32 ABI)?
Definition: X86Subtarget.h:173
bool isTarget64BitLP64() const
Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
Definition: X86Subtarget.h:178
bool hasAVX512() const
Definition: X86Subtarget.h:201
bool hasAVX() const
Definition: X86Subtarget.h:199
bool supportSwiftError() const override
Return true if the target supports swifterror attribute.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ X86_64_SysV
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
Definition: CallingConv.h:151
@ HiPE
Used by the High-Performance Erlang Compiler (HiPE).
Definition: CallingConv.h:53
@ CFGuard_Check
Special calling convention on Windows for calling the Control Guard Check ICall funtion.
Definition: CallingConv.h:82
@ PreserveMost
Used for runtime calls that preserves most registers.
Definition: CallingConv.h:63
@ AnyReg
OBSOLETED - Used for stack based JavaScript calls.
Definition: CallingConv.h:60
@ CXX_FAST_TLS
Used for access functions.
Definition: CallingConv.h:72
@ X86_INTR
x86 hardware interrupt context.
Definition: CallingConv.h:173
@ GHC
Used by the Glasgow Haskell Compiler (GHC).
Definition: CallingConv.h:50
@ Cold
Attempts to make code in the caller as efficient as possible under the assumption that the call is no...
Definition: CallingConv.h:47
@ PreserveAll
Used for runtime calls that preserves (almost) all registers.
Definition: CallingConv.h:66
@ Intel_OCL_BI
Used for Intel OpenCL built-ins.
Definition: CallingConv.h:147
@ PreserveNone
Used for runtime calls that preserves none general registers.
Definition: CallingConv.h:90
@ Win64
The C convention as implemented on Windows/x86-64 and AArch64.
Definition: CallingConv.h:159
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
Definition: CallingConv.h:87
@ GRAAL
Used by GraalVM. Two additional registers are reserved.
Definition: CallingConv.h:255
@ X86_RegCall
Register calling convention used for parameters transfer optimization.
Definition: CallingConv.h:203
void initLLVMToSEHAndCVRegMapping(MCRegisterInfo *MRI)
unsigned getNonNDVariant(unsigned Opc)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
MCRegister getX86SubSuperRegister(MCRegister Reg, unsigned Size, bool High=false)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1729
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
Definition: Format.h:187
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1886