diff options
Diffstat (limited to 'include/llvm/MC/SubtargetFeature.h')
-rw-r--r-- | include/llvm/MC/SubtargetFeature.h | 100 |
1 files changed, 55 insertions, 45 deletions
diff --git a/include/llvm/MC/SubtargetFeature.h b/include/llvm/MC/SubtargetFeature.h index 76c7dd560800..fc9565ceafad 100644 --- a/include/llvm/MC/SubtargetFeature.h +++ b/include/llvm/MC/SubtargetFeature.h @@ -1,9 +1,8 @@ //===- llvm/MC/SubtargetFeature.h - CPU characteristics ---------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // @@ -19,6 +18,7 @@ #define LLVM_MC_SUBTARGETFEATURE_H #include "llvm/ADT/StringRef.h" +#include <array> #include <bitset> #include <initializer_list> #include <string> @@ -26,11 +26,12 @@ namespace llvm { -template <typename T> class ArrayRef; class raw_ostream; class Triple; -const unsigned MAX_SUBTARGET_FEATURES = 192; +const unsigned MAX_SUBTARGET_WORDS = 3; +const unsigned MAX_SUBTARGET_FEATURES = MAX_SUBTARGET_WORDS * 64; + /// Container class for subtarget features. /// This is convenient because std::bitset does not have a constructor /// with an initializer list of set bits. @@ -45,38 +46,34 @@ public: for (auto I : Init) set(I); } -}; - -//===----------------------------------------------------------------------===// - -/// Used to provide key value pairs for feature and CPU bit flags. -struct SubtargetFeatureKV { - const char *Key; ///< K-V key string - const char *Desc; ///< Help descriptor - FeatureBitset Value; ///< K-V integer value - FeatureBitset Implies; ///< K-V bit mask - /// Compare routine for std::lower_bound - bool operator<(StringRef S) const { - return StringRef(Key) < S; - } - - /// Compare routine for std::is_sorted. - bool operator<(const SubtargetFeatureKV &Other) const { - return StringRef(Key) < StringRef(Other.Key); + bool operator < (const FeatureBitset &Other) const { + for (unsigned I = 0, E = size(); I != E; ++I) { + bool LHS = test(I), RHS = Other.test(I); + if (LHS != RHS) + return LHS < RHS; + } + return false; } }; -//===----------------------------------------------------------------------===// +/// Class used to store the subtarget bits in the tables created by tablegen. +/// The std::initializer_list constructor of FeatureBitset can't be done at +/// compile time and requires a static constructor to run at startup. +class FeatureBitArray { + std::array<uint64_t, MAX_SUBTARGET_WORDS> Bits; + +public: + constexpr FeatureBitArray(const std::array<uint64_t, MAX_SUBTARGET_WORDS> &B) + : Bits(B) {} -/// Used to provide key value pairs for CPU and arbitrary pointers. -struct SubtargetInfoKV { - const char *Key; ///< K-V key string - const void *Value; ///< K-V pointer value + FeatureBitset getAsBitset() const { + FeatureBitset Result; - /// Compare routine for std::lower_bound - bool operator<(StringRef S) const { - return StringRef(Key) < S; + for (unsigned i = 0, e = Bits.size(); i != e; ++i) + Result |= FeatureBitset(Bits[i]) << (64 * i); + + return Result; } }; @@ -102,19 +99,6 @@ public: /// Adds Features. void AddFeature(StringRef String, bool Enable = true); - /// Toggles a feature and update the feature bits. - static void ToggleFeature(FeatureBitset &Bits, StringRef String, - ArrayRef<SubtargetFeatureKV> FeatureTable); - - /// Applies the feature flag and update the feature bits. - static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature, - ArrayRef<SubtargetFeatureKV> FeatureTable); - - /// Returns feature bits of a CPU. - FeatureBitset getFeatureBits(StringRef CPU, - ArrayRef<SubtargetFeatureKV> CPUTable, - ArrayRef<SubtargetFeatureKV> FeatureTable); - /// Returns the vector of individual subtarget features. const std::vector<std::string> &getFeatures() const { return Features; } @@ -126,6 +110,32 @@ public: /// Adds the default features for the specified target triple. void getDefaultSubtargetFeatures(const Triple& Triple); + + /// Determine if a feature has a flag; '+' or '-' + static bool hasFlag(StringRef Feature) { + assert(!Feature.empty() && "Empty string"); + // Get first character + char Ch = Feature[0]; + // Check if first character is '+' or '-' flag + return Ch == '+' || Ch =='-'; + } + + /// Return string stripped of flag. + static std::string StripFlag(StringRef Feature) { + return hasFlag(Feature) ? Feature.substr(1) : Feature; + } + + /// Return true if enable flag; '+'. + static inline bool isEnabled(StringRef Feature) { + assert(!Feature.empty() && "Empty string"); + // Get first character + char Ch = Feature[0]; + // Check if first character is '+' for enabled + return Ch == '+'; + } + + /// Splits a string of comma separated items in to a vector of strings. + static void Split(std::vector<std::string> &V, StringRef S); }; } // end namespace llvm |