1 //===- SubtargetFeatureInfo.h - Helpers for subtarget features ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H
11 #define LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H
13 #include "llvm/TableGen/Error.h"
14 #include "llvm/TableGen/Record.h"
24 struct SubtargetFeatureInfo;
25 using SubtargetFeatureInfoMap = std::map<Record *, SubtargetFeatureInfo, LessRecordByID>;
27 /// Helper class for storing information on a subtarget feature which
28 /// participates in instruction matching.
29 struct SubtargetFeatureInfo {
30 /// The predicate record for this feature.
33 /// An unique index assigned to represent this feature.
36 SubtargetFeatureInfo(Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {}
38 /// The name of the enumerated constant identifying this feature.
39 std::string getEnumName() const {
40 return "Feature_" + TheDef->getName().str();
43 /// The name of the enumerated constant identifying the bitnumber for
45 std::string getEnumBitName() const {
46 return "Feature_" + TheDef->getName().str() + "Bit";
49 bool mustRecomputePerFunction() const {
50 return TheDef->getValueAsBit("RecomputePerFunction");
54 static std::vector<std::pair<Record *, SubtargetFeatureInfo>>
55 getAll(const RecordKeeper &Records);
57 /// Emit the subtarget feature flag definitions.
59 /// This version emits the bit value for the feature and is therefore limited
60 /// to 64 feature bits.
61 static void emitSubtargetFeatureFlagEnumeration(
62 SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS);
64 /// Emit the subtarget feature flag definitions.
66 /// This version emits the bit index for the feature and can therefore support
67 /// more than 64 feature bits.
69 emitSubtargetFeatureBitEnumeration(SubtargetFeatureInfoMap &SubtargetFeatures,
72 static void emitNameTable(SubtargetFeatureInfoMap &SubtargetFeatures,
75 /// Emit the function to compute the list of available features given a
78 /// This version is used for subtarget features defined using Predicate<>
79 /// and supports more than 64 feature bits.
81 /// \param TargetName The name of the target as used in class prefixes (e.g.
82 /// <TargetName>Subtarget)
83 /// \param ClassName The name of the class (without the <Target> prefix)
84 /// that will contain the generated functions.
85 /// \param FuncName The name of the function to emit.
86 /// \param SubtargetFeatures A map of TableGen records to the
87 /// SubtargetFeatureInfo equivalent.
88 /// \param ExtraParams Additional arguments to the generated function.
90 emitComputeAvailableFeatures(StringRef TargetName, StringRef ClassName,
92 SubtargetFeatureInfoMap &SubtargetFeatures,
93 raw_ostream &OS, StringRef ExtraParams = "");
95 /// Emit the function to compute the list of available features given a
98 /// This version is used for subtarget features defined using
99 /// AssemblerPredicate<> and supports up to 64 feature bits.
101 /// \param TargetName The name of the target as used in class prefixes (e.g.
102 /// <TargetName>Subtarget)
103 /// \param ClassName The name of the class (without the <Target> prefix)
104 /// that will contain the generated functions.
105 /// \param FuncName The name of the function to emit.
106 /// \param SubtargetFeatures A map of TableGen records to the
107 /// SubtargetFeatureInfo equivalent.
108 static void emitComputeAssemblerAvailableFeatures(
109 StringRef TargetName, StringRef ClassName, StringRef FuncName,
110 SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS);
112 } // end namespace llvm
114 #endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H