1 //===- SparcV8RegisterInfo.cpp - SparcV8 Register Information ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file contains the SparcV8 implementation of the MRegisterInfo class.
12 //===----------------------------------------------------------------------===//
15 #include "SparcV8RegisterInfo.h"
16 #include "llvm/CodeGen/MachineInstrBuilder.h"
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/CodeGen/MachineFrameInfo.h"
19 #include "llvm/Type.h"
20 #include "llvm/ADT/STLExtras.h"
24 SparcV8RegisterInfo::SparcV8RegisterInfo()
25 : SparcV8GenRegisterInfo(V8::ADJCALLSTACKDOWN,
26 V8::ADJCALLSTACKUP) {}
28 void SparcV8RegisterInfo::
29 storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
30 unsigned SrcReg, int FrameIdx) const {
31 const TargetRegisterClass *RC = getRegClass(SrcReg);
33 // On the order of operands here: think "[FrameIdx + 0] = SrcReg".
34 if (RC == SparcV8::IntRegsRegisterClass)
35 BuildMI (MBB, I, V8::ST, 3).addFrameIndex (FrameIdx).addSImm (0)
37 else if (RC == SparcV8::FPRegsRegisterClass)
38 BuildMI (MBB, I, V8::STFri, 3).addFrameIndex (FrameIdx).addSImm (0)
40 else if (RC == SparcV8::DFPRegsRegisterClass)
41 BuildMI (MBB, I, V8::STDFri, 3).addFrameIndex (FrameIdx).addSImm (0)
44 assert (0 && "Can't store this register to stack slot");
47 void SparcV8RegisterInfo::
48 loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
49 unsigned DestReg, int FrameIdx) const {
50 const TargetRegisterClass *RC = getRegClass(DestReg);
51 if (RC == SparcV8::IntRegsRegisterClass)
52 BuildMI (MBB, I, V8::LD, 2, DestReg).addFrameIndex (FrameIdx).addSImm (0);
53 else if (RC == SparcV8::FPRegsRegisterClass)
54 BuildMI (MBB, I, V8::LDFri, 2, DestReg).addFrameIndex (FrameIdx)
56 else if (RC == SparcV8::DFPRegsRegisterClass)
57 BuildMI (MBB, I, V8::LDDFri, 2, DestReg).addFrameIndex (FrameIdx)
60 assert(0 && "Can't load this register from stack slot");
63 void SparcV8RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
64 MachineBasicBlock::iterator I,
65 unsigned DestReg, unsigned SrcReg,
66 const TargetRegisterClass *RC) const {
67 if (RC == SparcV8::IntRegsRegisterClass)
68 BuildMI (MBB, I, V8::ORrr, 2, DestReg).addReg (V8::G0).addReg (SrcReg);
69 else if (RC == SparcV8::FPRegsRegisterClass)
70 BuildMI (MBB, I, V8::FMOVS, 1, DestReg).addReg (SrcReg);
71 else if (RC == SparcV8::DFPRegsRegisterClass)
72 BuildMI (MBB, I, V8::FpMOVD, 1, DestReg).addReg (SrcReg);
74 assert (0 && "Can't copy this register");
77 void SparcV8RegisterInfo::
78 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
79 MachineBasicBlock::iterator I) const {
81 << "Sorry, I don't know how to eliminate call frame pseudo instrs yet, in\n"
82 << __FUNCTION__ << " at " << __FILE__ << ":" << __LINE__ << "\n";
87 SparcV8RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II) const {
89 MachineInstr &MI = *II;
90 while (!MI.getOperand(i).isFrameIndex()) {
92 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
95 int FrameIndex = MI.getOperand(i).getFrameIndex();
97 // Replace frame index with a frame pointer reference
98 MI.SetMachineOperandReg (i, V8::FP);
100 // Addressable stack objects are accessed using neg. offsets from %fp
101 MachineFunction &MF = *MI.getParent()->getParent();
102 int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex) +
103 MI.getOperand(i+1).getImmedValue();
105 MI.SetMachineOperandConst (i+1, MachineOperand::MO_SignExtendedImmed, Offset);
108 void SparcV8RegisterInfo::
109 processFunctionBeforeFrameFinalized(MachineFunction &MF) const {}
111 void SparcV8RegisterInfo::emitPrologue(MachineFunction &MF) const {
112 MachineBasicBlock &MBB = MF.front();
113 MachineFrameInfo *MFI = MF.getFrameInfo();
115 // Get the number of bytes to allocate from the FrameInfo
116 int NumBytes = (int) MFI->getStackSize();
118 // Emit the correct save instruction based on the number of bytes in the frame.
119 // Minimum stack frame size according to V8 ABI is:
120 // 16 words for register window spill
121 // 1 word for address of returned aggregate-value
122 // + 6 words for passing parameters on the stack
124 // 23 words * 4 bytes per word = 92 bytes
126 // Round up to next doubleword boundary -- a double-word boundary
127 // is required by the ABI.
128 NumBytes = (NumBytes + 7) & ~7;
129 BuildMI(MBB, MBB.begin(), V8::SAVEri, 2,
130 V8::SP).addImm(-NumBytes).addReg(V8::SP);
133 void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
134 MachineBasicBlock &MBB) const {
135 MachineBasicBlock::iterator MBBI = prior(MBB.end());
136 assert(MBBI->getOpcode() == V8::RETL &&
137 "Can only put epilog before 'retl' instruction!");
138 BuildMI(MBB, MBBI, V8::RESTORErr, 2, V8::G0).addReg(V8::G0).addReg(V8::G0);
141 #include "SparcV8GenRegisterInfo.inc"
143 const TargetRegisterClass*
144 SparcV8RegisterInfo::getRegClassForType(const Type* Ty) const {
145 switch (Ty->getTypeID()) {
146 case Type::FloatTyID: return &FPRegsInstance;
147 case Type::DoubleTyID: return &DFPRegsInstance;
149 case Type::ULongTyID: assert(0 && "Long values do not fit in registers!");
150 default: assert(0 && "Invalid type to getClass!");
152 case Type::SByteTyID:
153 case Type::UByteTyID:
154 case Type::ShortTyID:
155 case Type::UShortTyID:
158 case Type::PointerTyID: return &IntRegsInstance;