1 //===- CXXPredicates.cpp ----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 //===----------------------------------------------------------------------===//
12 #include "CXXPredicates.h"
13 #include "llvm/ADT/STLExtras.h"
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
; });
27 const CXXPredicateCode
&CXXPredicateCode::get(CXXPredicateCodePool
&Pool
,
29 // Check if we already have an identical piece of code, if not, create an
31 const auto CodeHash
= hash_value(Code
);
32 if (auto It
= Pool
.find(CodeHash
); It
!= Pool
.end())
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
);
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
;