LLVM  4.0.0
LaneBitmask.h
Go to the documentation of this file.
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/Format.h"
34 #include "llvm/Support/Printable.h"
36 
37 namespace llvm {
38  struct LaneBitmask {
39  // When changing the underlying type, change the format string as well.
40  typedef unsigned Type;
41  enum : unsigned { BitWidth = 8*sizeof(Type) };
42  constexpr static const char *const FormatStr = "%08X";
43 
44  constexpr LaneBitmask() = default;
45  explicit constexpr LaneBitmask(Type V) : Mask(V) {}
46 
47  constexpr bool operator== (LaneBitmask M) const { return Mask == M.Mask; }
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 none() const { return Mask == 0; }
51  constexpr bool any() const { return Mask != 0; }
52  constexpr bool all() const { return ~Mask == 0; }
53 
54  constexpr LaneBitmask operator~() const {
55  return LaneBitmask(~Mask);
56  }
57  constexpr LaneBitmask operator|(LaneBitmask M) const {
58  return LaneBitmask(Mask | M.Mask);
59  }
60  constexpr LaneBitmask operator&(LaneBitmask M) const {
61  return LaneBitmask(Mask & M.Mask);
62  }
64  Mask |= M.Mask;
65  return *this;
66  }
68  Mask &= M.Mask;
69  return *this;
70  }
71 
72  constexpr Type getAsInteger() const { return Mask; }
73 
74  static LaneBitmask getNone() { return LaneBitmask(0); }
75  static LaneBitmask getAll() { return ~LaneBitmask(0); }
76 
77  private:
78  Type Mask = 0;
79  };
80 
81  /// Create Printable object to print LaneBitmasks on a \ref raw_ostream.
83  return Printable([LaneMask](raw_ostream &OS) {
84  OS << format(LaneBitmask::FormatStr, LaneMask.getAsInteger());
85  });
86  }
87 }
88 
89 #endif // LLVM_MC_LANEBITMASK_H
static LaneBitmask getAll()
Definition: LaneBitmask.h:75
constexpr bool any() const
Definition: LaneBitmask.h:51
static constexpr const char *const FormatStr
Definition: LaneBitmask.h:42
constexpr LaneBitmask()=default
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
LaneBitmask & operator|=(LaneBitmask M)
Definition: LaneBitmask.h:63
constexpr bool none() const
Definition: LaneBitmask.h:50
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
constexpr LaneBitmask operator&(LaneBitmask M) const
Definition: LaneBitmask.h:60
#define LLVM_ATTRIBUTE_UNUSED
Definition: Compiler.h:150
LaneBitmask & operator&=(LaneBitmask M)
Definition: LaneBitmask.h:67
constexpr LaneBitmask operator~() const
Definition: LaneBitmask.h:54
constexpr bool operator<(LaneBitmask M) const
Definition: LaneBitmask.h:49
constexpr Type getAsInteger() const
Definition: LaneBitmask.h:72
constexpr LaneBitmask operator|(LaneBitmask M) const
Definition: LaneBitmask.h:57
static LaneBitmask getNone()
Definition: LaneBitmask.h:74
constexpr bool all() const
Definition: LaneBitmask.h:52
static LLVM_ATTRIBUTE_UNUSED Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
Definition: LaneBitmask.h:82
constexpr bool operator!=(LaneBitmask M) const
Definition: LaneBitmask.h:48
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
constexpr bool operator==(LaneBitmask M) const
Definition: LaneBitmask.h:47
constexpr LaneBitmask(Type V)
Definition: LaneBitmask.h:45
Simple wrapper around std::function<void(raw_ostream&)>.
Definition: Printable.h:38