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