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 struct SubtargetFeatureInfo; 25 using SubtargetFeatureInfoMap = std::map<Record *, SubtargetFeatureInfo, LessRecordByID>; 26 27 /// Helper class for storing information on a subtarget feature which 28 /// participates in instruction matching. 29 struct SubtargetFeatureInfo { 30 /// The predicate record for this feature. 31 Record *TheDef; 32 33 /// An unique index assigned to represent this feature. 34 uint64_t Index; 35 SubtargetFeatureInfoSubtargetFeatureInfo36 SubtargetFeatureInfo(Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {} 37 38 /// The name of the enumerated constant identifying this feature. getEnumNameSubtargetFeatureInfo39 std::string getEnumName() const { 40 return "Feature_" + TheDef->getName().str(); 41 } 42 43 /// The name of the enumerated constant identifying the bitnumber for 44 /// this feature. getEnumBitNameSubtargetFeatureInfo45 std::string getEnumBitName() const { 46 return "Feature_" + TheDef->getName().str() + "Bit"; 47 } 48 mustRecomputePerFunctionSubtargetFeatureInfo49 bool mustRecomputePerFunction() const { 50 return TheDef->getValueAsBit("RecomputePerFunction"); 51 } 52 53 void dump() const; 54 static std::vector<std::pair<Record *, SubtargetFeatureInfo>> 55 getAll(const RecordKeeper &Records); 56 57 /// Emit the subtarget feature flag definitions. 58 /// 59 /// This version emits the bit value for the feature and is therefore limited 60 /// to 64 feature bits. 61 static void emitSubtargetFeatureFlagEnumeration( 62 SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS); 63 64 /// 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. 68 static void 69 emitSubtargetFeatureBitEnumeration(SubtargetFeatureInfoMap &SubtargetFeatures, 70 raw_ostream &OS); 71 72 static void emitNameTable(SubtargetFeatureInfoMap &SubtargetFeatures, 73 raw_ostream &OS); 74 75 /// Emit the function to compute the list of available features given a 76 /// subtarget. 77 /// 78 /// This version is used for subtarget features defined using Predicate<> 79 /// and supports more than 64 feature bits. 80 /// 81 /// \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. 85 /// \param FuncName The name of the function to emit. 86 /// \param SubtargetFeatures A map of TableGen records to the 87 /// SubtargetFeatureInfo equivalent. 88 /// \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 = ""); 94 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, 110 SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS); 111 }; 112 } // end namespace llvm 113 114 #endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H 115