LLVM API Documentation
00001 //===-- llvm/Target/SubtargetFeature.h - CPU characteristics ----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by James M. Laskey and is distributed under the 00006 // University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines and manages user or tool specified CPU characteristics. 00011 // The intent is to be able to package specific features that should or should 00012 // not be used on a specific target processor. A tool, such as llc, could, as 00013 // as example, gather chip info from the command line, a long with features 00014 // that should be used on that chip. 00015 // 00016 //===----------------------------------------------------------------------===// 00017 00018 #ifndef LLVM_TARGET_SUBTARGETFEATURE_H 00019 #define LLVM_TARGET_SUBTARGETFEATURE_H 00020 00021 #include <string> 00022 #include <vector> 00023 #include <iosfwd> 00024 #include "llvm/Support/DataTypes.h" 00025 00026 namespace llvm { 00027 00028 //===----------------------------------------------------------------------===// 00029 /// 00030 /// SubtargetFeatureKV - Used to provide key value pairs for feature and 00031 /// CPU bit flags. 00032 // 00033 struct SubtargetFeatureKV { 00034 const char *Key; // K-V key string 00035 const char *Desc; // Help descriptor 00036 uint32_t Value; // K-V integer value 00037 00038 // Compare routine for std binary search 00039 bool operator<(const SubtargetFeatureKV &S) const { 00040 return strcmp(Key, S.Key) < 0; 00041 } 00042 }; 00043 00044 //===----------------------------------------------------------------------===// 00045 /// 00046 /// SubtargetInfoKV - Used to provide key value pairs for CPU and arbitrary 00047 /// pointers. 00048 // 00049 struct SubtargetInfoKV { 00050 const char *Key; // K-V key string 00051 void *Value; // K-V pointer value 00052 00053 // Compare routine for std binary search 00054 bool operator<(const SubtargetInfoKV &S) const { 00055 return strcmp(Key, S.Key) < 0; 00056 } 00057 }; 00058 00059 //===----------------------------------------------------------------------===// 00060 /// 00061 /// SubtargetFeatures - Manages the enabling and disabling of subtarget 00062 /// specific features. Features are encoded as a string of the form 00063 /// "cpu,+attr1,+attr2,-attr3,...,+attrN" 00064 /// A comma separates each feature from the next (all lowercase.) 00065 /// The first feature is always the CPU subtype (eg. pentiumm). If the CPU 00066 /// value is "generic" then the CPU subtype should be generic for the target. 00067 /// Each of the remaining features is prefixed with + or - indicating whether 00068 /// that feature should be enabled or disabled contrary to the cpu 00069 /// specification. 00070 /// 00071 00072 class SubtargetFeatures { 00073 std::vector<std::string> Features; // Subtarget features as a vector 00074 public: 00075 SubtargetFeatures(const std::string &Initial = std::string()); 00076 00077 /// Features string accessors. 00078 std::string getString() const; 00079 void setString(const std::string &Initial); 00080 00081 /// Set the CPU string. Replaces previous setting. Setting to "" clears CPU. 00082 void setCPU(const std::string &String); 00083 00084 /// Setting CPU string only if no string is set. 00085 void setCPUIfNone(const std::string &String); 00086 00087 /// Adding Features. 00088 void AddFeature(const std::string &String, bool IsEnabled = true); 00089 00090 /// Get feature bits. 00091 uint32_t getBits(const SubtargetFeatureKV *CPUTable, 00092 size_t CPUTableSize, 00093 const SubtargetFeatureKV *FeatureTable, 00094 size_t FeatureTableSize); 00095 00096 /// Get info pointer 00097 void *getInfo(const SubtargetInfoKV *Table, size_t TableSize); 00098 00099 /// Print feature string. 00100 void print(std::ostream &OS) const; 00101 00102 // Dump feature info. 00103 void dump() const; 00104 }; 00105 00106 } // End namespace llvm 00107 00108 #endif