[llvm] r299975 - MIR: Allow parsing of empty machine functions

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 11 12:32:41 PDT 2017


Author: bogner
Date: Tue Apr 11 14:32:41 2017
New Revision: 299975

URL: http://llvm.org/viewvc/llvm-project?rev=299975&view=rev
Log:
MIR: Allow parsing of empty machine functions

If you run llc -stop-after=codegenprepare and feed the resulting MIR
to llc -start-after=codegenprepare, you'll have an empty machine
function since we haven't run any isel yet. Of course, this only works
if the MIRParser believes you that this is okay.

This is essentially a revert of r241862 with a fix for the problem it
was papering over.

Added:
    llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-body.mir
Removed:
    llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-body-error.mir
Modified:
    llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp
    llvm/trunk/lib/CodeGen/MachineVerifier.cpp
    llvm/trunk/test/CodeGen/MIR/Generic/llvmIR.mir
    llvm/trunk/test/CodeGen/MIR/Generic/llvmIRMissing.mir
    llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-function.mir
    llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-name.mir
    llvm/trunk/test/CodeGen/MIR/Generic/machine-function.mir
    llvm/trunk/test/CodeGen/MIR/Generic/register-info.mir

Modified: llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp?rev=299975&r1=299974&r2=299975&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRParser/MIRParser.cpp Tue Apr 11 14:32:41 2017
@@ -367,9 +367,6 @@ bool MIRParserImpl::initializeMachineFun
   }
   PFS.SM = &SM;
 
-  if (MF.empty())
-    return error(Twine("machine function '") + Twine(MF.getName()) +
-                 "' requires at least one machine basic block in its body");
   // Initialize the frame information after creating all the MBBs so that the
   // MBB references in the frame information can be resolved.
   if (initializeFrameInfo(PFS, YamlMF))

Modified: llvm/trunk/lib/CodeGen/MachineVerifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineVerifier.cpp?rev=299975&r1=299974&r2=299975&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineVerifier.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineVerifier.cpp Tue Apr 11 14:32:41 2017
@@ -528,7 +528,8 @@ void MachineVerifier::visitMachineFuncti
   lastIndex = SlotIndex();
   regsReserved = MRI->getReservedRegs();
 
-  markReachable(&MF->front());
+  if (!MF->empty())
+    markReachable(&MF->front());
 
   // Build a set of the basic blocks in the function.
   FunctionBlocks.clear();
@@ -548,7 +549,8 @@ void MachineVerifier::visitMachineFuncti
   // Check that the register use lists are sane.
   MRI->verifyUseLists();
 
-  verifyStackFrame();
+  if (!MF->empty())
+    verifyStackFrame();
 }
 
 // Does iterator point to a and b as the first two elements?

Modified: llvm/trunk/test/CodeGen/MIR/Generic/llvmIR.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/Generic/llvmIR.mir?rev=299975&r1=299974&r2=299975&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/Generic/llvmIR.mir (original)
+++ llvm/trunk/test/CodeGen/MIR/Generic/llvmIR.mir Tue Apr 11 14:32:41 2017
@@ -28,10 +28,8 @@
   IfUnequal:
     ret i32 0
   }
-  
+
 ...
 ---
 name: foo
-body: |
-  bb.0:
 ...

Modified: llvm/trunk/test/CodeGen/MIR/Generic/llvmIRMissing.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/Generic/llvmIRMissing.mir?rev=299975&r1=299974&r2=299975&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/Generic/llvmIRMissing.mir (original)
+++ llvm/trunk/test/CodeGen/MIR/Generic/llvmIRMissing.mir Tue Apr 11 14:32:41 2017
@@ -4,6 +4,4 @@
 ---
 # CHECK: name: foo
 name: foo
-body: |
-  bb.0:
 ...

