Skip to content

[CMake] Preserve clang-prebolt #109351

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

Merged
merged 6 commits into from
Sep 22, 2024
Merged

Conversation

aaupov
Copy link
Contributor

@aaupov aaupov commented Sep 19, 2024

In Clang-BOLT step, preserve pre-BOLT Clang binary (as well as clang++
symlink).

Also modify the default set of BOLT flags:

  • drop ICF (can mess with unwinders),
  • switch from hfsort+ to cdsort (aliases),
  • enable CDSplit,
  • update debug sections.

Created using spr 1.3.4
Copy link
Contributor

@maksfb maksfb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

PS. Let's drop ICF from the flags.

@aaupov aaupov marked this pull request as ready for review September 20, 2024 15:04
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Sep 20, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 20, 2024

@llvm/pr-subscribers-clang

Author: Amir Ayupov (aaupov)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/109351.diff

1 Files Affected:

  • (modified) clang/CMakeLists.txt (+5-2)
diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 46e1412c0727aa..07eeb8a451b58b 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -923,11 +923,14 @@ if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
   )
   add_custom_command(OUTPUT ${CLANG_OPTIMIZED}
     DEPENDS clang-bolt-profile
+    COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:clang> ${CLANG_PATH}.prebolt
+    COMMAND ${CMAKE_COMMAND} -E create_symlink ${CLANG_PATH}.prebolt ${CLANG_PATH}++.prebolt
     COMMAND llvm-bolt ${CLANG_PATH}
       -o ${CLANG_OPTIMIZED}
       -data ${BOLT_FDATA}
-      -reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions
-      -split-all-cold -split-eh -dyno-stats -icf=1 -use-gnu-stack
+      -reorder-blocks=ext-tsp -reorder-functions=cdsort -split-functions
+      -split-all-cold -split-eh -dyno-stats -use-gnu-stack
+      -split-strategy=cdsplit
       ${BOLT_NO_LBR}
     COMMAND ${CMAKE_COMMAND} -E rename ${CLANG_OPTIMIZED} $<TARGET_FILE:clang>
     COMMENT "Optimizing Clang with BOLT"

@aaupov aaupov changed the title [CMake] Preserve clang.pre-bolt [CMake] Preserve clang.prebolt Sep 20, 2024
Created using spr 1.3.4
@aaupov aaupov changed the title [CMake] Preserve clang.prebolt [CMake] Preserve clang-prebolt Sep 22, 2024
nicovank and others added 2 commits September 21, 2024 20:55
Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@aaupov aaupov changed the base branch from users/aaupov/spr/main.cmake-preserve-clangpre-bolt to main September 22, 2024 03:55
@aaupov aaupov merged commit bbca451 into main Sep 22, 2024
7 of 11 checks passed
@aaupov aaupov deleted the users/aaupov/spr/cmake-preserve-clangpre-bolt branch September 22, 2024 03:56
@madhur13490
Copy link
Contributor

madhur13490 commented Sep 23, 2024

This commit is breaking LTO-PGO-BOLT build while optimizing clang with BOLT.

[3064/3065] Merging BOLT fdata
Using legacy profile format.
Profile from 2 files merged.
[3064/3065] Optimizing Clang with BOLT
BOLT-INFO: shared object or position-independent executable detected
BOLT-INFO: Target architecture: aarch64
BOLT-INFO: BOLT version: 51d1d03b17bb8bf66b6422c4482d8d615ab53409
BOLT-INFO: first alloc address is 0x0
BOLT-INFO: enabling relocation mode
BOLT-INFO: pre-processing profile using branch profile reader
BOLT-WARNING: 1 collisions detected while hashing binary objects. Use -v=1 to see the list.
BOLT-INFO: number of removed linker-inserted veneers: 0
BOLT-INFO: 11906 out of 212101 functions in the binary (5.6%) have non-empty execution profile
BOLT-INFO: 272 functions with profile could not be optimized
BOLT-INFO: profile for 1 objects was ignored
BOLT-INFO: removed 1 empty block
BOLT-INFO: basic block reordering modified layout of 4273 functions (35.89% of profiled, 2.01% of total)
BOLT-INFO: UCE removed 1 blocks and 4 bytes of code
BOLT-INFO: 68 Functions were reordered by LoopInversionPass
<unknown>:0: error: fixup value out of range
<unknown>:0: error: fixup value out of range
<unknown>:0: error: fixup value out of range
<unknown>:0: error: fixup value out of range
<unknown>:0: error: fixup value out of range
<unknown>:0: error: fixup value out of range
<unknown>:0: error: fixup value out of range
<unknown>:0: error: fixup value out of range

More information on LTO-PGO-BOLT can be found on https://llvm.org/docs/AdvancedBuilds.html

@madhur13490
Copy link
Contributor

Here are CMAKE variables we use downstream. 

-DLLVM_ENABLE_PROJECTS=bolt;clang;openmp;lld                                                                                                                                                                                                                                                                                                                                            
-DLLVM_ENABLE_RUNTIMES=compiler-rt                                                                                                                                                                                                                                                                                                                                                      
-DLLVM_TARGETS_TO_BUILD=AArch64                                                                                                                                                                                                                                                                                                                                                         
-DCLANG_DEFAULT_LINKER=lld                                                                                                                                                                                                                                                                                                                                                              
-DCMAKE_BUILD_TYPE=Release                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                        
-C ../clang/cmake/caches/BOLT-PGO.cmake                                                                                                                                                                                                                                                                                                           
-DBOOTSTRAP_LLVM_ENABLE_LLD=ON                                                                                                                                                                                                                                                                                                                                                          
-DBOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_LLD=ON                                                                                                                                                                                                                                                                                                                                                
-DBOOTSTRAP_CLANG_DEFAULT_LINKER=lld                                                                                                                                                                                                                                                                                                                                                    
-DBOOTSTRAP_BOOTSTRAP_CLANG_DEFAULT_LINKER=lld                                                                                                                                                                                                                                                                                                                                          
-DPGO_INSTRUMENT_LTO=Thin                                                                                                                                                                                                                                                                                                                                                               
-DCLANG_BOOTSTRAP_PASSTHROUGH=CMAKE_INSTALL_PREFIX;LLVM_TARGETS_TO_BUILD;CMAKE_BUILD_TYPE;      
 

@aaupov
Copy link
Contributor Author

aaupov commented Sep 23, 2024

This commit is breaking LTO-PGO-BOLT build while optimizing clang with BOLT.


[3064/3065] Merging BOLT fdata

Using legacy profile format.

Profile from 2 files merged.

[3064/3065] Optimizing Clang with BOLT

BOLT-INFO: shared object or position-independent executable detected

BOLT-INFO: Target architecture: aarch64

BOLT-INFO: BOLT version: 51d1d03b17bb8bf66b6422c4482d8d615ab53409

BOLT-INFO: first alloc address is 0x0

BOLT-INFO: enabling relocation mode

BOLT-INFO: pre-processing profile using branch profile reader

BOLT-WARNING: 1 collisions detected while hashing binary objects. Use -v=1 to see the list.

BOLT-INFO: number of removed linker-inserted veneers: 0

BOLT-INFO: 11906 out of 212101 functions in the binary (5.6%) have non-empty execution profile

BOLT-INFO: 272 functions with profile could not be optimized

BOLT-INFO: profile for 1 objects was ignored

BOLT-INFO: removed 1 empty block

BOLT-INFO: basic block reordering modified layout of 4273 functions (35.89% of profiled, 2.01% of total)

BOLT-INFO: UCE removed 1 blocks and 4 bytes of code

BOLT-INFO: 68 Functions were reordered by LoopInversionPass

<unknown>:0: error: fixup value out of range

<unknown>:0: error: fixup value out of range

<unknown>:0: error: fixup value out of range

<unknown>:0: error: fixup value out of range

<unknown>:0: error: fixup value out of range

<unknown>:0: error: fixup value out of range

<unknown>:0: error: fixup value out of range

<unknown>:0: error: fixup value out of range

More information on LTO-PGO-BOLT can be found on https://llvm.org/docs/AdvancedBuilds.html

This change was tested on a buildbot: https://lab.llvm.org/buildbot/#/builders/113/builds/2934

Can you please try cleaning the build directory?

@ElvinaYakubova
Copy link
Contributor

@aaupov this happens on AArch64 target, and only with -split-strategy=cdsplit enabled. Changing it to profile2, for example, fixes the issue

@aaupov
Copy link
Contributor Author

aaupov commented Sep 23, 2024

@aaupov this happens on AArch64 target, and only with -split-strategy=cdsplit enabled. Changing it to profile2, for example, fixes the issue

Thanks for clarification. I'll drop cdsplit as we never tested it on AArch64. ARM clang-bolt buildbot hasn't picked this change up yet so I didn't get the signal.

aaupov added a commit that referenced this pull request Sep 23, 2024
Breaks AArch64 Clang-BOLT builds:
#109351 (comment)
aaupov added a commit to aaupov/llvm-devmtg-2022 that referenced this pull request Sep 25, 2024
llvm/llvm-project@76b2915
has dropped the use of clang++-bolt target.

llvm/llvm-project#109351
has introduced the clang-prebolt binary that can be used as base
version (since clang-bolt binary is no longer produced).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants