cc_toolchain_optimization.bzl 2.2 KB

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