98a589213a2bdebc1903ba89fdf14098f69ea9e5
[oota-llvm.git] / include / llvm / Target / SubtargetFeature.h
1 //===-- llvm/Target/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_TARGET_SUBTARGETFEATURE_H
19 #define LLVM_TARGET_SUBTARGETFEATURE_H
20
21 #include <string>
22 #include <vector>
23 #include <iosfwd>
24 #include "llvm/Support/DataTypes.h"
25
26 namespace llvm {
27
28 //===----------------------------------------------------------------------===//
29 ///
30 /// SubtargetFeatureKV - Used to provide key value pairs for feature and
31 /// CPU bit flags.
32 //
33 struct SubtargetFeatureKV {
34   const char *Key;                      // K-V key string
35   const char *Desc;                     // Help descriptor
36   uint32_t Value;                       // K-V integer value
37   uint32_t Implies;                     // K-V bit mask
38   
39   // Compare routine for std binary search
40   bool operator<(const SubtargetFeatureKV &S) const {
41     return strcmp(Key, S.Key) < 0;
42   }
43 };
44   
45 //===----------------------------------------------------------------------===//
46 ///
47 /// SubtargetInfoKV - Used to provide key value pairs for CPU and arbitrary
48 /// pointers.
49 //
50 struct SubtargetInfoKV {
51   const char *Key;                      // K-V key string
52   void *Value;                          // K-V pointer value
53   
54   // Compare routine for std binary search
55   bool operator<(const SubtargetInfoKV &S) const {
56     return strcmp(Key, S.Key) < 0;
57   }
58 };
59   
60 //===----------------------------------------------------------------------===//
61 ///
62 /// SubtargetFeatures - Manages the enabling and disabling of subtarget 
63 /// specific features.  Features are encoded as a string of the form
64 ///   "cpu,+attr1,+attr2,-attr3,...,+attrN"
65 /// A comma separates each feature from the next (all lowercase.)
66 /// The first feature is always the CPU subtype (eg. pentiumm).  If the CPU
67 /// value is "generic" then the CPU subtype should be generic for the target.
68 /// Each of the remaining features is prefixed with + or - indicating whether
69 /// that feature should be enabled or disabled contrary to the cpu
70 /// specification.
71 ///
72
73 class SubtargetFeatures {
74   std::vector<std::string> Features;    // Subtarget features as a vector
75 public:
76   explicit SubtargetFeatures(const std::string &Initial = std::string());
77
78   /// Features string accessors.
79   std::string getString() const;
80   void setString(const std::string &Initial);
81
82   /// Set the CPU string.  Replaces previous setting.  Setting to "" clears CPU.
83   void setCPU(const std::string &String);
84   
85   /// Setting CPU string only if no string is set.
86   void setCPUIfNone(const std::string &String);
87   
88   /// Adding Features.
89   void AddFeature(const std::string &String, bool IsEnabled = true);
90            
91   /// Get feature bits.
92   uint32_t getBits(const SubtargetFeatureKV *CPUTable,
93                          size_t CPUTableSize,
94                    const SubtargetFeatureKV *FeatureTable,
95                          size_t FeatureTableSize);
96                          
97   /// Get info pointer
98   void *getInfo(const SubtargetInfoKV *Table, size_t TableSize);
99   
100   /// Print feature string.
101   void print(std::ostream &OS) const;
102   void print(std::ostream *OS) const { if (OS) print(*OS); }
103   
104   // Dump feature info.
105   void dump() const;
106 };
107
108 } // End namespace llvm
109
110 #endif