1 //===- llvm/MC/LaneBitmask.h ------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// A common definition of LaneBitmask for use in TableGen and CodeGen.
12 /// A lane mask is a bitmask representing the covering of a register with
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
21 /// Iff the target has a register such that:
23 /// getSubReg(Reg, A) overlaps getSubReg(Reg, B)
27 /// (getSubRegIndexLaneMask(A) & getSubRegIndexLaneMask(B)) != 0
29 #ifndef LLVM_MC_LANEBITMASK_H
30 #define LLVM_MC_LANEBITMASK_H
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"
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";
45 constexpr LaneBitmask() = default;
46 explicit constexpr LaneBitmask(Type V
) : Mask(V
) {}
48 constexpr bool operator== (LaneBitmask M
) const { return Mask
== M
.Mask
; }
49 constexpr bool operator!= (LaneBitmask M
) const { return Mask
!= M
.Mask
; }
50 constexpr bool operator< (LaneBitmask M
) const { return Mask
< M
.Mask
; }
51 constexpr bool none() const { return Mask
== 0; }
52 constexpr bool any() const { return Mask
!= 0; }
53 constexpr bool all() const { return ~Mask
== 0; }
55 constexpr LaneBitmask
operator~() const {
56 return LaneBitmask(~Mask
);
58 constexpr LaneBitmask
operator|(LaneBitmask M
) const {
59 return LaneBitmask(Mask
| M
.Mask
);
61 constexpr LaneBitmask
operator&(LaneBitmask M
) const {
62 return LaneBitmask(Mask
& M
.Mask
);
64 LaneBitmask
&operator|=(LaneBitmask M
) {
68 LaneBitmask
&operator&=(LaneBitmask M
) {
73 constexpr Type
getAsInteger() const { return Mask
; }
75 unsigned getNumLanes() const {
76 return countPopulation(Mask
);
78 unsigned getHighestLane() const {
82 static constexpr LaneBitmask
getNone() { return LaneBitmask(0); }
83 static constexpr LaneBitmask
getAll() { return ~LaneBitmask(0); }
84 static constexpr LaneBitmask
getLane(unsigned Lane
) {
85 return LaneBitmask(Type(1) << Lane
);
92 /// Create Printable object to print LaneBitmasks on a \ref raw_ostream.
93 inline Printable
PrintLaneMask(LaneBitmask LaneMask
) {
94 return Printable([LaneMask
](raw_ostream
&OS
) {
95 OS
<< format(LaneBitmask::FormatStr
, LaneMask
.getAsInteger());
99 } // end namespace llvm
101 #endif // LLVM_MC_LANEBITMASK_H