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/Record.h"
18 struct SubtargetFeatureInfo
;
19 using SubtargetFeatureInfoMap
= std::map
<Record
*, SubtargetFeatureInfo
, LessRecordByID
>;
21 /// Helper class for storing information on a subtarget feature which
22 /// participates in instruction matching.
23 struct SubtargetFeatureInfo
{
24 /// The predicate record for this feature.
27 /// An unique index assigned to represent this feature.
30 SubtargetFeatureInfo(Record
*D
, uint64_t Idx
) : TheDef(D
), Index(Idx
) {}
32 /// The name of the enumerated constant identifying this feature.
33 std::string
getEnumName() const {
34 return "Feature_" + TheDef
->getName().str();
37 /// The name of the enumerated constant identifying the bitnumber for
39 std::string
getEnumBitName() const {
40 return "Feature_" + TheDef
->getName().str() + "Bit";
43 bool mustRecomputePerFunction() const {
44 return TheDef
->getValueAsBit("RecomputePerFunction");
48 static std::vector
<std::pair
<Record
*, SubtargetFeatureInfo
>>
49 getAll(const RecordKeeper
&Records
);
51 /// Emit the subtarget feature flag definitions.
53 /// This version emits the bit index for the feature and can therefore support
54 /// more than 64 feature bits.
56 emitSubtargetFeatureBitEnumeration(SubtargetFeatureInfoMap
&SubtargetFeatures
,
59 static void emitNameTable(SubtargetFeatureInfoMap
&SubtargetFeatures
,
62 /// Emit the function to compute the list of available features given a
65 /// This version is used for subtarget features defined using Predicate<>
66 /// and supports more than 64 feature bits.
68 /// \param TargetName The name of the target as used in class prefixes (e.g.
69 /// <TargetName>Subtarget)
70 /// \param ClassName The name of the class (without the <Target> prefix)
71 /// that will contain the generated functions.
72 /// \param FuncName The name of the function to emit.
73 /// \param SubtargetFeatures A map of TableGen records to the
74 /// SubtargetFeatureInfo equivalent.
75 /// \param ExtraParams Additional arguments to the generated function.
77 emitComputeAvailableFeatures(StringRef TargetName
, StringRef ClassName
,
79 SubtargetFeatureInfoMap
&SubtargetFeatures
,
80 raw_ostream
&OS
, StringRef ExtraParams
= "");
82 /// Emit the function to compute the list of available features given a
85 /// This version is used for subtarget features defined using
86 /// AssemblerPredicate<> and supports up to 64 feature bits.
88 /// \param TargetName The name of the target as used in class prefixes (e.g.
89 /// <TargetName>Subtarget)
90 /// \param ClassName The name of the class (without the <Target> prefix)
91 /// that will contain the generated functions.
92 /// \param FuncName The name of the function to emit.
93 /// \param SubtargetFeatures A map of TableGen records to the
94 /// SubtargetFeatureInfo equivalent.
95 static void emitComputeAssemblerAvailableFeatures(
96 StringRef TargetName
, StringRef ClassName
, StringRef FuncName
,
97 SubtargetFeatureInfoMap
&SubtargetFeatures
, raw_ostream
&OS
);
99 } // end namespace llvm
101 #endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H