[Frontend] Remove unused includes (NFC) (#116927)
[llvm-project.git] / llvm / utils / TableGen / Common / GlobalISel / CXXPredicates.cpp
blobcbf70278a2813bc0bd633080a8d51641852cac71
1 //===- CXXPredicates.cpp ----------------------------------------*- 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 //
10 //===----------------------------------------------------------------------===//
12 #include "CXXPredicates.h"
13 #include "llvm/ADT/STLExtras.h"
15 namespace llvm {
16 namespace gi {
18 std::vector<const CXXPredicateCode *>
19 CXXPredicateCode::getSorted(const CXXPredicateCodePool &Pool) {
20 std::vector<const CXXPredicateCode *> Out;
21 std::transform(Pool.begin(), Pool.end(), std::back_inserter(Out),
22 [&](auto &Elt) { return Elt.second.get(); });
23 sort(Out, [](const auto *A, const auto *B) { return A->ID < B->ID; });
24 return Out;
27 const CXXPredicateCode &CXXPredicateCode::get(CXXPredicateCodePool &Pool,
28 std::string Code) {
29 // Check if we already have an identical piece of code, if not, create an
30 // entry in the pool.
31 const auto CodeHash = hash_value(Code);
32 if (auto It = Pool.find(CodeHash); It != Pool.end())
33 return *It->second;
35 const auto ID = Pool.size();
36 auto OwnedData = std::unique_ptr<CXXPredicateCode>(
37 new CXXPredicateCode(std::move(Code), ID));
38 const auto &DataRef = *OwnedData;
39 Pool[CodeHash] = std::move(OwnedData);
40 return DataRef;
43 // TODO: Make BaseEnumName prefix configurable.
44 CXXPredicateCode::CXXPredicateCode(std::string Code, unsigned ID)
45 : Code(Code), ID(ID), BaseEnumName("GICombiner" + std::to_string(ID)) {}
47 CXXPredicateCode::CXXPredicateCodePool CXXPredicateCode::AllCXXMatchCode;
48 CXXPredicateCode::CXXPredicateCodePool CXXPredicateCode::AllCXXCustomActionCode;
50 } // namespace gi
51 } // namespace llvm