LCOV - code coverage report
Current view: top level - lib/CodeGen - TargetFrameLoweringImpl.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 26 26 100.0 %
Date: 2017-09-14 15:23:50 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- TargetFrameLoweringImpl.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/ADT/BitVector.h"
      15             : #include "llvm/CodeGen/MachineFrameInfo.h"
      16             : #include "llvm/CodeGen/MachineFunction.h"
      17             : #include "llvm/CodeGen/MachineRegisterInfo.h"
      18             : #include "llvm/IR/Attributes.h"
      19             : #include "llvm/IR/CallingConv.h"
      20             : #include "llvm/IR/Function.h"
      21             : #include "llvm/MC/MCRegisterInfo.h"
      22             : #include "llvm/Support/Compiler.h"
      23             : #include "llvm/Target/TargetFrameLowering.h"
      24             : #include "llvm/Target/TargetMachine.h"
      25             : #include "llvm/Target/TargetOptions.h"
      26             : #include "llvm/Target/TargetRegisterInfo.h"
      27             : #include "llvm/Target/TargetSubtargetInfo.h"
      28             : 
      29             : using namespace llvm;
      30             : 
      31             : TargetFrameLowering::~TargetFrameLowering() = default;
      32             : 
      33             : /// The default implementation just looks at attribute "no-frame-pointer-elim".
      34     1847357 : bool TargetFrameLowering::noFramePointerElim(const MachineFunction &MF) const {
      35     3694714 :   auto Attr = MF.getFunction()->getFnAttribute("no-frame-pointer-elim");
      36     3694714 :   return Attr.getValueAsString() == "true";
      37             : }
      38             : 
      39             : /// Returns the displacement from the frame register to the stack
      40             : /// frame of the specified index, along with the frame register used
      41             : /// (in output arg FrameReg). This is the default implementation which
      42             : /// is overridden for some targets.
      43           3 : int TargetFrameLowering::getFrameIndexReference(const MachineFunction &MF,
      44             :                                              int FI, unsigned &FrameReg) const {
      45           3 :   const MachineFrameInfo &MFI = MF.getFrameInfo();
      46           3 :   const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo();
      47             : 
      48             :   // By default, assume all frame indices are referenced via whatever
      49             :   // getFrameRegister() says. The target can override this if it's doing
      50             :   // something different.
      51           3 :   FrameReg = RI->getFrameRegister(MF);
      52             : 
      53           6 :   return MFI.getObjectOffset(FI) + MFI.getStackSize() -
      54           6 :          getOffsetOfLocalArea() + MFI.getOffsetAdjustment();
      55             : }
      56             : 
      57       70627 : bool TargetFrameLowering::needsFrameIndexResolution(
      58             :     const MachineFunction &MF) const {
      59      141254 :   return MF.getFrameInfo().hasStackObjects();
      60             : }
      61             : 
      62      142409 : void TargetFrameLowering::determineCalleeSaves(MachineFunction &MF,
      63             :                                                BitVector &SavedRegs,
      64             :                                                RegScavenger *RS) const {
      65      142409 :   const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
      66             : 
      67             :   // Resize before the early returns. Some backends expect that
      68             :   // SavedRegs.size() == TRI.getNumRegs() after this call even if there are no
      69             :   // saved registers.
      70      142409 :   SavedRegs.resize(TRI.getNumRegs());
      71             : 
      72             :   // When interprocedural register allocation is enabled caller saved registers
      73             :   // are preferred over callee saved registers.
      74      142409 :   if (MF.getTarget().Options.EnableIPRA && isSafeForNoCSROpt(MF.getFunction()))
      75             :     return;
      76             : 
      77             :   // Get the callee saved register list...
      78      142408 :   const MCPhysReg *CSRegs = MF.getRegInfo().getCalleeSavedRegs();
      79             : 
      80             :   // Early exit if there are no callee saved registers.
      81      142408 :   if (!CSRegs || CSRegs[0] == 0)
      82             :     return;
      83             : 
      84             :   // In Naked functions we aren't going to save any registers.
      85      250834 :   if (MF.getFunction()->hasFnAttribute(Attribute::Naked))
      86             :     return;
      87             : 
      88             :   // Functions which call __builtin_unwind_init get all their registers saved.
      89      125352 :   bool CallsUnwindInit = MF.callsUnwindInit();
      90      125352 :   const MachineRegisterInfo &MRI = MF.getRegInfo();
      91     1903843 :   for (unsigned i = 0; CSRegs[i]; ++i) {
      92     1778491 :     unsigned Reg = CSRegs[i];
      93     1778491 :     if (CallsUnwindInit || MRI.isPhysRegModified(Reg))
      94             :       SavedRegs.set(Reg);
      95             :   }
      96             : }
      97             : 
      98      141269 : unsigned TargetFrameLowering::getStackAlignmentSkew(
      99             :     const MachineFunction &MF) const {
     100             :   // When HHVM function is called, the stack is skewed as the return address
     101             :   // is removed from the stack before we enter the function.
     102      282538 :   if (LLVM_UNLIKELY(MF.getFunction()->getCallingConv() == CallingConv::HHVM))
     103          22 :     return MF.getTarget().getPointerSize();
     104             : 
     105             :   return 0;
     106             : }

Generated by: LCOV version 1.13