Coverage Report

Created: 2019-02-20 07:29

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/TargetRegisterInfo.h
Line
Count
Source (jump to first uncovered line)
1
//==- CodeGen/TargetRegisterInfo.h - Target Register Information -*- 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 describes an abstract interface used to get information about a
10
// target machines register file.  This information is used for a variety of
11
// purposed, especially register allocation.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CODEGEN_TARGETREGISTERINFO_H
16
#define LLVM_CODEGEN_TARGETREGISTERINFO_H
17
18
#include "llvm/ADT/ArrayRef.h"
19
#include "llvm/ADT/SmallVector.h"
20
#include "llvm/ADT/StringRef.h"
21
#include "llvm/ADT/iterator_range.h"
22
#include "llvm/CodeGen/MachineBasicBlock.h"
23
#include "llvm/IR/CallingConv.h"
24
#include "llvm/MC/LaneBitmask.h"
25
#include "llvm/MC/MCRegisterInfo.h"
26
#include "llvm/Support/ErrorHandling.h"
27
#include "llvm/Support/MachineValueType.h"
28
#include "llvm/Support/MathExtras.h"
29
#include "llvm/Support/Printable.h"
30
#include <cassert>
31
#include <cstdint>
32
#include <functional>
33
34
namespace llvm {
35
36
class BitVector;
37
class LiveRegMatrix;
38
class MachineFunction;
39
class MachineInstr;
40
class RegScavenger;
41
class VirtRegMap;
42
class LiveIntervals;
43
44
class TargetRegisterClass {
45
public:
46
  using iterator = const MCPhysReg *;
47
  using const_iterator = const MCPhysReg *;
48
  using sc_iterator = const TargetRegisterClass* const *;
49
50
  // Instance variables filled by tablegen, do not use!
51
  const MCRegisterClass *MC;
52
  const uint32_t *SubClassMask;
53
  const uint16_t *SuperRegIndices;
54
  const LaneBitmask LaneMask;
55
  /// Classes with a higher priority value are assigned first by register
56
  /// allocators using a greedy heuristic. The value is in the range [0,63].
57
  const uint8_t AllocationPriority;
58
  /// Whether the class supports two (or more) disjunct subregister indices.
59
  const bool HasDisjunctSubRegs;
60
  /// Whether a combination of subregisters can cover every register in the
61
  /// class. See also the CoveredBySubRegs description in Target.td.
62
  const bool CoveredBySubRegs;
63
  const sc_iterator SuperClasses;
64
  ArrayRef<MCPhysReg> (*OrderFunc)(const MachineFunction&);
65
66
  /// Return the register class ID number.
67
519M
  unsigned getID() const { return MC->getID(); }
68
69
  /// begin/end - Return all of the registers in this class.
70
  ///
71
17.6M
  iterator       begin() const { return MC->begin(); }
72
16.8M
  iterator         end() const { return MC->end(); }
73
74
  /// Return the number of registers in this class.
75
508M
  unsigned getNumRegs() const { return MC->getNumRegs(); }
76
77
  iterator_range<SmallVectorImpl<MCPhysReg>::const_iterator>
78
41.3k
  getRegisters() const {
79
41.3k
    return make_range(MC->begin(), MC->end());
80
41.3k
  }
81
82
  /// Return the specified register in the class.
83
15.8M
  unsigned getRegister(unsigned i) const {
84
15.8M
    return MC->getRegister(i);
85
15.8M
  }
86
87
  /// Return true if the specified register is included in this register class.
88
  /// This does not include virtual registers.
89
1.13G
  bool contains(unsigned Reg) const {
90
1.13G
    return MC->contains(Reg);
91
1.13G
  }
92
93
  /// Return true if both registers are in this class.
94
719k
  bool contains(unsigned Reg1, unsigned Reg2) const {
95
719k
    return MC->contains(Reg1, Reg2);
96
719k
  }
97
98
  /// Return the cost of copying a value between two registers in this class.
99
  /// A negative number means the register class is very expensive
100
  /// to copy e.g. status flag register classes.
101
940k
  int getCopyCost() const { return MC->getCopyCost(); }
102
103
  /// Return true if this register class may be used to create virtual
104
  /// registers.
105
16.7M
  bool isAllocatable() const { return MC->isAllocatable(); }
106
107
  /// Return true if the specified TargetRegisterClass
108
  /// is a proper sub-class of this TargetRegisterClass.
109
17.7M
  bool hasSubClass(const TargetRegisterClass *RC) const {
110
17.7M
    return RC != this && hasSubClassEq(RC);
111
17.7M
  }
112
113
  /// Returns true if RC is a sub-class of or equal to this class.
114
37.4M
  bool hasSubClassEq(const TargetRegisterClass *RC) const {
115
37.4M
    unsigned ID = RC->getID();
116
37.4M
    return (SubClassMask[ID / 32] >> (ID % 32)) & 1;
117
37.4M
  }
118
119
  /// Return true if the specified TargetRegisterClass is a
120
  /// proper super-class of this TargetRegisterClass.
121
0
  bool hasSuperClass(const TargetRegisterClass *RC) const {
122
0
    return RC->hasSubClass(this);
123
0
  }
124
125
  /// Returns true if RC is a super-class of or equal to this class.
126
17.3M
  bool hasSuperClassEq(const TargetRegisterClass *RC) const {
127
17.3M
    return RC->hasSubClassEq(this);
128
17.3M
  }
129
130
  /// Returns a bit vector of subclasses, including this one.
131
  /// The vector is indexed by class IDs.
132
  ///
133
  /// To use it, consider the returned array as a chunk of memory that
134
  /// contains an array of bits of size NumRegClasses. Each 32-bit chunk
135
  /// contains a bitset of the ID of the subclasses in big-endian style.
136
137
  /// I.e., the representation of the memory from left to right at the
138
  /// bit level looks like:
139
  /// [31 30 ... 1 0] [ 63 62 ... 33 32] ...
140
  ///                     [ XXX NumRegClasses NumRegClasses - 1 ... ]
141
  /// Where the number represents the class ID and XXX bits that
142
  /// should be ignored.
143
  ///
144
  /// See the implementation of hasSubClassEq for an example of how it
145
  /// can be used.
146
41.3M
  const uint32_t *getSubClassMask() const {
147
41.3M
    return SubClassMask;
148
41.3M
  }
149
150
  /// Returns a 0-terminated list of sub-register indices that project some
151
  /// super-register class into this register class. The list has an entry for
152
  /// each Idx such that:
153
  ///
154
  ///   There exists SuperRC where:
155
  ///     For all Reg in SuperRC:
156
  ///       this->contains(Reg:Idx)
157
3.64M
  const uint16_t *getSuperRegIndices() const {
158
3.64M
    return SuperRegIndices;
159
3.64M
  }
160
161
  /// Returns a NULL-terminated list of super-classes.  The
162
  /// classes are ordered by ID which is also a topological ordering from large
163
  /// to small classes.  The list does NOT include the current class.
164
566k
  sc_iterator getSuperClasses() const {
165
566k
    return SuperClasses;
166
566k
  }
167
168
  /// Return true if this TargetRegisterClass is a subset
169
  /// class of at least one other TargetRegisterClass.
170
0
  bool isASubClass() const {
171
0
    return SuperClasses[0] != nullptr;
172
0
  }
173
174
  /// Returns the preferred order for allocating registers from this register
175
  /// class in MF. The raw order comes directly from the .td file and may
176
  /// include reserved registers that are not allocatable.
177
  /// Register allocators should also make sure to allocate
178
  /// callee-saved registers only after all the volatiles are used. The
179
  /// RegisterClassInfo class provides filtered allocation orders with
180
  /// callee-saved registers moved to the end.
181
  ///
182
  /// The MachineFunction argument can be used to tune the allocatable
183
  /// registers based on the characteristics of the function, subtarget, or
184
  /// other criteria.
185
  ///
186
  /// By default, this method returns all registers in the class.
187
900k
  ArrayRef<MCPhysReg> getRawAllocationOrder(const MachineFunction &MF) const {
188
900k
    return OrderFunc ? 
OrderFunc(MF)160k
:
makeArrayRef(begin(), getNumRegs())739k
;
189
900k
  }
190
191
  /// Returns the combination of all lane masks of register in this class.
192
  /// The lane masks of the registers are the combination of all lane masks
193
  /// of their subregisters. Returns 1 if there are no subregisters.
194
13.8M
  LaneBitmask getLaneMask() const {
195
13.8M
    return LaneMask;
196
13.8M
  }
197
};
198
199
/// Extra information, not in MCRegisterDesc, about registers.
200
/// These are used by codegen, not by MC.
201
struct TargetRegisterInfoDesc {
202
  unsigned CostPerUse;          // Extra cost of instructions using register.
203
  bool inAllocatableClass;      // Register belongs to an allocatable regclass.
204
};
205
206
/// Each TargetRegisterClass has a per register weight, and weight
207
/// limit which must be less than the limits of its pressure sets.
208
struct RegClassWeight {
209
  unsigned RegWeight;
210
  unsigned WeightLimit;
211
};
212
213
/// TargetRegisterInfo base class - We assume that the target defines a static
214
/// array of TargetRegisterDesc objects that represent all of the machine
215
/// registers that the target has.  As such, we simply have to track a pointer
216
/// to this array so that we can turn register number into a register
217
/// descriptor.
218
///
219
class TargetRegisterInfo : public MCRegisterInfo {
220
public:
221
  using regclass_iterator = const TargetRegisterClass * const *;
222
  using vt_iterator = const MVT::SimpleValueType *;
223
  struct RegClassInfo {
224
    unsigned RegSize, SpillSize, SpillAlignment;
225
    vt_iterator VTList;
226
  };
227
private:
228
  const TargetRegisterInfoDesc *InfoDesc;     // Extra desc array for codegen
229
  const char *const *SubRegIndexNames;        // Names of subreg indexes.
230
  // Pointer to array of lane masks, one per sub-reg index.
231
  const LaneBitmask *SubRegIndexLaneMasks;
232
233
  regclass_iterator RegClassBegin, RegClassEnd;   // List of regclasses
234
  LaneBitmask CoveringLanes;
235
  const RegClassInfo *const RCInfos;
236
  unsigned HwMode;
237
238
protected:
239
  TargetRegisterInfo(const TargetRegisterInfoDesc *ID,
240
                     regclass_iterator RCB,
241
                     regclass_iterator RCE,
242
                     const char *const *SRINames,
243
                     const LaneBitmask *SRILaneMasks,
244
                     LaneBitmask CoveringLanes,
245
                     const RegClassInfo *const RCIs,
246
                     unsigned Mode = 0);
247
  virtual ~TargetRegisterInfo();
248
249
public:
250
  // Register numbers can represent physical registers, virtual registers, and
251
  // sometimes stack slots. The unsigned values are divided into these ranges:
252
  //
253
  //   0           Not a register, can be used as a sentinel.
254
  //   [1;2^30)    Physical registers assigned by TableGen.
255
  //   [2^30;2^31) Stack slots. (Rarely used.)
256
  //   [2^31;2^32) Virtual registers assigned by MachineRegisterInfo.
257
  //
258
  // Further sentinels can be allocated from the small negative integers.
259
  // DenseMapInfo<unsigned> uses -1u and -2u.
260
261
  /// isStackSlot - Sometimes it is useful the be able to store a non-negative
262
  /// frame index in a variable that normally holds a register. isStackSlot()
263
  /// returns true if Reg is in the range used for stack slots.
264
  ///
265
  /// Note that isVirtualRegister() and isPhysicalRegister() cannot handle stack
266
  /// slots, so if a variable may contains a stack slot, always check
267
  /// isStackSlot() first.
268
  ///
269
4.16M
  static bool isStackSlot(unsigned Reg) {
270
4.16M
    return int(Reg) >= (1 << 30);
271
4.16M
  }
272
273
  /// Compute the frame index from a register value representing a stack slot.
274
775k
  static int stackSlot2Index(unsigned Reg) {
275
775k
    assert(isStackSlot(Reg) && "Not a stack slot");
276
775k
    return int(Reg - (1u << 30));
277
775k
  }
278
279
  /// Convert a non-negative frame index to a stack slot register value.
280
360k
  static unsigned index2StackSlot(int FI) {
281
360k
    assert(FI >= 0 && "Cannot hold a negative frame index.");
282
360k
    return FI + (1u << 30);
283
360k
  }
284
285
  /// Return true if the specified register number is in
286
  /// the physical register namespace.
287
1.22G
  static bool isPhysicalRegister(unsigned Reg) {
288
1.22G
    assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first.");
289
1.22G
    return int(Reg) > 0;
290
1.22G
  }
291
292
  /// Return true if the specified register number is in
293
  /// the virtual register namespace.
294
2.06G
  static bool isVirtualRegister(unsigned Reg) {
295
2.06G
    assert(!isStackSlot(Reg) && "Not a register! Check isStackSlot() first.");
296
2.06G
    return int(Reg) < 0;
297
2.06G
  }
298
299
  /// Convert a virtual register number to a 0-based index.
300
  /// The first virtual register in a function will get the index 0.
301
2.56G
  static unsigned virtReg2Index(unsigned Reg) {
302
2.56G
    assert(isVirtualRegister(Reg) && "Not a virtual register");
303
2.56G
    return Reg & ~(1u << 31);
304
2.56G
  }
305
306
  /// Convert a 0-based index to a virtual register number.
307
  /// This is the inverse operation of VirtReg2IndexFunctor below.
308
269M
  static unsigned index2VirtReg(unsigned Index) {
309
269M
    return Index | (1u << 31);
310
269M
  }
311
312
  /// Return the size in bits of a register from class RC.
313
34.1M
  unsigned getRegSizeInBits(const TargetRegisterClass &RC) const {
314
34.1M
    return getRegClassInfo(RC).RegSize;
315
34.1M
  }
316
317
  /// Return the size in bytes of the stack slot allocated to hold a spilled
318
  /// copy of a register from class RC.
319
26.3M
  unsigned getSpillSize(const TargetRegisterClass &RC) const {
320
26.3M
    return getRegClassInfo(RC).SpillSize / 8;
321
26.3M
  }
322
323
  /// Return the minimum required alignment in bytes for a spill slot for
324
  /// a register of this class.
325
1.50M
  unsigned getSpillAlignment(const TargetRegisterClass &RC) const {
326
1.50M
    return getRegClassInfo(RC).SpillAlignment / 8;
327
1.50M
  }
328
329
  /// Return true if the given TargetRegisterClass has the ValueType T.
330
152M
  bool isTypeLegalForClass(const TargetRegisterClass &RC, MVT T) const {
331
366M
    for (auto I = legalclasstypes_begin(RC); *I != MVT::Other; 
++I214M
)
332
237M
      if (MVT(*I) == T)
333
23.3M
        return true;
334
152M
    
return false128M
;
335
152M
  }
336
337
  /// Loop over all of the value types that can be represented by values
338
  /// in the given register class.
339
180M
  vt_iterator legalclasstypes_begin(const TargetRegisterClass &RC) const {
340
180M
    return getRegClassInfo(RC).VTList;
341
180M
  }
342
343
0
  vt_iterator legalclasstypes_end(const TargetRegisterClass &RC) const {
344
0
    vt_iterator I = legalclasstypes_begin(RC);
345
0
    while (*I != MVT::Other)
346
0
      ++I;
347
0
    return I;
348
0
  }
349
350
  /// Returns the Register Class of a physical register of the given type,
351
  /// picking the most sub register class of the right type that contains this
352
  /// physreg.
353
  const TargetRegisterClass *
354
    getMinimalPhysRegClass(unsigned Reg, MVT VT = MVT::Other) const;
355
356
  /// Return the maximal subclass of the given register class that is
357
  /// allocatable or NULL.
358
  const TargetRegisterClass *
359
    getAllocatableClass(const TargetRegisterClass *RC) const;
360
361
  /// Returns a bitset indexed by register number indicating if a register is
362
  /// allocatable or not. If a register class is specified, returns the subset
363
  /// for the class.
364
  BitVector getAllocatableSet(const MachineFunction &MF,
365
                              const TargetRegisterClass *RC = nullptr) const;
366
367
  /// Return the additional cost of using this register instead
368
  /// of other registers in its class.
369
54.8M
  unsigned getCostPerUse(unsigned RegNo) const {
370
54.8M
    return InfoDesc[RegNo].CostPerUse;
371
54.8M
  }
372
373
  /// Return true if the register is in the allocation of any register class.
374
39.1M
  bool isInAllocatableClass(unsigned RegNo) const {
375
39.1M
    return InfoDesc[RegNo].inAllocatableClass;
376
39.1M
  }
377
378
  /// Return the human-readable symbolic target-specific
379
  /// name for the specified SubRegIndex.
380
15.8k
  const char *getSubRegIndexName(unsigned SubIdx) const {
381
15.8k
    assert(SubIdx && SubIdx < getNumSubRegIndices() &&
382
15.8k
           "This is not a subregister index");
383
15.8k
    return SubRegIndexNames[SubIdx-1];
384
15.8k
  }
385
386
  /// Return a bitmask representing the parts of a register that are covered by
387
  /// SubIdx \see LaneBitmask.
388
  ///
389
  /// SubIdx == 0 is allowed, it has the lane mask ~0u.
390
33.3M
  LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const {
391
33.3M
    assert(SubIdx < getNumSubRegIndices() && "This is not a subregister index");
392
33.3M
    return SubRegIndexLaneMasks[SubIdx];
393
33.3M
  }
394
395
  /// The lane masks returned by getSubRegIndexLaneMask() above can only be
396
  /// used to determine if sub-registers overlap - they can't be used to
397
  /// determine if a set of sub-registers completely cover another
398
  /// sub-register.
399
  ///
400
  /// The X86 general purpose registers have two lanes corresponding to the
401
  /// sub_8bit and sub_8bit_hi sub-registers. Both sub_32bit and sub_16bit have
402
  /// lane masks '3', but the sub_16bit sub-register doesn't fully cover the
403
  /// sub_32bit sub-register.
404
  ///
405
  /// On the other hand, the ARM NEON lanes fully cover their registers: The
406
  /// dsub_0 sub-register is completely covered by the ssub_0 and ssub_1 lanes.
407
  /// This is related to the CoveredBySubRegs property on register definitions.
408
  ///
409
  /// This function returns a bit mask of lanes that completely cover their
410
  /// sub-registers. More precisely, given:
411
  ///
412
  ///   Covering = getCoveringLanes();
413
  ///   MaskA = getSubRegIndexLaneMask(SubA);
414
  ///   MaskB = getSubRegIndexLaneMask(SubB);
415
  ///
416
  /// If (MaskA & ~(MaskB & Covering)) == 0, then SubA is completely covered by
417
  /// SubB.
418
0
  LaneBitmask getCoveringLanes() const { return CoveringLanes; }
419
420
  /// Returns true if the two registers are equal or alias each other.
421
  /// The registers may be virtual registers.
422
20.1M
  bool regsOverlap(unsigned regA, unsigned regB) const {
423
20.1M
    if (regA == regB) 
return true659k
;
424
19.4M
    if (isVirtualRegister(regA) || 
isVirtualRegister(regB)17.7M
)
425
1.75M
      return false;
426
17.7M
427
17.7M
    // Regunits are numerically ordered. Find a common unit.
428
17.7M
    MCRegUnitIterator RUA(regA, this);
429
17.7M
    MCRegUnitIterator RUB(regB, this);
430
22.3M
    do {
431
22.3M
      if (*RUA == *RUB) 
return true72.6k
;
432
22.2M
      if (*RUA < *RUB) 
++RUA10.2M
;
433
12.0M
      else             ++RUB;
434
22.2M
    } while (RUA.isValid() && 
RUB.isValid()14.4M
);
435
17.7M
    
return false17.6M
;
436
17.7M
  }
437
438
  /// Returns true if Reg contains RegUnit.
439
2.60M
  bool hasRegUnit(unsigned Reg, unsigned RegUnit) const {
440
5.05M
    for (MCRegUnitIterator Units(Reg, this); Units.isValid(); 
++Units2.44M
)
441
2.69M
      if (*Units == RegUnit)
442
247k
        return true;
443
2.60M
    
return false2.36M
;
444
2.60M
  }
445
446
  /// Returns the original SrcReg unless it is the target of a copy-like
447
  /// operation, in which case we chain backwards through all such operations
448
  /// to the ultimate source register.  If a physical register is encountered,
449
  /// we stop the search.
450
  virtual unsigned lookThruCopyLike(unsigned SrcReg,
451
                                    const MachineRegisterInfo *MRI) const;
452
453
  /// Return a null-terminated list of all of the callee-saved registers on
454
  /// this target. The register should be in the order of desired callee-save
455
  /// stack frame offset. The first register is closest to the incoming stack
456
  /// pointer if stack grows down, and vice versa.
457
  /// Notice: This function does not take into account disabled CSRs.
458
  ///         In most cases you will want to use instead the function
459
  ///         getCalleeSavedRegs that is implemented in MachineRegisterInfo.
460
  virtual const MCPhysReg*
461
  getCalleeSavedRegs(const MachineFunction *MF) const = 0;
462
463
  /// Return a mask of call-preserved registers for the given calling convention
464
  /// on the current function. The mask should include all call-preserved
465
  /// aliases. This is used by the register allocator to determine which
466
  /// registers can be live across a call.
467
  ///
468
  /// The mask is an array containing (TRI::getNumRegs()+31)/32 entries.
469
  /// A set bit indicates that all bits of the corresponding register are
470
  /// preserved across the function call.  The bit mask is expected to be
471
  /// sub-register complete, i.e. if A is preserved, so are all its
472
  /// sub-registers.
473
  ///
474
  /// Bits are numbered from the LSB, so the bit for physical register Reg can
475
  /// be found as (Mask[Reg / 32] >> Reg % 32) & 1.
476
  ///
477
  /// A NULL pointer means that no register mask will be used, and call
478
  /// instructions should use implicit-def operands to indicate call clobbered
479
  /// registers.
480
  ///
481
  virtual const uint32_t *getCallPreservedMask(const MachineFunction &MF,
482
0
                                               CallingConv::ID) const {
483
0
    // The default mask clobbers everything.  All targets should override.
484
0
    return nullptr;
485
0
  }
486
487
  /// Return a register mask that clobbers everything.
488
0
  virtual const uint32_t *getNoPreservedMask() const {
489
0
    llvm_unreachable("target does not provide no preserved mask");
490
0
  }
491
492
  /// Return true if all bits that are set in mask \p mask0 are also set in
493
  /// \p mask1.
494
  bool regmaskSubsetEqual(const uint32_t *mask0, const uint32_t *mask1) const;
495
496
  /// Return all the call-preserved register masks defined for this target.
497
  virtual ArrayRef<const uint32_t *> getRegMasks() const = 0;
498
  virtual ArrayRef<const char *> getRegMaskNames() const = 0;
499
500
  /// Returns a bitset indexed by physical register number indicating if a
501
  /// register is a special register that has particular uses and should be
502
  /// considered unavailable at all times, e.g. stack pointer, return address.
503
  /// A reserved register:
504
  /// - is not allocatable
505
  /// - is considered always live
506
  /// - is ignored by liveness tracking
507
  /// It is often necessary to reserve the super registers of a reserved
508
  /// register as well, to avoid them getting allocated indirectly. You may use
509
  /// markSuperRegs() and checkAllSuperRegsMarked() in this case.
510
  virtual BitVector getReservedRegs(const MachineFunction &MF) const = 0;
511
512
  /// Returns false if we can't guarantee that Physreg, specified as an IR asm
513
  /// clobber constraint, will be preserved across the statement.
514
  virtual bool isAsmClobberable(const MachineFunction &MF,
515
46.7k
                               unsigned PhysReg) const {
516
46.7k
    return true;
517
46.7k
  }
518
519
  /// Returns true if PhysReg is unallocatable and constant throughout the
520
  /// function.  Used by MachineRegisterInfo::isConstantPhysReg().
521
6.62M
  virtual bool isConstantPhysReg(unsigned PhysReg) const { return false; }
522
523
  /// Physical registers that may be modified within a function but are
524
  /// guaranteed to be restored before any uses. This is useful for targets that
525
  /// have call sequences where a GOT register may be updated by the caller
526
  /// prior to a call and is guaranteed to be restored (also by the caller)
527
  /// after the call.
528
  virtual bool isCallerPreservedPhysReg(unsigned PhysReg,
529
2.00M
                                        const MachineFunction &MF) const {
530
2.00M
    return false;
531
2.00M
  }
532
533
  /// Prior to adding the live-out mask to a stackmap or patchpoint
534
  /// instruction, provide the target the opportunity to adjust it (mainly to
535
  /// remove pseudo-registers that should be ignored).
536
74
  virtual void adjustStackMapLiveOutMask(uint32_t *Mask) const {}
537
538
  /// Return a super-register of the specified register
539
  /// Reg so its sub-register of index SubIdx is Reg.
540
  unsigned getMatchingSuperReg(unsigned Reg, unsigned SubIdx,
541
667k
                               const TargetRegisterClass *RC) const {
542
667k
    return MCRegisterInfo::getMatchingSuperReg(Reg, SubIdx, RC->MC);
543
667k
  }
544
545
  /// Return a subclass of the specified register
546
  /// class A so that each register in it has a sub-register of the
547
  /// specified sub-register index which is in the specified register class B.
548
  ///
549
  /// TableGen will synthesize missing A sub-classes.
550
  virtual const TargetRegisterClass *
551
  getMatchingSuperRegClass(const TargetRegisterClass *A,
552
                           const TargetRegisterClass *B, unsigned Idx) const;
553
554
  // For a copy-like instruction that defines a register of class DefRC with
555
  // subreg index DefSubReg, reading from another source with class SrcRC and
556
  // subregister SrcSubReg return true if this is a preferable copy
557
  // instruction or an earlier use should be used.
558
  virtual bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
559
                                    unsigned DefSubReg,
560
                                    const TargetRegisterClass *SrcRC,
561
                                    unsigned SrcSubReg) const;
562
563
  /// Returns the largest legal sub-class of RC that
564
  /// supports the sub-register index Idx.
565
  /// If no such sub-class exists, return NULL.
566
  /// If all registers in RC already have an Idx sub-register, return RC.
567
  ///
568
  /// TableGen generates a version of this function that is good enough in most
569
  /// cases.  Targets can override if they have constraints that TableGen
570
  /// doesn't understand.  For example, the x86 sub_8bit sub-register index is
571
  /// supported by the full GR32 register class in 64-bit mode, but only by the
572
  /// GR32_ABCD regiister class in 32-bit mode.
573
  ///
574
  /// TableGen will synthesize missing RC sub-classes.
575
  virtual const TargetRegisterClass *
576
0
  getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const {
577
0
    assert(Idx == 0 && "Target has no sub-registers");
578
0
    return RC;
579
0
  }
580
581
  /// Return the subregister index you get from composing
582
  /// two subregister indices.
583
  ///
584
  /// The special null sub-register index composes as the identity.
585
  ///
586
  /// If R:a:b is the same register as R:c, then composeSubRegIndices(a, b)
587
  /// returns c. Note that composeSubRegIndices does not tell you about illegal
588
  /// compositions. If R does not have a subreg a, or R:a does not have a subreg
589
  /// b, composeSubRegIndices doesn't tell you.
590
  ///
591
  /// The ARM register Q0 has two D subregs dsub_0:D0 and dsub_1:D1. It also has
592
  /// ssub_0:S0 - ssub_3:S3 subregs.
593
  /// If you compose subreg indices dsub_1, ssub_0 you get ssub_2.
594
28.7M
  unsigned composeSubRegIndices(unsigned a, unsigned b) const {
595
28.7M
    if (!a) 
return b26.2M
;
596
2.57M
    if (!b) 
return a2.05M
;
597
527k
    return composeSubRegIndicesImpl(a, b);
598
527k
  }
599
600
  /// Transforms a LaneMask computed for one subregister to the lanemask that
601
  /// would have been computed when composing the subsubregisters with IdxA
602
  /// first. @sa composeSubRegIndices()
603
  LaneBitmask composeSubRegIndexLaneMask(unsigned IdxA,
604
336k
                                         LaneBitmask Mask) const {
605
336k
    if (!IdxA)
606
11.7k
      return Mask;
607
324k
    return composeSubRegIndexLaneMaskImpl(IdxA, Mask);
608
324k
  }
609
610
  /// Transform a lanemask given for a virtual register to the corresponding
611
  /// lanemask before using subregister with index \p IdxA.
612
  /// This is the reverse of composeSubRegIndexLaneMask(), assuming Mask is a
613
  /// valie lane mask (no invalid bits set) the following holds:
614
  /// X0 = composeSubRegIndexLaneMask(Idx, Mask)
615
  /// X1 = reverseComposeSubRegIndexLaneMask(Idx, X0)
616
  /// => X1 == Mask
617
  LaneBitmask reverseComposeSubRegIndexLaneMask(unsigned IdxA,
618
640k
                                                LaneBitmask LaneMask) const {
619
640k
    if (!IdxA)
620
220k
      return LaneMask;
621
419k
    return reverseComposeSubRegIndexLaneMaskImpl(IdxA, LaneMask);
622
419k
  }
623
624
  /// Debugging helper: dump register in human readable form to dbgs() stream.
625
  static void dumpReg(unsigned Reg, unsigned SubRegIndex = 0,
626
                      const TargetRegisterInfo* TRI = nullptr);
627
628
protected:
629
  /// Overridden by TableGen in targets that have sub-registers.
630
0
  virtual unsigned composeSubRegIndicesImpl(unsigned, unsigned) const {
631
0
    llvm_unreachable("Target has no sub-registers");
632
0
  }
633
634
  /// Overridden by TableGen in targets that have sub-registers.
635
  virtual LaneBitmask
636
0
  composeSubRegIndexLaneMaskImpl(unsigned, LaneBitmask) const {
637
0
    llvm_unreachable("Target has no sub-registers");
638
0
  }
639
640
  virtual LaneBitmask reverseComposeSubRegIndexLaneMaskImpl(unsigned,
641
0
                                                            LaneBitmask) const {
642
0
    llvm_unreachable("Target has no sub-registers");
643
0
  }
644
645
public:
646
  /// Find a common super-register class if it exists.
647
  ///
648
  /// Find a register class, SuperRC and two sub-register indices, PreA and
649
  /// PreB, such that:
650
  ///
651
  ///   1. PreA + SubA == PreB + SubB  (using composeSubRegIndices()), and
652
  ///
653
  ///   2. For all Reg in SuperRC: Reg:PreA in RCA and Reg:PreB in RCB, and
654
  ///
655
  ///   3. SuperRC->getSize() >= max(RCA->getSize(), RCB->getSize()).
656
  ///
657
  /// SuperRC will be chosen such that no super-class of SuperRC satisfies the
658
  /// requirements, and there is no register class with a smaller spill size
659
  /// that satisfies the requirements.
660
  ///
661
  /// SubA and SubB must not be 0. Use getMatchingSuperRegClass() instead.
662
  ///
663
  /// Either of the PreA and PreB sub-register indices may be returned as 0. In
664
  /// that case, the returned register class will be a sub-class of the
665
  /// corresponding argument register class.
666
  ///
667
  /// The function returns NULL if no register class can be found.
668
  const TargetRegisterClass*
669
  getCommonSuperRegClass(const TargetRegisterClass *RCA, unsigned SubA,
670
                         const TargetRegisterClass *RCB, unsigned SubB,
671
                         unsigned &PreA, unsigned &PreB) const;
672
673
  //===--------------------------------------------------------------------===//
674
  // Register Class Information
675
  //
676
protected:
677
242M
  const RegClassInfo &getRegClassInfo(const TargetRegisterClass &RC) const {
678
242M
    return RCInfos[getNumRegClasses() * HwMode + RC.getID()];
679
242M
  }
680
681
public:
682
  /// Register class iterators
683
273M
  regclass_iterator regclass_begin() const { return RegClassBegin; }
684
273M
  regclass_iterator regclass_end() const { return RegClassEnd; }
685
5.49M
  iterator_range<regclass_iterator> regclasses() const {
686
5.49M
    return make_range(regclass_begin(), regclass_end());
687
5.49M
  }
688
689
268M
  unsigned getNumRegClasses() const {
690
268M
    return (unsigned)(regclass_end()-regclass_begin());
691
268M
  }
692
693
  /// Returns the register class associated with the enumeration value.
694
  /// See class MCOperandInfo.
695
111M
  const TargetRegisterClass *getRegClass(unsigned i) const {
696
111M
    assert(i < getNumRegClasses() && "Register Class ID out of range");
697
111M
    return RegClassBegin[i];
698
111M
  }
699
700
  /// Returns the name of the register class.
701
181k
  const char *getRegClassName(const TargetRegisterClass *Class) const {
702
181k
    return MCRegisterInfo::getRegClassName(Class->MC);
703
181k
  }
704
705
  /// Find the largest common subclass of A and B.
706
  /// Return NULL if there is no common subclass.
707
  /// The common subclass should contain
708
  /// simple value type SVT if it is not the Any type.
709
  const TargetRegisterClass *
710
  getCommonSubClass(const TargetRegisterClass *A,
711
                    const TargetRegisterClass *B,
712
                    const MVT::SimpleValueType SVT =
713
                    MVT::SimpleValueType::Any) const;
714
715
  /// Returns a TargetRegisterClass used for pointer values.
716
  /// If a target supports multiple different pointer register classes,
717
  /// kind specifies which one is indicated.
718
  virtual const TargetRegisterClass *
719
0
  getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const {
720
0
    llvm_unreachable("Target didn't implement getPointerRegClass!");
721
0
  }
722
723
  /// Returns a legal register class to copy a register in the specified class
724
  /// to or from. If it is possible to copy the register directly without using
725
  /// a cross register class copy, return the specified RC. Returns NULL if it
726
  /// is not possible to copy between two registers of the specified class.
727
  virtual const TargetRegisterClass *
728
0
  getCrossCopyRegClass(const TargetRegisterClass *RC) const {
729
0
    return RC;
730
0
  }
731
732
  /// Returns the largest super class of RC that is legal to use in the current
733
  /// sub-target and has the same spill size.
734
  /// The returned register class can be used to create virtual registers which
735
  /// means that all its registers can be copied and spilled.
736
  virtual const TargetRegisterClass *
737
  getLargestLegalSuperClass(const TargetRegisterClass *RC,
738
2.34M
                            const MachineFunction &) const {
739
2.34M
    /// The default implementation is very conservative and doesn't allow the
740
2.34M
    /// register allocator to inflate register classes.
741
2.34M
    return RC;
742
2.34M
  }
743
744
  /// Return the register pressure "high water mark" for the specific register
745
  /// class. The scheduler is in high register pressure mode (for the specific
746
  /// register class) if it goes over the limit.
747
  ///
748
  /// Note: this is the old register pressure model that relies on a manually
749
  /// specified representative register class per value type.
750
  virtual unsigned getRegPressureLimit(const TargetRegisterClass *RC,
751
1.39k
                                       MachineFunction &MF) const {
752
1.39k
    return 0;
753
1.39k
  }
754
755
  /// Return a heuristic for the machine scheduler to compare the profitability
756
  /// of increasing one register pressure set versus another.  The scheduler
757
  /// will prefer increasing the register pressure of the set which returns
758
  /// the largest value for this function.
759
  virtual unsigned getRegPressureSetScore(const MachineFunction &MF,
760
4.87M
                                          unsigned PSetID) const {
761
4.87M
    return PSetID;
762
4.87M
  }
763
764
  /// Get the weight in units of pressure for this register class.
765
  virtual const RegClassWeight &getRegClassWeight(
766
    const TargetRegisterClass *RC) const = 0;
767
768
  /// Returns size in bits of a phys/virtual/generic register.
769
  unsigned getRegSizeInBits(unsigned Reg, const MachineRegisterInfo &MRI) const;
770
771
  /// Get the weight in units of pressure for this register unit.
772
  virtual unsigned getRegUnitWeight(unsigned RegUnit) const = 0;
773
774
  /// Get the number of dimensions of register pressure.
775
  virtual unsigned getNumRegPressureSets() const = 0;
776
777
  /// Get the name of this register unit pressure set.
778
  virtual const char *getRegPressureSetName(unsigned Idx) const = 0;
779
780
  /// Get the register unit pressure limit for this dimension.
781
  /// This limit must be adjusted dynamically for reserved registers.
782
  virtual unsigned getRegPressureSetLimit(const MachineFunction &MF,
783
                                          unsigned Idx) const = 0;
784
785
  /// Get the dimensions of register pressure impacted by this register class.
786
  /// Returns a -1 terminated array of pressure set IDs.
787
  virtual const int *getRegClassPressureSets(
788
    const TargetRegisterClass *RC) const = 0;
789
790
  /// Get the dimensions of register pressure impacted by this register unit.
791
  /// Returns a -1 terminated array of pressure set IDs.
792
  virtual const int *getRegUnitPressureSets(unsigned RegUnit) const = 0;
793
794
  /// Get a list of 'hint' registers that the register allocator should try
795
  /// first when allocating a physical register for the virtual register
796
  /// VirtReg. These registers are effectively moved to the front of the
797
  /// allocation order. If true is returned, regalloc will try to only use
798
  /// hints to the greatest extent possible even if it means spilling.
799
  ///
800
  /// The Order argument is the allocation order for VirtReg's register class
801
  /// as returned from RegisterClassInfo::getOrder(). The hint registers must
802
  /// come from Order, and they must not be reserved.
803
  ///
804
  /// The default implementation of this function will only add target
805
  /// independent register allocation hints. Targets that override this
806
  /// function should typically call this default implementation as well and
807
  /// expect to see generic copy hints added.
808
  virtual bool getRegAllocationHints(unsigned VirtReg,
809
                                     ArrayRef<MCPhysReg> Order,
810
                                     SmallVectorImpl<MCPhysReg> &Hints,
811
                                     const MachineFunction &MF,
812
                                     const VirtRegMap *VRM = nullptr,
813
                                     const LiveRegMatrix *Matrix = nullptr)
814
    const;
815
816
  /// A callback to allow target a chance to update register allocation hints
817
  /// when a register is "changed" (e.g. coalesced) to another register.
818
  /// e.g. On ARM, some virtual registers should target register pairs,
819
  /// if one of pair is coalesced to another register, the allocation hint of
820
  /// the other half of the pair should be changed to point to the new register.
821
  virtual void updateRegAllocHint(unsigned Reg, unsigned NewReg,
822
3.93M
                                  MachineFunction &MF) const {
823
3.93M
    // Do nothing.
824
3.93M
  }
825
826
  /// Allow the target to reverse allocation order of local live ranges. This
827
  /// will generally allocate shorter local live ranges first. For targets with
828
  /// many registers, this could reduce regalloc compile time by a large
829
  /// factor. It is disabled by default for three reasons:
830
  /// (1) Top-down allocation is simpler and easier to debug for targets that
831
  /// don't benefit from reversing the order.
832
  /// (2) Bottom-up allocation could result in poor evicition decisions on some
833
  /// targets affecting the performance of compiled code.
834
  /// (3) Bottom-up allocation is no longer guaranteed to optimally color.
835
9.01M
  virtual bool reverseLocalAssignment() const { return false; }
836
837
  /// Allow the target to override the cost of using a callee-saved register for
838
  /// the first time. Default value of 0 means we will use a callee-saved
839
  /// register if it is available.
840
185k
  virtual unsigned getCSRFirstUseCost() const { return 0; }
841
842
  /// Returns true if the target requires (and can make use of) the register
843
  /// scavenger.
844
327k
  virtual bool requiresRegisterScavenging(const MachineFunction &MF) const {
845
327k
    return false;
846
327k
  }
847
848
  /// Returns true if the target wants to use frame pointer based accesses to
849
  /// spill to the scavenger emergency spill slot.
850
34.7k
  virtual bool useFPForScavengingIndex(const MachineFunction &MF) const {
851
34.7k
    return true;
852
34.7k
  }
853
854
  /// Returns true if the target requires post PEI scavenging of registers for
855
  /// materializing frame index constants.
856
135k
  virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const {
857
135k
    return false;
858
135k
  }
859
860
  /// Returns true if the target requires using the RegScavenger directly for
861
  /// frame elimination despite using requiresFrameIndexScavenging.
862
  virtual bool requiresFrameIndexReplacementScavenging(
863
451k
      const MachineFunction &MF) const {
864
451k
    return false;
865
451k
  }
866
867
  /// Returns true if the target wants the LocalStackAllocation pass to be run
868
  /// and virtual base registers used for more efficient stack access.
869
162k
  virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const {
870
162k
    return false;
871
162k
  }
872
873
  /// Return true if target has reserved a spill slot in the stack frame of
874
  /// the given function for the specified register. e.g. On x86, if the frame
875
  /// register is required, the first fixed stack object is reserved as its
876
  /// spill slot. This tells PEI not to create a new stack frame
877
  /// object for the given register. It should be called only after
878
  /// determineCalleeSaves().
879
  virtual bool hasReservedSpillSlot(const MachineFunction &MF, unsigned Reg,
880
1.34M
                                    int &FrameIdx) const {
881
1.34M
    return false;
882
1.34M
  }
883
884
  /// Returns true if the live-ins should be tracked after register allocation.
885
7.84k
  virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
886
7.84k
    return false;
887
7.84k
  }
