[llvm] [GlobalISel] Refactor Combiner MatchData & Apply C++ Code Handling (PR #92239)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu May 16 01:27:37 PDT 2024
================
@@ -1780,6 +1811,44 @@ bool CombineRuleBuilder::emitApplyPatterns(CodeExpansions &CE, RuleMatcher &M) {
return true;
}
+bool CombineRuleBuilder::emitCXXMatchApply(CodeExpansions &CE, RuleMatcher &M,
+ ArrayRef<CXXPattern *> Matchers) {
+ assert(hasOnlyCXXApplyPatterns());
+ declareAllMatchDatasExpansions(CE);
+
+ std::string CodeStr;
+ raw_string_ostream OS(CodeStr);
+
+ for (auto &MD : MatchDatas)
+ OS << MD.Type << " " << MD.getVarName() << ";\n";
+
+ if (!Matchers.empty()) {
+ OS << "// Match Patterns\n";
+ for (auto *M : Matchers) {
+ OS << "if(![&](){";
+ CodeExpander Expander(M->getRawCode(), CE, RuleDef.getLoc(),
+ /*ShowExpansions*/ false);
+ Expander.emit(OS);
+ OS << "}()) {\n"
+ << " return false;\n}\n";
+ }
+ }
+
+ OS << "// Apply Patterns\n";
+ ListSeparator LS("\n");
+ for (auto &Pat : ApplyPats) {
+ auto *CXXPat = cast<CXXPattern>(Pat.second.get());
+ CodeExpander Expander(CXXPat->getRawCode(), CE, RuleDef.getLoc(),
+ /*ShowExpansions*/ false);
----------------
arsenm wrote:
```suggestion
/*ShowExpansions=*/ false);
```
https://github.com/llvm/llvm-project/pull/92239
More information about the llvm-commits
mailing list