17d523365SDimitry Andric //===-- XCoreMachineFunctionInfo.cpp - XCore machine function info --------===//
2dff0c46cSDimitry Andric //
3dff0c46cSDimitry Andric //                     The LLVM Compiler Infrastructure
4dff0c46cSDimitry Andric //
5dff0c46cSDimitry Andric // This file is distributed under the University of Illinois Open Source
6dff0c46cSDimitry Andric // License. See LICENSE.TXT for details.
7dff0c46cSDimitry Andric //
8dff0c46cSDimitry Andric //===----------------------------------------------------------------------===//
9dff0c46cSDimitry Andric 
10dff0c46cSDimitry Andric #include "XCoreMachineFunctionInfo.h"
1191bc56edSDimitry Andric #include "XCoreInstrInfo.h"
12*2cab237bSDimitry Andric #include "llvm/CodeGen/TargetSubtargetInfo.h"
1391bc56edSDimitry Andric #include "llvm/IR/Function.h"
14dff0c46cSDimitry Andric 
15dff0c46cSDimitry Andric using namespace llvm;
16dff0c46cSDimitry Andric 
anchor()17dff0c46cSDimitry Andric void XCoreFunctionInfo::anchor() { }
1891bc56edSDimitry Andric 
isLargeFrame(const MachineFunction & MF) const1991bc56edSDimitry Andric bool XCoreFunctionInfo::isLargeFrame(const MachineFunction &MF) const {
2091bc56edSDimitry Andric   if (CachedEStackSize == -1) {
21d88c1a5aSDimitry Andric     CachedEStackSize = MF.getFrameInfo().estimateStackSize(MF);
2291bc56edSDimitry Andric   }
2391bc56edSDimitry Andric   // isLargeFrame() is used when deciding if spill slots should be added to
2491bc56edSDimitry Andric   // allow eliminateFrameIndex() to scavenge registers.
2591bc56edSDimitry Andric   // This is only required when there is no FP and offsets are greater than
2691bc56edSDimitry Andric   // ~256KB (~64Kwords). Thus only for code run on the emulator!
2791bc56edSDimitry Andric   //
2891bc56edSDimitry Andric   // The arbitrary value of 0xf000 allows frames of up to ~240KB before spill
2991bc56edSDimitry Andric   // slots are added for the use of eliminateFrameIndex() register scavenging.
3091bc56edSDimitry Andric   // For frames less than 240KB, it is assumed that there will be less than
3191bc56edSDimitry Andric   // 16KB of function arguments.
3291bc56edSDimitry Andric   return CachedEStackSize > 0xf000;
3391bc56edSDimitry Andric }
3491bc56edSDimitry Andric 
createLRSpillSlot(MachineFunction & MF)3591bc56edSDimitry Andric int XCoreFunctionInfo::createLRSpillSlot(MachineFunction &MF) {
3691bc56edSDimitry Andric   if (LRSpillSlotSet) {
3791bc56edSDimitry Andric     return LRSpillSlot;
3891bc56edSDimitry Andric   }
3951690af2SDimitry Andric   const TargetRegisterClass &RC = XCore::GRRegsRegClass;
4051690af2SDimitry Andric   const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
41d88c1a5aSDimitry Andric   MachineFrameInfo &MFI = MF.getFrameInfo();
42*2cab237bSDimitry Andric   if (! MF.getFunction().isVarArg()) {
4391bc56edSDimitry Andric     // A fixed offset of 0 allows us to save / restore LR using entsp / retsp.
4451690af2SDimitry Andric     LRSpillSlot = MFI.CreateFixedObject(TRI.getSpillSize(RC), 0, true);
4591bc56edSDimitry Andric   } else {
4651690af2SDimitry Andric     LRSpillSlot = MFI.CreateStackObject(TRI.getSpillSize(RC),
4751690af2SDimitry Andric                                         TRI.getSpillAlignment(RC), true);
4891bc56edSDimitry Andric   }
4991bc56edSDimitry Andric   LRSpillSlotSet = true;
5091bc56edSDimitry Andric   return LRSpillSlot;
5191bc56edSDimitry Andric }
5291bc56edSDimitry Andric 
createFPSpillSlot(MachineFunction & MF)5391bc56edSDimitry Andric int XCoreFunctionInfo::createFPSpillSlot(MachineFunction &MF) {
5491bc56edSDimitry Andric   if (FPSpillSlotSet) {
5591bc56edSDimitry Andric     return FPSpillSlot;
5691bc56edSDimitry Andric   }
5751690af2SDimitry Andric   const TargetRegisterClass &RC = XCore::GRRegsRegClass;
5851690af2SDimitry Andric   const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
59d88c1a5aSDimitry Andric   MachineFrameInfo &MFI = MF.getFrameInfo();
6051690af2SDimitry Andric   FPSpillSlot = MFI.CreateStackObject(TRI.getSpillSize(RC),
6151690af2SDimitry Andric                                       TRI.getSpillAlignment(RC), true);
6291bc56edSDimitry Andric   FPSpillSlotSet = true;
6391bc56edSDimitry Andric   return FPSpillSlot;
6491bc56edSDimitry Andric }
6591bc56edSDimitry Andric 
createEHSpillSlot(MachineFunction & MF)6691bc56edSDimitry Andric const int* XCoreFunctionInfo::createEHSpillSlot(MachineFunction &MF) {
6791bc56edSDimitry Andric   if (EHSpillSlotSet) {
6891bc56edSDimitry Andric     return EHSpillSlot;
6991bc56edSDimitry Andric   }
7051690af2SDimitry Andric   const TargetRegisterClass &RC = XCore::GRRegsRegClass;
7151690af2SDimitry Andric   const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
72d88c1a5aSDimitry Andric   MachineFrameInfo &MFI = MF.getFrameInfo();
7351690af2SDimitry Andric   unsigned Size = TRI.getSpillSize(RC);
7451690af2SDimitry Andric   unsigned Align = TRI.getSpillAlignment(RC);
7551690af2SDimitry Andric   EHSpillSlot[0] = MFI.CreateStackObject(Size, Align, true);
7651690af2SDimitry Andric   EHSpillSlot[1] = MFI.CreateStackObject(Size, Align, true);
7791bc56edSDimitry Andric   EHSpillSlotSet = true;
7891bc56edSDimitry Andric   return EHSpillSlot;
7991bc56edSDimitry Andric }
8091bc56edSDimitry Andric 
81