Make prolog align stack properly. Make epilog not touch any registers.
[oota-llvm.git] / lib / Target / Sparc / SparcRegisterInfo.cpp
1 //===- SparcV8RegisterInfo.cpp - SparcV8 Register Information ---*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the SparcV8 implementation of the MRegisterInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "SparcV8.h"
15 #include "SparcV8RegisterInfo.h"
16 #include "llvm/CodeGen/MachineInstrBuilder.h"
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/Type.h"
19 #include "Support/STLExtras.h"
20 using namespace llvm;
21
22 SparcV8RegisterInfo::SparcV8RegisterInfo()
23   : SparcV8GenRegisterInfo(V8::ADJCALLSTACKDOWN,
24                            V8::ADJCALLSTACKUP) {}
25
26 int SparcV8RegisterInfo::storeRegToStackSlot(
27   MachineBasicBlock &MBB,
28   MachineBasicBlock::iterator MBBI,
29   unsigned SrcReg, int FrameIdx,
30   const TargetRegisterClass *RC) const
31 {
32   abort();
33   return -1;
34 }
35
36 int SparcV8RegisterInfo::loadRegFromStackSlot(
37   MachineBasicBlock &MBB,
38   MachineBasicBlock::iterator MBBI,
39   unsigned DestReg, int FrameIdx,
40   const TargetRegisterClass *RC) const
41 {
42   abort();
43   return -1;
44 }
45
46 int SparcV8RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
47                                       MachineBasicBlock::iterator MBBI,
48                                       unsigned DestReg, unsigned SrcReg,
49                                       const TargetRegisterClass *RC) const {
50   abort();
51   return -1;
52 }
53
54 void SparcV8RegisterInfo::
55 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
56                               MachineBasicBlock::iterator I) const {
57   abort();
58 }
59
60 void
61 SparcV8RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
62                                          MachineBasicBlock::iterator II) const {
63   abort();
64 }
65
66 void SparcV8RegisterInfo::
67 processFunctionBeforeFrameFinalized(MachineFunction &MF) const {}
68
69 void SparcV8RegisterInfo::emitPrologue(MachineFunction &MF) const {
70   MachineBasicBlock &MBB = MF.front();
71
72   // Eventually this should emit the correct save instruction based on the
73   // number of bytes in the frame.  For now we just hardcode it.
74   BuildMI(MBB, MBB.begin(), V8::SAVEri, 2, V8::SP).addImm(-112).addReg(V8::SP);
75 }
76
77 void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
78                                        MachineBasicBlock &MBB) const {
79   MachineBasicBlock::iterator MBBI = prior(MBB.end());
80   assert(MBBI->getOpcode() == V8::RETL &&
81          "Can only put epilog before 'retl' instruction!");
82   BuildMI(MBB, MBBI, V8::RESTORErr, 2, V8::G0).addReg(V8::G0).addReg(V8::G0);
83 }
84
85
86 #include "SparcV8GenRegisterInfo.inc"
87
88 const TargetRegisterClass*
89 SparcV8RegisterInfo::getRegClassForType(const Type* Ty) const {
90   switch (Ty->getPrimitiveID()) {
91   case Type::FloatTyID:  return &FPRegsInstance;
92   case Type::DoubleTyID: return &DFPRegsInstance;
93   case Type::LongTyID:
94   case Type::ULongTyID: assert(0 && "Long values can't fit in registers!");
95   default:              assert(0 && "Invalid type to getClass!");
96   case Type::BoolTyID:
97   case Type::SByteTyID:
98   case Type::UByteTyID:
99   case Type::ShortTyID:
100   case Type::UShortTyID:
101   case Type::IntTyID:
102   case Type::UIntTyID:
103   case Type::PointerTyID: return &IntRegsInstance;
104   }
105 }
106