|
| 1 | +// LLVM feature name compatibility layer |
| 2 | +// Maps archspec feature names to LLVM feature names |
| 3 | + |
| 4 | +#ifndef ARCHSPEC_LLVM_COMPAT_HPP |
| 5 | +#define ARCHSPEC_LLVM_COMPAT_HPP |
| 6 | + |
| 7 | +#include <string> |
| 8 | +#include <string_view> |
| 9 | +#include <set> |
| 10 | +#include <vector> |
| 11 | + |
| 12 | +namespace archspec { |
| 13 | + |
| 14 | +// Forward declaration |
| 15 | +class Microarchitecture; |
| 16 | + |
| 17 | +/** |
| 18 | + * Map a single archspec feature name to LLVM feature name. |
| 19 | + * Returns empty string if the feature should be filtered out (no LLVM equivalent). |
| 20 | + * Returns the input unchanged if no mapping is needed. |
| 21 | + * |
| 22 | + * @param arch_family Architecture family ("x86_64", "aarch64", "ppc64le", "riscv64") |
| 23 | + * @param feature The archspec feature name |
| 24 | + * @return LLVM-compatible feature name, or empty string to filter |
| 25 | + */ |
| 26 | +std::string map_feature_to_llvm(std::string_view arch_family, std::string_view feature); |
| 27 | + |
| 28 | +/** |
| 29 | + * Get all LLVM-compatible features for a microarchitecture. |
| 30 | + * Handles mapping and filtering automatically. |
| 31 | + * |
| 32 | + * @param uarch The microarchitecture to get features for |
| 33 | + * @return Set of LLVM-compatible feature names (without +/- prefix) |
| 34 | + */ |
| 35 | +std::set<std::string> get_llvm_features(const Microarchitecture& uarch); |
| 36 | + |
| 37 | +/** |
| 38 | + * Get LLVM-compatible features as a comma-separated string with +prefix. |
| 39 | + * Example: "+neon,+dotprod,+crc" |
| 40 | + * |
| 41 | + * @param uarch The microarchitecture to get features for |
| 42 | + * @return Comma-separated feature string |
| 43 | + */ |
| 44 | +std::string get_llvm_features_string(const Microarchitecture& uarch); |
| 45 | + |
| 46 | +/** |
| 47 | + * Map archspec CPU name to LLVM CPU name. |
| 48 | + * Examples: |
| 49 | + * - "m4" (Apple) -> "apple-m4" |
| 50 | + * - "zen3" -> "znver3" |
| 51 | + * |
| 52 | + * @param uarch The microarchitecture |
| 53 | + * @return LLVM-compatible CPU name |
| 54 | + */ |
| 55 | +std::string get_llvm_cpu_name(const Microarchitecture& uarch); |
| 56 | + |
| 57 | +/** |
| 58 | + * Normalize a CPU name to archspec format (reverse of get_llvm_cpu_name). |
| 59 | + * Examples: |
| 60 | + * - "apple-m4" -> "m4" |
| 61 | + * - "znver3" -> "zen3" |
| 62 | + * |
| 63 | + * @param arch_family Architecture family ("x86_64", "aarch64", etc.) |
| 64 | + * @param llvm_name The LLVM CPU name |
| 65 | + * @return archspec-compatible CPU name |
| 66 | + */ |
| 67 | +std::string normalize_cpu_name(std::string_view arch_family, std::string_view llvm_name); |
| 68 | + |
| 69 | +/** |
| 70 | + * Look up a CPU by name (with normalization) and return its LLVM-compatible features. |
| 71 | + * Tries both the given name and normalized versions. |
| 72 | + * |
| 73 | + * @param cpu_name CPU name (can be LLVM or archspec format) |
| 74 | + * @param arch_family Architecture family for normalization |
| 75 | + * @return LLVM-compatible feature string, or empty if CPU not found |
| 76 | + */ |
| 77 | +std::string get_llvm_features_for_cpu(std::string_view cpu_name, std::string_view arch_family); |
| 78 | + |
| 79 | +} // namespace archspec |
| 80 | + |
| 81 | +#endif // ARCHSPEC_LLVM_COMPAT_HPP |
0 commit comments