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/ADT/StringRef.h" 13 #include "llvm/TableGen/Record.h" 14 #include <map> 15 #include <string> 16 #include <utility> 17 #include <vector> 18 19 namespace llvm { 20 struct SubtargetFeatureInfo; 21 using SubtargetFeatureInfoMap = std::map<Record *, SubtargetFeatureInfo, LessRecordByID>; 22 23 /// Helper class for storing information on a subtarget feature which 24 /// participates in instruction matching. 25 struct SubtargetFeatureInfo { 26 /// The predicate record for this feature. 27 Record *TheDef; 28 29 /// An unique index assigned to represent this feature. 30 uint64_t Index; 31 32 SubtargetFeatureInfo(Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {} 33 34 /// The name of the enumerated constant identifying this feature. 35 std::string getEnumName() const { 36 return "Feature_" + TheDef->getName().str(); 37 } 38 39 /// The name of the enumerated constant identifying the bitnumber for 40 /// this feature. 41 std::string getEnumBitName() const { 42 return "Feature_" + TheDef->getName().str() + "Bit"; 43 } 44 45 bool mustRecomputePerFunction() const { 46 return TheDef->getValueAsBit("RecomputePerFunction"); 47 } 48 49 void dump() const; 50 static std::vector<std::pair<Record *, SubtargetFeatureInfo>> 51 getAll(const RecordKeeper &Records); 52 53 /// Emit the subtarget feature flag definitions. 54 /// 55 /// This version emits the bit index for the feature and can therefore support 56 /// more than 64 feature bits. 57 static void 58 emitSubtargetFeatureBitEnumeration(SubtargetFeatureInfoMap &SubtargetFeatures, 59 raw_ostream &OS); 60 61 static void emitNameTable(SubtargetFeatureInfoMap &SubtargetFeatures, 62 raw_ostream &OS); 63 64 /// Emit the function to compute the list of available features given a 65 /// subtarget. 66 /// 67 /// This version is used for subtarget features defined using Predicate<> 68 /// and supports more than 64 feature bits. 69 /// 70 /// \param TargetName The name of the target as used in class prefixes (e.g. 71 /// <TargetName>Subtarget) 72 /// \param ClassName The name of the class that will contain the generated 73 /// functions (including the target prefix.) 74 /// \param FuncName The name of the function to emit. 75 /// \param SubtargetFeatures A map of TableGen records to the 76 /// SubtargetFeatureInfo equivalent. 77 /// \param ExtraParams Additional arguments to the generated function. 78 static void 79 emitComputeAvailableFeatures(StringRef TargetName, StringRef ClassName, 80 StringRef FuncName, 81 SubtargetFeatureInfoMap &SubtargetFeatures, 82 raw_ostream &OS, StringRef ExtraParams = ""); 83 84 /// Emit the function to compute the list of available features given a 85 /// subtarget. 86 /// 87 /// This version is used for subtarget features defined using 88 /// AssemblerPredicate<> and supports up to 64 feature bits. 89 /// 90 /// \param TargetName The name of the target as used in class prefixes (e.g. 91 /// <TargetName>Subtarget) 92 /// \param ClassName The name of the class (without the <Target> prefix) 93 /// that will contain the generated functions. 94 /// \param FuncName The name of the function to emit. 95 /// \param SubtargetFeatures A map of TableGen records to the 96 /// SubtargetFeatureInfo equivalent. 97 static void emitComputeAssemblerAvailableFeatures( 98 StringRef TargetName, StringRef ClassName, StringRef FuncName, 99 SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS); 100 }; 101 } // end namespace llvm 102 103 #endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H 104