[llvm] [GlobalISel] Support physical register inputs in nested patterns (PR #121239)

Evgenii Kudriashov via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 1 17:07:45 PST 2025


================
@@ -1412,15 +1412,18 @@ Expected<BuildMIAction &> GlobalISelEmitter::createAndImportInstructionRenderer(
   action_iterator InsertPt = InsertPtOrError.get();
   BuildMIAction &DstMIBuilder = *static_cast<BuildMIAction *>(InsertPt->get());
 
-  for (auto PhysInput : InsnMatcher.getPhysRegInputs()) {
-    InsertPt = M.insertAction<BuildMIAction>(
-        InsertPt, M.allocateOutputInsnID(),
-        &Target.getInstruction(RK.getDef("COPY")));
-    BuildMIAction &CopyToPhysRegMIBuilder =
-        *static_cast<BuildMIAction *>(InsertPt->get());
-    CopyToPhysRegMIBuilder.addRenderer<AddRegisterRenderer>(
-        Target, PhysInput.first, true);
-    CopyToPhysRegMIBuilder.addRenderer<CopyPhysRegRenderer>(PhysInput.first);
+  for (auto PhysOp : M.physoperands()) {
+    auto &OpInsnMatcher = PhysOp.second->getInstructionMatcher();
+    for (auto PhysInput : OpInsnMatcher.getPhysRegInputs()) {
+      InsertPt = M.insertAction<BuildMIAction>(
+          InsertPt, M.allocateOutputInsnID(),
+          &Target.getInstruction(RK.getDef("COPY")));
+      BuildMIAction &CopyToPhysRegMIBuilder =
+          *static_cast<BuildMIAction *>(InsertPt->get());
+      CopyToPhysRegMIBuilder.addRenderer<AddRegisterRenderer>(
+          Target, PhysInput.first, true);
+      CopyToPhysRegMIBuilder.addRenderer<CopyPhysRegRenderer>(PhysInput.first);
----------------
e-kud wrote:

It looks like it has more usages than debugging purposes. Physregs aren't added to `DefinedOperands` so we can't reuse `CopyRenderer`  as is.
https://github.com/llvm/llvm-project/blob/cd239493c1023cbccfe6b1e9be32e68592a7f304/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp#L1887-L1904

However when traversing `PhysRegOperands` we do have `OperandMatcher`s so we can ignore accessing `getPhysRegOperandMatcher` but still some changes/refactor are required in `CopyRenderer` to make it aware that `OperandMatcher` has been passed e.g., in constructor.


https://github.com/llvm/llvm-project/pull/121239


More information about the llvm-commits mailing list