1 //===- llvm/MC/LaneBitmask.h ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// A common definition of LaneBitmask for use in TableGen and CodeGen.
13 /// A lane mask is a bitmask representing the covering of a register with
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
22 /// Iff the target has a register such that:
24 /// getSubReg(Reg, A) overlaps getSubReg(Reg, B)
28 /// (getSubRegIndexLaneMask(A) & getSubRegIndexLaneMask(B)) != 0
30 #ifndef LLVM_MC_LANEBITMASK_H
31 #define LLVM_MC_LANEBITMASK_H
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"
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";
46 constexpr LaneBitmask() = default;
47 explicit constexpr LaneBitmask(Type V) : Mask(V) {}
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 operator< (LaneBitmask M) const { return Mask < M.Mask; }
52 constexpr bool none() const { return Mask == 0; }
53 constexpr bool any() const { return Mask != 0; }
54 constexpr bool all() const { return ~Mask == 0; }
56 constexpr LaneBitmask operator~() const {
57 return LaneBitmask(~Mask);
59 constexpr LaneBitmask operator|(LaneBitmask M) const {
60 return LaneBitmask(Mask | M.Mask);
62 constexpr LaneBitmask operator&(LaneBitmask M) const {
63 return LaneBitmask(Mask & M.Mask);
65 LaneBitmask &operator|=(LaneBitmask M) {
69 LaneBitmask &operator&=(LaneBitmask M) {
74 constexpr Type getAsInteger() const { return Mask; }
76 static LaneBitmask getNone() { return LaneBitmask(0); }
77 static LaneBitmask getAll() { return ~LaneBitmask(0); }
78 static LaneBitmask getLane(unsigned Lane) {
79 return LaneBitmask(Type(1) << Lane);
86 /// Create Printable object to print LaneBitmasks on a \ref raw_ostream.
87 static LLVM_ATTRIBUTE_UNUSED Printable PrintLaneMask(LaneBitmask LaneMask) {
88 return Printable([LaneMask](raw_ostream &OS) {
89 OS << format(LaneBitmask::FormatStr, LaneMask.getAsInteger());
93 } // end namespace llvm
95 #endif // LLVM_MC_LANEBITMASK_H