Coverage Report

Created: 2018-09-23 03:40

/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.46M
  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
71.7M
  MachineInstrBuilder(MachineFunction &F, MachineInstr *I) : MF(&F), MI(I) {}
71
  MachineInstrBuilder(MachineFunction &F, MachineBasicBlock::iterator I)
72
751k
      : MF(&F), MI(&*I) {}
73
74
  /// Allow automatic conversion to the machine instruction we are working on.
75
62.8M
  operator MachineInstr*() const { return MI; }
76
23.2M
  MachineInstr *operator->() const { return MI; }
77
62.3k
  operator MachineBasicBlock::iterator() const { return MI; }
78
79
  /// If conversion operators fail, use this method to get the MachineInstr
80
  /// explicitly.
81
11.0M
  MachineInstr *getInstr() const { return MI; }
82
83
  /// Add a new virtual register operand.
84
  const MachineInstrBuilder &addReg(unsigned RegNo, unsigned flags = 0,
85
102M
                                    unsigned SubReg = 0) const {
86
102M
    assert((flags & 0x1) == 0 &&
87
102M
           "Passing in 'true' to addReg is forbidden! Use enums instead.");
88
102M
    MI->addOperand(*MF, MachineOperand::CreateReg(RegNo,
89
102M
                                               flags & RegState::Define,
90
102M
                                               flags & RegState::Implicit,
91
102M
                                               flags & RegState::Kill,
92
102M
                                               flags & RegState::Dead,
93
102M
                                               flags & RegState::Undef,
94
102M
                                               flags & RegState::EarlyClobber,
95
102M
                                               SubReg,
96
102M
                                               flags & RegState::Debug,
97
102M
                                               flags & RegState::InternalRead,
98
102M
                                               flags & RegState::Renamable));
99
102M
    return *this;
100
102M
  }
101
102
  /// Add a virtual register definition operand.
103
  const MachineInstrBuilder &addDef(unsigned RegNo, unsigned Flags = 0,
104
18.8M
                                    unsigned SubReg = 0) const {
105
18.8M
    return addReg(RegNo, Flags | RegState::Define, SubReg);
106
18.8M
  }
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
28.2M
                                    unsigned SubReg = 0) const {
112
28.2M
    assert(!(Flags & RegState::Define) &&
113
28.2M
           "Misleading addUse defines register, use addReg instead.");
114
28.2M
    return addReg(RegNo, Flags, SubReg);
115
28.2M
  }
116
117
  /// Add a new immediate operand.
118
33.6M
  const MachineInstrBuilder &addImm(int64_t Val) const {
119
33.6M
    MI->addOperand(*MF, MachineOperand::CreateImm(Val));
120
33.6M
    return *this;
121
33.6M
  }
122
123
1.92M
  const MachineInstrBuilder &addCImm(const ConstantInt *Val) const {
124
1.92M
    MI->addOperand(*MF, MachineOperand::CreateCImm(Val));
125
1.92M
    return *this;
126
1.92M
  }
127
128
30.5k
  const MachineInstrBuilder &addFPImm(const ConstantFP *Val) const {
129
30.5k
    MI->addOperand(*MF, MachineOperand::CreateFPImm(Val));
130
30.5k
    return *this;
131
30.5k
  }
132
133
  const MachineInstrBuilder &addMBB(MachineBasicBlock *MBB,
134
16.3M
                                    unsigned char TargetFlags = 0) const {
135
16.3M
    MI->addOperand(*MF, MachineOperand::CreateMBB(MBB, TargetFlags));
136
16.3M
    return *this;
137
16.3M
  }
138
139
1.28M
  const MachineInstrBuilder &addFrameIndex(int Idx) const {
140
1.28M
    MI->addOperand(*MF, MachineOperand::CreateFI(Idx));
141
1.28M
    return *this;
142
1.28M
  }
143
144
  const MachineInstrBuilder &addConstantPoolIndex(unsigned Idx,
145
                                                  int Offset = 0,
146
147k
                                          unsigned char TargetFlags = 0) const {
147
147k
    MI->addOperand(*MF, MachineOperand::CreateCPI(Idx, Offset, TargetFlags));
148
147k
    return *this;
149
147k
  }
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.28k
                                          unsigned char TargetFlags = 0) const {
160
5.28k
    MI->addOperand(*MF, MachineOperand::CreateJTI(Idx, TargetFlags));
161
5.28k
    return *this;
162
5.28k
  }
