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