Path: blob/main/contrib/llvm-project/llvm/utils/TableGen/Common/SubtargetFeatureInfo.h
35290 views
//===- SubtargetFeatureInfo.h - Helpers for subtarget features --*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H9#define LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H1011#include "llvm/ADT/StringRef.h"12#include "llvm/TableGen/Record.h"13#include <map>14#include <string>15#include <utility>16#include <vector>1718namespace llvm {19struct SubtargetFeatureInfo;20using SubtargetFeatureInfoMap =21std::map<Record *, SubtargetFeatureInfo, LessRecordByID>;2223/// Helper class for storing information on a subtarget feature which24/// participates in instruction matching.25struct SubtargetFeatureInfo {26/// The predicate record for this feature.27Record *TheDef;2829/// An unique index assigned to represent this feature.30uint64_t Index;3132SubtargetFeatureInfo(Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {}3334/// The name of the enumerated constant identifying this feature.35std::string getEnumName() const {36return "Feature_" + TheDef->getName().str();37}3839/// The name of the enumerated constant identifying the bitnumber for40/// this feature.41std::string getEnumBitName() const {42return "Feature_" + TheDef->getName().str() + "Bit";43}4445bool mustRecomputePerFunction() const {46return TheDef->getValueAsBit("RecomputePerFunction");47}4849void dump() const;50static std::vector<std::pair<Record *, SubtargetFeatureInfo>>51getAll(const RecordKeeper &Records);5253/// Emit the subtarget feature flag definitions.54///55/// This version emits the bit index for the feature and can therefore support56/// more than 64 feature bits.57static void emitSubtargetFeatureBitEnumeration(58const SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS,59const std::map<std::string, unsigned> *HwModes = nullptr);6061static void emitNameTable(SubtargetFeatureInfoMap &SubtargetFeatures,62raw_ostream &OS);6364/// Emit the function to compute the list of available features given a65/// 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 generated73/// functions (including the target prefix.)74/// \param FuncName The name of the function to emit.75/// \param SubtargetFeatures A map of TableGen records to the76/// SubtargetFeatureInfo equivalent.77/// \param ExtraParams Additional arguments to the generated function.78/// \param HwModes Map of HwMode conditions to check.79static void emitComputeAvailableFeatures(80StringRef TargetName, StringRef ClassName, StringRef FuncName,81const SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS,82StringRef ExtraParams = "",83const std::map<std::string, unsigned> *HwModes = nullptr);8485/// Emit the function to compute the list of available features given a86/// subtarget.87///88/// This version is used for subtarget features defined using89/// AssemblerPredicate<> and supports up to 64 feature bits.90///91/// \param TargetName The name of the target as used in class prefixes (e.g.92/// <TargetName>Subtarget)93/// \param ClassName The name of the class (without the <Target> prefix)94/// that will contain the generated functions.95/// \param FuncName The name of the function to emit.96/// \param SubtargetFeatures A map of TableGen records to the97/// SubtargetFeatureInfo equivalent.98static void emitComputeAssemblerAvailableFeatures(99StringRef TargetName, StringRef ClassName, StringRef FuncName,100SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS);101};102} // end namespace llvm103104#endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H105106107