Move static functions to .cpp file, reduce #includes, pass strings by
[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 was developed by Jim Laskey and is distributed under the 
6 // University of Illinois Open Source 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   
38   // Compare routine for std binary search
39   bool operator<(const std::string &S) const {
40     return strcmp(Key, S.c_str()) < 0;
41   }
42 };
43   
44 //===----------------------------------------------------------------------===//
45 ///
46 /// SubtargetFeatures - Manages the enabling and disabling of subtarget 
47 /// specific features.  Features are encoded as a string of the form
48 ///   "cpu,+attr1,+attr2,-attr3,...,+attrN"
49 /// A comma separates each feature from the next (all lowercase.)
50 /// The first feature is always the CPU subtype (eg. pentiumm).  If the CPU
51 /// value is "generic" then the CPU subtype should be generic for the target.
52 /// Each of the remaining features is prefixed with + or - indicating whether
53 /// that feature should be enabled or disabled contrary to the cpu
54 /// specification.
55 ///
56
57 class SubtargetFeatures {
58   std::vector<std::string> Features;    // Subtarget features as a vector
59 public:
60   SubtargetFeatures(const std::string &Initial = std::string());
61
62   /// Features string accessors.
63   std::string getString() const;
64   void setString(const std::string &Initial);
65
66   /// Setting CPU string.  Replaces previous setting.  Setting to "" clears CPU.
67   ///
68   void setCPU(const std::string &String);
69   
70   /// Adding Features.
71   void AddFeature(const std::string &String, bool IsEnabled = true);
72            
73   /// Parse feature string for quick usage.
74   static uint32_t Parse(const std::string &String,
75                         const std::string &DefaultCPU,
76                         const SubtargetFeatureKV *CPUTable,
77                         size_t CPUTableSize,
78                         const SubtargetFeatureKV *FeatureTable,
79                         size_t FeatureTableSize);
80   
81   /// Print feature string.
82   void print(std::ostream &OS) const;
83   
84   // Dump feature info.
85   void dump() const;
86 };
87
88 } // End namespace llvm
89
90 #endif