[PATCH] D133257: [GISel] Fix match tree emitter.
Kai Nacke via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 3 09:24:12 PDT 2022
Kai created this revision.
Kai added reviewers: dsanders, aemerson, arsenm.
Herald added a project: All.
Kai requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
The following changes are necessary to get the generated tree matcher to compile:
- In `CodeExpansions::declare()`, the `assert()` prevents connecting two instructions. E.g. the match code `(match (MUL $t, $s1, $s2), (SUB $d, $t, $s3)),` results in two declarations of `$t,` one for the def and one for the use. Removing the assertion allows this construct. If `$t` is later used, it is one of the operands, which should be perfectly fine for now.
- The code emitted in `GIMatchTreeVRegDefPartitioner::generatePartitionSelectorCode()` is not compilable:
- The value of `NewInstrID` should be emitted, not the name
- Both calls involving `getOperand()` end with one parenthesis too many
With these changes, compilable code is emitted for the `TableGen/GICombinerEmitter/match-tree.td` test.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133257
Files:
llvm/utils/TableGen/GlobalISel/CodeExpansions.h
llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
Index: llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
===================================================================
--- llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
+++ llvm/utils/TableGen/GlobalISel/GIMatchTree.cpp
@@ -762,13 +762,14 @@
void GIMatchTreeVRegDefPartitioner::generatePartitionSelectorCode(
raw_ostream &OS, StringRef Indent) const {
- OS << Indent << "Partition = -1\n"
- << Indent << "if (MIs.size() <= NewInstrID) MIs.resize(NewInstrID + 1);\n"
+ OS << Indent << "Partition = -1;\n"
+ << Indent << "if (MIs.size() <= " << NewInstrID << ") MIs.resize("
+ << (NewInstrID + 1) << ");\n"
<< Indent << "MIs[" << NewInstrID << "] = nullptr;\n"
- << Indent << "if (MIs[" << InstrID << "].getOperand(" << OpIdx
- << ").isReg()))\n"
+ << Indent << "if (MIs[" << InstrID << "]->getOperand(" << OpIdx
+ << ").isReg())\n"
<< Indent << " MIs[" << NewInstrID << "] = MRI.getVRegDef(MIs[" << InstrID
- << "].getOperand(" << OpIdx << ").getReg()));\n";
+ << "]->getOperand(" << OpIdx << ").getReg());\n";
for (const auto &Pair : ResultToPartition)
OS << Indent << "if (MIs[" << NewInstrID << "] "
Index: llvm/utils/TableGen/GlobalISel/CodeExpansions.h
===================================================================
--- llvm/utils/TableGen/GlobalISel/CodeExpansions.h
+++ llvm/utils/TableGen/GlobalISel/CodeExpansions.h
@@ -25,7 +25,8 @@
public:
void declare(StringRef Name, StringRef Expansion) {
bool Inserted = Expansions.try_emplace(Name, Expansion).second;
- assert(Inserted && "Declared variable twice");
+ // Duplicates are not inserted. The expansion refers to different operands
+ // but to the same virtual register.
(void)Inserted;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133257.457799.patch
Type: text/x-patch
Size: 1755 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220903/edaf9026/attachment.bin>
More information about the llvm-commits
mailing list