Coverage Report

Created: 2018-07-18 22:01

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/MachineInstrBuilder.h
Line
Count
Source (jump to first uncovered line)
1
//===- CodeGen/MachineInstrBuilder.h - Simplify creation of MIs --*- 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 exposes a function named BuildMI, which is useful for dramatically
11
// simplifying how MachineInstr's are created.  It allows use of code like this:
12
//
13
//   M = BuildMI(MBB, MI, DL, TII.get(X86::ADD8rr), Dst)
14
//           .addReg(argVal1)
15
//           .addReg(argVal2);
16
//
17
//===----------------------------------------------------------------------===//
18
19
#ifndef LLVM_CODEGEN_MACHINEINSTRBUILDER_H
20
#define LLVM_CODEGEN_MACHINEINSTRBUILDER_H
21
22
#include "llvm/ADT/ArrayRef.h"
23
#include "llvm/CodeGen/GlobalISel/Utils.h"
24
#include "llvm/CodeGen/MachineBasicBlock.h"
25
#include "llvm/CodeGen/MachineFunction.h"
26
#include "llvm/CodeGen/MachineInstr.h"
27
#include "llvm/CodeGen/MachineInstrBundle.h"
28
#include "llvm/CodeGen/MachineOperand.h"
29
#include "llvm/CodeGen/TargetRegisterInfo.h"
30
#include "llvm/IR/InstrTypes.h"
31
#include "llvm/IR/Intrinsics.h"
32
#include "llvm/Support/ErrorHandling.h"
33
#include <cassert>
34
#include <cstdint>
35
#include <utility>
36
37
namespace llvm {
38
39
class MCInstrDesc;
40
class MDNode;
41
42
namespace RegState {
43
44
  enum {
45
    Define         = 0x2,
46
    Implicit       = 0x4,
47
    Kill           = 0x8,
48
    Dead           = 0x10,
49
    Undef          = 0x20,
50
    EarlyClobber   = 0x40,
51
    Debug          = 0x80,
52
    InternalRead   = 0x100,
53
    Renamable      = 0x200,
54
    DefineNoRead   = Define | Undef,
55
    ImplicitDefine = Implicit | Define,
56
    ImplicitKill   = Implicit | Kill
57
  };
58
59
} // end namespace RegState
60
61
class MachineInstrBuilder {
62
  MachineFunction *MF = nullptr;
63
  MachineInstr *MI = nullptr;
64
65
public:
66
2.42M
  MachineInstrBuilder() = default;
67
68
  /// Create a MachineInstrBuilder for manipulating an existing instruction.
69
  /// F must be the machine function that was used to allocate I.
70
69.9M
  MachineInstrBuilder(MachineFunction &F, MachineInstr *I) : MF(&F), MI(I) {}
71
  MachineInstrBuilder(MachineFunction &F, MachineBasicBlock::iterator I)
72
743k
      : MF(&F), MI(&*I) {}
73
74
  /// Allow automatic conversion to the machine instruction we are working on.
75
61.2M
  operator MachineInstr*() const { return MI; }
76
22.7M
  MachineInstr *operator->() const { return MI; }
77
62.2k
  operator MachineBasicBlock::iterator() const { return MI; }
78
79
  /// If conversion operators fail, use this method to get the MachineInstr
80
  /// explicitly.
81
9.80M
  MachineInstr *getInstr() const { return MI; }
82
83
  /// Add a new virtual register operand.
84
  const MachineInstrBuilder &addReg(unsigned RegNo, unsigned flags = 0,
85
99.8M
                                    unsigned SubReg = 0) const {
86
99.8M
    assert((flags & 0x1) == 0 &&
87
99.8M
           "Passing in 'true' to addReg is forbidden! Use enums instead.");
88
99.8M
    MI->addOperand(*MF, MachineOperand::CreateReg(RegNo,
89
99.8M
                                               flags & RegState::Define,
90
99.8M
                                               flags & RegState::Implicit,
91
99.8M
                                               flags & RegState::Kill,
92
99.8M
                                               flags & RegState::Dead,
93
99.8M
                                               flags & RegState::Undef,
94
99.8M
                                               flags & RegState::EarlyClobber,
95
99.8M
                                               SubReg,
96
99.8M
                                               flags & RegState::Debug,
97
99.8M
                                               flags & RegState::InternalRead,
98
99.8M
                                               flags & RegState::Renamable));
99
99.8M
    return *this;
100
99.8M
  }
101
102
  /// Add a virtual register definition operand.
103
  const MachineInstrBuilder &addDef(unsigned RegNo, unsigned Flags = 0,
104
18.3M
                                    unsigned SubReg = 0) const {
105
18.3M
    return addReg(RegNo, Flags | RegState::Define, SubReg);
106
18.3M
  }
107
108
  /// Add a virtual register use operand. It is an error for Flags to contain
109
  /// `RegState::Define` when calling this function.
110
  const MachineInstrBuilder &addUse(unsigned RegNo, unsigned Flags = 0,
111
27.5M
                                    unsigned SubReg = 0) const {
112
27.5M
    assert(!(Flags & RegState::Define) &&
113
27.5M
           "Misleading addUse defines register, use addReg instead.");
114
27.5M
    return addReg(RegNo, Flags, SubReg);
115
27.5M
  }
116
117
  /// Add a new immediate operand.
118
32.8M
  const MachineInstrBuilder &addImm(int64_t Val) const {
119
32.8M
    MI->addOperand(*MF, MachineOperand::CreateImm(Val));
120
32.8M
    return *this;
121
32.8M
  }
122
123
1.88M
  const MachineInstrBuilder &addCImm(const ConstantInt *Val) const {
124
1.88M
    MI->addOperand(*MF, MachineOperand::CreateCImm(Val));
125
1.88M
    return *this;
126
1.88M
  }
127
128
30.2k
  const MachineInstrBuilder &addFPImm(const ConstantFP *Val) const {
129
30.2k
    MI->addOperand(*MF, MachineOperand::CreateFPImm(Val));
130
30.2k
    return *this;
131
30.2k
  }
132
133
  const MachineInstrBuilder &addMBB(MachineBasicBlock *MBB,
134
15.8M
                                    unsigned char TargetFlags = 0) const {
135
15.8M
    MI->addOperand(*MF, MachineOperand::CreateMBB(MBB, TargetFlags));
136
15.8M
    return *this;
137
15.8M
  }
138
139
1.21M
  const MachineInstrBuilder &addFrameIndex(int Idx) const {
140
1.21M
    MI->addOperand(*MF, MachineOperand::CreateFI(Idx));
141
1.21M
    return *this;
142
1.21M
  }
143
144
  const MachineInstrBuilder &addConstantPoolIndex(unsigned Idx,
145
                                                  int Offset = 0,
146
145k
                                          unsigned char TargetFlags = 0) const {
147
145k
    MI->addOperand(*MF, MachineOperand::CreateCPI(Idx, Offset, TargetFlags));
148
145k
    return *this;
149
145k
  }
150
151
  const MachineInstrBuilder &addTargetIndex(unsigned Idx, int64_t Offset = 0,
152
0
                                          unsigned char TargetFlags = 0) const {
153
0
    MI->addOperand(*MF, MachineOperand::CreateTargetIndex(Idx, Offset,
154
0
                                                          TargetFlags));
155
0
    return *this;
156
0
  }
157
158
  const MachineInstrBuilder &addJumpTableIndex(unsigned Idx,
159
5.26k
                                          unsigned char TargetFlags = 0) const {
160
5.26k
    MI->addOperand(*MF, MachineOperand::CreateJTI(Idx, TargetFlags));
161
5.26k
    return *this;
162
5.26k
  }
163
164
  const MachineInstrBuilder &addGlobalAddress(const GlobalValue *GV,
165
                                              int64_t Offset = 0,
166
2.64M
                                          unsigned char TargetFlags = 0) const {
167
2.64M
    MI->addOperand(*MF, MachineOperand::CreateGA(GV, Offset, TargetFlags));
168
2.64M
    return *this;
169
2.64M
  }
170
171
  const MachineInstrBuilder &addExternalSymbol(const char *FnName,
172
51.3k
                                          unsigned char TargetFlags = 0) const {
173
51.3k
    MI->addOperand(*MF, MachineOperand::CreateES(FnName, TargetFlags));
174
51.3k
    return *this;
175
51.3k
  }
176
177
  const MachineInstrBuilder &addBlockAddress(const BlockAddress *BA,
178
                                             int64_t Offset = 0,
179
140
                                          unsigned char TargetFlags = 0) const {
180
140
    MI->addOperand(*MF, MachineOperand::CreateBA(BA, Offset, TargetFlags));
181
140
    return *this;
182
140
  }
183
184
1.98M
  const MachineInstrBuilder &addRegMask(const uint32_t *Mask) const {
185
1.98M
    MI->addOperand(*MF, MachineOperand::CreateRegMask(Mask));
186
1.98M
    return *this;
187
1.98M
  }
188
189
5.61M
  const MachineInstrBuilder &addMemOperand(MachineMemOperand *MMO) const {
190
5.61M
    MI->addMemOperand(*MF, MMO);
191
5.61M
    return *this;
192
5.61M
  }
193
194
  const MachineInstrBuilder &setMemRefs(MachineInstr::mmo_iterator b,
195
10.8M
                                        MachineInstr::mmo_iterator e) const {
196
10.8M
    MI->setMemRefs(b, e);
197
10.8M
    return *this;
198
10.8M
  }
199
200
  const MachineInstrBuilder &setMemRefs(std::pair<MachineInstr::mmo_iterator,
201
245k
                                        unsigned> MemOperandsRef) const {
202
245k
    MI->setMemRefs(MemOperandsRef);
203
245k
    return *this;
204
245k
  }
205
206
17.7M
  const MachineInstrBuilder &add(const MachineOperand &MO) const {
207
17.7M
    MI->addOperand(*MF, MO);
208
17.7M
    return *this;
209
17.7M
  }
210
211
291k
  const MachineInstrBuilder &add(ArrayRef<MachineOperand> MOs) const {
212
582k
    for (const MachineOperand &MO : MOs) {
213
582k
      MI->addOperand(*MF, MO);
214
582k
    }
215
291k
    return *this;
216
291k
  }
217
218
13.0k
  const MachineInstrBuilder &addMetadata(const MDNode *MD) const {
219
13.0k
    MI->addOperand(*MF, MachineOperand::CreateMetadata(MD));
220
13.0k
    assert((MI->isDebugValue() ? static_cast<bool>(MI->getDebugVariable())
221
13.0k
                               : true) &&
222
13.0k
           "first MDNode argument of a DBG_VALUE not a variable");
223
13.0k
    assert((MI->isDebugLabel() ? static_cast<bool>(MI->getDebugLabel())
224
13.0k
                               : true) &&
225
13.0k
           "first MDNode argument of a DBG_LABEL not a label");
226
13.0k
    return *this;
227
13.0k
  }
228
229
472k
  const MachineInstrBuilder &addCFIIndex(unsigned CFIIndex) const {
230
472k
    MI->addOperand(*MF, MachineOperand::CreateCFIIndex(CFIIndex));
231
472k
    return *this;
232
472k
  }
233
234
161k
  const MachineInstrBuilder &addIntrinsicID(Intrinsic::ID ID) const {
235
161k
    MI->addOperand(*MF, MachineOperand::CreateIntrinsicID(ID));
236
161k
    return *this;
237
161k
  }
238
239
1.07M
  const MachineInstrBuilder &addPredicate(CmpInst::Predicate Pred) const {
240
1.07M
    MI->addOperand(*MF, MachineOperand::CreatePredicate(Pred));
241
1.07M
    return *this;
242
1.07M
  }
243
244
  const MachineInstrBuilder &addSym(MCSymbol *Sym,
245
101k
                                    unsigned char TargetFlags = 0) const {
246
101k
    MI->addOperand(*MF, MachineOperand::CreateMCSymbol(Sym, TargetFlags));
247
101k
    return *this;
248
101k
  }
249
250
1.15M
  const MachineInstrBuilder &setMIFlags(unsigned Flags) const {
251
1.15M
    MI->setFlags(Flags);
252
1.15M
    return *this;
253
1.15M
  }
254
255
1.97M
  const MachineInstrBuilder &setMIFlag(MachineInstr::MIFlag Flag) const {
256
1.97M
    MI->setFlag(Flag);
257
1.97M
    return *this;
258
1.97M
  }
259
260
  // Add a displacement from an existing MachineOperand with an added offset.
261
  const MachineInstrBuilder &addDisp(const MachineOperand &Disp, int64_t off,
262
53
                                     unsigned char TargetFlags = 0) const {
263
53
    // If caller specifies new TargetFlags then use it, otherwise the
264
53
    // default behavior is to copy the target flags from the existing
265
53
    // MachineOperand. This means if the caller wants to clear the
266
53
    // target flags it needs to do so explicitly.
267
53
    if (0 == TargetFlags)
268
53
      TargetFlags = Disp.getTargetFlags();
269
53
270
53
    switch (Disp.getType()) {
271
53
      default:
272
0
        llvm_unreachable("Unhandled operand type in addDisp()");
273
53
      case MachineOperand::MO_Immediate:
274
29
        return addImm(Disp.getImm() + off);
275
53
      case MachineOperand::MO_ConstantPoolIndex:
276
6
        return addConstantPoolIndex(Disp.getIndex(), Disp.getOffset() + off,
277
6
                                    TargetFlags);
278
53
      case MachineOperand::MO_GlobalAddress:
279
18
        return addGlobalAddress(Disp.getGlobal(), Disp.getOffset() + off,
280
18
                                TargetFlags);
281
53
    }
282
53
  }
283
284
  /// Copy all the implicit operands from OtherMI onto this one.
285
  const MachineInstrBuilder &
286
10.1k
  copyImplicitOps(const MachineInstr &OtherMI) const {
287
10.1k
    MI->copyImplicitOps(*MF, OtherMI);
288
10.1k
    return *this;
289
10.1k
  }
290
291
  bool constrainAllUses(const TargetInstrInfo &TII,
292
                        const TargetRegisterInfo &TRI,
293
69.4k
                        const RegisterBankInfo &RBI) const {
294
69.4k
    return constrainSelectedInstRegOperands(*MI, TII, TRI, RBI);
295
69.4k
  }
296
};
297
298
/// Builder interface. Specify how to create the initial instruction itself.
299
inline MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
300
33.8M
                                   const MCInstrDesc &MCID) {
301
33.8M
  return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, DL));
