114 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_UTIL_TABLEGEN_COMMON_SUBTARGETFEATUREINFO_H10#define LLVM_UTIL_TABLEGEN_COMMON_SUBTARGETFEATUREINFO_H11 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 19namespace llvm {20struct SubtargetFeatureInfo;21using SubtargetFeatureInfoMap =22 std::map<const Record *, SubtargetFeatureInfo, LessRecordByID>;23using SubtargetFeaturesInfoVec =24 std::vector<std::pair<const Record *, SubtargetFeatureInfo>>;25 26/// Helper class for storing information on a subtarget feature which27/// participates in instruction matching.28struct SubtargetFeatureInfo {29 /// The predicate record for this feature.30 const Record *TheDef;31 32 /// An unique index assigned to represent this feature.33 uint64_t Index;34 35 SubtargetFeatureInfo(const 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 for43 /// 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 54 static SubtargetFeaturesInfoVec 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 support59 /// more than 64 feature bits.60 static void emitSubtargetFeatureBitEnumeration(61 const SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS,62 const std::map<std::string, unsigned> *HwModes = nullptr);63 64 static void emitNameTable(SubtargetFeatureInfoMap &SubtargetFeatures,65 raw_ostream &OS);66 67 /// Emit the function to compute the list of available features given a68 /// 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 that will contain the generated76 /// functions (including the target prefix.)77 /// \param FuncName The name of the function to emit.78 /// \param SubtargetFeatures A map of TableGen records to the79 /// SubtargetFeatureInfo equivalent.80 /// \param ExtraParams Additional arguments to the generated function.81 /// \param HwModes Map of HwMode conditions to check.82 static void emitComputeAvailableFeatures(83 StringRef TargetName, StringRef ClassName, StringRef FuncName,84 const SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS,85 StringRef ExtraParams = "",86 const std::map<std::string, unsigned> *HwModes = nullptr);87 88 /// Emit the function to compute the list of available features given a89 /// subtarget.90 ///91 /// This version is used for subtarget features defined using92 /// AssemblerPredicate<> and supports up to 64 feature bits.93 ///94 /// \param TargetName The name of the target as used in class prefixes (e.g.95 /// <TargetName>Subtarget)96 /// \param ClassName The name of the class (without the <Target> prefix)97 /// that will contain the generated functions.98 /// \param FuncName The name of the function to emit.99 /// \param SubtargetFeatures A map of TableGen records to the100 /// SubtargetFeatureInfo equivalent.101 static void emitComputeAssemblerAvailableFeatures(102 StringRef TargetName, StringRef ClassName, StringRef FuncName,103 SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS);104 105 static void emitPredicateCheck(raw_ostream &OS,106 ArrayRef<const Record *> Predicates);107 108 static void emitMCPredicateCheck(raw_ostream &OS, StringRef TargetName,109 ArrayRef<const Record *> Predicates);110};111} // end namespace llvm112 113#endif // LLVM_UTIL_TABLEGEN_COMMON_SUBTARGETFEATUREINFO_H114