@@ -876,23 +876,38 @@ if (CLANG_ENABLE_BOOTSTRAP)
876876 endforeach ()
877877endif ()
878878
879- if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
879+ set (CLANG_BOLT OFF CACHE STRING "Apply BOLT optimization to Clang. \
880+ May be specified as Instrument or Perf or LBR to use a particular profiling \
881+ mechanism." )
882+ string (TOUPPER "${CLANG_BOLT} " CLANG_BOLT)
883+
884+ if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
880885 set (CLANG_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR} /clang)
881- set (CLANG_INSTRUMENTED ${CLANG_PATH} -bolt.inst )
886+ set (CLANG_INSTRUMENTED ${LLVM_RUNTIME_OUTPUT_INTDIR} / ${CLANG_BOLT_INSTRUMENTED} )
882887 set (BOLT_FDATA ${CMAKE_CURRENT_BINARY_DIR} /utils/perf-training/prof.fdata)
883888
884- # Instrument clang with BOLT
885- add_custom_target (clang-instrumented
886- DEPENDS ${CLANG_INSTRUMENTED}
887- )
888- add_custom_command (OUTPUT ${CLANG_INSTRUMENTED}
889- DEPENDS clang llvm-bolt
890- COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
891- -instrument --instrumentation-file-append -pid
892- --instrumentation-file=${BOLT_FDATA}
893- COMMENT "Instrumenting clang binary with BOLT"
894- VERBATIM
895- )
889+ # Pass extra flag in no-LBR mode
890+ if (CLANG_BOLT STREQUAL "PERF" )
891+ set (BOLT_NO_LBR "-nl" )
892+ endif ()
893+
894+ if (CLANG_BOLT STREQUAL "INSTRUMENT" )
895+ # Instrument clang with BOLT
896+ add_custom_target (clang-instrumented
897+ DEPENDS ${CLANG_INSTRUMENTED}
898+ )
899+ add_custom_command (OUTPUT ${CLANG_INSTRUMENTED}
900+ DEPENDS clang llvm-bolt
901+ COMMAND llvm-bolt ${CLANG_PATH} -o ${CLANG_INSTRUMENTED}
902+ -instrument --instrumentation-file-append -pid
903+ --instrumentation-file=${BOLT_FDATA}
904+ COMMENT "Instrumenting clang binary with BOLT"
905+ VERBATIM
906+ )
907+ add_custom_target (clang-bolt-training-deps DEPENDS clang-instrumented)
908+ else () # perf or LBR
909+ add_custom_target (clang-bolt-training-deps DEPENDS clang)
910+ endif ()
896911
897912 # Optimize original (pre-bolt) Clang using the collected profile
898913 set (CLANG_OPTIMIZED ${CMAKE_CURRENT_BINARY_DIR} /clang.bolt)
@@ -906,6 +921,7 @@ if (CLANG_BOLT_INSTRUMENT AND NOT LLVM_BUILD_INSTRUMENTED)
906921 -data ${BOLT_FDATA}
907922 -reorder-blocks=ext -tsp -reorder-functions=hfsort+ -split-functions
908923 -split-all -cold -split-eh -dyno-stats -icf=1 -use-gnu-stack
924+ ${BOLT_NO_LBR}
909925 COMMAND ${CMAKE_COMMAND} -E rename ${CLANG_OPTIMIZED} $<TARGET_FILE:clang>
910926 COMMENT "Optimizing Clang with BOLT"
911927 VERBATIM
0 commit comments