302
33.8M
}
303
304
/// This version of the builder sets up the first operand as a
305
/// destination virtual register.
306
inline MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
307
561k
                                   const MCInstrDesc &MCID, unsigned DestReg) {
308
561k
  return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, DL))
309
561k
           .addReg(DestReg, RegState::Define);
310
561k
}
311
312
/// This version of the builder inserts the newly-built instruction before
313
/// the given position in the given MachineBasicBlock, and sets up the first
314
/// operand as a destination virtual register.
315
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
316
                                   MachineBasicBlock::iterator I,
317
                                   const DebugLoc &DL, const MCInstrDesc &MCID,
318
14.4M
                                   unsigned DestReg) {
319
14.4M
  MachineFunction &MF = *BB.getParent();
320
14.4M
  MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
321
14.4M
  BB.insert(I, MI);
322
14.4M
  return MachineInstrBuilder(MF, MI).addReg(DestReg, RegState::Define);
323
14.4M
}
324
325
/// This version of the builder inserts the newly-built instruction before
326
/// the given position in the given MachineBasicBlock, and sets up the first
327
/// operand as a destination virtual register.
328
///
329
/// If \c I is inside a bundle, then the newly inserted \a MachineInstr is
330
/// added to the same bundle.
331
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
332
                                   MachineBasicBlock::instr_iterator I,
