Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:12

0001 //===- llvm/MC/LaneBitmask.h ------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// \file
0010 /// A common definition of LaneBitmask for use in TableGen and CodeGen.
0011 ///
0012 /// A lane mask is a bitmask representing the covering of a register with
0013 /// sub-registers.
0014 ///
0015 /// This is typically used to track liveness at sub-register granularity.
0016 /// Lane masks for sub-register indices are similar to register units for
0017 /// physical registers. The individual bits in a lane mask can't be assigned
0018 /// any specific meaning. They can be used to check if two sub-register
0019 /// indices overlap.
0020 ///
0021 /// Iff the target has a register such that:
0022 ///
0023 ///   getSubReg(Reg, A) overlaps getSubReg(Reg, B)
0024 ///
0025 /// then:
0026 ///
0027 ///   (getSubRegIndexLaneMask(A) & getSubRegIndexLaneMask(B)) != 0
0028 
0029 #ifndef LLVM_MC_LANEBITMASK_H
0030 #define LLVM_MC_LANEBITMASK_H
0031 
0032 #include "llvm/Support/Compiler.h"
0033 #include "llvm/Support/Format.h"
0034 #include "llvm/Support/MathExtras.h"
0035 #include "llvm/Support/Printable.h"
0036 #include "llvm/Support/raw_ostream.h"
0037 
0038 namespace llvm {
0039 
0040   struct LaneBitmask {
0041     // When changing the underlying type, change the format string as well.
0042     using Type = uint64_t;
0043     enum : unsigned { BitWidth = 8*sizeof(Type) };
0044     constexpr static const char *const FormatStr = "%016llX";
0045 
0046     constexpr LaneBitmask() = default;
0047     explicit constexpr LaneBitmask(Type V) : Mask(V) {}
0048 
0049     constexpr bool operator== (LaneBitmask M) const { return Mask == M.Mask; }
0050     constexpr bool operator!= (LaneBitmask M) const { return Mask != M.Mask; }
0051     constexpr bool operator< (LaneBitmask M)  const { return Mask < M.Mask; }
0052     constexpr bool none() const { return Mask == 0; }
0053     constexpr bool any()  const { return Mask != 0; }
0054     constexpr bool all()  const { return ~Mask == 0; }
0055 
0056     constexpr LaneBitmask operator~() const {
0057       return LaneBitmask(~Mask);
0058     }
0059     constexpr LaneBitmask operator|(LaneBitmask M) const {
0060       return LaneBitmask(Mask | M.Mask);
0061     }
0062     constexpr LaneBitmask operator&(LaneBitmask M) const {
0063       return LaneBitmask(Mask & M.Mask);
0064     }
0065     LaneBitmask &operator|=(LaneBitmask M) {
0066       Mask |= M.Mask;
0067       return *this;
0068     }
0069     LaneBitmask &operator&=(LaneBitmask M) {
0070       Mask &= M.Mask;
0071       return *this;
0072     }
0073 
0074     constexpr Type getAsInteger() const { return Mask; }
0075 
0076     unsigned getNumLanes() const { return llvm::popcount(Mask); }
0077     unsigned getHighestLane() const {
0078       return Log2_64(Mask);
0079     }
0080 
0081     static constexpr LaneBitmask getNone() { return LaneBitmask(0); }
0082     static constexpr LaneBitmask getAll() { return ~LaneBitmask(0); }
0083     static constexpr LaneBitmask getLane(unsigned Lane) {
0084       return LaneBitmask(Type(1) << Lane);
0085     }
0086 
0087   private:
0088     Type Mask = 0;
0089   };
0090 
0091   /// Create Printable object to print LaneBitmasks on a \ref raw_ostream.
0092   inline Printable PrintLaneMask(LaneBitmask LaneMask) {
0093     return Printable([LaneMask](raw_ostream &OS) {
0094       OS << format(LaneBitmask::FormatStr, LaneMask.getAsInteger());
0095     });
0096   }
0097 
0098 } // end namespace llvm
0099 
0100 #endif // LLVM_MC_LANEBITMASK_H