Path: blob/main/contrib/llvm-project/llvm/utils/TableGen/Common/CodeGenHwModes.h
35290 views
//===--- CodeGenHwModes.h ---------------------------------------*- 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//===----------------------------------------------------------------------===//7// Classes to parse and store HW mode information for instruction selection.8//===----------------------------------------------------------------------===//910#ifndef LLVM_UTILS_TABLEGEN_CODEGENHWMODES_H11#define LLVM_UTILS_TABLEGEN_CODEGENHWMODES_H1213#include "llvm/ADT/DenseMap.h"14#include "llvm/ADT/StringRef.h"15#include <cassert>16#include <map>17#include <string>18#include <utility>19#include <vector>2021// HwModeId -> list of predicates (definition)2223namespace llvm {24class Record;25class RecordKeeper;2627struct CodeGenHwModes;2829struct HwMode {30HwMode(Record *R);31StringRef Name;32std::string Features;33std::string Predicates;34void dump() const;35};3637struct HwModeSelect {38HwModeSelect(Record *R, CodeGenHwModes &CGH);39typedef std::pair<unsigned, Record *> PairType;40std::vector<PairType> Items;41void dump() const;42};4344struct CodeGenHwModes {45enum : unsigned { DefaultMode = 0 };46static StringRef DefaultModeName;4748CodeGenHwModes(RecordKeeper &R);49unsigned getHwModeId(Record *R) const;50const HwMode &getMode(unsigned Id) const {51assert(Id != 0 && "Mode id of 0 is reserved for the default mode");52return Modes[Id - 1];53}54StringRef getModeName(unsigned Id, bool IncludeDefault = false) const {55if (IncludeDefault && Id == CodeGenHwModes::DefaultMode)56return DefaultModeName;57return getMode(Id).Name;58}59const HwModeSelect &getHwModeSelect(Record *R) const;60const std::map<Record *, HwModeSelect> &getHwModeSelects() const {61return ModeSelects;62}63unsigned getNumModeIds() const { return Modes.size() + 1; }64void dump() const;6566private:67RecordKeeper &Records;68DenseMap<Record *, unsigned> ModeIds; // HwMode Record -> HwModeId69std::vector<HwMode> Modes;70std::map<Record *, HwModeSelect> ModeSelects;71};72} // namespace llvm7374#endif // LLVM_UTILS_TABLEGEN_CODEGENHWMODES_H757677