[clang] [Clang][BPF] Add __bpf_cpu_version__ macro (PR #71856)

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 9 15:04:50 PST 2023


================
@@ -29,6 +29,14 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
                                      MacroBuilder &Builder) const {
   Builder.defineMacro("__bpf__");
   Builder.defineMacro("__BPF__");
+
+  std::string CPU = getTargetOpts().CPU;
+  if (CPU == "probe")
+    Builder.defineMacro("__bpf_cpu_version__", "0");
+  else if (CPU.empty() || CPU == "generic")
+    Builder.defineMacro("__bpf_cpu_version__", "1");
+  else
+    Builder.defineMacro("__bpf_cpu_version__", CPU.substr(1));
----------------
yonghong-song wrote:

Okay, I don't particularly like __BPF_CPU_VERSION either and actually prefer double underscore before and after BPF_CPU_VERSION. Now, I realize that you actually mean with double underscore before and after BPF_CPU_VERSION. github just displays as highlight.

https://github.com/llvm/llvm-project/pull/71856


More information about the cfe-commits mailing list