Index: llvm/include/llvm/CodeGen/MachineBasicBlock.h =================================================================== --- llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -571,19 +571,6 @@ /// Set alignment of the basic block. void setAlignment(Align A) { Alignment = A; } - void setAlignment(Align A, unsigned MaxBytes) { - setAlignment(A); - setMaxBytesForAlignment(MaxBytes); - } - - /// Return the maximum amount of padding allowed for aligning the basic block. - unsigned getMaxBytesForAlignment() const { return MaxBytesForAlignment; } - - /// Set the maximum amount of padding allowed for aligning the basic block - void setMaxBytesForAlignment(unsigned 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; } Index: llvm/include/llvm/CodeGen/TargetLowering.h =================================================================== --- llvm/include/llvm/CodeGen/TargetLowering.h +++ llvm/include/llvm/CodeGen/TargetLowering.h @@ -1900,9 +1900,10 @@ virtual Align getPrefLoopAlignment(MachineLoop *ML = nullptr) const; /// Return the maximum amount of bytes allowed to be emitted when padding for - /// alignment - virtual unsigned - getMaxPermittedBytesForAlignment(MachineBasicBlock *MBB) const; + /// alignment of a MachineBasicBlock. + unsigned getMaxPermittedBytesForAlignment() const { + return MaxBytesForAlignment; + } /// Should loops be aligned even when the function is marked OptSize (but not /// MinSize). Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -155,6 +155,12 @@ STATISTIC(EmittedInsts, "Number of machine instrs printed"); +static cl::opt MaxBytesForAlignmentOverride( + "max-bytes-for-alignment", + cl::desc("Forces the maximum bytes allowed to be emitted when padding for " + "alignment"), + cl::init(0), cl::Hidden); + char AsmPrinter::ID = 0; namespace { @@ -3798,8 +3804,14 @@ // Emit an alignment directive for this block, if needed. const Align Alignment = MBB.getAlignment(); - if (Alignment != Align(1)) - emitAlignment(Alignment, nullptr, MBB.getMaxBytesForAlignment()); + if (Alignment != Align(1)) { + const TargetLowering *TLI = MF->getSubtarget().getTargetLowering(); + unsigned MaxBytes = MaxBytesForAlignmentOverride.getNumOccurrences() > 0 ? + MaxBytesForAlignmentOverride : + TLI->getMaxPermittedBytesForAlignment(); + + emitAlignment(Alignment, nullptr, MaxBytes); + } // If the block has its address taken, emit any labels that were used to // reference the block. It is possible that there is more than one label Index: llvm/lib/CodeGen/BranchRelaxation.cpp =================================================================== --- llvm/lib/CodeGen/BranchRelaxation.cpp +++ llvm/lib/CodeGen/BranchRelaxation.cpp @@ -67,6 +67,9 @@ /// block. unsigned postOffset(const MachineBasicBlock &MBB) const { const unsigned PO = Offset + Size; + + // FIXME: Alignment is ignored if the padding is greater than + // getMaxPermittedBytesForAlignment const Align Alignment = MBB.getAlignment(); const Align ParentAlign = MBB.getParent()->getAlignment(); if (Alignment <= ParentAlign) Index: llvm/lib/CodeGen/MachineBlockPlacement.cpp =================================================================== --- llvm/lib/CodeGen/MachineBlockPlacement.cpp +++ llvm/lib/CodeGen/MachineBlockPlacement.cpp @@ -97,12 +97,6 @@ "format (e.g 4 means align on 16B boundaries)."), cl::init(0), cl::Hidden); -static cl::opt MaxBytesForAlignmentOverride( - "max-bytes-for-alignment", - cl::desc("Forces the maximum bytes allowed to be emitted when padding for " - "alignment"), - cl::init(0), cl::Hidden); - // FIXME: Find a good default for this flag and remove the flag. static cl::opt ExitBlockBias( "block-placement-exit-block-bias", @@ -2945,21 +2939,10 @@ MachineBasicBlock *LayoutPred = &*std::prev(MachineFunction::iterator(ChainBB)); - auto DetermineMaxAlignmentPadding = [&]() { - // Set the maximum bytes allowed to be emitted for alignment. - unsigned MaxBytes; - if (MaxBytesForAlignmentOverride.getNumOccurrences() > 0) - MaxBytes = MaxBytesForAlignmentOverride; - else - MaxBytes = TLI->getMaxPermittedBytesForAlignment(ChainBB); - ChainBB->setMaxBytesForAlignment(MaxBytes); - }; - // Force alignment if all the predecessors are jumps. We already checked // that the block isn't cold above. if (!LayoutPred->isSuccessor(ChainBB)) { ChainBB->setAlignment(Align); - DetermineMaxAlignmentPadding(); continue; } @@ -2972,7 +2955,6 @@ BlockFrequency LayoutEdgeFreq = MBFI->getBlockFreq(LayoutPred) * LayoutProb; if (LayoutEdgeFreq <= (Freq * ColdProb)) { ChainBB->setAlignment(Align); - DetermineMaxAlignmentPadding(); } } } @@ -3448,30 +3430,17 @@ ComputedEdges.clear(); ChainAllocator.DestroyAll(); - bool HasMaxBytesOverride = - MaxBytesForAlignmentOverride.getNumOccurrences() > 0; - - if (AlignAllBlock) + if (AlignAllBlock) { // Align all of the blocks in the function to a specific alignment. - for (MachineBasicBlock &MBB : MF) { - if (HasMaxBytesOverride) - MBB.setAlignment(Align(1ULL << AlignAllBlock), - MaxBytesForAlignmentOverride); - else - MBB.setAlignment(Align(1ULL << AlignAllBlock)); - } - else if (AlignAllNonFallThruBlocks) { + for (MachineBasicBlock &MBB : MF) + MBB.setAlignment(Align(1ULL << AlignAllBlock)); + } else if (AlignAllNonFallThruBlocks) { // Align all of the blocks that have no fall-through predecessors to a // specific alignment. for (auto MBI = std::next(MF.begin()), MBE = MF.end(); MBI != MBE; ++MBI) { auto LayoutPred = std::prev(MBI); - if (!LayoutPred->isSuccessor(&*MBI)) { - if (HasMaxBytesOverride) - MBI->setAlignment(Align(1ULL << AlignAllNonFallThruBlocks), - MaxBytesForAlignmentOverride); - else - MBI->setAlignment(Align(1ULL << AlignAllNonFallThruBlocks)); - } + if (!LayoutPred->isSuccessor(&*MBI)) + MBI->setAlignment(Align(1ULL << AlignAllNonFallThruBlocks)); } } if (ViewBlockLayoutWithBFI != GVDT_None && Index: llvm/lib/CodeGen/TargetLoweringBase.cpp =================================================================== --- llvm/lib/CodeGen/TargetLoweringBase.cpp +++ llvm/lib/CodeGen/TargetLoweringBase.cpp @@ -2064,11 +2064,6 @@ return PrefLoopAlignment; } -unsigned TargetLoweringBase::getMaxPermittedBytesForAlignment( - MachineBasicBlock *MBB) const { - return MaxBytesForAlignment; -} - //===----------------------------------------------------------------------===// // Reciprocal Estimates //===----------------------------------------------------------------------===// Index: llvm/tools/llvm-reduce/ReducerWorkItem.cpp =================================================================== --- llvm/tools/llvm-reduce/ReducerWorkItem.cpp +++ llvm/tools/llvm-reduce/ReducerWorkItem.cpp @@ -238,9 +238,6 @@ DstMBB->setAlignment(SrcMBB.getAlignment()); - // FIXME: This is not serialized - DstMBB->setMaxBytesForAlignment(SrcMBB.getMaxBytesForAlignment()); - DstMBB->setIsEHPad(SrcMBB.isEHPad()); DstMBB->setIsEHScopeEntry(SrcMBB.isEHScopeEntry()); DstMBB->setIsEHCatchretTarget(SrcMBB.isEHCatchretTarget());