333
                                   const DebugLoc &DL, const MCInstrDesc &MCID,
334
10.2k
                                   unsigned DestReg) {
335
10.2k
  MachineFunction &MF = *BB.getParent();
336
10.2k
  MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
337
10.2k
  BB.insert(I, MI);
338
10.2k
  return MachineInstrBuilder(MF, MI).addReg(DestReg, RegState::Define);
339
10.2k
}
340
341
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineInstr &I,
342
                                   const DebugLoc &DL, const MCInstrDesc &MCID,
343
421k
                                   unsigned DestReg) {
344
421k
  // Calling the overload for instr_iterator is always correct.  However, the
345
421k
  // definition is not available in headers, so inline the check.
346
421k
  if (I.isInsideBundle())
347
0
    return BuildMI(BB, MachineBasicBlock::instr_iterator(I), DL, MCID, DestReg);
348
421k
  return BuildMI(BB, MachineBasicBlock::iterator(I), DL, MCID, DestReg);
349
421k
}
350
351
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineInstr *I,
352
                                   const DebugLoc &DL, const MCInstrDesc &MCID,
353
367k
                                   unsigned DestReg) {
354
367k
  return BuildMI(BB, *I, DL, MCID, DestReg);
355
367k
}
356
357
/// This version of the builder inserts the newly-built instruction before the
358
/// given position in the given MachineBasicBlock, and does NOT take a
359
/// destination register.
360
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
361
                                   MachineBasicBlock::iterator I,