163
164
  const MachineInstrBuilder &addGlobalAddress(const GlobalValue *GV,
165
                                              int64_t Offset = 0,
166
2.67M
                                          unsigned char TargetFlags = 0) const {
167
2.67M
    MI->addOperand(*MF, MachineOperand::CreateGA(GV, Offset, TargetFlags));
168
2.67M
    return *this;
169
2.67M
  }
170
171
  const MachineInstrBuilder &addExternalSymbol(const char *FnName,
172
52.9k
                                          unsigned char TargetFlags = 0) const {
173
52.9k
    MI->addOperand(*MF, MachineOperand::CreateES(FnName, TargetFlags));
174
52.9k
    return *this;
175
52.9k
  }
176
177
  const MachineInstrBuilder &addBlockAddress(const BlockAddress *BA,
178
                                             int64_t Offset = 0,
179
150
                                          unsigned char TargetFlags = 0) const {
180
150
    MI->addOperand(*MF, MachineOperand::CreateBA(BA, Offset, TargetFlags));
181
150
    return *this;
182
150
  }
183
184
2.04M
  const MachineInstrBuilder &addRegMask(const uint32_t *Mask) const {
185
2.04M
    MI->addOperand(*MF, MachineOperand::CreateRegMask(Mask));
186
2.04M
    return *this;
187
2.04M
  }
188
189
5.75M
  const MachineInstrBuilder &addMemOperand(MachineMemOperand *MMO) const {
190
5.75M
    MI->addMemOperand(*MF, MMO);
191
5.75M
    return *this;
192
5.75M
  }
193
194
  const MachineInstrBuilder &
195
11.2M
  setMemRefs(ArrayRef<MachineMemOperand *> MMOs) const {
196
11.2M
    MI->setMemRefs(*MF, MMOs);
197
11.2M
    return *this;
198
11.2M
  }
199
200
14.3k
  const MachineInstrBuilder &cloneMemRefs(const MachineInstr &OtherMI) const {
201
14.3k
    MI->cloneMemRefs(*MF, OtherMI);
202
14.3k
    return *this;
203
14.3k
  }
204
205
  const MachineInstrBuilder &
206
250k
  cloneMergedMemRefs(ArrayRef<const MachineInstr *> OtherMIs) const {
207
250k
    MI->cloneMergedMemRefs(*MF, OtherMIs);
208
250k
    return *this;
209
250k
  }
210
211
18.1M
  const MachineInstrBuilder &add(const MachineOperand &MO) const {
212
18.1M
    MI->addOperand(*MF, MO);
213
18.1M
    return *this;
214
18.1M
  }
215
216
292k
  const MachineInstrBuilder &add(ArrayRef<MachineOperand> MOs) const {
217
585k
    for (const MachineOperand &MO : MOs) {
218
585k
      MI->addOperand(*MF, MO);
219
585k
    }
220
292k
    return *this;
221
292k
  }
222
223
13.2k
  const MachineInstrBuilder &addMetadata(const MDNode *MD) const {
224
13.2k
    MI->addOperand(*MF, MachineOperand::CreateMetadata(MD));
225
13.2k
    assert((MI->isDebugValue() ? static_cast<bool>(MI->getDebugVariable())
226
13.2k
                               : true) &&
227
13.2k
           "first MDNode argument of a DBG_VALUE not a variable");
228
13.2k
    assert((MI->isDebugLabel() ? static_cast<bool>(MI->getDebugLabel())
229
13.2k
                               : true) &&
230
13.2k
           "first MDNode argument of a DBG_LABEL not a label");
231
13.2k
    return *this;
232
13.2k
  }
233
234
481k
  const MachineInstrBuilder &addCFIIndex(unsigned CFIIndex) const {
235
481k
    MI->addOperand(*MF, MachineOperand::CreateCFIIndex(CFIIndex));
236
481k
    return *this;
237
481k
  }
238
239
169k
  const MachineInstrBuilder &addIntrinsicID(Intrinsic::ID ID) const {
240
169k
    MI->addOperand(*MF, MachineOperand::CreateIntrinsicID(ID));
241
169k
    return *this;
242
169k
  }
