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