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

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 9 13:08:14 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));
----------------
4ast wrote:

That works and somewhat similar to other archs. Like __amdgcn_processor__.
I have slight preference to use capitol case __BPF_CPU_VERSION__.
Let's add all groups too:
    HasJmpExt = true;
    HasJmp32 = true;
    HasAlu32 = true;
    HasJmpExt = true;
    HasJmp32 = true;
    HasAlu32 = true;
    HasLdsx = !Disable_ldsx;
    HasMovsx = !Disable_movsx;
    HasBswap = !Disable_bswap;
    HasSdivSmod = !Disable_sdiv_smod;
    HasGotol = !Disable_gotol;

arm does __ARM_FEATURE_xx.
We can do __BPF_FEATURE_ALU32, __BPF_FEATURE_GOTOL.

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


More information about the cfe-commits mailing list