1 //===-- XCoreMachineFunctionInfo.cpp - XCore machine function info --------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "XCoreMachineFunctionInfo.h"
10 #include "XCoreInstrInfo.h"
11 #include "llvm/CodeGen/TargetSubtargetInfo.h"
12 #include "llvm/IR/Function.h"
16 void XCoreFunctionInfo::anchor() { }
18 bool XCoreFunctionInfo::isLargeFrame(const MachineFunction
&MF
) const {
19 if (CachedEStackSize
== -1) {
20 CachedEStackSize
= MF
.getFrameInfo().estimateStackSize(MF
);
22 // isLargeFrame() is used when deciding if spill slots should be added to
23 // allow eliminateFrameIndex() to scavenge registers.
24 // This is only required when there is no FP and offsets are greater than
25 // ~256KB (~64Kwords). Thus only for code run on the emulator!
27 // The arbitrary value of 0xf000 allows frames of up to ~240KB before spill
28 // slots are added for the use of eliminateFrameIndex() register scavenging.
29 // For frames less than 240KB, it is assumed that there will be less than
30 // 16KB of function arguments.
31 return CachedEStackSize
> 0xf000;
34 int XCoreFunctionInfo::createLRSpillSlot(MachineFunction
&MF
) {
38 const TargetRegisterClass
&RC
= XCore::GRRegsRegClass
;
39 const TargetRegisterInfo
&TRI
= *MF
.getSubtarget().getRegisterInfo();
40 MachineFrameInfo
&MFI
= MF
.getFrameInfo();
41 if (! MF
.getFunction().isVarArg()) {
42 // A fixed offset of 0 allows us to save / restore LR using entsp / retsp.
43 LRSpillSlot
= MFI
.CreateFixedObject(TRI
.getSpillSize(RC
), 0, true);
45 LRSpillSlot
= MFI
.CreateStackObject(TRI
.getSpillSize(RC
),
46 TRI
.getSpillAlignment(RC
), true);
48 LRSpillSlotSet
= true;
52 int XCoreFunctionInfo::createFPSpillSlot(MachineFunction
&MF
) {
56 const TargetRegisterClass
&RC
= XCore::GRRegsRegClass
;
57 const TargetRegisterInfo
&TRI
= *MF
.getSubtarget().getRegisterInfo();
58 MachineFrameInfo
&MFI
= MF
.getFrameInfo();
59 FPSpillSlot
= MFI
.CreateStackObject(TRI
.getSpillSize(RC
),
60 TRI
.getSpillAlignment(RC
), true);
61 FPSpillSlotSet
= true;
65 const int* XCoreFunctionInfo::createEHSpillSlot(MachineFunction
&MF
) {
69 const TargetRegisterClass
&RC
= XCore::GRRegsRegClass
;
70 const TargetRegisterInfo
&TRI
= *MF
.getSubtarget().getRegisterInfo();
71 MachineFrameInfo
&MFI
= MF
.getFrameInfo();
72 unsigned Size
= TRI
.getSpillSize(RC
);
73 unsigned Align
= TRI
.getSpillAlignment(RC
);
74 EHSpillSlot
[0] = MFI
.CreateStackObject(Size
, Align
, true);
75 EHSpillSlot
[1] = MFI
.CreateStackObject(Size
, Align
, true);
76 EHSpillSlotSet
= true;