1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

[NewPM][PassInstrument] Make PrintIR and TimePasses to use before-pass-run callback

Reviewed By: asbirlea, aeubanks

Differential Revision: https://reviews.llvm.org/D84773
This commit is contained in:
Yuanfang Chen 2020-07-28 16:31:46 -07:00
parent 53414ad22f
commit 4fad307f88
4 changed files with 12 additions and 15 deletions

View File

@ -100,7 +100,7 @@ private:
void stopTimer(StringRef PassID); void stopTimer(StringRef PassID);
// Implementation of pass instrumentation callbacks. // Implementation of pass instrumentation callbacks.
bool runBeforePass(StringRef PassID); void runBeforePass(StringRef PassID);
void runAfterPass(StringRef PassID); void runAfterPass(StringRef PassID);
}; };

View File

@ -39,7 +39,7 @@ public:
void registerCallbacks(PassInstrumentationCallbacks &PIC); void registerCallbacks(PassInstrumentationCallbacks &PIC);
private: private:
bool printBeforePass(StringRef PassID, Any IR); void printBeforePass(StringRef PassID, Any IR);
void printAfterPass(StringRef PassID, Any IR); void printAfterPass(StringRef PassID, Any IR);
void printAfterPassInvalidated(StringRef PassID); void printAfterPassInvalidated(StringRef PassID);

View File

@ -240,17 +240,14 @@ static bool matchPassManager(StringRef PassID) {
Prefix.endswith("AnalysisManagerProxy"); Prefix.endswith("AnalysisManagerProxy");
} }
bool TimePassesHandler::runBeforePass(StringRef PassID) { void TimePassesHandler::runBeforePass(StringRef PassID) {
if (matchPassManager(PassID)) if (matchPassManager(PassID))
return true; return;
startTimer(PassID); startTimer(PassID);
LLVM_DEBUG(dbgs() << "after runBeforePass(" << PassID << ")\n"); LLVM_DEBUG(dbgs() << "after runBeforePass(" << PassID << ")\n");
LLVM_DEBUG(dump()); LLVM_DEBUG(dump());
// we are not going to skip this pass, thus return true.
return true;
} }
void TimePassesHandler::runAfterPass(StringRef PassID) { void TimePassesHandler::runAfterPass(StringRef PassID) {
@ -267,8 +264,8 @@ void TimePassesHandler::registerCallbacks(PassInstrumentationCallbacks &PIC) {
if (!Enabled) if (!Enabled)
return; return;
PIC.registerBeforePassCallback( PIC.registerBeforeNonSkippedPassCallback(
[this](StringRef P, Any) { return this->runBeforePass(P); }); [this](StringRef P, Any) { this->runBeforePass(P); });
PIC.registerAfterPassCallback( PIC.registerAfterPassCallback(
[this](StringRef P, Any) { this->runAfterPass(P); }); [this](StringRef P, Any) { this->runAfterPass(P); });
PIC.registerAfterPassInvalidatedCallback( PIC.registerAfterPassInvalidatedCallback(

View File

@ -180,9 +180,9 @@ PrintIRInstrumentation::popModuleDesc(StringRef PassID) {
return ModuleDesc; return ModuleDesc;
} }
bool PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) { void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
if (PassID.startswith("PassManager<") || PassID.contains("PassAdaptor<")) if (PassID.startswith("PassManager<") || PassID.contains("PassAdaptor<"))
return true; return;
// Saving Module for AfterPassInvalidated operations. // Saving Module for AfterPassInvalidated operations.
// Note: here we rely on a fact that we do not change modules while // Note: here we rely on a fact that we do not change modules while
@ -192,11 +192,11 @@ bool PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
pushModuleDesc(PassID, IR); pushModuleDesc(PassID, IR);
if (!llvm::shouldPrintBeforePass(PassID)) if (!llvm::shouldPrintBeforePass(PassID))
return true; return;
SmallString<20> Banner = formatv("*** IR Dump Before {0} ***", PassID); SmallString<20> Banner = formatv("*** IR Dump Before {0} ***", PassID);
unwrapAndPrint(IR, Banner, llvm::forcePrintModuleIR()); unwrapAndPrint(IR, Banner, llvm::forcePrintModuleIR());
return true; return;
} }
void PrintIRInstrumentation::printAfterPass(StringRef PassID, Any IR) { void PrintIRInstrumentation::printAfterPass(StringRef PassID, Any IR) {
@ -240,8 +240,8 @@ void PrintIRInstrumentation::registerCallbacks(
// for later use in AfterPassInvalidated. // for later use in AfterPassInvalidated.
StoreModuleDesc = llvm::forcePrintModuleIR() && llvm::shouldPrintAfterPass(); StoreModuleDesc = llvm::forcePrintModuleIR() && llvm::shouldPrintAfterPass();
if (llvm::shouldPrintBeforePass() || StoreModuleDesc) if (llvm::shouldPrintBeforePass() || StoreModuleDesc)
PIC.registerBeforePassCallback( PIC.registerBeforeNonSkippedPassCallback(
[this](StringRef P, Any IR) { return this->printBeforePass(P, IR); }); [this](StringRef P, Any IR) { this->printBeforePass(P, IR); });
if (llvm::shouldPrintAfterPass()) { if (llvm::shouldPrintAfterPass()) {
PIC.registerAfterPassCallback( PIC.registerAfterPassCallback(