[PATCH] D132663: [NVPTX] Use MBB.begin() instead MBB.front() in NVPTXFrameLowering::emitPrologue

Shivam Gupta via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 25 07:59:56 PDT 2022


xgupta created this revision.
xgupta added reviewers: tianshilei1992, tra.
Herald added subscribers: mattd, gchakrabarti, asavonic, hiraditya.
Herald added a project: All.
xgupta requested review of this revision.
Herald added subscribers: llvm-commits, jholewinski.
Herald added a project: LLVM.

The second argument of `NVPTXFrameLowering::emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB)` is the first MBB of the MF. In that function, it assumes the first MBB always contains instructions, so it gets the first instruction by MachineInstr *MI = &MBB.front();. However, with the reproducer/test case attached, all instructions in the first MBB is cleared in a previous pass for stack coloring. As a consequence, MBB.front() triggers the assertion that the first node is actually a sentinel node. Hence we are using MachineBasicBlock::iterator to iterate over MBB.

Fix #52623.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132663

Files:
  llvm/lib/Target/NVPTX/NVPTXFrameLowering.cpp


Index: llvm/lib/Target/NVPTX/NVPTXFrameLowering.cpp
===================================================================
--- llvm/lib/Target/NVPTX/NVPTXFrameLowering.cpp
+++ llvm/lib/Target/NVPTX/NVPTXFrameLowering.cpp
@@ -33,7 +33,7 @@
                                       MachineBasicBlock &MBB) const {
   if (MF.getFrameInfo().hasStackObjects()) {
     assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
-    MachineInstr *MI = &MBB.front();
+    MachineBasicBlock::iterator MBBI = MBB.begin();
     MachineRegisterInfo &MR = MF.getRegInfo();
 
     const NVPTXRegisterInfo *NRI =
@@ -55,12 +55,12 @@
         (Is64Bit ? NVPTX::MOV_DEPOT_ADDR_64 : NVPTX::MOV_DEPOT_ADDR);
     if (!MR.use_empty(NRI->getFrameRegister(MF))) {
       // If %SP is not used, do not bother emitting "cvta.local %SP, %SPL".
-      MI = BuildMI(MBB, MI, dl,
+      MBBI = BuildMI(MBB, MBBI, dl,
                    MF.getSubtarget().getInstrInfo()->get(CvtaLocalOpcode),
                    NRI->getFrameRegister(MF))
                .addReg(NRI->getFrameLocalRegister(MF));
     }
-    BuildMI(MBB, MI, dl, MF.getSubtarget().getInstrInfo()->get(MovDepotOpcode),
+    BuildMI(MBB, MBBI, dl, MF.getSubtarget().getInstrInfo()->get(MovDepotOpcode),
             NRI->getFrameLocalRegister(MF))
         .addImm(MF.getFunctionNumber());
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132663.455584.patch
Type: text/x-patch
Size: 1337 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220825/bbb3e4b0/attachment.bin>


More information about the llvm-commits mailing list