[llvm] [llvm][AArch64][TableGen] Create a ProcessorAlias record. NFC (PR #96249)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 20 16:31:41 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: Jon Roelofs (jroelofs)
<details>
<summary>Changes</summary>
... and use it to organize all of the Apple CPU aliases.
---
Full diff: https://github.com/llvm/llvm-project/pull/96249.diff
2 Files Affected:
- (modified) llvm/lib/Target/AArch64/AArch64Processors.td (+16-19)
- (modified) llvm/utils/TableGen/ARMTargetDefEmitter.cpp (+22-3)
``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64Processors.td b/llvm/lib/Target/AArch64/AArch64Processors.td
index 53b46ff42b72f..46f665cb15a9a 100644
--- a/llvm/lib/Target/AArch64/AArch64Processors.td
+++ b/llvm/lib/Target/AArch64/AArch64Processors.td
@@ -930,6 +930,12 @@ def ProcessorFeatures {
list<SubtargetFeature> Generic = [FeatureFPARMv8, FeatureNEON, FeatureETE];
}
+// Define an alternative name for a given Processor.
+class ProcessorAlias<string n, string alias> {
+ string Name = n;
+ string Alias = alias;
+}
+
// FeatureFuseAdrpAdd is enabled under Generic to allow linker merging
// optimizations.
def : ProcessorModel<"generic", CortexA510Model, ProcessorFeatures.Generic,
@@ -1050,15 +1056,12 @@ def : ProcessorModel<"tsv110", TSV110Model, ProcessorFeatures.TSV110,
// Apple CPUs
-// Support cyclone as an alias for apple-a7 so we can still LTO old bitcode.
-def : ProcessorModel<"cyclone", CycloneModel, ProcessorFeatures.AppleA7,
- [TuneAppleA7]>;
def : ProcessorModel<"apple-a7", CycloneModel, ProcessorFeatures.AppleA7,
[TuneAppleA7]>;
-def : ProcessorModel<"apple-a8", CycloneModel, ProcessorFeatures.AppleA7,
- [TuneAppleA7]>;
-def : ProcessorModel<"apple-a9", CycloneModel, ProcessorFeatures.AppleA7,
- [TuneAppleA7]>;
+// Support cyclone as an alias for apple-a7 so we can still LTO old bitcode.
+def : ProcessorAlias<"cyclone", "apple-a7">;
+def : ProcessorAlias<"apple-a8", "apple-a7">;
+def : ProcessorAlias<"apple-a9", "apple-a7">;
def : ProcessorModel<"apple-a10", CycloneModel, ProcessorFeatures.AppleA10,
[TuneAppleA10]>;
@@ -1068,28 +1071,23 @@ def : ProcessorModel<"apple-a11", CycloneModel, ProcessorFeatures.AppleA11,
def : ProcessorModel<"apple-a12", CycloneModel, ProcessorFeatures.AppleA12,
[TuneAppleA12]>;
-def : ProcessorModel<"apple-s4", CycloneModel, ProcessorFeatures.AppleA12,
- [TuneAppleA12]>;
-def : ProcessorModel<"apple-s5", CycloneModel, ProcessorFeatures.AppleA12,
- [TuneAppleA12]>;
+def : ProcessorAlias<"apple-s4", "apple-a12">;
+def : ProcessorAlias<"apple-s5", "apple-a12">;
def : ProcessorModel<"apple-a13", CycloneModel, ProcessorFeatures.AppleA13,
[TuneAppleA13]>;
def : ProcessorModel<"apple-a14", CycloneModel, ProcessorFeatures.AppleA14,
[TuneAppleA14]>;
-def : ProcessorModel<"apple-m1", CycloneModel, ProcessorFeatures.AppleA14,
- [TuneAppleA14]>;
+def : ProcessorAlias<"apple-m1", "apple-a14">;
def : ProcessorModel<"apple-a15", CycloneModel, ProcessorFeatures.AppleA15,
[TuneAppleA15]>;
-def : ProcessorModel<"apple-m2", CycloneModel, ProcessorFeatures.AppleA15,
- [TuneAppleA15]>;
+def : ProcessorAlias<"apple-m2", "apple-a15">;
def : ProcessorModel<"apple-a16", CycloneModel, ProcessorFeatures.AppleA16,
[TuneAppleA16]>;
-def : ProcessorModel<"apple-m3", CycloneModel, ProcessorFeatures.AppleA16,
- [TuneAppleA16]>;
+def : ProcessorAlias<"apple-m3", "apple-a16">;
def : ProcessorModel<"apple-a17", CycloneModel, ProcessorFeatures.AppleA17,
[TuneAppleA17]>;
@@ -1098,8 +1096,7 @@ def : ProcessorModel<"apple-m4", CycloneModel, ProcessorFeatures.AppleM4,
[TuneAppleM4]>;
// Alias for the latest Apple processor model supported by LLVM.
-def : ProcessorModel<"apple-latest", CycloneModel, ProcessorFeatures.AppleM4,
- [TuneAppleM4]>;
+def : ProcessorAlias<"apple-latest", "apple-m4">;
// Fujitsu A64FX
diff --git a/llvm/utils/TableGen/ARMTargetDefEmitter.cpp b/llvm/utils/TableGen/ARMTargetDefEmitter.cpp
index e22f353b451f9..3e111813280a3 100644
--- a/llvm/utils/TableGen/ARMTargetDefEmitter.cpp
+++ b/llvm/utils/TableGen/ARMTargetDefEmitter.cpp
@@ -221,8 +221,28 @@ static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) {
OS << "#ifdef EMIT_CPU_INFO\n"
<< "inline constexpr CpuInfo CpuInfos[] = {\n";
+ std::map<std::string, std::pair<std::string, const Record *>> ProcessorModels;
for (const Record *Rec : RK.getAllDerivedDefinitions("ProcessorModel")) {
auto Name = Rec->getValueAsString("Name");
+ ProcessorModels.insert(std::make_pair(Name, std::make_pair(Name, Rec)));
+ }
+
+ for (const Record *Rec : RK.getAllDerivedDefinitions("ProcessorAlias")) {
+ std::string Name = Rec->getValueAsString("Name").str();
+ auto Alias = Rec->getValueAsString("Alias");
+ auto It = ProcessorModels.find(Alias.str());
+ if (!ProcessorModels
+ .insert(
+ std::make_pair(Name, std::make_pair(Alias, It->second.second)))
+ .second)
+ PrintFatalError(
+ Rec, "Alias duplicates an existing ProcessorAlias or ProcessorModel");
+ }
+
+ for (auto &[K, V] : ProcessorModels) {
+ auto Name = K;
+ auto Alias = V.first;
+ auto *Rec = V.second;
auto Features = Rec->getValueAsListOfDefs("Features");
// "apple-latest" is backend-only, should not be accepted by TargetParser.
@@ -253,9 +273,8 @@ static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) {
auto Profile = Arch->getValueAsString("Profile");
auto ArchInfo = ArchInfoName(Major, Minor, Profile);
- // The apple-latest alias is backend only, do not expose it to -mcpu.
- if (Name == "apple-latest")
- continue;
+ if (Name != Alias)
+ OS << " // Alias: " << Name << " -> " << Alias << "\n";
OS << " {\n"
<< " \"" << Name << "\",\n"
``````````
</details>
https://github.com/llvm/llvm-project/pull/96249
More information about the llvm-commits
mailing list