1 //===- SubtargetFeatureInfo.h - Helpers for subtarget features --*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H
10 #define LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H
12 #include "llvm/TableGen/Error.h"
13 #include "llvm/TableGen/Record.h"
23 struct SubtargetFeatureInfo
;
24 using SubtargetFeatureInfoMap
= std::map
<Record
*, SubtargetFeatureInfo
, LessRecordByID
>;
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.
32 /// An unique index assigned to represent this feature.
35 SubtargetFeatureInfo(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
44 std::string
getEnumBitName() const {
45 return "Feature_" + TheDef
->getName().str() + "Bit";
48 bool mustRecomputePerFunction() const {
49 return TheDef
->getValueAsBit("RecomputePerFunction");
53 static std::vector
<std::pair
<Record
*, SubtargetFeatureInfo
>>
54 getAll(const RecordKeeper
&Records
);
56 /// Emit the subtarget feature flag definitions.
58 /// This version emits the bit index for the feature and can therefore support
59 /// more than 64 feature bits.
61 emitSubtargetFeatureBitEnumeration(SubtargetFeatureInfoMap
&SubtargetFeatures
,
64 static void emitNameTable(SubtargetFeatureInfoMap
&SubtargetFeatures
,
67 /// Emit the function to compute the list of available features given a
70 /// This version is used for subtarget features defined using Predicate<>
71 /// and supports more than 64 feature bits.
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 (without the <Target> prefix)
76 /// that will contain the generated functions.
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.
82 emitComputeAvailableFeatures(StringRef TargetName
, StringRef ClassName
,
84 SubtargetFeatureInfoMap
&SubtargetFeatures
,
85 raw_ostream
&OS
, StringRef ExtraParams
= "");
87 /// Emit the function to compute the list of available features given a
90 /// This version is used for subtarget features defined using
91 /// AssemblerPredicate<> and supports up to 64 feature bits.
93 /// \param TargetName The name of the target as used in class prefixes (e.g.
94 /// <TargetName>Subtarget)
95 /// \param ClassName The name of the class (without the <Target> prefix)
96 /// that will contain the generated functions.
97 /// \param FuncName The name of the function to emit.
98 /// \param SubtargetFeatures A map of TableGen records to the
99 /// SubtargetFeatureInfo equivalent.
100 static void emitComputeAssemblerAvailableFeatures(
101 StringRef TargetName
, StringRef ClassName
, StringRef FuncName
,
102 SubtargetFeatureInfoMap
&SubtargetFeatures
, raw_ostream
&OS
);
104 } // end namespace llvm
106 #endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H