888
889
  /// True if the stack can be realigned for the target.
890
  virtual bool canRealignStack(const MachineFunction &MF) const;
891
892
  /// True if storage within the function requires the stack pointer to be
893
  /// aligned more than the normal calling convention calls for.
894
  /// This cannot be overriden by the target, but canRealignStack can be
895
  /// overridden.
896
  bool needsStackRealignment(const MachineFunction &MF) const;
897
898
  /// Get the offset from the referenced frame index in the instruction,
899
  /// if there is one.
900
  virtual int64_t getFrameIndexInstrOffset(const MachineInstr *MI,
901
1.82k
                                           int Idx) const {
902
1.82k
    return 0;
903
1.82k
  }
904
905
  /// Returns true if the instruction's frame index reference would be better
906
  /// served by a base register other than FP or SP.
907
  /// Used by LocalStackFrameAllocation to determine which frame index
908
  /// references it should create new base registers for.
909
0
  virtual bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const {
910
0
    return false;
911
0
  }
912
913
  /// Insert defining instruction(s) for BaseReg to be a pointer to FrameIdx
914
  /// before insertion point I.
915
  virtual void materializeFrameBaseRegister(MachineBasicBlock *MBB,
916
                                            unsigned BaseReg, int FrameIdx,
917
0
                                            int64_t Offset) const {
918
0
    llvm_unreachable("materializeFrameBaseRegister does not exist on this "
919
0
                     "target");
920
0
  }
