[llvm] r264780 - Add a print method to MachineFunctionProperties for better error messages
Derek Schuff via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 29 13:28:20 PDT 2016
Author: dschuff
Date: Tue Mar 29 15:28:20 2016
New Revision: 264780
URL: http://llvm.org/viewvc/llvm-project?rev=264780&view=rev
Log:
Add a print method to MachineFunctionProperties for better error messages
This makes check failures much easier to understand.
Make it empty (but leave it in the class) for NDEBUG builds.
Differential Revision: http://reviews.llvm.org/D18529
Modified:
llvm/trunk/include/llvm/CodeGen/MachineFunction.h
llvm/trunk/lib/CodeGen/MachineFunction.cpp
llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp
Modified: llvm/trunk/include/llvm/CodeGen/MachineFunction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineFunction.h?rev=264780&r1=264779&r2=264780&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineFunction.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineFunction.h Tue Mar 29 15:28:20 2016
@@ -143,6 +143,8 @@ public:
return !V.Properties.test(Properties);
}
+ void print(raw_ostream &ROS) const;
+
private:
BitVector Properties =
BitVector(static_cast<unsigned>(Property::LastProperty));
Modified: llvm/trunk/lib/CodeGen/MachineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunction.cpp?rev=264780&r1=264779&r2=264780&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineFunction.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineFunction.cpp Tue Mar 29 15:28:20 2016
@@ -54,6 +54,28 @@ static cl::opt<unsigned>
void MachineFunctionInitializer::anchor() {}
+void MachineFunctionProperties::print(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 @@ StringRef MachineFunction::getName() con
void MachineFunction::print(raw_ostream &OS, SlotIndexes *Indexes) const {
OS << "# Machine code for function " << getName() << ": ";
+ OS << "Properties: <";
+ getProperties().print(OS);
+ OS << "> : ";
if (RegInfo) {
OS << (RegInfo->isSSA() ? "SSA" : "Post SSA");
if (!RegInfo->tracksLiveness())
Modified: llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp?rev=264780&r1=264779&r2=264780&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineFunctionPass.cpp Tue Mar 29 15:28:20 2016
@@ -44,8 +44,18 @@ bool MachineFunctionPass::runOnFunction(
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.print(errs());
+ errs() << "\nCurrent properties: ";
+ MFProps.print(errs());
+ errs() << "\n";
+ llvm_unreachable("MachineFunctionProperties check failed");
+ }
+#endif
bool RV = runOnMachineFunction(MF);
More information about the llvm-commits
mailing list