Coverage Report

Created: 2018-07-18 22:01

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/LiveRegUnits.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/CodeGen/LiveRegUnits.h - Register Unit Set ----------*- C++ -*-===//
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
/// \file
11
/// A set of register units. It is intended for register liveness tracking.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CODEGEN_LIVEREGUNITS_H
16
#define LLVM_CODEGEN_LIVEREGUNITS_H
17
18
#include "llvm/ADT/BitVector.h"
19
#include "llvm/CodeGen/MachineRegisterInfo.h"
20
#include "llvm/CodeGen/TargetRegisterInfo.h"
21
#include "llvm/MC/LaneBitmask.h"
22
#include "llvm/MC/MCRegisterInfo.h"
23
#include <cstdint>
24
25
namespace llvm {
26
27
class MachineInstr;
28
class MachineBasicBlock;
29
30
/// A set of register units used to track register liveness.
31
class LiveRegUnits {
32
  const TargetRegisterInfo *TRI = nullptr;
33
  BitVector Units;
34
35
public:
36
  /// Constructs a new empty LiveRegUnits set.
37
1.03M
  LiveRegUnits() = default;
38
39
  /// Constructs and initialize an empty LiveRegUnits set.
40
345k
  LiveRegUnits(const TargetRegisterInfo &TRI) {
41
345k
    init(TRI);
42
345k
  }
43
44
  /// For a machine instruction \p MI, adds all register units used in
45
  /// \p UsedRegUnits and defined or clobbered in \p ModifiedRegUnits. This is
46
  /// useful when walking over a range of instructions to track registers
47
  /// used or defined seperately.
48
  static void accumulateUsedDefed(const MachineInstr &MI,
49
                                  LiveRegUnits &ModifiedRegUnits,
50
                                  LiveRegUnits &UsedRegUnits,
51
21.3M
                                  const TargetRegisterInfo *TRI) {
52
95.8M
    for (ConstMIBundleOperands O(MI); O.isValid(); 
++O74.4M
) {
53
74.4M
      if (O->isRegMask())
54
612k
        ModifiedRegUnits.addRegsInMask(O->getRegMask());
55
74.4M
      if (!O->isReg())
56
24.5M
        continue;
57
49.8M
      unsigned Reg = O->getReg();
58
49.8M
      if (!TargetRegisterInfo::isPhysicalRegister(Reg))
59
537k
        continue;
60
49.3M
      if (O->isDef()) {
61
19.2M
        // Some architectures (e.g. AArch64 XZR/WZR) have registers that are
62
19.2M
        // constant and may be used as destinations to indicate the generated
63
19.2M
        // value is discarded. No need to track such case as a def.
64
19.2M
        if (!TRI->isConstantPhysReg(Reg))
65
17.7M
          ModifiedRegUnits.addReg(Reg);
66
30.0M
      } else {
67
30.0M
        assert(O->isUse() && "Reg operand not a def and not a use");
68
30.0M
        UsedRegUnits.addReg(Reg);
69
30.0M
      }
70
49.3M
    }
71
21.3M
    return;
72
21.3M
  }
73
74
  /// Initialize and clear the set.
75
2.79M
  void init(const TargetRegisterInfo &TRI) {
76
2.79M
    this->TRI = &TRI;
77
2.79M
    Units.reset();
78
2.79M
    Units.resize(TRI.getNumRegUnits());
79
2.79M
  }
80
81
  /// Clears the set.
82
14.6M
  void clear() { Units.reset(); }
83
84
  /// Returns true if the set is empty.
85
38.2k
  bool empty() const { return Units.none(); }
86
87
  /// Adds register units covered by physical register \p Reg.
88
48.8M
  void addReg(unsigned Reg) {
89
99.3M
    for (MCRegUnitIterator Unit(Reg, TRI); Unit.isValid(); 
++Unit50.4M
)
90
50.4M
      Units.set(*Unit);
91
48.8M
  }
92
93
  /// Adds register units covered by physical register \p Reg that are
94
  /// part of the lanemask \p Mask.
95
1.65M
  void addRegMasked(unsigned Reg, LaneBitmask Mask) {
96
3.61M
    for (MCRegUnitMaskIterator Unit(Reg, TRI); Unit.isValid(); 
++Unit1.96M
) {
97
1.96M
      LaneBitmask UnitMask = (*Unit).second;
98
1.96M
      if (UnitMask.none() || 
(UnitMask & Mask).any()1.64M
)
99
1.96M
        Units.set((*Unit).first);
100
1.96M
    }
101
1.65M
  }
102
103
  /// Removes all register units covered by physical register \p Reg.
104
682k
  void removeReg(unsigned Reg) {
105
1.39M
    for (MCRegUnitIterator Unit(Reg, TRI); Unit.isValid(); 
++Unit707k
)
106
707k
      Units.reset(*Unit);
107
682k
  }
108
109
  /// Removes register units not preserved by the regmask \p RegMask.
110
  /// The regmask has the same format as the one in the RegMask machine operand.
111
  void removeRegsNotPreserved(const uint32_t *RegMask);
112
113
  /// Adds register units not preserved by the regmask \p RegMask.
114
  /// The regmask has the same format as the one in the RegMask machine operand.
115
  void addRegsInMask(const uint32_t *RegMask);
116
117
  /// Returns true if no part of physical register \p Reg is live.
118
25.6M
  bool available(unsigned Reg) const {
119
48.3M
    for (MCRegUnitIterator Unit(Reg, TRI); Unit.isValid(); 
++Unit22.6M
) {
120
25.8M
      if (Units.test(*Unit))
121
3.24M
        return false;
122
25.8M
    }
123
25.6M
    
return true22.4M
;
124
25.6M
  }
125
126
  /// Updates liveness when stepping backwards over the instruction \p MI.
127
  /// This removes all register units defined or clobbered in \p MI and then
128
  /// adds the units used (as in use operands) in \p MI.
129
  void stepBackward(const MachineInstr &MI);
130
131
  /// Adds all register units used, defined or clobbered in \p MI.
132
  /// This is useful when walking over a range of instruction to find registers
133
  /// unused over the whole range.
134
  void accumulate(const MachineInstr &MI);
135
136
  /// Adds registers living out of block \p MBB.
137
  /// Live out registers are the union of the live-in registers of the successor
138
  /// blocks and pristine registers. Live out registers of the end block are the
139
  /// callee saved registers.
140
  void addLiveOuts(const MachineBasicBlock &MBB);
141
142
  /// Adds registers living into block \p MBB.
143
  void addLiveIns(const MachineBasicBlock &MBB);
144
145
  /// Adds all register units marked in the bitvector \p RegUnits.
146
5.11k
  void addUnits(const BitVector &RegUnits) {
147
5.11k
    Units |= RegUnits;
148
5.11k
  }
149
  /// Removes all register units marked in the bitvector \p RegUnits.
150
5.11k
  void removeUnits(const BitVector &RegUnits) {
151
5.11k
    Units.reset(RegUnits);
152
5.11k
  }
153
  /// Return the internal bitvector representation of the set.
154
0
  const BitVector &getBitVector() const {
155
0
    return Units;
156
0
  }
157
158
private:
159
  /// Adds pristine registers. Pristine registers are callee saved registers
160
  /// that are unused in the function.
161
  void addPristines(const MachineFunction &MF);
162
};
163
164
} // end namespace llvm
165
166
#endif // LLVM_CODEGEN_LIVEREGUNITS_H