[llvm] 53d8858 - llvm-reduce: Clone properties of blocks

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 20 06:47:50 PDT 2022


Author: Matt Arsenault
Date: 2022-04-20T09:47:45-04:00
New Revision: 53d88581f155631a61923541fb88c9c696282070

URL: https://github.com/llvm/llvm-project/commit/53d88581f155631a61923541fb88c9c696282070
DIFF: https://github.com/llvm/llvm-project/commit/53d88581f155631a61923541fb88c9c696282070.diff

LOG: llvm-reduce: Clone properties of blocks

getSuccProbability was private for some reason, saying to go through
MachineBranchProbabilityInfo. There doesn't seem to be much point to
that, as that wrapper directly calls this.

Like other areas, some of these fields aren't handled by the MIR
printer/parser so aren't tested.

Added: 
    llvm/test/tools/llvm-reduce/mir/preserve-block-info.mir

Modified: 
    llvm/include/llvm/CodeGen/MachineBasicBlock.h
    llvm/tools/llvm-reduce/ReducerWorkItem.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
index 7d9a9ac505fa3..23305b5117c03 100644
--- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
@@ -1086,6 +1086,11 @@ class MachineBasicBlock
     IrrLoopHeaderWeight = Weight;
   }
 
+  /// Return probability of the edge from this block to MBB. This method should
+  /// NOT be called directly, but by using getEdgeProbability method from
+  /// MachineBranchProbabilityInfo class.
+  BranchProbability getSuccProbability(const_succ_iterator Succ) const;
+
 private:
   /// Return probability iterator corresponding to the I successor iterator.
   probability_iterator getProbabilityIterator(succ_iterator I);
@@ -1095,11 +1100,6 @@ class MachineBasicBlock
   friend class MachineBranchProbabilityInfo;
   friend class MIPrinter;
 
-  /// Return probability of the edge from this block to MBB. This method should
-  /// NOT be called directly, but by using getEdgeProbability method from
-  /// MachineBranchProbabilityInfo class.
-  BranchProbability getSuccProbability(const_succ_iterator Succ) const;
-
   // Methods used to maintain doubly linked list of blocks...
   friend struct ilist_callback_traits<MachineBasicBlock>;
 

diff  --git a/llvm/test/tools/llvm-reduce/mir/preserve-block-info.mir b/llvm/test/tools/llvm-reduce/mir/preserve-block-info.mir
new file mode 100644
index 0000000000000..f20ebd5dec5b5
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/mir/preserve-block-info.mir
@@ -0,0 +1,72 @@
+# REQUIRES: amdgpu-registered-target
+# RUN: llvm-reduce -simplify-mir -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg --check-prefix=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t 2> %t.log
+# RUN: FileCheck --match-full-lines --check-prefix=RESULT %s < %t
+
+# CHECK-INTERESTINGNESS: V_MOV_B32
+
+
+# RESULT: bb.0.entry:
+# RESULT: %{{[0-9]+}}:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
+
+# RESULT: bb.1 (address-taken, align 8):
+# RESULT: bb.2 (landing-pad, align 16):
+# RESULT: bb.3 (inlineasm-br-indirect-target):
+# RESULT: bb.4 (ehfunclet-entry):
+# RESULT: bb.5 (bbsections 1):
+# RESULT: bb.6 (bbsections 2):
+# RESULT: bb.7 (bbsections 3):
+# RESULT: bb.8:
+# RESULT-NEXT: successors: %bb.9(0x66666666), %bb.10(0x1999999a)
+# RESULT: bb.9:
+# RESULT: bb.10.exitblock:
+
+--- |
+  define void @func(i32 %size)  {
+  entry:
+    br label %exitblock
+
+  exitblock:
+    ret void
+  }
+
+...
+
+---
+name: func
+alignment:       32
+exposesReturnsTwice: true
+legalized:       true
+regBankSelected: true
+selected:        true
+failedISel:      true
+tracksRegLiveness: true
+hasWinCFI:       true
+failsVerification: true
+tracksDebugUserValues: true
+body:             |
+  bb.0.entry:
+    S_NOP 0
+    %0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
+
+  bb.1 (address-taken, align 8):
+
+  bb.2 (landing-pad, align 16):
+
+  bb.3 (inlineasm-br-indirect-target):
+
+  bb.4 (ehfunclet-entry):
+
+  bb.5 (bbsections 1):
+  bb.6 (bbsections 2):
+  bb.7 (bbsections 3):
+
+  bb.8:
+    successors: %bb.9(4), %bb.10(1)
+    S_CBRANCH_SCC1 %bb.10, implicit undef $scc
+    S_BRANCH %bb.9
+
+  bb.9:
+
+  bb.10.exitblock:
+    S_ENDPGM 0, implicit %0
+...

