CodeGenHwModes.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #ifndef LLVM_UTILS_TABLEGEN_CODEGENHWMODES_H
  11. #define LLVM_UTILS_TABLEGEN_CODEGENHWMODES_H
  12. #include "llvm/ADT/StringMap.h"
  13. #include <cassert>
  14. #include <map>
  15. #include <string>
  16. #include <vector>
  17. // HwModeId -> list of predicates (definition)
  18. namespace llvm {
  19. class Record;
  20. class RecordKeeper;
  21. struct CodeGenHwModes;
  22. struct HwMode {
  23. HwMode(Record *R);
  24. StringRef Name;
  25. std::string Features;
  26. void dump() const;
  27. };
  28. struct HwModeSelect {
  29. HwModeSelect(Record *R, CodeGenHwModes &CGH);
  30. typedef std::pair<unsigned, Record*> PairType;
  31. std::vector<PairType> Items;
  32. void dump() const;
  33. };
  34. struct CodeGenHwModes {
  35. enum : unsigned { DefaultMode = 0 };
  36. static StringRef DefaultModeName;
  37. CodeGenHwModes(RecordKeeper &R);
  38. unsigned getHwModeId(StringRef Name) const;
  39. const HwMode &getMode(unsigned Id) const {
  40. assert(Id != 0 && "Mode id of 0 is reserved for the default mode");
  41. return Modes[Id-1];
  42. }
  43. const HwModeSelect &getHwModeSelect(Record *R) const;
  44. unsigned getNumModeIds() const { return Modes.size()+1; }
  45. void dump() const;
  46. private:
  47. RecordKeeper &Records;
  48. StringMap<unsigned> ModeIds; // HwMode (string) -> HwModeId
  49. std::vector<HwMode> Modes;
  50. std::map<Record*,HwModeSelect> ModeSelects;
  51. };
  52. }
  53. #endif // LLVM_UTILS_TABLEGEN_CODEGENHWMODES_H