/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 <array> |
22 | | #include <bitset> |
23 | | #include <initializer_list> |
24 | | #include <string> |
25 | | #include <vector> |
26 | | |
27 | | namespace llvm { |
28 | | |
29 | | class raw_ostream; |
30 | | class Triple; |
31 | | |
32 | | const unsigned MAX_SUBTARGET_WORDS = 3; |
33 | | const unsigned MAX_SUBTARGET_FEATURES = MAX_SUBTARGET_WORDS * 64; |
34 | | |
35 | | /// Container class for subtarget features. |
36 | | /// This is convenient because std::bitset does not have a constructor |
37 | | /// with an initializer list of set bits. |
38 | | class FeatureBitset : public std::bitset<MAX_SUBTARGET_FEATURES> { |
39 | | public: |
40 | | // Cannot inherit constructors because it's not supported by VC++.. |
41 | 1.59G | FeatureBitset() = default; |
42 | | |
43 | 4.48G | FeatureBitset(const bitset<MAX_SUBTARGET_FEATURES>& B) : bitset(B) {} |
44 | | |
45 | 95.9M | FeatureBitset(std::initializer_list<unsigned> Init) { |
46 | 95.9M | for (auto I : Init) |
47 | 317M | set(I); |
48 | 95.9M | } |
49 | | |
50 | 0 | bool operator < (const FeatureBitset &Other) const { |
51 | 0 | for (unsigned I = 0, E = size(); I != E; ++I) { |
52 | 0 | bool LHS = test(I), RHS = Other.test(I); |
53 | 0 | if (LHS != RHS) |
54 | 0 | return LHS < RHS; |
55 | 0 | } |
56 | 0 | return false; |
57 | 0 | } |
58 | | }; |
59 | | |
60 | | /// Class used to store the subtarget bits in the tables created by tablegen. |
61 | | /// The std::initializer_list constructor of FeatureBitset can't be done at |
62 | | /// compile time and requires a static constructor to run at startup. |
63 | | class FeatureBitArray { |
64 | | std::array<uint64_t, MAX_SUBTARGET_WORDS> Bits; |
65 | | |
66 | | public: |
67 | | constexpr FeatureBitArray(const std::array<uint64_t, MAX_SUBTARGET_WORDS> &B) |
68 | 0 | : Bits(B) {} |
69 | | |
70 | 1.49G | FeatureBitset getAsBitset() const { |
71 | 1.49G | FeatureBitset Result; |
72 | 1.49G | |
73 | 5.97G | for (unsigned i = 0, e = Bits.size(); i != e; ++i4.48G ) |
74 | 4.48G | Result |= FeatureBitset(Bits[i]) << (64 * i); |
75 | 1.49G | |
76 | 1.49G | return Result; |
77 | 1.49G | } |
78 | | }; |
79 | | |
80 | | //===----------------------------------------------------------------------===// |
81 | | |
82 | | /// Manages the enabling and disabling of subtarget specific features. |
83 | | /// |
84 | | /// Features are encoded as a string of the form |
85 | | /// "+attr1,+attr2,-attr3,...,+attrN" |
86 | | /// A comma separates each feature from the next (all lowercase.) |
87 | | /// Each of the remaining features is prefixed with + or - indicating whether |
88 | | /// that feature should be enabled or disabled contrary to the cpu |
89 | | /// specification. |
90 | | class SubtargetFeatures { |
91 | | std::vector<std::string> Features; ///< Subtarget features as a vector |
92 | | |
93 | | public: |
94 | | explicit SubtargetFeatures(StringRef Initial = ""); |
95 | | |
96 | | /// Returns features as a string. |
97 | | std::string getString() const; |
98 | | |
99 | | /// Adds Features. |
100 | | void AddFeature(StringRef String, bool Enable = true); |
101 | | |
102 | | /// Returns the vector of individual subtarget features. |
103 | 207k | const std::vector<std::string> &getFeatures() const { return Features; } |
104 | | |
105 | | /// Prints feature string. |
106 | | void print(raw_ostream &OS) const; |
107 | | |
108 | | // Dumps feature info. |
109 | | void dump() const; |
110 | | |
111 | | /// Adds the default features for the specified target triple. |
112 | | void getDefaultSubtargetFeatures(const Triple& Triple); |
113 | | |
114 | | /// Determine if a feature has a flag; '+' or '-' |
115 | 875k | static bool hasFlag(StringRef Feature) { |
116 | 875k | assert(!Feature.empty() && "Empty string"); |
117 | 875k | // Get first character |
118 | 875k | char Ch = Feature[0]; |
119 | 875k | // Check if first character is '+' or '-' flag |
120 | 875k | return Ch == '+' || Ch =='-'188k ; |
121 | 875k | } |
122 | | |
123 | | /// Return string stripped of flag. |
124 | 858k | static std::string StripFlag(StringRef Feature) { |
125 | 858k | return hasFlag(Feature) ? Feature.substr(1)858k : Feature377 ; |
126 | 858k | } |
127 | | |
128 | | /// Return true if enable flag; '+'. |
129 | 858k | static inline bool isEnabled(StringRef Feature) { |
130 | 858k | assert(!Feature.empty() && "Empty string"); |
131 | 858k | // Get first character |
132 | 858k | char Ch = Feature[0]; |
133 | 858k | // Check if first character is '+' for enabled |
134 | 858k | return Ch == '+'; |
135 | 858k | } |
136 | | |
137 | | /// Splits a string of comma separated items in to a vector of strings. |
138 | | static void Split(std::vector<std::string> &V, StringRef S); |
139 | | }; |
140 | | |
141 | | } // end namespace llvm |
142 | | |
143 | | #endif // LLVM_MC_SUBTARGETFEATURE_H |