[PATCH] D62617: [MIR-Canon] Fixing case where MachineFunction is empty.

Puyan Lotfi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 29 11:57:57 PDT 2019

plotfi created this revision.
Herald added subscribers: llvm-commits, hiraditya, javed.absar.
Herald added a project: LLVM.
plotfi added reviewers: compnerd, bogner.

This small change is to handle changes where a machine function is:

body:             |

Currently, dereferencing the MF.begin() prior to RPO causes core dump.

  rG LLVM Github Monorepo



Index: llvm/test/CodeGen/MIR/AArch64/print-parse-overloaded-intrinsics.mir
--- llvm/test/CodeGen/MIR/AArch64/print-parse-overloaded-intrinsics.mir
+++ llvm/test/CodeGen/MIR/AArch64/print-parse-overloaded-intrinsics.mir
@@ -2,6 +2,9 @@
 # RUN:   -verify-machineinstrs; llc -mtriple aarch64-- -run-pass legalizer \
 # RUN:   -simplify-mir %t -x mir -o - -verify-machineinstrs | FileCheck %s
+# RUN: llc -mtriple aarch64-- -run-pass mir-canonicalizer %s -o %t \
+# RUN:   -verify-machineinstrs
 # Test that MIRParser is able to deserialize back MIR MIRPrinter serialized,
 # specifically overloaded intrinsic names in this case which aren't required
 # to encode all the concrete arg types in the name at MIR level.
Index: llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
--- llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
+++ llvm/lib/CodeGen/MIRCanonicalizerPass.cpp
@@ -104,6 +104,8 @@
                     "Rename Register Operands Canonically", false, false)
 static std::vector<MachineBasicBlock *> GetRPOList(MachineFunction &MF) {
+  if (MF.begin() == MF.end())
+    return std::vector<MachineBasicBlock*>{};
   ReversePostOrderTraversal<MachineBasicBlock *> RPOT(&*MF.begin());
   std::vector<MachineBasicBlock *> RPOList;
   for (auto MBB : RPOT) {

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62617.202012.patch
Type: text/x-patch
Size: 1386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190529/facacb35/attachment.bin>

More information about the llvm-commits mailing list