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 | MachineFunctionInfo *XCoreFunctionInfo::clone( |
19 | BumpPtrAllocator &Allocator, MachineFunction &DestMF, |
20 | const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB) |
21 | const { |
22 | return DestMF.cloneInfo<XCoreFunctionInfo>(Old: *this); |
23 | } |
24 | |
25 | bool XCoreFunctionInfo::isLargeFrame(const MachineFunction &MF) const { |
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 | |
41 | int XCoreFunctionInfo::createLRSpillSlot(MachineFunction &MF) { |
42 | if (LRSpillSlotSet) { |
43 | return LRSpillSlot; |
44 | } |
45 | const TargetRegisterClass &RC = XCore::GRRegsRegClass; |
46 | const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); |
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(Size: TRI.getSpillSize(RC), SPOffset: 0, IsImmutable: true); |
51 | } else { |
52 | LRSpillSlot = MFI.CreateStackObject(Size: TRI.getSpillSize(RC), |
53 | Alignment: TRI.getSpillAlign(RC), isSpillSlot: true); |
54 | } |
55 | LRSpillSlotSet = true; |
56 | return LRSpillSlot; |
57 | } |
58 | |
59 | int XCoreFunctionInfo::createFPSpillSlot(MachineFunction &MF) { |
60 | if (FPSpillSlotSet) { |
61 | return FPSpillSlot; |
62 | } |
63 | const TargetRegisterClass &RC = XCore::GRRegsRegClass; |
64 | const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); |
65 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
66 | FPSpillSlot = |
67 | MFI.CreateStackObject(Size: TRI.getSpillSize(RC), Alignment: TRI.getSpillAlign(RC), isSpillSlot: true); |
68 | FPSpillSlotSet = true; |
69 | return FPSpillSlot; |
70 | } |
71 | |
72 | const int* XCoreFunctionInfo::createEHSpillSlot(MachineFunction &MF) { |
73 | if (EHSpillSlotSet) { |
74 | return EHSpillSlot; |
75 | } |
76 | const TargetRegisterClass &RC = XCore::GRRegsRegClass; |
77 | const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); |
78 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
79 | unsigned Size = TRI.getSpillSize(RC); |
80 | Align Alignment = TRI.getSpillAlign(RC); |
81 | EHSpillSlot[0] = MFI.CreateStackObject(Size, Alignment, isSpillSlot: true); |
82 | EHSpillSlot[1] = MFI.CreateStackObject(Size, Alignment, isSpillSlot: true); |
83 | EHSpillSlotSet = true; |
84 | return EHSpillSlot; |
85 | } |
86 | |
87 | |