LLVM  16.0.0git
XCoreMachineFunctionInfo.cpp
Go to the documentation of this file.
1 //===-- XCoreMachineFunctionInfo.cpp - XCore machine function info --------===//
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 
10 #include "XCoreInstrInfo.h"
12 #include "llvm/IR/Function.h"
13 
14 using namespace llvm;
15 
16 void XCoreFunctionInfo::anchor() { }
17 
21  const {
22  return DestMF.cloneInfo<XCoreFunctionInfo>(*this);
23 }
24 
26  if (CachedEStackSize == -1) {
27  CachedEStackSize = MF.getFrameInfo().estimateStackSize(MF);
28  }
29  // isLargeFrame() is used when deciding if spill slots should be added to
30  // allow eliminateFrameIndex() to scavenge registers.
31  // This is only required when there is no FP and offsets are greater than
32  // ~256KB (~64Kwords). Thus only for code run on the emulator!
33  //
34  // The arbitrary value of 0xf000 allows frames of up to ~240KB before spill
35  // slots are added for the use of eliminateFrameIndex() register scavenging.
36  // For frames less than 240KB, it is assumed that there will be less than
37  // 16KB of function arguments.
38  return CachedEStackSize > 0xf000;
39 }
40 
42  if (LRSpillSlotSet) {
43  return LRSpillSlot;
44  }
45  const TargetRegisterClass &RC = XCore::GRRegsRegClass;
47  MachineFrameInfo &MFI = MF.getFrameInfo();
48  if (! MF.getFunction().isVarArg()) {
49  // A fixed offset of 0 allows us to save / restore LR using entsp / retsp.
50  LRSpillSlot = MFI.CreateFixedObject(TRI.getSpillSize(RC), 0, true);
51  } else {
52  LRSpillSlot = MFI.CreateStackObject(TRI.getSpillSize(RC),
53  TRI.getSpillAlign(RC), true);
54  }
55  LRSpillSlotSet = true;
56  return LRSpillSlot;
57 }
58 
60  if (FPSpillSlotSet) {
61  return FPSpillSlot;
62  }
63  const TargetRegisterClass &RC = XCore::GRRegsRegClass;
65  MachineFrameInfo &MFI = MF.getFrameInfo();
66  FPSpillSlot =
68  FPSpillSlotSet = true;
69  return FPSpillSlot;
70 }
71 
73  if (EHSpillSlotSet) {
74  return EHSpillSlot;
75  }
76  const TargetRegisterClass &RC = XCore::GRRegsRegClass;
78  MachineFrameInfo &MFI = MF.getFrameInfo();
79  unsigned Size = TRI.getSpillSize(RC);
80  Align Alignment = TRI.getSpillAlign(RC);
81  EHSpillSlot[0] = MFI.CreateStackObject(Size, Alignment, true);
82  EHSpillSlot[1] = MFI.CreateStackObject(Size, Alignment, true);
83  EHSpillSlotSet = true;
84  return EHSpillSlot;
85 }
86 
llvm::MachineFrameInfo::estimateStackSize
uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
Definition: MachineFrameInfo.cpp:137
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::XCoreFunctionInfo::createLRSpillSlot
int createLRSpillSlot(MachineFunction &MF)
Definition: XCoreMachineFunctionInfo.cpp:41
llvm::TargetSubtargetInfo::getRegisterInfo
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
Definition: TargetSubtargetInfo.h:127
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:237
llvm::XCoreFunctionInfo::createFPSpillSlot
int createFPSpillSlot(MachineFunction &MF)
Definition: XCoreMachineFunctionInfo.cpp:59
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1628
XCoreInstrInfo.h
llvm::TargetRegisterClass
Definition: TargetRegisterInfo.h:46
XCoreMachineFunctionInfo.h
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::TargetRegisterInfo::getSpillAlign
Align getSpillAlign(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class.
Definition: TargetRegisterInfo.h:292
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:657
llvm::TargetRegisterInfo::getSpillSize
unsigned getSpillSize(const TargetRegisterClass &RC) const
Return the size in bytes of the stack slot allocated to hold a spilled copy of a register from class ...
Definition: TargetRegisterInfo.h:286
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
llvm::DenseMap
Definition: DenseMap.h:714
llvm::MachineFrameInfo::CreateFixedObject
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
Definition: MachineFrameInfo.cpp:83
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:673
llvm::XCoreFunctionInfo::isLargeFrame
bool isLargeFrame(const MachineFunction &MF) const
Definition: XCoreMachineFunctionInfo.cpp:25
llvm::XCoreFunctionInfo::clone
MachineFunctionInfo * clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, const DenseMap< MachineBasicBlock *, MachineBasicBlock * > &Src2DstMBB) const override
Make a functionally equivalent copy of this MachineFunctionInfo in MF.
Definition: XCoreMachineFunctionInfo.cpp:18
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::XCoreFunctionInfo
XCoreFunctionInfo - This class is derived from MachineFunction private XCore target-specific informat...
Definition: XCoreMachineFunctionInfo.h:27
llvm::MachineFrameInfo::CreateStackObject
int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
Definition: MachineFrameInfo.cpp:51
TargetSubtargetInfo.h
llvm::MachineFunction::cloneInfo
Ty * cloneInfo(const Ty &Old)
Definition: MachineFunction.h:766
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:623
Function.h
llvm::Function::isVarArg
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Definition: Function.h:188
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition: MachineFrameInfo.h:106
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:143
llvm::XCoreFunctionInfo::createEHSpillSlot
const int * createEHSpillSlot(MachineFunction &MF)
Definition: XCoreMachineFunctionInfo.cpp:72
llvm::MachineFunctionInfo
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
Definition: MachineFunction.h:95