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