Skip to content

Commit

Permalink
build-llvm.py: Only apply native optimizations if specifically requested
Browse files Browse the repository at this point in the history
This may cause issues with older versions of LLVM.

At the same time, drop the -O2 flag; release LLVM builds are compiled
with -O3 and it overrides our choice.

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
  • Loading branch information
nathanchance committed Jun 26, 2019
1 parent 9afa4c2 commit 9f1ae41
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions build-llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ def parse_parameters(root_folder):
By default, the script always updates the LLVM repo before building. This prevents
that, which can be helpful during something like bisecting.
"""),
action="store_true")
parser.add_argument("-o",
"--opt-for-native",
help=textwrap.dedent("""\
Add -march=native and -mtune=native to CFLAGS to further optimize the toolchain for
the host processor.
"""),
action="store_true")
parser.add_argument("-p",
Expand Down Expand Up @@ -503,11 +511,13 @@ def stage_specific_cmake_defines(args, dirs, stage):
"""
defines = {}

if args.opt_for_native:
defines['CMAKE_C_FLAGS'] = '-march=native -mtune=native'
defines['CMAKE_CXX_FLAGS'] = '-march=native -mtune=native'

if stage == 1 and not args.stage1_only:
# Based on clang/cmake/caches/Apple-stage1.cmake
defines['CMAKE_BUILD_TYPE'] = 'Release'
defines['CMAKE_C_FLAGS'] = '-O2 -march=native -mtune=native'
defines['CMAKE_CXX_FLAGS'] = '-O2 -march=native -mtune=native'
defines['LLVM_ENABLE_BACKTRACES'] = 'OFF'
defines['LLVM_ENABLE_WARNINGS'] = 'OFF'
defines['LLVM_INCLUDE_TESTS'] = 'OFF'
Expand All @@ -516,14 +526,10 @@ def stage_specific_cmake_defines(args, dirs, stage):
# If a debug build was requested
if args.debug:
defines['CMAKE_BUILD_TYPE'] = 'Debug'
defines['CMAKE_C_FLAGS'] = '-march=native -mtune=native'
defines['CMAKE_CXX_FLAGS'] = '-march=native -mtune=native'
defines['LLVM_BUILD_TESTS'] = 'ON'
# If a release build was requested
else:
defines['CMAKE_BUILD_TYPE'] = 'Release'
defines['CMAKE_C_FLAGS'] = '-O2 -march=native -mtune=native'
defines['CMAKE_CXX_FLAGS'] = '-O2 -march=native -mtune=native'
defines['LLVM_ENABLE_WARNINGS'] = 'OFF'
defines['LLVM_INCLUDE_TESTS'] = 'OFF'

Expand Down

0 comments on commit 9f1ae41

Please sign in to comment.