[PATCH] D18529: Add a dump method to MachineFunctionProperties for better error messages

Derek Schuff via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 16:52:57 PDT 2016


dschuff updated this revision to Diff 51856.
dschuff added a comment.

- Also print the properties when printing the MF


http://reviews.llvm.org/D18529

Files:
  include/llvm/CodeGen/MachineFunction.h
  lib/CodeGen/MachineFunction.cpp
  lib/CodeGen/MachineFunctionPass.cpp

Index: lib/CodeGen/MachineFunctionPass.cpp
===================================================================
--- lib/CodeGen/MachineFunctionPass.cpp
+++ lib/CodeGen/MachineFunctionPass.cpp
@@ -44,8 +44,18 @@
   MachineFunction &MF = getAnalysis<MachineFunctionAnalysis>().getMF();
   MachineFunctionProperties &MFProps = MF.getProperties();
 
-  assert(MFProps.verifyRequiredProperties(RequiredProperties) &&
-         "Properties required by the pass are not met by the function");
+#ifndef NDEBUG
+  if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
+    errs() << "MachineFunctionProperties required by " << getPassName()
+           << " pass are not met by function " << F.getName() << ".\n"
+           << "Required properties: ";
+    RequiredProperties.dump(errs());
+    errs() << "\nCurrent properties: ";
+    MFProps.dump(errs());
+    errs() << "\n";
+    llvm_unreachable("MachineFunctionProperties check failed");
+  }
+#endif
 
   bool RV = runOnMachineFunction(MF);
 
Index: lib/CodeGen/MachineFunction.cpp
===================================================================
--- lib/CodeGen/MachineFunction.cpp
+++ lib/CodeGen/MachineFunction.cpp
@@ -54,6 +54,28 @@
 
 void MachineFunctionInitializer::anchor() {}
 
+void MachineFunctionProperties::dump(raw_ostream &ROS) const {
+  // Leave this function even in NDEBUG as an out-of-line anchor.
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  if (!Properties.any()) {
+    ROS << "(empty)";
+    return;
+  }
+  for (BitVector::size_type i = 0; i < Properties.size(); ++i) {
+    if (Properties[i]) {
+      switch(static_cast<Property>(i)) {
+        case Property::AllVRegsAllocated:
+          ROS << "AllVRegsAllocated ";
+          break;
+        default:
+          // TODO: Implement IsSSA/TracksLiveness when we make them properties.
+          llvm_unreachable("Unexpected value for property enum");
+      }
+    }
+  }
+#endif
+}
+
 //===----------------------------------------------------------------------===//
 // MachineFunction implementation
 //===----------------------------------------------------------------------===//
@@ -370,6 +392,9 @@
 
 void MachineFunction::print(raw_ostream &OS, SlotIndexes *Indexes) const {
   OS << "# Machine code for function " << getName() << ": ";
+  OS << "Properties: <";
+  getProperties().dump(OS);
+  OS << "> : ";
   if (RegInfo) {
     OS << (RegInfo->isSSA() ? "SSA" : "Post SSA");
     if (!RegInfo->tracksLiveness())
Index: include/llvm/CodeGen/MachineFunction.h
===================================================================
--- include/llvm/CodeGen/MachineFunction.h
+++ include/llvm/CodeGen/MachineFunction.h
@@ -143,6 +143,8 @@
     return !V.Properties.test(Properties);
   }
 
+  void dump(raw_ostream &ROS) const;
+
 private:
   BitVector Properties =
       BitVector(static_cast<unsigned>(Property::LastProperty));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18529.51856.patch
Type: text/x-patch
Size: 2882 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160328/aae7369e/attachment.bin>


More information about the llvm-commits mailing list