LLVM: lib/Target/Sparc/SparcFrameLowering.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

25

26using namespace llvm;

27

31 cl::desc("Disable Sparc leaf procedure optimization."),

33

39

40void SparcFrameLowering::emitSPAdjustment(MachineFunction &MF,

43 int NumBytes,

44 unsigned ADDrr,

45 unsigned ADDri) const {

46

50

51 if (NumBytes >= -4096 && NumBytes < 4096) {

54 return;

55 }

56

57

58

59 if (NumBytes >= 0) {

60

61

62

63

70 return ;

71 }

72

73

74

75

76

83}

84

88

89 assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");

93

94

96

97 unsigned SAVEri = SP::SAVEri;

98 unsigned SAVErr = SP::SAVErr;

100 if (NumBytes == 0)

101 return;

102 SAVEri = SP::ADDri;

103 SAVErr = SP::ADDrr;

104 }

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

124

125

126

128

129

130

132

133

135

136 emitSPAdjustment(MF, MBB, MBBI, -NumBytes, SAVErr, SAVEri);

137

143 }

144}

145

151 int Size = MI.getOperand(0).getImm();

152 if (MI.getOpcode() == SP::ADJCALLSTACKDOWN)

154

156 emitSPAdjustment(MF, MBB, I, Size, SP::ADDrr, SP::ADDri);

157 }

158 return MBB.erase(I);

159}

160

161

169 assert((MBBI->getOpcode() == SP::RETL || MBBI->getOpcode() == SP::TAIL_CALL ||

170 MBBI->getOpcode() == SP::TAIL_CALLri) &&

171 "Can only put epilog before 'retl' or 'tail_call' instruction!");

175 return;

176 }

178

180 if (NumBytes != 0)

181 emitSPAdjustment(MF, MBB, MBBI, NumBytes, SP::ADDrr, SP::ADDri);

182

183

184 if (MBBI->getOpcode() == SP::TAIL_CALL) {

185 MBB.addLiveIn(SP::O7);

192 }

193}

194

199

200

201

202

208

216 bool isFixed = MFI.isFixedObjectIndex(FI);

217

218

219

220 bool UseFP;

221

222

223

224

226

227

228 UseFP = false;

229 } else if (isFixed) {

230

231 UseFP = true;

232 } else {

233

234 UseFP = true;

235 }

236

239

240 if (UseFP) {

241 FrameReg = RegInfo->getFrameRegister(MF);

243 } else {

244 FrameReg = SP::O6;

246 }

247}

248

250

251 for (unsigned reg = SP::I0; reg <= SP::I7; ++reg)

252 if (MRI->isPhysRegUsed(reg))

253 return false;

254

255 for (unsigned reg = SP::L0; reg <= SP::L7; ++reg)

256 if (MRI->isPhysRegUsed(reg))

257 return false;

258

259 return true;

260}

261

262bool SparcFrameLowering::isLeafProc(MachineFunction &MF) const

263{

264

267

268 return !(MFI.hasCalls()

269 || MRI.isPhysRegUsed(SP::L0)

270 || MRI.isPhysRegUsed(SP::O6)

271 || hasFP(MF)

272 || MF.hasInlineAsm());

273}

274

275void SparcFrameLowering::remapRegsForLeafProc(MachineFunction &MF) const {

277

278 for (unsigned reg = SP::I0; reg <= SP::I7; ++reg) {

279 if (MRI.isPhysRegUsed(reg))

280 continue;

281

282 unsigned mapped_reg = reg - SP::I0 + SP::O0;

283

284

285 MRI.replaceRegWith(reg, mapped_reg);

286

287

288 if ((reg - SP::I0) % 2 == 0) {

289 unsigned preg = (reg - SP::I0) / 2 + SP::I0_I1;

290 unsigned mapped_preg = preg - SP::I0_I1 + SP::O0_O1;

291 MRI.replaceRegWith(preg, mapped_preg);

292 }

293 }

294

295

296 for (MachineBasicBlock &MBB : MF) {

297 for (unsigned reg = SP::I0_I1; reg <= SP::I6_I7; ++reg) {

299 continue;

302 }

303 for (unsigned reg = SP::I0; reg <= SP::I7; ++reg) {

305 continue;

308 }

309 }

310

312#ifdef EXPENSIVE_CHECKS

313 MF.verify(0, "After LeafProc Remapping");

314#endif

315}

316

324

325 remapRegsForLeafProc(MF);

326 }

327

328}

unsigned const MachineRegisterInfo * MRI

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

const TargetInstrInfo & TII

MachineBasicBlock MachineBasicBlock::iterator MBBI

