[PATCH] D33939: Make memory operands for MIs resulting from Memcpy/Memset on SystemZ

Jonas Paulsson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 6 06:56:56 PDT 2017


jonpa created this revision.

On SystemZ, memory operands on the MIs that result from lowering of Memcpy (Memset is handled in a similar way) are currently missing.

I wanted to use the MachinePointerInfos passed to EmitTargetCodeForMemcpy(), but I did not find a simple way to just add them as an operand when calling DAG.getNode(). I therefore instead thought that since the achinePointerInfo is basically just a a Value and an offset, it might be good enough to just extract them
and reconstruct them during Pseudo Expansion.

It would of course have been nicer and cleaner to build SDNodes for these memory operands instead instead of extracting after isel. I however don't see any support for this... It seems MemSDNode has just one MachineMemOperand* as a protected member, so memcpy isn't supported with it, or? And there is no SDNode that would wrap a MachineMemOperand...

Is there any better way of doing this than per this patch? (I.e. making the memory operands in EmitTargetCodeForMemcpy() instead and passing them on through isel, to avoid the extraction).

Also, are these memory operands correct with just a load/store flag set?


https://reviews.llvm.org/D33939

Files:
  lib/Target/SystemZ/SystemZISelLowering.cpp


Index: lib/Target/SystemZ/SystemZISelLowering.cpp
===================================================================
--- lib/Target/SystemZ/SystemZISelLowering.cpp
+++ lib/Target/SystemZ/SystemZISelLowering.cpp
@@ -5805,6 +5805,39 @@
   return MBB;
 }
 
+static MachinePointerInfo getMachinePointerInfo(MachineInstr *MI,
+                                                unsigned BaseOpNo,
+                                                MachineRegisterInfo &MRI) {
+  MachineFunction *MF = MI->getParent()->getParent();
+  MachineOperand *BaseMO = &MI->getOperand(BaseOpNo);
+  unsigned Displ         = MI->getOperand(BaseOpNo + 1).getImm();
+  if (BaseMO->isReg()) {
+    MachineInstr *AddrDefMI = MRI.getVRegDef(BaseMO->getReg());
+    if (AddrDefMI != nullptr) {
+      if (AddrDefMI->getOpcode() == SystemZ::LARL &&
+          AddrDefMI->getOperand(1).isGlobal())
+        return MachinePointerInfo(AddrDefMI->getOperand(1).getGlobal(),
+                                  Displ);
+      if ((AddrDefMI->getOpcode() == SystemZ::LA ||
+           AddrDefMI->getOpcode() == SystemZ::LAY) &&
+          AddrDefMI->getOperand(1).isFI() &&
+          AddrDefMI->getOperand(3).getReg() == SystemZ::NoRegister) {
+        Displ += AddrDefMI->getOperand(2).getImm();
+        BaseMO = &AddrDefMI->getOperand(1);
+      }
+    }
+  }
+
+  if (BaseMO->isFI()) {
+    MachinePointerInfo MPtrI =
+      MachinePointerInfo::getFixedStack(*MF, BaseMO->getIndex());
+    MPtrI.Offset = Displ;
+    return MPtrI;
+  }
+
+  return MachinePointerInfo();
+}
+
 MachineBasicBlock *SystemZTargetLowering::emitMemMemWrapper(
     MachineInstr &MI, MachineBasicBlock *MBB, unsigned Opcode) const {
   MachineFunction &MF = *MBB->getParent();
@@ -5947,13 +5980,29 @@
       SrcBase = MachineOperand::CreateReg(Reg, false);
       SrcDisp = 0;
     }
+    MachineInstr *BuiltMI =
     BuildMI(*MBB, MI, DL, TII->get(Opcode))
         .add(DestBase)
         .addImm(DestDisp)
         .addImm(ThisLength)
         .add(SrcBase)
-        .addImm(SrcDisp)
-        ->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
+        .addImm(SrcDisp);
+    if (!MI.memoperands_empty())
+      BuiltMI->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
+    else {
+      uint64_t Size = MI.getOperand(4).getImm();
+      MachinePointerInfo SrcPtrInfo = getMachinePointerInfo(&MI, 2, MRI);
+      if (!SrcPtrInfo.V.isNull())
+        BuiltMI->addMemOperand(MF, MF.getMachineMemOperand(SrcPtrInfo,
+                               MachineMemOperand::MOLoad, Size, 1));
+      if (Opcode != SystemZ::CLC) {
+        MachinePointerInfo DstPtrInfo = getMachinePointerInfo(&MI, 0, MRI);
+        if (!DstPtrInfo.V.isNull())
+          BuiltMI->addMemOperand(MF, MF.getMachineMemOperand(DstPtrInfo,
+                                 MachineMemOperand::MOStore, Size, 1));
+      }
+    }
+
     DestDisp += ThisLength;
     SrcDisp += ThisLength;
     Length -= ThisLength;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33939.101554.patch
Type: text/x-patch
Size: 2952 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170606/e1b18bab/attachment.bin>


More information about the llvm-commits mailing list