1 //===-- llvm/Target/SubtargetFeature.h - CPU characteristics ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by James M. Laskey and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_TARGET_SUBTARGETFEATURE_H
19 #define LLVM_TARGET_SUBTARGETFEATURE_H
24 #include "llvm/Support/DataTypes.h"
28 //===----------------------------------------------------------------------===//
30 /// SubtargetFeatureKV - Used to provide key value pairs for feature and
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
38 // Compare routine for std binary search
39 bool operator<(const SubtargetFeatureKV &S) const {
40 return strcmp(Key, S.Key) < 0;
44 //===----------------------------------------------------------------------===//
46 /// SubtargetInfoKV - Used to provide key value pairs for CPU and arbitrary
49 struct SubtargetInfoKV {
50 const char *Key; // K-V key string
51 void *Value; // K-V pointer value
53 // Compare routine for std binary search
54 bool operator<(const SubtargetInfoKV &S) const {
55 return strcmp(Key, S.Key) < 0;
59 //===----------------------------------------------------------------------===//
61 /// SubtargetFeatures - Manages the enabling and disabling of subtarget
62 /// specific features. Features are encoded as a string of the form
63 /// "cpu,+attr1,+attr2,-attr3,...,+attrN"
64 /// A comma separates each feature from the next (all lowercase.)
65 /// The first feature is always the CPU subtype (eg. pentiumm). If the CPU
66 /// value is "generic" then the CPU subtype should be generic for the target.
67 /// Each of the remaining features is prefixed with + or - indicating whether
68 /// that feature should be enabled or disabled contrary to the cpu
72 class SubtargetFeatures {
73 std::vector<std::string> Features; // Subtarget features as a vector
75 SubtargetFeatures(const std::string &Initial = std::string());
77 /// Features string accessors.
78 std::string getString() const;
79 void setString(const std::string &Initial);
81 /// Set the CPU string. Replaces previous setting. Setting to "" clears CPU.
82 void setCPU(const std::string &String);
84 /// Setting CPU string only if no string is set.
85 void setCPUIfNone(const std::string &String);
88 void AddFeature(const std::string &String, bool IsEnabled = true);
91 uint32_t getBits(const SubtargetFeatureKV *CPUTable,
93 const SubtargetFeatureKV *FeatureTable,
94 size_t FeatureTableSize);
97 void *getInfo(const SubtargetInfoKV *Table, size_t TableSize);
99 /// Print feature string.
100 void print(std::ostream &OS) const;
102 // Dump feature info.
106 } // End namespace llvm