Coverage Report

Created: 2018-07-12 09:57

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/MachineInstrBundle.h
Line
Count
Source (jump to first uncovered line)
1
//===-- CodeGen/MachineInstBundle.h - MI bundle utilities -------*- 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 provide utility functions to manipulate machine instruction
11
// bundles.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CODEGEN_MACHINEINSTRBUNDLE_H
16
#define LLVM_CODEGEN_MACHINEINSTRBUNDLE_H
17
18
#include "llvm/CodeGen/MachineBasicBlock.h"
19
20
namespace llvm {
21
22
/// finalizeBundle - Finalize a machine instruction bundle which includes
23
/// a sequence of instructions starting from FirstMI to LastMI (exclusive).
24
/// This routine adds a BUNDLE instruction to represent the bundle, it adds
25
/// IsInternalRead markers to MachineOperands which are defined inside the
26
/// bundle, and it copies externally visible defs and uses to the BUNDLE
27
/// instruction.
28
void finalizeBundle(MachineBasicBlock &MBB,
29
                    MachineBasicBlock::instr_iterator FirstMI,
30
                    MachineBasicBlock::instr_iterator LastMI);
31
32
/// finalizeBundle - Same functionality as the previous finalizeBundle except
33
/// the last instruction in the bundle is not provided as an input. This is
34
/// used in cases where bundles are pre-determined by marking instructions
35
/// with 'InsideBundle' marker. It returns the MBB instruction iterator that
36
/// points to the end of the bundle.
37
MachineBasicBlock::instr_iterator finalizeBundle(MachineBasicBlock &MBB,
38
                    MachineBasicBlock::instr_iterator FirstMI);
39
40
/// finalizeBundles - Finalize instruction bundles in the specified
41
/// MachineFunction. Return true if any bundles are finalized.
42
bool finalizeBundles(MachineFunction &MF);
43
44
/// Returns an iterator to the first instruction in the bundle containing \p I.
45
inline MachineBasicBlock::instr_iterator getBundleStart(
46
61.2M
    MachineBasicBlock::instr_iterator I) {
47
61.2M
  while (I->isBundledWithPred())
48
8
    --I;
49
61.2M
  return I;
50
61.2M
}
51
52
/// Returns an iterator to the first instruction in the bundle containing \p I.
53
inline MachineBasicBlock::const_instr_iterator getBundleStart(
54
143M
    MachineBasicBlock::const_instr_iterator I) {
55
143M
  while (I->isBundledWithPred())
56
1.51k
    --I;
57
143M
  return I;
58
143M
}
59
60
/// Returns an iterator pointing beyond the bundle containing \p I.
61
inline MachineBasicBlock::instr_iterator getBundleEnd(
62
171
    MachineBasicBlock::instr_iterator I) {
63
171
  while (I->isBundledWithSucc())
64
0
    ++I;
65
171
  return ++I;
66
171
}
67
68
/// Returns an iterator pointing beyond the bundle containing \p I.
69
inline MachineBasicBlock::const_instr_iterator getBundleEnd(
70
0
    MachineBasicBlock::const_instr_iterator I) {
71
0
  while (I->isBundledWithSucc())
72
0
    ++I;
73
0
  return ++I;
74
0
}
75
76
//===----------------------------------------------------------------------===//
77
// MachineOperand iterator
78
//
79
80
/// MachineOperandIteratorBase - Iterator that can visit all operands on a
81
/// MachineInstr, or all operands on a bundle of MachineInstrs.  This class is
82
/// not intended to be used directly, use one of the sub-classes instead.
83
///
84
/// Intended use:
85
///
86
///   for (MIBundleOperands MIO(MI); MIO.isValid(); ++MIO) {
87
///     if (!MIO->isReg())
88
///       continue;
89
///     ...
90
///   }
91
///
92
class MachineOperandIteratorBase {
93
  MachineBasicBlock::instr_iterator InstrI, InstrE;
94
  MachineInstr::mop_iterator OpI, OpE;
95
96
  // If the operands on InstrI are exhausted, advance InstrI to the next
97
  // bundled instruction with operands.
98
270M
  void advance() {
99
270M
    while (OpI == OpE) {
100
59.3M
      // Don't advance off the basic block, or into a new bundle.
101
59.3M
      if (++InstrI == InstrE || 
!InstrI->isInsideBundle()51.7M
)
102
59.3M
        break;
103
27.8k
      OpI = InstrI->operands_begin();
104
27.8k
      OpE = InstrI->operands_end();
105
27.8k
    }
106
270M
  }
107
108
protected:
109
  /// MachineOperandIteratorBase - Create an iterator that visits all operands
110
  /// on MI, or all operands on every instruction in the bundle containing MI.
111
  ///
112
  /// @param MI The instruction to examine.
113
  /// @param WholeBundle When true, visit all operands on the entire bundle.
114
  ///
115
59.3M
  explicit MachineOperandIteratorBase(MachineInstr &MI, bool WholeBundle) {
116
59.3M
    if (WholeBundle) {
117
59.3M
      InstrI = getBundleStart(MI.getIterator());
118
59.3M
      InstrE = MI.getParent()->instr_end();
119
59.3M
    } else {
120
3.06k
      InstrI = InstrE = MI.getIterator();
121
3.06k
      ++InstrE;
122
3.06k
    }
123
59.3M
    OpI = InstrI->operands_begin();
124
59.3M
    OpE = InstrI->operands_end();
125
59.3M
    if (WholeBundle)
126
59.3M
      advance();
127
59.3M
  }
128
129
483M
  MachineOperand &deref() const { return *OpI; }
130
131
public:
132
  /// isValid - Returns true until all the operands have been visited.
133
270M
  bool isValid() const { return OpI != OpE; }
134
135
  /// Preincrement.  Move to the next operand.
136
211M
  void operator++() {
137
211M
    assert(isValid() && "Cannot advance MIOperands beyond the last operand");
138
211M
    ++OpI;
139
211M
    advance();
140
211M
  }
141
142
  /// getOperandNo - Returns the number of the current operand relative to its
143
  /// instruction.
144
  ///
145
1.17M
  unsigned getOperandNo() const {
146
1.17M
    return OpI - InstrI->operands_begin();
147
1.17M
  }
148
149
  /// VirtRegInfo - Information about a virtual register used by a set of operands.
150
  ///
151
  struct VirtRegInfo {
152
    /// Reads - One of the operands read the virtual register.  This does not
153
    /// include undef or internal use operands, see MO::readsReg().
154
    bool Reads;
155
156
    /// Writes - One of the operands writes the virtual register.
157
    bool Writes;
158
159
    /// Tied - Uses and defs must use the same register. This can be because of
160
    /// a two-address constraint, or there may be a partial redefinition of a
161
    /// sub-register.
162
    bool Tied;
163
  };
164
165
  /// Information about how a physical register Reg is used by a set of
166
  /// operands.
167
  struct PhysRegInfo {
168
    /// There is a regmask operand indicating Reg is clobbered.
169
    /// \see MachineOperand::CreateRegMask().
170
    bool Clobbered;
171
172
    /// Reg or one of its aliases is defined. The definition may only cover
173
    /// parts of the register.
174
    bool Defined;
175
    /// Reg or a super-register is defined. The definition covers the full
176
    /// register.
177
    bool FullyDefined;
178
179
    /// Reg or one of its aliases is read. The register may only be read
180
    /// partially.
181
    bool Read;
182
    /// Reg or a super-register is read. The full register is read.
183
    bool FullyRead;
184
185
    /// Either:
186
    /// - Reg is FullyDefined and all defs of reg or an overlapping
187
    ///   register are dead, or
188
    /// - Reg is completely dead because "defined" by a clobber.
189
    bool DeadDef;
190
191
    /// Reg is Defined and all defs of reg or an overlapping register are
192
    /// dead.
193
    bool PartialDeadDef;
194
195
    /// There is a use operand of reg or a super-register with kill flag set.
196
    bool Killed;
197
  };
198
199
  /// analyzeVirtReg - Analyze how the current instruction or bundle uses a
200
  /// virtual register.  This function should not be called after operator++(),
201
  /// it expects a fresh iterator.
202
  ///
203
  /// @param Reg The virtual register to analyze.
204
  /// @param Ops When set, this vector will receive an (MI, OpNum) entry for
205
  ///            each operand referring to Reg.
206
  /// @returns A filled-in RegInfo struct.
207
  VirtRegInfo analyzeVirtReg(unsigned Reg,
208
           SmallVectorImpl<std::pair<MachineInstr*, unsigned> > *Ops = nullptr);
209
210
  /// analyzePhysReg - Analyze how the current instruction or bundle uses a
211
  /// physical register.  This function should not be called after operator++(),
212
  /// it expects a fresh iterator.
213
  ///
214
  /// @param Reg The physical register to analyze.
215
  /// @returns A filled-in PhysRegInfo struct.
216
  PhysRegInfo analyzePhysReg(unsigned Reg, const TargetRegisterInfo *TRI);
217
};
218
219
/// MIOperands - Iterate over operands of a single instruction.
220
///
221
class MIOperands : public MachineOperandIteratorBase {
222
public:
223
259
  MIOperands(MachineInstr &MI) : MachineOperandIteratorBase(MI, false) {}
224
  MachineOperand &operator* () const { return deref(); }
225
  MachineOperand *operator->() const { return &deref(); }
226
};
227
228
/// ConstMIOperands - Iterate over operands of a single const instruction.
229
///
230
class ConstMIOperands : public MachineOperandIteratorBase {
231
public:
232
  ConstMIOperands(const MachineInstr &MI)
233
2.80k
      : MachineOperandIteratorBase(const_cast<MachineInstr &>(MI), false) {}
234
  const MachineOperand &operator* () const { return deref(); }
235
  const MachineOperand *operator->() const { return &deref(); }
236
};
237
238
/// MIBundleOperands - Iterate over all operands in a bundle of machine
239
/// instructions.
240
///
241
class MIBundleOperands : public MachineOperandIteratorBase {
242
public:
243
1.20M
  MIBundleOperands(MachineInstr &MI) : MachineOperandIteratorBase(MI, true) {}
244
  MachineOperand &operator* () const { return deref(); }
245
2.92M
  MachineOperand *operator->() const { return &deref(); }
246
};
247
248
/// ConstMIBundleOperands - Iterate over all operands in a const bundle of
249
/// machine instructions.
250
///
251
class ConstMIBundleOperands : public MachineOperandIteratorBase {
252
public:
253
  ConstMIBundleOperands(const MachineInstr &MI)
254
58.1M
      : MachineOperandIteratorBase(const_cast<MachineInstr &>(MI), true) {}
255
66.6M
  const MachineOperand &operator* () const { return deref(); }
256
411M
  const MachineOperand *operator->() const { return &deref(); }
257
};
258
259
} // End llvm namespace
260
261
#endif