921
922
  /// Resolve a frame index operand of an instruction
923
  /// to reference the indicated base register plus offset instead.
924
  virtual void resolveFrameIndex(MachineInstr &MI, unsigned BaseReg,
925
0
                                 int64_t Offset) const {
926
0
    llvm_unreachable("resolveFrameIndex does not exist on this target");
927
0
  }
928
929
  /// Determine whether a given base register plus offset immediate is
930
  /// encodable to resolve a frame index.
931
  virtual bool isFrameOffsetLegal(const MachineInstr *MI, unsigned BaseReg,
932
0
                                  int64_t Offset) const {
933
0
    llvm_unreachable("isFrameOffsetLegal does not exist on this target");
934
0
  }
935
936
  /// Spill the register so it can be used by the register scavenger.
937
  /// Return true if the register was spilled, false otherwise.
938
  /// If this function does not spill the register, the scavenger
939
  /// will instead spill it to the emergency spill slot.
940
  virtual bool saveScavengerRegister(MachineBasicBlock &MBB,
941
                                     MachineBasicBlock::iterator I,
942
                                     MachineBasicBlock::iterator &UseMI,
943
                                     const TargetRegisterClass *RC,
944
27
                                     unsigned Reg) const {
945
27
    return false;
946
27
  }
947
948
  /// This method must be overriden to eliminate abstract frame indices from
