1 //===- SubtargetFeature.cpp - CPU characteristics Implementation ----------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 /// \file Implements the SubtargetFeature interface.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/MC/SubtargetFeature.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/ADT/StringExtras.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/Config/llvm-config.h"
19 #include "llvm/Support/Compiler.h"
20 #include "llvm/Support/Debug.h"
21 #include "llvm/Support/raw_ostream.h"
32 /// Splits a string of comma separated items in to a vector of strings.
33 void SubtargetFeatures::Split(std::vector
<std::string
> &V
, StringRef S
) {
34 SmallVector
<StringRef
, 3> Tmp
;
35 S
.split(Tmp
, ',', -1, false /* KeepEmpty */);
36 V
.assign(Tmp
.begin(), Tmp
.end());
39 void SubtargetFeatures::AddFeature(StringRef String
, bool Enable
) {
40 // Don't add empty features.
42 // Convert to lowercase, prepend flag if we don't already have a flag.
43 Features
.push_back(hasFlag(String
) ? String
.lower()
44 : (Enable
? "+" : "-") + String
.lower());
47 SubtargetFeatures::SubtargetFeatures(StringRef Initial
) {
48 // Break up string into separate features
49 Split(Features
, Initial
);
52 std::string
SubtargetFeatures::getString() const {
53 return join(Features
.begin(), Features
.end(), ",");
56 void SubtargetFeatures::print(raw_ostream
&OS
) const {
57 for (auto &F
: Features
)
62 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
63 LLVM_DUMP_METHOD
void SubtargetFeatures::dump() const {
68 void SubtargetFeatures::getDefaultSubtargetFeatures(const Triple
& Triple
) {
69 // FIXME: This is an inelegant way of specifying the features of a
70 // subtarget. It would be better if we could encode this information
71 // into the IR. See <rdar://5972456>.
72 if (Triple
.getVendor() == Triple::Apple
) {
73 if (Triple
.getArch() == Triple::ppc
) {
75 AddFeature("altivec");
76 } else if (Triple
.getArch() == Triple::ppc64
) {
79 AddFeature("altivec");