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.
llvm-svn: 299975
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index d1f5ed4..a2773cc 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -367,9 +367,6 @@
}
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))
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index fc40261..f49232b 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -528,7 +528,8 @@
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 @@
// 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?
diff --git a/llvm/test/CodeGen/MIR/Generic/llvmIR.mir b/llvm/test/CodeGen/MIR/Generic/llvmIR.mir
index 432b18f..5c0e60e 100644
--- a/llvm/test/CodeGen/MIR/Generic/llvmIR.mir
+++ b/llvm/test/CodeGen/MIR/Generic/llvmIR.mir
@@ -28,10 +28,8 @@
IfUnequal:
ret i32 0
}
-
+
...
---
name: foo
-body: |
- bb.0:
...
diff --git a/llvm/test/CodeGen/MIR/Generic/llvmIRMissing.mir b/llvm/test/CodeGen/MIR/Generic/llvmIRMissing.mir
index 9bd2a3e..419f60b 100644
--- a/llvm/test/CodeGen/MIR/Generic/llvmIRMissing.mir
+++ b/llvm/test/CodeGen/MIR/Generic/llvmIRMissing.mir
@@ -4,6 +4,4 @@
---
# CHECK: name: foo
name: foo
-body: |
- bb.0:
...
diff --git a/llvm/test/CodeGen/MIR/Generic/machine-function-missing-body-error.mir b/llvm/test/CodeGen/MIR/Generic/machine-function-missing-body-error.mir
deleted file mode 100644
index 1896371..0000000
--- a/llvm/test/CodeGen/MIR/Generic/machine-function-missing-body-error.mir
+++ /dev/null
@@ -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
-...
diff --git a/llvm/test/CodeGen/MIR/Generic/machine-function-missing-body.mir b/llvm/test/CodeGen/MIR/Generic/machine-function-missing-body.mir
new file mode 100644
index 0000000..0fd970c
--- /dev/null
+++ b/llvm/test/CodeGen/MIR/Generic/machine-function-missing-body.mir
@@ -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
+...
diff --git a/llvm/test/CodeGen/MIR/Generic/machine-function-missing-function.mir b/llvm/test/CodeGen/MIR/Generic/machine-function-missing-function.mir
index c547bb2..b218afd 100644
--- a/llvm/test/CodeGen/MIR/Generic/machine-function-missing-function.mir
+++ b/llvm/test/CodeGen/MIR/Generic/machine-function-missing-function.mir
@@ -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:
...
diff --git a/llvm/test/CodeGen/MIR/Generic/machine-function-missing-name.mir b/llvm/test/CodeGen/MIR/Generic/machine-function-missing-name.mir
index 30f0e51..bc279a6 100644
--- a/llvm/test/CodeGen/MIR/Generic/machine-function-missing-name.mir
+++ b/llvm/test/CodeGen/MIR/Generic/machine-function-missing-name.mir
@@ -16,11 +16,7 @@
---
# CHECK: [[@LINE+1]]:1: missing required key 'name'
nme: foo
-body: |
- bb.0:
...
---
name: bar
-body: |
- bb.0:
...
diff --git a/llvm/test/CodeGen/MIR/Generic/machine-function.mir b/llvm/test/CodeGen/MIR/Generic/machine-function.mir
index f9001cc..9c19b98 100644
--- a/llvm/test/CodeGen/MIR/Generic/machine-function.mir
+++ b/llvm/test/CodeGen/MIR/Generic/machine-function.mir
@@ -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 @@
# CHECK-NEXT: exposesReturnsTwice: false
# CHECK: ...
name: bar
-body: |
- bb.0:
...
---
# CHECK: name: func
@@ -45,8 +41,6 @@
# CHECK: ...
name: func
alignment: 8
-body: |
- bb.0:
...
---
# CHECK: name: func2
@@ -56,6 +50,4 @@
name: func2
alignment: 16
exposesReturnsTwice: true
-body: |
- bb.0:
...
diff --git a/llvm/test/CodeGen/MIR/Generic/register-info.mir b/llvm/test/CodeGen/MIR/Generic/register-info.mir
index af3f44f..84a6125 100644
--- a/llvm/test/CodeGen/MIR/Generic/register-info.mir
+++ b/llvm/test/CodeGen/MIR/Generic/register-info.mir
@@ -20,8 +20,6 @@
# CHECK: tracksRegLiveness: false
# CHECK: ...
name: foo
-body: |
- bb.0:
...
---
# CHECK: name: bar
@@ -29,6 +27,4 @@
# CHECK: ...
name: bar
tracksRegLiveness: true
-body: |
- bb.0:
...