949
  /// instructions which may use them. The instruction referenced by the
950
  /// iterator contains an MO_FrameIndex operand which must be eliminated by
951
  /// this method. This method may modify or replace the specified instruction,
952
  /// as long as it keeps the iterator pointing at the finished product.
953
  /// SPAdj is the SP adjustment due to call frame setup instruction.
954
  /// FIOperandNum is the FI operand number.
955
  virtual void eliminateFrameIndex(MachineBasicBlock::iterator MI,
956
                                   int SPAdj, unsigned FIOperandNum,
957
                                   RegScavenger *RS = nullptr) const = 0;
958
959
  /// Return the assembly name for \p Reg.
960
109M
  virtual StringRef getRegAsmName(unsigned Reg) const {
961
109M
    // FIXME: We are assuming that the assembly name is equal to the TableGen
962
109M
    // name converted to lower case
963
109M
    //
964
109M
    // The TableGen name is the name of the definition for this register in the
965
109M
    // target's tablegen files.  For example, the TableGen name of
966
109M
    // def EAX : Register <...>; is "EAX"
967
109M
    return StringRef(getName(Reg));
968
109M
  }
969
970
  //===--------------------------------------------------------------------===//
971
  /// Subtarget Hooks
972
973
  /// SrcRC and DstRC will be morphed into NewRC if this returns true.
