Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 1 | //===--- CodeGenHwModes.h ---------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Krzysztof Parzyszek | 779d98e | 2017-09-14 16:56:21 +0000 | [diff] [blame] | 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/StringMap.h" |
| 15 | #include <map> |
| 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
| 19 | // HwModeId -> list of predicates (definition) |
| 20 | |
| 21 | namespace llvm { |
| 22 | class Record; |
| 23 | class RecordKeeper; |
| 24 | |
| 25 | struct CodeGenHwModes; |
| 26 | |
| 27 | struct HwMode { |
| 28 | HwMode(Record *R); |
| 29 | StringRef Name; |
| 30 | std::string Features; |
| 31 | void dump() const; |
| 32 | }; |
| 33 | |
| 34 | struct HwModeSelect { |
| 35 | HwModeSelect(Record *R, CodeGenHwModes &CGH); |
| 36 | typedef std::pair<unsigned, Record*> PairType; |
| 37 | std::vector<PairType> Items; |
| 38 | void dump() const; |
| 39 | }; |
| 40 | |
| 41 | struct CodeGenHwModes { |
| 42 | enum : unsigned { DefaultMode = 0 }; |
| 43 | static StringRef DefaultModeName; |
| 44 | |
| 45 | CodeGenHwModes(RecordKeeper &R); |
| 46 | unsigned getHwModeId(StringRef Name) const; |
| 47 | const HwMode &getMode(unsigned Id) const { |
| 48 | assert(Id != 0 && "Mode id of 0 is reserved for the default mode"); |
| 49 | return Modes[Id-1]; |
| 50 | } |
| 51 | const HwModeSelect &getHwModeSelect(Record *R) const; |
| 52 | unsigned getNumModeIds() const { return Modes.size()+1; } |
| 53 | void dump() const; |
| 54 | |
| 55 | private: |
| 56 | RecordKeeper &Records; |
| 57 | StringMap<unsigned> ModeIds; // HwMode (string) -> HwModeId |
| 58 | std::vector<HwMode> Modes; |
| 59 | std::map<Record*,HwModeSelect> ModeSelects; |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | #endif // LLVM_UTILS_TABLEGEN_CODEGENHWMODES_H |