[llvm] r340680 - [CodeGen] Set FrameSetup/FrameDestroy on BUNDLE instructions

Bjorn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 25 04:26:17 PDT 2018


Author: bjope
Date: Sat Aug 25 04:26:17 2018
New Revision: 340680

URL: http://llvm.org/viewvc/llvm-project?rev=340680&view=rev
Log:
[CodeGen] Set FrameSetup/FrameDestroy on BUNDLE instructions

Summary:
If any of the bundled instructions are marked as FrameSetup
or FrameDestroy, then that property is set on the BUNDLE
instruction as well.

As long as the scheduler/packetizer aren't mixing
prologue/epilogue instructions (i.e. all the bundled
instructions have the same property) then this simply gives
the bundle the correct property (so when using a bundle
iterator in late passes a bundle will be correctly identified
as FrameSetup/FrameDestroy).

When for example bundling a mix of FrameSetup instructions
with non-FrameSetup instructions it could be discussed if
the bundle should have the property or not. The choice here
has been to set these properties on the BUNDLE instruction if
any of the bundled instructions have the property set.

Reviewers: #debug-info, kparzysz

Reviewed By: kparzysz

Subscribers: vsk, thegameg, llvm-commits

Differential Revision: https://reviews.llvm.org/D50637

Added:
    llvm/trunk/test/CodeGen/Hexagon/packetize-frame-setup-destroy.mir
Modified:
    llvm/trunk/lib/CodeGen/MachineInstrBundle.cpp

Modified: llvm/trunk/lib/CodeGen/MachineInstrBundle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstrBundle.cpp?rev=340680&r1=340679&r2=340680&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineInstrBundle.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineInstrBundle.cpp Sat Aug 25 04:26:17 2018
@@ -145,9 +145,9 @@ void llvm::finalizeBundle(MachineBasicBl
   SmallSet<unsigned, 8> KilledUseSet;
   SmallSet<unsigned, 8> UndefUseSet;
   SmallVector<MachineOperand*, 4> Defs;
-  for (; FirstMI != LastMI; ++FirstMI) {
-    for (unsigned i = 0, e = FirstMI->getNumOperands(); i != e; ++i) {
-      MachineOperand &MO = FirstMI->getOperand(i);
+  for (auto MII = FirstMI; MII != LastMI; ++MII) {
+    for (unsigned i = 0, e = MII->getNumOperands(); i != e; ++i) {
+      MachineOperand &MO = MII->getOperand(i);
       if (!MO.isReg())
         continue;
       if (MO.isDef()) {
@@ -225,6 +225,15 @@ void llvm::finalizeBundle(MachineBasicBl
     MIB.addReg(Reg, getKillRegState(isKill) | getUndefRegState(isUndef) |
                getImplRegState(true));
   }
+
+  // Set FrameSetup/FrameDestroy for the bundle. If any of the instructions got
+  // the property, then also set it on the bundle.
+  for (auto MII = FirstMI; MII != LastMI; ++MII) {
+    if (MII->getFlag(MachineInstr::FrameSetup))
+      MIB.setMIFlag(MachineInstr::FrameSetup);
+    if (MII->getFlag(MachineInstr::FrameDestroy))
+      MIB.setMIFlag(MachineInstr::FrameDestroy);
+  }
 }
 
 /// finalizeBundle - Same functionality as the previous finalizeBundle except

Added: llvm/trunk/test/CodeGen/Hexagon/packetize-frame-setup-destroy.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Hexagon/packetize-frame-setup-destroy.mir?rev=340680&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Hexagon/packetize-frame-setup-destroy.mir (added)
+++ llvm/trunk/test/CodeGen/Hexagon/packetize-frame-setup-destroy.mir Sat Aug 25 04:26:17 2018
@@ -0,0 +1,62 @@
+# RUN: llc -march=hexagon -run-pass hexagon-packetizer %s -o - | FileCheck %s
+
+##############################################################################
+# This test case is not really hexagon specific, but we use hexagon to get
+# bundling.
+#
+# The goal is to verify that the BUNDLE instruction is getting the
+# frame-setup/frame-destroy attribute if any of the bundled instructions got
+# the attribute.
+##############################################################################
+
+---
+name: setup
+tracksRegLiveness: true
+body: |
+  bb.0:
+    liveins: $r1, $r2
+    successors: %bb.1
+    $r3 = frame-setup L2_loadri_io $r1, 0
+    J4_cmpgtu_f_jumpnv_t killed $r3, killed $r2, %bb.1, implicit-def $pc
+
+  bb.1:
+...
+
+# CHECK-LABEL: name: setup
+# CHECK: frame-setup BUNDLE
+
+##############################################################################
+
+---
+name: destroy
+tracksRegLiveness: true
+body: |
+  bb.0:
+    liveins: $r1, $r2
+    successors: %bb.1
+    $r3 = frame-destroy L2_loadri_io $r1, 0
+    J4_cmpgtu_f_jumpnv_t killed $r3, killed $r2, %bb.1, implicit-def $pc
+
+  bb.1:
+...
+
+# CHECK-LABEL: name: destroy
+# CHECK: frame-destroy BUNDLE
+
+##############################################################################
+
+---
+name: mixed
+tracksRegLiveness: true
+body: |
+  bb.0:
+    liveins: $r1, $r2
+    successors: %bb.1
+    $r3 = frame-setup L2_loadri_io $r1, 0
+    frame-destroy J4_cmpgtu_f_jumpnv_t killed $r3, killed $r2, %bb.1, implicit-def $pc
+
+  bb.1:
+...
+
+# CHECK-LABEL: name: mixed
+# CHECK: frame-setup frame-destroy BUNDLE




More information about the llvm-commits mailing list