Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/CodeGen/TargetFrameLoweringImpl.cpp
Line
Count
Source
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
28.0k
TargetFrameLowering::~TargetFrameLowering() = default;
32
33
/// The default implementation just looks at attribute "no-frame-pointer-elim".
34
5.28M
bool TargetFrameLowering::noFramePointerElim(const MachineFunction &MF) const {
35
5.28M
  auto Attr = MF.getFunction()->getFnAttribute("no-frame-pointer-elim");
36
5.28M
  return Attr.getValueAsString() == "true";
37
5.28M
}
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
int TargetFrameLowering::getFrameIndexReference(const MachineFunction &MF,
44
4
                                             int FI, unsigned &FrameReg) const {
45
4
  const MachineFrameInfo &MFI = MF.getFrameInfo();
46
4
  const TargetRegisterInfo *RI = MF.getSubtarget().getRegisterInfo();
47
4
48
4
  // By default, assume all frame indices are referenced via whatever
49
4
  // getFrameRegister() says. The target can override this if it's doing
50
4
  // something different.
51
4
  FrameReg = RI->getFrameRegister(MF);
52
4
53
4
  return MFI.getObjectOffset(FI) + MFI.getStackSize() -
54
4
         getOffsetOfLocalArea() + MFI.getOffsetAdjustment();
55
4
}
56
57
bool TargetFrameLowering::needsFrameIndexResolution(
58
521k
    const MachineFunction &MF) const {
59
521k
  return MF.getFrameInfo().hasStackObjects();
60
521k
}
61
62
void TargetFrameLowering::determineCalleeSaves(MachineFunction &MF,
63
                                               BitVector &SavedRegs,
64
711k
                                               RegScavenger *RS) const {
65
711k
  const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
66
711k
67
711k
  // Resize before the early returns. Some backends expect that
68
711k
  // SavedRegs.size() == TRI.getNumRegs() after this call even if there are no
69
711k
  // saved registers.
70
711k
  SavedRegs.resize(TRI.getNumRegs());
71
711k
72
711k
  // When interprocedural register allocation is enabled caller saved registers
73
711k
  // are preferred over callee saved registers.
74
711k
  if (
MF.getTarget().Options.EnableIPRA && 711k
isSafeForNoCSROpt(MF.getFunction())17
)
75
1
    return;
76
711k
77
711k
  // Get the callee saved register list...
78
711k
  const MCPhysReg *CSRegs = MF.getRegInfo().getCalleeSavedRegs();
79
711k
80
711k
  // Early exit if there are no callee saved registers.
81
711k
  if (
!CSRegs || 711k
CSRegs[0] == 0711k
)
82
17.0k
    return;
83
694k
84
694k
  // In Naked functions we aren't going to save any registers.
85
694k
  
if (694k
MF.getFunction()->hasFnAttribute(Attribute::Naked)694k
)
86
65
    return;
87
693k
88
693k
  // Functions which call __builtin_unwind_init get all their registers saved.
89
693k
  bool CallsUnwindInit = MF.callsUnwindInit();
90
693k
  const MachineRegisterInfo &MRI = MF.getRegInfo();
91
13.8M
  for (unsigned i = 0; 
CSRegs[i]13.8M
;
++i13.1M
) {
92
13.1M
    unsigned Reg = CSRegs[i];
93
13.1M
    if (
CallsUnwindInit || 13.1M
MRI.isPhysRegModified(Reg)13.1M
)
94
1.59M
      SavedRegs.set(Reg);
95
13.1M
  }
96
711k
}
97
98
unsigned TargetFrameLowering::getStackAlignmentSkew(
99
594k
    const MachineFunction &MF) const {
100
594k
  // When HHVM function is called, the stack is skewed as the return address
101
594k
  // is removed from the stack before we enter the function.
102
594k
  if (LLVM_UNLIKELY(MF.getFunction()->getCallingConv() == CallingConv::HHVM))
103
11
    return MF.getTarget().getPointerSize();
104
594k
105
594k
  return 0;
106
594k
}