SubtargetFeature.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //===-- llvm/MC/SubtargetFeature.h - CPU characteristics --------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines and manages user or tool specified CPU characteristics.
  11. // The intent is to be able to package specific features that should or should
  12. // not be used on a specific target processor. A tool, such as llc, could, as
  13. // as example, gather chip info from the command line, a long with features
  14. // that should be used on that chip.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_MC_SUBTARGETFEATURE_H
  18. #define LLVM_MC_SUBTARGETFEATURE_H
  19. #include "llvm/ADT/ArrayRef.h"
  20. #include "llvm/ADT/Triple.h"
  21. #include "llvm/Support/DataTypes.h"
  22. #include <bitset>
  23. namespace llvm {
  24. class raw_ostream;
  25. class StringRef;
  26. // A container class for subtarget features.
  27. // This is convenient because std::bitset does not have a constructor
  28. // with an initializer list of set bits.
  29. const unsigned MAX_SUBTARGET_FEATURES = 64;
  30. class FeatureBitset : public std::bitset<MAX_SUBTARGET_FEATURES> {
  31. public:
  32. // Cannot inherit constructors because it's not supported by VC++..
  33. FeatureBitset() : bitset() {}
  34. FeatureBitset(const bitset<MAX_SUBTARGET_FEATURES>& B) : bitset(B) {}
  35. FeatureBitset(std::initializer_list<unsigned> Init) : bitset() {
  36. for (auto I = Init.begin() , E = Init.end(); I != E; ++I)
  37. set(*I);
  38. }
  39. };
  40. //===----------------------------------------------------------------------===//
  41. ///
  42. /// SubtargetFeatureKV - Used to provide key value pairs for feature and
  43. /// CPU bit flags.
  44. //
  45. struct SubtargetFeatureKV {
  46. const char *Key; // K-V key string
  47. const char *Desc; // Help descriptor
  48. FeatureBitset Value; // K-V integer value
  49. FeatureBitset Implies; // K-V bit mask
  50. // Compare routine for std::lower_bound
  51. bool operator<(StringRef S) const {
  52. return StringRef(Key) < S;
  53. }
  54. };
  55. //===----------------------------------------------------------------------===//
  56. ///
  57. /// SubtargetInfoKV - Used to provide key value pairs for CPU and arbitrary
  58. /// pointers.
  59. //
  60. struct SubtargetInfoKV {
  61. const char *Key; // K-V key string
  62. const void *Value; // K-V pointer value
  63. // Compare routine for std::lower_bound
  64. bool operator<(StringRef S) const {
  65. return StringRef(Key) < S;
  66. }
  67. };
  68. // //
  69. ///////////////////////////////////////////////////////////////////////////////
  70. ///
  71. /// SubtargetFeatures - Manages the enabling and disabling of subtarget
  72. /// specific features. Features are encoded as a string of the form
  73. /// "+attr1,+attr2,-attr3,...,+attrN"
  74. /// A comma separates each feature from the next (all lowercase.)
  75. /// Each of the remaining features is prefixed with + or - indicating whether
  76. /// that feature should be enabled or disabled contrary to the cpu
  77. /// specification.
  78. ///
  79. class SubtargetFeatures {
  80. std::vector<std::string> Features; // Subtarget features as a vector
  81. public:
  82. explicit SubtargetFeatures(StringRef Initial = "");
  83. /// Features string accessors.
  84. std::string getString() const;
  85. /// Adding Features.
  86. void AddFeature(StringRef String, bool Enable = true);
  87. /// ToggleFeature - Toggle a feature and returns the newly updated feature
  88. /// bits.
  89. FeatureBitset ToggleFeature(FeatureBitset Bits, StringRef String,
  90. ArrayRef<SubtargetFeatureKV> FeatureTable);
  91. /// Apply the feature flag and return the newly updated feature bits.
  92. FeatureBitset ApplyFeatureFlag(FeatureBitset Bits, StringRef Feature,
  93. ArrayRef<SubtargetFeatureKV> FeatureTable);
  94. /// Get feature bits of a CPU.
  95. FeatureBitset getFeatureBits(StringRef CPU,
  96. ArrayRef<SubtargetFeatureKV> CPUTable,
  97. ArrayRef<SubtargetFeatureKV> FeatureTable);
  98. /// Print feature string.
  99. void print(raw_ostream &OS) const;
  100. // Dump feature info.
  101. void dump() const;
  102. /// Adds the default features for the specified target triple.
  103. void getDefaultSubtargetFeatures(const Triple& Triple);
  104. };
  105. } // End namespace llvm
  106. #endif