LLVM  9.0.0svn
SubtargetFeature.h
Go to the documentation of this file.
1 //===- llvm/MC/SubtargetFeature.h - CPU characteristics ---------*- 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 //
9 /// \file Defines and manages user or tool specified CPU characteristics.
10 /// The intent is to be able to package specific features that should or should
11 /// not be used on a specific target processor. A tool, such as llc, could, as
12 /// as example, gather chip info from the command line, a long with features
13 /// that should be used on that chip.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_MC_SUBTARGETFEATURE_H
18 #define LLVM_MC_SUBTARGETFEATURE_H
19 
20 #include "llvm/ADT/StringRef.h"
21 #include <bitset>
22 #include <initializer_list>
23 #include <string>
24 #include <vector>
25 
26 namespace llvm {
27 
28 template <typename T> class ArrayRef;
29 class raw_ostream;
30 class Triple;
31 
32 const unsigned MAX_SUBTARGET_FEATURES = 192;
33 /// Container class for subtarget features.
34 /// This is convenient because std::bitset does not have a constructor
35 /// with an initializer list of set bits.
36 class FeatureBitset : public std::bitset<MAX_SUBTARGET_FEATURES> {
37 public:
38  // Cannot inherit constructors because it's not supported by VC++..
39  FeatureBitset() = default;
40 
41  FeatureBitset(const bitset<MAX_SUBTARGET_FEATURES>& B) : bitset(B) {}
42 
43  FeatureBitset(std::initializer_list<unsigned> Init) {
44  for (auto I : Init)
45  set(I);
46  }
47 };
48 
49 //===----------------------------------------------------------------------===//
50 
51 /// Used to provide key value pairs for feature and CPU bit flags.
53  const char *Key; ///< K-V key string
54  const char *Desc; ///< Help descriptor
55  unsigned Value; ///< K-V integer value
56  FeatureBitset Implies; ///< K-V bit mask
57 
58  /// Compare routine for std::lower_bound
59  bool operator<(StringRef S) const {
60  return StringRef(Key) < S;
61  }
62 
63  /// Compare routine for std::is_sorted.
64  bool operator<(const SubtargetFeatureKV &Other) const {
65  return StringRef(Key) < StringRef(Other.Key);
66  }
67 };
68 
69 //===----------------------------------------------------------------------===//
70 
71 /// Used to provide key value pairs for CPU and arbitrary pointers.
73  const char *Key; ///< K-V key string
74  const void *Value; ///< K-V pointer value
75 
76  /// Compare routine for std::lower_bound
77  bool operator<(StringRef S) const {
78  return StringRef(Key) < S;
79  }
80 };
81 
82 //===----------------------------------------------------------------------===//
83 
84 /// Manages the enabling and disabling of subtarget specific features.
85 ///
86 /// Features are encoded as a string of the form
87 /// "+attr1,+attr2,-attr3,...,+attrN"
88 /// A comma separates each feature from the next (all lowercase.)
89 /// Each of the remaining features is prefixed with + or - indicating whether
90 /// that feature should be enabled or disabled contrary to the cpu
91 /// specification.
93  std::vector<std::string> Features; ///< Subtarget features as a vector
94 
95 public:
96  explicit SubtargetFeatures(StringRef Initial = "");
97 
98  /// Returns features as a string.
99  std::string getString() const;
100 
101  /// Adds Features.
102  void AddFeature(StringRef String, bool Enable = true);
103 
104  /// Toggles a feature and update the feature bits.
105  static void ToggleFeature(FeatureBitset &Bits, StringRef String,
106  ArrayRef<SubtargetFeatureKV> FeatureTable);
107 
108  /// Applies the feature flag and update the feature bits.
109  static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
110  ArrayRef<SubtargetFeatureKV> FeatureTable);
111 
112  /// Returns feature bits of a CPU.
113  FeatureBitset getFeatureBits(StringRef CPU,
115  ArrayRef<SubtargetFeatureKV> FeatureTable);
116 
117  /// Returns the vector of individual subtarget features.
118  const std::vector<std::string> &getFeatures() const { return Features; }
119 
120  /// Prints feature string.
121  void print(raw_ostream &OS) const;
122 
123  // Dumps feature info.
124  void dump() const;
125 
126  /// Adds the default features for the specified target triple.
127  void getDefaultSubtargetFeatures(const Triple& Triple);
128 };
129 
130 } // end namespace llvm
131 
132 #endif // LLVM_MC_SUBTARGETFEATURE_H
const unsigned MAX_SUBTARGET_FEATURES
This class represents lattice values for constants.
Definition: AllocatorList.h:23
const FeatureBitset Features
const char * Key
K-V key string.
Used to provide key value pairs for CPU and arbitrary pointers.
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:32
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.
unsigned Value
K-V integer value.
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:43
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:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
FeatureBitset Implies
K-V bit mask.