362
                                   const DebugLoc &DL,
363
18.1M
                                   const MCInstrDesc &MCID) {
364
18.1M
  MachineFunction &MF = *BB.getParent();
365
18.1M
  MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
366
18.1M
  BB.insert(I, MI);
367
18.1M
  return MachineInstrBuilder(MF, MI);
368
18.1M
}
369
370
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
371
                                   MachineBasicBlock::instr_iterator I,
372
                                   const DebugLoc &DL,
373
44.7k
                                   const MCInstrDesc &MCID) {
374
44.7k
  MachineFunction &MF = *BB.getParent();
375
44.7k
  MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
376
44.7k
  BB.insert(I, MI);
377
44.7k
  return MachineInstrBuilder(MF, MI);
378
44.7k
}
379
380
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineInstr &I,
381
                                   const DebugLoc &DL,
382
3.56M
                                   const MCInstrDesc &MCID) {
383
3.56M
  // Calling the overload for instr_iterator is always correct.  However, the
384
3.56M
  // definition is not available in headers, so inline the check.
385
3.56M
  if (I.isInsideBundle())
386
8.81k
    return BuildMI(BB, MachineBasicBlock::instr_iterator(I), DL, MCID);
387
3.55M
  return BuildMI(BB, MachineBasicBlock::iterator(I), DL, MCID);
388
3.55M
}
389
390
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineInstr *I,
391
                                   const DebugLoc &DL,
