LLVM  14.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 
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.reserve(Tmp.size());
37  for (StringRef T : Tmp)
38  V.push_back(std::string(T));
39 }
40 
41 void SubtargetFeatures::AddFeature(StringRef String, bool Enable) {
42  // Don't add empty features.
43  if (!String.empty())
44  // Convert to lowercase, prepend flag if we don't already have a flag.
45  Features.push_back(hasFlag(String) ? String.lower()
46  : (Enable ? "+" : "-") + String.lower());
47 }
48 
50  // Break up string into separate features
51  Split(Features, Initial);
52 }
53 
54 std::string SubtargetFeatures::getString() const {
55  return join(Features.begin(), Features.end(), ",");
56 }
57 
59  for (auto &F : Features)
60  OS << F << " ";
61  OS << "\n";
62 }
63 
64 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
66  print(dbgs());
67 }
68 #endif
69 
71  // FIXME: This is an inelegant way of specifying the features of a
72  // subtarget. It would be better if we could encode this information
73  // into the IR. See <rdar://5972456>.
74  if (Triple.getVendor() == Triple::Apple) {
75  if (Triple.getArch() == Triple::ppc) {
76  // powerpc-apple-*
77  AddFeature("altivec");
78  } else if (Triple.getArch() == Triple::ppc64) {
79  // powerpc64-apple-*
80  AddFeature("64bit");
81  AddFeature("altivec");
82  }
83  }
84 }
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:506
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
T
StringRef.h
llvm::SubtargetFeatures::AddFeature
void AddFeature(StringRef String, bool Enable=true)
Adds Features.
Definition: SubtargetFeature.cpp:41
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::Triple::ppc
@ ppc
Definition: Triple.h:67
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
SubtargetFeature.h
llvm::SubtargetFeatures::Split
static void Split(std::vector< std::string > &V, StringRef S)
Splits a string of comma separated items in to a vector of strings.
Definition: SubtargetFeature.cpp:33
llvm::Triple::ppc64
@ ppc64
Definition: Triple.h:69
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::Triple::getArch
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:310
llvm::SubtargetFeatures::getDefaultSubtargetFeatures
void getDefaultSubtargetFeatures(const Triple &Triple)
Adds the default features for the specified target triple.
Definition: SubtargetFeature.cpp:70
llvm::SubtargetFeatures::SubtargetFeatures
SubtargetFeatures(StringRef Initial="")
Definition: SubtargetFeature.cpp:49
llvm::SubtargetFeatures::getString
std::string getString() const
Returns features as a string.
Definition: SubtargetFeature.cpp:54
StringExtras.h
Enable
@ Enable
Definition: DwarfDebug.cpp:88
llvm::SubtargetFeatures::dump
void dump() const
Definition: SubtargetFeature.cpp:65
Triple.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
Compiler.h
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::SubtargetFeatures::hasFlag
static bool hasFlag(StringRef Feature)
Determine if a feature has a flag; '+' or '-'.
Definition: SubtargetFeature.h:208
llvm::SubtargetFeatures::print
void print(raw_ostream &OS) const
Prints feature string.
Definition: SubtargetFeature.cpp:58
SmallVector.h
llvm::Triple::getVendor
VendorType getVendor() const
Get the parsed vendor type of this triple.
Definition: Triple.h:316
raw_ostream.h
Debug.h
llvm::Triple::Apple
@ Apple
Definition: Triple.h:151