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
19using namespace llvm;
20
21static 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(ClassName: "SubtargetFeature")) {
29 if (Rec->getValueAsString(FieldName: "FieldName") == FieldName) {
30 Set.insert(key: Rec->getValueAsString(FieldName: "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
61static TableGen::Emitter::Opt
62 X("gen-arm-target-def", EmitARMTargetDef,
63 "Generate the ARM or AArch64 Architecture information header.");
64

source code of llvm/utils/TableGen/ARMTargetDefEmitter.cpp