blob: 67a67428e966b42102fd9acffddc22b05466253b [file] [log] [blame]
Brian Gaekee785e532004-02-25 19:28:19 +00001//===- 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"
Chris Lattnere1274de2004-02-29 05:18:30 +000016#include "llvm/CodeGen/MachineInstrBuilder.h"
17#include "llvm/CodeGen/MachineFunction.h"
Brian Gaeke6c5526e2004-04-02 20:53:37 +000018#include "llvm/CodeGen/MachineFrameInfo.h"
Brian Gaekee785e532004-02-25 19:28:19 +000019#include "llvm/Type.h"
Chris Lattnere1274de2004-02-29 05:18:30 +000020#include "Support/STLExtras.h"
Brian Gaekee785e532004-02-25 19:28:19 +000021using namespace llvm;
22
23SparcV8RegisterInfo::SparcV8RegisterInfo()
Chris Lattner275f6452004-02-28 19:37:18 +000024 : SparcV8GenRegisterInfo(V8::ADJCALLSTACKDOWN,
25 V8::ADJCALLSTACKUP) {}
Brian Gaekee785e532004-02-25 19:28:19 +000026
27int SparcV8RegisterInfo::storeRegToStackSlot(
28 MachineBasicBlock &MBB,
Brian Gaeke6713d982004-06-17 22:34:48 +000029 MachineBasicBlock::iterator I,
Brian Gaekee785e532004-02-25 19:28:19 +000030 unsigned SrcReg, int FrameIdx,
31 const TargetRegisterClass *RC) const
32{
Brian Gaeke6c5526e2004-04-02 20:53:37 +000033 assert (RC == SparcV8::IntRegsRegisterClass
34 && "Can only store 32-bit values to stack slots");
Brian Gaeke6713d982004-06-17 22:34:48 +000035 // On the order of operands here: think "[FrameIdx + 0] = SrcReg".
36 BuildMI (MBB, I, V8::STrm, 3).addFrameIndex (FrameIdx).addSImm (0).addReg (SrcReg);
Brian Gaeke6c5526e2004-04-02 20:53:37 +000037 return 1;
Brian Gaekee785e532004-02-25 19:28:19 +000038}
39
40int SparcV8RegisterInfo::loadRegFromStackSlot(
41 MachineBasicBlock &MBB,
Brian Gaeke88ddd4a2004-04-07 04:29:14 +000042 MachineBasicBlock::iterator I,
Brian Gaekee785e532004-02-25 19:28:19 +000043 unsigned DestReg, int FrameIdx,
44 const TargetRegisterClass *RC) const
45{
Brian Gaeke6c5526e2004-04-02 20:53:37 +000046 assert (RC == SparcV8::IntRegsRegisterClass
47 && "Can only load 32-bit registers from stack slots");
Brian Gaeke88ddd4a2004-04-07 04:29:14 +000048 BuildMI (MBB, I, V8::LDmr, 2, DestReg).addFrameIndex (FrameIdx).addSImm (0);
Brian Gaeke6c5526e2004-04-02 20:53:37 +000049 return 1;
Brian Gaekee785e532004-02-25 19:28:19 +000050}
51
52int SparcV8RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
Brian Gaeke88ddd4a2004-04-07 04:29:14 +000053 MachineBasicBlock::iterator I,
Brian Gaekee785e532004-02-25 19:28:19 +000054 unsigned DestReg, unsigned SrcReg,
55 const TargetRegisterClass *RC) const {
Brian Gaeke6c5526e2004-04-02 20:53:37 +000056 assert (RC == SparcV8::IntRegsRegisterClass
57 && "Can only copy 32-bit registers");
Brian Gaeke88ddd4a2004-04-07 04:29:14 +000058 BuildMI (MBB, I, V8::ORrr, 2, DestReg).addReg (V8::G0).addReg (SrcReg);
Brian Gaeke6713d982004-06-17 22:34:48 +000059 return 1;
Brian Gaekee785e532004-02-25 19:28:19 +000060}
61
62void SparcV8RegisterInfo::
63eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
64 MachineBasicBlock::iterator I) const {
Brian Gaeke6c5526e2004-04-02 20:53:37 +000065 std::cerr
66 << "Sorry, I don't know how to eliminate call frame pseudo instrs yet, in\n"
67 << __FUNCTION__ << " at " << __FILE__ << ":" << __LINE__ << "\n";
Brian Gaekee785e532004-02-25 19:28:19 +000068 abort();
69}
70
71void
72SparcV8RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
73 MachineBasicBlock::iterator II) const {
Brian Gaeke6c5526e2004-04-02 20:53:37 +000074 unsigned i = 0;
75 MachineInstr &MI = *II;
76 while (!MI.getOperand(i).isFrameIndex()) {
77 ++i;
78 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
79 }
80
81 int FrameIndex = MI.getOperand(i).getFrameIndex();
82
Brian Gaeke3a8ad622004-04-06 22:10:22 +000083 // Replace frame index with a frame pointer reference
84 MI.SetMachineOperandReg (i, V8::FP);
85
86 // Addressable stack objects are accessed using neg. offsets from %fp
87 int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex) +
88 MI.getOperand(i+1).getImmedValue();
89 // note: Offset < 0
90 MI.SetMachineOperandConst (i+1, MachineOperand::MO_SignExtendedImmed, Offset);
Brian Gaekee785e532004-02-25 19:28:19 +000091}
92
Chris Lattnere1274de2004-02-29 05:18:30 +000093void SparcV8RegisterInfo::
94processFunctionBeforeFrameFinalized(MachineFunction &MF) const {}
Brian Gaekee785e532004-02-25 19:28:19 +000095
96void SparcV8RegisterInfo::emitPrologue(MachineFunction &MF) const {
Chris Lattnere1274de2004-02-29 05:18:30 +000097 MachineBasicBlock &MBB = MF.front();
Brian Gaeke6c5526e2004-04-02 20:53:37 +000098 MachineFrameInfo *MFI = MF.getFrameInfo();
Chris Lattnere1274de2004-02-29 05:18:30 +000099
Brian Gaeke6c5526e2004-04-02 20:53:37 +0000100 // Get the number of bytes to allocate from the FrameInfo
Brian Gaekeef8e48a2004-04-13 18:28:37 +0000101 int NumBytes = (int) MFI->getStackSize();
Brian Gaeke6c5526e2004-04-02 20:53:37 +0000102
103 // Emit the correct save instruction based on the number of bytes in the frame.
104 // Minimum stack frame size according to V8 ABI is:
105 // 16 words for register window spill
106 // 1 word for address of returned aggregate-value
107 // + 6 words for passing parameters on the stack
108 // ----------
109 // 23 words * 4 bytes per word = 92 bytes
110 NumBytes += 92;
Brian Gaeke6713d982004-06-17 22:34:48 +0000111 // Round up to next doubleword boundary -- a double-word boundary
112 // is required by the ABI.
113 NumBytes = (NumBytes + 7) & ~7;
Brian Gaeke6c5526e2004-04-02 20:53:37 +0000114 BuildMI(MBB, MBB.begin(), V8::SAVEri, 2,
115 V8::SP).addImm(-NumBytes).addReg(V8::SP);
Brian Gaekee785e532004-02-25 19:28:19 +0000116}
117
118void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
119 MachineBasicBlock &MBB) const {
Chris Lattnere1274de2004-02-29 05:18:30 +0000120 MachineBasicBlock::iterator MBBI = prior(MBB.end());
Brian Gaeked69b3c52004-03-06 05:31:21 +0000121 assert(MBBI->getOpcode() == V8::RETL &&
122 "Can only put epilog before 'retl' instruction!");
123 BuildMI(MBB, MBBI, V8::RESTORErr, 2, V8::G0).addReg(V8::G0).addReg(V8::G0);
Brian Gaekee785e532004-02-25 19:28:19 +0000124}
125
Brian Gaekee785e532004-02-25 19:28:19 +0000126#include "SparcV8GenRegisterInfo.inc"
127
128const TargetRegisterClass*
129SparcV8RegisterInfo::getRegClassForType(const Type* Ty) const {
Chris Lattnerf70c22b2004-06-17 18:19:28 +0000130 switch (Ty->getTypeID()) {
Brian Gaekea98e0512004-03-06 03:54:13 +0000131 case Type::FloatTyID: return &FPRegsInstance;
132 case Type::DoubleTyID: return &DFPRegsInstance;
Brian Gaekee785e532004-02-25 19:28:19 +0000133 case Type::LongTyID:
134 case Type::ULongTyID: assert(0 && "Long values can't fit in registers!");
135 default: assert(0 && "Invalid type to getClass!");
136 case Type::BoolTyID:
137 case Type::SByteTyID:
138 case Type::UByteTyID:
139 case Type::ShortTyID:
140 case Type::UShortTyID:
141 case Type::IntTyID:
142 case Type::UIntTyID:
Chris Lattner275f6452004-02-28 19:37:18 +0000143 case Type::PointerTyID: return &IntRegsInstance;
Brian Gaekee785e532004-02-25 19:28:19 +0000144 }
145}
146