diff  --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
index 75fef698a3b8c..e12e81134cac2 100644
--- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
+++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
@@ -125,8 +125,41 @@ static std::unique_ptr<MachineFunction> cloneMF(MachineFunction *SrcMF) {
   auto *DstMRI = &DstMF->getRegInfo();
 
   // Clone blocks.
-  for (MachineBasicBlock &SrcMBB : *SrcMF)
-    Src2DstMBB[&SrcMBB] = DstMF->CreateMachineBasicBlock();
+  for (MachineBasicBlock &SrcMBB : *SrcMF) {
+    MachineBasicBlock *DstMBB =
+        DstMF->CreateMachineBasicBlock(SrcMBB.getBasicBlock());
+    Src2DstMBB[&SrcMBB] = DstMBB;
+
+    if (SrcMBB.hasAddressTaken())
+      DstMBB->setHasAddressTaken();
+
+    // FIXME: This is not serialized
+    if (SrcMBB.hasLabelMustBeEmitted())
+      DstMBB->setLabelMustBeEmitted();
+
+    DstMBB->setAlignment(SrcMBB.getAlignment());
+
+    // FIXME: This is not serialized
+    DstMBB->setMaxBytesForAlignment(SrcMBB.getMaxBytesForAlignment());
+
+    DstMBB->setIsEHPad(SrcMBB.isEHPad());
+    DstMBB->setIsEHScopeEntry(SrcMBB.isEHScopeEntry());
+    DstMBB->setIsEHCatchretTarget(SrcMBB.isEHCatchretTarget());
+    DstMBB->setIsEHFuncletEntry(SrcMBB.isEHFuncletEntry());
+
+    // FIXME: These are not serialized
+    DstMBB->setIsCleanupFuncletEntry(SrcMBB.isCleanupFuncletEntry());
+    DstMBB->setIsBeginSection(SrcMBB.isBeginSection());
+    DstMBB->setIsEndSection(SrcMBB.isEndSection());
+
+    DstMBB->setSectionID(SrcMBB.getSectionID());
+    DstMBB->setIsInlineAsmBrIndirectTarget(
+        SrcMBB.isInlineAsmBrIndirectTarget());
+
+    // FIXME: This is not serialized
+    if (Optional<uint64_t> Weight = SrcMBB.getIrrLoopHeaderWeight())
+      DstMBB->setIrrLoopHeaderWeight(*Weight);
+  }
 
   const MachineFrameInfo &SrcMFI = SrcMF->getFrameInfo();
   MachineFrameInfo &DstMFI = DstMF->getFrameInfo();
@@ -187,25 +220,36 @@ static std::unique_ptr<MachineFunction> cloneMF(MachineFunction *SrcMF) {
     }
   }
 
+  const TargetSubtargetInfo &STI = DstMF->getSubtarget();
+  const TargetInstrInfo *TII = STI.getInstrInfo();
+  const TargetRegisterInfo *TRI = STI.getRegisterInfo();
+
   // Link blocks.
   for (auto &SrcMBB : *SrcMF) {
     auto *DstMBB = Src2DstMBB[&SrcMBB];
     DstMF->push_back(DstMBB);
+
     for (auto It = SrcMBB.succ_begin(), IterEnd = SrcMBB.succ_end();
          It != IterEnd; ++It) {
       auto *SrcSuccMBB = *It;
       auto *DstSuccMBB = Src2DstMBB[SrcSuccMBB];
-      DstMBB->addSuccessor(DstSuccMBB);
+      DstMBB->addSuccessor(DstSuccMBB, SrcMBB.getSuccProbability(It));
     }
     for (auto &LI : SrcMBB.liveins())
       DstMBB->addLiveIn(LI);
+
+    // Make sure MRI knows about registers clobbered by unwinder.
+    if (DstMBB->isEHPad()) {
+      if (auto *RegMask = TRI->getCustomEHPadPreservedMask(*DstMF))
+        DstMRI->addPhysRegsUsedFromRegMask(RegMask);
+    }
   }
+
   // Clone instructions.
   for (auto &SrcMBB : *SrcMF) {
     auto *DstMBB = Src2DstMBB[&SrcMBB];
     for (auto &SrcMI : SrcMBB) {
-      const auto &MCID =
-          DstMF->getSubtarget().getInstrInfo()->get(SrcMI.getOpcode());
+      const auto &MCID = TII->get(SrcMI.getOpcode());
       auto *DstMI = DstMF->CreateMachineInstr(MCID, SrcMI.getDebugLoc(),
                                               /*NoImplicit=*/true);
       DstMBB->push_back(DstMI);


        


More information about the llvm-commits mailing list