LLVM  4.0.0
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 // 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 
18 #ifndef LLVM_MC_SUBTARGETFEATURE_H
19 #define LLVM_MC_SUBTARGETFEATURE_H
20 
21 #include "llvm/ADT/Triple.h"
22 #include "llvm/Support/DataTypes.h"
23 #include <bitset>
24 #include <vector>
25 
26 namespace llvm {
27 template <typename T> class ArrayRef;
28  class raw_ostream;
29  class StringRef;
30 
31 // A container class for subtarget features.
32 // This is convenient because std::bitset does not have a constructor
33 // with an initializer list of set bits.
34 const unsigned MAX_SUBTARGET_FEATURES = 128;
35 class FeatureBitset : public std::bitset<MAX_SUBTARGET_FEATURES> {
36 public:
37  // Cannot inherit constructors because it's not supported by VC++..
38  FeatureBitset() : bitset() {}
39 
40  FeatureBitset(const bitset<MAX_SUBTARGET_FEATURES>& B) : bitset(B) {}
41 
42  FeatureBitset(std::initializer_list<unsigned> Init) : bitset() {
43  for (auto I : Init)
44  set(I);
45  }
46 };
47 
48 //===----------------------------------------------------------------------===//
49 ///
50 /// SubtargetFeatureKV - Used to provide key value pairs for feature and
51 /// CPU bit flags.
52 //
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 /// SubtargetInfoKV - Used to provide key value pairs for CPU and arbitrary
73 /// pointers.
74 //
76  const char *Key; // K-V key string
77  const void *Value; // K-V pointer value
78 
79  // Compare routine for std::lower_bound
80  bool operator<(StringRef S) const {
81  return StringRef(Key) < S;
82  }
83 };
84 
85 //===----------------------------------------------------------------------===//
86 ///
87 /// SubtargetFeatures - Manages the enabling and disabling of subtarget
88 /// specific features. Features are encoded as a string of the form
89 /// "+attr1,+attr2,-attr3,...,+attrN"
90 /// A comma separates each feature from the next (all lowercase.)
91 /// Each of the remaining features is prefixed with + or - indicating whether
92 /// that feature should be enabled or disabled contrary to the cpu
93 /// specification.
94 ///
95 
97  std::vector<std::string> Features; // Subtarget features as a vector
98 public:
99  explicit SubtargetFeatures(StringRef Initial = "");
100 
101  /// Features string accessors.
102  std::string getString() const;
103 
104  /// Adding Features.
105  void AddFeature(StringRef String, bool Enable = true);
106 
107  /// ToggleFeature - Toggle a feature and update the feature bits.
108  static void ToggleFeature(FeatureBitset &Bits, StringRef String,
109  ArrayRef<SubtargetFeatureKV> FeatureTable);
110 
111  /// Apply the feature flag and update the feature bits.
112  static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
113  ArrayRef<SubtargetFeatureKV> FeatureTable);
114 
115  /// Get feature bits of a CPU.
118  ArrayRef<SubtargetFeatureKV> FeatureTable);
119 
120  /// Print feature string.
121  void print(raw_ostream &OS) const;
122 
123  // Dump feature info.
124  void dump() const;
125 
126  /// Adds the default features for the specified target triple.
128 };
129 
130 } // End namespace llvm
131 
132 #endif
const unsigned MAX_SUBTARGET_FEATURES
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
bool operator<(StringRef S) const
SubtargetInfoKV - Used to provide key value pairs for CPU and arbitrary pointers. ...
void AddFeature(StringRef String, bool Enable=true)
Adding Features.
SubtargetFeatureKV - 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
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
void dump() const
dump - Dump feature info.
std::string getString() const
Features string accessors.
static void ToggleFeature(FeatureBitset &Bits, StringRef String, ArrayRef< SubtargetFeatureKV > FeatureTable)
ToggleFeature - Toggle a feature and update the feature bits.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool operator<(StringRef S) const
FeatureBitset(const bitset< MAX_SUBTARGET_FEATURES > &B)
SubtargetFeatures(StringRef Initial="")
SubtargetFeatures - Manages the enabling and disabling of subtarget specific features.
#define I(x, y, z)
Definition: MD5.cpp:54
FeatureBitset(std::initializer_list< unsigned > Init)
static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature, ArrayRef< SubtargetFeatureKV > FeatureTable)
Apply the feature flag and update the feature bits.
void print(raw_ostream &OS) const
Print feature string.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
FeatureBitset getFeatureBits(StringRef CPU, ArrayRef< SubtargetFeatureKV > CPUTable, ArrayRef< SubtargetFeatureKV > FeatureTable)
Get feature bits of a CPU.
bool operator<(const SubtargetFeatureKV &Other) const