LLVM API Documentation

SubtargetFeature.h

Go to the documentation of this file.
00001 //===-- llvm/Target/SubtargetFeature.h - CPU characteristics ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // 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 <cstring>
00025 #include "llvm/Support/DataTypes.h"
00026 
00027 namespace llvm {
00028 
00029 //===----------------------------------------------------------------------===//
00030 ///
00031 /// SubtargetFeatureKV - Used to provide key value pairs for feature and
00032 /// CPU bit flags.
00033 //
00034 struct SubtargetFeatureKV {
00035   const char *Key;                      // K-V key string
00036   const char *Desc;                     // Help descriptor
00037   uint32_t Value;                       // K-V integer value
00038   uint32_t Implies;                     // K-V bit mask
00039   
00040   // Compare routine for std binary search
00041   bool operator<(const SubtargetFeatureKV &S) const {
00042     return strcmp(Key, S.Key) < 0;
00043   }
00044 };
00045   
00046 //===----------------------------------------------------------------------===//
00047 ///
00048 /// SubtargetInfoKV - Used to provide key value pairs for CPU and arbitrary
00049 /// pointers.
00050 //
00051 struct SubtargetInfoKV {
00052   const char *Key;                      // K-V key string
00053   void *Value;                          // K-V pointer value
00054   
00055   // Compare routine for std binary search
00056   bool operator<(const SubtargetInfoKV &S) const {
00057     return strcmp(Key, S.Key) < 0;
00058   }
00059 };
00060   
00061 //===----------------------------------------------------------------------===//
00062 ///
00063 /// SubtargetFeatures - Manages the enabling and disabling of subtarget 
00064 /// specific features.  Features are encoded as a string of the form
00065 ///   "cpu,+attr1,+attr2,-attr3,...,+attrN"
00066 /// A comma separates each feature from the next (all lowercase.)
00067 /// The first feature is always the CPU subtype (eg. pentiumm).  If the CPU
00068 /// value is "generic" then the CPU subtype should be generic for the target.
00069 /// Each of the remaining features is prefixed with + or - indicating whether
00070 /// that feature should be enabled or disabled contrary to the cpu
00071 /// specification.
00072 ///
00073 
00074 class SubtargetFeatures {
00075   std::vector<std::string> Features;    // Subtarget features as a vector
00076 public:
00077   explicit SubtargetFeatures(const std::string &Initial = std::string());
00078 
00079   /// Features string accessors.
00080   std::string getString() const;
00081   void setString(const std::string &Initial);
00082 
00083   /// Set the CPU string.  Replaces previous setting.  Setting to "" clears CPU.
00084   void setCPU(const std::string &String);
00085   
00086   /// Setting CPU string only if no string is set.
00087   void setCPUIfNone(const std::string &String);
00088   
00089   /// Adding Features.
00090   void AddFeature(const std::string &String, bool IsEnabled = true);
00091            
00092   /// Get feature bits.
00093   uint32_t getBits(const SubtargetFeatureKV *CPUTable,
00094                          size_t CPUTableSize,
00095                    const SubtargetFeatureKV *FeatureTable,
00096                          size_t FeatureTableSize);
00097                          
00098   /// Get info pointer
00099   void *getInfo(const SubtargetInfoKV *Table, size_t TableSize);
00100   
00101   /// Print feature string.
00102   void print(std::ostream &OS) const;
00103   void print(std::ostream *OS) const { if (OS) print(*OS); }
00104   
00105   // Dump feature info.
00106   void dump() const;
00107 };
00108 
00109 } // End namespace llvm
00110 
00111 #endif