blob: 71e6748c863f4a5989c019a6090895ba33239346 [file] [log] [blame]
Daniel Sanders57a599e2016-11-15 09:51:02 +00001//===- 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>
Daniel Sandersb313c742016-11-19 13:05:44 +000017#include <string>
18#include <vector>
Daniel Sanders57a599e2016-11-15 09:51:02 +000019
20namespace llvm {
21class Record;
22class RecordKeeper;
23
Daniel Sandersf31ac9d2017-04-29 17:30:09 +000024struct SubtargetFeatureInfo;
25using SubtargetFeatureInfoMap = std::map<Record *, SubtargetFeatureInfo, LessRecordByID>;
26
Daniel Sanders57a599e2016-11-15 09:51:02 +000027/// Helper class for storing information on a subtarget feature which
28/// participates in instruction matching.
29struct SubtargetFeatureInfo {
Adrian Prantl26b584c2018-05-01 15:54:18 +000030 /// The predicate record for this feature.
Daniel Sanders57a599e2016-11-15 09:51:02 +000031 Record *TheDef;
32
Adrian Prantl26b584c2018-05-01 15:54:18 +000033 /// An unique index assigned to represent this feature.
Daniel Sanders57a599e2016-11-15 09:51:02 +000034 uint64_t Index;
35
36 SubtargetFeatureInfo(Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {}
37
Adrian Prantl26b584c2018-05-01 15:54:18 +000038 /// The name of the enumerated constant identifying this feature.
Matthias Braun0c517c82016-12-04 05:48:16 +000039 std::string getEnumName() const {
40 return "Feature_" + TheDef->getName().str();
41 }
Daniel Sanders57a599e2016-11-15 09:51:02 +000042
Adrian Prantl26b584c2018-05-01 15:54:18 +000043 /// The name of the enumerated constant identifying the bitnumber for
Daniel Sanderse8660ea2017-04-21 15:59:56 +000044 /// this feature.
45 std::string getEnumBitName() const {
46 return "Feature_" + TheDef->getName().str() + "Bit";
47 }
48
Daniel Sandersf31ac9d2017-04-29 17:30:09 +000049 bool mustRecomputePerFunction() const {
50 return TheDef->getValueAsBit("RecomputePerFunction");
51 }
52
Daniel Sanders57a599e2016-11-15 09:51:02 +000053 void dump() const;
54 static std::vector<std::pair<Record *, SubtargetFeatureInfo>>
55 getAll(const RecordKeeper &Records);
56
Daniel Sandersb313c742016-11-19 13:05:44 +000057 /// Emit the subtarget feature flag definitions.
Daniel Sanderse8660ea2017-04-21 15:59:56 +000058 ///
59 /// This version emits the bit value for the feature and is therefore limited
60 /// to 64 feature bits.
Daniel Sandersb313c742016-11-19 13:05:44 +000061 static void emitSubtargetFeatureFlagEnumeration(
Daniel Sandersf31ac9d2017-04-29 17:30:09 +000062 SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS);
Daniel Sandersb313c742016-11-19 13:05:44 +000063
Daniel Sanderse8660ea2017-04-21 15:59:56 +000064 /// Emit the subtarget feature flag definitions.
65 ///
66 /// This version emits the bit index for the feature and can therefore support
67 /// more than 64 feature bits.
Daniel Sandersf31ac9d2017-04-29 17:30:09 +000068 static void
69 emitSubtargetFeatureBitEnumeration(SubtargetFeatureInfoMap &SubtargetFeatures,
70 raw_ostream &OS);
Daniel Sanderse8660ea2017-04-21 15:59:56 +000071
Daniel Sandersf31ac9d2017-04-29 17:30:09 +000072 static void emitNameTable(SubtargetFeatureInfoMap &SubtargetFeatures,
Daniel Sandersb313c742016-11-19 13:05:44 +000073 raw_ostream &OS);
74
Daniel Sanders57a599e2016-11-15 09:51:02 +000075 /// Emit the function to compute the list of available features given a
76 /// subtarget.
77 ///
Daniel Sanderse8660ea2017-04-21 15:59:56 +000078 /// This version is used for subtarget features defined using Predicate<>
79 /// and supports more than 64 feature bits.
80 ///
Daniel Sanders57a599e2016-11-15 09:51:02 +000081 /// \param TargetName The name of the target as used in class prefixes (e.g.
82 /// <TargetName>Subtarget)
83 /// \param ClassName The name of the class (without the <Target> prefix)
84 /// that will contain the generated functions.
Daniel Sandersb313c742016-11-19 13:05:44 +000085 /// \param FuncName The name of the function to emit.
Daniel Sanders57a599e2016-11-15 09:51:02 +000086 /// \param SubtargetFeatures A map of TableGen records to the
87 /// SubtargetFeatureInfo equivalent.
Daniel Sandersf31ac9d2017-04-29 17:30:09 +000088 /// \param ExtraParams Additional arguments to the generated function.
89 static void
90 emitComputeAvailableFeatures(StringRef TargetName, StringRef ClassName,
91 StringRef FuncName,
92 SubtargetFeatureInfoMap &SubtargetFeatures,
93 raw_ostream &OS, StringRef ExtraParams = "");
Daniel Sanderse8660ea2017-04-21 15:59:56 +000094
95 /// Emit the function to compute the list of available features given a
96 /// subtarget.
97 ///
98 /// This version is used for subtarget features defined using
99 /// AssemblerPredicate<> and supports up to 64 feature bits.
100 ///
101 /// \param TargetName The name of the target as used in class prefixes (e.g.
102 /// <TargetName>Subtarget)
103 /// \param ClassName The name of the class (without the <Target> prefix)
104 /// that will contain the generated functions.
105 /// \param FuncName The name of the function to emit.
106 /// \param SubtargetFeatures A map of TableGen records to the
107 /// SubtargetFeatureInfo equivalent.
108 static void emitComputeAssemblerAvailableFeatures(
109 StringRef TargetName, StringRef ClassName, StringRef FuncName,
Daniel Sandersf31ac9d2017-04-29 17:30:09 +0000110 SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS);
Daniel Sanders57a599e2016-11-15 09:51:02 +0000111};
112} // end namespace llvm
113
114#endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H