-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ARM][AArch64] autogenerate header file for TargetParser from Target tablegen files #88378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tmatheson-arm
merged 6 commits into
llvm:main
from
tmatheson-arm:tablegen_for_targetparser
Apr 24, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7d2968e
[ARM] autogen ARMProcFamilyEnum/ARMArchEnum from ARM.td
tmatheson-arm 3201b36
[AArch64] autogen ARMProcFamilyEnum from AArch64.td
tmatheson-arm 50ce58a
clang-format
tmatheson-arm 6e320b4
Remove some non-existent ARMProcFamily values:
tmatheson-arm 298d9b0
Merge remote-tracking branch 'upstream/main' into tablegen_for_target…
tmatheson-arm 835a5ed
Address review comments
tmatheson-arm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
set(LLVM_TARGET_DEFINITIONS ${PROJECT_SOURCE_DIR}/lib/Target/ARM/ARM.td) | ||
tablegen(LLVM ARMTargetParserDef.inc -gen-arm-target-def -I ${PROJECT_SOURCE_DIR}/lib/Target/ARM/) | ||
add_public_tablegen_target(ARMTargetParserTableGen) | ||
|
||
set(LLVM_TARGET_DEFINITIONS ${PROJECT_SOURCE_DIR}/lib/Target/AArch64/AArch64.td) | ||
tablegen(LLVM AArch64TargetParserDef.inc -gen-arm-target-def -I ${PROJECT_SOURCE_DIR}/lib/Target/AArch64/) | ||
add_public_tablegen_target(AArch64TargetParserTableGen) | ||
|
||
set(LLVM_TARGET_DEFINITIONS ${PROJECT_SOURCE_DIR}/lib/Target/RISCV/RISCV.td) | ||
tablegen(LLVM RISCVTargetParserDef.inc -gen-riscv-target-def -I ${PROJECT_SOURCE_DIR}/lib/Target/RISCV/) | ||
add_public_tablegen_target(RISCVTargetParserTableGen) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//===- ARMTargetDefEmitter.cpp - Generate data about ARM Architectures ----===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This tablegen backend exports information about CPUs, FPUs, architectures, | ||
// and features into a common format that can be used by both TargetParser and | ||
// the ARM and AArch64 backends. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/ADT/StringSet.h" | ||
#include "llvm/TableGen/Record.h" | ||
#include "llvm/TableGen/TableGenBackend.h" | ||
|
||
using namespace llvm; | ||
|
||
static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream &OS) { | ||
OS << "// Autogenerated by ARMTargetDefEmitter.cpp\n\n"; | ||
|
||
// Look through all SubtargetFeature defs with the given FieldName, and | ||
// collect the set of all Values that that FieldName is set to. | ||
auto gatherSubtargetFeatureFieldValues = [&RK](StringRef FieldName) { | ||
llvm::StringSet<> Set; | ||
for (const Record *Rec : RK.getAllDerivedDefinitions("SubtargetFeature")) { | ||
if (Rec->getValueAsString("FieldName") == FieldName) { | ||
Set.insert(Rec->getValueAsString("Value")); | ||
} | ||
} | ||
return Set; | ||
}; | ||
|
||
// The ARMProcFamilyEnum values are initialised by SubtargetFeature defs | ||
// which set the ARMProcFamily field. We can generate the enum from these defs | ||
// which look like this: | ||
// | ||
// def ProcA5 : SubtargetFeature<"a5", "ARMProcFamily", "CortexA5", | ||
// "Cortex-A5 ARM processors", []>; | ||
OS << "#ifndef ARM_PROCESSOR_FAMILY\n" | ||
<< "#define ARM_PROCESSOR_FAMILY(ENUM)\n" | ||
<< "#endif\n\n"; | ||
const StringSet<> ARMProcFamilyVals = | ||
gatherSubtargetFeatureFieldValues("ARMProcFamily"); | ||
for (const StringRef &Family : ARMProcFamilyVals.keys()) | ||
OS << "ARM_PROCESSOR_FAMILY(" << Family << ")\n"; | ||
OS << "\n#undef ARM_PROCESSOR_FAMILY\n\n"; | ||
|
||
OS << "#ifndef ARM_ARCHITECTURE\n" | ||
<< "#define ARM_ARCHITECTURE(ENUM)\n" | ||
<< "#endif\n\n"; | ||
// This should correspond to instances of the Architecture tablegen class. | ||
const StringSet<> ARMArchVals = gatherSubtargetFeatureFieldValues("ARMArch"); | ||
for (const StringRef &Arch : ARMArchVals.keys()) | ||
OS << "ARM_ARCHITECTURE(" << Arch << ")\n"; | ||
OS << "\n#undef ARM_ARCHITECTURE\n\n"; | ||
} | ||
|
||
static TableGen::Emitter::Opt | ||
X("gen-arm-target-def", EmitARMTargetDef, | ||
"Generate the ARM or AArch64 Architecture information header."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.