[ORE] Move loop invariant ORE checks outside the PM loop.

Summary:
This takes 22ms out of ~20s compiling sqlite3.c because we call it
for every unit of compilation and every pass.

Reviewers: paquette, anemet

Subscribers: mehdi_amini, llvm-commits

Differential Revision: https://reviews.llvm.org/D49586

llvm-svn: 337654
This commit is contained in:
Xin Tong 2018-07-22 05:27:41 +00:00
parent cc4ad95c30
commit 023e25ad14
4 changed files with 41 additions and 20 deletions

View File

@ -256,6 +256,13 @@ public:
/// versions when the pass does not change.
std::unique_ptr<RandomNumberGenerator> createRNG(const Pass* P) const;
/// Return true if size-info optimization remark is enabled, false
/// otherwise.
bool shouldEmitInstrCountChangedRemark() {
return getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled(
"size-info");
}
/// @}
/// @name Module Level Mutators
/// @{

View File

@ -130,12 +130,16 @@ bool CGPassManager::RunPassOnSCC(Pass *P, CallGraphSCC &CurSCC,
}
{
unsigned InstrCount = 0;
bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
TimeRegion PassTimer(getPassTimer(CGSP));
unsigned InstrCount = initSizeRemarkInfo(M);
if (EmitICRemark)
InstrCount = initSizeRemarkInfo(M);
Changed = CGSP->runOnSCC(CurSCC);
// If the pass modified the module, it may have modified the instruction
// count of the module. Try emitting a remark.
if (EmitICRemark)
emitInstrCountChangedRemark(P, M, InstrCount);
}

View File

@ -193,6 +193,8 @@ bool LPPassManager::runOnFunction(Function &F) {
}
// Walk Loops
unsigned InstrCount = 0;
bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
while (!LQ.empty()) {
CurrentLoopDeleted = false;
CurrentLoop = LQ.back();
@ -210,8 +212,10 @@ bool LPPassManager::runOnFunction(Function &F) {
{
PassManagerPrettyStackEntry X(P, *CurrentLoop->getHeader());
TimeRegion PassTimer(getPassTimer(P));
unsigned InstrCount = initSizeRemarkInfo(M);
if (EmitICRemark)
InstrCount = initSizeRemarkInfo(M);
Changed |= P->runOnLoop(CurrentLoop, *this);
if (EmitICRemark)
emitInstrCountChangedRemark(P, M, InstrCount);
}

View File

@ -137,17 +137,11 @@ bool PMDataManager::isPassDebuggingExecutionsOrMore() const {
unsigned PMDataManager::initSizeRemarkInfo(Module &M) {
// Only calculate getInstructionCount if the size-info remark is requested.
if (M.getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled("size-info"))
return M.getInstructionCount();
return 0;
}
void PMDataManager::emitInstrCountChangedRemark(Pass *P, Module &M,
unsigned CountBefore) {
// Did the user request the remark? If not, quit.
if (!M.getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled("size-info"))
return;
// We need a function containing at least one basic block in order to output
// remarks. Since it's possible that the first function in the module doesn't
// actually contain a basic block, we have to go and find one that's suitable
@ -1349,6 +1343,8 @@ bool BBPassManager::runOnFunction(Function &F) {
bool Changed = doInitialization(F);
Module &M = *F.getParent();
unsigned InstrCount = 0;
bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
for (BasicBlock &BB : F)
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
BasicBlockPass *BP = getContainedPass(Index);
@ -1363,8 +1359,10 @@ bool BBPassManager::runOnFunction(Function &F) {
// If the pass crashes, remember this.
PassManagerPrettyStackEntry X(BP, BB);
TimeRegion PassTimer(getPassTimer(BP));
unsigned InstrCount = initSizeRemarkInfo(M);
if (EmitICRemark)
InstrCount = initSizeRemarkInfo(M);
LocalChanged |= BP->runOnBasicBlock(BB);
if (EmitICRemark)
emitInstrCountChangedRemark(BP, M, InstrCount);
}
@ -1569,6 +1567,8 @@ bool FPPassManager::runOnFunction(Function &F) {
// Collect inherited analysis from Module level pass manager.
populateInheritedAnalysis(TPM->activeStack);
unsigned InstrCount = 0;
bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
FunctionPass *FP = getContainedPass(Index);
bool LocalChanged = false;
@ -1581,8 +1581,10 @@ bool FPPassManager::runOnFunction(Function &F) {
{
PassManagerPrettyStackEntry X(FP, F);
TimeRegion PassTimer(getPassTimer(FP));
unsigned InstrCount = initSizeRemarkInfo(M);
if (EmitICRemark)
InstrCount = initSizeRemarkInfo(M);
LocalChanged |= FP->runOnFunction(F);
if (EmitICRemark)
emitInstrCountChangedRemark(FP, M, InstrCount);
}
@ -1647,6 +1649,8 @@ MPPassManager::runOnModule(Module &M) {
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
Changed |= getContainedPass(Index)->doInitialization(M);
unsigned InstrCount = 0;
bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
ModulePass *MP = getContainedPass(Index);
bool LocalChanged = false;
@ -1660,8 +1664,10 @@ MPPassManager::runOnModule(Module &M) {
PassManagerPrettyStackEntry X(MP, M);
TimeRegion PassTimer(getPassTimer(MP));
unsigned InstrCount = initSizeRemarkInfo(M);
if (EmitICRemark)
InstrCount = initSizeRemarkInfo(M);
LocalChanged |= MP->runOnModule(M);
if (EmitICRemark)
emitInstrCountChangedRemark(MP, M, InstrCount);
}