392
1.52M
                                   const MCInstrDesc &MCID) {
393
1.52M
  return BuildMI(BB, *I, DL, MCID);
394
1.52M
}
395
396
/// This version of the builder inserts the newly-built instruction at the end
397
/// of the given MachineBasicBlock, and does NOT take a destination register.
398
inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, const DebugLoc &DL,
399
9.11M
                                   const MCInstrDesc &MCID) {
400
9.11M
  return BuildMI(*BB, BB->end(), DL, MCID);
401
9.11M
}
402
403
/// This version of the builder inserts the newly-built instruction at the
404
/// end of the given MachineBasicBlock, and sets up the first operand as a
405
/// destination virtual register.
406
inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, const DebugLoc &DL,
407
436k
                                   const MCInstrDesc &MCID, unsigned DestReg) {
408
436k
  return BuildMI(*BB, BB->end(), DL, MCID, DestReg);
409
436k
}
410
411
/// This version of the builder builds a DBG_VALUE intrinsic
412
/// for either a value in a register or a register-indirect
413
/// address.  The convention is that a DBG_VALUE is indirect iff the
414
/// second operand is an immediate.
415
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
416
                            const MCInstrDesc &MCID, bool IsIndirect,
417
                            unsigned Reg, const MDNode *Variable,
418
                            const MDNode *Expr);
