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

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 9 15:01:52 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, during coding, I feel that I don't really like __BPF_CPU_VERSION. I would prefer either BPF_CPU_VERSION or __BPF_CPU_VERSION__. I will tentatively use BPF_CPU_VERSION for now.

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


More information about the cfe-commits mailing list