[Frontend] Remove unused includes (NFC) (#116927)
[llvm-project.git] / llvm / utils / TableGen / Common / SubtargetFeatureInfo.h
blobd75a9a41636de3d64f70d15a5e8fe268a5bdbf25
1 //===- SubtargetFeatureInfo.h - Helpers for subtarget features --*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_UTIL_TABLEGEN_COMMON_SUBTARGETFEATUREINFO_H
10 #define LLVM_UTIL_TABLEGEN_COMMON_SUBTARGETFEATUREINFO_H
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/TableGen/Record.h"
14 #include <map>
15 #include <string>
16 #include <utility>
17 #include <vector>
19 namespace llvm {
20 struct SubtargetFeatureInfo;
21 using SubtargetFeatureInfoMap =
22 std::map<const Record *, SubtargetFeatureInfo, LessRecordByID>;
23 using SubtargetFeaturesInfoVec =
24 std::vector<std::pair<const Record *, SubtargetFeatureInfo>>;
26 /// Helper class for storing information on a subtarget feature which
27 /// participates in instruction matching.
28 struct SubtargetFeatureInfo {
29 /// The predicate record for this feature.
30 const Record *TheDef;
32 /// An unique index assigned to represent this feature.
33 uint64_t Index;
35 SubtargetFeatureInfo(const Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {}
37 /// The name of the enumerated constant identifying this feature.
38 std::string getEnumName() const {
39 return "Feature_" + TheDef->getName().str();
42 /// The name of the enumerated constant identifying the bitnumber for
43 /// this feature.
44 std::string getEnumBitName() const {
45 return "Feature_" + TheDef->getName().str() + "Bit";
48 bool mustRecomputePerFunction() const {
49 return TheDef->getValueAsBit("RecomputePerFunction");
52 void dump() const;
54 static SubtargetFeaturesInfoVec getAll(const RecordKeeper &Records);
56 /// Emit the subtarget feature flag definitions.
57 ///
58 /// This version emits the bit index for the feature and can therefore support
59 /// more than 64 feature bits.
60 static void emitSubtargetFeatureBitEnumeration(
61 const SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS,
62 const std::map<std::string, unsigned> *HwModes = nullptr);
64 static void emitNameTable(SubtargetFeatureInfoMap &SubtargetFeatures,
65 raw_ostream &OS);
67 /// Emit the function to compute the list of available features given a
68 /// subtarget.
69 ///
70 /// This version is used for subtarget features defined using Predicate<>
71 /// and supports more than 64 feature bits.
72 ///
73 /// \param TargetName The name of the target as used in class prefixes (e.g.
74 /// <TargetName>Subtarget)
75 /// \param ClassName The name of the class that will contain the generated
76 /// functions (including the target prefix.)
77 /// \param FuncName The name of the function to emit.
78 /// \param SubtargetFeatures A map of TableGen records to the
79 /// SubtargetFeatureInfo equivalent.
80 /// \param ExtraParams Additional arguments to the generated function.
81 /// \param HwModes Map of HwMode conditions to check.
82 static void emitComputeAvailableFeatures(
83 StringRef TargetName, StringRef ClassName, StringRef FuncName,
84 const SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS,
85 StringRef ExtraParams = "",
86 const std::map<std::string, unsigned> *HwModes = nullptr);
88 /// Emit the function to compute the list of available features given a
89 /// subtarget.
90 ///
91 /// This version is used for subtarget features defined using
92 /// AssemblerPredicate<> and supports up to 64 feature bits.
93 ///
94 /// \param TargetName The name of the target as used in class prefixes (e.g.
95 /// <TargetName>Subtarget)
96 /// \param ClassName The name of the class (without the <Target> prefix)
97 /// that will contain the generated functions.
98 /// \param FuncName The name of the function to emit.
99 /// \param SubtargetFeatures A map of TableGen records to the
100 /// SubtargetFeatureInfo equivalent.
101 static void emitComputeAssemblerAvailableFeatures(
102 StringRef TargetName, StringRef ClassName, StringRef FuncName,
103 SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS);
105 } // end namespace llvm
107 #endif // LLVM_UTIL_TABLEGEN_COMMON_SUBTARGETFEATUREINFO_H