243
244
1.10M
  const MachineInstrBuilder &addPredicate(CmpInst::Predicate Pred) const {
245
1.10M
    MI->addOperand(*MF, MachineOperand::CreatePredicate(Pred));
246
1.10M
    return *this;
247
1.10M
  }
248
249
  const MachineInstrBuilder &addSym(MCSymbol *Sym,
250
126k
                                    unsigned char TargetFlags = 0) const {
251
126k
    MI->addOperand(*MF, MachineOperand::CreateMCSymbol(Sym, TargetFlags));
252
126k
    return *this;
253
126k
  }
254
255
1.17M
  const MachineInstrBuilder &setMIFlags(unsigned Flags) const {
256
1.17M
    MI->setFlags(Flags);
257
1.17M
    return *this;
258
1.17M
  }
259
260
2.00M
  const MachineInstrBuilder &setMIFlag(MachineInstr::MIFlag Flag) const {
261
2.00M
    MI->setFlag(Flag);
262
2.00M
    return *this;
263
2.00M
  }
264
265
  // Add a displacement from an existing MachineOperand with an added offset.
266
  const MachineInstrBuilder &addDisp(const MachineOperand &Disp, int64_t off,
267
56
                                     unsigned char TargetFlags = 0) const {
268
56
    // If caller specifies new TargetFlags then use it, otherwise the
269
56
    // default behavior is to copy the target flags from the existing
270
56
    // MachineOperand. This means if the caller wants to clear the
271
56
    // target flags it needs to do so explicitly.
272
56
    if (0 == TargetFlags)
273
56
      TargetFlags = Disp.getTargetFlags();
274
56
275
56
    switch (Disp.getType()) {
276
56
      default:
277
0
        llvm_unreachable("Unhandled operand type in addDisp()");
278
56
      case MachineOperand::MO_Immediate:
279
32
        return addImm(Disp.getImm() + off);
280
56
      case MachineOperand::MO_ConstantPoolIndex:
281
6
        return addConstantPoolIndex(Disp.getIndex(), Disp.getOffset() + off,
282
6
                                    TargetFlags);
283
56
      case MachineOperand::MO_GlobalAddress:
284
18
        return addGlobalAddress(Disp.getGlobal(), Disp.getOffset() + off,
285
18
                                TargetFlags);
286
56
    }
287
56
  }
288
289
  /// Copy all the implicit operands from OtherMI onto this one.
290
  const MachineInstrBuilder &
291
10.2k
  copyImplicitOps(const MachineInstr &OtherMI) const {
292
10.2k
    MI->copyImplicitOps(*MF, OtherMI);
293
10.2k
    return *this;
294
10.2k
  }
295
296
  bool constrainAllUses(const TargetInstrInfo &TII,
297
                        const TargetRegisterInfo &TRI,
298
70.7k
                        const RegisterBankInfo &RBI) const {
299
70.7k
    return constrainSelectedInstRegOperands(*MI, TII, TRI, RBI);
300
70.7k
  }
301
};
302
303
/// Builder interface. Specify how to create the initial instruction itself.
304
inline MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
305
34.8M
                                   const MCInstrDesc &MCID) {
306
34.8M
  return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, DL));
307
34.8M
}
308
309
/// This version of the builder sets up the first operand as a
310
/// destination virtual register.
311
inline MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
312
561k
                                   const MCInstrDesc &MCID, unsigned DestReg) {
313
561k
  return MachineInstrBuilder(MF, MF.CreateMachineInstr(MCID, DL))
314
561k
           .addReg(DestReg, RegState::Define);
315
561k
}
316
317
/// This version of the builder inserts the newly-built instruction before
318
/// the given position in the given MachineBasicBlock, and sets up the first
319
/// operand as a destination virtual register.
320
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
321
                                   MachineBasicBlock::iterator I,
322
                                   const DebugLoc &DL, const MCInstrDesc &MCID,
323
14.7M
                                   unsigned DestReg) {
324
14.7M
  MachineFunction &MF = *BB.getParent();
325
14.7M
  MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
326
14.7M
  BB.insert(I, MI);
327
14.7M
  return MachineInstrBuilder(MF, MI).addReg(DestReg, RegState::Define);
328
14.7M
}
329
330
/// This version of the builder inserts the newly-built instruction before
331
/// the given position in the given MachineBasicBlock, and sets up the first
332
/// operand as a destination virtual register.
333
///
334
/// If \c I is inside a bundle, then the newly inserted \a MachineInstr is
335
/// added to the same bundle.
336
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
337
                                   MachineBasicBlock::instr_iterator I,
