Go to the documentation of this file.
21 #ifndef LLVM_SUPPORT_ALIGNMENT_H_
22 #define LLVM_SUPPORT_ALIGNMENT_H_
33 #define ALIGN_CHECK_ISPOSITIVE(decl) \
34 assert(decl > 0 && (#decl " should be defined"))
41 uint8_t ShiftValue = 0;
68 constexpr
Align() =
default;
80 assert(ShiftValue < 64 &&
"Broken invariant");
89 assert(ShiftValue != 0 &&
"Undefined operation");
91 Out.ShiftValue = ShiftValue - 1;
97 return LogValue{
static_cast<uint8_t
>(CTLog2<kValue>())};
102 template <
typename T> constexpr
static Align Of() {
107 constexpr
Align(LogValue CA) : ShiftValue(CA.Log) {}
119 using UP = std::optional<Align>;
135 "Alignment is neither 0 nor a power of 2");
146 return SizeInBytes % Lhs.
value() == 0;
183 return alignTo(Size - Skew, A) + Skew;
188 uintptr_t ArithAddr =
reinterpret_cast<uintptr_t
>(
Addr);
189 assert(
static_cast<uintptr_t
>(ArithAddr + Alignment.
value() - 1) >=
192 return alignTo(ArithAddr, Alignment);
224 Out.ShiftValue =
Value - 1;
235 return Lhs.
value() == Rhs;
239 return Lhs.
value() != Rhs;
243 return Lhs.
value() <= Rhs;
247 return Lhs.
value() >= Rhs;
251 return Lhs.
value() < Rhs;
255 return Lhs.
value() > Rhs;
260 return Lhs.ShiftValue == Rhs.ShiftValue;
263 return Lhs.ShiftValue != Rhs.ShiftValue;
266 return Lhs.ShiftValue <= Rhs.ShiftValue;
269 return Lhs.ShiftValue >= Rhs.ShiftValue;
272 return Lhs.ShiftValue < Rhs.ShiftValue;
275 return Lhs.ShiftValue > Rhs.ShiftValue;
289 bool operator<=(MaybeAlign Lhs, MaybeAlign Rhs) =
delete;
290 bool operator>=(MaybeAlign Lhs, MaybeAlign Rhs) =
delete;
291 bool operator<(MaybeAlign Lhs, MaybeAlign Rhs) =
delete;
292 bool operator>(MaybeAlign Lhs, MaybeAlign Rhs) =
delete;
301 return (Lhs && Rhs && (*Lhs == *Rhs)) || (!Lhs && !Rhs);
323 #undef ALIGN_CHECK_ISPOSITIVE
327 #endif // LLVM_SUPPORT_ALIGNMENT_H_
friend bool operator<=(Align Lhs, Align Rhs)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
This is an optimization pass for GlobalISel generic memory operations.
bool operator<=(int64_t V1, const APSInt &V2)
std::string DebugStr(const Align &A)
uintptr_t alignAddr(const void *Addr, Align Alignment)
Aligns Addr to Alignment bytes, rounding up.
friend bool operator<(Align Lhs, Align Rhs)
friend bool operator>=(Align Lhs, Align Rhs)
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
bool operator!=(uint64_t V1, const APInt &V2)
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
constexpr Align(LogValue CA)
Constexpr constructor from LogValue type.
unsigned Log2(Align A)
Returns the log2 of the alignment.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
friend bool operator==(Align Lhs, Align Rhs)
Comparisons operators between Align.
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
constexpr MaybeAlign(std::nullopt_t None)
MaybeAlign()=default
Default is undefined.
This struct is a compact representation of a valid (non-zero power of two) alignment.
friend bool operator!=(Align Lhs, Align Rhs)
bool operator>=(int64_t V1, const APSInt &V2)
This is an important base class in LLVM.
constexpr static Align Of()
Allow constructions of constexpr Align from types.
constexpr Align()=default
Default is byte-aligned.
Align assumeAligned(uint64_t Value)
Treats the value 0 as a 1, so Align is always at least 1.
bool operator<(int64_t V1, const APSInt &V2)
friend unsigned Log2(Align)
Returns the log2 of the alignment.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator==(uint64_t V1, const APInt &V2)
Align & operator=(const Align &Other)=default
constexpr MaybeAlign(Align Value)
uint64_t offsetToAlignedAddr(const void *Addr, Align Alignment)
Returns the necessary adjustment for aligning Addr to Alignment bytes, rounding up.
friend bool operator>(Align Lhs, Align Rhs)
friend unsigned encode(struct MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
MaybeAlign & operator=(const MaybeAlign &Other)=default
constexpr std::nullopt_t None
uint64_t value() const
This is a hole in the type system and should not be abused.
bool isAddrAligned(Align Lhs, const void *Addr)
Checks that Addr is a multiple of the alignment.
constexpr static Align Constant()
Allow constructions of constexpr Align.
MaybeAlign decodeMaybeAlign(unsigned Value)
Dual operation of the encode function above.
std::optional< std::vector< StOtherPiece > > Other
friend struct MaybeAlign decodeMaybeAlign(unsigned Value)
Dual operation of the encode function above.
std::string to_string(const T &Value)
bool operator>(int64_t V1, const APSInt &V2)
MaybeAlign(uint64_t Value)
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
LLVM Value Representation.
#define ALIGN_CHECK_ISPOSITIVE(decl)