Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/include/llvm/CodeGen/MachineFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,8 @@ class LLVM_ABI MachineFunction {
Alignment = A;
}

Align getPreferredAlignment() const;

/// exposesReturnsTwice - Returns true if the function calls setjmp or
/// any other similar functions with attribute "returns twice" without
/// having the attribute itself.
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ void AsmPrinter::emitFunctionHeader() {

emitLinkage(&F, CurrentFnSym);
if (MAI->hasFunctionAlignment())
emitAlignment(MF->getAlignment(), &F);
emitAlignment(MF->getPreferredAlignment(), &F);

if (MAI->hasDotTypeDotSizeDirective())
OutStreamer->emitSymbolAttribute(CurrentFnSym, MCSA_ELF_TypeFunction);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/AsmPrinter/WinException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ void WinException::beginFunclet(const MachineBasicBlock &MBB,

// We want our funclet's entry point to be aligned such that no nops will be
// present after the label.
Asm->emitAlignment(std::max(Asm->MF->getAlignment(), MBB.getAlignment()),
&F);
Asm->emitAlignment(
std::max(Asm->MF->getPreferredAlignment(), MBB.getAlignment()), &F);

// Now that we've emitted the alignment directive, point at our funclet.
Asm->OutStreamer->emitLabel(Sym);
Expand Down
18 changes: 13 additions & 5 deletions llvm/lib/CodeGen/MachineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,6 @@ void MachineFunction::init() {
ConstantPool = new (Allocator) MachineConstantPool(getDataLayout());
Alignment = STI.getTargetLowering()->getMinFunctionAlignment();

// FIXME: Shouldn't use pref alignment if explicit alignment is set on F.
if (!F.hasOptSize())
Alignment = std::max(Alignment,
STI.getTargetLowering()->getPrefFunctionAlignment());

// -fsanitize=function and -fsanitize=kcfi instrument indirect function calls
// to load a type hash before the function label. Ensure functions are aligned
// by a least 4 to avoid unaligned access, which is especially important for
Expand Down Expand Up @@ -330,6 +325,19 @@ bool MachineFunction::shouldSplitStack() const {
return getFunction().hasFnAttribute("split-stack");
}

Align MachineFunction::getPreferredAlignment() const {
Align PrefAlignment;

if (MaybeAlign A = F.getPreferredAlignment())
PrefAlignment = *A;
else if (!F.hasOptSize())
PrefAlignment = STI.getTargetLowering()->getPrefFunctionAlignment();
else
PrefAlignment = Align(1);

return std::max(PrefAlignment, getAlignment());
}

[[nodiscard]] unsigned
MachineFunction::addFrameInst(const MCCFIInstruction &Inst) {
FrameInstructions.push_back(Inst);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/X86/X86AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void X86AsmPrinter::EmitKCFITypePadding(const MachineFunction &MF,
if (HasType)
PrefixBytes += 5;

emitNops(offsetToAlignment(PrefixBytes, MF.getAlignment()));
emitNops(offsetToAlignment(PrefixBytes, MF.getPreferredAlignment()));
}

/// emitKCFITypeId - Emit the KCFI type information in architecture specific
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/alloca-crspill.ll
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ entry:
declare signext i32 @do_something(ptr)

; CHECK: name: test
; CHECK: alignment: 16
; CHECK: alignment: 4
; CHECK: liveins:
; CHECK64: - { reg: '$x3', virtual-reg: '' }
; CHECK32: - { reg: '$r3', virtual-reg: '' }
Expand Down
Loading