Coverage Report

Created: 2019-02-23 12:57

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/MC/SubtargetFeature.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/MC/SubtargetFeature.h - CPU characteristics ---------*- C++ -*-===//
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 Defines and manages user or tool specified CPU characteristics.
10
/// The intent is to be able to package specific features that should or should
11
/// not be used on a specific target processor.  A tool, such as llc, could, as
12
/// as example, gather chip info from the command line, a long with features
13
/// that should be used on that chip.
14
//
15
//===----------------------------------------------------------------------===//
16
17
#ifndef LLVM_MC_SUBTARGETFEATURE_H
18
#define LLVM_MC_SUBTARGETFEATURE_H
19
20
#include "llvm/ADT/StringRef.h"
21
#include <bitset>
22
#include <initializer_list>
23
#include <string>
24
#include <vector>
25
26
namespace llvm {
27
28
template <typename T> class ArrayRef;
29
class raw_ostream;
30
class Triple;
31
32
const unsigned MAX_SUBTARGET_FEATURES = 192;
33
/// Container class for subtarget features.
34
/// This is convenient because std::bitset does not have a constructor
35
/// with an initializer list of set bits.
36
0
class FeatureBitset : public std::bitset<MAX_SUBTARGET_FEATURES> {
37
public:
38
  // Cannot inherit constructors because it's not supported by VC++..
39
127M
  FeatureBitset() = default;
40
41
372k
  FeatureBitset(const bitset<MAX_SUBTARGET_FEATURES>& B) : bitset(B) {}
42
43
97.6M
  FeatureBitset(std::initializer_list<unsigned> Init) {
44
97.6M
    for (auto I : Init)
45
528M
      set(I);
46
97.6M
  }
47
};
48
49
//===----------------------------------------------------------------------===//
50
51
/// Used to provide key value pairs for feature and CPU bit flags.
52
struct SubtargetFeatureKV {
53
  const char *Key;                      ///< K-V key string
54
  const char *Desc;                     ///< Help descriptor
55
  unsigned Value;                       ///< K-V integer value
56
  FeatureBitset Implies;                ///< K-V bit mask
57
58
  /// Compare routine for std::lower_bound
59
5.21M
  bool operator<(StringRef S) const {
60
5.21M
    return StringRef(Key) < S;
61
5.21M
  }
62
63
  /// Compare routine for std::is_sorted.
64
0
  bool operator<(const SubtargetFeatureKV &Other) const {
65
0
    return StringRef(Key) < StringRef(Other.Key);
66
0
  }
67
};
68
69
//===----------------------------------------------------------------------===//
70
71
/// Used to provide key value pairs for CPU and arbitrary pointers.
72
struct SubtargetInfoKV {
73
  const char *Key;                      ///< K-V key string
74
  const void *Value;                    ///< K-V pointer value
75
76
  /// Compare routine for std::lower_bound
77
846k
  bool operator<(StringRef S) const {
78
846k
    return StringRef(Key) < S;
79
846k
  }
80
};
81
82
//===----------------------------------------------------------------------===//
83
84
/// Manages the enabling and disabling of subtarget specific features.
85
///
86
/// Features are encoded as a string of the form
87
///   "+attr1,+attr2,-attr3,...,+attrN"
88
/// A comma separates each feature from the next (all lowercase.)
89
/// Each of the remaining features is prefixed with + or - indicating whether
90
/// that feature should be enabled or disabled contrary to the cpu
91
/// specification.
92
class SubtargetFeatures {
93
  std::vector<std::string> Features;    ///< Subtarget features as a vector
94
95
public:
96
  explicit SubtargetFeatures(StringRef Initial = "");
97
98
  /// Returns features as a string.
99
  std::string getString() const;
100
101
  /// Adds Features.
102
  void AddFeature(StringRef String, bool Enable = true);
103
104
  /// Toggles a feature and update the feature bits.
105
  static void ToggleFeature(FeatureBitset &Bits, StringRef String,
106
                            ArrayRef<SubtargetFeatureKV> FeatureTable);
107
108
  /// Applies the feature flag and update the feature bits.
109
  static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
110
                               ArrayRef<SubtargetFeatureKV> FeatureTable);
111
112
  /// Returns feature bits of a CPU.
113
  FeatureBitset getFeatureBits(StringRef CPU,
114
                               ArrayRef<SubtargetFeatureKV> CPUTable,
115
                               ArrayRef<SubtargetFeatureKV> FeatureTable);
116
117
  /// Returns the vector of individual subtarget features.
118
7.24k
  const std::vector<std::string> &getFeatures() const { return Features; }
119
120
  /// Prints feature string.
121
  void print(raw_ostream &OS) const;
122
123
  // Dumps feature info.
124
  void dump() const;
125
126
  /// Adds the default features for the specified target triple.
127
  void getDefaultSubtargetFeatures(const Triple& Triple);
128
};
129
130
} // end namespace llvm
131
132
#endif // LLVM_MC_SUBTARGETFEATURE_H