Skip to content

Commit 71c5964

Browse files
[ARM][AArch64] autogenerate header file for TargetParser from Target tablegen files (#88378)
Introduce a mechanism to share data between the ARM and AArch64 backends and TargetParser, to reduce duplication of code. This is similar to the current RISC-V implementation. The target tablegen file (in this case `ARM.td` or `AArch64.td`) is processed during building of `TargetParser` to generate the following files in the build tree: - `build/include/llvm/TargetParser/ARMTargetParserDef.inc` - `build/include/llvm/TargetParser/AArch64TargetParserDef.inc` For now, the use of these generated files is limited to files _outside_ of `TargetParser`. The main reason for this is that the modifications to `TargetParser` will require additional data added to the tablegen files, which I want to split into separate PRs.
1 parent 662ef86 commit 71c5964

File tree

8 files changed

+84
-136
lines changed

8 files changed

+84
-136
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
set(LLVM_TARGET_DEFINITIONS ${PROJECT_SOURCE_DIR}/lib/Target/ARM/ARM.td)
2+
tablegen(LLVM ARMTargetParserDef.inc -gen-arm-target-def -I ${PROJECT_SOURCE_DIR}/lib/Target/ARM/)
3+
add_public_tablegen_target(ARMTargetParserTableGen)
4+
5+
set(LLVM_TARGET_DEFINITIONS ${PROJECT_SOURCE_DIR}/lib/Target/AArch64/AArch64.td)
6+
tablegen(LLVM AArch64TargetParserDef.inc -gen-arm-target-def -I ${PROJECT_SOURCE_DIR}/lib/Target/AArch64/)
7+
add_public_tablegen_target(AArch64TargetParserTableGen)
8+
19
set(LLVM_TARGET_DEFINITIONS ${PROJECT_SOURCE_DIR}/lib/Target/RISCV/RISCV.td)
210
tablegen(LLVM RISCVTargetParserDef.inc -gen-riscv-target-def -I ${PROJECT_SOURCE_DIR}/lib/Target/RISCV/)
311
add_public_tablegen_target(RISCVTargetParserTableGen)
12+

llvm/lib/Target/AArch64/AArch64Subtarget.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ void AArch64Subtarget::initializeProperties(bool HasMinSize) {
144144
case CortexA78C:
145145
case CortexR82:
146146
case CortexX1:
147-
case CortexX1C:
148147
PrefFunctionAlignment = Align(16);
149148
PrefLoopAlignment = Align(32);
150149
MaxBytesForLoopAlignment = 16;

llvm/lib/Target/AArch64/AArch64Subtarget.h

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -39,61 +39,9 @@ class AArch64Subtarget final : public AArch64GenSubtargetInfo {
3939
public:
4040
enum ARMProcFamilyEnum : uint8_t {
4141
Others,
42-
A64FX,
43-
Ampere1,
44-
Ampere1A,
45-
Ampere1B,
46-
AppleA7,
47-
AppleA10,
48-
AppleA11,
49-
AppleA12,
50-
AppleA13,
51-
AppleA14,
52-
AppleA15,
53-
AppleA16,
54-
AppleA17,
55-
Carmel,
56-
CortexA35,
57-
CortexA53,
58-
CortexA55,
59-
CortexA510,
60-
CortexA520,
61-
CortexA57,
62-
CortexA65,
63-
CortexA72,
64-
CortexA73,
65-
CortexA75,
66-
CortexA76,
67-
CortexA77,
68-
CortexA78,
69-
CortexA78AE,
70-
CortexA78C,
71-
CortexA710,
72-
CortexA715,
73-
CortexA720,
74-
CortexR82,
75-
CortexX1,
76-
CortexX1C,
77-
CortexX2,
78-
CortexX3,
79-
CortexX4,
80-
ExynosM3,
81-
Falkor,
82-
Kryo,
83-
NeoverseE1,
84-
NeoverseN1,
85-
NeoverseN2,
86-
Neoverse512TVB,
87-
NeoverseV1,
88-
NeoverseV2,
89-
Saphira,
90-
ThunderX2T99,
91-
ThunderX,
92-
ThunderXT81,
93-
ThunderXT83,
94-
ThunderXT88,
95-
ThunderX3T110,
96-
TSV110
42+
#define ARM_PROCESSOR_FAMILY(ENUM) ENUM,
43+
#include "llvm/TargetParser/AArch64TargetParserDef.inc"
44+
#undef ARM_PROCESSOR_FAMILY
9745
};
9846

9947
protected:

llvm/lib/Target/ARM/ARMSubtarget.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,11 @@ void ARMSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
293293
case CortexA78C:
294294
case CortexA710:
295295
case CortexR4:
296-
case CortexR4F:
297296
case CortexR5:
298297
case CortexR7:
299298
case CortexM3:
300299
case CortexM7:
301300
case CortexR52:
302-
case CortexM52:
303301
case CortexX1:
304302
case CortexX1C:
305303
break;
@@ -314,8 +312,6 @@ void ARMSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
314312
case Krait:
315313
PreISelOperandLatencyAdjustment = 1;
316314
break;
317-
case NeoverseN1:
318-
case NeoverseN2:
319315
case NeoverseV1:
320316
break;
321317
case Swift:

llvm/lib/Target/ARM/ARMSubtarget.h

Lines changed: 6 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -49,45 +49,9 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
4949
protected:
5050
enum ARMProcFamilyEnum {
5151
Others,
52-
53-
CortexA12,
54-
CortexA15,
55-
CortexA17,
56-
CortexA32,
57-
CortexA35,
58-
CortexA5,
59-
CortexA53,
60-
CortexA55,
61-
CortexA57,
62-
CortexA7,
63-
CortexA72,
64-
CortexA73,
65-
CortexA75,
66-
CortexA76,
67-
CortexA77,
68-
CortexA78,
69-
CortexA78AE,
70-
CortexA78C,
71-
CortexA710,
72-
CortexA8,
73-
CortexA9,
74-
CortexM3,
75-
CortexM7,
76-
CortexM52,
77-
CortexR4,
78-
CortexR4F,
79-
CortexR5,
80-
CortexR52,
81-
CortexR7,
82-
CortexX1,
83-
CortexX1C,
84-
Exynos,
85-
Krait,
86-
Kryo,
87-
NeoverseN1,
88-
NeoverseN2,
89-
NeoverseV1,
90-
Swift
52+
#define ARM_PROCESSOR_FAMILY(ENUM) ENUM,
53+
#include "llvm/TargetParser/ARMTargetParserDef.inc"
54+
#undef ARM_PROCESSOR_FAMILY
9155
};
9256
enum ARMProcClassEnum {
9357
None,
@@ -97,43 +61,9 @@ class ARMSubtarget : public ARMGenSubtargetInfo {
9761
RClass
9862
};
9963
enum ARMArchEnum {
100-
ARMv4,
101-
ARMv4t,
102-
ARMv5,
103-
ARMv5t,
104-
ARMv5te,
105-
ARMv5tej,
106-
ARMv6,
107-
ARMv6k,
108-
ARMv6kz,
109-
ARMv6m,
110-
ARMv6sm,
111-
ARMv6t2,
112-
ARMv7a,
113-
ARMv7em,
114-
ARMv7m,
115-
ARMv7r,
116-
ARMv7ve,
117-
ARMv81a,
118-
ARMv82a,
119-
ARMv83a,
120-
ARMv84a,
121-
ARMv85a,
122-
ARMv86a,
123-
ARMv87a,
124-
ARMv88a,
125-
ARMv89a,
126-
ARMv8a,
127-
ARMv8mBaseline,
128-
ARMv8mMainline,
129-
ARMv8r,
130-
ARMv81mMainline,
131-
ARMv9a,
132-
ARMv91a,
133-
ARMv92a,
134-
ARMv93a,
135-
ARMv94a,
136-
ARMv95a,
64+
#define ARM_ARCHITECTURE(ENUM) ENUM,
65+
#include "llvm/TargetParser/ARMTargetParserDef.inc"
66+
#undef ARM_ARCHITECTURE
13767
};
13868

13969
public:

llvm/lib/TargetParser/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@ add_llvm_component_library(LLVMTargetParser
3838
Support
3939

4040
DEPENDS
41+
ARMTargetParserTableGen
42+
AArch64TargetParserTableGen
4143
RISCVTargetParserTableGen
4244
)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//===- ARMTargetDefEmitter.cpp - Generate data about ARM Architectures ----===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This tablegen backend exports information about CPUs, FPUs, architectures,
10+
// and features into a common format that can be used by both TargetParser and
11+
// the ARM and AArch64 backends.
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#include "llvm/ADT/StringSet.h"
16+
#include "llvm/TableGen/Record.h"
17+
#include "llvm/TableGen/TableGenBackend.h"
18+
19+
using namespace llvm;
20+
21+
static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) {
22+
OS << "// Autogenerated by ARMTargetDefEmitter.cpp\n\n";
23+
24+
// Look through all SubtargetFeature defs with the given FieldName, and
25+
// collect the set of all Values that that FieldName is set to.
26+
auto gatherSubtargetFeatureFieldValues = [&RK](StringRef FieldName) {
27+
llvm::StringSet<> Set;
28+
for (const Record *Rec : RK.getAllDerivedDefinitions("SubtargetFeature")) {
29+
if (Rec->getValueAsString("FieldName") == FieldName) {
30+
Set.insert(Rec->getValueAsString("Value"));
31+
}
32+
}
33+
return Set;
34+
};
35+
36+
// The ARMProcFamilyEnum values are initialised by SubtargetFeature defs
37+
// which set the ARMProcFamily field. We can generate the enum from these defs
38+
// which look like this:
39+
//
40+
// def ProcA5 : SubtargetFeature<"a5", "ARMProcFamily", "CortexA5",
41+
// "Cortex-A5 ARM processors", []>;
42+
OS << "#ifndef ARM_PROCESSOR_FAMILY\n"
43+
<< "#define ARM_PROCESSOR_FAMILY(ENUM)\n"
44+
<< "#endif\n\n";
45+
const StringSet<> ARMProcFamilyVals =
46+
gatherSubtargetFeatureFieldValues("ARMProcFamily");
47+
for (const StringRef &Family : ARMProcFamilyVals.keys())
48+
OS << "ARM_PROCESSOR_FAMILY(" << Family << ")\n";
49+
OS << "\n#undef ARM_PROCESSOR_FAMILY\n\n";
50+
51+
OS << "#ifndef ARM_ARCHITECTURE\n"
52+
<< "#define ARM_ARCHITECTURE(ENUM)\n"
53+
<< "#endif\n\n";
54+
// This should correspond to instances of the Architecture tablegen class.
55+
const StringSet<> ARMArchVals = gatherSubtargetFeatureFieldValues("ARMArch");
56+
for (const StringRef &Arch : ARMArchVals.keys())
57+
OS << "ARM_ARCHITECTURE(" << Arch << ")\n";
58+
OS << "\n#undef ARM_ARCHITECTURE\n\n";
59+
}
60+
61+
static TableGen::Emitter::Opt
62+
X("gen-arm-target-def", EmitARMTargetDef,
63+
"Generate the ARM or AArch64 Architecture information header.");

llvm/utils/TableGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set(LLVM_LINK_COMPONENTS Support)
1313
# ValueType definitions.
1414
add_tablegen(llvm-min-tblgen LLVM_HEADERS
1515
TableGen.cpp
16+
ARMTargetDefEmitter.cpp
1617
Attributes.cpp
1718
DirectiveEmitter.cpp
1819
IntrinsicEmitter.cpp

0 commit comments

Comments
 (0)