338
                                   const DebugLoc &DL, const MCInstrDesc &MCID,
339
10.5k
                                   unsigned DestReg) {
340
10.5k
  MachineFunction &MF = *BB.getParent();
341
10.5k
  MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
342
10.5k
  BB.insert(I, MI);
343
10.5k
  return MachineInstrBuilder(MF, MI).addReg(DestReg, RegState::Define);
344
10.5k
}
345
346
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineInstr &I,
347
                                   const DebugLoc &DL, const MCInstrDesc &MCID,
348
429k
                                   unsigned DestReg) {
349
429k
  // Calling the overload for instr_iterator is always correct.  However, the
350
429k
  // definition is not available in headers, so inline the check.
351
429k
  if (I.isInsideBundle())
352
0
    return BuildMI(BB, MachineBasicBlock::instr_iterator(I), DL, MCID, DestReg);
353
429k
  return BuildMI(BB, MachineBasicBlock::iterator(I), DL, MCID, DestReg);
354
429k
}
355
356
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineInstr *I,
357
                                   const DebugLoc &DL, const MCInstrDesc &MCID,
358
373k
                                   unsigned DestReg) {
359
373k
  return BuildMI(BB, *I, DL, MCID, DestReg);
360
373k
}
361
362
/// This version of the builder inserts the newly-built instruction before the
363
/// given position in the given MachineBasicBlock, and does NOT take a
364
/// destination register.
365
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
366
                                   MachineBasicBlock::iterator I,
367
                                   const DebugLoc &DL,
368
18.5M
                                   const MCInstrDesc &MCID) {
369
18.5M
  MachineFunction &MF = *BB.getParent();
370
18.5M
  MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
371
18.5M
  BB.insert(I, MI);
372
18.5M
  return MachineInstrBuilder(MF, MI);
373
18.5M
}
374
375
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
376
                                   MachineBasicBlock::instr_iterator I,
377
                                   const DebugLoc &DL,
378
46.1k
                                   const MCInstrDesc &MCID) {
379
46.1k
  MachineFunction &MF = *BB.getParent();
380
46.1k
  MachineInstr *MI = MF.CreateMachineInstr(MCID, DL);
381
46.1k
  BB.insert(I, MI);
382
46.1k
  return MachineInstrBuilder(MF, MI);
383
46.1k
}
384
385
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineInstr &I,
386
                                   const DebugLoc &DL,
387
3.66M
                                   const MCInstrDesc &MCID) {
388
3.66M
  // Calling the overload for instr_iterator is always correct.  However, the
389
3.66M
  // definition is not available in headers, so inline the check.
390
3.66M
  if (I.isInsideBundle())
391
8.84k
    return BuildMI(BB, MachineBasicBlock::instr_iterator(I), DL, MCID);
392
3.65M
  return BuildMI(BB, MachineBasicBlock::iterator(I), DL, MCID);
393
3.65M
}
394
395
inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineInstr *I,
396
                                   const DebugLoc &DL,
397
1.55M
                                   const MCInstrDesc &MCID) {
398
1.55M
  return BuildMI(BB, *I, DL, MCID);
399
1.55M
}
400
401
/// This version of the builder inserts the newly-built instruction at the end
402
/// of the given MachineBasicBlock, and does NOT take a destination register.
403
inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, const DebugLoc &DL,
404
9.37M
                                   const MCInstrDesc &MCID) {
405
9.37M
  return BuildMI(*BB, BB->end(), DL, MCID);
406
9.37M
}
407
408
/// This version of the builder inserts the newly-built instruction at the
409
/// end of the given MachineBasicBlock, and sets up the first operand as a
410
/// destination virtual register.
411
inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, const DebugLoc &DL,
412
450k
                                   const MCInstrDesc &MCID, unsigned DestReg) {
413
450k
  return BuildMI(*BB, BB->end(), DL, MCID, DestReg);
414
450k
}
415
416
/// This version of the builder builds a DBG_VALUE intrinsic
417
/// for either a value in a register or a register-indirect
418
/// address.  The convention is that a DBG_VALUE is indirect iff the
419
/// second operand is an immediate.
420
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
421
                            const MCInstrDesc &MCID, bool IsIndirect,
