1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 11:42:57 +01:00

Switch SubtargetFeatures from std::string to StringRef.

llvm-svn: 134219
This commit is contained in:
Evan Cheng 2011-07-01 00:23:10 +00:00
parent aec0b9ae1f
commit 1fa6460e3f
2 changed files with 25 additions and 29 deletions

View File

@ -18,13 +18,13 @@
#ifndef LLVM_MC_SUBTARGETFEATURE_H
#define LLVM_MC_SUBTARGETFEATURE_H
#include <string>
#include <vector>
#include "llvm/ADT/Triple.h"
#include "llvm/Support/DataTypes.h"
namespace llvm {
class raw_ostream;
class StringRef;
//===----------------------------------------------------------------------===//
///
@ -74,24 +74,23 @@ struct SubtargetInfoKV {
class SubtargetFeatures {
std::vector<std::string> Features; // Subtarget features as a vector
public:
explicit SubtargetFeatures(const std::string &Initial = std::string());
explicit SubtargetFeatures(const StringRef Initial = "");
/// Features string accessors.
std::string getString() const;
void setString(const std::string &Initial);
StringRef getString() const;
/// Adding Features.
void AddFeature(const std::string &String, bool IsEnabled = true);
void AddFeature(const StringRef String, bool IsEnabled = true);
/// Get feature bits of a CPU.
uint64_t getFeatureBits(const std::string &CPU,
uint64_t getFeatureBits(const StringRef CPU,
const SubtargetFeatureKV *CPUTable,
size_t CPUTableSize,
const SubtargetFeatureKV *FeatureTable,
size_t FeatureTableSize);
/// Get scheduling itinerary of a CPU.
void *getItinerary(const std::string &CPU,
void *getItinerary(const StringRef CPU,
const SubtargetInfoKV *Table, size_t TableSize);
/// Print feature string.

View File

@ -27,7 +27,7 @@ using namespace llvm;
/// hasFlag - Determine if a feature has a flag; '+' or '-'
///
static inline bool hasFlag(const std::string &Feature) {
static inline bool hasFlag(const StringRef Feature) {
assert(!Feature.empty() && "Empty string");
// Get first character
char Ch = Feature[0];
@ -37,13 +37,13 @@ static inline bool hasFlag(const std::string &Feature) {
/// StripFlag - Return string stripped of flag.
///
static inline std::string StripFlag(const std::string &Feature) {
static inline std::string StripFlag(const StringRef Feature) {
return hasFlag(Feature) ? Feature.substr(1) : Feature;
}
/// isEnabled - Return true if enable flag; '+'.
///
static inline bool isEnabled(const std::string &Feature) {
static inline bool isEnabled(const StringRef Feature) {
assert(!Feature.empty() && "Empty string");
// Get first character
char Ch = Feature[0];
@ -53,16 +53,19 @@ static inline bool isEnabled(const std::string &Feature) {
/// PrependFlag - Return a string with a prepended flag; '+' or '-'.
///
static inline std::string PrependFlag(const std::string &Feature,
bool IsEnabled) {
static inline StringRef PrependFlag(const StringRef Feature,
bool IsEnabled) {
assert(!Feature.empty() && "Empty string");
if (hasFlag(Feature)) return Feature;
return std::string(IsEnabled ? "+" : "-") + Feature;
if (hasFlag(Feature))
return Feature;
std::string Prefix = IsEnabled ? "+" : "-";
Prefix += Feature;
return StringRef(Prefix);
}
/// Split - Splits a string of comma separated items in to a vector of strings.
///
static void Split(std::vector<std::string> &V, const std::string &S) {
static void Split(std::vector<std::string> &V, const StringRef S) {
if (S.empty())
return;
@ -106,7 +109,7 @@ static std::string Join(const std::vector<std::string> &V) {
}
/// Adding features.
void SubtargetFeatures::AddFeature(const std::string &String,
void SubtargetFeatures::AddFeature(const StringRef String,
bool IsEnabled) {
// Don't add empty features
if (!String.empty()) {
@ -116,10 +119,10 @@ void SubtargetFeatures::AddFeature(const std::string &String,
}
/// Find KV in array using binary search.
template<typename T> const T *Find(const std::string &S, const T *A, size_t L) {
template<typename T> const T *Find(const StringRef S, const T *A, size_t L) {
// Make the lower bound element we're looking for
T KV;
KV.Key = S.c_str();
KV.Key = S.data();
// Determine the end of the array
const T *Hi = A + L;
// Binary search the array
@ -173,21 +176,15 @@ static void Help(const SubtargetFeatureKV *CPUTable, size_t CPUTableSize,
// SubtargetFeatures Implementation
//===----------------------------------------------------------------------===//
SubtargetFeatures::SubtargetFeatures(const std::string &Initial) {
SubtargetFeatures::SubtargetFeatures(const StringRef Initial) {
// Break up string into separate features
Split(Features, Initial);
}
std::string SubtargetFeatures::getString() const {
StringRef SubtargetFeatures::getString() const {
return Join(Features);
}
void SubtargetFeatures::setString(const std::string &Initial) {
// Throw out old features
Features.clear();
// Break up string into separate features
Split(Features, LowercaseString(Initial));
}
/// SetImpliedBits - For each feature that is (transitively) implied by this
/// feature, set it.
@ -229,7 +226,7 @@ void ClearImpliedBits(uint64_t &Bits, const SubtargetFeatureKV *FeatureEntry,
/// getFeatureBits - Get feature bits a CPU.
///
uint64_t SubtargetFeatures::getFeatureBits(const std::string &CPU,
uint64_t SubtargetFeatures::getFeatureBits(const StringRef CPU,
const SubtargetFeatureKV *CPUTable,
size_t CPUTableSize,
const SubtargetFeatureKV *FeatureTable,
@ -272,7 +269,7 @@ uint64_t SubtargetFeatures::getFeatureBits(const std::string &CPU,
}
// Iterate through each feature
for (size_t i = 0, E = Features.size(); i < E; i++) {
const std::string &Feature = Features[i];
const StringRef Feature = Features[i];
// Check for help
if (Feature == "+help")
@ -306,7 +303,7 @@ uint64_t SubtargetFeatures::getFeatureBits(const std::string &CPU,
}
/// Get scheduling itinerary of a CPU.
void *SubtargetFeatures::getItinerary(const std::string &CPU,
void *SubtargetFeatures::getItinerary(const StringRef CPU,
const SubtargetInfoKV *Table,
size_t TableSize) {
assert(Table && "missing table");