SubtargetFeature.h revision 224133
1224133Sdim//===-- llvm/MC/SubtargetFeature.h - CPU characteristics --------*- C++ -*-===//
2224133Sdim//
3224133Sdim//                     The LLVM Compiler Infrastructure
4224133Sdim//
5224133Sdim// This file is distributed under the University of Illinois Open Source
6224133Sdim// License. See LICENSE.TXT for details.
7224133Sdim//
8224133Sdim//===----------------------------------------------------------------------===//
9224133Sdim//
10224133Sdim// This file defines and manages user or tool specified CPU characteristics.
11224133Sdim// The intent is to be able to package specific features that should or should
12224133Sdim// not be used on a specific target processor.  A tool, such as llc, could, as
13224133Sdim// as example, gather chip info from the command line, a long with features
14224133Sdim// that should be used on that chip.
15224133Sdim//
16224133Sdim//===----------------------------------------------------------------------===//
17224133Sdim
18224133Sdim#ifndef LLVM_MC_SUBTARGETFEATURE_H
19224133Sdim#define LLVM_MC_SUBTARGETFEATURE_H
20224133Sdim
21224133Sdim#include <vector>
22224133Sdim#include "llvm/ADT/Triple.h"
23224133Sdim#include "llvm/Support/DataTypes.h"
24224133Sdim
25224133Sdimnamespace llvm {
26224133Sdim  class raw_ostream;
27224133Sdim  class StringRef;
28224133Sdim
29224133Sdim//===----------------------------------------------------------------------===//
30224133Sdim///
31224133Sdim/// SubtargetFeatureKV - Used to provide key value pairs for feature and
32224133Sdim/// CPU bit flags.
33224133Sdim//
34224133Sdimstruct SubtargetFeatureKV {
35224133Sdim  const char *Key;                      // K-V key string
36224133Sdim  const char *Desc;                     // Help descriptor
37224133Sdim  uint64_t Value;                       // K-V integer value
38224133Sdim  uint64_t Implies;                     // K-V bit mask
39224133Sdim
40224133Sdim  // Compare routine for std binary search
41224133Sdim  bool operator<(const SubtargetFeatureKV &S) const {
42224133Sdim    return strcmp(Key, S.Key) < 0;
43224133Sdim  }
44224133Sdim};
45224133Sdim
46224133Sdim//===----------------------------------------------------------------------===//
47224133Sdim///
48224133Sdim/// SubtargetInfoKV - Used to provide key value pairs for CPU and arbitrary
49224133Sdim/// pointers.
50224133Sdim//
51224133Sdimstruct SubtargetInfoKV {
52224133Sdim  const char *Key;                      // K-V key string
53224133Sdim  void *Value;                          // K-V pointer value
54224133Sdim
55224133Sdim  // Compare routine for std binary search
56224133Sdim  bool operator<(const SubtargetInfoKV &S) const {
57224133Sdim    return strcmp(Key, S.Key) < 0;
58224133Sdim  }
59224133Sdim};
60224133Sdim
61224133Sdim//===----------------------------------------------------------------------===//
62224133Sdim///
63224133Sdim/// SubtargetFeatures - Manages the enabling and disabling of subtarget
64224133Sdim/// specific features.  Features are encoded as a string of the form
65224133Sdim///   "cpu,+attr1,+attr2,-attr3,...,+attrN"
66224133Sdim/// A comma separates each feature from the next (all lowercase.)
67224133Sdim/// The first feature is always the CPU subtype (eg. pentiumm).  If the CPU
68224133Sdim/// value is "generic" then the CPU subtype should be generic for the target.
69224133Sdim/// Each of the remaining features is prefixed with + or - indicating whether
70224133Sdim/// that feature should be enabled or disabled contrary to the cpu
71224133Sdim/// specification.
72224133Sdim///
73224133Sdim
74224133Sdimclass SubtargetFeatures {
75224133Sdim  std::vector<std::string> Features;    // Subtarget features as a vector
76224133Sdimpublic:
77224133Sdim  explicit SubtargetFeatures(const StringRef Initial = "");
78224133Sdim
79224133Sdim  /// Features string accessors.
80224133Sdim  std::string getString() const;
81224133Sdim
82224133Sdim  /// Adding Features.
83224133Sdim  void AddFeature(const StringRef String, bool IsEnabled = true);
84224133Sdim
85224133Sdim  /// ToggleFeature - Toggle a feature and returns the newly updated feature
86224133Sdim  /// bits.
87224133Sdim  uint64_t ToggleFeature(uint64_t Bits, const StringRef String,
88224133Sdim                         const SubtargetFeatureKV *FeatureTable,
89224133Sdim                         size_t FeatureTableSize);
90224133Sdim
91224133Sdim  /// Get feature bits of a CPU.
92224133Sdim  uint64_t getFeatureBits(const StringRef CPU,
93224133Sdim                          const SubtargetFeatureKV *CPUTable,
94224133Sdim                          size_t CPUTableSize,
95224133Sdim                          const SubtargetFeatureKV *FeatureTable,
96224133Sdim                          size_t FeatureTableSize);
97224133Sdim
98224133Sdim  /// Get scheduling itinerary of a CPU.
99224133Sdim  void *getItinerary(const StringRef CPU,
100224133Sdim                     const SubtargetInfoKV *Table, size_t TableSize);
101224133Sdim
102224133Sdim  /// Print feature string.
103224133Sdim  void print(raw_ostream &OS) const;
104224133Sdim
105224133Sdim  // Dump feature info.
106224133Sdim  void dump() const;
107224133Sdim
108224133Sdim  /// Retrieve a formatted string of the default features for the specified
109224133Sdim  /// target triple.
110224133Sdim  void getDefaultSubtargetFeatures(const Triple& Triple);
111224133Sdim};
112224133Sdim
113224133Sdim} // End namespace llvm
114224133Sdim
115224133Sdim#endif
116