llvm.org GIT mirror llvm / 6c5526e
Add support for many of the MRegisterInfo callbacks. Eliminating call-frame pseudo instrs and frame indices are still stubs. Flesh out the emitPrologue method based on better ABI knowledge. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12632 91177308-0d34-0410-b5e6-96231b3b80d8 Brian Gaeke 15 years ago
2 changed file(s) with 96 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
1414 #include "SparcV8RegisterInfo.h"
1515 #include "llvm/CodeGen/MachineInstrBuilder.h"
1616 #include "llvm/CodeGen/MachineFunction.h"
17 #include "llvm/CodeGen/MachineFrameInfo.h"
1718 #include "llvm/Type.h"
1819 #include "Support/STLExtras.h"
1920 using namespace llvm;
2829 unsigned SrcReg, int FrameIdx,
2930 const TargetRegisterClass *RC) const
3031 {
31 abort();
32 return -1;
32 assert (RC == SparcV8::IntRegsRegisterClass
33 && "Can only store 32-bit values to stack slots");
34 MachineInstr *I =
35 BuildMI (V8::STrm, 2).addFrameIndex (FrameIdx).addReg (SrcReg);
36 MBB.insert(MBBI, I);
37 return 1;
3338 }
3439
3540 int SparcV8RegisterInfo::loadRegFromStackSlot(
3843 unsigned DestReg, int FrameIdx,
3944 const TargetRegisterClass *RC) const
4045 {
41 abort();
42 return -1;
46 assert (RC == SparcV8::IntRegsRegisterClass
47 && "Can only load 32-bit registers from stack slots");
48 MachineInstr *I =
49 BuildMI (V8::LDmr, 2).addReg (DestReg).addFrameIndex (FrameIdx);
50 MBB.insert(MBBI, I);
51 return 1;
4352 }
4453
4554 int SparcV8RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
4655 MachineBasicBlock::iterator MBBI,
4756 unsigned DestReg, unsigned SrcReg,
4857 const TargetRegisterClass *RC) const {
49 abort();
58 assert (RC == SparcV8::IntRegsRegisterClass
59 && "Can only copy 32-bit registers");
60 MBB.insert (MBBI,
61 BuildMI (V8::ORrr, 3, DestReg).addReg (V8::G0).addReg (SrcReg));
5062 return -1;
5163 }
5264
5365 void SparcV8RegisterInfo::
5466 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
5567 MachineBasicBlock::iterator I) const {
68 std::cerr
69 << "Sorry, I don't know how to eliminate call frame pseudo instrs yet, in\n"
70 << __FUNCTION__ << " at " << __FILE__ << ":" << __LINE__ << "\n";
5671 abort();
5772 }
5873
5974 void
6075 SparcV8RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
6176 MachineBasicBlock::iterator II) const {
77 unsigned i = 0;
78 MachineInstr &MI = *II;
79 while (!MI.getOperand(i).isFrameIndex()) {
80 ++i;
81 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
82 }
83
84 int FrameIndex = MI.getOperand(i).getFrameIndex();
85
86 std::cerr
87 << "Sorry, I don't know how to eliminate frame indices yet\n"
88 << "Frame index was " << FrameIndex << ", in\n"
89 << __FUNCTION__ << "() at " << __FILE__ << ":" << __LINE__ << "\n";
6290 abort();
6391 }
6492
6795
6896 void SparcV8RegisterInfo::emitPrologue(MachineFunction &MF) const {
6997 MachineBasicBlock &MBB = MF.front();
98 MachineFrameInfo *MFI = MF.getFrameInfo();
7099
71 // Eventually this should emit the correct save instruction based on the
72 // number of bytes in the frame. For now we just hardcode it.
73 BuildMI(MBB, MBB.begin(), V8::SAVEri, 2, V8::SP).addImm(-112).addReg(V8::SP);
100 // Get the number of bytes to allocate from the FrameInfo
101 int NumBytes = (int) MFI->getStackSize();
102
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;
111 NumBytes = (NumBytes + 3) & ~3; // Round up to next word boundary
112 BuildMI(MBB, MBB.begin(), V8::SAVEri, 2,
113 V8::SP).addImm(-NumBytes).addReg(V8::SP);
74114 }
75115
76116 void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
80120 "Can only put epilog before 'retl' instruction!");
81121 BuildMI(MBB, MBBI, V8::RESTORErr, 2, V8::G0).addReg(V8::G0).addReg(V8::G0);
82122 }
83
84123
85124 #include "SparcV8GenRegisterInfo.inc"
86125
1414 #include "SparcV8RegisterInfo.h"
1515 #include "llvm/CodeGen/MachineInstrBuilder.h"
1616 #include "llvm/CodeGen/MachineFunction.h"
17 #include "llvm/CodeGen/MachineFrameInfo.h"
1718 #include "llvm/Type.h"
1819 #include "Support/STLExtras.h"
1920 using namespace llvm;
2829 unsigned SrcReg, int FrameIdx,
2930 const TargetRegisterClass *RC) const
3031 {
31 abort();
32 return -1;
32 assert (RC == SparcV8::IntRegsRegisterClass
33 && "Can only store 32-bit values to stack slots");
34 MachineInstr *I =
35 BuildMI (V8::STrm, 2).addFrameIndex (FrameIdx).addReg (SrcReg);
36 MBB.insert(MBBI, I);
37 return 1;
3338 }
3439
3540 int SparcV8RegisterInfo::loadRegFromStackSlot(
3843 unsigned DestReg, int FrameIdx,
3944 const TargetRegisterClass *RC) const
4045 {
41 abort();
42 return -1;
46 assert (RC == SparcV8::IntRegsRegisterClass
47 && "Can only load 32-bit registers from stack slots");
48 MachineInstr *I =
49 BuildMI (V8::LDmr, 2).addReg (DestReg).addFrameIndex (FrameIdx);
50 MBB.insert(MBBI, I);
51 return 1;
4352 }
4453
4554 int SparcV8RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
4655 MachineBasicBlock::iterator MBBI,
4756 unsigned DestReg, unsigned SrcReg,
4857 const TargetRegisterClass *RC) const {
49 abort();
58 assert (RC == SparcV8::IntRegsRegisterClass
59 && "Can only copy 32-bit registers");
60 MBB.insert (MBBI,
61 BuildMI (V8::ORrr, 3, DestReg).addReg (V8::G0).addReg (SrcReg));
5062 return -1;
5163 }
5264
5365 void SparcV8RegisterInfo::
5466 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
5567 MachineBasicBlock::iterator I) const {
68 std::cerr
69 << "Sorry, I don't know how to eliminate call frame pseudo instrs yet, in\n"
70 << __FUNCTION__ << " at " << __FILE__ << ":" << __LINE__ << "\n";
5671 abort();
5772 }
5873
5974 void
6075 SparcV8RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
6176 MachineBasicBlock::iterator II) const {
77 unsigned i = 0;
78 MachineInstr &MI = *II;
79 while (!MI.getOperand(i).isFrameIndex()) {
80 ++i;
81 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
82 }
83
84 int FrameIndex = MI.getOperand(i).getFrameIndex();
85
86 std::cerr
87 << "Sorry, I don't know how to eliminate frame indices yet\n"
88 << "Frame index was " << FrameIndex << ", in\n"
89 << __FUNCTION__ << "() at " << __FILE__ << ":" << __LINE__ << "\n";
6290 abort();
6391 }
6492
6795
6896 void SparcV8RegisterInfo::emitPrologue(MachineFunction &MF) const {
6997 MachineBasicBlock &MBB = MF.front();
98 MachineFrameInfo *MFI = MF.getFrameInfo();
7099
71 // Eventually this should emit the correct save instruction based on the
72 // number of bytes in the frame. For now we just hardcode it.
73 BuildMI(MBB, MBB.begin(), V8::SAVEri, 2, V8::SP).addImm(-112).addReg(V8::SP);
100 // Get the number of bytes to allocate from the FrameInfo
101 int NumBytes = (int) MFI->getStackSize();
102
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;
111 NumBytes = (NumBytes + 3) & ~3; // Round up to next word boundary
112 BuildMI(MBB, MBB.begin(), V8::SAVEri, 2,
113 V8::SP).addImm(-NumBytes).addReg(V8::SP);
74114 }
75115
76116 void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
80120 "Can only put epilog before 'retl' instruction!");
81121 BuildMI(MBB, MBBI, V8::RESTORErr, 2, V8::G0).addReg(V8::G0).addReg(V8::G0);
82122 }
83
84123
85124 #include "SparcV8GenRegisterInfo.inc"
86125