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

source code of llvm/utils/TableGen/Common/SubtargetFeatureInfo.h