forked from OSchip/llvm-project
[NewPM][CodeGen] Add machine code verification callback
D83608 need this. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D85916
This commit is contained in:
parent
4cb016cd2d
commit
a5ed20b549
|
@ -1141,6 +1141,11 @@ template <> struct GraphTraits<Inverse<const MachineFunction*>> :
|
|||
}
|
||||
};
|
||||
|
||||
class MachineFunctionAnalysisManager;
|
||||
void verifyMachineFunction(MachineFunctionAnalysisManager *,
|
||||
const std::string &Banner,
|
||||
const MachineFunction &MF);
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_CODEGEN_MACHINEFUNCTION_H
|
||||
|
|
|
@ -134,8 +134,10 @@ class MachineFunctionPassManager
|
|||
|
||||
public:
|
||||
MachineFunctionPassManager(bool DebugLogging = false,
|
||||
bool RequireCodeGenSCCOrder = false)
|
||||
: Base(DebugLogging), RequireCodeGenSCCOrder(RequireCodeGenSCCOrder) {}
|
||||
bool RequireCodeGenSCCOrder = false,
|
||||
bool VerifyMachineFunction = false)
|
||||
: Base(DebugLogging), RequireCodeGenSCCOrder(RequireCodeGenSCCOrder),
|
||||
VerifyMachineFunction(VerifyMachineFunction) {}
|
||||
MachineFunctionPassManager(MachineFunctionPassManager &&) = default;
|
||||
MachineFunctionPassManager &
|
||||
operator=(MachineFunctionPassManager &&) = default;
|
||||
|
@ -245,6 +247,8 @@ private:
|
|||
|
||||
// Run codegen in the SCC order.
|
||||
bool RequireCodeGenSCCOrder;
|
||||
|
||||
bool VerifyMachineFunction;
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/CodeGen/MachinePassManager.h"
|
||||
#include "llvm/CodeGen/MachineFunction.h"
|
||||
#include "llvm/CodeGen/MachineModuleInfo.h"
|
||||
#include "llvm/IR/PassManagerImpl.h"
|
||||
|
||||
|
@ -32,6 +33,22 @@ Error MachineFunctionPassManager::run(Module &M,
|
|||
(void)RequireCodeGenSCCOrder;
|
||||
assert(!RequireCodeGenSCCOrder && "not implemented");
|
||||
|
||||
// Add a PIC to verify machine functions.
|
||||
if (VerifyMachineFunction) {
|
||||
PassInstrumentation PI = MFAM.getResult<PassInstrumentationAnalysis>(M);
|
||||
|
||||
// No need to pop this callback later since MIR pipeline is flat which means
|
||||
// current pipeline is the top-level pipeline. Callbacks are not used after
|
||||
// current pipeline.
|
||||
PI.pushBeforeNonSkippedPassCallback([&MFAM](StringRef PassID, Any IR) {
|
||||
assert(any_isa<const MachineFunction *>(IR));
|
||||
const MachineFunction *MF = any_cast<const MachineFunction *>(IR);
|
||||
assert(MF && "Machine function should be valid for printing");
|
||||
std::string Banner = std::string("After ") + std::string(PassID);
|
||||
verifyMachineFunction(&MFAM, Banner, *MF);
|
||||
});
|
||||
}
|
||||
|
||||
if (DebugLogging) {
|
||||
dbgs() << "Starting " << getTypeName<MachineFunction>()
|
||||
<< " pass manager run.\n";
|
||||
|
|
|
@ -304,6 +304,19 @@ FunctionPass *llvm::createMachineVerifierPass(const std::string &Banner) {
|
|||
return new MachineVerifierPass(Banner);
|
||||
}
|
||||
|
||||
void llvm::verifyMachineFunction(MachineFunctionAnalysisManager *,
|
||||
const std::string &Banner,
|
||||
const MachineFunction &MF) {
|
||||
// TODO: Use MFAM after porting below analyses.
|
||||
// LiveVariables *LiveVars;
|
||||
// LiveIntervals *LiveInts;
|
||||
// LiveStacks *LiveStks;
|
||||
// SlotIndexes *Indexes;
|
||||
unsigned FoundErrors = MachineVerifier(nullptr, Banner.c_str()).verify(MF);
|
||||
if (FoundErrors)
|
||||
report_fatal_error("Found " + Twine(FoundErrors) + " machine code errors.");
|
||||
}
|
||||
|
||||
bool MachineFunction::verify(Pass *p, const char *Banner, bool AbortOnErrors)
|
||||
const {
|
||||
MachineFunction &MF = const_cast<MachineFunction&>(*this);
|
||||
|
|
Loading…
Reference in New Issue