• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- subzero/src/IceRangeSpec.h - Include/exclude specs -------*- C++ -*-===//
2 //
3 //                        The Subzero Code Generator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief Declares a class for specifying inclusion/exclusion of values, such
12 /// as functions to match.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef SUBZERO_SRC_ICERANGESPEC_H
17 #define SUBZERO_SRC_ICERANGESPEC_H
18 
19 #include "IceStringPool.h"
20 
21 #include <string>
22 #include <unordered_set>
23 #include <vector>
24 
25 #include "llvm/ADT/BitVector.h"
26 
27 namespace Ice {
28 
29 class RangeSpec {
30   RangeSpec(const RangeSpec &) = delete;
31   RangeSpec &operator=(const RangeSpec &) = delete;
32 
33 public:
34   static constexpr char DELIM_LIST = ',';
35   static constexpr char DELIM_RANGE = ':';
36   static constexpr uint32_t RangeMax = std::numeric_limits<uint32_t>::max();
37   RangeSpec() = default;
38   struct Desc {
39     // Set of names explicitly provided.
40     std::unordered_set<std::string> Names;
41     // Set of numbers explicitly provided.
42     llvm::BitVector Numbers;
43     // The smallest X for which the open-ended interval "X:" was provided.  This
44     // is needed because the intervals are parsed before we know the largest
45     // number that might be matched against, and we can't make the Numbers
46     // bitvector infinitely long.
47     uint32_t AllFrom = RangeMax;
48     // Whether a clause was explicitly provided.
49     bool IsExplicit = false;
50   };
51   void init(const std::string &Spec);
52   bool match(const std::string &Name, uint32_t Number) const;
match(GlobalString Name,uint32_t Number)53   bool match(GlobalString Name, uint32_t Number) const {
54     return match(Name.toStringOrEmpty(), Number);
55   }
56   // Returns true if any RangeSpec object has had init() called with an explicit
57   // name rather than (or in addition to) a numeric range.  If so, we want to
58   // construct explicit names for functions even in a non-DUMP build so that
59   // matching on function name works correctly.  Note that this is not
60   // thread-safe, so we count on all this being handled by the startup thread.
hasNames()61   static bool hasNames() { return HasNames; }
62   // Helper function to tokenize a string into a vector of string tokens, given
63   // a single delimiter character.  An empty string produces an empty token
64   // vector.  Zero-length tokens are allowed, e.g. ",a,,,b," may tokenize to
65   // {"","a","","","b",""}.
66   static std::vector<std::string> tokenize(const std::string &Spec,
67                                            char Delimiter);
68 
69 private:
70   void include(const std::string &Token);
71   void exclude(const std::string &Token);
72   Desc Includes;
73   Desc Excludes;
74   static bool HasNames;
75 };
76 
77 } // end of namespace Ice
78 
79 #endif // SUBZERO_SRC_ICERANGESPEC_H
80