OSDN Git Service

[MIR-Canon] Fixing case where MachineFunction is empty.
authorPuyan Lotfi <puyan@puyan.org>
Thu, 30 May 2019 21:37:25 +0000 (21:37 +0000)
committerPuyan Lotfi <puyan@puyan.org>
Thu, 30 May 2019 21:37:25 +0000 (21:37 +0000)
In cases where the machine function is empty: bail on the RPO traversal.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362158 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/MIRCanonicalizerPass.cpp
test/CodeGen/MIR/AArch64/empty-MF.mir [new file with mode: 0644]

index e8a6e40..650240e 100644 (file)
@@ -104,6 +104,8 @@ INITIALIZE_PASS_END(MIRCanonicalizer, "mir-canonicalizer",
                     "Rename Register Operands Canonically", false, false)
 
 static std::vector<MachineBasicBlock *> GetRPOList(MachineFunction &MF) {
+  if (MF.empty())
+    return {};
   ReversePostOrderTraversal<MachineBasicBlock *> RPOT(&*MF.begin());
   std::vector<MachineBasicBlock *> RPOList;
   for (auto MBB : RPOT) {
diff --git a/test/CodeGen/MIR/AArch64/empty-MF.mir b/test/CodeGen/MIR/AArch64/empty-MF.mir
new file mode 100644 (file)
index 0000000..40b1bff
--- /dev/null
@@ -0,0 +1,11 @@
+# RUN: llc -mtriple aarch64-- -run-pass mir-canonicalizer %s -o - | FileCheck %s
+# CHECK: ...
+# CHECK-NEXT: ---
+# CHECK-NEXT: name:            foo
+# CHECK: body:             |
+# CHECK-EMPTY:
+# CHECK-NEXT: ...
+---
+name: foo
+body:             |
+...