cc_toolchain_optimization.bzl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. )
  12. load(
  13. ":cc_toolchain_actions.bzl",
  14. "all_compile_actions",
  15. "codegen_compile_actions",
  16. )
  17. # Handle different levels of optimization with individual features so that
  18. # they can be ordered and the defaults can override the minimal settings if
  19. # both are enabled.
  20. minimal_optimization_flags = feature(
  21. name = "minimal_optimization_flags",
  22. flag_sets = [flag_set(
  23. actions = codegen_compile_actions,
  24. flag_groups = [flag_group(flags = ["-O1"])],
  25. )],
  26. )
  27. default_optimization_flags = feature(
  28. name = "default_optimization_flags",
  29. enabled = True,
  30. requires = [feature_set(["opt"])],
  31. flag_sets = [
  32. flag_set(
  33. actions = all_compile_actions,
  34. flag_groups = [flag_group(flags = ["-DNDEBUG"])],
  35. ),
  36. flag_set(
  37. actions = codegen_compile_actions,
  38. flag_groups = [flag_group(flags = ["-O3"])],
  39. ),
  40. ],
  41. )
  42. aarch64_cpu_flags = feature(
  43. name = "aarch64_cpu_flags",
  44. enabled = True,
  45. flag_sets = [flag_set(
  46. actions = all_compile_actions,
  47. flag_groups = [flag_group(flags = ["-march=armv8.2-a"])],
  48. )],
  49. )
  50. x86_64_cpu_flags = feature(
  51. name = "x86_64_cpu_flags",
  52. enabled = True,
  53. flag_sets = [flag_set(
  54. actions = all_compile_actions,
  55. flag_groups = [flag_group(flags = ["-march=x86-64-v2"])],
  56. )],
  57. )
  58. # Note that the order of features is significant in this list and determines the
  59. # relative order of flags from the features listed.
  60. optimization_features = [
  61. minimal_optimization_flags,
  62. default_optimization_flags,
  63. ]