Index: llvm/include/llvm/CodeGen/MachineFunction.h =================================================================== --- llvm/include/llvm/CodeGen/MachineFunction.h +++ llvm/include/llvm/CodeGen/MachineFunction.h @@ -831,6 +831,12 @@ bool verify(Pass *p = nullptr, const char *Banner = nullptr, bool AbortOnError = true) const; + /// Run the current MachineFunction through the machine code verifier, useful + /// for debugger use. + /// \returns true if no problems were found. + bool verify(LiveIntervals *LiveInts, SlotIndexes *Indexes, + const char *Banner = nullptr, bool AbortOnError = true) const; + // Provide accessors for the MachineBasicBlock list... using iterator = BasicBlockListType::iterator; using const_iterator = BasicBlockListType::const_iterator; Index: llvm/lib/CodeGen/MachineVerifier.cpp =================================================================== --- llvm/lib/CodeGen/MachineVerifier.cpp +++ llvm/lib/CodeGen/MachineVerifier.cpp @@ -90,9 +90,15 @@ struct MachineVerifier { MachineVerifier(Pass *pass, const char *b) : PASS(pass), Banner(b) {} + MachineVerifier(const char *b, LiveVariables *LiveVars, + LiveIntervals *LiveInts, LiveStacks *LiveStks, + SlotIndexes *Indexes) + : Banner(b), LiveVars(LiveVars), LiveInts(LiveInts), LiveStks(LiveStks), + Indexes(Indexes) {} + unsigned verify(const MachineFunction &MF); - Pass *const PASS; + Pass *const PASS = nullptr; const char *Banner; const MachineFunction *MF; const TargetMachine *TM; @@ -207,10 +213,10 @@ } // Analysis information if available - LiveVariables *LiveVars; - LiveIntervals *LiveInts; - LiveStacks *LiveStks; - SlotIndexes *Indexes; + LiveVariables *LiveVars = nullptr; + LiveIntervals *LiveInts = nullptr; + LiveStacks *LiveStks = nullptr; + SlotIndexes *Indexes = nullptr; void visitMachineFunctionBefore(); void visitMachineBasicBlockBefore(const MachineBasicBlock *MBB); @@ -346,6 +352,16 @@ return FoundErrors == 0; } +bool MachineFunction::verify(LiveIntervals *LiveInts, SlotIndexes *Indexes, + const char *Banner, bool AbortOnErrors) const { + MachineFunction &MF = const_cast(*this); + unsigned FoundErrors = + MachineVerifier(Banner, nullptr, LiveInts, nullptr, Indexes).verify(MF); + if (AbortOnErrors && FoundErrors) + report_fatal_error("Found " + Twine(FoundErrors) + " machine code errors."); + return FoundErrors == 0; +} + void MachineVerifier::verifySlotIndexes() const { if (Indexes == nullptr) return; @@ -395,10 +411,6 @@ isFunctionTracksDebugUserValues = MF.getProperties().hasProperty( MachineFunctionProperties::Property::TracksDebugUserValues); - LiveVars = nullptr; - LiveInts = nullptr; - LiveStks = nullptr; - Indexes = nullptr; if (PASS) { LiveInts = PASS->getAnalysisIfAvailable(); // We don't want to verify LiveVariables if LiveIntervals is available.