Skip to content

Commit

Permalink
[SystemZ][z/OS] Fix the entry point marker for leaf functions
Browse files Browse the repository at this point in the history
The function emitFunctionEntryLabel does not look at whether or not a function is a leaf when setting the entry flags,
and instead blindly marks all functions as non-leaf routines. Change it to check if a function is a leaf function and
mark it accordingly.
  • Loading branch information
Everybody0523 committed Aug 21, 2023
1 parent 7ed0f5b commit 8af297b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,14 +1315,16 @@ void SystemZAsmPrinter::emitFunctionEntryLabel() {
// EntryPoint Marker
const MachineFrameInfo &MFFrame = MF->getFrameInfo();
bool IsUsingAlloca = MFFrame.hasVarSizedObjects();
uint32_t DSASize = MFFrame.getStackSize();
bool IsLeaf = DSASize == 0 && MFFrame.getCalleeSavedInfo().empty();

// Set Flags
uint8_t Flags = 0;
if (IsLeaf)
Flags |= 0x08;
if (IsUsingAlloca)
Flags |= 0x04;

uint32_t DSASize = MFFrame.getStackSize();

// Combine into top 27 bits of DSASize and bottom 5 bits of Flags.
uint32_t DSAAndFlags = DSASize & 0xFFFFFFE0; // (x/32) << 5
DSAAndFlags |= Flags;
Expand All @@ -1340,6 +1342,10 @@ void SystemZAsmPrinter::emitFunctionEntryLabel() {
if (OutStreamer->isVerboseAsm()) {
OutStreamer->AddComment("DSA Size 0x" + Twine::utohexstr(DSASize));
OutStreamer->AddComment("Entry Flags");
if (Flags & 0x08)
OutStreamer->AddComment(" Bit 1: 1 = Leaf function");
else
OutStreamer->AddComment(" Bit 1: 0 = Non-leaf function");
if (Flags & 0x04)
OutStreamer->AddComment(" Bit 2: 1 = Uses alloca");
else
Expand Down
4 changes: 4 additions & 0 deletions llvm/test/CodeGen/SystemZ/zos-prologue-epilog.ll
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ define void @large_stack2(i64 %n1, i64 %n2, i64 %n3) {
}

; CHECK-LABEL: leaf_func
; CHECK: .long 8 * DSA Size 0x0
; CHECK-NEXT: * Entry Flags
; CHECK-NEXT: * Bit 1: 1 = Leaf function
; CHECK-NEXT: * Bit 2: 0 = Does not use alloca
; CHECK-NOT: aghi 4,
; CHECK-NOT: stmg
; CHECK: agr 1, 2
Expand Down

0 comments on commit 8af297b

Please sign in to comment.