blob: d72f8b93461fabeb366949b5c7754dc12a2df68c [file] [log] [blame]
Matt Arsenaulte1cbaba2019-02-21 15:48:10 +00001//===- SubtargetFeatureInfo.h - Helpers for subtarget features --*- C++ -*-===//
Daniel Sandersea6ef3d2016-11-15 09:51:02 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Daniel Sandersea6ef3d2016-11-15 09:51:02 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H
10#define LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H
11
12#include "llvm/TableGen/Error.h"
13#include "llvm/TableGen/Record.h"
14
15#include <map>
Daniel Sanders72db2a32016-11-19 13:05:44 +000016#include <string>
17#include <vector>
Daniel Sandersea6ef3d2016-11-15 09:51:02 +000018
19namespace llvm {
20class Record;
21class RecordKeeper;
22
Daniel Sanderse9fdba32017-04-29 17:30:09 +000023struct SubtargetFeatureInfo;
24using SubtargetFeatureInfoMap = std::map<Record *, SubtargetFeatureInfo, LessRecordByID>;
25
Daniel Sandersea6ef3d2016-11-15 09:51:02 +000026/// Helper class for storing information on a subtarget feature which
27/// participates in instruction matching.
28struct SubtargetFeatureInfo {
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000029 /// The predicate record for this feature.
Daniel Sandersea6ef3d2016-11-15 09:51:02 +000030 Record *TheDef;
31
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000032 /// An unique index assigned to represent this feature.
Daniel Sandersea6ef3d2016-11-15 09:51:02 +000033 uint64_t Index;
34
35 SubtargetFeatureInfo(Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {}
36
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000037 /// The name of the enumerated constant identifying this feature.
Matthias Braun4a86d452016-12-04 05:48:16 +000038 std::string getEnumName() const {
39 return "Feature_" + TheDef->getName().str();
40 }
Daniel Sandersea6ef3d2016-11-15 09:51:02 +000041
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000042 /// The name of the enumerated constant identifying the bitnumber for
Daniel Sanderse7b0d662017-04-21 15:59:56 +000043 /// this feature.
44 std::string getEnumBitName() const {
45 return "Feature_" + TheDef->getName().str() + "Bit";
46 }
47
Daniel Sanderse9fdba32017-04-29 17:30:09 +000048 bool mustRecomputePerFunction() const {
49 return TheDef->getValueAsBit("RecomputePerFunction");
50 }
51
Daniel Sandersea6ef3d2016-11-15 09:51:02 +000052 void dump() const;
53 static std::vector<std::pair<Record *, SubtargetFeatureInfo>>
54 getAll(const RecordKeeper &Records);
55
Daniel Sanders72db2a32016-11-19 13:05:44 +000056 /// Emit the subtarget feature flag definitions.
Daniel Sanderse7b0d662017-04-21 15:59:56 +000057 ///
Daniel Sanderse7b0d662017-04-21 15:59:56 +000058 /// This version emits the bit index for the feature and can therefore support
59 /// more than 64 feature bits.
Daniel Sanderse9fdba32017-04-29 17:30:09 +000060 static void
61 emitSubtargetFeatureBitEnumeration(SubtargetFeatureInfoMap &SubtargetFeatures,
62 raw_ostream &OS);
Daniel Sanderse7b0d662017-04-21 15:59:56 +000063
Daniel Sanderse9fdba32017-04-29 17:30:09 +000064 static void emitNameTable(SubtargetFeatureInfoMap &SubtargetFeatures,
Daniel Sanders72db2a32016-11-19 13:05:44 +000065 raw_ostream &OS);
66
Daniel Sandersea6ef3d2016-11-15 09:51:02 +000067 /// Emit the function to compute the list of available features given a
68 /// subtarget.
69 ///
Daniel Sanderse7b0d662017-04-21 15:59:56 +000070 /// This version is used for subtarget features defined using Predicate<>
71 /// and supports more than 64 feature bits.
72 ///
Daniel Sandersea6ef3d2016-11-15 09:51:02 +000073 /// \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.
Daniel Sanders72db2a32016-11-19 13:05:44 +000077 /// \param FuncName The name of the function to emit.
Daniel Sandersea6ef3d2016-11-15 09:51:02 +000078 /// \param SubtargetFeatures A map of TableGen records to the
79 /// SubtargetFeatureInfo equivalent.
Daniel Sanderse9fdba32017-04-29 17:30:09 +000080 /// \param ExtraParams Additional arguments to the generated function.
81 static void
82 emitComputeAvailableFeatures(StringRef TargetName, StringRef ClassName,
83 StringRef FuncName,
84 SubtargetFeatureInfoMap &SubtargetFeatures,
85 raw_ostream &OS, StringRef ExtraParams = "");
Daniel Sanderse7b0d662017-04-21 15:59:56 +000086
87 /// Emit the function to compute the list of available features given a
88 /// subtarget.
89 ///
90 /// This version is used for subtarget features defined using
91 /// AssemblerPredicate<> and supports up to 64 feature bits.
92 ///
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,
Daniel Sanderse9fdba32017-04-29 17:30:09 +0000102 SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS);
Daniel Sandersea6ef3d2016-11-15 09:51:02 +0000103};
104} // end namespace llvm
105
106#endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H