2009-06-02 13:52:33 -04:00
|
|
|
//===- SubtargetFeature.cpp - CPU characteristics Implementation ----------===//
|
|
|
|
|
//
|
2019-08-20 16:50:12 -04:00
|
|
|
// 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
|
2009-06-02 13:52:33 -04:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
//
|
2017-04-16 12:01:22 -04:00
|
|
|
/// \file Implements the SubtargetFeature interface.
|
2009-06-02 13:52:33 -04:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2023-09-02 17:17:18 -04:00
|
|
|
#include "llvm/TargetParser/SubtargetFeature.h"
|
2017-04-16 12:01:22 -04:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2015-06-09 15:06:30 -04:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2017-04-16 12:01:22 -04:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2018-07-28 06:51:19 -04:00
|
|
|
#include "llvm/Config/llvm-config.h"
|
2017-04-16 12:01:22 -04:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2010-01-15 10:37:28 -05:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-10-14 13:57:32 -04:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2023-09-02 17:17:18 -04:00
|
|
|
#include "llvm/TargetParser/Triple.h"
|
2009-06-02 13:52:33 -04:00
|
|
|
#include <algorithm>
|
2017-04-16 12:01:22 -04:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2009-06-02 13:52:33 -04:00
|
|
|
|
2017-04-16 12:01:22 -04:00
|
|
|
using namespace llvm;
|
2009-06-02 13:52:33 -04:00
|
|
|
|
2017-04-16 12:01:22 -04:00
|
|
|
/// Splits a string of comma separated items in to a vector of strings.
|
2019-08-20 16:50:12 -04:00
|
|
|
void SubtargetFeatures::Split(std::vector<std::string> &V, StringRef S) {
|
2015-01-18 11:17:27 -05:00
|
|
|
SmallVector<StringRef, 3> Tmp;
|
2015-12-30 06:46:15 -05:00
|
|
|
S.split(Tmp, ',', -1, false /* KeepEmpty */);
|
2020-07-26 15:36:28 -04:00
|
|
|
V.reserve(Tmp.size());
|
|
|
|
|
for (StringRef T : Tmp)
|
|
|
|
|
V.push_back(std::string(T));
|
2009-06-02 13:52:33 -04:00
|
|
|
}
|
|
|
|
|
|
2015-05-27 14:44:32 -04:00
|
|
|
void SubtargetFeatures::AddFeature(StringRef String, bool Enable) {
|
|
|
|
|
// Don't add empty features.
|
2014-11-24 04:08:18 -05:00
|
|
|
if (!String.empty())
|
|
|
|
|
// Convert to lowercase, prepend flag if we don't already have a flag.
|
2015-05-27 14:44:32 -04:00
|
|
|
Features.push_back(hasFlag(String) ? String.lower()
|
|
|
|
|
: (Enable ? "+" : "-") + String.lower());
|
2009-06-02 13:52:33 -04:00
|
|
|
}
|
|
|
|
|
|
2023-02-11 07:38:04 -05:00
|
|
|
void SubtargetFeatures::addFeaturesVector(
|
|
|
|
|
const ArrayRef<std::string> OtherFeatures) {
|
|
|
|
|
Features.insert(Features.cend(), OtherFeatures.begin(), OtherFeatures.end());
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-18 11:17:27 -05:00
|
|
|
SubtargetFeatures::SubtargetFeatures(StringRef Initial) {
|
2009-06-02 13:52:33 -04:00
|
|
|
// Break up string into separate features
|
|
|
|
|
Split(Features, Initial);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string SubtargetFeatures::getString() const {
|
2015-06-09 15:06:30 -04:00
|
|
|
return join(Features.begin(), Features.end(), ",");
|
2009-06-02 13:52:33 -04:00
|
|
|
}
|
|
|
|
|
|
2009-10-14 13:57:32 -04:00
|
|
|
void SubtargetFeatures::print(raw_ostream &OS) const {
|
2023-02-11 07:38:04 -05:00
|
|
|
for (const auto &F : Features)
|
2014-11-24 04:08:18 -05:00
|
|
|
OS << F << " ";
|
2009-06-02 13:52:33 -04:00
|
|
|
OS << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-16 12:01:22 -04:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2016-07-23 16:41:05 -04:00
|
|
|
LLVM_DUMP_METHOD void SubtargetFeatures::dump() const {
|
2010-01-15 10:37:28 -05:00
|
|
|
print(dbgs());
|
2009-06-02 13:52:33 -04:00
|
|
|
}
|
2017-04-16 12:01:22 -04:00
|
|
|
#endif
|
2009-11-19 03:59:28 -05:00
|
|
|
|
2011-07-17 11:36:56 -04:00
|
|
|
void SubtargetFeatures::getDefaultSubtargetFeatures(const Triple& Triple) {
|
2017-04-16 12:01:22 -04:00
|
|
|
// FIXME: This is an inelegant way of specifying the features of a
|
|
|
|
|
// subtarget. It would be better if we could encode this information
|
2023-12-18 15:30:12 -05:00
|
|
|
// into the IR.
|
2010-05-27 11:15:58 -04:00
|
|
|
if (Triple.getVendor() == Triple::Apple) {
|
|
|
|
|
if (Triple.getArch() == Triple::ppc) {
|
|
|
|
|
// powerpc-apple-*
|
|
|
|
|
AddFeature("altivec");
|
|
|
|
|
} else if (Triple.getArch() == Triple::ppc64) {
|
|
|
|
|
// powerpc64-apple-*
|
|
|
|
|
AddFeature("64bit");
|
|
|
|
|
AddFeature("altivec");
|
2009-11-19 03:59:28 -05:00
|
|
|
}
|
2010-05-27 11:15:58 -04:00
|
|
|
}
|
2009-11-19 03:59:28 -05:00
|
|
|
}
|