21 #ifndef LLVM_SUPPORT_ALIGNMENT_H_ 22 #define LLVM_SUPPORT_ALIGNMENT_H_ 32 #define ALIGN_CHECK_ISPOSITIVE(decl) \ 33 assert(decl > 0 && (#decl " should be defined")) 34 #define ALIGN_CHECK_ISSET(decl) \ 35 assert(decl.hasValue() && (#decl " should be defined")) 42 uint8_t ShiftValue = 0;
69 constexpr
Align() =
default;
78 assert(Value > 0 &&
"Value must not be 0");
81 assert(ShiftValue < 64 &&
"Broken invariant");
86 uint64_t
value()
const {
return uint64_t(1) << ShiftValue; }
96 template <
size_t kValue> constexpr
static LogValue
Constant() {
97 return LogValue{
static_cast<uint8_t
>(CTLog2<kValue>())};
102 template <
typename T> constexpr
static LogValue
Of() {
107 constexpr
Align(LogValue CA) : ShiftValue(CA.Log) {}
136 "Alignment is neither 0 nor a power of 2");
147 return SizeInBytes % Lhs.
value() == 0;
154 return SizeInBytes % (*Lhs).value() == 0;
159 return isAligned(Lhs, reinterpret_cast<uintptr_t>(Addr));
174 return (Size + value - 1) & ~(value - 1);
185 uintptr_t ArithAddr =
reinterpret_cast<uintptr_t
>(Addr);
186 assert(static_cast<uintptr_t>(ArithAddr + Alignment.
value() - 1) >=
187 ArithAddr &&
"Overflow");
188 return alignTo(ArithAddr, Alignment);
243 Out.ShiftValue = Value - 1;
254 return Lhs.
value() == Rhs;
258 return Lhs.
value() != Rhs;
262 return Lhs.
value() <= Rhs;
266 return Lhs.
value() >= Rhs;
270 return Lhs.
value() < Rhs;
274 return Lhs.
value() > Rhs;
279 return Lhs ? (*Lhs).value() == Rhs : Rhs == 0;
282 return Lhs ? (*Lhs).value() != Rhs : Rhs != 0;
287 return (*Lhs).value() <= Rhs;
292 return (*Lhs).value() >= Rhs;
297 return (*Lhs).value() < Rhs;
302 return (*Lhs).value() > Rhs;
307 return Lhs.ShiftValue == Rhs.ShiftValue;
310 return Lhs.ShiftValue != Rhs.ShiftValue;
313 return Lhs.ShiftValue <= Rhs.ShiftValue;
316 return Lhs.ShiftValue >= Rhs.ShiftValue;
319 return Lhs.ShiftValue < Rhs.ShiftValue;
322 return Lhs.ShiftValue > Rhs.ShiftValue;
328 return Lhs.
value() == (*Rhs).value();
332 return Lhs.
value() != (*Rhs).value();
336 return Lhs.
value() <= (*Rhs).value();
340 return Lhs.
value() >= (*Rhs).value();
344 return Lhs.
value() < (*Rhs).value();
348 return Lhs.
value() > (*Rhs).value();
354 return Lhs && (*Lhs).value() == Rhs.
value();
358 return Lhs && (*Lhs).value() != Rhs.
value();
362 return Lhs && (*Lhs).value() <= Rhs.
value();
366 return Lhs && (*Lhs).value() >= Rhs.
value();
370 return Lhs && (*Lhs).value() < Rhs.
value();
374 return Lhs && (*Lhs).value() > Rhs.
value();
379 "Divisor must be positive and a power of 2");
380 assert(Lhs != 1 &&
"Can't halve byte alignment");
386 "Divisor must be positive and a power of 2");
391 return Lhs && *Lhs > Rhs ? *Lhs : Rhs;
395 return Rhs && *Rhs > Lhs ? *Rhs : Lhs;
398 #undef ALIGN_CHECK_ISPOSITIVE 399 #undef ALIGN_CHECK_ISSET 403 #endif // LLVM_SUPPORT_ALIGNMENT_H_ Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
This class represents lattice values for constants.
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)
Comparisons operators between Align.
Align operator/(Align Lhs, uint64_t Divisor)
static constexpr LogValue Of()
Allow constructions of constexpr Align from types.
friend bool operator<=(Align Lhs, Align Rhs)
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...
friend struct MaybeAlign decodeMaybeAlign(unsigned Value)
Dual operation of the encode function above.
uintptr_t alignAddr(const void *Addr, Align Alignment)
Aligns Addr to Alignment bytes, rounding up.
Align commonAlignment(Align A, Align B)
Returns the alignment that satisfies both alignments.
constexpr Align()=default
Default is byte-aligned.
const T & getValue() const LLVM_LVALUE_FUNCTION
friend bool operator>(Align Lhs, Align Rhs)
friend struct MaybeAlign
The log2 of the required alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
#define ALIGN_CHECK_ISSET(decl)
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
friend unsigned encode(struct MaybeAlign A)
Returns a representation of the alignment that encodes undefined as 0.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This is an important base class in LLVM.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
bool isAddrAligned(Align Lhs, const void *Addr)
Checks that Addr is a multiple of the alignment.
friend bool operator>=(Align Lhs, Align Rhs)
friend bool operator<(Align Lhs, Align Rhs)
static constexpr const Align None()
Returns a default constructed Align which corresponds to no alignment.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Align max(MaybeAlign Lhs, Align Rhs)
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
Align & operator=(const Align &Other)=default
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
static constexpr LogValue Constant()
Allow constructions of constexpr Align.
constexpr Align(LogValue CA)
Constexpr constructor from LogValue type.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
friend unsigned Log2(Align)
Returns the log2 of the alignment.
friend bool operator!=(Align Lhs, Align Rhs)
#define ALIGN_CHECK_ISPOSITIVE(decl)
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
MaybeAlign(uint64_t Value)
Align assumeAligned(uint64_t Value)
Treats the value 0 as a 1, so Align is always at least 1.