static cl::opt< bool > DisableLeafProc("disable-sparc-leaf-proc", cl::init(false), cl::desc("Disable Sparc leaf procedure optimization."), cl::Hidden)

static bool verifyLeafProcRegUse(MachineRegisterInfo *MRI)

Definition SparcFrameLowering.cpp:249

static bool is64Bit(const char *name)

Helper class for creating CFI instructions and inserting them into MIR.

void buildWindowSave() const

void buildRegister(MCRegister Reg1, MCRegister Reg2) const

void buildDefCFARegister(MCRegister Reg) const

const MCInstrDesc & get(unsigned Opcode) const

Return the machine instruction descriptor that corresponds to the specified instruction opcode.

LLVM_ABI void removeLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll())

Remove the specified register from the live in set.

void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())

Adds the specified register as a live in.

MachineInstrBundleIterator< MachineInstr > iterator

LLVM_ABI bool isLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const

Return true if the specified register is in the live in set.

The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.

bool hasVarSizedObjects() const

This method may be called any time after instruction selection is complete to determine if the stack ...

uint64_t getStackSize() const

Return the number of bytes that must be allocated to hold all of the fixed size frame objects.

bool adjustsStack() const

Return true if this function adjusts the stack – e.g., when calling another function.

bool hasCalls() const

Return true if the current function has any function calls.

bool isFrameAddressTaken() const

This method may be called any time after instruction selection is complete to determine if there is a...

Align getMaxAlign() const

Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...

uint64_t getMaxCallFrameSize() const

Return the maximum size of a call frame that must be allocated for an outgoing function call.

int64_t getObjectOffset(int ObjectIdx) const

Return the assigned stack offset of the specified object from the incoming stack pointer.

void setStackSize(uint64_t Size)

Set the size of the stack.

const TargetSubtargetInfo & getSubtarget() const

getSubtarget - Return the subtarget for which this machine code is being compiled.

bool hasInlineAsm() const

Returns true if the function contains any inline assembly.

bool needsFrameMoves() const

True if this function needs frame moves for debug or exceptions.

MachineFrameInfo & getFrameInfo()

getFrameInfo - Return the frame info object for the current function.

MachineRegisterInfo & getRegInfo()

getRegInfo - Return information about the registers currently in use.

Ty * getInfo()

getInfo - Keep track of various per-function pieces of information for backends that would like to do...

const MachineBasicBlock & front() const

const TargetMachine & getTarget() const

getTarget - Return the target machine this machine code is compiled with

const MachineInstrBuilder & addImm(int64_t Val) const

Add a new immediate operand.

const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const

Add a new virtual register operand.

Representation of each machine instruction.

MachineRegisterInfo - Keep track of information for virtual and physical registers,...

Wrapper class representing virtual and physical registers.

void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override

emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.

Definition SparcFrameLowering.cpp:85

SparcFrameLowering(const SparcSubtarget &ST)

Definition SparcFrameLowering.cpp:34

void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override

Definition SparcFrameLowering.cpp:162

void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override

This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...

Definition SparcFrameLowering.cpp:317

bool hasFPImpl(const MachineFunction &MF) const override

Definition SparcFrameLowering.cpp:203

StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override

getFrameIndexReference - This method should return the base register and offset used to reference a f...

Definition SparcFrameLowering.cpp:210

MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override

This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...

Definition SparcFrameLowering.cpp:147

bool hasReservedCallFrame(const MachineFunction &MF) const override

hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...

Definition SparcFrameLowering.cpp:195

void setLeafProc(bool rhs)

const SparcRegisterInfo * getRegisterInfo() const override

int64_t getStackPointerBias() const

The 64-bit ABI uses biased stack and frame pointers, so the stack frame of the current function is th...

int getAdjustedFrameSize(int stackSize) const

Given a actual stack size as determined by FrameInfo, this function returns adjusted framesize which ...

StackOffset holds a fixed and a scalable offset in bytes.

int64_t getFixed() const

Returns the fixed component of the stack.

bool hasFP(const MachineFunction &MF) const

hasFP - Return true if the specified function should have a dedicated frame pointer register.

virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const

This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...

TargetFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl=Align(1), bool StackReal=true)

LLVM_ABI bool DisableFramePointerElim(const MachineFunction &MF) const

DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...

initializer< Ty > init(const Ty &Val)

This is an optimization pass for GlobalISel generic memory operations.

MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)

Builder interface. Specify how to create the initial instruction itself.

static unsigned HI22(int64_t imm)

static unsigned HIX22(int64_t imm)

static unsigned LOX10(int64_t imm)

uint64_t alignTo(uint64_t Size, Align A)

Returns a multiple of A needed to store Size bytes.

static unsigned LO10(int64_t imm)

This struct is a compact representation of a valid (non-zero power of two) alignment.