comparison lib/Target/Mips/Mips16FrameLowering.cpp @ 120:1172e4bd9c6f

update 4.0.0
author mir3636
date Fri, 25 Nov 2016 19:14:25 +0900
parents 7d135dc70f03
children 803732b1fca8
comparison
equal deleted inserted replaced
101:34baf5011add 120:1172e4bd9c6f
22 #include "llvm/CodeGen/MachineInstrBuilder.h" 22 #include "llvm/CodeGen/MachineInstrBuilder.h"
23 #include "llvm/CodeGen/MachineModuleInfo.h" 23 #include "llvm/CodeGen/MachineModuleInfo.h"
24 #include "llvm/CodeGen/MachineRegisterInfo.h" 24 #include "llvm/CodeGen/MachineRegisterInfo.h"
25 #include "llvm/IR/DataLayout.h" 25 #include "llvm/IR/DataLayout.h"
26 #include "llvm/IR/Function.h" 26 #include "llvm/IR/Function.h"
27 #include "llvm/Support/CommandLine.h"
28 #include "llvm/Target/TargetOptions.h" 27 #include "llvm/Target/TargetOptions.h"
29 28
30 using namespace llvm; 29 using namespace llvm;
31 30
32 Mips16FrameLowering::Mips16FrameLowering(const MipsSubtarget &STI) 31 Mips16FrameLowering::Mips16FrameLowering(const MipsSubtarget &STI)
33 : MipsFrameLowering(STI, STI.stackAlignment()) {} 32 : MipsFrameLowering(STI, STI.stackAlignment()) {}
34 33
35 void Mips16FrameLowering::emitPrologue(MachineFunction &MF, 34 void Mips16FrameLowering::emitPrologue(MachineFunction &MF,
36 MachineBasicBlock &MBB) const { 35 MachineBasicBlock &MBB) const {
37 assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported"); 36 assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
38 MachineFrameInfo *MFI = MF.getFrameInfo(); 37 MachineFrameInfo &MFI = MF.getFrameInfo();
39 const Mips16InstrInfo &TII = 38 const Mips16InstrInfo &TII =
40 *static_cast<const Mips16InstrInfo *>(STI.getInstrInfo()); 39 *static_cast<const Mips16InstrInfo *>(STI.getInstrInfo());
41 MachineBasicBlock::iterator MBBI = MBB.begin(); 40 MachineBasicBlock::iterator MBBI = MBB.begin();
42 41
43 // Debug location must be unknown since the first debug location is used 42 // Debug location must be unknown since the first debug location is used
44 // to determine the end of the prologue. 43 // to determine the end of the prologue.
45 DebugLoc dl; 44 DebugLoc dl;
46 45
47 uint64_t StackSize = MFI->getStackSize(); 46 uint64_t StackSize = MFI.getStackSize();
48 47
49 // No need to allocate space on the stack. 48 // No need to allocate space on the stack.
50 if (StackSize == 0 && !MFI->adjustsStack()) return; 49 if (StackSize == 0 && !MFI.adjustsStack()) return;
51 50
52 MachineModuleInfo &MMI = MF.getMMI(); 51 MachineModuleInfo &MMI = MF.getMMI();
53 const MCRegisterInfo *MRI = MMI.getContext().getRegisterInfo(); 52 const MCRegisterInfo *MRI = MMI.getContext().getRegisterInfo();
54 MachineLocation DstML, SrcML; 53 MachineLocation DstML, SrcML;
55 54
60 unsigned CFIIndex = MMI.addFrameInst( 59 unsigned CFIIndex = MMI.addFrameInst(
61 MCCFIInstruction::createDefCfaOffset(nullptr, -StackSize)); 60 MCCFIInstruction::createDefCfaOffset(nullptr, -StackSize));
62 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION)) 61 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
63 .addCFIIndex(CFIIndex); 62 .addCFIIndex(CFIIndex);
64 63
65 const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo(); 64 const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
66 65
67 if (CSI.size()) { 66 if (CSI.size()) {
68 const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo(); 67 const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
69 68
70 for (std::vector<CalleeSavedInfo>::const_iterator I = CSI.begin(), 69 for (std::vector<CalleeSavedInfo>::const_iterator I = CSI.begin(),
71 E = CSI.end(); I != E; ++I) { 70 E = CSI.end(); I != E; ++I) {
72 int64_t Offset = MFI->getObjectOffset(I->getFrameIdx()); 71 int64_t Offset = MFI.getObjectOffset(I->getFrameIdx());
73 unsigned Reg = I->getReg(); 72 unsigned Reg = I->getReg();
74 unsigned DReg = MRI->getDwarfRegNum(Reg, true); 73 unsigned DReg = MRI->getDwarfRegNum(Reg, true);
75 unsigned CFIIndex = MMI.addFrameInst( 74 unsigned CFIIndex = MMI.addFrameInst(
76 MCCFIInstruction::createOffset(nullptr, DReg, Offset)); 75 MCCFIInstruction::createOffset(nullptr, DReg, Offset));
77 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION)) 76 BuildMI(MBB, MBBI, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
85 } 84 }
86 85
87 void Mips16FrameLowering::emitEpilogue(MachineFunction &MF, 86 void Mips16FrameLowering::emitEpilogue(MachineFunction &MF,
88 MachineBasicBlock &MBB) const { 87 MachineBasicBlock &MBB) const {
89 MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr(); 88 MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
90 MachineFrameInfo *MFI = MF.getFrameInfo(); 89 MachineFrameInfo &MFI = MF.getFrameInfo();
91 const Mips16InstrInfo &TII = 90 const Mips16InstrInfo &TII =
92 *static_cast<const Mips16InstrInfo *>(STI.getInstrInfo()); 91 *static_cast<const Mips16InstrInfo *>(STI.getInstrInfo());
93 DebugLoc dl = MBBI->getDebugLoc(); 92 DebugLoc dl = MBBI->getDebugLoc();
94 uint64_t StackSize = MFI->getStackSize(); 93 uint64_t StackSize = MFI.getStackSize();
95 94
96 if (!StackSize) 95 if (!StackSize)
97 return; 96 return;
98 97
99 if (hasFP(MF)) 98 if (hasFP(MF))
119 // during emitPrologue 118 // during emitPrologue
120 // 119 //
121 for (unsigned i = 0, e = CSI.size(); i != e; ++i) { 120 for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
122 // Add the callee-saved register as live-in. Do not add if the register is 121 // Add the callee-saved register as live-in. Do not add if the register is
123 // RA and return address is taken, because it has already been added in 122 // RA and return address is taken, because it has already been added in
124 // method MipsTargetLowering::LowerRETURNADDR. 123 // method MipsTargetLowering::lowerRETURNADDR.
125 // It's killed at the spill, unless the register is RA and return address 124 // It's killed at the spill, unless the register is RA and return address
126 // is taken. 125 // is taken.
127 unsigned Reg = CSI[i].getReg(); 126 unsigned Reg = CSI[i].getReg();
128 bool IsRAAndRetAddrIsTaken = (Reg == Mips::RA) 127 bool IsRAAndRetAddrIsTaken = (Reg == Mips::RA)
129 && MF->getFrameInfo()->isReturnAddressTaken(); 128 && MF->getFrameInfo().isReturnAddressTaken();
130 if (!IsRAAndRetAddrIsTaken) 129 if (!IsRAAndRetAddrIsTaken)
131 EntryBlock->addLiveIn(Reg); 130 EntryBlock->addLiveIn(Reg);
132 } 131 }
133 132
134 return true; 133 return true;
148 return true; 147 return true;
149 } 148 }
150 149
151 bool 150 bool
152 Mips16FrameLowering::hasReservedCallFrame(const MachineFunction &MF) const { 151 Mips16FrameLowering::hasReservedCallFrame(const MachineFunction &MF) const {
153 const MachineFrameInfo *MFI = MF.getFrameInfo(); 152 const MachineFrameInfo &MFI = MF.getFrameInfo();
154 // Reserve call frame if the size of the maximum call frame fits into 15-bit 153 // Reserve call frame if the size of the maximum call frame fits into 15-bit
155 // immediate field and there are no variable sized objects on the stack. 154 // immediate field and there are no variable sized objects on the stack.
156 return isInt<15>(MFI->getMaxCallFrameSize()) && !MFI->hasVarSizedObjects(); 155 return isInt<15>(MFI.getMaxCallFrameSize()) && !MFI.hasVarSizedObjects();
157 } 156 }
158 157
159 void Mips16FrameLowering::determineCalleeSaves(MachineFunction &MF, 158 void Mips16FrameLowering::determineCalleeSaves(MachineFunction &MF,
160 BitVector &SavedRegs, 159 BitVector &SavedRegs,
161 RegScavenger *RS) const { 160 RegScavenger *RS) const {