974
  virtual bool shouldCoalesce(MachineInstr *MI,
975
                              const TargetRegisterClass *SrcRC,
976
                              unsigned SubReg,
977
                              const TargetRegisterClass *DstRC,
978
                              unsigned DstSubReg,
979
                              const TargetRegisterClass *NewRC,
980
                              LiveIntervals &LIS) const
981
3.93M
  { return true; }
982
983
  //===--------------------------------------------------------------------===//
984
  /// Debug information queries.
985
986
  /// getFrameRegister - This method should return the register used as a base
987
  /// for values allocated in the current stack frame.
988
  virtual unsigned getFrameRegister(const MachineFunction &MF) const = 0;
989
990
  /// Mark a register and all its aliases as reserved in the given set.
991
  void markSuperRegs(BitVector &RegisterSet, unsigned Reg) const;
992
993
  /// Returns true if for every register in the set all super registers are part
994
  /// of the set as well.
995
  bool checkAllSuperRegsMarked(const BitVector &RegisterSet,
996
      ArrayRef<MCPhysReg> Exceptions = ArrayRef<MCPhysReg>()) const;
997
998
  virtual const TargetRegisterClass *
999
  getConstrainedRegClassForOperand(const MachineOperand &MO,
1000
0
                                   const MachineRegisterInfo &MRI) const {
1001
0
    return nullptr;
1002
0
  }
