Path: blob/main/contrib/llvm-project/llvm/utils/TableGen/Common/GlobalISel/CXXPredicates.h
35315 views
//===- CXXPredicates.h ------------------------------------------*- 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/// \file Contains utilities related to handling C++ code in MIR patterns for9/// GlobalISel. C++ predicates need to be expanded, and then stored in a10/// static pool until they can be emitted.11//12//===----------------------------------------------------------------------===//1314#ifndef LLVM_UTILS_MIRPATTERNS_CXXPREDICATES_H15#define LLVM_UTILS_MIRPATTERNS_CXXPREDICATES_H1617#include "llvm/ADT/DenseMap.h"18#include "llvm/ADT/Hashing.h"19#include "llvm/ADT/StringRef.h"20#include <memory>21#include <string>22#include <vector>2324namespace llvm {25namespace gi {2627/// Entry into the static pool of all CXX Predicate code. This contains28/// fully expanded C++ code.29///30/// The static pool is hidden inside the object and can be accessed through31/// getAllMatchCode/getAllApplyCode32///33/// Note that CXXPattern trims C++ code, so the Code is already expected to be34/// free of leading/trailing whitespace.35class CXXPredicateCode {36using CXXPredicateCodePool =37DenseMap<hash_code, std::unique_ptr<CXXPredicateCode>>;38static CXXPredicateCodePool AllCXXMatchCode;39static CXXPredicateCodePool AllCXXCustomActionCode;4041/// Sorts a `CXXPredicateCodePool` by their IDs and returns it.42static std::vector<const CXXPredicateCode *>43getSorted(const CXXPredicateCodePool &Pool);4445/// Gets an instance of `CXXPredicateCode` for \p Code, or returns an already46/// existing one.47static const CXXPredicateCode &get(CXXPredicateCodePool &Pool,48std::string Code);4950CXXPredicateCode(std::string Code, unsigned ID);5152public:53static const CXXPredicateCode &getMatchCode(std::string Code) {54return get(AllCXXMatchCode, std::move(Code));55}5657static const CXXPredicateCode &getCustomActionCode(std::string Code) {58return get(AllCXXCustomActionCode, std::move(Code));59}6061static std::vector<const CXXPredicateCode *> getAllMatchCode() {62return getSorted(AllCXXMatchCode);63}6465static std::vector<const CXXPredicateCode *> getAllCustomActionsCode() {66return getSorted(AllCXXCustomActionCode);67}6869const std::string Code;70const unsigned ID;71const std::string BaseEnumName;7273bool needsUnreachable() const {74return !StringRef(Code).starts_with("return");75}7677std::string getEnumNameWithPrefix(StringRef Prefix) const {78return Prefix.str() + BaseEnumName;79}80};8182} // namespace gi83} // end namespace llvm8485#endif // ifndef LLVM_UTILS_MIRPATTERNS_CXXPREDICATES_H868788