[Frontend] Remove unused includes (NFC) (#116927)
[llvm-project.git] / llvm / utils / TableGen / Common / GlobalISel / CXXPredicates.h
blob0cfdf702c78b13840f1aa920bdebfb13fb2aa1be
1 //===- CXXPredicates.h ------------------------------------------*- 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 Contains utilities related to handling C++ code in MIR patterns for
10 /// GlobalISel. C++ predicates need to be expanded, and then stored in a
11 /// static pool until they can be emitted.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CXXPREDICATES_H
16 #define LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CXXPREDICATES_H
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/Hashing.h"
20 #include "llvm/ADT/StringRef.h"
21 #include <memory>
22 #include <string>
23 #include <vector>
25 namespace llvm {
26 namespace gi {
28 /// Entry into the static pool of all CXX Predicate code. This contains
29 /// fully expanded C++ code.
30 ///
31 /// The static pool is hidden inside the object and can be accessed through
32 /// getAllMatchCode/getAllApplyCode
33 ///
34 /// Note that CXXPattern trims C++ code, so the Code is already expected to be
35 /// free of leading/trailing whitespace.
36 class CXXPredicateCode {
37 using CXXPredicateCodePool =
38 DenseMap<hash_code, std::unique_ptr<CXXPredicateCode>>;
39 static CXXPredicateCodePool AllCXXMatchCode;
40 static CXXPredicateCodePool AllCXXCustomActionCode;
42 /// Sorts a `CXXPredicateCodePool` by their IDs and returns it.
43 static std::vector<const CXXPredicateCode *>
44 getSorted(const CXXPredicateCodePool &Pool);
46 /// Gets an instance of `CXXPredicateCode` for \p Code, or returns an already
47 /// existing one.
48 static const CXXPredicateCode &get(CXXPredicateCodePool &Pool,
49 std::string Code);
51 CXXPredicateCode(std::string Code, unsigned ID);
53 public:
54 static const CXXPredicateCode &getMatchCode(std::string Code) {
55 return get(AllCXXMatchCode, std::move(Code));
58 static const CXXPredicateCode &getCustomActionCode(std::string Code) {
59 return get(AllCXXCustomActionCode, std::move(Code));
62 static std::vector<const CXXPredicateCode *> getAllMatchCode() {
63 return getSorted(AllCXXMatchCode);
66 static std::vector<const CXXPredicateCode *> getAllCustomActionsCode() {
67 return getSorted(AllCXXCustomActionCode);
70 const std::string Code;
71 const unsigned ID;
72 const std::string BaseEnumName;
74 bool needsUnreachable() const {
75 return !StringRef(Code).starts_with("return");
78 std::string getEnumNameWithPrefix(StringRef Prefix) const {
79 return Prefix.str() + BaseEnumName;
83 } // namespace gi
84 } // end namespace llvm
86 #endif // LLVM_UTILS_TABLEGEN_COMMON_GLOBALISEL_CXXPREDICATES_H