Matt Arsenault | e1cbaba | 2019-02-21 15:48:10 +0000 | [diff] [blame] | 1 | //===- SubtargetFeatureInfo.h - Helpers for subtarget features --*- C++ -*-===// |
Daniel Sanders | ea6ef3d | 2016-11-15 09:51:02 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Daniel Sanders | ea6ef3d | 2016-11-15 09:51:02 +0000 | [diff] [blame] | 6 | // |
| 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 Sanders | 72db2a3 | 2016-11-19 13:05:44 +0000 | [diff] [blame] | 16 | #include <string> |
| 17 | #include <vector> |
Daniel Sanders | ea6ef3d | 2016-11-15 09:51:02 +0000 | [diff] [blame] | 18 | |
| 19 | namespace llvm { |
| 20 | class Record; |
| 21 | class RecordKeeper; |
| 22 | |
Daniel Sanders | e9fdba3 | 2017-04-29 17:30:09 +0000 | [diff] [blame] | 23 | struct SubtargetFeatureInfo; |
| 24 | using SubtargetFeatureInfoMap = std::map<Record *, SubtargetFeatureInfo, LessRecordByID>; |
| 25 | |
Daniel Sanders | ea6ef3d | 2016-11-15 09:51:02 +0000 | [diff] [blame] | 26 | /// Helper class for storing information on a subtarget feature which |
| 27 | /// participates in instruction matching. |
| 28 | struct SubtargetFeatureInfo { |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 29 | /// The predicate record for this feature. |
Daniel Sanders | ea6ef3d | 2016-11-15 09:51:02 +0000 | [diff] [blame] | 30 | Record *TheDef; |
| 31 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 32 | /// An unique index assigned to represent this feature. |
Daniel Sanders | ea6ef3d | 2016-11-15 09:51:02 +0000 | [diff] [blame] | 33 | uint64_t Index; |
| 34 | |
| 35 | SubtargetFeatureInfo(Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {} |
| 36 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 37 | /// The name of the enumerated constant identifying this feature. |
Matthias Braun | 4a86d45 | 2016-12-04 05:48:16 +0000 | [diff] [blame] | 38 | std::string getEnumName() const { |
| 39 | return "Feature_" + TheDef->getName().str(); |
| 40 | } |
Daniel Sanders | ea6ef3d | 2016-11-15 09:51:02 +0000 | [diff] [blame] | 41 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 42 | /// The name of the enumerated constant identifying the bitnumber for |
Daniel Sanders | e7b0d66 | 2017-04-21 15:59:56 +0000 | [diff] [blame] | 43 | /// this feature. |
| 44 | std::string getEnumBitName() const { |
| 45 | return "Feature_" + TheDef->getName().str() + "Bit"; |
| 46 | } |
| 47 | |
Daniel Sanders | e9fdba3 | 2017-04-29 17:30:09 +0000 | [diff] [blame] | 48 | bool mustRecomputePerFunction() const { |
| 49 | return TheDef->getValueAsBit("RecomputePerFunction"); |
| 50 | } |
| 51 | |
Daniel Sanders | ea6ef3d | 2016-11-15 09:51:02 +0000 | [diff] [blame] | 52 | void dump() const; |
| 53 | static std::vector<std::pair<Record *, SubtargetFeatureInfo>> |
| 54 | getAll(const RecordKeeper &Records); |
| 55 | |
Daniel Sanders | 72db2a3 | 2016-11-19 13:05:44 +0000 | [diff] [blame] | 56 | /// Emit the subtarget feature flag definitions. |
Daniel Sanders | e7b0d66 | 2017-04-21 15:59:56 +0000 | [diff] [blame] | 57 | /// |
Daniel Sanders | e7b0d66 | 2017-04-21 15:59:56 +0000 | [diff] [blame] | 58 | /// This version emits the bit index for the feature and can therefore support |
| 59 | /// more than 64 feature bits. |
Daniel Sanders | e9fdba3 | 2017-04-29 17:30:09 +0000 | [diff] [blame] | 60 | static void |
| 61 | emitSubtargetFeatureBitEnumeration(SubtargetFeatureInfoMap &SubtargetFeatures, |
| 62 | raw_ostream &OS); |
Daniel Sanders | e7b0d66 | 2017-04-21 15:59:56 +0000 | [diff] [blame] | 63 | |
Daniel Sanders | e9fdba3 | 2017-04-29 17:30:09 +0000 | [diff] [blame] | 64 | static void emitNameTable(SubtargetFeatureInfoMap &SubtargetFeatures, |
Daniel Sanders | 72db2a3 | 2016-11-19 13:05:44 +0000 | [diff] [blame] | 65 | raw_ostream &OS); |
| 66 | |
Daniel Sanders | ea6ef3d | 2016-11-15 09:51:02 +0000 | [diff] [blame] | 67 | /// Emit the function to compute the list of available features given a |
| 68 | /// subtarget. |
| 69 | /// |
Daniel Sanders | e7b0d66 | 2017-04-21 15:59:56 +0000 | [diff] [blame] | 70 | /// This version is used for subtarget features defined using Predicate<> |
| 71 | /// and supports more than 64 feature bits. |
| 72 | /// |
Daniel Sanders | ea6ef3d | 2016-11-15 09:51:02 +0000 | [diff] [blame] | 73 | /// \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 Sanders | 72db2a3 | 2016-11-19 13:05:44 +0000 | [diff] [blame] | 77 | /// \param FuncName The name of the function to emit. |
Daniel Sanders | ea6ef3d | 2016-11-15 09:51:02 +0000 | [diff] [blame] | 78 | /// \param SubtargetFeatures A map of TableGen records to the |
| 79 | /// SubtargetFeatureInfo equivalent. |
Daniel Sanders | e9fdba3 | 2017-04-29 17:30:09 +0000 | [diff] [blame] | 80 | /// \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 Sanders | e7b0d66 | 2017-04-21 15:59:56 +0000 | [diff] [blame] | 86 | |
| 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 Sanders | e9fdba3 | 2017-04-29 17:30:09 +0000 | [diff] [blame] | 102 | SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS); |
Daniel Sanders | ea6ef3d | 2016-11-15 09:51:02 +0000 | [diff] [blame] | 103 | }; |
| 104 | } // end namespace llvm |
| 105 | |
| 106 | #endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H |