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
14using namespace llvm;
15
16void XCoreFunctionInfo::anchor() { }
17
18bool XCoreFunctionInfo::isLargeFrame(const MachineFunction &MF) const {
19  if (CachedEStackSize == -1) {
20    CachedEStackSize = MF.getFrameInfo()->estimateStackSize(MF);
21  }
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!
26  //
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;
32}
33
34int XCoreFunctionInfo::createLRSpillSlot(MachineFunction &MF) {
35  if (LRSpillSlotSet) {
36    return LRSpillSlot;
37  }
38  const TargetRegisterClass *RC = &XCore::GRRegsRegClass;
39  MachineFrameInfo *MFI = MF.getFrameInfo();
40  if (! MF.getFunction()->isVarArg()) {
41    // A fixed offset of 0 allows us to save / restore LR using entsp / retsp.
42    LRSpillSlot = MFI->CreateFixedObject(RC->getSize(), 0, true);
43  } else {
44    LRSpillSlot = MFI->CreateStackObject(RC->getSize(), RC->getAlignment(), true);
45  }
46  LRSpillSlotSet = true;
47  return LRSpillSlot;
48}
49
50int XCoreFunctionInfo::createFPSpillSlot(MachineFunction &MF) {
51  if (FPSpillSlotSet) {
52    return FPSpillSlot;
53  }
54  const TargetRegisterClass *RC = &XCore::GRRegsRegClass;
55  MachineFrameInfo *MFI = MF.getFrameInfo();
56  FPSpillSlot = MFI->CreateStackObject(RC->getSize(), RC->getAlignment(), true);
57  FPSpillSlotSet = true;
58  return FPSpillSlot;
59}
60
61const int* XCoreFunctionInfo::createEHSpillSlot(MachineFunction &MF) {
62  if (EHSpillSlotSet) {
63    return EHSpillSlot;
64  }
65  const TargetRegisterClass *RC = &XCore::GRRegsRegClass;
66  MachineFrameInfo *MFI = MF.getFrameInfo();
67  EHSpillSlot[0] = MFI->CreateStackObject(RC->getSize(), RC->getAlignment(), true);
68  EHSpillSlot[1] = MFI->CreateStackObject(RC->getSize(), RC->getAlignment(), true);
69  EHSpillSlotSet = true;
70  return EHSpillSlot;
71}
72
73