From 0b57cec536236d46e3dba9bd041533462f33dbb7 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Fri, 20 Dec 2019 19:53:05 +0000 Subject: Move all sources from the llvm project into contrib/llvm-project. This uses the new layout of the upstream repository, which was recently migrated to GitHub, and converted into a "monorepo". That is, most of the earlier separate sub-projects with their own branches and tags were consolidated into one top-level directory, and are now branched and tagged together. Updating the vendor area to match this layout is next. --- .../llvm-project/llvm/lib/MC/SubtargetFeature.cpp | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 contrib/llvm-project/llvm/lib/MC/SubtargetFeature.cpp (limited to 'contrib/llvm-project/llvm/lib/MC/SubtargetFeature.cpp') diff --git a/contrib/llvm-project/llvm/lib/MC/SubtargetFeature.cpp b/contrib/llvm-project/llvm/lib/MC/SubtargetFeature.cpp new file mode 100644 index 000000000000..c4dd77359b24 --- /dev/null +++ b/contrib/llvm-project/llvm/lib/MC/SubtargetFeature.cpp @@ -0,0 +1,82 @@ +//===- SubtargetFeature.cpp - CPU characteristics Implementation ----------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +/// \file Implements the SubtargetFeature interface. +// +//===----------------------------------------------------------------------===// + +#include "llvm/MC/SubtargetFeature.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Triple.h" +#include "llvm/Config/llvm-config.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" +#include +#include +#include +#include +#include +#include +#include + +using namespace llvm; + +/// Splits a string of comma separated items in to a vector of strings. +void SubtargetFeatures::Split(std::vector &V, StringRef S) { + SmallVector Tmp; + S.split(Tmp, ',', -1, false /* KeepEmpty */); + V.assign(Tmp.begin(), Tmp.end()); +} + +void SubtargetFeatures::AddFeature(StringRef String, bool Enable) { + // Don't add empty features. + if (!String.empty()) + // Convert to lowercase, prepend flag if we don't already have a flag. + Features.push_back(hasFlag(String) ? String.lower() + : (Enable ? "+" : "-") + String.lower()); +} + +SubtargetFeatures::SubtargetFeatures(StringRef Initial) { + // Break up string into separate features + Split(Features, Initial); +} + +std::string SubtargetFeatures::getString() const { + return join(Features.begin(), Features.end(), ","); +} + +void SubtargetFeatures::print(raw_ostream &OS) const { + for (auto &F : Features) + OS << F << " "; + OS << "\n"; +} + +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) +LLVM_DUMP_METHOD void SubtargetFeatures::dump() const { + print(dbgs()); +} +#endif + +void SubtargetFeatures::getDefaultSubtargetFeatures(const Triple& Triple) { + // 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 . + 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"); + } + } +} -- cgit v1.2.3