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