]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/Target/XCore/XCoreMachineFunctionInfo.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / Target / XCore / XCoreMachineFunctionInfo.cpp
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
9 #include "XCoreMachineFunctionInfo.h"
10 #include "XCoreInstrInfo.h"
11 #include "llvm/CodeGen/TargetSubtargetInfo.h"
12 #include "llvm/IR/Function.h"
13
14 using namespace llvm;
15
16 void XCoreFunctionInfo::anchor() { }
17
18 bool XCoreFunctionInfo::isLargeFrame(const MachineFunction &MF) const {
19   if (CachedEStackSize == -1) {
20     CachedEStackSize = MF.getFrameInfo().estimateStackSize(MF);
21   }
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!
26   //
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;
32 }
33
34 int XCoreFunctionInfo::createLRSpillSlot(MachineFunction &MF) {
35   if (LRSpillSlotSet) {
36     return LRSpillSlot;
37   }
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);
44   } else {
45     LRSpillSlot = MFI.CreateStackObject(TRI.getSpillSize(RC),
46                                         TRI.getSpillAlignment(RC), true);
47   }
48   LRSpillSlotSet = true;
49   return LRSpillSlot;
50 }
51
52 int XCoreFunctionInfo::createFPSpillSlot(MachineFunction &MF) {
53   if (FPSpillSlotSet) {
54     return FPSpillSlot;
55   }
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;
62   return FPSpillSlot;
63 }
64
65 const int* XCoreFunctionInfo::createEHSpillSlot(MachineFunction &MF) {
66   if (EHSpillSlotSet) {
67     return EHSpillSlot;
68   }
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;
77   return EHSpillSlot;
78 }
79