Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always add the frame-pointer=all attribute #57209

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xal-0
Copy link
Contributor

@xal-0 xal-0 commented Jan 30, 2025

At some point LLVM on MacOS started doing frame pointer optimization by default. We should ask for a frame pointer on every function, on all platforms.

Prior to this change, on 1.11.3+0.aarch64.apple.darwin14:

julia> @code_native ((x,y) -> Core.Intrinsics.add_float(x,y))(1.0,2.0)
	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 15, 0
	.globl	"_julia_#1_678"                 ; -- Begin function julia_#1_678
	.p2align	2
"_julia_#1_678":                        ; @"julia_#1_678"
; Function Signature: var"#1"(Float64, Float64)
; ┌ @ REPL[1]:1 within `#1`
; %bb.0:                                ; %top
; │ @ REPL[1] within `#1`
	;DEBUG_VALUE: #1:x <- $d0
	;DEBUG_VALUE: #1:x <- $d0
	;DEBUG_VALUE: #1:y <- $d1
	;DEBUG_VALUE: #1:y <- $d1
; │ @ REPL[1]:1 within `#1`
	fadd	d0, d0, d1
	ret
; └
                                        ; -- End function
	.section	__DATA,__const
	.p2align	3, 0x0                          ; @"+Core.Float64#680"
"l_+Core.Float64#680":
	.quad	"l_+Core.Float64#680.jit"

.set "l_+Core.Float64#680.jit", 5490712608
.subsections_via_symbols

Prior to this change, on 1.11.3+0.aarch64.linux.gnu:

julia> @code_native ((x,y) -> Core.Intrinsics.add_float(x,y))(1.0,2.0)
	.text
	.file	"#1"
	.globl	"julia_#1_656"                  // -- Begin function julia_#1_656
	.p2align	2
	.type	"julia_#1_656",@function
"julia_#1_656":                         // @"julia_#1_656"
; Function Signature: var"#1"(Float64, Float64)
; ┌ @ REPL[1]:1 within `#1`
// %bb.0:                               // %top
; │ @ REPL[1] within `#1`
	//DEBUG_VALUE: #1:x <- $d0
	//DEBUG_VALUE: #1:x <- $d0
	//DEBUG_VALUE: #1:y <- $d1
	//DEBUG_VALUE: #1:y <- $d1
	stp	x29, x30, [sp, #-16]!           // 16-byte Folded Spill
	mov	x29, sp
; │ @ REPL[1]:1 within `#1`
	fadd	d0, d0, d1
	ldp	x29, x30, [sp], #16             // 16-byte Folded Reload
	ret
.Lfunc_end0:
	.size	"julia_#1_656", .Lfunc_end0-"julia_#1_656"
; └
                                        // -- End function
	.type	".L+Core.Float64#658",@object   // @"+Core.Float64#658"
	.section	.rodata,"a",@progbits
	.p2align	3, 0x0
".L+Core.Float64#658":
	.xword	".L+Core.Float64#658.jit"
	.size	".L+Core.Float64#658", 8

.set ".L+Core.Float64#658.jit", 278205186835760
	.size	".L+Core.Float64#658.jit", 8
	.section	".note.GNU-stack","",@progbits

At some point LLVM on MacOS started doing frame pointer optimization by default.
Ask for a frame pointer on every function, on all platforms.
@topolarity
Copy link
Member

What's the user-facing consequence for this change?

@giordano
Copy link
Contributor

I don't see much difference on aarch64-linux on this PR:

julia> versioninfo()
Julia Version 1.12.0-DEV.1955
Commit 5256457fc45 (2025-01-30 21:23 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (aarch64-linux-gnu)
  CPU: 72 × unknown
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, neoverse-v2)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 72 virtual cores)

julia> @code_native ((x,y) -> Core.Intrinsics.add_float(x,y))(1.0,2.0)
        .text
        .file   "#5"
        .globl  "julia_#5_2248"                 // -- Begin function julia_#5_2248
        .p2align        4
        .type   "julia_#5_2248",@function
"julia_#5_2248":                        // @"julia_#5_2248"
; Function Signature: var"#5"(Float64, Float64)
; ┌ @ REPL[4]:1 within `#5`
// %bb.0:                               // %top
        //DEBUG_VALUE: #5:x <- $d0
        //DEBUG_VALUE: #5:x <- $d0
        //DEBUG_VALUE: #5:y <- $d1
        //DEBUG_VALUE: #5:y <- $d1
        stp     x29, x30, [sp, #-16]!           // 16-byte Folded Spill
        mov     x29, sp
        fadd    d0, d0, d1
        ldp     x29, x30, [sp], #16             // 16-byte Folded Reload
        ret
.Lfunc_end0:
        .size   "julia_#5_2248", .Lfunc_end0-"julia_#5_2248"
;// -- End function
        .type   ".L+Core.Float64#2250",@object  // @"+Core.Float64#2250"
        .section        .rodata,"a",@progbits
        .p2align        3, 0x0
".L+Core.Float64#2250":
        .xword  ".L+Core.Float64#2250.jit"
        .size   ".L+Core.Float64#2250", 8

.set ".L+Core.Float64#2250.jit", 281472563526608
        .size   ".L+Core.Float64#2250.jit", 8
        .section        ".note.GNU-stack","",@progbits

@gbaraldi
Copy link
Member

Should affect macos only

@xal-0
Copy link
Contributor Author

xal-0 commented Jan 31, 2025

I can't find official documentation on what the apple profiling tools expect, but apple clang on arm includes -mframe-pointer=non-leaf by default:

$ /usr/bin/clang -v -S -emit-llvm basic.c    
Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: arm64-apple-darwin24.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple arm64-apple-macosx15.0.0 -Wundef-prefix=TARGET_OS_ -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-llvm -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name basic.c -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -fno-strict-return -ffp-contract=on -fno-rounding-math -funwind-tables=1 -fobjc-msgsend-selector-stubs -target-sdk-version=15.2 -fvisibility-inlines-hidden-static-local-var -fno-modulemap-allow-subdirectory-search -target-cpu apple-m1 -target-feature +v8.5a -target-feature +aes -target-feature +crc -target-feature +dotprod -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +lse -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sha2 -target-feature +sha3 -target-feature +neon -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-abi darwinpcs -debugger-tuning=lldb -target-linker-version 1115.7.3 -v -fcoverage-compilation-dir=/tmp/a -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/16 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/16/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -Wno-elaborated-enum-base -Wno-reserved-identifier -Wno-gnu-folding-constant -fdebug-compilation-dir=/tmp/a -ferror-limit 19 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcommon -fcolor-diagnostics -clang-vendor-feature=+disableNonDependentMemberExprInCurrentInstantiation -fno-odr-hash-protocols -clang-vendor-feature=+enableAggressiveVLAFolding -clang-vendor-feature=+revert09abecef7bbf -clang-vendor-feature=+thisNoAlignAttr -clang-vendor-feature=+thisNoNullAttr -clang-vendor-feature=+disableAtImportPrivateFrameworkInImplementationError -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o basic.ll -x c basic.c
clang -cc1 version 16.0.0 (clang-1600.0.26.6) default target arm64-apple-darwin24.3.0
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/16/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.

attr.addAttribute("frame-pointer", "non-leaf"); might be a reasonable choice for Linux, too.

If we don't add this attribute, the default varies by platform: CommonArgs.cpp:

  • x86_64 linux doesn't get frame pointers by default, but -fno-omit-frame-pointer also does leaf frame pointers
  • aarch64 gets non-leaf frame pointers by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants