SubtargetFeature.h revision 255f89faee13dc491cb64fbeae3c763e7e2ea4e6
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===-- llvm/MC/SubtargetFeature.h - CPU characteristics --------*- C++ -*-===//
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                     The LLVM Compiler Infrastructure
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file is distributed under the University of Illinois Open Source
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// License. See LICENSE.TXT for details.
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===//
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file defines and manages user or tool specified CPU characteristics.
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The intent is to be able to package specific features that should or should
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// not be used on a specific target processor.  A tool, such as llc, could, as
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// as example, gather chip info from the command line, a long with features
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// that should be used on that chip.
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===//
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef LLVM_MC_SUBTARGETFEATURE_H
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define LLVM_MC_SUBTARGETFEATURE_H
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/ADT/Triple.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "llvm/Support/DataTypes.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace llvm {
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class raw_ostream;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class StringRef;
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===//
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// SubtargetFeatureKV - Used to provide key value pairs for feature and
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// CPU bit flags.
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct SubtargetFeatureKV {
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const char *Key;                      // K-V key string
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const char *Desc;                     // Help descriptor
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  uint64_t Value;                       // K-V integer value
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  uint64_t Implies;                     // K-V bit mask
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Compare routine for std binary search
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool operator<(const SubtargetFeatureKV &S) const {
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return strcmp(Key, S.Key) < 0;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===//
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)///
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// SubtargetInfoKV - Used to provide key value pairs for CPU and arbitrary
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/// pointers.
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct SubtargetInfoKV {
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const char *Key;                      // K-V key string
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const void *Value;                    // K-V pointer value
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Compare routine for std binary search
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool operator<(const SubtargetInfoKV &S) const {
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return strcmp(Key, S.Key) < 0;
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///   "cpu,+attr1,+attr2,-attr3,...,+attrN"
66/// A comma separates each feature from the next (all lowercase.)
67/// The first feature is always the CPU subtype (eg. pentiumm).  If the CPU
68/// value is "generic" then the CPU subtype should be generic for the target.
69/// Each of the remaining features is prefixed with + or - indicating whether
70/// that feature should be enabled or disabled contrary to the cpu
71/// specification.
72///
73
74class SubtargetFeatures {
75  std::vector<std::string> Features;    // Subtarget features as a vector
76public:
77  explicit SubtargetFeatures(const StringRef Initial = "");
78
79  /// Features string accessors.
80  std::string getString() const;
81
82  /// Adding Features.
83  void AddFeature(const StringRef String, bool IsEnabled = true);
84
85  /// ToggleFeature - Toggle a feature and returns the newly updated feature
86  /// bits.
87  uint64_t ToggleFeature(uint64_t Bits, const StringRef String,
88                         const SubtargetFeatureKV *FeatureTable,
89                         size_t FeatureTableSize);
90
91  /// Get feature bits of a CPU.
92  uint64_t getFeatureBits(const StringRef CPU,
93                          const SubtargetFeatureKV *CPUTable,
94                          size_t CPUTableSize,
95                          const SubtargetFeatureKV *FeatureTable,
96                          size_t FeatureTableSize);
97
98  /// Print feature string.
99  void print(raw_ostream &OS) const;
100
101  // Dump feature info.
102  void dump() const;
103
104  /// Retrieve a formatted string of the default features for the specified
105  /// target triple.
106  void getDefaultSubtargetFeatures(const Triple& Triple);
107};
108
109} // End namespace llvm
110
111#endif
112