LLVM 22.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"
16#include "X86FrameLowering.h"
18#include "X86Subtarget.h"
19#include "llvm/ADT/BitVector.h"
20#include "llvm/ADT/STLExtras.h"
21#include "llvm/ADT/SmallSet.h"
30#include "llvm/IR/Function.h"
31#include "llvm/IR/Type.h"
32#include "llvm/MC/MCContext.h"
37
38using namespace llvm;
39
40#define GET_REGINFO_TARGET_DESC
41#include "X86GenRegisterInfo.inc"
42
43static cl::opt<bool>
44EnableBasePointer("x86-use-base-pointer", cl::Hidden, cl::init(true),
45 cl::desc("Enable use of a base pointer for complex stack frames"));
46
47static cl::opt<bool>
48 DisableRegAllocNDDHints("x86-disable-regalloc-hints-for-ndd", cl::Hidden,
49 cl::init(false),
50 cl::desc("Disable two address hints for register "
51 "allocation"));
52
54
56 : X86GenRegisterInfo((TT.isX86_64() ? X86::RIP : X86::EIP),
57 X86_MC::getDwarfRegFlavour(TT, false),
58 X86_MC::getDwarfRegFlavour(TT, true),
59 (TT.isX86_64() ? X86::RIP : X86::EIP)) {
61
62 // Cache some information.
63 Is64Bit = TT.isX86_64();
64 IsTarget64BitLP64 = Is64Bit && !TT.isX32();
65 IsWin64 = Is64Bit && TT.isOSWindows();
66 IsUEFI64 = Is64Bit && TT.isUEFI();
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
90 unsigned Idx) const {
91 // The sub_8bit sub-register index is more constrained in 32-bit mode.
92 // It behaves just like the sub_8bit_hi index.
93 if (!Is64Bit && Idx == X86::sub_8bit)
94 Idx = X86::sub_8bit_hi;
95
96 // Forward to TableGen's default version.
97 return X86GenRegisterInfo::getSubClassWithSubReg(RC, Idx);
98}
99
102 const TargetRegisterClass *B,
103 unsigned SubIdx) const {
104 // The sub_8bit sub-register index is more constrained in 32-bit mode.
105 if (!Is64Bit && SubIdx == X86::sub_8bit) {
106 A = X86GenRegisterInfo::getSubClassWithSubReg(A, X86::sub_8bit_hi);
107 if (!A)
108 return nullptr;
109 }
110 return X86GenRegisterInfo::getMatchingSuperRegClass(A, B, SubIdx);
111}
112
115 const MachineFunction &MF) const {
116 // Don't allow super-classes of GR8_NOREX. This class is only used after
117 // extracting sub_8bit_hi sub-registers. The H sub-registers cannot be copied
118 // to the full GR8 register class in 64-bit mode, so we cannot allow the
119 // reigster class inflation.
120 //
121 // The GR8_NOREX class is always used in a way that won't be constrained to a
122 // sub-class, so sub-classes like GR8_ABCD_L are allowed to expand to the
123 // full GR8 class.
124 if (RC == &X86::GR8_NOREXRegClass)
125 return RC;
126
127 // Keep using non-rex2 register class when APX feature (EGPR/NDD/NF) is not
128 // enabled for relocation.
130 return RC;
131
132 const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
133
134 const TargetRegisterClass *Super = RC;
135 auto I = RC->superclasses().begin();
136 auto E = RC->superclasses().end();
137 do {
138 switch (Super->getID()) {
139 case X86::FR32RegClassID:
140 case X86::FR64RegClassID:
141 // If AVX-512 isn't supported we should only inflate to these classes.
142 if (!Subtarget.hasAVX512() &&
143 getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
144 return Super;
145 break;
146 case X86::VR128RegClassID:
147 case X86::VR256RegClassID:
148 // If VLX isn't supported we should only inflate to these classes.
149 if (!Subtarget.hasVLX() &&
150 getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
151 return Super;
152 break;
153 case X86::VR128XRegClassID:
154 case X86::VR256XRegClassID:
155 // If VLX isn't support we shouldn't inflate to these classes.
156 if (Subtarget.hasVLX() &&
157 getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
158 return Super;
159 break;
160 case X86::FR32XRegClassID:
161 case X86::FR64XRegClassID:
162 // If AVX-512 isn't support we shouldn't inflate to these classes.
163 if (Subtarget.hasAVX512() &&
164 getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
165 return Super;
166 break;
167 case X86::GR8RegClassID:
168 case X86::GR16RegClassID:
169 case X86::GR32RegClassID:
170 case X86::GR64RegClassID:
171 case X86::GR8_NOREX2RegClassID:
172 case X86::GR16_NOREX2RegClassID:
173 case X86::GR32_NOREX2RegClassID:
174 case X86::GR64_NOREX2RegClassID:
175 case X86::RFP32RegClassID:
176 case X86::RFP64RegClassID:
177 case X86::RFP80RegClassID:
178 case X86::VR512_0_15RegClassID:
179 case X86::VR512RegClassID:
180 // Don't return a super-class that would shrink the spill size.
181 // That can happen with the vector and float classes.
182 if (getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
183 return Super;
184 }
185 if (I != E) {
186 Super = getRegClass(*I);
187 ++I;
188 } else {
189 Super = nullptr;
190 }
191 } while (Super);
192 return RC;
193}
194
197 assert(Kind == 0 && "this should only be used for default cases");
198 if (IsTarget64BitLP64)
199 return &X86::GR64RegClass;
200 // If the target is 64bit but we have been told to use 32bit addresses,
201 // we can still use 64-bit register as long as we know the high bits
202 // are zeros.
203 // Reflect that in the returned register class.
204 return Is64Bit ? &X86::LOW32_ADDR_ACCESSRegClass : &X86::GR32RegClass;
205}
206
209 if (RC == &X86::CCRRegClass) {
210 if (Is64Bit)
211 return &X86::GR64RegClass;
212 else
213 return &X86::GR32RegClass;
214 }
215 return RC;
216}
217
218unsigned
220 MachineFunction &MF) const {
221 const X86FrameLowering *TFI = getFrameLowering(MF);
222
223 unsigned FPDiff = TFI->hasFP(MF) ? 1 : 0;
224 switch (RC->getID()) {
225 default:
226 return 0;
227 case X86::GR32RegClassID:
228 return 4 - FPDiff;
229 case X86::GR64RegClassID:
230 return 12 - FPDiff;
231 case X86::VR128RegClassID:
232 return Is64Bit ? 10 : 4;
233 case X86::VR64RegClassID:
234 return 4;
235 }
236}
237
238const MCPhysReg *
240 assert(MF && "MachineFunction required");
241
242 const X86Subtarget &Subtarget = MF->getSubtarget<X86Subtarget>();
243 const Function &F = MF->getFunction();
244 bool HasSSE = Subtarget.hasSSE1();
245 bool HasAVX = Subtarget.hasAVX();
246 bool HasAVX512 = Subtarget.hasAVX512();
247 bool CallsEHReturn = MF->callsEHReturn();
248
249 CallingConv::ID CC = F.getCallingConv();
250
251 // If attribute NoCallerSavedRegisters exists then we set X86_INTR calling
252 // convention because it has the CSR list.
253 if (MF->getFunction().hasFnAttribute("no_caller_saved_registers"))
255
256 // If atribute specified, override the CSRs normally specified by the
257 // calling convention and use the empty set instead.
258 if (MF->getFunction().hasFnAttribute("no_callee_saved_registers"))
259 return CSR_NoRegs_SaveList;
260
261 switch (CC) {
262 case CallingConv::GHC:
264 return CSR_NoRegs_SaveList;
266 if (HasAVX)
267 return CSR_64_AllRegs_AVX_SaveList;
268 return CSR_64_AllRegs_SaveList;
270 return IsWin64 ? CSR_Win64_RT_MostRegs_SaveList
271 : CSR_64_RT_MostRegs_SaveList;
273 if (HasAVX)
274 return CSR_64_RT_AllRegs_AVX_SaveList;
275 return CSR_64_RT_AllRegs_SaveList;
277 return CSR_64_NoneRegs_SaveList;
279 if (Is64Bit)
280 return MF->getInfo<X86MachineFunctionInfo>()->isSplitCSR() ?
281 CSR_64_CXX_TLS_Darwin_PE_SaveList : CSR_64_TLS_Darwin_SaveList;
282 break;
284 if (HasAVX512 && IsWin64)
285 return CSR_Win64_Intel_OCL_BI_AVX512_SaveList;
286 if (HasAVX512 && Is64Bit)
287 return CSR_64_Intel_OCL_BI_AVX512_SaveList;
288 if (HasAVX && IsWin64)
289 return CSR_Win64_Intel_OCL_BI_AVX_SaveList;
290 if (HasAVX && Is64Bit)
291 return CSR_64_Intel_OCL_BI_AVX_SaveList;
292 if (!HasAVX && !IsWin64 && Is64Bit)
293 return CSR_64_Intel_OCL_BI_SaveList;
294 break;
295 }
297 if (Is64Bit) {
298 if (IsWin64) {
299 return (HasSSE ? CSR_Win64_RegCall_SaveList :
300 CSR_Win64_RegCall_NoSSE_SaveList);
301 } else {
302 return (HasSSE ? CSR_SysV64_RegCall_SaveList :
303 CSR_SysV64_RegCall_NoSSE_SaveList);
304 }
305 } else {
306 return (HasSSE ? CSR_32_RegCall_SaveList :
307 CSR_32_RegCall_NoSSE_SaveList);
308 }
310 assert(!Is64Bit && "CFGuard check mechanism only used on 32-bit X86");
311 return (HasSSE ? CSR_Win32_CFGuard_Check_SaveList
312 : CSR_Win32_CFGuard_Check_NoSSE_SaveList);
314 if (Is64Bit)
315 return CSR_64_MostRegs_SaveList;
316 break;
318 if (!HasSSE)
319 return CSR_Win64_NoSSE_SaveList;
320 return CSR_Win64_SaveList;
322 if (!Is64Bit)
323 return CSR_32_SaveList;
324 return IsWin64 ? CSR_Win64_SwiftTail_SaveList : CSR_64_SwiftTail_SaveList;
326 if (CallsEHReturn)
327 return CSR_64EHRet_SaveList;
328 return CSR_64_SaveList;
330 if (Is64Bit) {
331 if (HasAVX512)
332 return CSR_64_AllRegs_AVX512_SaveList;
333 if (HasAVX)
334 return CSR_64_AllRegs_AVX_SaveList;
335 if (HasSSE)
336 return CSR_64_AllRegs_SaveList;
337 return CSR_64_AllRegs_NoSSE_SaveList;
338 } else {
339 if (HasAVX512)
340 return CSR_32_AllRegs_AVX512_SaveList;
341 if (HasAVX)
342 return CSR_32_AllRegs_AVX_SaveList;
343 if (HasSSE)
344 return CSR_32_AllRegs_SSE_SaveList;
345 return CSR_32_AllRegs_SaveList;
346 }
347 default:
348 break;
349 }
350
351 if (Is64Bit) {
352 bool IsSwiftCC = Subtarget.getTargetLowering()->supportSwiftError() &&
353 F.getAttributes().hasAttrSomewhere(Attribute::SwiftError);
354 if (IsSwiftCC)
355 return IsWin64 ? CSR_Win64_SwiftError_SaveList
356 : CSR_64_SwiftError_SaveList;
357
358 if (IsWin64 || IsUEFI64)
359 return HasSSE ? CSR_Win64_SaveList : CSR_Win64_NoSSE_SaveList;
360 if (CallsEHReturn)
361 return CSR_64EHRet_SaveList;
362 return CSR_64_SaveList;
363 }
364
365 return CallsEHReturn ? CSR_32EHRet_SaveList : CSR_32_SaveList;
366}
367
368const MCPhysReg *
370 return Is64Bit ? CSR_IPRA_64_SaveList : CSR_IPRA_32_SaveList;
371}
372
374 const MachineFunction *MF) const {
375 assert(MF && "Invalid MachineFunction pointer.");
378 return CSR_64_CXX_TLS_Darwin_ViaCopy_SaveList;
379 return nullptr;
380}
381
382const uint32_t *
384 CallingConv::ID CC) const {
385 const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
386 bool HasSSE = Subtarget.hasSSE1();
387 bool HasAVX = Subtarget.hasAVX();
388 bool HasAVX512 = Subtarget.hasAVX512();
389
390 switch (CC) {
391 case CallingConv::GHC:
393 return CSR_NoRegs_RegMask;
395 if (HasAVX)
396 return CSR_64_AllRegs_AVX_RegMask;
397 return CSR_64_AllRegs_RegMask;
399 return IsWin64 ? CSR_Win64_RT_MostRegs_RegMask : CSR_64_RT_MostRegs_RegMask;
401 if (HasAVX)
402 return CSR_64_RT_AllRegs_AVX_RegMask;
403 return CSR_64_RT_AllRegs_RegMask;
405 return CSR_64_NoneRegs_RegMask;
407 if (Is64Bit)
408 return CSR_64_TLS_Darwin_RegMask;
409 break;
411 if (HasAVX512 && IsWin64)
412 return CSR_Win64_Intel_OCL_BI_AVX512_RegMask;
413 if (HasAVX512 && Is64Bit)
414 return CSR_64_Intel_OCL_BI_AVX512_RegMask;
415 if (HasAVX && IsWin64)
416 return CSR_Win64_Intel_OCL_BI_AVX_RegMask;
417 if (HasAVX && Is64Bit)
418 return CSR_64_Intel_OCL_BI_AVX_RegMask;
419 if (!HasAVX && !IsWin64 && Is64Bit)
420 return CSR_64_Intel_OCL_BI_RegMask;
421 break;
422 }
424 if (Is64Bit) {
425 if (IsWin64) {
426 return (HasSSE ? CSR_Win64_RegCall_RegMask :
427 CSR_Win64_RegCall_NoSSE_RegMask);
428 } else {
429 return (HasSSE ? CSR_SysV64_RegCall_RegMask :
430 CSR_SysV64_RegCall_NoSSE_RegMask);
431 }
432 } else {
433 return (HasSSE ? CSR_32_RegCall_RegMask :
434 CSR_32_RegCall_NoSSE_RegMask);
435 }
437 assert(!Is64Bit && "CFGuard check mechanism only used on 32-bit X86");
438 return (HasSSE ? CSR_Win32_CFGuard_Check_RegMask
439 : CSR_Win32_CFGuard_Check_NoSSE_RegMask);
441 if (Is64Bit)
442 return CSR_64_MostRegs_RegMask;
443 break;
445 return CSR_Win64_RegMask;
447 if (!Is64Bit)
448 return CSR_32_RegMask;
449 return IsWin64 ? CSR_Win64_SwiftTail_RegMask : CSR_64_SwiftTail_RegMask;
451 return CSR_64_RegMask;
453 if (Is64Bit) {
454 if (HasAVX512)
455 return CSR_64_AllRegs_AVX512_RegMask;
456 if (HasAVX)
457 return CSR_64_AllRegs_AVX_RegMask;
458 if (HasSSE)
459 return CSR_64_AllRegs_RegMask;
460 return CSR_64_AllRegs_NoSSE_RegMask;
461 } else {
462 if (HasAVX512)
463 return CSR_32_AllRegs_AVX512_RegMask;
464 if (HasAVX)
465 return CSR_32_AllRegs_AVX_RegMask;
466 if (HasSSE)
467 return CSR_32_AllRegs_SSE_RegMask;
468 return CSR_32_AllRegs_RegMask;
469 }
470 default:
471 break;
472 }
473
474 // Unlike getCalleeSavedRegs(), we don't have MMI so we can't check
475 // callsEHReturn().
476 if (Is64Bit) {
477 const Function &F = MF.getFunction();
478 bool IsSwiftCC = Subtarget.getTargetLowering()->supportSwiftError() &&
479 F.getAttributes().hasAttrSomewhere(Attribute::SwiftError);
480 if (IsSwiftCC)
481 return IsWin64 ? CSR_Win64_SwiftError_RegMask : CSR_64_SwiftError_RegMask;
482
483 return (IsWin64 || IsUEFI64) ? CSR_Win64_RegMask : CSR_64_RegMask;
484 }
485
486 return CSR_32_RegMask;
487}
488
489const uint32_t*
491 return CSR_NoRegs_RegMask;
492}
493
495 return CSR_64_TLS_Darwin_RegMask;
496}
497
499 BitVector Reserved(getNumRegs());
500 const X86FrameLowering *TFI = getFrameLowering(MF);
501
502 // Set the floating point control register as reserved.
503 Reserved.set(X86::FPCW);
504
505 // Set the floating point status register as reserved.
506 Reserved.set(X86::FPSW);
507
508 // Set the SIMD floating point control register as reserved.
509 Reserved.set(X86::MXCSR);
510
511 // Set the stack-pointer register and its aliases as reserved.
512 for (const MCPhysReg &SubReg : subregs_inclusive(X86::RSP))
513 Reserved.set(SubReg);
514
515 // Set the Shadow Stack Pointer as reserved.
516 Reserved.set(X86::SSP);
517
518 // Set the instruction pointer register and its aliases as reserved.
519 for (const MCPhysReg &SubReg : subregs_inclusive(X86::RIP))
520 Reserved.set(SubReg);
521
522 // Set the frame-pointer register and its aliases as reserved if needed.
523 if (TFI->hasFP(MF) || MF.getTarget().Options.FramePointerIsReserved(MF)) {
526 SMLoc(),
527 "Frame pointer clobbered by function invoke is not supported.");
528
529 for (const MCPhysReg &SubReg : subregs_inclusive(X86::RBP))
530 Reserved.set(SubReg);
531 }
532
533 // Set the base-pointer register and its aliases as reserved if needed.
534 if (hasBasePointer(MF)) {
537 "Stack realignment in presence of dynamic "
538 "allocas is not supported with "
539 "this calling convention.");
540
542 for (const MCPhysReg &SubReg : subregs_inclusive(BasePtr))
543 Reserved.set(SubReg);
544 }
545
546 // Mark the segment registers as reserved.
547 Reserved.set(X86::CS);
548 Reserved.set(X86::SS);
549 Reserved.set(X86::DS);
550 Reserved.set(X86::ES);
551 Reserved.set(X86::FS);
552 Reserved.set(X86::GS);
553
554 // Mark the floating point stack registers as reserved.
555 for (unsigned n = 0; n != 8; ++n)
556 Reserved.set(X86::ST0 + n);
557
558 // Reserve the registers that only exist in 64-bit mode.
559 if (!Is64Bit) {
560 // These 8-bit registers are part of the x86-64 extension even though their
561 // super-registers are old 32-bits.
562 Reserved.set(X86::SIL);
563 Reserved.set(X86::DIL);
564 Reserved.set(X86::BPL);
565 Reserved.set(X86::SPL);
566 Reserved.set(X86::SIH);
567 Reserved.set(X86::DIH);
568 Reserved.set(X86::BPH);
569 Reserved.set(X86::SPH);
570
571 for (unsigned n = 0; n != 8; ++n) {
572 // R8, R9, ...
573 for (MCRegAliasIterator AI(X86::R8 + n, this, true); AI.isValid(); ++AI)
574 Reserved.set(*AI);
575
576 // XMM8, XMM9, ...
577 for (MCRegAliasIterator AI(X86::XMM8 + n, this, true); AI.isValid(); ++AI)
578 Reserved.set(*AI);
579 }
580 }
581 if (!Is64Bit || !MF.getSubtarget<X86Subtarget>().hasAVX512()) {
582 for (unsigned n = 0; n != 16; ++n) {
583 for (MCRegAliasIterator AI(X86::XMM16 + n, this, true); AI.isValid();
584 ++AI)
585 Reserved.set(*AI);
586 }
587 }
588
589 // Reserve the extended general purpose registers.
590 if (!Is64Bit || !MF.getSubtarget<X86Subtarget>().hasEGPR())
591 Reserved.set(X86::R16, X86::R31WH + 1);
592
594 for (MCRegAliasIterator AI(X86::R14, this, true); AI.isValid(); ++AI)
595 Reserved.set(*AI);
596 for (MCRegAliasIterator AI(X86::R15, this, true); AI.isValid(); ++AI)
597 Reserved.set(*AI);
598 }
599
600 // Reserve low half pair registers in case they are used by RA aggressively.
601 Reserved.set(X86::TMM0_TMM1);
602 Reserved.set(X86::TMM2_TMM3);
603
604 assert(checkAllSuperRegsMarked(Reserved,
605 {X86::SIL, X86::DIL, X86::BPL, X86::SPL,
606 X86::SIH, X86::DIH, X86::BPH, X86::SPH}));
607 return Reserved;
608}
609
611 // All existing Intel CPUs that support AMX support AVX512 and all existing
612 // Intel CPUs that support APX support AMX. AVX512 implies AVX.
613 //
614 // We enumerate the registers in X86GenRegisterInfo.inc in this order:
615 //
616 // Registers before AVX512,
617 // AVX512 registers (X/YMM16-31, ZMM0-31, K registers)
618 // AMX registers (TMM)
619 // APX registers (R16-R31)
620 //
621 // and try to return the minimum number of registers supported by the target.
622 static_assert((X86::R15WH + 1 == X86::YMM0) && (X86::YMM15 + 1 == X86::K0) &&
623 (X86::K6_K7 + 1 == X86::TMMCFG) &&
624 (X86::TMM6_TMM7 + 1 == X86::R16) &&
625 (X86::R31WH + 1 == X86::NUM_TARGET_REGS),
626 "Register number may be incorrect");
627
628 const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
629 if (ST.hasEGPR())
630 return X86::NUM_TARGET_REGS;
631 if (ST.hasAMXTILE())
632 return X86::TMM7 + 1;
633 if (ST.hasAVX512())
634 return X86::K6_K7 + 1;
635 if (ST.hasAVX())
636 return X86::YMM15 + 1;
637 return X86::R15WH + 1;
638}
639
641 MCRegister Reg) const {
642 const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
643 const TargetRegisterInfo &TRI = *ST.getRegisterInfo();
644 auto IsSubReg = [&](MCRegister RegA, MCRegister RegB) {
645 return TRI.isSuperOrSubRegisterEq(RegA, RegB);
646 };
647
648 if (!ST.is64Bit())
649 return llvm::any_of(
650 SmallVector<MCRegister>{X86::EAX, X86::ECX, X86::EDX},
651 [&](MCRegister &RegA) { return IsSubReg(RegA, Reg); }) ||
652 (ST.hasMMX() && X86::VR64RegClass.contains(Reg));
653
655
656 if (CC == CallingConv::X86_64_SysV && IsSubReg(X86::RAX, Reg))
657 return true;
658
659 if (llvm::any_of(
660 SmallVector<MCRegister>{X86::RDX, X86::RCX, X86::R8, X86::R9},
661 [&](MCRegister &RegA) { return IsSubReg(RegA, Reg); }))
662 return true;
663
664 if (CC != CallingConv::Win64 &&
665 llvm::any_of(SmallVector<MCRegister>{X86::RDI, X86::RSI},
666 [&](MCRegister &RegA) { return IsSubReg(RegA, Reg); }))
667 return true;
668
669 if (ST.hasSSE1() &&
670 llvm::any_of(SmallVector<MCRegister>{X86::XMM0, X86::XMM1, X86::XMM2,
671 X86::XMM3, X86::XMM4, X86::XMM5,
672 X86::XMM6, X86::XMM7},
673 [&](MCRegister &RegA) { return IsSubReg(RegA, Reg); }))
674 return true;
675
676 return X86GenRegisterInfo::isArgumentRegister(MF, Reg);
677}
678
680 MCRegister PhysReg) const {
681 const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
682 const TargetRegisterInfo &TRI = *ST.getRegisterInfo();
683
684 // Stack pointer.
685 if (TRI.isSuperOrSubRegisterEq(X86::RSP, PhysReg))
686 return true;
687
688 // Don't use the frame pointer if it's being used.
689 const X86FrameLowering &TFI = *getFrameLowering(MF);
690 if (TFI.hasFP(MF) && TRI.isSuperOrSubRegisterEq(X86::RBP, PhysReg))
691 return true;
692
693 return X86GenRegisterInfo::isFixedRegister(MF, PhysReg);
694}
695
697 return RC->getID() == X86::TILERegClassID ||
698 RC->getID() == X86::TILEPAIRRegClassID;
699}
700
702 // Check if the EFLAGS register is marked as live-out. This shouldn't happen,
703 // because the calling convention defines the EFLAGS register as NOT
704 // preserved.
705 //
706 // Unfortunatelly the EFLAGS show up as live-out after branch folding. Adding
707 // an assert to track this and clear the register afterwards to avoid
708 // unnecessary crashes during release builds.
709 assert(!(Mask[X86::EFLAGS / 32] & (1U << (X86::EFLAGS % 32))) &&
710 "EFLAGS are not live-out from a patchpoint.");
711
712 // Also clean other registers that don't need preserving (IP).
713 for (auto Reg : {X86::EFLAGS, X86::RIP, X86::EIP, X86::IP})
714 Mask[Reg / 32] &= ~(1U << (Reg % 32));
715}
716
717//===----------------------------------------------------------------------===//
718// Stack Frame Processing methods
719//===----------------------------------------------------------------------===//
720
721static bool CantUseSP(const MachineFrameInfo &MFI) {
722 return MFI.hasVarSizedObjects() || MFI.hasOpaqueSPAdjustment();
723}
724
727 // We have a virtual register to reference argument, and don't need base
728 // pointer.
729 if (X86FI->getStackPtrSaveMI() != nullptr)
730 return false;
731
732 if (X86FI->hasPreallocatedCall())
733 return true;
734
735 const MachineFrameInfo &MFI = MF.getFrameInfo();
736
738 return false;
739
740 // When we need stack realignment, we can't address the stack from the frame
741 // pointer. When we have dynamic allocas or stack-adjusting inline asm, we
742 // can't address variables from the stack pointer. MS inline asm can
743 // reference locals while also adjusting the stack pointer. When we can't
744 // use both the SP and the FP, we need a separate base pointer register.
745 bool CantUseFP = hasStackRealignment(MF);
746 return CantUseFP && CantUseSP(MFI);
747}
748
751 return false;
752
753 const MachineFrameInfo &MFI = MF.getFrameInfo();
754 const MachineRegisterInfo *MRI = &MF.getRegInfo();
755
756 // Stack realignment requires a frame pointer. If we already started
757 // register allocation with frame pointer elimination, it is too late now.
758 if (!MRI->canReserveReg(FramePtr))
759 return false;
760
761 // If a base pointer is necessary. Check that it isn't too late to reserve
762 // it.
763 if (CantUseSP(MFI))
764 return MRI->canReserveReg(BasePtr);
765 return true;
766}
767
770 return true;
771
772 return !Is64Bit && MF.getFunction().getCallingConv() == CallingConv::X86_INTR;
773}
774
775// tryOptimizeLEAtoMOV - helper function that tries to replace a LEA instruction
776// of the form 'lea (%esp), %ebx' --> 'mov %esp, %ebx'.
777// TODO: In this case we should be really trying first to entirely eliminate
778// this instruction which is a plain copy.
780 MachineInstr &MI = *II;
781 unsigned Opc = II->getOpcode();
782 // Check if this is a LEA of the form 'lea (%esp), %ebx'
783 if ((Opc != X86::LEA32r && Opc != X86::LEA64r && Opc != X86::LEA64_32r) ||
784 MI.getOperand(2).getImm() != 1 ||
785 MI.getOperand(3).getReg() != X86::NoRegister ||
786 MI.getOperand(4).getImm() != 0 ||
787 MI.getOperand(5).getReg() != X86::NoRegister)
788 return false;
789 Register BasePtr = MI.getOperand(1).getReg();
790 // In X32 mode, ensure the base-pointer is a 32-bit operand, so the LEA will
791 // be replaced with a 32-bit operand MOV which will zero extend the upper
792 // 32-bits of the super register.
793 if (Opc == X86::LEA64_32r)
794 BasePtr = getX86SubSuperRegister(BasePtr, 32);
795 Register NewDestReg = MI.getOperand(0).getReg();
796 const X86InstrInfo *TII =
797 MI.getParent()->getParent()->getSubtarget<X86Subtarget>().getInstrInfo();
798 TII->copyPhysReg(*MI.getParent(), II, MI.getDebugLoc(), NewDestReg, BasePtr,
799 MI.getOperand(1).isKill());
800 MI.eraseFromParent();
801 return true;
802}
803
805 switch (MI.getOpcode()) {
806 case X86::CATCHRET:
807 case X86::CLEANUPRET:
808 return true;
809 default:
810 return false;
811 }
812 llvm_unreachable("impossible");
813}
814
816 unsigned FIOperandNum,
817 Register BaseReg,
818 int FIOffset) const {
819 MachineInstr &MI = *II;
820 unsigned Opc = MI.getOpcode();
821 if (Opc == TargetOpcode::LOCAL_ESCAPE) {
822 MachineOperand &FI = MI.getOperand(FIOperandNum);
823 FI.ChangeToImmediate(FIOffset);
824 return;
825 }
826
827 MI.getOperand(FIOperandNum).ChangeToRegister(BaseReg, false);
828
829 // The frame index format for stackmaps and patchpoints is different from the
830 // X86 format. It only has a FI and an offset.
831 if (Opc == TargetOpcode::STACKMAP || Opc == TargetOpcode::PATCHPOINT) {
832 assert(BasePtr == FramePtr && "Expected the FP as base register");
833 int64_t Offset = MI.getOperand(FIOperandNum + 1).getImm() + FIOffset;
834 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
835 return;
836 }
837
838 if (MI.getOperand(FIOperandNum + 3).isImm()) {
839 // Offset is a 32-bit integer.
840 int Imm = (int)(MI.getOperand(FIOperandNum + 3).getImm());
841 int Offset = FIOffset + Imm;
842 assert((!Is64Bit || isInt<32>((long long)FIOffset + Imm)) &&
843 "Requesting 64-bit offset in 32-bit immediate!");
844 if (Offset != 0)
845 MI.getOperand(FIOperandNum + 3).ChangeToImmediate(Offset);
846 } else {
847 // Offset is symbolic. This is extremely rare.
849 FIOffset + (uint64_t)MI.getOperand(FIOperandNum + 3).getOffset();
850 MI.getOperand(FIOperandNum + 3).setOffset(Offset);
851 }
852}
853
854bool
856 int SPAdj, unsigned FIOperandNum,
857 RegScavenger *RS) const {
858 MachineInstr &MI = *II;
859 MachineBasicBlock &MBB = *MI.getParent();
860 MachineFunction &MF = *MBB.getParent();
861 MachineBasicBlock::iterator MBBI = MBB.getFirstTerminator();
862 bool IsEHFuncletEpilogue = MBBI == MBB.end() ? false
864 const X86FrameLowering *TFI = getFrameLowering(MF);
865 int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
866
867 // Determine base register and offset.
868 int64_t FIOffset;
869 Register BasePtr;
870 if (MI.isReturn()) {
871 assert((!hasStackRealignment(MF) ||
872 MF.getFrameInfo().isFixedObjectIndex(FrameIndex)) &&
873 "Return instruction can only reference SP relative frame objects");
874 FIOffset =
875 TFI->getFrameIndexReferenceSP(MF, FrameIndex, BasePtr, 0).getFixed();
876 } else if (TFI->Is64Bit && (MBB.isEHFuncletEntry() || IsEHFuncletEpilogue)) {
877 FIOffset = TFI->getWin64EHFrameIndexRef(MF, FrameIndex, BasePtr);
878 } else {
879 FIOffset = TFI->getFrameIndexReference(MF, FrameIndex, BasePtr).getFixed();
880 }
881
882 // LOCAL_ESCAPE uses a single offset, with no register. It only works in the
883 // simple FP case, and doesn't work with stack realignment. On 32-bit, the
884 // offset is from the traditional base pointer location. On 64-bit, the
885 // offset is from the SP at the end of the prologue, not the FP location. This
886 // matches the behavior of llvm.frameaddress.
887 unsigned Opc = MI.getOpcode();
888 if (Opc == TargetOpcode::LOCAL_ESCAPE) {
889 MachineOperand &FI = MI.getOperand(FIOperandNum);
890 FI.ChangeToImmediate(FIOffset);
891 return false;
892 }
893
894 // For LEA64_32r when BasePtr is 32-bits (X32) we can use full-size 64-bit
895 // register as source operand, semantic is the same and destination is
896 // 32-bits. It saves one byte per lea in code since 0x67 prefix is avoided.
897 // Don't change BasePtr since it is used later for stack adjustment.
898 Register MachineBasePtr = BasePtr;
899 if (Opc == X86::LEA64_32r && X86::GR32RegClass.contains(BasePtr))
900 MachineBasePtr = getX86SubSuperRegister(BasePtr, 64);
901
902 // This must be part of a four operand memory reference. Replace the
903 // FrameIndex with base register. Add an offset to the offset.
904 MI.getOperand(FIOperandNum).ChangeToRegister(MachineBasePtr, false);
905
906 if (BasePtr == StackPtr)
907 FIOffset += SPAdj;
908
909 // The frame index format for stackmaps and patchpoints is different from the
910 // X86 format. It only has a FI and an offset.
911 if (Opc == TargetOpcode::STACKMAP || Opc == TargetOpcode::PATCHPOINT) {
912 assert(BasePtr == FramePtr && "Expected the FP as base register");
913 int64_t Offset = MI.getOperand(FIOperandNum + 1).getImm() + FIOffset;
914 MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
915 return false;
916 }
917
918 if (MI.getOperand(FIOperandNum+3).isImm()) {
919 const X86InstrInfo *TII = MF.getSubtarget<X86Subtarget>().getInstrInfo();
920 const DebugLoc &DL = MI.getDebugLoc();
921 int64_t Imm = MI.getOperand(FIOperandNum + 3).getImm();
922 int64_t Offset = FIOffset + Imm;
923 bool FitsIn32Bits = isInt<32>(Offset);
924 // If the offset will not fit in a 32-bit displacement, then for 64-bit
925 // targets, scavenge a register to hold it. Otherwise...
926 if (Is64Bit && !FitsIn32Bits) {
927 assert(RS && "RegisterScavenger was NULL");
928
930 RS->backward(std::next(II));
931
932 Register ScratchReg = RS->scavengeRegisterBackwards(
933 X86::GR64RegClass, II, /*RestoreAfter=*/false, /*SPAdj=*/0,
934 /*AllowSpill=*/true);
935 assert(ScratchReg != 0 && "scratch reg was 0");
936 RS->setRegUsed(ScratchReg);
937
938 BuildMI(MBB, II, DL, TII->get(X86::MOV64ri), ScratchReg).addImm(Offset);
939
940 MI.getOperand(FIOperandNum + 3).setImm(0);
941 MI.getOperand(FIOperandNum + 2).setReg(ScratchReg);
942
943 return false;
944 }
945
946 // ... for 32-bit targets, this is a bug!
947 if (!Is64Bit && !FitsIn32Bits) {
948 MI.emitGenericError("64-bit offset calculated but target is 32-bit");
949 // Trap so that the instruction verification pass does not fail if run.
950 BuildMI(MBB, MBBI, DL, TII->get(X86::TRAP));
951 return false;
952 }
953
954 if (Offset != 0 || !tryOptimizeLEAtoMOV(II))
955 MI.getOperand(FIOperandNum + 3).ChangeToImmediate(Offset);
956 } else {
957 // Offset is symbolic. This is extremely rare.
958 uint64_t Offset = FIOffset +
959 (uint64_t)MI.getOperand(FIOperandNum+3).getOffset();
960 MI.getOperand(FIOperandNum + 3).setOffset(Offset);
961 }
962 return false;
963}
964
967 const MachineFunction *MF = MBB.getParent();
968 const MachineRegisterInfo &MRI = MF->getRegInfo();
969 if (MF->callsEHReturn())
970 return 0;
971
972 if (MBBI == MBB.end())
973 return 0;
974
975 switch (MBBI->getOpcode()) {
976 default:
977 return 0;
978 case TargetOpcode::PATCHABLE_RET:
979 case X86::RET:
980 case X86::RET32:
981 case X86::RET64:
982 case X86::RETI32:
983 case X86::RETI64:
984 case X86::TCRETURNdi:
985 case X86::TCRETURNri:
986 case X86::TCRETURN_WIN64ri:
987 case X86::TCRETURN_HIPE32ri:
988 case X86::TCRETURNmi:
989 case X86::TCRETURNdi64:
990 case X86::TCRETURNri64:
991 case X86::TCRETURNri64_ImpCall:
992 case X86::TCRETURNmi64:
993 case X86::TCRETURN_WINmi64:
994 case X86::EH_RETURN:
995 case X86::EH_RETURN64: {
996 LiveRegUnits LRU(*this);
997 LRU.addLiveOuts(MBB);
998 LRU.stepBackward(*MBBI);
999
1000 const TargetRegisterClass &RC =
1001 Is64Bit ? X86::GR64_NOSPRegClass : X86::GR32_NOSPRegClass;
1002 for (MCRegister Reg : RC) {
1003 if (LRU.available(Reg) && !MRI.isReserved(Reg))
1004 return Reg;
1005 }
1006 }
1007 }
1008
1009 return 0;
1010}
1011
1013 const X86FrameLowering *TFI = getFrameLowering(MF);
1014 return TFI->hasFP(MF) ? FramePtr : StackPtr;
1015}
1016
1019 const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
1020 Register FrameReg = getFrameRegister(MF);
1021 if (Subtarget.isTarget64BitILP32())
1022 FrameReg = getX86SubSuperRegister(FrameReg, 32);
1023 return FrameReg;
1024}
1025
1028 const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
1029 Register StackReg = getStackRegister();
1030 if (Subtarget.isTarget64BitILP32())
1031 StackReg = getX86SubSuperRegister(StackReg, 32);
1032 return StackReg;
1033}
1034
1036 const MachineRegisterInfo *MRI) {
1037 if (VRM->hasShape(VirtReg))
1038 return VRM->getShape(VirtReg);
1039
1040 const MachineOperand &Def = *MRI->def_begin(VirtReg);
1041 MachineInstr *MI = const_cast<MachineInstr *>(Def.getParent());
1042 unsigned OpCode = MI->getOpcode();
1043 switch (OpCode) {
1044 default:
1045 llvm_unreachable("Unexpected machine instruction on tile register!");
1046 break;
1047 case X86::COPY: {
1048 Register SrcReg = MI->getOperand(1).getReg();
1049 ShapeT Shape = getTileShape(SrcReg, VRM, MRI);
1050 VRM->assignVirt2Shape(VirtReg, Shape);
1051 return Shape;
1052 }
1053 // We only collect the tile shape that is defined.
1054 case X86::PTILELOADDV:
1055 case X86::PTILELOADDT1V:
1056 case X86::PTDPBSSDV:
1057 case X86::PTDPBSUDV:
1058 case X86::PTDPBUSDV:
1059 case X86::PTDPBUUDV:
1060 case X86::PTILEZEROV:
1061 case X86::PTDPBF16PSV:
1062 case X86::PTDPFP16PSV:
1063 case X86::PTCMMIMFP16PSV:
1064 case X86::PTCMMRLFP16PSV:
1065 case X86::PTTRANSPOSEDV:
1066 case X86::PTTDPBF16PSV:
1067 case X86::PTTDPFP16PSV:
1068 case X86::PTTCMMIMFP16PSV:
1069 case X86::PTTCMMRLFP16PSV:
1070 case X86::PTCONJTCMMIMFP16PSV:
1071 case X86::PTCONJTFP16V:
1072 case X86::PTILELOADDRSV:
1073 case X86::PTILELOADDRST1V:
1074 case X86::PTMMULTF32PSV:
1075 case X86::PTTMMULTF32PSV:
1076 case X86::PTDPBF8PSV:
1077 case X86::PTDPBHF8PSV:
1078 case X86::PTDPHBF8PSV:
1079 case X86::PTDPHF8PSV: {
1080 MachineOperand &MO1 = MI->getOperand(1);
1081 MachineOperand &MO2 = MI->getOperand(2);
1082 ShapeT Shape(&MO1, &MO2, MRI);
1083 VRM->assignVirt2Shape(VirtReg, Shape);
1084 return Shape;
1085 }
1086 case X86::PT2RPNTLVWZ0V:
1087 case X86::PT2RPNTLVWZ0T1V:
1088 case X86::PT2RPNTLVWZ1V:
1089 case X86::PT2RPNTLVWZ1T1V:
1090 case X86::PT2RPNTLVWZ0RSV:
1091 case X86::PT2RPNTLVWZ0RST1V:
1092 case X86::PT2RPNTLVWZ1RSV:
1093 case X86::PT2RPNTLVWZ1RST1V: {
1094 MachineOperand &MO1 = MI->getOperand(1);
1095 MachineOperand &MO2 = MI->getOperand(2);
1096 MachineOperand &MO3 = MI->getOperand(3);
1097 ShapeT Shape({&MO1, &MO2, &MO1, &MO3}, MRI);
1098 VRM->assignVirt2Shape(VirtReg, Shape);
1099 return Shape;
1100 }
1101 }
1102}
1103
1104static bool canHintShape(ShapeT &PhysShape, ShapeT &VirtShape) {
1105 unsigned PhysShapeNum = PhysShape.getShapeNum();
1106 unsigned VirtShapeNum = VirtShape.getShapeNum();
1107
1108 if (PhysShapeNum < VirtShapeNum)
1109 return false;
1110
1111 if (PhysShapeNum == VirtShapeNum) {
1112 if (PhysShapeNum == 1)
1113 return PhysShape == VirtShape;
1114
1115 for (unsigned I = 0; I < PhysShapeNum; I++) {
1116 ShapeT PShape(PhysShape.getRow(I), PhysShape.getCol(I));
1117 ShapeT VShape(VirtShape.getRow(I), VirtShape.getCol(I));
1118 if (VShape != PShape)
1119 return false;
1120 }
1121 return true;
1122 }
1123
1124 // Hint subreg of mult-tile reg to single tile reg.
1125 if (VirtShapeNum == 1) {
1126 for (unsigned I = 0; I < PhysShapeNum; I++) {
1127 ShapeT PShape(PhysShape.getRow(I), PhysShape.getCol(I));
1128 if (VirtShape == PShape)
1129 return true;
1130 }
1131 }
1132
1133 // Note: Currently we have no requirement for case of
1134 // (VirtShapeNum > 1 and PhysShapeNum > VirtShapeNum)
1135 return false;
1136}
1137
1139 ArrayRef<MCPhysReg> Order,
1141 const MachineFunction &MF,
1142 const VirtRegMap *VRM,
1143 const LiveRegMatrix *Matrix) const {
1144 const MachineRegisterInfo *MRI = &MF.getRegInfo();
1145 const TargetRegisterClass &RC = *MRI->getRegClass(VirtReg);
1146 bool BaseImplRetVal = TargetRegisterInfo::getRegAllocationHints(
1147 VirtReg, Order, Hints, MF, VRM, Matrix);
1148 const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
1149 const TargetRegisterInfo &TRI = *ST.getRegisterInfo();
1150
1151 unsigned ID = RC.getID();
1152
1153 if (!VRM)
1154 return BaseImplRetVal;
1155
1156 if (ID != X86::TILERegClassID && ID != X86::TILEPAIRRegClassID) {
1157 if (DisableRegAllocNDDHints || !ST.hasNDD() ||
1158 !TRI.isGeneralPurposeRegisterClass(&RC))
1159 return BaseImplRetVal;
1160
1161 // Add any two address hints after any copy hints.
1162 SmallSet<unsigned, 4> TwoAddrHints;
1163
1164 auto TryAddNDDHint = [&](const MachineOperand &MO) {
1165 Register Reg = MO.getReg();
1166 Register PhysReg = Reg.isPhysical() ? Reg : Register(VRM->getPhys(Reg));
1167 if (PhysReg && !MRI->isReserved(PhysReg) && !is_contained(Hints, PhysReg))
1168 TwoAddrHints.insert(PhysReg);
1169 };
1170
1171 // NDD instructions is compressible when Op0 is allocated to the same
1172 // physic register as Op1 (or Op2 if it's commutable).
1173 for (auto &MO : MRI->reg_nodbg_operands(VirtReg)) {
1174 const MachineInstr &MI = *MO.getParent();
1175 if (!X86::getNonNDVariant(MI.getOpcode()))
1176 continue;
1177 unsigned OpIdx = MI.getOperandNo(&MO);
1178 if (OpIdx == 0) {
1179 assert(MI.getOperand(1).isReg());
1180 TryAddNDDHint(MI.getOperand(1));
1181 if (MI.isCommutable()) {
1182 assert(MI.getOperand(2).isReg());
1183 TryAddNDDHint(MI.getOperand(2));
1184 }
1185 } else if (OpIdx == 1) {
1186 TryAddNDDHint(MI.getOperand(0));
1187 } else if (MI.isCommutable() && OpIdx == 2) {
1188 TryAddNDDHint(MI.getOperand(0));
1189 }
1190 }
1191
1192 for (MCPhysReg OrderReg : Order)
1193 if (TwoAddrHints.count(OrderReg))
1194 Hints.push_back(OrderReg);
1195
1196 return BaseImplRetVal;
1197 }
1198
1199 ShapeT VirtShape = getTileShape(VirtReg, const_cast<VirtRegMap *>(VRM), MRI);
1200 auto AddHint = [&](MCPhysReg PhysReg) {
1201 Register VReg = Matrix->getOneVReg(PhysReg);
1202 if (VReg == MCRegister::NoRegister) { // Not allocated yet
1203 Hints.push_back(PhysReg);
1204 return;
1205 }
1206 ShapeT PhysShape = getTileShape(VReg, const_cast<VirtRegMap *>(VRM), MRI);
1207 if (canHintShape(PhysShape, VirtShape))
1208 Hints.push_back(PhysReg);
1209 };
1210
1211 SmallSet<MCPhysReg, 4> CopyHints(llvm::from_range, Hints);
1212 Hints.clear();
1213 for (auto Hint : CopyHints) {
1214 if (RC.contains(Hint) && !MRI->isReserved(Hint))
1215 AddHint(Hint);
1216 }
1217 for (MCPhysReg PhysReg : Order) {
1218 if (!CopyHints.count(PhysReg) && RC.contains(PhysReg) &&
1219 !MRI->isReserved(PhysReg))
1220 AddHint(PhysReg);
1221 }
1222
1223#define DEBUG_TYPE "tile-hint"
1224 LLVM_DEBUG({
1225 dbgs() << "Hints for virtual register " << format_hex(VirtReg, 8) << "\n";
1226 for (auto Hint : Hints) {
1227 dbgs() << "tmm" << Hint << ",";
1228 }
1229 dbgs() << "\n";
1230 });
1231#undef DEBUG_TYPE
1232
1233 return true;
1234}
1235
1237 const TargetRegisterClass *RC) const {
1238 switch (RC->getID()) {
1239 default:
1240 return RC;
1241 case X86::GR8RegClassID:
1242 return &X86::GR8_NOREX2RegClass;
1243 case X86::GR16RegClassID:
1244 return &X86::GR16_NOREX2RegClass;
1245 case X86::GR32RegClassID:
1246 return &X86::GR32_NOREX2RegClass;
1247 case X86::GR64RegClassID:
1248 return &X86::GR64_NOREX2RegClass;
1249 case X86::GR32_NOSPRegClassID:
1250 return &X86::GR32_NOREX2_NOSPRegClass;
1251 case X86::GR64_NOSPRegClassID:
1252 return &X86::GR64_NOREX2_NOSPRegClass;
1253 }
1254}
1255
1257 switch (RC->getID()) {
1258 default:
1259 return false;
1260 case X86::GR8_NOREX2RegClassID:
1261 case X86::GR16_NOREX2RegClassID:
1262 case X86::GR32_NOREX2RegClassID:
1263 case X86::GR64_NOREX2RegClassID:
1264 case X86::GR32_NOREX2_NOSPRegClassID:
1265 case X86::GR64_NOREX2_NOSPRegClassID:
1266 case X86::GR64_with_sub_16bit_in_GR16_NOREX2RegClassID:
1267 return true;
1268 }
1269}
unsigned SubReg
unsigned const MachineRegisterInfo * MRI
static const TargetRegisterClass * getRegClass(const MachineInstr &MI, Register Reg)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file implements the BitVector class.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
MachineInstr unsigned OpIdx
uint64_t IntrinsicInst * II
This file declares the machine register scavenger class.
This file contains some templates that are useful if you are working with the STL at all.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:480
This file defines the SmallSet class.
#define LLVM_DEBUG(...)
Definition Debug.h:114
cl::opt< bool > X86EnableAPXForRelocation
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)
static bool canHintShape(ShapeT &PhysShape, ShapeT &VirtShape)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
iterator end() const
Definition ArrayRef.h:136
iterator begin() const
Definition ArrayRef.h:135
A debug info location.
Definition DebugLoc.h:124
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition Function.h:270
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:727
A set of register units used to track register liveness.
bool available(MCRegister Reg) const
Returns true if no part of physical register Reg is live.
LLVM_ABI void stepBackward(const MachineInstr &MI)
Updates liveness when stepping backwards over the instruction MI.
LLVM_ABI void addLiveOuts(const MachineBasicBlock &MBB)
Adds registers living out of block MBB.
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
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
MachineInstrBundleIterator< MachineInstr > iterator
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 TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
LLVM_ABI 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
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:78
Represents a location in source code.
Definition SMLoc.h:23
MachineOperand * getRow(unsigned I=0) const
MachineOperand * getCol(unsigned I=0) const
unsigned getShapeNum()
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition SmallSet.h:133
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition SmallSet.h:175
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:181
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static StackOffset getFixed(int64_t Fixed)
Definition TypeSize.h:40
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
TargetOptions Options
LLVM_ABI bool FramePointerIsReserved(const MachineFunction &MF) const
FramePointerIsReserved - This returns true if the frame pointer must always either point to a new fra...
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.
ArrayRef< unsigned > superclasses() const
Returns a list of super-classes.
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 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:47
bool hasShape(Register virtReg) const
Definition VirtRegMap.h:102
ShapeT getShape(Register virtReg) const
Definition VirtRegMap.h:106
MCRegister getPhys(Register virtReg) const
returns the physical register mapped to the specified virtual register
Definition VirtRegMap.h:91
void assignVirt2Shape(Register virtReg, ShapeT shape)
Definition VirtRegMap.h:111
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.
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
bool hasBasePointer(const MachineFunction &MF) const
const TargetRegisterClass * getPointerRegClass(unsigned Kind=0) const override
getPointerRegClass - Returns a TargetRegisterClass used for pointer values.
const MCPhysReg * getCalleeSavedRegsViaCopy(const MachineFunction *MF) const
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 ...
Register getPtrSizedFrameRegister(const MachineFunction &MF) const
bool shouldRealignStack(const MachineFunction &MF) const override
unsigned getNumSupportedRegs(const MachineFunction &MF) const override
Return the number of registers for the function.
const MCPhysReg * getIPRACSRegs(const MachineFunction *MF) const override
getIPRACSRegs - This API can be removed when rbp is safe to optimized out when IPRA is on.
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.
bool isNonRex2RegClass(const TargetRegisterClass *RC) const
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const override
Register getPtrSizedStackRegister(const MachineFunction &MF) const
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
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)
const TargetRegisterClass * constrainRegClassToNonRex2(const TargetRegisterClass *RC) const
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
const X86TargetLowering * getTargetLowering() const override
bool isTarget64BitILP32() const
Is this x86_64 with the ILP32 programming model (x32 ABI)?
bool hasAVX512() const
bool hasAVX() const
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ X86_64_SysV
The C convention as specified in the x86-64 supplement to the System V ABI, used on most non-Windows ...
@ 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.
@ 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.
@ 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.
@ 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.
@ X86_RegCall
Register calling convention used for parameters transfer optimization.
void initLLVMToSEHAndCVRegMapping(MCRegisterInfo *MRI)
Define some predicates that are used for node matching.
unsigned getNonNDVariant(unsigned Opc)
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:174
MCRegister getX86SubSuperRegister(MCRegister Reg, unsigned Size, bool High=false)
constexpr from_range_t from_range
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:1712
static bool isFuncletReturnInstr(const MachineInstr &MI)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
Definition Format.h:188
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1877