LLVM 19.0.0git
SubtargetFeature.cpp
Go to the documentation of this file.
1//===- SubtargetFeature.cpp - CPU characteristics Implementation ----------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file Implements the SubtargetFeature interface.
10//
11//===----------------------------------------------------------------------===//
12
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Config/llvm-config.h"
19#include "llvm/Support/Debug.h"
22#include <algorithm>
23#include <string>
24#include <vector>
25
26using namespace llvm;
27
28/// Splits a string of comma separated items in to a vector of strings.
29void SubtargetFeatures::Split(std::vector<std::string> &V, StringRef S) {
31 S.split(Tmp, ',', -1, false /* KeepEmpty */);
32 V.reserve(Tmp.size());
33 for (StringRef T : Tmp)
34 V.push_back(std::string(T));
35}
36
38 // Don't add empty features.
39 if (!String.empty())
40 // Convert to lowercase, prepend flag if we don't already have a flag.
41 Features.push_back(hasFlag(String) ? String.lower()
42 : (Enable ? "+" : "-") + String.lower());
43}
44
46 const ArrayRef<std::string> OtherFeatures) {
47 Features.insert(Features.cend(), OtherFeatures.begin(), OtherFeatures.end());
48}
49
51 // Break up string into separate features
52 Split(Features, Initial);
53}
54
55std::string SubtargetFeatures::getString() const {
56 return join(Features.begin(), Features.end(), ",");
57}
58
60 for (const auto &F : Features)
61 OS << F << " ";
62 OS << "\n";
63}
64
65#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
67 print(dbgs());
68}
69#endif
70
72 // FIXME: This is an inelegant way of specifying the features of a
73 // subtarget. It would be better if we could encode this information
74 // into the IR.
76 if (Triple.getArch() == Triple::ppc) {
77 // powerpc-apple-*
78 AddFeature("altivec");
79 } else if (Triple.getArch() == Triple::ppc64) {
80 // powerpc64-apple-*
81 AddFeature("64bit");
82 AddFeature("altivec");
83 }
84 }
85}
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:529
#define F(x, y, z)
Definition: MD5.cpp:55
raw_pwrite_stream & OS
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
iterator end() const
Definition: ArrayRef.h:154
iterator begin() const
Definition: ArrayRef.h:153
size_t size() const
Definition: SmallVector.h:91
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:696
static void Split(std::vector< std::string > &V, StringRef S)
Splits a string of comma separated items in to a vector of strings.
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
static bool hasFlag(StringRef Feature)
Determine if a feature has a flag; '+' or '-'.
void print(raw_ostream &OS) const
Prints feature string.
std::string getString() const
Returns features as a string.
SubtargetFeatures(StringRef Initial="")
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
void addFeaturesVector(const ArrayRef< std::string > OtherFeatures)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:361
VendorType getVendor() const
Get the parsed vendor type of this triple.
Definition: Triple.h:367
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
@ Enable
Enable colors.