[PATCH] D114590: [CodeGen] Emit alignment "Max Skip" operand
Nicholas Guy via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 25 06:39:42 PST 2021
NickGuy created this revision.
NickGuy added reviewers: SjoerdMeijer, dmgreen, samtebbs.
NickGuy added a project: LLVM.
Herald added subscribers: dexonsmith, hiraditya.
NickGuy requested review of this revision.
The current AsmPrinter has support to emit the "Max Skip" operand
(the 3rd of .p2align), however has no support for it to actually be specified.
Adding MaxBytesForAlignment to the Align struct provides this capability, allowing
for targets to specify the max skips for alignment anywhere that alignment shift
value is currently specified. Leaving the value as default (0) causes no observable
differences in behaviour.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D114590
Files:
llvm/include/llvm/Support/Alignment.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ 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());
}
Index: llvm/include/llvm/Support/Alignment.h
===================================================================
--- llvm/include/llvm/Support/Alignment.h
+++ 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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114590.389765.patch
Type: text/x-patch
Size: 3364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211125/2eb639fa/attachment-0001.bin>
More information about the llvm-commits
mailing list