Path: blob/main/contrib/llvm-project/llvm/utils/TableGen/Common/GlobalISel/CXXPredicates.cpp
35315 views
//===- CXXPredicates.cpp ----------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8//9//===----------------------------------------------------------------------===//1011#include "CXXPredicates.h"12#include "llvm/ADT/STLExtras.h"1314namespace llvm {15namespace gi {1617std::vector<const CXXPredicateCode *>18CXXPredicateCode::getSorted(const CXXPredicateCodePool &Pool) {19std::vector<const CXXPredicateCode *> Out;20std::transform(Pool.begin(), Pool.end(), std::back_inserter(Out),21[&](auto &Elt) { return Elt.second.get(); });22sort(Out, [](const auto *A, const auto *B) { return A->ID < B->ID; });23return Out;24}2526const CXXPredicateCode &CXXPredicateCode::get(CXXPredicateCodePool &Pool,27std::string Code) {28// Check if we already have an identical piece of code, if not, create an29// entry in the pool.30const auto CodeHash = hash_value(Code);31if (auto It = Pool.find(CodeHash); It != Pool.end())32return *It->second;3334const auto ID = Pool.size();35auto OwnedData = std::unique_ptr<CXXPredicateCode>(36new CXXPredicateCode(std::move(Code), ID));37const auto &DataRef = *OwnedData;38Pool[CodeHash] = std::move(OwnedData);39return DataRef;40}4142// TODO: Make BaseEnumName prefix configurable.43CXXPredicateCode::CXXPredicateCode(std::string Code, unsigned ID)44: Code(Code), ID(ID), BaseEnumName("GICombiner" + std::to_string(ID)) {}4546CXXPredicateCode::CXXPredicateCodePool CXXPredicateCode::AllCXXMatchCode;47CXXPredicateCode::CXXPredicateCodePool CXXPredicateCode::AllCXXCustomActionCode;4849} // namespace gi50} // namespace llvm515253