Split MatchDataInfo, CXXPredicates and the Pattern hierarchy into their own files. This should help with maintenance a bit, and make the API easier to navigate. I hope this encourages a bit more experimentation with MIR patterns, e.g. I'd like to try getting them in ISel at some point. Currently, this is pretty much only moving code around. There is no significant refactoring in there. I want to split the Combiner backend even more at some point though, e.g. by separating the TableGen parsing logic into yet another file so other backends could very easily parse patterns themselves. Note: I moved the responsibility of managing string lifetimes into the backend instead of the Pattern class. e.g. Before you'd do `P.addOperand(Name)` but now it's `P.addOperand(insertStrRef(Name))`. I verified this was done correctly by running the tests with UBSan/ASan.
52 lines
1.8 KiB
C++
52 lines
1.8 KiB
C++
//===- CXXPredicates.cpp ----------------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "CXXPredicates.h"
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
namespace llvm {
|
|
namespace gi {
|
|
|
|
std::vector<const CXXPredicateCode *>
|
|
CXXPredicateCode::getSorted(const CXXPredicateCodePool &Pool) {
|
|
std::vector<const CXXPredicateCode *> Out;
|
|
std::transform(Pool.begin(), Pool.end(), std::back_inserter(Out),
|
|
[&](auto &Elt) { return Elt.second.get(); });
|
|
sort(Out, [](const auto *A, const auto *B) { return A->ID < B->ID; });
|
|
return Out;
|
|
}
|
|
|
|
const CXXPredicateCode &CXXPredicateCode::get(CXXPredicateCodePool &Pool,
|
|
std::string Code) {
|
|
// Check if we already have an identical piece of code, if not, create an
|
|
// entry in the pool.
|
|
const auto CodeHash = hash_value(Code);
|
|
if (auto It = Pool.find(CodeHash); It != Pool.end())
|
|
return *It->second;
|
|
|
|
const auto ID = Pool.size();
|
|
auto OwnedData = std::unique_ptr<CXXPredicateCode>(
|
|
new CXXPredicateCode(std::move(Code), ID));
|
|
const auto &DataRef = *OwnedData;
|
|
Pool[CodeHash] = std::move(OwnedData);
|
|
return DataRef;
|
|
}
|
|
|
|
// TODO: Make BaseEnumName prefix configurable.
|
|
CXXPredicateCode::CXXPredicateCode(std::string Code, unsigned ID)
|
|
: Code(Code), ID(ID), BaseEnumName("GICombiner" + std::to_string(ID)) {}
|
|
|
|
CXXPredicateCode::CXXPredicateCodePool CXXPredicateCode::AllCXXMatchCode;
|
|
CXXPredicateCode::CXXPredicateCodePool CXXPredicateCode::AllCXXApplyCode;
|
|
|
|
} // namespace gi
|
|
} // namespace llvm
|