LLVM  13.0.0git
LaneBitmask.h
Go to the documentation of this file.
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"
36 
37 namespace llvm {
38 
39  struct LaneBitmask {
40  // When changing the underlying type, change the format string as well.
41  using Type = uint64_t;
42  enum : unsigned { BitWidth = 8*sizeof(Type) };
43  constexpr static const char *const FormatStr = "%016llX";
44 
45  constexpr LaneBitmask() = default;
46  explicit constexpr LaneBitmask(Type V) : Mask(V) {}
47 
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; }
54 
55  constexpr LaneBitmask operator~() const {
56  return LaneBitmask(~Mask);
57  }
58  constexpr LaneBitmask operator|(LaneBitmask M) const {
59  return LaneBitmask(Mask | M.Mask);
60  }
61  constexpr LaneBitmask operator&(LaneBitmask M) const {
62  return LaneBitmask(Mask & M.Mask);
63  }
65  Mask |= M.Mask;
66  return *this;
67  }
69  Mask &= M.Mask;
70  return *this;
71  }
72 
73  constexpr Type getAsInteger() const { return Mask; }
74 
75  unsigned getNumLanes() const {
76  return countPopulation(Mask);
77  }
78  unsigned getHighestLane() const {
79  return Log2_64(Mask);
80  }
81 
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);
86  }
87 
88  private:
89  Type Mask = 0;
90  };
91 
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());
96  });
97  }
98 
99 } // end namespace llvm
100 
101 #endif // LLVM_MC_LANEBITMASK_H
llvm::LaneBitmask
Definition: LaneBitmask.h:39
llvm::LaneBitmask::BitWidth
@ BitWidth
Definition: LaneBitmask.h:42
llvm
Definition: AllocatorList.h:23
llvm::LaneBitmask::LaneBitmask
constexpr LaneBitmask(Type V)
Definition: LaneBitmask.h:46
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
Printable.h
llvm::LaneBitmask::operator<
constexpr bool operator<(LaneBitmask M) const
Definition: LaneBitmask.h:50
llvm::LaneBitmask::getNumLanes
unsigned getNumLanes() const
Definition: LaneBitmask.h:75
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::LaneBitmask::LaneBitmask
constexpr LaneBitmask()=default
llvm::LaneBitmask::FormatStr
constexpr static const char *const FormatStr
Definition: LaneBitmask.h:43
Format.h
llvm::Log2_64
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
Definition: MathExtras.h:602
llvm::LaneBitmask::operator|=
LaneBitmask & operator|=(LaneBitmask M)
Definition: LaneBitmask.h:64
llvm::LaneBitmask::getNone
static constexpr LaneBitmask getNone()
Definition: LaneBitmask.h:82
llvm::LaneBitmask::operator!=
constexpr bool operator!=(LaneBitmask M) const
Definition: LaneBitmask.h:49
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::PrintLaneMask
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
Definition: LaneBitmask.h:93
llvm::LaneBitmask::Type
uint64_t Type
Definition: LaneBitmask.h:41
llvm::LaneBitmask::operator~
constexpr LaneBitmask operator~() const
Definition: LaneBitmask.h:55
llvm::LaneBitmask::operator&=
LaneBitmask & operator&=(LaneBitmask M)
Definition: LaneBitmask.h:68
llvm::countPopulation
unsigned countPopulation(T Value)
Count the number of set bits in a value.
Definition: MathExtras.h:567
llvm::LaneBitmask::operator&
constexpr LaneBitmask operator&(LaneBitmask M) const
Definition: LaneBitmask.h:61
llvm::LaneBitmask::any
constexpr bool any() const
Definition: LaneBitmask.h:52
llvm::LaneBitmask::none
constexpr bool none() const
Definition: LaneBitmask.h:51
Compiler.h
llvm::LaneBitmask::getAsInteger
constexpr Type getAsInteger() const
Definition: LaneBitmask.h:73
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
llvm::LaneBitmask::operator==
constexpr bool operator==(LaneBitmask M) const
Definition: LaneBitmask.h:48
llvm::LaneBitmask::getLane
static constexpr LaneBitmask getLane(unsigned Lane)
Definition: LaneBitmask.h:84
llvm::LaneBitmask::all
constexpr bool all() const
Definition: LaneBitmask.h:53
llvm::LaneBitmask::operator|
constexpr LaneBitmask operator|(LaneBitmask M) const
Definition: LaneBitmask.h:58
llvm::Printable
Simple wrapper around std::function<void(raw_ostream&)>.
Definition: Printable.h:37
llvm::LaneBitmask::getHighestLane
unsigned getHighestLane() const
Definition: LaneBitmask.h:78
raw_ostream.h
llvm::LaneBitmask::getAll
static constexpr LaneBitmask getAll()
Definition: LaneBitmask.h:83