Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / utils / TableGen / SubtargetFeatureInfo.h
blob9401004484350a3d11a589e637fb11c4b9b22326
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_SUBTARGETFEATUREINFO_H
10 #define LLVM_UTIL_TABLEGEN_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 = std::map<Record *, SubtargetFeatureInfo, LessRecordByID>;
23 /// Helper class for storing information on a subtarget feature which
24 /// participates in instruction matching.
25 struct SubtargetFeatureInfo {
26 /// The predicate record for this feature.
27 Record *TheDef;
29 /// An unique index assigned to represent this feature.
30 uint64_t Index;
32 SubtargetFeatureInfo(Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {}
34 /// The name of the enumerated constant identifying this feature.
35 std::string getEnumName() const {
36 return "Feature_" + TheDef->getName().str();
39 /// The name of the enumerated constant identifying the bitnumber for
40 /// this feature.
41 std::string getEnumBitName() const {
42 return "Feature_" + TheDef->getName().str() + "Bit";
45 bool mustRecomputePerFunction() const {
46 return TheDef->getValueAsBit("RecomputePerFunction");
49 void dump() const;
50 static std::vector<std::pair<Record *, SubtargetFeatureInfo>>
51 getAll(const RecordKeeper &Records);
53 /// Emit the subtarget feature flag definitions.
54 ///
55 /// This version emits the bit index for the feature and can therefore support
56 /// more than 64 feature bits.
57 static void emitSubtargetFeatureBitEnumeration(
58 const SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS,
59 const std::map<std::string, unsigned> *HwModes = nullptr);
61 static void emitNameTable(SubtargetFeatureInfoMap &SubtargetFeatures,
62 raw_ostream &OS);
64 /// Emit the function to compute the list of available features given a
65 /// subtarget.
66 ///
67 /// This version is used for subtarget features defined using Predicate<>
68 /// and supports more than 64 feature bits.
69 ///
70 /// \param TargetName The name of the target as used in class prefixes (e.g.
71 /// <TargetName>Subtarget)
72 /// \param ClassName The name of the class that will contain the generated
73 /// functions (including the target prefix.)
74 /// \param FuncName The name of the function to emit.
75 /// \param SubtargetFeatures A map of TableGen records to the
76 /// SubtargetFeatureInfo equivalent.
77 /// \param ExtraParams Additional arguments to the generated function.
78 /// \param HwModes Map of HwMode conditions to check.
79 static void emitComputeAvailableFeatures(
80 StringRef TargetName, StringRef ClassName, StringRef FuncName,
81 const SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS,
82 StringRef ExtraParams = "",
83 const std::map<std::string, unsigned> *HwModes = nullptr);
85 /// Emit the function to compute the list of available features given a
86 /// subtarget.
87 ///
88 /// This version is used for subtarget features defined using
89 /// AssemblerPredicate<> and supports up to 64 feature bits.
90 ///
91 /// \param TargetName The name of the target as used in class prefixes (e.g.
92 /// <TargetName>Subtarget)
93 /// \param ClassName The name of the class (without the <Target> prefix)
94 /// that will contain the generated functions.
95 /// \param FuncName The name of the function to emit.
96 /// \param SubtargetFeatures A map of TableGen records to the
97 /// SubtargetFeatureInfo equivalent.
98 static void emitComputeAssemblerAvailableFeatures(
99 StringRef TargetName, StringRef ClassName, StringRef FuncName,
100 SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS);
102 } // end namespace llvm
104 #endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H