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 "llvm/ADT/Triple.h" 22224133Sdim#include "llvm/Support/DataTypes.h" 23249423Sdim#include <vector> 24224133Sdim 25224133Sdimnamespace llvm { 26224133Sdim class raw_ostream; 27224133Sdim class StringRef; 28239462Sdim 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 39239462Sdim 40263508Sdim // Compare routine for std::lower_bound 41263508Sdim bool operator<(StringRef S) const { 42263508Sdim return StringRef(Key) < S; 43224133Sdim } 44224133Sdim}; 45239462Sdim 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 53243830Sdim const void *Value; // K-V pointer value 54239462Sdim 55263508Sdim // Compare routine for std::lower_bound 56263508Sdim bool operator<(StringRef S) const { 57263508Sdim return StringRef(Key) < S; 58224133Sdim } 59224133Sdim}; 60239462Sdim 61224133Sdim//===----------------------------------------------------------------------===// 62224133Sdim/// 63239462Sdim/// SubtargetFeatures - Manages the enabling and disabling of subtarget 64224133Sdim/// specific features. Features are encoded as a string of the form 65251662Sdim/// "+attr1,+attr2,-attr3,...,+attrN" 66224133Sdim/// A comma separates each feature from the next (all lowercase.) 67224133Sdim/// Each of the remaining features is prefixed with + or - indicating whether 68224133Sdim/// that feature should be enabled or disabled contrary to the cpu 69224133Sdim/// specification. 70224133Sdim/// 71224133Sdim 72224133Sdimclass SubtargetFeatures { 73224133Sdim std::vector<std::string> Features; // Subtarget features as a vector 74224133Sdimpublic: 75224133Sdim explicit SubtargetFeatures(const StringRef Initial = ""); 76224133Sdim 77224133Sdim /// Features string accessors. 78224133Sdim std::string getString() const; 79224133Sdim 80224133Sdim /// Adding Features. 81224133Sdim void AddFeature(const StringRef String, bool IsEnabled = true); 82239462Sdim 83224133Sdim /// ToggleFeature - Toggle a feature and returns the newly updated feature 84224133Sdim /// bits. 85224133Sdim uint64_t ToggleFeature(uint64_t Bits, const StringRef String, 86224133Sdim const SubtargetFeatureKV *FeatureTable, 87224133Sdim size_t FeatureTableSize); 88239462Sdim 89224133Sdim /// Get feature bits of a CPU. 90224133Sdim uint64_t getFeatureBits(const StringRef CPU, 91224133Sdim const SubtargetFeatureKV *CPUTable, 92224133Sdim size_t CPUTableSize, 93224133Sdim const SubtargetFeatureKV *FeatureTable, 94224133Sdim size_t FeatureTableSize); 95239462Sdim 96224133Sdim /// Print feature string. 97224133Sdim void print(raw_ostream &OS) const; 98239462Sdim 99224133Sdim // Dump feature info. 100224133Sdim void dump() const; 101224133Sdim 102263508Sdim /// Adds the default features for the specified target triple. 103224133Sdim void getDefaultSubtargetFeatures(const Triple& Triple); 104224133Sdim}; 105224133Sdim 106224133Sdim} // End namespace llvm 107224133Sdim 108224133Sdim#endif 109