422
                            unsigned Reg, const MDNode *Variable,
423
                            const MDNode *Expr);
424
425
/// This version of the builder builds a DBG_VALUE intrinsic
426
/// for a MachineOperand.
427
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL,
428
                            const MCInstrDesc &MCID, bool IsIndirect,
429
                            MachineOperand &MO, const MDNode *Variable,
430
                            const MDNode *Expr);
431
432
/// This version of the builder builds a DBG_VALUE intrinsic
433
/// for either a value in a register or a register-indirect
434
/// address and inserts it at position I.
435
MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
436
                            MachineBasicBlock::iterator I, const DebugLoc &DL,
437
                            const MCInstrDesc &MCID, bool IsIndirect,
438
                            unsigned Reg, const MDNode *Variable,
439
                            const MDNode *Expr);
440
441
/// This version of the builder builds a DBG_VALUE intrinsic
442
/// for a machine operand and inserts it at position I.
443
MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
444
                            MachineBasicBlock::iterator I, const DebugLoc &DL,
445
                            const MCInstrDesc &MCID, bool IsIndirect,
446
                            MachineOperand &MO, const MDNode *Variable,
447
                            const MDNode *Expr);
448
449
/// Clone a DBG_VALUE whose value has been spilled to FrameIndex.
450
MachineInstr *buildDbgValueForSpill(MachineBasicBlock &BB,
451
                                    MachineBasicBlock::iterator I,
452
                                    const MachineInstr &Orig, int FrameIndex);
