Coverage Report

Created: 2019-07-24 05:18

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