LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <vector>
24 
25 namespace llvm {
26  class raw_ostream;
27  class StringRef;
28 
29 //===----------------------------------------------------------------------===//
30 ///
31 /// SubtargetFeatureKV - Used to provide key value pairs for feature and
32 /// CPU bit flags.
33 //
35  const char *Key; // K-V key string
36  const char *Desc; // Help descriptor
37  uint64_t Value; // K-V integer value
38  uint64_t Implies; // K-V bit mask
39 
40  // Compare routine for std::lower_bound
41  bool operator<(StringRef S) const {
42  return StringRef(Key) < S;
43  }
44 };
45 
46 //===----------------------------------------------------------------------===//
47 ///
48 /// SubtargetInfoKV - Used to provide key value pairs for CPU and arbitrary
49 /// pointers.
50 //
52  const char *Key; // K-V key string
53  const void *Value; // K-V pointer value
54 
55  // Compare routine for std::lower_bound
56  bool operator<(StringRef S) const {
57  return StringRef(Key) < S;
58  }
59 };
60 
61 //===----------------------------------------------------------------------===//
62 ///
63 /// SubtargetFeatures - Manages the enabling and disabling of subtarget
64 /// specific features. Features are encoded as a string of the form
65 /// "+attr1,+attr2,-attr3,...,+attrN"
66 /// A comma separates each feature from the next (all lowercase.)
67 /// Each of the remaining features is prefixed with + or - indicating whether
68 /// that feature should be enabled or disabled contrary to the cpu
69 /// specification.
70 ///
71 
73  std::vector<std::string> Features; // Subtarget features as a vector
74 public:
75  explicit SubtargetFeatures(const StringRef Initial = "");
76 
77  /// Features string accessors.
78  std::string getString() const;
79 
80  /// Adding Features.
81  void AddFeature(const StringRef String, bool IsEnabled = true);
82 
83  /// ToggleFeature - Toggle a feature and returns the newly updated feature
84  /// bits.
85  uint64_t ToggleFeature(uint64_t Bits, const StringRef String,
86  const SubtargetFeatureKV *FeatureTable,
87  size_t FeatureTableSize);
88 
89  /// Get feature bits of a CPU.
90  uint64_t getFeatureBits(const StringRef CPU,
91  const SubtargetFeatureKV *CPUTable,
92  size_t CPUTableSize,
93  const SubtargetFeatureKV *FeatureTable,
94  size_t FeatureTableSize);
95 
96  /// Print feature string.
97  void print(raw_ostream &OS) const;
98 
99  // Dump feature info.
100  void dump() const;
101 
102  /// Adds the default features for the specified target triple.
104 };
105 
106 } // End namespace llvm
107 
108 #endif
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
bool operator<(StringRef S) const
SubtargetFeatures(const StringRef Initial="")
std::string getString() const
Features string accessors.
uint64_t getFeatureBits(const StringRef CPU, const SubtargetFeatureKV *CPUTable, size_t CPUTableSize, const SubtargetFeatureKV *FeatureTable, size_t FeatureTableSize)
Get feature bits of a CPU.
void AddFeature(const StringRef String, bool IsEnabled=true)
Adding Features.
bool operator<(StringRef S) const
uint64_t ToggleFeature(uint64_t Bits, const StringRef String, const SubtargetFeatureKV *FeatureTable, size_t FeatureTableSize)
void print(raw_ostream &OS) const
Print feature string.