Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/MC/SubtargetFeature.cpp
Line
Count
Source (jump to first uncovered line)
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
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"
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
244k
void SubtargetFeatures::Split(std::vector<std::string> &V, StringRef S) {
34
244k
  SmallVector<StringRef, 3> Tmp;
35
244k
  S.split(Tmp, ',', -1, false /* KeepEmpty */);
36
244k
  V.assign(Tmp.begin(), Tmp.end());
37
244k
}
38
39
16.6k
void SubtargetFeatures::AddFeature(StringRef String, bool Enable) {
40
16.6k
  // Don't add empty features.
41
16.6k
  if (!String.empty())
42
16.6k
    // Convert to lowercase, prepend flag if we don't already have a flag.
43
16.6k
    Features.push_back(hasFlag(String) ? 
String.lower()15.0k
44
16.6k
                                       : 
(Enable 1.57k
?
"+"1.56k
:
"-"9
) + String.lower());
45
16.6k
}
46
47
244k
SubtargetFeatures::SubtargetFeatures(StringRef Initial) {
48
244k
  // Break up string into separate features
49
244k
  Split(Features, Initial);
50
244k
}
51
52
36.6k
std::string SubtargetFeatures::getString() const {
53
36.6k
  return join(Features.begin(), Features.end(), ",");
54
36.6k
}
55
56
0
void SubtargetFeatures::print(raw_ostream &OS) const {
57
0
  for (auto &F : Features)
58
0
    OS << F << " ";
59
0
  OS << "\n";
60
0
}
61
62
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
63
LLVM_DUMP_METHOD void SubtargetFeatures::dump() const {
64
  print(dbgs());
65
}
66
#endif
67
68
921
void SubtargetFeatures::getDefaultSubtargetFeatures(const Triple& Triple) {
69
921
  // FIXME: This is an inelegant way of specifying the features of a
70
921
  // subtarget. It would be better if we could encode this information
71
921
  // into the IR. See <rdar://5972456>.
72
921
  if (Triple.getVendor() == Triple::Apple) {
73
152
    if (Triple.getArch() == Triple::ppc) {
74
0
      // powerpc-apple-*
75
0
      AddFeature("altivec");
76
152
    } else if (Triple.getArch() == Triple::ppc64) {
77
0
      // powerpc64-apple-*
78
0
      AddFeature("64bit");
79
0
      AddFeature("altivec");
80
0
    }
81
152
  }
82
921
}