cc_toolchain_optimization.bzl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. """Definitions of optimization `cc_toolchain_config` features."""
  5. load(
  6. "@rules_cc//cc:cc_toolchain_config_lib.bzl",
  7. "feature",
  8. "feature_set",
  9. "flag_group",
  10. "flag_set",
  11. "with_feature_set",
  12. )
  13. load(
  14. ":cc_toolchain_actions.bzl",
  15. "all_compile_actions",
  16. "all_link_actions",
  17. "codegen_compile_actions",
  18. )
  19. # Handle different levels of optimization with individual features so that
  20. # they can be ordered and the defaults can override the minimal settings if
  21. # both are enabled.
  22. minimal_optimization_flags = feature(
  23. name = "minimal_optimization_flags",
  24. flag_sets = [flag_set(
  25. actions = codegen_compile_actions,
  26. flag_groups = [flag_group(flags = ["-Og"])],
  27. )],
  28. )
  29. default_optimization_flags = feature(
  30. name = "default_optimization_flags",
  31. enabled = True,
  32. requires = [feature_set(["opt"])],
  33. flag_sets = [
  34. flag_set(
  35. actions = all_compile_actions,
  36. flag_groups = [flag_group(flags = ["-DNDEBUG"])],
  37. ),
  38. flag_set(
  39. actions = codegen_compile_actions,
  40. flag_groups = [flag_group(flags = ["-O3"])],
  41. ),
  42. ],
  43. )
  44. cpu_flags = feature(
  45. name = "aarch64_cpu_flags",
  46. enabled = True,
  47. flag_sets = [
  48. flag_set(
  49. actions = all_compile_actions + all_link_actions,
  50. flag_groups = [flag_group(flags = ["-march=armv8.2-a"])],
  51. with_features = [with_feature_set(["aarch64_target"])],
  52. ),
  53. flag_set(
  54. actions = all_compile_actions + all_link_actions,
  55. flag_groups = [flag_group(flags = ["-march=x86-64-v2"])],
  56. with_features = [with_feature_set(["x86_64_target"])],
  57. ),
  58. ],
  59. )
  60. # Note that the order of features is significant in this list and determines the
  61. # relative order of flags from the features listed.
  62. optimization_features = [
  63. minimal_optimization_flags,
  64. default_optimization_flags,
  65. cpu_flags,
  66. ]