1003
};
1004
1005
//===----------------------------------------------------------------------===//
1006
//                           SuperRegClassIterator
1007
//===----------------------------------------------------------------------===//
1008
//
1009
// Iterate over the possible super-registers for a given register class. The
1010
// iterator will visit a list of pairs (Idx, Mask) corresponding to the
1011
// possible classes of super-registers.
1012
//
1013
// Each bit mask will have at least one set bit, and each set bit in Mask
1014
// corresponds to a SuperRC such that:
1015
//
1016
//   For all Reg in SuperRC: Reg:Idx is in RC.
1017
//
1018
// The iterator can include (O, RC->getSubClassMask()) as the first entry which
1019
// also satisfies the above requirement, assuming Reg:0 == Reg.
1020
//
1021
class SuperRegClassIterator {
1022
  const unsigned RCMaskWords;
1023
  unsigned SubReg = 0;
1024
  const uint16_t *Idx;
1025
  const uint32_t *Mask;
1026
1027
public:
1028
  /// Create a SuperRegClassIterator that visits all the super-register classes
1029
  /// of RC. When IncludeSelf is set, also include the (0, sub-classes) entry.
1030
  SuperRegClassIterator(const TargetRegisterClass *RC,
1031
                        const TargetRegisterInfo *TRI,
1032
                        bool IncludeSelf = false)
1033
    : RCMaskWords((TRI->getNumRegClasses() + 31) / 32),
1034
3.64M
      Idx(RC->getSuperRegIndices()), Mask(RC->getSubClassMask()) {
1035
3.64M
    if (!IncludeSelf)
1036
3.36M
      ++*this;
1037
3.64M
  }
1038
1039
  /// Returns true if this iterator is still pointing at a valid entry.
1040
8.83M
  bool isValid() const { return Idx; }
1041
1042
  /// Returns the current sub-register index.
1043
6.33M
  unsigned getSubReg() const { return SubReg; }
1044
1045
  /// Returns the bit mask of register classes that getSubReg() projects into
1046
  /// RC.
1047
  /// See TargetRegisterClass::getSubClassMask() for how to use it.
1048
6.27M
  const uint32_t *getMask() const { return Mask; }
1049
1050
  /// Advance iterator to the next entry.
1051
8.56M
  void operator++() {
1052
8.56M
    assert(isValid() && "Cannot move iterator past end.");
1053
8.56M
    Mask += RCMaskWords;
1054
8.56M
    SubReg = *Idx++;
1055
8.56M
    if (!SubReg)
1056
450k
      Idx = nullptr;
1057
8.56M
  }
1058
};
1059
1060
//===----------------------------------------------------------------------===//
1061
//                           BitMaskClassIterator
1062
//===----------------------------------------------------------------------===//
1063
/// This class encapuslates the logic to iterate over bitmask returned by
1064
/// the various RegClass related APIs.
1065
/// E.g., this class can be used to iterate over the subclasses provided by
1066
/// TargetRegisterClass::getSubClassMask or SuperRegClassIterator::getMask.
1067
class BitMaskClassIterator {
1068
  /// Total number of register classes.
1069
  const unsigned NumRegClasses;
1070
  /// Base index of CurrentChunk.
1071
  /// In other words, the number of bit we read to get at the
1072
  /// beginning of that chunck.
1073
  unsigned Base = 0;
1074
  /// Adjust base index of CurrentChunk.
1075
  /// Base index + how many bit we read within CurrentChunk.
1076
  unsigned Idx = 0;
1077
  /// Current register class ID.
1078
  unsigned ID = 0;
1079
  /// Mask we are iterating over.
1080
  const uint32_t *Mask;
1081
  /// Current chunk of the Mask we are traversing.
1082
  uint32_t CurrentChunk;
1083
1084
  /// Move ID to the next set bit.
1085
290k
  void moveToNextID() {
1086
290k
    // If the current chunk of memory is empty, move to the next one,
1087
290k
    // while making sure we do not go pass the number of register
1088
290k
    // classes.
1089
724k
    while (!CurrentChunk) {
1090
579k
      // Move to the next chunk.
1091
579k
      Base += 32;
1092
579k
      if (Base >= NumRegClasses) {
1093
144k
        ID = NumRegClasses;
1094
144k
        return;
1095
144k
      }
1096
434k
      CurrentChunk = *++Mask;
1097
434k
      Idx = Base;
1098
434k
    }
1099
290k
    // Otherwise look for the first bit set from the right
1100
290k
    // (representation of the class ID is big endian).
1101
290k
    // See getSubClassMask for more details on the representation.
1102
290k
    unsigned Offset = countTrailingZeros(CurrentChunk);
1103
145k
    // Add the Offset to the adjusted base number of this chunk: Idx.
1104
145k
    // This is the ID of the register class.
1105
145k
    ID = Idx + Offset;
1106
145k
1107
145k
    // Consume the zeros, if any, and the bit we just read
1108
145k
    // so that we are at the right spot for the next call.
1109
145k
    // Do not do Offset + 1 because Offset may be 31 and 32
1110
145k
    // will be UB for the shift, though in that case we could
1111
145k
    // have make the chunk being equal to 0, but that would
1112
145k
    // have introduced a if statement.
1113
145k
    moveNBits(Offset);
1114
145k
    moveNBits(1);
1115
145k
  }
1116
1117
  /// Move \p NumBits Bits forward in CurrentChunk.
1118
290k
  void moveNBits(unsigned NumBits) {
1119
290k
    assert(NumBits < 32 && "Undefined behavior spotted!");
1120
290k
    // Consume the bit we read for the next call.
1121
290k
    CurrentChunk >>= NumBits;
1122
290k
    // Adjust the base for the chunk.
1123
290k
    Idx += NumBits;
1124
290k
  }
1125
1126
public:
1127
  /// Create a BitMaskClassIterator that visits all the register classes
1128
  /// represented by \p Mask.
1129
  ///
1130
  /// \pre \p Mask != nullptr
1131
  BitMaskClassIterator(const uint32_t *Mask, const TargetRegisterInfo &TRI)
1132
145k
      : NumRegClasses(TRI.getNumRegClasses()), Mask(Mask), CurrentChunk(*Mask) {
1133
145k
    // Move to the first ID.
1134
145k
    moveToNextID();
1135
145k
  }
1136
1137
  /// Returns true if this iterator is still pointing at a valid entry.
1138
290k
  bool isValid() const { return getID() != NumRegClasses; }
1139
1140
  /// Returns the current register class ID.
1141
435k
  unsigned getID() const { return ID; }
1142
1143
  /// Advance iterator to the next entry.
1144
145k
  void operator++() {
1145
145k
    assert(isValid() && "Cannot move iterator past end.");
1146
145k
    moveToNextID();
1147
145k
  }
1148
};
1149
1150
// This is useful when building IndexedMaps keyed on virtual registers
1151
struct VirtReg2IndexFunctor {
1152
  using argument_type = unsigned;
1153
2.47G
  unsigned operator()(unsigned Reg) const {
1154
2.47G
    return TargetRegisterInfo::virtReg2Index(Reg);
1155
2.47G
  }
1156
};
1157
1158
/// Prints virtual and physical registers with or without a TRI instance.
1159
///
1160
/// The format is:
1161
///   %noreg          - NoRegister
1162
///   %5              - a virtual register.
1163
///   %5:sub_8bit     - a virtual register with sub-register index (with TRI).
1164
///   %eax            - a physical register
1165
///   %physreg17      - a physical register when no TRI instance given.
1166
///
1167
/// Usage: OS << printReg(Reg, TRI, SubRegIdx) << '\n';
1168
Printable printReg(unsigned Reg, const TargetRegisterInfo *TRI = nullptr,
1169
                   unsigned SubIdx = 0,
1170
                   const MachineRegisterInfo *MRI = nullptr);
1171
1172
/// Create Printable object to print register units on a \ref raw_ostream.
1173
///
1174
/// Register units are named after their root registers:
1175
///
1176
///   al      - Single root.
1177
///   fp0~st7 - Dual roots.
1178
///
1179
/// Usage: OS << printRegUnit(Unit, TRI) << '\n';
1180
Printable printRegUnit(unsigned Unit, const TargetRegisterInfo *TRI);
1181
1182
/// Create Printable object to print virtual registers and physical
1183
/// registers on a \ref raw_ostream.
1184
Printable printVRegOrUnit(unsigned VRegOrUnit, const TargetRegisterInfo *TRI);
1185
1186
/// Create Printable object to print register classes or register banks
1187
/// on a \ref raw_ostream.
1188
Printable printRegClassOrBank(unsigned Reg, const MachineRegisterInfo &RegInfo,
1189
                              const TargetRegisterInfo *TRI);
1190
1191
} // end namespace llvm
1192
1193
#endif // LLVM_CODEGEN_TARGETREGISTERINFO_H