Coverage Report

Created: 2019-07-24 05:18

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