Kaynağa Gözat

Add `-march=...` to our compile flags. (#2439)

This makes more modern CPU instructions available. I noticed that we weren't already doing this when working on another bit of code where its actually relevant. This doesn't make a big difference for any of the few benchmarks we have at the moment, but it seems like a good idea.

Modern Clang/LLVM support this exact spelling both on x86 and ARM CPUs, so its surprisingly portable. I've tested it on my ARM mac just in case.

I've picked specific arch flags here because using detection with `native` seems to run into issues in the GitHub actions. Sadly, the x86 macOS runners force a somewhat minimal set of features for x86, but it will still give us consistent results.
Chandler Carruth 3 yıl önce
ebeveyn
işleme
5f85822caa

+ 32 - 0
bazel/cc_toolchains/clang_cc_toolchain_config.bzl

@@ -291,6 +291,32 @@ def _impl(ctx):
         ],
         ],
     )
     )
 
 
+    x86_64_cpu_flags = feature(
+        name = "x86_64_cpu_flags",
+        enabled = True,
+        flag_sets = [
+            flag_set(
+                actions = all_compile_actions,
+                flag_groups = [flag_group(flags = [
+                    "-march=x86-64-v2",
+                ])],
+            ),
+        ],
+    )
+
+    aarch64_cpu_flags = feature(
+        name = "aarch64_cpu_flags",
+        enabled = True,
+        flag_sets = [
+            flag_set(
+                actions = all_compile_actions,
+                flag_groups = [flag_group(flags = [
+                    "-march=armv8.2-a",
+                ])],
+            ),
+        ],
+    )
+
     # Handle different levels and forms of debug info emission with individual
     # Handle different levels and forms of debug info emission with individual
     # features so that they can be ordered and the defaults can override the
     # features so that they can be ordered and the defaults can override the
     # minimal settings if both are enabled.
     # minimal settings if both are enabled.
@@ -814,6 +840,12 @@ def _impl(ctx):
     else:
     else:
         fail("Unsupported target platform!")
         fail("Unsupported target platform!")
 
 
+    # TODO: Need to support non-macOS ARM platforms here.
+    if ctx.attr.target_cpu == "darwin_arm64":
+        features += [aarch64_cpu_flags]
+    else:
+        features += [x86_64_cpu_flags]
+
     # Finally append the libraries to link and any final flags.
     # Finally append the libraries to link and any final flags.
     features += [
     features += [
         default_link_libraries_feature,
         default_link_libraries_feature,