Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/CodeGen/AllocationOrder.h
Line
Count
Source (jump to first uncovered line)
1
//===-- llvm/CodeGen/AllocationOrder.h - Allocation Order -*- 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 implements an allocation order for virtual registers.
11
//
12
// The preferred allocation order for a virtual register depends on allocation
13
// hints and target hooks. The AllocationOrder class encapsulates all of that.
14
//
15
//===----------------------------------------------------------------------===//
16
17
#ifndef LLVM_LIB_CODEGEN_ALLOCATIONORDER_H
18
#define LLVM_LIB_CODEGEN_ALLOCATIONORDER_H
19
20
#include "llvm/ADT/ArrayRef.h"
21
#include "llvm/ADT/STLExtras.h"
22
#include "llvm/MC/MCRegisterInfo.h"
23
24
namespace llvm {
25
26
class RegisterClassInfo;
27
class VirtRegMap;
28
class LiveRegMatrix;
29
30
class LLVM_LIBRARY_VISIBILITY AllocationOrder {
31
  SmallVector<MCPhysReg, 16> Hints;
32
  ArrayRef<MCPhysReg> Order;
33
  int Pos;
34
35
public:
36
  /// Create a new AllocationOrder for VirtReg.
37
  /// @param VirtReg      Virtual register to allocate for.
38
  /// @param VRM          Virtual register map for function.
39
  /// @param RegClassInfo Information about reserved and allocatable registers.
40
  AllocationOrder(unsigned VirtReg,
41
                  const VirtRegMap &VRM,
42
                  const RegisterClassInfo &RegClassInfo,
43
                  const LiveRegMatrix *Matrix);
44
45
  /// Get the allocation order without reordered hints.
46
1.04M
  ArrayRef<MCPhysReg> getOrder() const { return Order; }
47
48
  /// Return the next physical register in the allocation order, or 0.
49
  /// It is safe to call next() again after it returned 0, it will keep
50
  /// returning 0 until rewind() is called.
51
299M
  unsigned next(unsigned Limit = 0) {
52
299M
    if (Pos < 0)
53
5.46M
      return Hints.end()[Pos++];
54
294M
    
if (294M
!Limit294M
)
55
265M
      Limit = Order.size();
56
296M
    while (
Pos < int(Limit)296M
) {
57
289M
      unsigned Reg = Order[Pos++];
58
289M
      if (!isHint(Reg))
59
286M
        return Reg;
60
289M
    }
61
7.30M
    return 0;
62
299M
  }
63
64
  /// As next(), but allow duplicates to be returned, and stop before the
65
  /// Limit'th register in the RegisterClassInfo allocation order.
66
  ///
67
  /// This can produce more than Limit registers if there are hints.
68
0
  unsigned nextWithDups(unsigned Limit) {
69
0
    if (Pos < 0)
70
0
      return Hints.end()[Pos++];
71
0
    if (Pos < int(Limit))
72
0
      return Order[Pos++];
73
0
    return 0;
74
0
  }
75
76
  /// Start over from the beginning.
77
28.5M
  void rewind() { Pos = -int(Hints.size()); }
78
79
  /// Return true if the last register returned from next() was a preferred register.
80
10.7M
  bool isHint() const { return Pos <= 0; }
81
82
  /// Return true if PhysReg is a preferred register.
83
291M
  bool isHint(unsigned PhysReg) const { return is_contained(Hints, PhysReg); }
84
};
85
86
} // end namespace llvm
87
88
#endif