2011-12-16 06:58:58 +08:00
|
|
|
//===----- TargetFrameLoweringImpl.cpp - Implement target frame interface --==//
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2004-03-12 07:52:43 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2004-03-12 07:52:43 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Implements the layout of a stack frame on the target machine.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-07-15 01:17:13 +08:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetFrameLowering.h"
|
2010-11-21 00:14:57 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2015-07-15 01:17:13 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2015-05-23 09:14:08 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
2010-11-20 23:59:32 +08:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2014-08-05 05:25:23 +08:00
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
2004-03-12 07:52:43 +08:00
|
|
|
#include <cstdlib>
|
|
|
|
using namespace llvm;
|
|
|
|
|
2011-01-10 20:39:04 +08:00
|
|
|
TargetFrameLowering::~TargetFrameLowering() {
|
2005-02-18 05:40:27 +08:00
|
|
|
}
|
2010-11-19 07:25:52 +08:00
|
|
|
|
2015-05-23 09:14:08 +08:00
|
|
|
/// The default implementation just looks at attribute "no-frame-pointer-elim".
|
|
|
|
bool TargetFrameLowering::noFramePointerElim(const MachineFunction &MF) const {
|
|
|
|
auto Attr = MF.getFunction()->getFnAttribute("no-frame-pointer-elim");
|
|
|
|
return Attr.getValueAsString() == "true";
|
|
|
|
}
|
|
|
|
|
2010-11-20 23:59:32 +08:00
|
|
|
/// getFrameIndexOffset - Returns the displacement from the frame register to
|
|
|
|
/// the stack frame of the specified index. This is the default implementation
|
|
|
|
/// which is overridden for some targets.
|
2011-01-10 20:39:04 +08:00
|
|
|
int TargetFrameLowering::getFrameIndexOffset(const MachineFunction &MF,
|
2014-10-14 15:22:08 +08:00
|
|
|
int FI) const {
|
2010-11-20 23:59:32 +08:00
|
|
|
const MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
return MFI->getObjectOffset(FI) + MFI->getStackSize() -
|
|
|
|
getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
|
|
|
|
}
|
|
|
|
|
2011-01-10 20:39:04 +08:00
|
|
|
int TargetFrameLowering::getFrameIndexReference(const MachineFunction &MF,
|
|
|
|
int FI, unsigned &FrameReg) const {
|
2014-08-05 10:39:49 +08:00
|
|
|
const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo();
|
2010-11-20 23:59:32 +08:00
|
|
|
|
|
|
|
// By default, assume all frame indices are referenced via whatever
|
|
|
|
// getFrameRegister() says. The target can override this if it's doing
|
|
|
|
// something different.
|
|
|
|
FrameReg = RI->getFrameRegister(MF);
|
|
|
|
return getFrameIndexOffset(MF, FI);
|
|
|
|
}
|
2015-02-02 00:56:04 +08:00
|
|
|
|
|
|
|
bool TargetFrameLowering::needsFrameIndexResolution(
|
|
|
|
const MachineFunction &MF) const {
|
|
|
|
return MF.getFrameInfo()->hasStackObjects();
|
|
|
|
}
|
2015-07-15 01:17:13 +08:00
|
|
|
|
|
|
|
void TargetFrameLowering::determineCalleeSaves(MachineFunction &MF,
|
|
|
|
BitVector &SavedRegs,
|
|
|
|
RegScavenger *RS) const {
|
|
|
|
// Get the callee saved register list...
|
|
|
|
const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
|
|
|
|
const MCPhysReg *CSRegs = TRI.getCalleeSavedRegs(&MF);
|
|
|
|
|
|
|
|
// Early exit if there are no callee saved registers.
|
|
|
|
if (!CSRegs || CSRegs[0] == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SavedRegs.resize(TRI.getNumRegs());
|
|
|
|
|
|
|
|
// In Naked functions we aren't going to save any registers.
|
|
|
|
if (MF.getFunction()->hasFnAttribute(Attribute::Naked))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Functions which call __builtin_unwind_init get all their registers saved.
|
|
|
|
bool CallsUnwindInit = MF.getMMI().callsUnwindInit();
|
|
|
|
const MachineRegisterInfo &MRI = MF.getRegInfo();
|
|
|
|
for (unsigned i = 0; CSRegs[i]; ++i) {
|
|
|
|
unsigned Reg = CSRegs[i];
|
|
|
|
if (CallsUnwindInit || MRI.isPhysRegModified(Reg))
|
|
|
|
SavedRegs.set(Reg);
|
|
|
|
}
|
|
|
|
}
|