[InstCombine] Signed saturation patterns
[llvm-core.git] / lib / Target / XCore / XCoreMachineFunctionInfo.cpp
blob0b4fcffbc655948dae6354a6649087733b0c4c80
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 //===----------------------------------------------------------------------===//
9 #include "XCoreMachineFunctionInfo.h"
10 #include "XCoreInstrInfo.h"
11 #include "llvm/CodeGen/TargetSubtargetInfo.h"
12 #include "llvm/IR/Function.h"
14 using namespace llvm;
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) {
35 if (LRSpillSlotSet) {
36 return LRSpillSlot;
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);
48 LRSpillSlotSet = true;
49 return LRSpillSlot;
52 int XCoreFunctionInfo::createFPSpillSlot(MachineFunction &MF) {
53 if (FPSpillSlotSet) {
54 return FPSpillSlot;
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;
65 const int* XCoreFunctionInfo::createEHSpillSlot(MachineFunction &MF) {
66 if (EHSpillSlotSet) {
67 return EHSpillSlot;
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;