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 /// Helper class for storing information on a subtarget feature which
25 /// participates in instruction matching.
26 struct SubtargetFeatureInfo {
27 /// \brief The predicate record for this feature.
30 /// \brief An unique index assigned to represent this feature.
33 SubtargetFeatureInfo(Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {}
35 /// \brief The name of the enumerated constant identifying this feature.
36 std::string getEnumName() const {
37 return "Feature_" + TheDef->getName().str();
40 /// \brief The name of the enumerated constant identifying the bitnumber for
42 std::string getEnumBitName() const {
43 return "Feature_" + TheDef->getName().str() + "Bit";
47 static std::vector<std::pair<Record *, SubtargetFeatureInfo>>
48 getAll(const RecordKeeper &Records);
50 /// Emit the subtarget feature flag definitions.
52 /// This version emits the bit value for the feature and is therefore limited
53 /// to 64 feature bits.
54 static void emitSubtargetFeatureFlagEnumeration(
55 std::map<Record *, SubtargetFeatureInfo, LessRecordByID>
59 /// Emit the subtarget feature flag definitions.
61 /// This version emits the bit index for the feature and can therefore support
62 /// more than 64 feature bits.
63 static void emitSubtargetFeatureBitEnumeration(
64 std::map<Record *, SubtargetFeatureInfo, LessRecordByID>
68 static void emitNameTable(std::map<Record *, SubtargetFeatureInfo,
69 LessRecordByID> &SubtargetFeatures,
72 /// Emit the function to compute the list of available features given a
75 /// This version is used for subtarget features defined using Predicate<>
76 /// and supports more than 64 feature bits.
78 /// \param TargetName The name of the target as used in class prefixes (e.g.
79 /// <TargetName>Subtarget)
80 /// \param ClassName The name of the class (without the <Target> prefix)
81 /// that will contain the generated functions.
82 /// \param FuncName The name of the function to emit.
83 /// \param SubtargetFeatures A map of TableGen records to the
84 /// SubtargetFeatureInfo equivalent.
85 static void emitComputeAvailableFeatures(
86 StringRef TargetName, StringRef ClassName, StringRef FuncName,
87 std::map<Record *, SubtargetFeatureInfo, LessRecordByID>
91 /// Emit the function to compute the list of available features given a
94 /// This version is used for subtarget features defined using
95 /// AssemblerPredicate<> and supports up to 64 feature bits.
97 /// \param TargetName The name of the target as used in class prefixes (e.g.
98 /// <TargetName>Subtarget)
99 /// \param ClassName The name of the class (without the <Target> prefix)
100 /// that will contain the generated functions.
101 /// \param FuncName The name of the function to emit.
102 /// \param SubtargetFeatures A map of TableGen records to the
103 /// SubtargetFeatureInfo equivalent.
104 static void emitComputeAssemblerAvailableFeatures(
105 StringRef TargetName, StringRef ClassName, StringRef FuncName,
106 std::map<Record *, SubtargetFeatureInfo, LessRecordByID>
110 } // end namespace llvm
112 #endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H