453
454
/// Update a DBG_VALUE whose value has been spilled to FrameIndex. Useful when
455
/// modifying an instruction in place while iterating over a basic block.
456
void updateDbgValueForSpill(MachineInstr &Orig, int FrameIndex);
457
458
9.87M
inline unsigned getDefRegState(bool B) {
459
9.87M
  return B ? 
RegState::Define1.76M
:
08.10M
;
460
9.87M
}
461
4.64M
inline unsigned getImplRegState(bool B) {
462
4.64M
  return B ? 
RegState::Implicit2.03M
:
02.61M
;
463
4.64M
}
464
12.2M
inline unsigned getKillRegState(bool B) {
465
12.2M
  return B ? 
RegState::Kill5.04M
:
07.22M
;
466
12.2M
}
467
777k
inline unsigned getDeadRegState(bool B) {
468
777k
  return B ? 
RegState::Dead37.1k
:
0740k
;
469
777k
}
470
158k
inline unsigned getUndefRegState(bool B) {
471
158k
  return B ? 
RegState::Undef6.64k
:
0152k
;
472
158k
}
473
6.79k
inline unsigned getInternalReadRegState(bool B) {
474
6.79k
  return B ? 
RegState::InternalRead11
:
06.78k
;
475
6.79k
}
476
8.09M
inline unsigned getDebugRegState(bool B) {
477
8.09M
  return B ? 
RegState::Debug314
:
08.09M
;
478
8.09M
}
479
1.70k
inline unsigned getRenamableRegState(bool B) {
480
1.70k
  return B ? 
RegState::Renamable268
:
01.44k
;
481
1.70k
}
482
483
/// Get all register state flags from machine operand \p RegOp.
484
1.70k
inline unsigned getRegState(const MachineOperand &RegOp) {
485
1.70k
  assert(RegOp.isReg() && "Not a register operand");
486
1.70k
  return getDefRegState(RegOp.isDef())                    |
487
1.70k
         getImplRegState(RegOp.isImplicit())              |
488
1.70k
         getKillRegState(RegOp.isKill())                  |
489
1.70k
         getDeadRegState(RegOp.isDead())                  |
490
1.70k
         getUndefRegState(RegOp.isUndef())                |
491
1.70k
         getInternalReadRegState(RegOp.isInternalRead())  |
492
1.70k
         getDebugRegState(RegOp.isDebug())                |
493
1.70k
         getRenamableRegState(
494
1.70k
             TargetRegisterInfo::isPhysicalRegister(RegOp.getReg()) &&
495
1.70k
             
RegOp.isRenamable()269
);
496
1.70k
}
497
498
/// Helper class for constructing bundles of MachineInstrs.
499
///
500
/// MIBundleBuilder can create a bundle from scratch by inserting new
501
/// MachineInstrs one at a time, or it can create a bundle from a sequence of
502
/// existing MachineInstrs in a basic block.
503
class MIBundleBuilder {
504
  MachineBasicBlock &MBB;
505
  MachineBasicBlock::instr_iterator Begin;
506
  MachineBasicBlock::instr_iterator End;
507
508
public:
509
  /// Create an MIBundleBuilder that inserts instructions into a new bundle in
510
  /// BB above the bundle or instruction at Pos.
511
  MIBundleBuilder(MachineBasicBlock &BB, MachineBasicBlock::iterator Pos)
512
664
      : MBB(BB), Begin(Pos.getInstrIterator()), End(Begin) {}
513
514
  /// Create a bundle from the sequence of instructions between B and E.
515
  MIBundleBuilder(MachineBasicBlock &BB, MachineBasicBlock::iterator B,
516
                  MachineBasicBlock::iterator E)
517
51.5k
      : MBB(BB), Begin(B.getInstrIterator()), End(E.getInstrIterator()) {
518
51.5k
    assert(B != E && "No instructions to bundle");
519
51.5k
    ++B;
520
120k
    while (B != E) {
521
68.8k
      MachineInstr &MI = *B;
522
68.8k
      ++B;
523
68.8k
      MI.bundleWithPred();
524
68.8k
    }
525
51.5k
  }
526
527
  /// Create an MIBundleBuilder representing an existing instruction or bundle
528
  /// that has MI as its head.
529
  explicit MIBundleBuilder(MachineInstr *MI)
530
      : MBB(*MI->getParent()), Begin(MI),
531
184
        End(getBundleEnd(MI->getIterator())) {}
532
533
  /// Return a reference to the basic block containing this bundle.
534
  MachineBasicBlock &getMBB() const { return MBB; }
535
536
  /// Return true if no instructions have been inserted in this bundle yet.
537
  /// Empty bundles aren't representable in a MachineBasicBlock.
538
36.3k
  bool empty() const { return Begin == End; }
539
540
  /// Return an iterator to the first bundled instruction.
541
36.2k
  MachineBasicBlock::instr_iterator begin() const { return Begin; }
542
543
  /// Return an iterator beyond the last bundled instruction.
544
2.12k
  MachineBasicBlock::instr_iterator end() const { return End; }
545
546
  /// Insert MI into this bundle before I which must point to an instruction in
547
  /// the bundle, or end().
548
  MIBundleBuilder &insert(MachineBasicBlock::instr_iterator I,
549
37.7k
                          MachineInstr *MI) {
550
37.7k
    MBB.insert(I, MI);
551
37.7k
    if (I == Begin) {
552
36.3k
      if (!empty())
553
35.6k
        MI->bundleWithSucc();
554
36.3k
      Begin = MI->getIterator();
555
36.3k
      return *this;
556
36.3k
    }
557
1.45k
    if (I == End) {
558
1.45k
      MI->bundleWithPred();
559
1.45k
      return *this;
560
1.45k
    }
561
0
    // MI was inserted in the middle of the bundle, so its neighbors' flags are
562
0
    // already fine. Update MI's bundle flags manually.
563
0
    MI->setFlag(MachineInstr::BundledPred);
564
0
    MI->setFlag(MachineInstr::BundledSucc);
565
0
    return *this;
566
0
  }
567
568
  /// Insert MI into MBB by prepending it to the instructions in the bundle.
569
  /// MI will become the first instruction in the bundle.
570
35.6k
  MIBundleBuilder &prepend(MachineInstr *MI) {
571
35.6k
    return insert(begin(), MI);
572
35.6k
  }
573
574
  /// Insert MI into MBB by appending it to the instructions in the bundle.
575
  /// MI will become the last instruction in the bundle.
576
2.12k
  MIBundleBuilder &append(MachineInstr *MI) {
577
2.12k
    return insert(end(), MI);
578
2.12k
  }
579
};
580
581
} // end namespace llvm
582
583
#endif // LLVM_CODEGEN_MACHINEINSTRBUILDER_H