• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  //===----- TargetFrameLowering.cpp - Implement target frame interface ------==//
2  //
3  //                     The LLVM Compiler Infrastructure
4  //
5  // This file is distributed under the University of Illinois Open Source
6  // License. See LICENSE.TXT for details.
7  //
8  //===----------------------------------------------------------------------===//
9  //
10  // Implements the layout of a stack frame on the target machine.
11  //
12  //===----------------------------------------------------------------------===//
13  
14  #include "llvm/CodeGen/MachineFrameInfo.h"
15  #include "llvm/CodeGen/MachineFunction.h"
16  #include "llvm/Target/TargetFrameLowering.h"
17  #include "llvm/Target/TargetMachine.h"
18  #include "llvm/Target/TargetRegisterInfo.h"
19  
20  #include <cstdlib>
21  using namespace llvm;
22  
~TargetFrameLowering()23  TargetFrameLowering::~TargetFrameLowering() {
24  }
25  
26  /// getFrameIndexOffset - Returns the displacement from the frame register to
27  /// the stack frame of the specified index. This is the default implementation
28  /// which is overridden for some targets.
getFrameIndexOffset(const MachineFunction & MF,int FI) const29  int TargetFrameLowering::getFrameIndexOffset(const MachineFunction &MF,
30                                           int FI) const {
31    const MachineFrameInfo *MFI = MF.getFrameInfo();
32    return MFI->getObjectOffset(FI) + MFI->getStackSize() -
33      getOffsetOfLocalArea() + MFI->getOffsetAdjustment();
34  }
35  
getFrameIndexReference(const MachineFunction & MF,int FI,unsigned & FrameReg) const36  int TargetFrameLowering::getFrameIndexReference(const MachineFunction &MF,
37                                               int FI, unsigned &FrameReg) const {
38    const TargetRegisterInfo *RI = MF.getTarget().getRegisterInfo();
39  
40    // By default, assume all frame indices are referenced via whatever
41    // getFrameRegister() says. The target can override this if it's doing
42    // something different.
43    FrameReg = RI->getFrameRegister(MF);
44    return getFrameIndexOffset(MF, FI);
45  }
46