LLVM  14.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"
17 #include "X86MachineFunctionInfo.h"
18 #include "X86Subtarget.h"
19 #include "llvm/ADT/BitVector.h"
20 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/ADT/SmallSet.h"
29 #include "llvm/IR/Constants.h"
30 #include "llvm/IR/Function.h"
31 #include "llvm/IR/Type.h"
36 
37 using namespace llvm;
38 
39 #define GET_REGINFO_TARGET_DESC
40 #include "X86GenRegisterInfo.inc"
41 
42 static cl::opt<bool>
43 EnableBasePointer("x86-use-base-pointer", cl::Hidden, cl::init(true),
44  cl::desc("Enable use of a base pointer for complex stack frames"));
45 
47  : X86GenRegisterInfo((TT.isArch64Bit() ? X86::RIP : X86::EIP),
48  X86_MC::getDwarfRegFlavour(TT, false),
49  X86_MC::getDwarfRegFlavour(TT, true),
50  (TT.isArch64Bit() ? X86::RIP : X86::EIP)) {
52 
53  // Cache some information.
54  Is64Bit = TT.isArch64Bit();
55  IsWin64 = Is64Bit && TT.isOSWindows();
56 
57  // Use a callee-saved register as the base pointer. These registers must
58  // not conflict with any ABI requirements. For example, in 32-bit mode PIC
59  // requires GOT in the EBX register before function calls via PLT GOT pointer.
60  if (Is64Bit) {
61  SlotSize = 8;
62  // This matches the simplified 32-bit pointer code in the data layout
63  // computation.
64  // FIXME: Should use the data layout?
65  bool Use64BitReg = !TT.isX32();
66  StackPtr = Use64BitReg ? X86::RSP : X86::ESP;
67  FramePtr = Use64BitReg ? X86::RBP : X86::EBP;
68  BasePtr = Use64BitReg ? X86::RBX : X86::EBX;
69  } else {
70  SlotSize = 4;
71  StackPtr = X86::ESP;
72  FramePtr = X86::EBP;
73  BasePtr = X86::ESI;
74  }
75 }
76 
77 int
79  return getEncodingValue(i);
80 }
81 
82 const TargetRegisterClass *
84  unsigned Idx) const {
85  // The sub_8bit sub-register index is more constrained in 32-bit mode.
86  // It behaves just like the sub_8bit_hi index.
87  if (!Is64Bit && Idx == X86::sub_8bit)
88  Idx = X86::sub_8bit_hi;
89 
90  // Forward to TableGen's default version.
91  return X86GenRegisterInfo::getSubClassWithSubReg(RC, Idx);
92 }
93 
94 const TargetRegisterClass *
96  const TargetRegisterClass *B,
97  unsigned SubIdx) const {
98  // The sub_8bit sub-register index is more constrained in 32-bit mode.
99  if (!Is64Bit && SubIdx == X86::sub_8bit) {
100  A = X86GenRegisterInfo::getSubClassWithSubReg(A, X86::sub_8bit_hi);
101  if (!A)
102  return nullptr;
103  }
104  return X86GenRegisterInfo::getMatchingSuperRegClass(A, B, SubIdx);
105 }
106 
107 const TargetRegisterClass *
109  const MachineFunction &MF) const {
110  // Don't allow super-classes of GR8_NOREX. This class is only used after
111  // extracting sub_8bit_hi sub-registers. The H sub-registers cannot be copied
112  // to the full GR8 register class in 64-bit mode, so we cannot allow the
113  // reigster class inflation.
114  //
115  // The GR8_NOREX class is always used in a way that won't be constrained to a
116  // sub-class, so sub-classes like GR8_ABCD_L are allowed to expand to the
117  // full GR8 class.
118  if (RC == &X86::GR8_NOREXRegClass)
119  return RC;
120 
121  const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
122 
123  const TargetRegisterClass *Super = RC;
125  do {
126  switch (Super->getID()) {
127  case X86::FR32RegClassID:
128  case X86::FR64RegClassID:
129  // If AVX-512 isn't supported we should only inflate to these classes.
130  if (!Subtarget.hasAVX512() &&
131  getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
132  return Super;
133  break;
134  case X86::VR128RegClassID:
135  case X86::VR256RegClassID:
136  // If VLX isn't supported we should only inflate to these classes.
137  if (!Subtarget.hasVLX() &&
138  getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
139  return Super;
140  break;
141  case X86::VR128XRegClassID:
142  case X86::VR256XRegClassID:
143  // If VLX isn't support we shouldn't inflate to these classes.
144  if (Subtarget.hasVLX() &&
145  getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
146  return Super;
147  break;
148  case X86::FR32XRegClassID:
149  case X86::FR64XRegClassID:
150  // If AVX-512 isn't support we shouldn't inflate to these classes.
151  if (Subtarget.hasAVX512() &&
152  getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
153  return Super;
154  break;
155  case X86::GR8RegClassID:
156  case X86::GR16RegClassID:
157  case X86::GR32RegClassID:
158  case X86::GR64RegClassID:
159  case X86::RFP32RegClassID:
160  case X86::RFP64RegClassID:
161  case X86::RFP80RegClassID:
162  case X86::VR512_0_15RegClassID:
163  case X86::VR512RegClassID:
164  // Don't return a super-class that would shrink the spill size.
165  // That can happen with the vector and float classes.
166  if (getRegSizeInBits(*Super) == getRegSizeInBits(*RC))
167  return Super;
168  }
169  Super = *I++;
170  } while (Super);
171  return RC;
172 }
173 
174 const TargetRegisterClass *
176  unsigned Kind) const {
177  const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
178  switch (Kind) {
179  default: llvm_unreachable("Unexpected Kind in getPointerRegClass!");
180  case 0: // Normal GPRs.
181  if (Subtarget.isTarget64BitLP64())
182  return &X86::GR64RegClass;
183  // If the target is 64bit but we have been told to use 32bit addresses,
184  // we can still use 64-bit register as long as we know the high bits
185  // are zeros.
186  // Reflect that in the returned register class.
187  if (Is64Bit) {
188  // When the target also allows 64-bit frame pointer and we do have a
189  // frame, this is fine to use it for the address accesses as well.
190  const X86FrameLowering *TFI = getFrameLowering(MF);
191  return TFI->hasFP(MF) && TFI->Uses64BitFramePtr
192  ? &X86::LOW32_ADDR_ACCESS_RBPRegClass
193  : &X86::LOW32_ADDR_ACCESSRegClass;
194  }
195  return &X86::GR32RegClass;
196  case 1: // Normal GPRs except the stack pointer (for encoding reasons).
197  if (Subtarget.isTarget64BitLP64())
198  return &X86::GR64_NOSPRegClass;
199  // NOSP does not contain RIP, so no special case here.
200  return &X86::GR32_NOSPRegClass;
201  case 2: // NOREX GPRs.
202  if (Subtarget.isTarget64BitLP64())
203  return &X86::GR64_NOREXRegClass;
204  return &X86::GR32_NOREXRegClass;
205  case 3: // NOREX GPRs except the stack pointer (for encoding reasons).
206  if (Subtarget.isTarget64BitLP64())
207  return &X86::GR64_NOREX_NOSPRegClass;
208  // NOSP does not contain RIP, so no special case here.
209  return &X86::GR32_NOREX_NOSPRegClass;
210  case 4: // Available for tailcall (not callee-saved GPRs).
211  return getGPRsForTailCall(MF);
212  }
213 }
214 
216  unsigned DefSubReg,
217  const TargetRegisterClass *SrcRC,
218  unsigned SrcSubReg) const {
219  // Prevent rewriting a copy where the destination size is larger than the
220  // input size. See PR41619.
221  // FIXME: Should this be factored into the base implementation somehow.
222  if (DefRC->hasSuperClassEq(&X86::GR64RegClass) && DefSubReg == 0 &&
223  SrcRC->hasSuperClassEq(&X86::GR64RegClass) && SrcSubReg == X86::sub_32bit)
224  return false;
225 
226  return TargetRegisterInfo::shouldRewriteCopySrc(DefRC, DefSubReg,
227  SrcRC, SrcSubReg);
228 }
229 
230 const TargetRegisterClass *
232  const Function &F = MF.getFunction();
233  if (IsWin64 || (F.getCallingConv() == CallingConv::Win64))
234  return &X86::GR64_TCW64RegClass;
235  else if (Is64Bit)
236  return &X86::GR64_TCRegClass;
237 
238  bool hasHipeCC = (F.getCallingConv() == CallingConv::HiPE);
239  if (hasHipeCC)
240  return &X86::GR32RegClass;
241  return &X86::GR32_TCRegClass;
242 }
243 
244 const TargetRegisterClass *
246  if (RC == &X86::CCRRegClass) {
247  if (Is64Bit)
248  return &X86::GR64RegClass;
249  else
250  return &X86::GR32RegClass;
251  }
252  return RC;
253 }
254 
255 unsigned
257  MachineFunction &MF) const {
258  const X86FrameLowering *TFI = getFrameLowering(MF);
259 
260  unsigned FPDiff = TFI->hasFP(MF) ? 1 : 0;
261  switch (RC->getID()) {
262  default:
263  return 0;
264  case X86::GR32RegClassID:
265  return 4 - FPDiff;
266  case X86::GR64RegClassID:
267  return 12 - FPDiff;
268  case X86::VR128RegClassID:
269  return Is64Bit ? 10 : 4;
270  case X86::VR64RegClassID:
271  return 4;
272  }
273 }
274 
275 const MCPhysReg *
277  assert(MF && "MachineFunction required");
278 
279  const X86Subtarget &Subtarget = MF->getSubtarget<X86Subtarget>();
280  const Function &F = MF->getFunction();
281  bool HasSSE = Subtarget.hasSSE1();
282  bool HasAVX = Subtarget.hasAVX();
283  bool HasAVX512 = Subtarget.hasAVX512();
284  bool CallsEHReturn = MF->callsEHReturn();
285 
286  CallingConv::ID CC = F.getCallingConv();
287 
288  // If attribute NoCallerSavedRegisters exists then we set X86_INTR calling
289  // convention because it has the CSR list.
290  if (MF->getFunction().hasFnAttribute("no_caller_saved_registers"))
292 
293  // If atribute specified, override the CSRs normally specified by the
294  // calling convention and use the empty set instead.
295  if (MF->getFunction().hasFnAttribute("no_callee_saved_registers"))
296  return CSR_NoRegs_SaveList;
297 
298  switch (CC) {
299  case CallingConv::GHC:
300  case CallingConv::HiPE:
301  return CSR_NoRegs_SaveList;
302  case CallingConv::AnyReg:
303  if (HasAVX)
304  return CSR_64_AllRegs_AVX_SaveList;
305  return CSR_64_AllRegs_SaveList;
307  return CSR_64_RT_MostRegs_SaveList;
309  if (HasAVX)
310  return CSR_64_RT_AllRegs_AVX_SaveList;
311  return CSR_64_RT_AllRegs_SaveList;
313  if (Is64Bit)
314  return MF->getInfo<X86MachineFunctionInfo>()->isSplitCSR() ?
315  CSR_64_CXX_TLS_Darwin_PE_SaveList : CSR_64_TLS_Darwin_SaveList;
316  break;
318  if (HasAVX512 && IsWin64)
319  return CSR_Win64_Intel_OCL_BI_AVX512_SaveList;
320  if (HasAVX512 && Is64Bit)
321  return CSR_64_Intel_OCL_BI_AVX512_SaveList;
322  if (HasAVX && IsWin64)
323  return CSR_Win64_Intel_OCL_BI_AVX_SaveList;
324  if (HasAVX && Is64Bit)
325  return CSR_64_Intel_OCL_BI_AVX_SaveList;
326  if (!HasAVX && !IsWin64 && Is64Bit)
327  return CSR_64_Intel_OCL_BI_SaveList;
328  break;
329  }
330  case CallingConv::HHVM:
331  return CSR_64_HHVM_SaveList;
333  if (Is64Bit) {
334  if (IsWin64) {
335  return (HasSSE ? CSR_Win64_RegCall_SaveList :
336  CSR_Win64_RegCall_NoSSE_SaveList);
337  } else {
338  return (HasSSE ? CSR_SysV64_RegCall_SaveList :
339  CSR_SysV64_RegCall_NoSSE_SaveList);
340  }
341  } else {
342  return (HasSSE ? CSR_32_RegCall_SaveList :
343  CSR_32_RegCall_NoSSE_SaveList);
344  }
346  assert(!Is64Bit && "CFGuard check mechanism only used on 32-bit X86");
347  return (HasSSE ? CSR_Win32_CFGuard_Check_SaveList
348  : CSR_Win32_CFGuard_Check_NoSSE_SaveList);
349  case CallingConv::Cold:
350  if (Is64Bit)
351  return CSR_64_MostRegs_SaveList;
352  break;
353  case CallingConv::Win64:
354  if (!HasSSE)
355  return CSR_Win64_NoSSE_SaveList;
356  return CSR_Win64_SaveList;
358  if (!Is64Bit)
359  return CSR_32_SaveList;
360  return IsWin64 ? CSR_Win64_SwiftTail_SaveList : CSR_64_SwiftTail_SaveList;
362  if (CallsEHReturn)
363  return CSR_64EHRet_SaveList;
364  return CSR_64_SaveList;
366  if (Is64Bit) {
367  if (HasAVX512)
368  return CSR_64_AllRegs_AVX512_SaveList;
369  if (HasAVX)
370  return CSR_64_AllRegs_AVX_SaveList;
371  if (HasSSE)
372  return CSR_64_AllRegs_SaveList;
373  return CSR_64_AllRegs_NoSSE_SaveList;
374  } else {
375  if (HasAVX512)
376  return CSR_32_AllRegs_AVX512_SaveList;
377  if (HasAVX)
378  return CSR_32_AllRegs_AVX_SaveList;
379  if (HasSSE)
380  return CSR_32_AllRegs_SSE_SaveList;
381  return CSR_32_AllRegs_SaveList;
382  }
383  default:
384  break;
385  }
386 
387  if (Is64Bit) {
388  bool IsSwiftCC = Subtarget.getTargetLowering()->supportSwiftError() &&
389  F.getAttributes().hasAttrSomewhere(Attribute::SwiftError);
390  if (IsSwiftCC)
391  return IsWin64 ? CSR_Win64_SwiftError_SaveList
392  : CSR_64_SwiftError_SaveList;
393 
394  if (IsWin64)
395  return HasSSE ? CSR_Win64_SaveList : CSR_Win64_NoSSE_SaveList;
396  if (CallsEHReturn)
397  return CSR_64EHRet_SaveList;
398  return CSR_64_SaveList;
399  }
400 
401  return CallsEHReturn ? CSR_32EHRet_SaveList : CSR_32_SaveList;
402 }
403 
405  const MachineFunction *MF) const {
406  assert(MF && "Invalid MachineFunction pointer.");
409  return CSR_64_CXX_TLS_Darwin_ViaCopy_SaveList;
410  return nullptr;
411 }
412 
413 const uint32_t *
415  CallingConv::ID CC) const {
416  const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
417  bool HasSSE = Subtarget.hasSSE1();
418  bool HasAVX = Subtarget.hasAVX();
419  bool HasAVX512 = Subtarget.hasAVX512();
420 
421  switch (CC) {
422  case CallingConv::GHC:
423  case CallingConv::HiPE:
424  return CSR_NoRegs_RegMask;
425  case CallingConv::AnyReg:
426  if (HasAVX)
427  return CSR_64_AllRegs_AVX_RegMask;
428  return CSR_64_AllRegs_RegMask;
430  return CSR_64_RT_MostRegs_RegMask;
432  if (HasAVX)
433  return CSR_64_RT_AllRegs_AVX_RegMask;
434  return CSR_64_RT_AllRegs_RegMask;
436  if (Is64Bit)
437  return CSR_64_TLS_Darwin_RegMask;
438  break;
440  if (HasAVX512 && IsWin64)
441  return CSR_Win64_Intel_OCL_BI_AVX512_RegMask;
442  if (HasAVX512 && Is64Bit)
443  return CSR_64_Intel_OCL_BI_AVX512_RegMask;
444  if (HasAVX && IsWin64)
445  return CSR_Win64_Intel_OCL_BI_AVX_RegMask;
446  if (HasAVX && Is64Bit)
447  return CSR_64_Intel_OCL_BI_AVX_RegMask;
448  if (!HasAVX && !IsWin64 && Is64Bit)
449  return CSR_64_Intel_OCL_BI_RegMask;
450  break;
451  }
452  case CallingConv::HHVM:
453  return CSR_64_HHVM_RegMask;
455  if (Is64Bit) {
456  if (IsWin64) {
457  return (HasSSE ? CSR_Win64_RegCall_RegMask :
458  CSR_Win64_RegCall_NoSSE_RegMask);
459  } else {
460  return (HasSSE ? CSR_SysV64_RegCall_RegMask :
461  CSR_SysV64_RegCall_NoSSE_RegMask);
462  }
463  } else {
464  return (HasSSE ? CSR_32_RegCall_RegMask :
465  CSR_32_RegCall_NoSSE_RegMask);
466  }
468  assert(!Is64Bit && "CFGuard check mechanism only used on 32-bit X86");
469  return (HasSSE ? CSR_Win32_CFGuard_Check_RegMask
470  : CSR_Win32_CFGuard_Check_NoSSE_RegMask);
471  case CallingConv::Cold:
472  if (Is64Bit)
473  return CSR_64_MostRegs_RegMask;
474  break;
475  case CallingConv::Win64:
476  return CSR_Win64_RegMask;
478  if (!Is64Bit)
479  return CSR_32_RegMask;
480  return IsWin64 ? CSR_Win64_SwiftTail_RegMask : CSR_64_SwiftTail_RegMask;
482  return CSR_64_RegMask;
484  if (Is64Bit) {
485  if (HasAVX512)
486  return CSR_64_AllRegs_AVX512_RegMask;
487  if (HasAVX)
488  return CSR_64_AllRegs_AVX_RegMask;
489  if (HasSSE)
490  return CSR_64_AllRegs_RegMask;
491  return CSR_64_AllRegs_NoSSE_RegMask;
492  } else {
493  if (HasAVX512)
494  return CSR_32_AllRegs_AVX512_RegMask;
495  if (HasAVX)
496  return CSR_32_AllRegs_AVX_RegMask;
497  if (HasSSE)
498  return CSR_32_AllRegs_SSE_RegMask;
499  return CSR_32_AllRegs_RegMask;
500  }
501  default:
502  break;
503  }
504 
505  // Unlike getCalleeSavedRegs(), we don't have MMI so we can't check
506  // callsEHReturn().
507  if (Is64Bit) {
508  const Function &F = MF.getFunction();
509  bool IsSwiftCC = Subtarget.getTargetLowering()->supportSwiftError() &&
510  F.getAttributes().hasAttrSomewhere(Attribute::SwiftError);
511  if (IsSwiftCC)
512  return IsWin64 ? CSR_Win64_SwiftError_RegMask : CSR_64_SwiftError_RegMask;
513 
514  return IsWin64 ? CSR_Win64_RegMask : CSR_64_RegMask;
515  }
516 
517  return CSR_32_RegMask;
518 }
519 
520 const uint32_t*
522  return CSR_NoRegs_RegMask;
523 }
524 
526  return CSR_64_TLS_Darwin_RegMask;
527 }
528 
530  BitVector Reserved(getNumRegs());
531  const X86FrameLowering *TFI = getFrameLowering(MF);
532 
533  // Set the floating point control register as reserved.
534  Reserved.set(X86::FPCW);
535 
536  // Set the floating point status register as reserved.
537  Reserved.set(X86::FPSW);
538 
539  // Set the SIMD floating point control register as reserved.
540  Reserved.set(X86::MXCSR);
541 
542  // Set the stack-pointer register and its aliases as reserved.
543  for (const MCPhysReg &SubReg : subregs_inclusive(X86::RSP))
544  Reserved.set(SubReg);
545 
546  // Set the Shadow Stack Pointer as reserved.
547  Reserved.set(X86::SSP);
548 
549  // Set the instruction pointer register and its aliases as reserved.
550  for (const MCPhysReg &SubReg : subregs_inclusive(X86::RIP))
551  Reserved.set(SubReg);
552 
553  // Set the frame-pointer register and its aliases as reserved if needed.
554  if (TFI->hasFP(MF)) {
555  for (const MCPhysReg &SubReg : subregs_inclusive(X86::RBP))
556  Reserved.set(SubReg);
557  }
558 
559  // Set the base-pointer register and its aliases as reserved if needed.
560  if (hasBasePointer(MF)) {
562  const uint32_t *RegMask = getCallPreservedMask(MF, CC);
565  "Stack realignment in presence of dynamic allocas is not supported with"
566  "this calling convention.");
567 
569  for (const MCPhysReg &SubReg : subregs_inclusive(BasePtr))
570  Reserved.set(SubReg);
571  }
572 
573  // Mark the segment registers as reserved.
574  Reserved.set(X86::CS);
575  Reserved.set(X86::SS);
576  Reserved.set(X86::DS);
577  Reserved.set(X86::ES);
578  Reserved.set(X86::FS);
579  Reserved.set(X86::GS);
580 
581  // Mark the floating point stack registers as reserved.
582  for (unsigned n = 0; n != 8; ++n)
583  Reserved.set(X86::ST0 + n);
584 
585  // Reserve the registers that only exist in 64-bit mode.
586  if (!Is64Bit) {
587  // These 8-bit registers are part of the x86-64 extension even though their
588  // super-registers are old 32-bits.
589  Reserved.set(X86::SIL);
590  Reserved.set(X86::DIL);
591  Reserved.set(X86::BPL);
592  Reserved.set(X86::SPL);
593  Reserved.set(X86::SIH);
594  Reserved.set(X86::DIH);
595  Reserved.set(X86::BPH);
596  Reserved.set(X86::SPH);
597 
598  for (unsigned n = 0; n != 8; ++n) {
599  // R8, R9, ...
600  for (MCRegAliasIterator AI(X86::R8 + n, this, true); AI.isValid(); ++AI)
601  Reserved.set(*AI);
602 
603  // XMM8, XMM9, ...
604  for (MCRegAliasIterator AI(X86::XMM8 + n, this, true); AI.isValid(); ++AI)
605  Reserved.set(*AI);
606  }
607  }
608  if (!Is64Bit || !MF.getSubtarget<X86Subtarget>().hasAVX512()) {
609  for (unsigned n = 16; n != 32; ++n) {
610  for (MCRegAliasIterator AI(X86::XMM0 + n, this, true); AI.isValid(); ++AI)
611  Reserved.set(*AI);
612  }
613  }
614 
615  assert(checkAllSuperRegsMarked(Reserved,
616  {X86::SIL, X86::DIL, X86::BPL, X86::SPL,
617  X86::SIH, X86::DIH, X86::BPH, X86::SPH}));
618  return Reserved;
619 }
620 
622  // Check if the EFLAGS register is marked as live-out. This shouldn't happen,
623  // because the calling convention defines the EFLAGS register as NOT
624  // preserved.
625  //
626  // Unfortunatelly the EFLAGS show up as live-out after branch folding. Adding
627  // an assert to track this and clear the register afterwards to avoid
628  // unnecessary crashes during release builds.
629  assert(!(Mask[X86::EFLAGS / 32] & (1U << (X86::EFLAGS % 32))) &&
630  "EFLAGS are not live-out from a patchpoint.");
631 
632  // Also clean other registers that don't need preserving (IP).
633  for (auto Reg : {X86::EFLAGS, X86::RIP, X86::EIP, X86::IP})
634  Mask[Reg / 32] &= ~(1U << (Reg % 32));
635 }
636 
637 //===----------------------------------------------------------------------===//
638 // Stack Frame Processing methods
639 //===----------------------------------------------------------------------===//
640 
641 static bool CantUseSP(const MachineFrameInfo &MFI) {
642  return MFI.hasVarSizedObjects() || MFI.hasOpaqueSPAdjustment();
643 }
644 
647  if (X86FI->hasPreallocatedCall())
648  return true;
649 
650  const MachineFrameInfo &MFI = MF.getFrameInfo();
651 
652  if (!EnableBasePointer)
653  return false;
654 
655  // When we need stack realignment, we can't address the stack from the frame
656  // pointer. When we have dynamic allocas or stack-adjusting inline asm, we
657  // can't address variables from the stack pointer. MS inline asm can
658  // reference locals while also adjusting the stack pointer. When we can't
659  // use both the SP and the FP, we need a separate base pointer register.
660  bool CantUseFP = hasStackRealignment(MF);
661  return CantUseFP && CantUseSP(MFI);
662 }
663 
666  return false;
667 
668  const MachineFrameInfo &MFI = MF.getFrameInfo();
669  const MachineRegisterInfo *MRI = &MF.getRegInfo();
670 
671  // Stack realignment requires a frame pointer. If we already started
672  // register allocation with frame pointer elimination, it is too late now.
673  if (!MRI->canReserveReg(FramePtr))
674  return false;
675 
676  // If a base pointer is necessary. Check that it isn't too late to reserve
677  // it.
678  if (CantUseSP(MFI))
679  return MRI->canReserveReg(BasePtr);
680  return true;
681 }
682 
683 // tryOptimizeLEAtoMOV - helper function that tries to replace a LEA instruction
684 // of the form 'lea (%esp), %ebx' --> 'mov %esp, %ebx'.
685 // TODO: In this case we should be really trying first to entirely eliminate
686 // this instruction which is a plain copy.
688  MachineInstr &MI = *II;
689  unsigned Opc = II->getOpcode();
690  // Check if this is a LEA of the form 'lea (%esp), %ebx'
691  if ((Opc != X86::LEA32r && Opc != X86::LEA64r && Opc != X86::LEA64_32r) ||
692  MI.getOperand(2).getImm() != 1 ||
693  MI.getOperand(3).getReg() != X86::NoRegister ||
694  MI.getOperand(4).getImm() != 0 ||
695  MI.getOperand(5).getReg() != X86::NoRegister)
696  return false;
697  Register BasePtr = MI.getOperand(1).getReg();
698  // In X32 mode, ensure the base-pointer is a 32-bit operand, so the LEA will
699  // be replaced with a 32-bit operand MOV which will zero extend the upper
700  // 32-bits of the super register.
701  if (Opc == X86::LEA64_32r)
702  BasePtr = getX86SubSuperRegister(BasePtr, 32);
703  Register NewDestReg = MI.getOperand(0).getReg();
704  const X86InstrInfo *TII =
705  MI.getParent()->getParent()->getSubtarget<X86Subtarget>().getInstrInfo();
706  TII->copyPhysReg(*MI.getParent(), II, MI.getDebugLoc(), NewDestReg, BasePtr,
707  MI.getOperand(1).isKill());
708  MI.eraseFromParent();
709  return true;
710 }
711 
713  switch (MI.getOpcode()) {
714  case X86::CATCHRET:
715  case X86::CLEANUPRET:
716  return true;
717  default:
718  return false;
719  }
720  llvm_unreachable("impossible");
721 }
722 
723 void
725  int SPAdj, unsigned FIOperandNum,
726  RegScavenger *RS) const {
727  MachineInstr &MI = *II;
728  MachineBasicBlock &MBB = *MI.getParent();
729  MachineFunction &MF = *MBB.getParent();
731  bool IsEHFuncletEpilogue = MBBI == MBB.end() ? false
733  const X86FrameLowering *TFI = getFrameLowering(MF);
734  int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
735 
736  // Determine base register and offset.
737  int FIOffset;
738  Register BasePtr;
739  if (MI.isReturn()) {
740  assert((!hasStackRealignment(MF) ||
742  "Return instruction can only reference SP relative frame objects");
743  FIOffset =
744  TFI->getFrameIndexReferenceSP(MF, FrameIndex, BasePtr, 0).getFixed();
745  } else if (TFI->Is64Bit && (MBB.isEHFuncletEntry() || IsEHFuncletEpilogue)) {
746  FIOffset = TFI->getWin64EHFrameIndexRef(MF, FrameIndex, BasePtr);
747  } else {
748  FIOffset = TFI->getFrameIndexReference(MF, FrameIndex, BasePtr).getFixed();
749  }
750 
751  // LOCAL_ESCAPE uses a single offset, with no register. It only works in the
752  // simple FP case, and doesn't work with stack realignment. On 32-bit, the
753  // offset is from the traditional base pointer location. On 64-bit, the
754  // offset is from the SP at the end of the prologue, not the FP location. This
755  // matches the behavior of llvm.frameaddress.
756  unsigned Opc = MI.getOpcode();
757  if (Opc == TargetOpcode::LOCAL_ESCAPE) {
758  MachineOperand &FI = MI.getOperand(FIOperandNum);
759  FI.ChangeToImmediate(FIOffset);
760  return;
761  }
762 
763  // For LEA64_32r when BasePtr is 32-bits (X32) we can use full-size 64-bit
764  // register as source operand, semantic is the same and destination is
765  // 32-bits. It saves one byte per lea in code since 0x67 prefix is avoided.
766  // Don't change BasePtr since it is used later for stack adjustment.
767  Register MachineBasePtr = BasePtr;
768  if (Opc == X86::LEA64_32r && X86::GR32RegClass.contains(BasePtr))
769  MachineBasePtr = getX86SubSuperRegister(BasePtr, 64);
770 
771  // This must be part of a four operand memory reference. Replace the
772  // FrameIndex with base register. Add an offset to the offset.
773  MI.getOperand(FIOperandNum).ChangeToRegister(MachineBasePtr, false);
774 
775  if (BasePtr == StackPtr)
776  FIOffset += SPAdj;
777 
778  // The frame index format for stackmaps and patchpoints is different from the
779  // X86 format. It only has a FI and an offset.
780  if (Opc == TargetOpcode::STACKMAP || Opc == TargetOpcode::PATCHPOINT) {
781  assert(BasePtr == FramePtr && "Expected the FP as base register");
782  int64_t Offset = MI.getOperand(FIOperandNum + 1).getImm() + FIOffset;
783  MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
784  return;
785  }
786 
787  if (MI.getOperand(FIOperandNum+3).isImm()) {
788  // Offset is a 32-bit integer.
789  int Imm = (int)(MI.getOperand(FIOperandNum + 3).getImm());
790  int Offset = FIOffset + Imm;
791  assert((!Is64Bit || isInt<32>((long long)FIOffset + Imm)) &&
792  "Requesting 64-bit offset in 32-bit immediate!");
793  if (Offset != 0 || !tryOptimizeLEAtoMOV(II))
794  MI.getOperand(FIOperandNum + 3).ChangeToImmediate(Offset);
795  } else {
796  // Offset is symbolic. This is extremely rare.
797  uint64_t Offset = FIOffset +
798  (uint64_t)MI.getOperand(FIOperandNum+3).getOffset();
799  MI.getOperand(FIOperandNum + 3).setOffset(Offset);
800  }
801 }
802 
805  const MachineFunction *MF = MBB.getParent();
806  if (MF->callsEHReturn())
807  return 0;
808 
809  const TargetRegisterClass &AvailableRegs = *getGPRsForTailCall(*MF);
810 
811  if (MBBI == MBB.end())
812  return 0;
813 
814  switch (MBBI->getOpcode()) {
815  default:
816  return 0;
817  case TargetOpcode::PATCHABLE_RET:
818  case X86::RET:
819  case X86::RETL:
820  case X86::RETQ:
821  case X86::RETIL:
822  case X86::RETIQ:
823  case X86::TCRETURNdi:
824  case X86::TCRETURNri:
825  case X86::TCRETURNmi:
826  case X86::TCRETURNdi64:
827  case X86::TCRETURNri64:
828  case X86::TCRETURNmi64:
829  case X86::EH_RETURN:
830  case X86::EH_RETURN64: {
832  for (unsigned I = 0, E = MBBI->getNumOperands(); I != E; ++I) {
833  MachineOperand &MO = MBBI->getOperand(I);
834  if (!MO.isReg() || MO.isDef())
835  continue;
836  Register Reg = MO.getReg();
837  if (!Reg)
838  continue;
839  for (MCRegAliasIterator AI(Reg, this, true); AI.isValid(); ++AI)
840  Uses.insert(*AI);
841  }
842 
843  for (auto CS : AvailableRegs)
844  if (!Uses.count(CS) && CS != X86::RIP && CS != X86::RSP && CS != X86::ESP)
845  return CS;
846  }
847  }
848 
849  return 0;
850 }
851 
853  const X86FrameLowering *TFI = getFrameLowering(MF);
854  return TFI->hasFP(MF) ? FramePtr : StackPtr;
855 }
856 
857 unsigned
859  const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
860  Register FrameReg = getFrameRegister(MF);
861  if (Subtarget.isTarget64BitILP32())
862  FrameReg = getX86SubSuperRegister(FrameReg, 32);
863  return FrameReg;
864 }
865 
866 unsigned
868  const X86Subtarget &Subtarget = MF.getSubtarget<X86Subtarget>();
869  Register StackReg = getStackRegister();
870  if (Subtarget.isTarget64BitILP32())
871  StackReg = getX86SubSuperRegister(StackReg, 32);
872  return StackReg;
873 }
874 
875 static ShapeT getTileShape(Register VirtReg, VirtRegMap *VRM,
876  const MachineRegisterInfo *MRI) {
877  if (VRM->hasShape(VirtReg))
878  return VRM->getShape(VirtReg);
879 
880  const MachineOperand &Def = *MRI->def_begin(VirtReg);
881  MachineInstr *MI = const_cast<MachineInstr *>(Def.getParent());
882  unsigned OpCode = MI->getOpcode();
883  switch (OpCode) {
884  default:
885  llvm_unreachable("Unexpected machine instruction on tile register!");
886  break;
887  case X86::COPY: {
888  Register SrcReg = MI->getOperand(1).getReg();
889  ShapeT Shape = getTileShape(SrcReg, VRM, MRI);
890  VRM->assignVirt2Shape(VirtReg, Shape);
891  return Shape;
892  }
893  // We only collect the tile shape that is defined.
894  case X86::PTILELOADDV:
895  case X86::PTILELOADDT1V:
896  case X86::PTDPBSSDV:
897  case X86::PTDPBSUDV:
898  case X86::PTDPBUSDV:
899  case X86::PTDPBUUDV:
900  case X86::PTILEZEROV:
901  case X86::PTDPBF16PSV:
902  MachineOperand &MO1 = MI->getOperand(1);
903  MachineOperand &MO2 = MI->getOperand(2);
904  ShapeT Shape(&MO1, &MO2, MRI);
905  VRM->assignVirt2Shape(VirtReg, Shape);
906  return Shape;
907  }
908 }
909 
911  ArrayRef<MCPhysReg> Order,
913  const MachineFunction &MF,
914  const VirtRegMap *VRM,
915  const LiveRegMatrix *Matrix) const {
916  const MachineRegisterInfo *MRI = &MF.getRegInfo();
917  const TargetRegisterClass &RC = *MRI->getRegClass(VirtReg);
918  bool BaseImplRetVal = TargetRegisterInfo::getRegAllocationHints(
919  VirtReg, Order, Hints, MF, VRM, Matrix);
920 
921  if (RC.getID() != X86::TILERegClassID)
922  return BaseImplRetVal;
923 
924  ShapeT VirtShape = getTileShape(VirtReg, const_cast<VirtRegMap *>(VRM), MRI);
925  auto AddHint = [&](MCPhysReg PhysReg) {
926  Register VReg = Matrix->getOneVReg(PhysReg);
927  if (VReg == MCRegister::NoRegister) { // Not allocated yet
928  Hints.push_back(PhysReg);
929  return;
930  }
931  ShapeT PhysShape = getTileShape(VReg, const_cast<VirtRegMap *>(VRM), MRI);
932  if (PhysShape == VirtShape)
933  Hints.push_back(PhysReg);
934  };
935 
936  SmallSet<MCPhysReg, 4> CopyHints;
937  CopyHints.insert(Hints.begin(), Hints.end());
938  Hints.clear();
939  for (auto Hint : CopyHints) {
940  if (RC.contains(Hint) && !MRI->isReserved(Hint))
941  AddHint(Hint);
942  }
943  for (MCPhysReg PhysReg : Order) {
944  if (!CopyHints.count(PhysReg) && RC.contains(PhysReg) &&
945  !MRI->isReserved(PhysReg))
946  AddHint(PhysReg);
947  }
948 
949 #define DEBUG_TYPE "tile-hint"
950  LLVM_DEBUG({
951  dbgs() << "Hints for virtual register " << format_hex(VirtReg, 8) << "\n";
952  for (auto Hint : Hints) {
953  dbgs() << "tmm" << Hint << ",";
954  }
955  dbgs() << "\n";
956  });
957 #undef DEBUG_TYPE
958 
959  return true;
960 }
i
i
Definition: README.txt:29
LiveRegMatrix.h
llvm::MachineFrameInfo::hasVarSizedObjects
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
Definition: MachineFrameInfo.h:353
llvm::X86_MC::getDwarfRegFlavour
unsigned getDwarfRegFlavour(const Triple &TT, bool isEH)
Definition: X86MCTargetDesc.cpp:59
llvm::CallingConv::SwiftTail
@ SwiftTail
SwiftTail - This follows the Swift calling convention in how arguments are passed but guarantees tail...
Definition: CallingConv.h:92
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:103
llvm::MachineRegisterInfo::def_begin
def_iterator def_begin(Register RegNo) const
Definition: MachineRegisterInfo.h:384
llvm::TargetRegisterClass::getID
unsigned getID() const
Return the register class ID number.
Definition: TargetRegisterInfo.h:71
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::tgtok::Def
@ Def
Definition: TGLexer.h:50
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
TargetFrameLowering.h
X86Subtarget.h
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:52
llvm::Function
Definition: Function.h:61
llvm::X86FrameLowering::hasFP
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register.
Definition: X86FrameLowering.cpp:93
llvm::BitVector::set
BitVector & set()
Definition: BitVector.h:343
llvm::MachineBasicBlock::isEHFuncletEntry
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
Definition: MachineBasicBlock.h:552
contains
return AArch64::GPR64RegClass contains(Reg)
llvm::X86Subtarget
Definition: X86Subtarget.h:52
ErrorHandling.h
llvm::VirtRegMap
Definition: VirtRegMap.h:33
llvm::X86RegisterInfo::getFrameRegister
Register getFrameRegister(const MachineFunction &MF) const override
Definition: X86RegisterInfo.cpp:852
llvm::CallingConv::X86_RegCall
@ X86_RegCall
Register calling convention used for parameters transfer optimization.
Definition: CallingConv.h:219
llvm::X86Subtarget::isTarget64BitILP32
bool isTarget64BitILP32() const
Is this x86_64 with the ILP32 programming model (x32 ABI)?
Definition: X86Subtarget.h:619
llvm::X86RegisterInfo::getRegPressureLimit
unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const override
Definition: X86RegisterInfo.cpp:256
llvm::MachineRegisterInfo::canReserveReg
bool canReserveReg(MCRegister PhysReg) const
canReserveReg - Returns true if PhysReg can be used as a reserved register.
Definition: MachineRegisterInfo.h:897
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::X86RegisterInfo::eliminateFrameIndex
void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const override
Definition: X86RegisterInfo.cpp:724
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
TargetInstrInfo.h
llvm::SmallSet
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:134
llvm::MCRegister::NoRegister
static constexpr unsigned NoRegister
Definition: MCRegister.h:42
llvm::CallingConv::Cold
@ Cold
Definition: CallingConv.h:48
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::ShapeT
Definition: TileShapeInfo.h:30
STLExtras.h
llvm::X86RegisterInfo::getCalleeSavedRegsViaCopy
const MCPhysReg * getCalleeSavedRegsViaCopy(const MachineFunction *MF) const
Definition: X86RegisterInfo.cpp:404
llvm::BitmaskEnumDetail::Mask
std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:80
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
F
#define F(x, y, z)
Definition: MD5.cpp:56
MachineRegisterInfo.h
Uses
SmallPtrSet< MachineInstr *, 2 > Uses
Definition: ARMLowOverheadLoops.cpp:588
llvm::X86RegisterInfo::getGPRsForTailCall
const TargetRegisterClass * getGPRsForTailCall(const MachineFunction &MF) const
getGPRsForTailCall - Returns a register class with registers that can be used in forming tail calls.
Definition: X86RegisterInfo.cpp:231
llvm::X86RegisterInfo::getDarwinTLSCallPreservedMask
const uint32_t * getDarwinTLSCallPreservedMask() const
Definition: X86RegisterInfo.cpp:525
X86FrameLowering.h
X86GenRegisterInfo
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::X86MachineFunctionInfo::hasPreallocatedCall
bool hasPreallocatedCall() const
Definition: X86MachineFunctionInfo.h:204
llvm::CallingConv::Win64
@ Win64
The C convention as implemented on Windows/x86-64 and AArch64.
Definition: CallingConv.h:169
CommandLine.h
llvm::X86RegisterInfo::getLargestLegalSuperClass
const TargetRegisterClass * getLargestLegalSuperClass(const TargetRegisterClass *RC, const MachineFunction &MF) const override
Definition: X86RegisterInfo.cpp:108
X86MachineFunctionInfo.h
llvm::TargetRegisterClass::contains
bool contains(Register Reg) const
Return true if the specified register is included in this register class.
Definition: TargetRegisterInfo.h:93
llvm::TargetRegisterInfo::canRealignStack
virtual bool canRealignStack(const MachineFunction &MF) const
True if the stack can be realigned for the target.
Definition: TargetRegisterInfo.cpp:478
llvm::MachineFunction::getRegInfo
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Definition: MachineFunction.h:636
TargetMachine.h
llvm::X86FrameLowering::getWin64EHFrameIndexRef
int getWin64EHFrameIndexRef(const MachineFunction &MF, int FI, Register &SPReg) const
Definition: X86FrameLowering.cpp:2313
Constants.h
llvm::X86FrameLowering::getFrameIndexReferenceSP
StackOffset getFrameIndexReferenceSP(const MachineFunction &MF, int FI, Register &SPReg, int Adjustment) const
Definition: X86FrameLowering.cpp:2329
llvm::N86::ESP
@ ESP
Definition: X86MCTargetDesc.h:51
llvm::X86RegisterInfo::getNoPreservedMask
const uint32_t * getNoPreservedMask() const override
Definition: X86RegisterInfo.cpp:521
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::MachineFunction::getInfo
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
Definition: MachineFunction.h:724
llvm::ISD::CATCHRET
@ CATCHRET
CATCHRET - Represents a return from a catch block funclet.
Definition: ISDOpcodes.h:999
llvm::MachineRegisterInfo::isReserved
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
Definition: MachineRegisterInfo.h:915
int
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
Definition: README.txt:536
CantUseSP
static bool CantUseSP(const MachineFrameInfo &MFI)
Definition: X86RegisterInfo.cpp:641
llvm::TargetRegisterClass
Definition: TargetRegisterInfo.h:46
llvm::X86RegisterInfo::getBaseRegister
Register getBaseRegister() const
Definition: X86RegisterInfo.h:139
false
Definition: StackSlotColoring.cpp:142
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:129
llvm::MachineOperand::ChangeToImmediate
void ChangeToImmediate(int64_t ImmVal, unsigned TargetFlags=0)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value.
Definition: MachineOperand.cpp:156
llvm::X86Subtarget::hasSSE1
bool hasSSE1() const
Definition: X86Subtarget.h:637
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::SIInstrFlags::DS
@ DS
Definition: SIDefines.h:59
llvm::TargetRegisterClass::hasSuperClassEq
bool hasSuperClassEq(const TargetRegisterClass *RC) const
Returns true if RC is a super-class of or equal to this class.
Definition: TargetRegisterInfo.h:138
llvm::X86RegisterInfo::shouldRewriteCopySrc
bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const override
Definition: X86RegisterInfo.cpp:215
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
BitVector.h
llvm::BitVector
Definition: BitVector.h:74
llvm::MachineFrameInfo::isFixedObjectIndex
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
Definition: MachineFrameInfo.h:656
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
Type.h
llvm::X86Subtarget::isTarget64BitLP64
bool isTarget64BitLP64() const
Is this x86_64 with the LP64 programming model (standard AMD64, no x32)?
Definition: X86Subtarget.h:624
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineRegisterInfo::getRegClass
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
Definition: MachineRegisterInfo.h:634
llvm::CallingConv::Intel_OCL_BI
@ Intel_OCL_BI
Intel_OCL_BI - Calling conventions for Intel OpenCL built-ins.
Definition: CallingConv.h:155
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:626
llvm::Function::hasFnAttribute
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.cpp:626
llvm::cl::opt< bool >
llvm::X86RegisterInfo::getRegAllocationHints
bool getRegAllocationHints(Register VirtReg, ArrayRef< MCPhysReg > Order, SmallVectorImpl< MCPhysReg > &Hints, const MachineFunction &MF, const VirtRegMap *VRM, const LiveRegMatrix *Matrix) const override
Definition: X86RegisterInfo.cpp:910
llvm::MachineOperand::clobbersPhysReg
static bool clobbersPhysReg(const uint32_t *RegMask, MCRegister PhysReg)
clobbersPhysReg - Returns true if this RegMask clobbers PhysReg.
Definition: MachineOperand.h:617
llvm::CallingConv::AnyReg
@ AnyReg
Definition: CallingConv.h:62
llvm::X86RegisterInfo::getSubClassWithSubReg
const TargetRegisterClass * getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const override
Definition: X86RegisterInfo.cpp:83
llvm::isInt< 32 >
constexpr bool isInt< 32 >(int64_t x)
Definition: MathExtras.h:373
llvm::MachineOperand::isReg
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Definition: MachineOperand.h:321
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::MachineFunction::callsEHReturn
bool callsEHReturn() const
Definition: MachineFunction.h:1038
uint64_t
llvm::Function::getCallingConv
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition: Function.h:239
llvm::CallingConv::HiPE
@ HiPE
Definition: CallingConv.h:55
llvm::CallingConv::CFGuard_Check
@ CFGuard_Check
Special calling convention on Windows for calling the Control Guard Check ICall funtion.
Definition: CallingConv.h:87
llvm::X86FrameLowering
Definition: X86FrameLowering.h:27
llvm::getX86SubSuperRegister
MCRegister getX86SubSuperRegister(MCRegister, unsigned, bool High=false)
Returns the sub or super register of a specific X86 register.
Definition: X86MCTargetDesc.cpp:786
llvm::X86AS::GS
@ GS
Definition: X86.h:187
isFuncletReturnInstr
static bool isFuncletReturnInstr(MachineInstr &MI)
Definition: X86RegisterInfo.cpp:712
llvm::ISD::CLEANUPRET
@ CLEANUPRET
CLEANUPRET - Represents a return from a cleanup block funclet.
Definition: ISDOpcodes.h:1003
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::X86RegisterInfo::getPtrSizedFrameRegister
unsigned getPtrSizedFrameRegister(const MachineFunction &MF) const
Definition: X86RegisterInfo.cpp:858
llvm::RegScavenger
Definition: RegisterScavenging.h:34
llvm::TargetRegisterInfo::getRegAllocationHints
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...
Definition: TargetRegisterInfo.cpp:421
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::CallingConv::X86_INTR
@ X86_INTR
X86_INTR - x86 hardware interrupt context.
Definition: CallingConv.h:189
llvm::X86RegisterInfo::X86RegisterInfo
X86RegisterInfo(const Triple &TT)
Definition: X86RegisterInfo.cpp:46
llvm::CallingConv::X86_64_SysV
@ 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:159
MachineFunctionPass.h
llvm::X86_MC::initLLVMToSEHAndCVRegMapping
void initLLVMToSEHAndCVRegMapping(MCRegisterInfo *MRI)
Definition: X86MCTargetDesc.cpp:75
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::X86Subtarget::getTargetLowering
const X86TargetLowering * getTargetLowering() const override
Definition: X86Subtarget.h:556
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:642
llvm::MachineBasicBlock::getParent
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Definition: MachineBasicBlock.h:225
llvm::VirtRegMap::hasShape
bool hasShape(Register virtReg) const
Definition: VirtRegMap.h:117
llvm::X86RegisterInfo::getCallPreservedMask
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const override
Definition: X86RegisterInfo.cpp:414
llvm::X86MachineFunctionInfo
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
Definition: X86MachineFunctionInfo.h:25
llvm::CallingConv::CXX_FAST_TLS
@ CXX_FAST_TLS
Definition: CallingConv.h:76
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:360
EnableBasePointer
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"))
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::VirtRegMap::assignVirt2Shape
void assignVirt2Shape(Register virtReg, ShapeT shape)
Definition: VirtRegMap.h:126
llvm::X86InstrInfo
Definition: X86InstrInfo.h:130
TargetOptions.h
llvm::VirtRegMap::getShape
ShapeT getShape(Register virtReg) const
Definition: VirtRegMap.h:121
llvm::MachineBasicBlock::getFirstTerminator
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
Definition: MachineBasicBlock.cpp:242
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
Matrix
Live Register Matrix
Definition: LiveRegMatrix.cpp:44
MBBI
MachineBasicBlock MachineBasicBlock::iterator MBBI
Definition: AArch64SLSHardening.cpp:75
llvm::X86RegisterInfo::adjustStackMapLiveOutMask
void adjustStackMapLiveOutMask(uint32_t *Mask) const override
Definition: X86RegisterInfo.cpp:621
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
getTileShape
static ShapeT getTileShape(Register VirtReg, VirtRegMap *VRM, const MachineRegisterInfo *MRI)
Definition: X86RegisterInfo.cpp:875
uint32_t
llvm::MachineOperand::isDef
bool isDef() const
Definition: MachineOperand.h:375
llvm::X86RegisterInfo::getMatchingSuperRegClass
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 ...
Definition: X86RegisterInfo.cpp:95
llvm::X86RegisterInfo::canRealignStack
bool canRealignStack(const MachineFunction &MF) const override
Definition: X86RegisterInfo.cpp:664
llvm::SmallSet::insert
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:180
llvm::X86RegisterInfo::getSEHRegNum
int getSEHRegNum(unsigned i) const
Definition: X86RegisterInfo.cpp:78
llvm::StackOffset::getFixed
static StackOffset getFixed(ScalarTy Fixed)
Definition: TypeSize.h:143
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::ISD::FrameIndex
@ FrameIndex
Definition: ISDOpcodes.h:80
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::TargetRegisterInfo::shouldRewriteCopySrc
virtual bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC, unsigned DefSubReg, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) const
Definition: TargetRegisterInfo.cpp:412
llvm::X86Subtarget::hasAVX512
bool hasAVX512() const
Definition: X86Subtarget.h:645
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:592
uint16_t
llvm::X86RegisterInfo::getCalleeSavedRegs
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
getCalleeSavedRegs - Return a null-terminated list of all of the callee-save registers on this target...
Definition: X86RegisterInfo.cpp:276
llvm::X86RegisterInfo::findDeadCallerSavedReg
unsigned findDeadCallerSavedReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI) const
findDeadCallerSavedReg - Return a caller-saved register that isn't live when it reaches the "return" ...
Definition: X86RegisterInfo.cpp:803
llvm::TargetRegisterClass::getSuperClasses
sc_iterator getSuperClasses() const
Returns a NULL-terminated list of super-classes.
Definition: TargetRegisterInfo.h:176
MachineFrameInfo.h
llvm::ARCISD::RET
@ RET
Definition: ARCISelLowering.h:52
llvm::X86Subtarget::hasVLX
bool hasVLX() const
Definition: X86Subtarget.h:751
llvm::X86RegisterInfo::hasBasePointer
bool hasBasePointer(const MachineFunction &MF) const
Definition: X86RegisterInfo.cpp:645
llvm::X86AS::FS
@ FS
Definition: X86.h:188
llvm::CallingConv::PreserveMost
@ PreserveMost
Definition: CallingConv.h:66
Function.h
llvm::TargetRegisterClass::sc_iterator
const TargetRegisterClass *const * sc_iterator
Definition: TargetRegisterInfo.h:50
llvm::ISD::EH_RETURN
@ EH_RETURN
OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents 'eh_return' gcc dwarf builtin,...
Definition: ISDOpcodes.h:135
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:585
tryOptimizeLEAtoMOV
static bool tryOptimizeLEAtoMOV(MachineBasicBlock::iterator II)
Definition: X86RegisterInfo.cpp:687
llvm::X86Subtarget::hasAVX
bool hasAVX() const
Definition: X86Subtarget.h:643
X86RegisterInfo.h
false
Function Alias Analysis false
Definition: AliasAnalysis.cpp:847
llvm::X86RegisterInfo::getCrossCopyRegClass
const TargetRegisterClass * getCrossCopyRegClass(const TargetRegisterClass *RC) const override
getCrossCopyRegClass - Returns a legal register class to copy a register in the specified class to or...
Definition: X86RegisterInfo.cpp:245
llvm::MCRegAliasIterator::isValid
bool isValid() const
Definition: MCRegisterInfo.h:805
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition: MachineFrameInfo.h:107
llvm::CallingConv::PreserveAll
@ PreserveAll
Definition: CallingConv.h:70
llvm::X86AS::SS
@ SS
Definition: X86.h:189
llvm::N86::ESI
@ ESI
Definition: X86MCTargetDesc.h:51
llvm::X86FrameLowering::Is64Bit
bool Is64Bit
Is64Bit implies that x86_64 instructions are available.
Definition: X86FrameLowering.h:40
llvm::X86FrameLowering::Uses64BitFramePtr
bool Uses64BitFramePtr
True if the 64-bit frame or stack pointer should be used.
Definition: X86FrameLowering.h:47
llvm::SmallVectorImpl< MCPhysReg >
llvm::X86MachineFunctionInfo::isSplitCSR
bool isSplitCSR() const
Definition: X86MachineFunctionInfo.h:195
llvm::X86RegisterInfo::getReservedRegs
BitVector getReservedRegs(const MachineFunction &MF) const override
getReservedRegs - Returns a bitset indexed by physical register number indicating if a register is a ...
Definition: X86RegisterInfo.cpp:529
llvm::X86RegisterInfo::getStackRegister
Register getStackRegister() const
Definition: X86RegisterInfo.h:138
llvm::MachineFrameInfo::hasOpaqueSPAdjustment
bool hasOpaqueSPAdjustment() const
Returns true if the function contains opaque dynamic stack adjustments.
Definition: MachineFrameInfo.h:585
llvm::N86::EBX
@ EBX
Definition: X86MCTargetDesc.h:51
llvm::cl::desc
Definition: CommandLine.h:414
llvm::X86TargetLowering::supportSwiftError
bool supportSwiftError() const override
Return true if the target supports swifterror attribute.
Definition: X86ISelLowering.cpp:53840
n
The same transformation can work with an even modulo with the addition of a and shrink the compare RHS by the same amount Unless the target supports that transformation probably isn t worthwhile The transformation can also easily be made to work with non zero equality for n
Definition: README.txt:685
MachineFunction.h
X86
Unrolling by would eliminate the &in both leading to a net reduction in code size The resultant code would then also be suitable for exit value computation We miss a bunch of rotate opportunities on various including etc On X86
Definition: README.txt:568
llvm::MachineInstrBundleIterator< MachineInstr >
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1853
llvm::format_hex
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
Definition: Format.h:186
llvm::HexagonInstrInfo::copyPhysReg
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.
Definition: HexagonInstrInfo.cpp:812
llvm::X86FrameLowering::getFrameIndexReference
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...
Definition: X86FrameLowering.cpp:2231
llvm::CallingConv::HHVM
@ HHVM
Calling convention used by HipHop Virtual Machine (HHVM) to perform calls to and from translation cac...
Definition: CallingConv.h:179
llvm::MachineBasicBlock::end
iterator end()
Definition: MachineBasicBlock.h:270
SubReg
unsigned SubReg
Definition: AArch64AdvSIMDScalarPass.cpp:104
llvm::CallingConv::GHC
@ GHC
Definition: CallingConv.h:51
llvm::X86RegisterInfo::getPtrSizedStackRegister
unsigned getPtrSizedStackRegister(const MachineFunction &MF) const
Definition: X86RegisterInfo.cpp:867
llvm::MCRegAliasIterator
MCRegAliasIterator enumerates all registers aliasing Reg.
Definition: MCRegisterInfo.h:780
llvm::X86RegisterInfo::getPointerRegClass
const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const override
getPointerRegClass - Returns a TargetRegisterClass used for pointer values.
Definition: X86RegisterInfo.cpp:175
SmallSet.h
llvm::LiveRegMatrix
Definition: LiveRegMatrix.h:40