419
420
/// This version of the builder builds a DBG_VALUE intrinsic
421
/// for a MachineOperand.
422
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
423
                            const MCInstrDesc &MCID, bool IsIndirect,
424
                            MachineOperand &MO, const MDNode *Variable,
425
                            const MDNode *Expr);
426
427
/// This version of the builder builds a DBG_VALUE intrinsic
428
/// for either a value in a register or a register-indirect
429
/// address and inserts it at position I.
430
MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
431
                            MachineBasicBlock::iterator I, const DebugLoc &DL,
432
                            const MCInstrDesc &MCID, bool IsIndirect,
433
                            unsigned Reg, const MDNode *Variable,
434
                            const MDNode *Expr);
435
436
/// This version of the builder builds a DBG_VALUE intrinsic
437
/// for a machine operand and inserts it at position I.
438
MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
439
                            MachineBasicBlock::iterator I, const DebugLoc &DL,
440
                            const MCInstrDesc &MCID, bool IsIndirect,
441
                            MachineOperand &MO, const MDNode *Variable,
442
                            const MDNode *Expr);
443
444
/// Clone a DBG_VALUE whose value has been spilled to FrameIndex.
445
MachineInstr *buildDbgValueForSpill(MachineBasicBlock &BB,
446
                                    MachineBasicBlock::iterator I,
447
                                    const MachineInstr &Orig, int FrameIndex);
