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"))
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;
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;
301 return (Lhs && Rhs && (*Lhs == *Rhs)) || (!Lhs && !Rhs);
313 return std::to_string(
A.value());
318 return std::to_string(MA->value());
323#undef ALIGN_CHECK_ISPOSITIVE
#define ALIGN_CHECK_ISPOSITIVE(decl)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static TripleVec::iterator emplace(TripleVec &Container, Triple &&T)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This is an important base class in LLVM.
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)
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.
friend bool operator>=(Align Lhs, Align Rhs)
constexpr Align(LogValue CA)
Constexpr constructor from LogValue type.
static constexpr Align Of()
Allow constructions of constexpr Align from types.
friend struct MaybeAlign decodeMaybeAlign(unsigned Value)
Dual operation of the encode function above.
Align & operator=(Align &&Other)=default
uint64_t value() const
This is a hole in the type system and should not be abused.
constexpr Align(Align &&Other)=default
friend bool operator<(Align Lhs, Align Rhs)
static constexpr Align Constant()
Allow constructions of constexpr Align.
Align & operator=(const Align &Other)=default
friend bool operator==(Align Lhs, Align Rhs)
Comparisons operators between Align.
friend bool operator<=(Align Lhs, Align Rhs)
constexpr Align()=default
Default is byte-aligned.
friend bool operator!=(Align Lhs, Align Rhs)
friend unsigned Log2(Align)
Returns the log2 of the alignment.
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