Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/MC/LaneBitmask.h
Line
Count
Source
1
//===- llvm/MC/LaneBitmask.h ------------------------------------*- 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
/// \file
11
/// A common definition of LaneBitmask for use in TableGen and CodeGen.
12
///
13
/// A lane mask is a bitmask representing the covering of a register with
14
/// sub-registers.
15
///
16
/// This is typically used to track liveness at sub-register granularity.
17
/// Lane masks for sub-register indices are similar to register units for
18
/// physical registers. The individual bits in a lane mask can't be assigned
19
/// any specific meaning. They can be used to check if two sub-register
20
/// indices overlap.
21
///
22
/// Iff the target has a register such that:
23
///
24
///   getSubReg(Reg, A) overlaps getSubReg(Reg, B)
25
///
26
/// then:
27
///
28
///   (getSubRegIndexLaneMask(A) & getSubRegIndexLaneMask(B)) != 0
29
30
#ifndef LLVM_MC_LANEBITMASK_H
31
#define LLVM_MC_LANEBITMASK_H
32
33
#include "llvm/Support/Compiler.h"
34
#include "llvm/Support/Format.h"
35
#include "llvm/Support/Printable.h"
36
#include "llvm/Support/raw_ostream.h"
37
38
namespace llvm {
39
40
  struct LaneBitmask {
41
    // When changing the underlying type, change the format string as well.
42
    using Type = unsigned;
43
    enum : unsigned { BitWidth = 8*sizeof(Type) };
44
    constexpr static const char *const FormatStr = "%08X";
45
46
81.5M
    constexpr LaneBitmask() = default;
47
393M
    explicit constexpr LaneBitmask(Type V) : Mask(V) {}
48
49
10.5M
    constexpr bool operator== (LaneBitmask M) const { return Mask == M.Mask; }
50
376k
    constexpr bool operator!= (LaneBitmask M) const { return Mask != M.Mask; }
51
1.66M
    constexpr bool operator< (LaneBitmask M)  const { return Mask < M.Mask; }
52
92.0M
    constexpr bool none() const { return Mask == 0; }
53
102M
    constexpr bool any()  const { return Mask != 0; }
54
19.7M
    constexpr bool all()  const { return ~Mask == 0; }
55
56
137M
    constexpr LaneBitmask operator~() const {
57
137M
      return LaneBitmask(~Mask);
58
137M
    }
59
23.8M
    constexpr LaneBitmask operator|(LaneBitmask M) const {
60
23.8M
      return LaneBitmask(Mask | M.Mask);
61
23.8M
    }
62
66.5M
    constexpr LaneBitmask operator&(LaneBitmask M) const {
63
66.5M
      return LaneBitmask(Mask & M.Mask);
64
66.5M
    }
65
35.8M
    LaneBitmask &operator|=(LaneBitmask M) {
66
35.8M
      Mask |= M.Mask;
67
35.8M
      return *this;
68
35.8M
    }
69
18.5M
    LaneBitmask &operator&=(LaneBitmask M) {
70
18.5M
      Mask &= M.Mask;
71
18.5M
      return *this;
72
18.5M
    }
73
74
1.04M
    constexpr Type getAsInteger() const { return Mask; }
75
76
1.00M
    unsigned getNumLanes() const {
77
1.00M
      return countPopulation(Mask);
78
1.00M
    }
79
675
    unsigned getHighestLane() const {
80
675
      return Log2_32(Mask);
81
675
    }
82
83
62.5M
    static constexpr LaneBitmask getNone() { return LaneBitmask(0); }
84
102M
    static constexpr LaneBitmask getAll() { return ~LaneBitmask(0); }
85
395k
    static constexpr LaneBitmask getLane(unsigned Lane) {
86
395k
      return LaneBitmask(Type(1) << Lane);
87
395k
    }
88
89
  private:
90
    Type Mask = 0;
91
  };
92
93
  /// Create Printable object to print LaneBitmasks on a \ref raw_ostream.
94
1.60k
  inline Printable PrintLaneMask(LaneBitmask LaneMask) {
95
1.60k
    return Printable([LaneMask](raw_ostream &OS) {
96
1.60k
      OS << format(LaneBitmask::FormatStr, LaneMask.getAsInteger());
97
1.60k
    });
98
1.60k
  }
99
100
} // end namespace llvm
101
102
#endif // LLVM_MC_LANEBITMASK_H