1 //===-- llvm/MC/SubtargetFeature.h - CPU characteristics --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_MC_SUBTARGETFEATURE_H
19 #define LLVM_MC_SUBTARGETFEATURE_H
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/Triple.h"
23 #include "llvm/Support/DataTypes.h"
30 // A container class for subtarget features.
31 // This is convenient because std::bitset does not have a constructor
32 // with an initializer list of set bits.
33 const unsigned MAX_SUBTARGET_FEATURES = 128;
34 class FeatureBitset : public std::bitset<MAX_SUBTARGET_FEATURES> {
36 // Cannot inherit constructors because it's not supported by VC++..
37 FeatureBitset() : bitset() {}
39 FeatureBitset(const bitset<MAX_SUBTARGET_FEATURES>& B) : bitset(B) {}
41 FeatureBitset(std::initializer_list<unsigned> Init) : bitset() {
47 //===----------------------------------------------------------------------===//
49 /// SubtargetFeatureKV - Used to provide key value pairs for feature and
52 struct SubtargetFeatureKV {
53 const char *Key; // K-V key string
54 const char *Desc; // Help descriptor
55 FeatureBitset Value; // K-V integer value
56 FeatureBitset Implies; // K-V bit mask
58 // Compare routine for std::lower_bound
59 bool operator<(StringRef S) const {
60 return StringRef(Key) < S;
63 // Compare routine for std::is_sorted.
64 bool operator<(const SubtargetFeatureKV &Other) const {
65 return StringRef(Key) < StringRef(Other.Key);
69 //===----------------------------------------------------------------------===//
71 /// SubtargetInfoKV - Used to provide key value pairs for CPU and arbitrary
74 struct SubtargetInfoKV {
75 const char *Key; // K-V key string
76 const void *Value; // K-V pointer value
78 // Compare routine for std::lower_bound
79 bool operator<(StringRef S) const {
80 return StringRef(Key) < S;
84 //===----------------------------------------------------------------------===//
86 /// SubtargetFeatures - Manages the enabling and disabling of subtarget
87 /// specific features. 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
95 class SubtargetFeatures {
96 std::vector<std::string> Features; // Subtarget features as a vector
98 explicit SubtargetFeatures(StringRef Initial = "");
100 /// Features string accessors.
101 std::string getString() const;
104 void AddFeature(StringRef String, bool Enable = true);
106 /// ToggleFeature - Toggle a feature and update the feature bits.
107 static void ToggleFeature(FeatureBitset &Bits, StringRef String,
108 ArrayRef<SubtargetFeatureKV> FeatureTable);
110 /// Apply the feature flag and update the feature bits.
111 static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
112 ArrayRef<SubtargetFeatureKV> FeatureTable);
114 /// Get feature bits of a CPU.
115 FeatureBitset getFeatureBits(StringRef CPU,
116 ArrayRef<SubtargetFeatureKV> CPUTable,
117 ArrayRef<SubtargetFeatureKV> FeatureTable);
119 /// Print feature string.
120 void print(raw_ostream &OS) const;
122 // Dump feature info.
125 /// Adds the default features for the specified target triple.
126 void getDefaultSubtargetFeatures(const Triple& Triple);
129 } // End namespace llvm