LLVM  10.0.0svn
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 
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"
22 #include <algorithm>
23 #include <cassert>
24 #include <cstddef>
25 #include <cstring>
26 #include <iterator>
27 #include <string>
28 #include <vector>
29 
30 using namespace llvm;
31 
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) {
35  S.split(Tmp, ',', -1, false /* KeepEmpty */);
36  V.assign(Tmp.begin(), Tmp.end());
37 }
38 
40  // Don't add empty features.
41  if (!String.empty())
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());
45 }
46 
48  // Break up string into separate features
49  Split(Features, Initial);
50 }
51 
52 std::string SubtargetFeatures::getString() const {
53  return join(Features.begin(), Features.end(), ",");
54 }
55 
57  for (auto &F : Features)
58  OS << F << " ";
59  OS << "\n";
60 }
61 
62 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
64  print(dbgs());
65 }
66 #endif
67 
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) {
74  // powerpc-apple-*
75  AddFeature("altivec");
76  } else if (Triple.getArch() == Triple::ppc64) {
77  // powerpc64-apple-*
78  AddFeature("64bit");
79  AddFeature("altivec");
80  }
81  }
82 }
void print(raw_ostream &OS) const
Prints feature string.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:476
std::string getString() const
Returns features as a string.
F(f)
static bool hasFlag(StringRef Feature)
Determine if a feature has a flag; &#39;+&#39; or &#39;-&#39;.
std::string join(IteratorT Begin, IteratorT End, StringRef Separator)
Joins the strings in the range [Begin, End), adding Separator between the elements.
Definition: StringExtras.h:370
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:140
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:296
static void Split(std::vector< std::string > &V, StringRef S)
Splits a string of comma separated items in to a vector of strings.
VendorType getVendor() const
getVendor - Get the parsed vendor type of this triple.
Definition: Triple.h:302
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:710
SubtargetFeatures(StringRef Initial="")
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
LLVM_NODISCARD std::string lower() const
Definition: StringRef.cpp:107
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48