LLVM  8.0.1
SubtargetFeature.h
Go to the documentation of this file.
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 /// \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 
18 #ifndef LLVM_MC_SUBTARGETFEATURE_H
19 #define LLVM_MC_SUBTARGETFEATURE_H
20 
21 #include "llvm/ADT/StringRef.h"
22 #include <bitset>
23 #include <initializer_list>
24 #include <string>
25 #include <vector>
26 
27 namespace llvm {
28 
29 template <typename T> class ArrayRef;
30 class raw_ostream;
31 class Triple;
32 
33 const unsigned MAX_SUBTARGET_FEATURES = 192;
34 /// Container class for subtarget features.
35 /// This is convenient because std::bitset does not have a constructor
36 /// with an initializer list of set bits.
37 class FeatureBitset : public std::bitset<MAX_SUBTARGET_FEATURES> {
38 public:
39  // Cannot inherit constructors because it's not supported by VC++..
40  FeatureBitset() = default;
41 
42  FeatureBitset(const bitset<MAX_SUBTARGET_FEATURES>& B) : bitset(B) {}
43 
44  FeatureBitset(std::initializer_list<unsigned> Init) {
45  for (auto I : Init)
46  set(I);
47  }
48 };
49 
50 //===----------------------------------------------------------------------===//
51 
52 /// Used to provide key value pairs for feature and CPU bit flags.
54  const char *Key; ///< K-V key string
55  const char *Desc; ///< Help descriptor
56  FeatureBitset Value; ///< K-V integer value
57  FeatureBitset Implies; ///< K-V bit mask
58 
59  /// Compare routine for std::lower_bound
60  bool operator<(StringRef S) const {
61  return StringRef(Key) < S;
62  }
63 
64  /// Compare routine for std::is_sorted.
65  bool operator<(const SubtargetFeatureKV &Other) const {
66  return StringRef(Key) < StringRef(Other.Key);
67  }
68 };
69 
70 //===----------------------------------------------------------------------===//
71 
72 /// Used to provide key value pairs for CPU and arbitrary pointers.
74  const char *Key; ///< K-V key string
75  const void *Value; ///< K-V pointer value
76 
77  /// Compare routine for std::lower_bound
78  bool operator<(StringRef S) const {
79  return StringRef(Key) < S;
80  }
81 };
82 
83 //===----------------------------------------------------------------------===//
84 
85 /// Manages the enabling and disabling of subtarget specific features.
86 ///
87 /// Features are encoded as a string of the form
88 /// "+attr1,+attr2,-attr3,...,+attrN"
89 /// A comma separates each feature from the next (all lowercase.)
90 /// Each of the remaining features is prefixed with + or - indicating whether
91 /// that feature should be enabled or disabled contrary to the cpu
92 /// specification.
94  std::vector<std::string> Features; ///< Subtarget features as a vector
95 
96 public:
97  explicit SubtargetFeatures(StringRef Initial = "");
98 
99  /// Returns features as a string.
100  std::string getString() const;
101 
102  /// Adds Features.
103  void AddFeature(StringRef String, bool Enable = true);
104 
105  /// Toggles a feature and update the feature bits.
106  static void ToggleFeature(FeatureBitset &Bits, StringRef String,
107  ArrayRef<SubtargetFeatureKV> FeatureTable);
108 
109  /// Applies the feature flag and update the feature bits.
110  static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
111  ArrayRef<SubtargetFeatureKV> FeatureTable);
112 
113  /// Returns feature bits of a CPU.
114  FeatureBitset getFeatureBits(StringRef CPU,
116  ArrayRef<SubtargetFeatureKV> FeatureTable);
117 
118  /// Returns the vector of individual subtarget features.
119  const std::vector<std::string> &getFeatures() const { return Features; }
120 
121  /// Prints feature string.
122  void print(raw_ostream &OS) const;
123 
124  // Dumps feature info.
125  void dump() const;
126 
127  /// Adds the default features for the specified target triple.
128  void getDefaultSubtargetFeatures(const Triple& Triple);
129 };
130 
131 } // end namespace llvm
132 
133 #endif // LLVM_MC_SUBTARGETFEATURE_H
const unsigned MAX_SUBTARGET_FEATURES
This class represents lattice values for constants.
Definition: AllocatorList.h:24
const FeatureBitset Features
const char * Key
K-V key string.
Used to provide key value pairs for CPU and arbitrary pointers.
FeatureBitset Value
K-V integer value.
Used to provide key value pairs for feature and CPU bit flags.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
bool operator<(StringRef S) const
Compare routine for std::lower_bound.
bool operator<(const SubtargetFeatureKV &Other) const
Compare routine for std::is_sorted.
const std::vector< std::string > & getFeatures() const
Returns the vector of individual subtarget features.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Container class for subtarget features.
const char * Key
K-V key string.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
const void * Value
K-V pointer value.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool operator<(StringRef S) const
Compare routine for std::lower_bound.
const char * Desc
Help descriptor.
FeatureBitset(const bitset< MAX_SUBTARGET_FEATURES > &B)
Manages the enabling and disabling of subtarget specific features.
FeatureBitset()=default
#define I(x, y, z)
Definition: MD5.cpp:58
FeatureBitset(std::initializer_list< unsigned > Init)
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
FeatureBitset Implies
K-V bit mask.