448
449
/// Update a DBG_VALUE whose value has been spilled to FrameIndex. Useful when
450
/// modifying an instruction in place while iterating over a basic block.
451
void updateDbgValueForSpill(MachineInstr &Orig, int FrameIndex);
452
453
9.63M
inline unsigned getDefRegState(bool B) {
454
9.63M
  return B ? 
RegState::Define1.74M
:
07.88M
;
455
9.63M
}
456
4.56M
inline unsigned getImplRegState(bool B) {
457
4.56M
  return B ? 
RegState::Implicit1.99M
:
02.57M
;
458
4.56M
}
459
11.9M
inline unsigned getKillRegState(bool B) {
460
11.9M
  return B ? 
RegState::Kill4.94M
:
07.03M
;
461
11.9M
}
462
765k
inline unsigned getDeadRegState(bool B) {
463
765k
  return B ? 
RegState::Dead36.4k
:
0729k
;
464
765k
}
465
159k
inline unsigned getUndefRegState(bool B) {
466
159k
  return B ? 
RegState::Undef6.84k
:
0152k
;
467
159k
}
468
6.74k
inline unsigned getInternalReadRegState(bool B) {
469
6.74k
  return B ? 
RegState::InternalRead11
:
06.72k
;
470
6.74k
}
471
7.87M
inline unsigned getDebugRegState(bool B) {
472
7.87M
  return B ? 
RegState::Debug307
:
07.87M
;
473
7.87M
}
474
1.66k
inline unsigned getRenamableRegState(bool B) {
475
1.66k
  return B ? 
RegState::Renamable242
:
01.42k
;
476
1.66k
}
477
478
/// Get all register state flags from machine operand \p RegOp.
479
1.66k
inline unsigned getRegState(const MachineOperand &RegOp) {
480
1.66k
  assert(RegOp.isReg() && "Not a register operand");
481
1.66k
  return getDefRegState(RegOp.isDef())                    |
482
1.66k
         getImplRegState(RegOp.isImplicit())              |
483
1.66k
         getKillRegState(RegOp.isKill())                  |
484
1.66k
         getDeadRegState(RegOp.isDead())                  |
485
1.66k
         getUndefRegState(RegOp.isUndef())                |
486
1.66k
         getInternalReadRegState(RegOp.isInternalRead())  |
487
1.66k
         getDebugRegState(RegOp.isDebug())                |
488
1.66k
         getRenamableRegState(
489
1.66k
             TargetRegisterInfo::isPhysicalRegister(RegOp.getReg()) &&
490
1.66k
             
RegOp.isRenamable()243
);
491
1.66k
}
492
493
/// Helper class for constructing bundles of MachineInstrs.
494
///
495
/// MIBundleBuilder can create a bundle from scratch by inserting new
496
/// MachineInstrs one at a time, or it can create a bundle from a sequence of
497
/// existing MachineInstrs in a basic block.
498
class MIBundleBuilder {
499
  MachineBasicBlock &MBB;
500
  MachineBasicBlock::instr_iterator Begin;
501
  MachineBasicBlock::instr_iterator End;
502
503
public:
504
  /// Create an MIBundleBuilder that inserts instructions into a new bundle in
505
  /// BB above the bundle or instruction at Pos.
506
  MIBundleBuilder(MachineBasicBlock &BB, MachineBasicBlock::iterator Pos)
507
570
      : MBB(BB), Begin(Pos.getInstrIterator()), End(Begin) {}
508
509
  /// Create a bundle from the sequence of instructions between B and E.
510
  MIBundleBuilder(MachineBasicBlock &BB, MachineBasicBlock::iterator B,
511
                  MachineBasicBlock::iterator E)
512
51.2k
      : MBB(BB), Begin(B.getInstrIterator()), End(E.getInstrIterator()) {
513
51.2k
    assert(B != E && "No instructions to bundle");
514
51.2k
    ++B;
515
119k
    while (B != E) {
516
68.6k
      MachineInstr &MI = *B;
517
68.6k
      ++B;
518
68.6k
      MI.bundleWithPred();
519
68.6k
    }
520
51.2k
  }
521
522
  /// Create an MIBundleBuilder representing an existing instruction or bundle
523
  /// that has MI as its head.
524
  explicit MIBundleBuilder(MachineInstr *MI)
525
      : MBB(*MI->getParent()), Begin(MI),
526
171
        End(getBundleEnd(MI->getIterator())) {}
527
528
  /// Return a reference to the basic block containing this bundle.
529
  MachineBasicBlock &getMBB() const { return MBB; }
530
531
  /// Return true if no instructions have been inserted in this bundle yet.
532
  /// Empty bundles aren't representable in a MachineBasicBlock.
533
36.0k
  bool empty() const { return Begin == End; }
534
535
  /// Return an iterator to the first bundled instruction.
536
35.9k
  MachineBasicBlock::instr_iterator begin() const { return Begin; }
537
538
  /// Return an iterator beyond the last bundled instruction.
539
1.83k
  MachineBasicBlock::instr_iterator end() const { return End; }
540
541
  /// Insert MI into this bundle before I which must point to an instruction in
542
  /// the bundle, or end().
543
  MIBundleBuilder &insert(MachineBasicBlock::instr_iterator I,
544
37.3k
                          MachineInstr *MI) {
545
37.3k
    MBB.insert(I, MI);
546
37.3k
    if (I == Begin) {
547
36.0k
      if (!empty())
548
35.4k
        MI->bundleWithSucc();
549
36.0k
      Begin = MI->getIterator();
550
36.0k
      return *this;
551
36.0k
    }
552
1.26k
    if (I == End) {
553
1.26k
      MI->bundleWithPred();
554
1.26k
      return *this;
555
1.26k
    }
556
0
    // MI was inserted in the middle of the bundle, so its neighbors' flags are
557
0
    // already fine. Update MI's bundle flags manually.
558
0
    MI->setFlag(MachineInstr::BundledPred);
559
0
    MI->setFlag(MachineInstr::BundledSucc);
560
0
    return *this;
561
0
  }
562
563
  /// Insert MI into MBB by prepending it to the instructions in the bundle.
564
  /// MI will become the first instruction in the bundle.
565
35.4k
  MIBundleBuilder &prepend(MachineInstr *MI) {
566
35.4k
    return insert(begin(), MI);
567
35.4k
  }
568
569
  /// Insert MI into MBB by appending it to the instructions in the bundle.
570
  /// MI will become the last instruction in the bundle.
571
1.83k
  MIBundleBuilder &append(MachineInstr *MI) {
572
1.83k
    return insert(end(), MI);
573
1.83k
  }
574
};
575
576
} // end namespace llvm
577
578
#endif // LLVM_CODEGEN_MACHINEINSTRBUILDER_H