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"))
45 friend unsigned Log2(Align);
50 friend bool operator<(Align Lhs, Align Rhs);
51 friend bool operator>(Align Lhs, Align Rhs);
55 struct FromShiftValue {};
56 constexpr Align(FromShiftValue,
uint8_t Shift) : ShiftValue(Shift) {}
72 assert(ShiftValue < 64 &&
"Broken invariant");
81 assert(ShiftValue != 0 &&
"Undefined operation");
83 Out.ShiftValue = ShiftValue - 1;
88 template <
size_t kValue>
constexpr static Align
Constant() {
94 template <
typename T>
constexpr static Align
Of() {
108 using UP = std::optional<Align>;
124 "Alignment is neither 0 nor a power of 2");
135 return SizeInBytes % Lhs.
value() == 0;
140 return isAligned(Lhs,
reinterpret_cast<uintptr_t
>(Addr));
177 uintptr_t ArithAddr =
reinterpret_cast<uintptr_t
>(Addr);
178 assert(
static_cast<uintptr_t
>(ArithAddr + Alignment.
value() - 1) >=
181 return alignTo(ArithAddr, Alignment);
197inline unsigned Log2(Align
A) {
return A.ShiftValue; }
213 Out.ShiftValue =
Value - 1;
224 return Lhs.
value() == Rhs;
228 return Lhs.
value() != Rhs;
232 return Lhs.
value() <= Rhs;
236 return Lhs.
value() >= Rhs;
240 return Lhs.
value() < Rhs;
244 return Lhs.
value() > Rhs;
249 return Lhs.ShiftValue == Rhs.ShiftValue;
252 return Lhs.ShiftValue != Rhs.ShiftValue;
255 return Lhs.ShiftValue <= Rhs.ShiftValue;
258 return Lhs.ShiftValue >= Rhs.ShiftValue;
261 return Lhs.ShiftValue < Rhs.ShiftValue;
264 return Lhs.ShiftValue > Rhs.ShiftValue;
290 return (Lhs && Rhs && (*Lhs == *Rhs)) || (!Lhs && !Rhs);
302 return std::to_string(
A.value());
307 return std::to_string(MA->value());
312#undef ALIGN_CHECK_ISPOSITIVE
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define ALIGN_CHECK_ISPOSITIVE(decl)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static TripleVec::iterator emplace(TripleVec &Container, Triple &&T)
LLVM Value Representation.
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
unsigned encode(MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
bool operator!=(uint64_t V1, const APInt &V2)
bool operator>=(int64_t V1, const APSInt &V2)
constexpr size_t ConstantLog2()
Compile time Log2.
uint64_t offsetToAlignedAddr(const void *Addr, Align Alignment)
Returns the necessary adjustment for aligning Addr to Alignment bytes, rounding up.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
constexpr T MinAlign(U A, V B)
A and B are either alignments or offsets.
bool operator>(int64_t V1, const APSInt &V2)
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...
MaybeAlign decodeMaybeAlign(unsigned Value)
Dual operation of the encode function above.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
Align assumeAligned(uint64_t Value)
Treats the value 0 as a 1, so Align is always at least 1.
unsigned Log2(Align A)
Returns the log2 of the alignment.
bool operator<=(int64_t V1, const APSInt &V2)
bool isAddrAligned(Align Lhs, const void *Addr)
Checks that Addr is a multiple of the alignment.
uintptr_t alignAddr(const void *Addr, Align Alignment)
Aligns Addr to Alignment bytes, rounding up.
This struct is a compact representation of a valid (non-zero power of two) alignment.
friend unsigned encode(struct MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
constexpr Align & operator=(const Align &Other)=default
friend bool operator>=(Align Lhs, Align Rhs)
static constexpr Align Of()
Allow constructions of constexpr Align from types.
friend struct MaybeAlign decodeMaybeAlign(unsigned Value)
Dual operation of the encode function above.
constexpr Align(Align &&Other)=default
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
friend bool operator<(Align Lhs, Align Rhs)
static constexpr Align Constant()
Allow constructions of constexpr Align.
friend bool operator==(Align Lhs, Align Rhs)
Comparisons operators between Align.
friend bool operator<=(Align Lhs, Align Rhs)
friend unsigned Log2(Align)
Returns the log2 of the alignment.
constexpr Align()=default
Default is byte-aligned.
constexpr Align & operator=(Align &&Other)=default
friend struct MaybeAlign
The log2 of the required alignment.
friend bool operator!=(Align Lhs, Align Rhs)
constexpr Align(const Align &Other)=default
Do not perform checks in case of copy/move construct/assign, because the checks have been performed w...
friend bool operator>(Align Lhs, Align Rhs)
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
MaybeAlign(MaybeAlign &&Other)=default
constexpr MaybeAlign(Align Value)
constexpr MaybeAlign(std::nullopt_t None)
MaybeAlign(const MaybeAlign &Other)=default
Do not perform checks in case of copy/move construct/assign, because the checks have been performed w...
MaybeAlign(uint64_t Value)
MaybeAlign()=default
Default is undefined.
MaybeAlign & operator=(MaybeAlign &&Other)=default
MaybeAlign & operator=(const MaybeAlign &Other)=default