diff --git a/llvm/include/llvm/Support/Alignment.h b/llvm/include/llvm/Support/Alignment.h --- a/llvm/include/llvm/Support/Alignment.h +++ b/llvm/include/llvm/Support/Alignment.h @@ -40,6 +40,8 @@ private: uint8_t ShiftValue = 0; /// The log2 of the required alignment. /// ShiftValue is less than 64 by construction. + uint8_t MaxBytesForAlignment = 0; /// The maximum amount of bytes that can be + /// use to align a block. friend struct MaybeAlign; friend unsigned Log2(Align); @@ -84,6 +86,12 @@ /// Needed to interact with C for instance. uint64_t value() const { return uint64_t(1) << ShiftValue; } + uint8_t constraint() const { return MaxBytesForAlignment; } + + void setConstraint(uint8_t MaxBytes) { + MaxBytesForAlignment = MaxBytes; + } + /// Allow constructions of constexpr Align. template <size_t kValue> constexpr static LogValue Constant() { return LogValue{static_cast<uint8_t>(CTLog2<kValue>())}; @@ -278,23 +286,42 @@ return Lhs ? (*Lhs).value() != Rhs : Rhs != 0; } -/// Comparisons operators between Align. +/// Comparisons operators between Align. MaxBytesForAlignment is only considered +/// if both aligns have it as non-zero inline bool operator==(Align Lhs, Align Rhs) { + if(Lhs.MaxBytesForAlignment != 0 && Rhs.MaxBytesForAlignment != 0) + if(Lhs.MaxBytesForAlignment != Rhs.MaxBytesForAlignment) + return false; return Lhs.ShiftValue == Rhs.ShiftValue; } inline bool operator!=(Align Lhs, Align Rhs) { + if(Lhs.MaxBytesForAlignment != 0 && Rhs.MaxBytesForAlignment != 0) + if(Lhs.MaxBytesForAlignment == Rhs.MaxBytesForAlignment) + return false; return Lhs.ShiftValue != Rhs.ShiftValue; } inline bool operator<=(Align Lhs, Align Rhs) { + if(Lhs.MaxBytesForAlignment != 0 && Rhs.MaxBytesForAlignment != 0) + if(Lhs.MaxBytesForAlignment > Rhs.MaxBytesForAlignment) + return false; return Lhs.ShiftValue <= Rhs.ShiftValue; } inline bool operator>=(Align Lhs, Align Rhs) { + if(Lhs.MaxBytesForAlignment != 0 && Rhs.MaxBytesForAlignment != 0) + if(Lhs.MaxBytesForAlignment < Rhs.MaxBytesForAlignment) + return false; return Lhs.ShiftValue >= Rhs.ShiftValue; } inline bool operator<(Align Lhs, Align Rhs) { + if(Lhs.MaxBytesForAlignment != 0 && Rhs.MaxBytesForAlignment != 0) + if(Lhs.MaxBytesForAlignment >= Rhs.MaxBytesForAlignment) + return false; return Lhs.ShiftValue < Rhs.ShiftValue; } inline bool operator>(Align Lhs, Align Rhs) { + if(Lhs.MaxBytesForAlignment != 0 && Rhs.MaxBytesForAlignment != 0) + if(Lhs.MaxBytesForAlignment <= Rhs.MaxBytesForAlignment) + return false; return Lhs.ShiftValue > Rhs.ShiftValue; } diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -2460,7 +2460,7 @@ STI = &getSubtargetInfo(); else STI = TM.getMCSubtargetInfo(); - OutStreamer->emitCodeAlignment(Alignment.value(), STI); + OutStreamer->emitCodeAlignment(Alignment.value(), STI, Alignment.constraint()); } else OutStreamer->emitValueToAlignment(Alignment.value()); }