Coverage Report

Created: 2018-09-17 19:50

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/VirtRegMap.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/CodeGen/VirtRegMap.h - Virtual Register Map ---------*- 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
// This file implements a virtual register map. This maps virtual registers to
11
// physical registers and virtual registers to stack slots. It is created and
12
// updated by a register allocator and then used by a machine code rewriter that
13
// adds spill code and rewrites virtual into physical register references.
14
//
15
//===----------------------------------------------------------------------===//
16
17
#ifndef LLVM_CODEGEN_VIRTREGMAP_H
18
#define LLVM_CODEGEN_VIRTREGMAP_H
19
20
#include "llvm/ADT/IndexedMap.h"
21
#include "llvm/CodeGen/MachineFunctionPass.h"
22
#include "llvm/CodeGen/TargetRegisterInfo.h"
23
#include "llvm/MC/MCRegisterInfo.h"
24
#include "llvm/Pass.h"
25
#include <cassert>
26
27
namespace llvm {
28
29
class MachineFunction;
30
class MachineRegisterInfo;
31
class raw_ostream;
32
class TargetInstrInfo;
33
34
  class VirtRegMap : public MachineFunctionPass {
35
  public:
36
    enum {
37
      NO_PHYS_REG = 0,
38
      NO_STACK_SLOT = (1L << 30)-1,
39
      MAX_STACK_SLOT = (1L << 18)-1
40
    };
41
42
  private:
43
    MachineRegisterInfo *MRI;
44
    const TargetInstrInfo *TII;
45
    const TargetRegisterInfo *TRI;
46
    MachineFunction *MF;
47
48
    /// Virt2PhysMap - This is a virtual to physical register
49
    /// mapping. Each virtual register is required to have an entry in
50
    /// it; even spilled virtual registers (the register mapped to a
51
    /// spilled register is the temporary used to load it from the
52
    /// stack).
53
    IndexedMap<unsigned, VirtReg2IndexFunctor> Virt2PhysMap;
54
55
    /// Virt2StackSlotMap - This is virtual register to stack slot
56
    /// mapping. Each spilled virtual register has an entry in it
57
    /// which corresponds to the stack slot this register is spilled
58
    /// at.
59
    IndexedMap<int, VirtReg2IndexFunctor> Virt2StackSlotMap;
60
61
    /// Virt2SplitMap - This is virtual register to splitted virtual register
62
    /// mapping.
63
    IndexedMap<unsigned, VirtReg2IndexFunctor> Virt2SplitMap;
64
65
    /// createSpillSlot - Allocate a spill slot for RC from MFI.
66
    unsigned createSpillSlot(const TargetRegisterClass *RC);
67
68
  public:
69
    static char ID;
70
71
    VirtRegMap() : MachineFunctionPass(ID), Virt2PhysMap(NO_PHYS_REG),
72
30.9k
                   Virt2StackSlotMap(NO_STACK_SLOT), Virt2SplitMap(0) {}
73
    VirtRegMap(const VirtRegMap &) = delete;
74
    VirtRegMap &operator=(const VirtRegMap &) = delete;
75
76
    bool runOnMachineFunction(MachineFunction &MF) override;
77
78
30.9k
    void getAnalysisUsage(AnalysisUsage &AU) const override {
79
30.9k
      AU.setPreservesAll();
80
30.9k
      MachineFunctionPass::getAnalysisUsage(AU);
81
30.9k
    }
82
83
16.3M
    MachineFunction &getMachineFunction() const {
84
16.3M
      assert(MF && "getMachineFunction called before runOnMachineFunction");
85
16.3M
      return *MF;
86
16.3M
    }
87
88
455k
    MachineRegisterInfo &getRegInfo() const { return *MRI; }
89
11.7M
    const TargetRegisterInfo &getTargetRegInfo() const { return *TRI; }
90
91
    void grow();
92
93
    /// returns true if the specified virtual register is
94
    /// mapped to a physical register
95
2.73M
    bool hasPhys(unsigned virtReg) const {
96
2.73M
      return getPhys(virtReg) != NO_PHYS_REG;
97
2.73M
    }
98
99
    /// returns the physical register mapped to the specified
100
    /// virtual register
101
42.5M
    unsigned getPhys(unsigned virtReg) const {
102
42.5M
      assert(TargetRegisterInfo::isVirtualRegister(virtReg));
103
42.5M
      return Virt2PhysMap[virtReg];
104
42.5M
    }
105
106
    /// creates a mapping for the specified virtual register to
107
    /// the specified physical register
108
    void assignVirt2Phys(unsigned virtReg, MCPhysReg physReg);
109
110
    /// clears the specified virtual register's, physical
111
    /// register mapping
112
500k
    void clearVirt(unsigned virtReg) {
113
500k
      assert(TargetRegisterInfo::isVirtualRegister(virtReg));
114
500k
      assert(Virt2PhysMap[virtReg] != NO_PHYS_REG &&
115
500k
             "attempt to clear a not assigned virtual register");
116
500k
      Virt2PhysMap[virtReg] = NO_PHYS_REG;
117
500k
    }
118
119
    /// clears all virtual to physical register mappings
120
455k
    void clearAllVirt() {
121
455k
      Virt2PhysMap.clear();
122
455k
      grow();
123
455k
    }
124
125
    /// returns true if VirtReg is assigned to its preferred physreg.
126
    bool hasPreferredPhys(unsigned VirtReg);
127
128
    /// returns true if VirtReg has a known preferred register.
129
    /// This returns false if VirtReg has a preference that is a virtual
130
    /// register that hasn't been assigned yet.
131
    bool hasKnownPreference(unsigned VirtReg);
132
133
    /// records virtReg is a split live interval from SReg.
134
794k
    void setIsSplitFromReg(unsigned virtReg, unsigned SReg) {
135
794k
      Virt2SplitMap[virtReg] = SReg;
136
794k
    }
137
138
    /// returns the live interval virtReg is split from.
139
25.1M
    unsigned getPreSplitReg(unsigned virtReg) const {
140
25.1M
      return Virt2SplitMap[virtReg];
141
25.1M
    }
142
143
    /// getOriginal - Return the original virtual register that VirtReg descends
144
    /// from through splitting.
145
    /// A register that was not created by splitting is its own original.
146
    /// This operation is idempotent.
147
8.63M
    unsigned getOriginal(unsigned VirtReg) const {
148
8.63M
      unsigned Orig = getPreSplitReg(VirtReg);
149
8.63M
      return Orig ? 
Orig2.16M
:
VirtReg6.47M
;
150
8.63M
    }
151
152
    /// returns true if the specified virtual register is not
153
    /// mapped to a stack slot or rematerialized.
154
417
    bool isAssignedReg(unsigned virtReg) const {
155
417
      if (getStackSlot(virtReg) == NO_STACK_SLOT)
156
401
        return true;
157
16
      // Split register can be assigned a physical register as well as a
158
16
      // stack slot or remat id.
159
16
      return (Virt2SplitMap[virtReg] && 
Virt2PhysMap[virtReg] != NO_PHYS_REG10
);
160
16
    }
161
162
    /// returns the stack slot mapped to the specified virtual
163
    /// register
164
270k
    int getStackSlot(unsigned virtReg) const {
165
270k
      assert(TargetRegisterInfo::isVirtualRegister(virtReg));
166
270k
      return Virt2StackSlotMap[virtReg];
167
270k
    }
168
169
    /// create a mapping for the specifed virtual register to
170
    /// the next available stack slot
171
    int assignVirt2StackSlot(unsigned virtReg);
172
173
    /// create a mapping for the specified virtual register to
174
    /// the specified stack slot
175
    void assignVirt2StackSlot(unsigned virtReg, int SS);
176
177
    void print(raw_ostream &OS, const Module* M = nullptr) const override;
178
    void dump() const;
179
  };
180
181
0
  inline raw_ostream &operator<<(raw_ostream &OS, const VirtRegMap &VRM) {
182
0
    VRM.print(OS);
183
0
    return OS;
184
0
  }
185
186
} // end llvm namespace
187
188
#endif // LLVM_CODEGEN_VIRTREGMAP_H