SubtargetFeatureInfo.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //===- SubtargetFeatureInfo.h - Helpers for subtarget features --*- 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. #ifndef LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H
  9. #define LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H
  10. #include "llvm/TableGen/Record.h"
  11. #include <map>
  12. #include <string>
  13. #include <vector>
  14. namespace llvm {
  15. struct SubtargetFeatureInfo;
  16. using SubtargetFeatureInfoMap = std::map<Record *, SubtargetFeatureInfo, LessRecordByID>;
  17. /// Helper class for storing information on a subtarget feature which
  18. /// participates in instruction matching.
  19. struct SubtargetFeatureInfo {
  20. /// The predicate record for this feature.
  21. Record *TheDef;
  22. /// An unique index assigned to represent this feature.
  23. uint64_t Index;
  24. SubtargetFeatureInfo(Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {}
  25. /// The name of the enumerated constant identifying this feature.
  26. std::string getEnumName() const {
  27. return "Feature_" + TheDef->getName().str();
  28. }
  29. /// The name of the enumerated constant identifying the bitnumber for
  30. /// this feature.
  31. std::string getEnumBitName() const {
  32. return "Feature_" + TheDef->getName().str() + "Bit";
  33. }
  34. bool mustRecomputePerFunction() const {
  35. return TheDef->getValueAsBit("RecomputePerFunction");
  36. }
  37. void dump() const;
  38. static std::vector<std::pair<Record *, SubtargetFeatureInfo>>
  39. getAll(const RecordKeeper &Records);
  40. /// Emit the subtarget feature flag definitions.
  41. ///
  42. /// This version emits the bit index for the feature and can therefore support
  43. /// more than 64 feature bits.
  44. static void
  45. emitSubtargetFeatureBitEnumeration(SubtargetFeatureInfoMap &SubtargetFeatures,
  46. raw_ostream &OS);
  47. static void emitNameTable(SubtargetFeatureInfoMap &SubtargetFeatures,
  48. raw_ostream &OS);
  49. /// Emit the function to compute the list of available features given a
  50. /// subtarget.
  51. ///
  52. /// This version is used for subtarget features defined using Predicate<>
  53. /// and supports more than 64 feature bits.
  54. ///
  55. /// \param TargetName The name of the target as used in class prefixes (e.g.
  56. /// <TargetName>Subtarget)
  57. /// \param ClassName The name of the class (without the <Target> prefix)
  58. /// that will contain the generated functions.
  59. /// \param FuncName The name of the function to emit.
  60. /// \param SubtargetFeatures A map of TableGen records to the
  61. /// SubtargetFeatureInfo equivalent.
  62. /// \param ExtraParams Additional arguments to the generated function.
  63. static void
  64. emitComputeAvailableFeatures(StringRef TargetName, StringRef ClassName,
  65. StringRef FuncName,
  66. SubtargetFeatureInfoMap &SubtargetFeatures,
  67. raw_ostream &OS, StringRef ExtraParams = "");
  68. /// Emit the function to compute the list of available features given a
  69. /// subtarget.
  70. ///
  71. /// This version is used for subtarget features defined using
  72. /// AssemblerPredicate<> and supports up to 64 feature bits.
  73. ///
  74. /// \param TargetName The name of the target as used in class prefixes (e.g.
  75. /// <TargetName>Subtarget)
  76. /// \param ClassName The name of the class (without the <Target> prefix)
  77. /// that will contain the generated functions.
  78. /// \param FuncName The name of the function to emit.
  79. /// \param SubtargetFeatures A map of TableGen records to the
  80. /// SubtargetFeatureInfo equivalent.
  81. static void emitComputeAssemblerAvailableFeatures(
  82. StringRef TargetName, StringRef ClassName, StringRef FuncName,
  83. SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS);
  84. };
  85. } // end namespace llvm
  86. #endif // LLVM_UTIL_TABLEGEN_SUBTARGETFEATUREINFO_H