aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachinePassManager.cpp
diff options
context:
space:
mode:
authorYuanfang Chen <yuanfang.chen@sony.com>2020-08-13 12:52:35 -0700
committerYuanfang Chen <yuanfang.chen@sony.com>2020-08-13 16:13:01 -0700
commita5ed20b549782bf284162c712af4673f7cd75222 (patch)
treecc9110bd8494ef9cfa9cbaa45ea304bc3356a668 /llvm/lib/CodeGen/MachinePassManager.cpp
parent4cb016cd2d8467c572b2e5c5d34f376ee79e4ac1 (diff)
downloadllvm-a5ed20b549782bf284162c712af4673f7cd75222.zip
llvm-a5ed20b549782bf284162c712af4673f7cd75222.tar.gz
llvm-a5ed20b549782bf284162c712af4673f7cd75222.tar.bz2
[NewPM][CodeGen] Add machine code verification callback
D83608 need this. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D85916
Diffstat (limited to 'llvm/lib/CodeGen/MachinePassManager.cpp')
-rw-r--r--llvm/lib/CodeGen/MachinePassManager.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachinePassManager.cpp b/llvm/lib/CodeGen/MachinePassManager.cpp
index f5514e4..be81fc8 100644
--- a/llvm/lib/CodeGen/MachinePassManager.cpp
+++ b/llvm/lib/CodeGen/MachinePassManager.cpp
@@ -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";