Removed: llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-body-error.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-body-error.mir?rev=299974&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-body-error.mir (original)
+++ llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-body-error.mir (removed)
@@ -1,15 +0,0 @@
-# RUN: not llc -run-pass none -o /dev/null %s 2>&1 | FileCheck %s
-# This test ensures that the MIR parser reports an error when it encounters a
-# machine function with an empty body.
-
---- |
-
-  define i32 @foo() {
-    ret i32 0
-  }
-
-...
----
-# CHECK: machine function 'foo' requires at least one machine basic block in its body
-name:            foo
-...

Added: llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-body.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-body.mir?rev=299975&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-body.mir (added)
+++ llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-body.mir Tue Apr 11 14:32:41 2017
@@ -0,0 +1,15 @@
+# RUN: llc -run-pass none -o - %s | FileCheck %s
+# This test ensures that the MIR parser accepts files with llvm IR but
+# no machine function body.
+
+--- |
+  ; CHECK: define i32 @foo()
+  define i32 @foo() {
+    ret i32 0
+  }
+
+...
+---
+# CHECK: name: foo
+name:            foo
+...

Modified: llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-function.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-function.mir?rev=299975&r1=299974&r2=299975&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-function.mir (original)
+++ llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-function.mir Tue Apr 11 14:32:41 2017
@@ -12,12 +12,8 @@
 ...
 ---
 name:            foo
-body: |
-  bb.0:
 ...
 ---
 # CHECK: function 'faa' isn't defined in the provided LLVM IR
 name:            faa
-body: |
-  bb.0:
 ...

Modified: llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-name.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-name.mir?rev=299975&r1=299974&r2=299975&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-name.mir (original)
+++ llvm/trunk/test/CodeGen/MIR/Generic/machine-function-missing-name.mir Tue Apr 11 14:32:41 2017
@@ -16,11 +16,7 @@
 ---
 # CHECK: [[@LINE+1]]:1: missing required key 'name'
 nme:             foo
-body: |
-  bb.0:
 ...
 ---
 name:            bar
-body: |
-  bb.0:
 ...

Modified: llvm/trunk/test/CodeGen/MIR/Generic/machine-function.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/Generic/machine-function.mir?rev=299975&r1=299974&r2=299975&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/Generic/machine-function.mir (original)
+++ llvm/trunk/test/CodeGen/MIR/Generic/machine-function.mir Tue Apr 11 14:32:41 2017
@@ -18,7 +18,7 @@
   define i32 @func2() {
     ret i32 0
   }
-  
+
 ...
 ---
 # CHECK: name: foo
@@ -26,8 +26,6 @@
 # CHECK-NEXT: exposesReturnsTwice: false
 # CHECK: ...
 name:            foo
-body: |
-  bb.0:
 ...
 ---
 # CHECK: name: bar
@@ -35,8 +33,6 @@ body: |
 # CHECK-NEXT: exposesReturnsTwice: false
 # CHECK: ...
 name:            bar
-body: |
-  bb.0:
 ...
 ---
 # CHECK: name: func
@@ -45,8 +41,6 @@ body: |
 # CHECK: ...
 name:            func
 alignment:       8
-body: |
-  bb.0:
 ...
 ---
 # CHECK: name: func2
@@ -56,6 +50,4 @@ body: |
 name:            func2
 alignment:       16
 exposesReturnsTwice: true
-body: |
-  bb.0:
 ...

Modified: llvm/trunk/test/CodeGen/MIR/Generic/register-info.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/MIR/Generic/register-info.mir?rev=299975&r1=299974&r2=299975&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/MIR/Generic/register-info.mir (original)
+++ llvm/trunk/test/CodeGen/MIR/Generic/register-info.mir Tue Apr 11 14:32:41 2017
@@ -20,8 +20,6 @@
 # CHECK: tracksRegLiveness: false
 # CHECK: ...
 name:            foo
-body: |
-  bb.0:
 ...
 ---
 # CHECK: name: bar
@@ -29,6 +27,4 @@ body: |
 # CHECK: ...
 name: bar
 tracksRegLiveness: true
-body: |
-  bb.0:
 ...




More information about the llvm-commits mailing list