LaneBitmask.h revision 311142
1230557Sjimharris//===-- llvm/MC/LaneBitmask.h -----------------------------------*- C++ -*-===// 2230557Sjimharris// 3230557Sjimharris// The LLVM Compiler Infrastructure 4230557Sjimharris// 5230557Sjimharris// This file is distributed under the University of Illinois Open Source 6230557Sjimharris// License. See LICENSE.TXT for details. 7230557Sjimharris// 8230557Sjimharris//===----------------------------------------------------------------------===// 9230557Sjimharris/// 10230557Sjimharris/// \file 11230557Sjimharris/// A common definition of LaneBitmask for use in TableGen and CodeGen. 12230557Sjimharris/// 13230557Sjimharris/// A lane mask is a bitmask representing the covering of a register with 14230557Sjimharris/// sub-registers. 15230557Sjimharris/// 16230557Sjimharris/// This is typically used to track liveness at sub-register granularity. 17230557Sjimharris/// Lane masks for sub-register indices are similar to register units for 18230557Sjimharris/// physical registers. The individual bits in a lane mask can't be assigned 19230557Sjimharris/// any specific meaning. They can be used to check if two sub-register 20230557Sjimharris/// indices overlap. 21230557Sjimharris/// 22230557Sjimharris/// Iff the target has a register such that: 23230557Sjimharris/// 24230557Sjimharris/// getSubReg(Reg, A) overlaps getSubReg(Reg, B) 25230557Sjimharris/// 26230557Sjimharris/// then: 27230557Sjimharris/// 28230557Sjimharris/// (getSubRegIndexLaneMask(A) & getSubRegIndexLaneMask(B)) != 0 29230557Sjimharris 30230557Sjimharris#ifndef LLVM_MC_LANEBITMASK_H 31230557Sjimharris#define LLVM_MC_LANEBITMASK_H 32230557Sjimharris 33230557Sjimharris#include "llvm/Support/Format.h" 34230557Sjimharris#include "llvm/Support/Printable.h" 35230557Sjimharris#include "llvm/Support/raw_ostream.h" 36230557Sjimharris 37230557Sjimharrisnamespace llvm { 38230557Sjimharris struct LaneBitmask { 39230557Sjimharris // When changing the underlying type, change the format string as well. 40230557Sjimharris typedef unsigned Type; 41230557Sjimharris enum : unsigned { BitWidth = 8*sizeof(Type) }; 42230557Sjimharris constexpr static const char *const FormatStr = "%08X"; 43230557Sjimharris 44230557Sjimharris constexpr LaneBitmask() = default; 45230557Sjimharris explicit constexpr LaneBitmask(Type V) : Mask(V) {} 46230557Sjimharris 47230557Sjimharris constexpr bool operator== (LaneBitmask M) const { return Mask == M.Mask; } 48230557Sjimharris constexpr bool operator!= (LaneBitmask M) const { return Mask != M.Mask; } 49230557Sjimharris constexpr bool operator< (LaneBitmask M) const { return Mask < M.Mask; } 50230557Sjimharris constexpr bool none() const { return Mask == 0; } 51230557Sjimharris constexpr bool any() const { return Mask != 0; } 52230557Sjimharris constexpr bool all() const { return ~Mask == 0; } 53230557Sjimharris 54230557Sjimharris constexpr LaneBitmask operator~() const { 55230557Sjimharris return LaneBitmask(~Mask); 56230557Sjimharris } 57230557Sjimharris constexpr LaneBitmask operator|(LaneBitmask M) const { 58230557Sjimharris return LaneBitmask(Mask | M.Mask); 59230557Sjimharris } 60230557Sjimharris constexpr LaneBitmask operator&(LaneBitmask M) const { 61230557Sjimharris return LaneBitmask(Mask & M.Mask); 62230557Sjimharris } 63230557Sjimharris LaneBitmask &operator|=(LaneBitmask M) { 64230557Sjimharris Mask |= M.Mask; 65230557Sjimharris return *this; 66230557Sjimharris } 67230557Sjimharris LaneBitmask &operator&=(LaneBitmask M) { 68230557Sjimharris Mask &= M.Mask; 69230557Sjimharris return *this; 70230557Sjimharris } 71230557Sjimharris 72230557Sjimharris constexpr Type getAsInteger() const { return Mask; } 73230557Sjimharris 74230557Sjimharris static LaneBitmask getNone() { return LaneBitmask(0); } 75230557Sjimharris static LaneBitmask getAll() { return ~LaneBitmask(0); } 76230557Sjimharris 77230557Sjimharris private: 78230557Sjimharris Type Mask = 0; 79230557Sjimharris }; 80230557Sjimharris 81230557Sjimharris /// Create Printable object to print LaneBitmasks on a \ref raw_ostream. 82230557Sjimharris static LLVM_ATTRIBUTE_UNUSED Printable PrintLaneMask(LaneBitmask LaneMask) { 83230557Sjimharris return Printable([LaneMask](raw_ostream &OS) { 84230557Sjimharris OS << format(LaneBitmask::FormatStr, LaneMask.getAsInteger()); 85230557Sjimharris }); 86230557Sjimharris } 87230557Sjimharris} 88230557Sjimharris 89230557Sjimharris#endif // LLVM_MC_LANEBITMASK_H 90230557Sjimharris