1//===--- CodeGenHwModes.h ---------------------------------------*- 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// Classes to parse and store HW mode information for instruction selection.
9//===----------------------------------------------------------------------===//
10
11#ifndef LLVM_UTILS_TABLEGEN_COMMON_CODEGENHWMODES_H
12#define LLVM_UTILS_TABLEGEN_COMMON_CODEGENHWMODES_H
13
14#include "llvm/ADT/DenseMap.h"
15#include "llvm/ADT/StringRef.h"
16#include <cassert>
17#include <map>
18#include <utility>
19#include <vector>
20
21// HwModeId -> list of predicates (definition)
22
23namespace llvm {
24class Record;
25class RecordKeeper;
26
27struct CodeGenHwModes;
28
29struct HwMode {
30 HwMode(const Record *R);
31 StringRef Name;
32 std::vector<const Record *> Predicates;
33 void dump() const;
34};
35
36struct HwModeSelect {
37 HwModeSelect(const Record *R, CodeGenHwModes &CGH);
38 using PairType = std::pair<unsigned, const Record *>;
39 std::vector<PairType> Items;
40 void dump() const;
41};
42
43struct CodeGenHwModes {
44 enum : unsigned { DefaultMode = 0 };
45 static StringRef DefaultModeName;
46
47 CodeGenHwModes(const RecordKeeper &R);
48 unsigned getHwModeId(const Record *R) const;
49 const HwMode &getMode(unsigned Id) const {
50 assert(Id != 0 && "Mode id of 0 is reserved for the default mode");
51 return Modes[Id - 1];
52 }
53 StringRef getModeName(unsigned Id, bool IncludeDefault = false) const {
54 if (IncludeDefault && Id == CodeGenHwModes::DefaultMode)
55 return DefaultModeName;
56 return getMode(Id).Name;
57 }
58 const HwModeSelect &getHwModeSelect(const Record *R) const;
59 const std::map<const Record *, HwModeSelect> &getHwModeSelects() const {
60 return ModeSelects;
61 }
62 unsigned getNumModeIds() const { return Modes.size() + 1; }
63 void dump() const;
64
65private:
66 const RecordKeeper &Records;
67 DenseMap<const Record *, unsigned> ModeIds; // HwMode Record -> HwModeId
68 std::vector<HwMode> Modes;
69 std::map<const Record *, HwModeSelect> ModeSelects;
70};
71} // namespace llvm
72
73#endif // LLVM_UTILS_TABLEGEN_COMMON_CODEGENHWMODES_H
74