LLVM API Documentation

XCoreMachineFunctionInfo.cpp
Go to the documentation of this file.
00001 //===-- XCoreMachineFuctionInfo.cpp - XCore machine function info ---------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "XCoreMachineFunctionInfo.h"
00011 #include "XCoreInstrInfo.h"
00012 #include "llvm/IR/Function.h"
00013 
00014 using namespace llvm;
00015 
00016 void XCoreFunctionInfo::anchor() { }
00017 
00018 bool XCoreFunctionInfo::isLargeFrame(const MachineFunction &MF) const {
00019   if (CachedEStackSize == -1) {
00020     CachedEStackSize = MF.getFrameInfo()->estimateStackSize(MF);
00021   }
00022   // isLargeFrame() is used when deciding if spill slots should be added to
00023   // allow eliminateFrameIndex() to scavenge registers.
00024   // This is only required when there is no FP and offsets are greater than
00025   // ~256KB (~64Kwords). Thus only for code run on the emulator!
00026   //
00027   // The arbitrary value of 0xf000 allows frames of up to ~240KB before spill
00028   // slots are added for the use of eliminateFrameIndex() register scavenging.
00029   // For frames less than 240KB, it is assumed that there will be less than
00030   // 16KB of function arguments.
00031   return CachedEStackSize > 0xf000;
00032 }
00033 
00034 int XCoreFunctionInfo::createLRSpillSlot(MachineFunction &MF) {
00035   if (LRSpillSlotSet) {
00036     return LRSpillSlot;
00037   }
00038   const TargetRegisterClass *RC = &XCore::GRRegsRegClass;
00039   MachineFrameInfo *MFI = MF.getFrameInfo();
00040   if (! MF.getFunction()->isVarArg()) {
00041     // A fixed offset of 0 allows us to save / restore LR using entsp / retsp.
00042     LRSpillSlot = MFI->CreateFixedObject(RC->getSize(), 0, true);
00043   } else {
00044     LRSpillSlot = MFI->CreateStackObject(RC->getSize(), RC->getAlignment(), true);
00045   }
00046   LRSpillSlotSet = true;
00047   return LRSpillSlot;
00048 }
00049 
00050 int XCoreFunctionInfo::createFPSpillSlot(MachineFunction &MF) {
00051   if (FPSpillSlotSet) {
00052     return FPSpillSlot;
00053   }
00054   const TargetRegisterClass *RC = &XCore::GRRegsRegClass;
00055   MachineFrameInfo *MFI = MF.getFrameInfo();
00056   FPSpillSlot = MFI->CreateStackObject(RC->getSize(), RC->getAlignment(), true);
00057   FPSpillSlotSet = true;
00058   return FPSpillSlot;
00059 }
00060 
00061 const int* XCoreFunctionInfo::createEHSpillSlot(MachineFunction &MF) {
00062   if (EHSpillSlotSet) {
00063     return EHSpillSlot;
00064   }
00065   const TargetRegisterClass *RC = &XCore::GRRegsRegClass;
00066   MachineFrameInfo *MFI = MF.getFrameInfo();
00067   EHSpillSlot[0] = MFI->CreateStackObject(RC->getSize(), RC->getAlignment(), true);
00068   EHSpillSlot[1] = MFI->CreateStackObject(RC->getSize(), RC->getAlignment(), true);
00069   EHSpillSlotSet = true;
00070   return EHSpillSlot;
00071 }
00072