LLVM API Documentation

SubtargetFeature.h
Go to the documentation of this file.
00001 //===-- llvm/MC/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_MC_SUBTARGETFEATURE_H
00019 #define LLVM_MC_SUBTARGETFEATURE_H
00020 
00021 #include "llvm/ADT/ArrayRef.h"
00022 #include "llvm/ADT/Triple.h"
00023 #include "llvm/Support/DataTypes.h"
00024 
00025 namespace llvm {
00026   class raw_ostream;
00027   class StringRef;
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   uint64_t Value;                       // K-V integer value
00038   uint64_t Implies;                     // K-V bit mask
00039 
00040   // Compare routine for std::lower_bound
00041   bool operator<(StringRef S) const {
00042     return StringRef(Key) < S;
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   const void *Value;                    // K-V pointer value
00054 
00055   // Compare routine for std::lower_bound
00056   bool operator<(StringRef S) const {
00057     return StringRef(Key) < S;
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 ///   "+attr1,+attr2,-attr3,...,+attrN"
00066 /// A comma separates each feature from the next (all lowercase.)
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   explicit SubtargetFeatures(StringRef Initial = "");
00076 
00077   /// Features string accessors.
00078   std::string getString() const;
00079 
00080   /// Adding Features.
00081   void AddFeature(StringRef String);
00082 
00083   /// ToggleFeature - Toggle a feature and returns the newly updated feature
00084   /// bits.
00085   uint64_t ToggleFeature(uint64_t Bits, StringRef String,
00086                          ArrayRef<SubtargetFeatureKV> FeatureTable);
00087 
00088   /// Get feature bits of a CPU.
00089   uint64_t getFeatureBits(StringRef CPU,
00090                           ArrayRef<SubtargetFeatureKV> CPUTable,
00091                           ArrayRef<SubtargetFeatureKV> FeatureTable);
00092 
00093   /// Print feature string.
00094   void print(raw_ostream &OS) const;
00095 
00096   // Dump feature info.
00097   void dump() const;
00098 
00099   /// Adds the default features for the specified target triple.
00100   void getDefaultSubtargetFeatures(const Triple& Triple);
00101 };
00102 
00103 } // End namespace llvm
00104 
00105 #endif