diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h --- a/llvm/include/llvm/CodeGen/AsmPrinter.h +++ b/llvm/include/llvm/CodeGen/AsmPrinter.h @@ -432,7 +432,7 @@ /// global value is specified, and if that global has an explicit alignment /// requested, it will override the alignment request if required for /// correctness. - void emitAlignment(Align Alignment, const GlobalObject *GV = nullptr) const; + void emitAlignment(Align Alignment, const GlobalObject *GV = nullptr, unsigned MaxBytesToEmit = 0) const; /// Lower the specified LLVM Constant to an MCExpr. virtual const MCExpr *lowerConstant(const Constant *CV); diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h --- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -136,6 +136,11 @@ /// Alignment of the basic block. One if the basic block does not need to be /// aligned. Align Alignment; + /// Maximum amount of bytes that can be added to align the basic block. + /// Zero to represent no maximum. + /// Values greater than Alignment^2 are understood to be functionally useless, + /// and are equivalent to a value of Zero. + uint8_t MaxBytesForAlignment = 0; /// Indicate that this basic block is entered via an exception handler. bool IsEHPad = false; @@ -521,6 +526,11 @@ /// Set alignment of the basic block. void setAlignment(Align A) { Alignment = A; } + /// Return the maximum amount of padding allowed for aligning the basic block + uint8_t getMaxBytesForAlignment() const { return MaxBytesForAlignment; } + /// Set the maximum amount of padding allowed for aligning the basic block + void setMaxBytesForAlignment(uint8_t MaxBytes) { MaxBytesForAlignment = MaxBytes; } + /// Returns true if the block is a landing pad. That is this basic block is /// entered via an exception handler. bool isEHPad() const { return IsEHPad; } 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 @@ -2447,7 +2447,7 @@ // two boundary. If a global value is specified, and if that global has // an explicit alignment requested, it will override the alignment request // if required for correctness. -void AsmPrinter::emitAlignment(Align Alignment, const GlobalObject *GV) const { +void AsmPrinter::emitAlignment(Align Alignment, const GlobalObject *GV, unsigned MaxBytesToEmit) const { if (GV) Alignment = getGVAlignment(GV, GV->getParent()->getDataLayout(), Alignment); @@ -2460,7 +2460,7 @@ STI = &getSubtargetInfo(); else STI = TM.getMCSubtargetInfo(); - OutStreamer->emitCodeAlignment(Alignment.value(), STI); + OutStreamer->emitCodeAlignment(Alignment.value(), STI, MaxBytesToEmit); } else OutStreamer->emitValueToAlignment(Alignment.value()); } @@ -3253,7 +3253,7 @@ // Emit an alignment directive for this block, if needed. const Align Alignment = MBB.getAlignment(); if (Alignment != Align(1)) - emitAlignment(Alignment); + emitAlignment(Alignment, nullptr, MBB.getMaxBytesForAlignment()); // Switch to a new section if this basic block must begin a section. The // entry block is always placed in the function section and is handled