1 //===-- XCoreMachineFunctionInfo.cpp - XCore machine function info --------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "XCoreMachineFunctionInfo.h" 11 #include "XCoreInstrInfo.h" 12 #include "llvm/IR/Function.h" 13 #include "llvm/Target/TargetSubtargetInfo.h" 14 15 using namespace llvm; 16 17 void XCoreFunctionInfo::anchor() { } 18 19 bool XCoreFunctionInfo::isLargeFrame(const MachineFunction &MF) const { 20 if (CachedEStackSize == -1) { 21 CachedEStackSize = MF.getFrameInfo().estimateStackSize(MF); 22 } 23 // isLargeFrame() is used when deciding if spill slots should be added to 24 // allow eliminateFrameIndex() to scavenge registers. 25 // This is only required when there is no FP and offsets are greater than 26 // ~256KB (~64Kwords). Thus only for code run on the emulator! 27 // 28 // The arbitrary value of 0xf000 allows frames of up to ~240KB before spill 29 // slots are added for the use of eliminateFrameIndex() register scavenging. 30 // For frames less than 240KB, it is assumed that there will be less than 31 // 16KB of function arguments. 32 return CachedEStackSize > 0xf000; 33 } 34 35 int XCoreFunctionInfo::createLRSpillSlot(MachineFunction &MF) { 36 if (LRSpillSlotSet) { 37 return LRSpillSlot; 38 } 39 const TargetRegisterClass &RC = XCore::GRRegsRegClass; 40 const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); 41 MachineFrameInfo &MFI = MF.getFrameInfo(); 42 if (! MF.getFunction()->isVarArg()) { 43 // A fixed offset of 0 allows us to save / restore LR using entsp / retsp. 44 LRSpillSlot = MFI.CreateFixedObject(TRI.getSpillSize(RC), 0, true); 45 } else { 46 LRSpillSlot = MFI.CreateStackObject(TRI.getSpillSize(RC), 47 TRI.getSpillAlignment(RC), true); 48 } 49 LRSpillSlotSet = true; 50 return LRSpillSlot; 51 } 52 53 int XCoreFunctionInfo::createFPSpillSlot(MachineFunction &MF) { 54 if (FPSpillSlotSet) { 55 return FPSpillSlot; 56 } 57 const TargetRegisterClass &RC = XCore::GRRegsRegClass; 58 const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); 59 MachineFrameInfo &MFI = MF.getFrameInfo(); 60 FPSpillSlot = MFI.CreateStackObject(TRI.getSpillSize(RC), 61 TRI.getSpillAlignment(RC), true); 62 FPSpillSlotSet = true; 63 return FPSpillSlot; 64 } 65 66 const int* XCoreFunctionInfo::createEHSpillSlot(MachineFunction &MF) { 67 if (EHSpillSlotSet) { 68 return EHSpillSlot; 69 } 70 const TargetRegisterClass &RC = XCore::GRRegsRegClass; 71 const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo(); 72 MachineFrameInfo &MFI = MF.getFrameInfo(); 73 unsigned Size = TRI.getSpillSize(RC); 74 unsigned Align = TRI.getSpillAlignment(RC); 75 EHSpillSlot[0] = MFI.CreateStackObject(Size, Align, true); 76 EHSpillSlot[1] = MFI.CreateStackObject(Size, Align, true); 77 EHSpillSlotSet = true; 78 return EHSpillSlot; 79 } 80 81