LLVM 20.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
33#include "llvm/Support/Format.h"
37
38namespace llvm {
39
40 struct LaneBitmask {
41 // When changing the underlying type, change the format string as well.
42 using Type = uint64_t;
43 enum : unsigned { BitWidth = 8*sizeof(Type) };
44 constexpr static const char *const FormatStr = "%016llX";
45
46 constexpr LaneBitmask() = default;
47 explicit constexpr LaneBitmask(Type V) : Mask(V) {}
48
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; }
55
56 constexpr LaneBitmask operator~() const {
57 return LaneBitmask(~Mask);
58 }
59 constexpr LaneBitmask operator|(LaneBitmask M) const {
60 return LaneBitmask(Mask | M.Mask);
61 }
62 constexpr LaneBitmask operator&(LaneBitmask M) const {
63 return LaneBitmask(Mask & M.Mask);
64 }
66 Mask |= M.Mask;
67 return *this;
68 }
70 Mask &= M.Mask;
71 return *this;
72 }
73
74 constexpr Type getAsInteger() const { return Mask; }
75
76 unsigned getNumLanes() const { return llvm::popcount(Mask); }
77 unsigned getHighestLane() const {
78 return Log2_64(Mask);
79 }
80
81 static constexpr LaneBitmask getNone() { return LaneBitmask(0); }
82 static constexpr LaneBitmask getAll() { return ~LaneBitmask(0); }
83 static constexpr LaneBitmask getLane(unsigned Lane) {
84 return LaneBitmask(Type(1) << Lane);
85 }
86
87 private:
88 Type Mask = 0;
89 };
90
91 /// Create Printable object to print LaneBitmasks on a \ref raw_ostream.
93 return Printable([LaneMask](raw_ostream &OS) {
95 });
96 }
97
98} // end namespace llvm
99
100#endif // LLVM_MC_LANEBITMASK_H
raw_pwrite_stream & OS
Simple wrapper around std::function<void(raw_ostream&)>.
Definition: Printable.h:38
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
int popcount(T Value) noexcept
Count the number of set bits in a value.
Definition: bit.h:385
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
Definition: LaneBitmask.h:92
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:346
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:125
LaneBitmask & operator&=(LaneBitmask M)
Definition: LaneBitmask.h:69
constexpr bool operator!=(LaneBitmask M) const
Definition: LaneBitmask.h:50
constexpr LaneBitmask(Type V)
Definition: LaneBitmask.h:47
constexpr LaneBitmask operator|(LaneBitmask M) const
Definition: LaneBitmask.h:59
constexpr LaneBitmask()=default
static constexpr LaneBitmask getLane(unsigned Lane)
Definition: LaneBitmask.h:83
LaneBitmask & operator|=(LaneBitmask M)
Definition: LaneBitmask.h:65
static constexpr LaneBitmask getAll()
Definition: LaneBitmask.h:82
constexpr bool operator<(LaneBitmask M) const
Definition: LaneBitmask.h:51
constexpr bool none() const
Definition: LaneBitmask.h:52
constexpr bool any() const
Definition: LaneBitmask.h:53
constexpr bool all() const
Definition: LaneBitmask.h:54
static constexpr LaneBitmask getNone()
Definition: LaneBitmask.h:81
constexpr LaneBitmask operator~() const
Definition: LaneBitmask.h:56
unsigned getNumLanes() const
Definition: LaneBitmask.h:76
constexpr LaneBitmask operator&(LaneBitmask M) const
Definition: LaneBitmask.h:62
static constexpr const char *const FormatStr
Definition: LaneBitmask.h:44
constexpr Type getAsInteger() const
Definition: LaneBitmask.h:74
unsigned getHighestLane() const
Definition: LaneBitmask.h:77