]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/utils/TableGen/SubtargetFeatureInfo.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r301441, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / utils / TableGen / SubtargetFeatureInfo.h
1 //===- SubtargetFeatureInfo.h - Helpers for subtarget features ------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H
11 #define LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H
12
13 #include "llvm/TableGen/Error.h"
14 #include "llvm/TableGen/Record.h"
15
16 #include <map>
17 #include <string>
18 #include <vector>
19
20 namespace llvm {
21 class Record;
22 class RecordKeeper;
23
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.
28   Record *TheDef;
29
30   /// \brief 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   /// \brief The name of the enumerated constant identifying this feature.
36   std::string getEnumName() const {
37     return "Feature_" + TheDef->getName().str();
38   }
39
40   /// \brief 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   void dump() const;
47   static std::vector<std::pair<Record *, SubtargetFeatureInfo>>
48   getAll(const RecordKeeper &Records);
49
50   /// Emit the subtarget feature flag definitions.
51   ///
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>
56           &SubtargetFeatures,
57       raw_ostream &OS);
58
59   /// Emit the subtarget feature flag definitions.
60   ///
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>
65           &SubtargetFeatures,
66       raw_ostream &OS);
67
68   static void emitNameTable(std::map<Record *, SubtargetFeatureInfo,
69                                      LessRecordByID> &SubtargetFeatures,
70                             raw_ostream &OS);
71
72   /// Emit the function to compute the list of available features given a
73   /// subtarget.
74   ///
75   /// This version is used for subtarget features defined using Predicate<>
76   /// and supports more than 64 feature bits.
77   ///
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>
88           &SubtargetFeatures,
89       raw_ostream &OS);
90
91   /// Emit the function to compute the list of available features given a
92   /// subtarget.
93   ///
94   /// This version is used for subtarget features defined using
95   /// AssemblerPredicate<> and supports up to 64 feature bits.
96   ///
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>
107           &SubtargetFeatures,
108       raw_ostream &OS);
109 };
110 } // end namespace llvm
111
112 #endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H