Skip to content

Commit 023e25a

Browse files
committedJul 22, 2018
[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
1 parent cc4ad95 commit 023e25a

File tree

4 files changed

+41
-20
lines changed

4 files changed

+41
-20
lines changed
 

‎llvm/include/llvm/IR/Module.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,16 @@ class Module {
256256
/// versions when the pass does not change.
257257
std::unique_ptr<RandomNumberGenerator> createRNG(const Pass* P) const;
258258

259-
/// @}
260-
/// @name Module Level Mutators
261-
/// @{
259+
/// Return true if size-info optimization remark is enabled, false
260+
/// otherwise.
261+
bool shouldEmitInstrCountChangedRemark() {
262+
return getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled(
263+
"size-info");
264+
}
265+
266+
/// @}
267+
/// @name Module Level Mutators
268+
/// @{
262269

263270
/// Set the module identifier.
264271
void setModuleIdentifier(StringRef ID) { ModuleID = ID; }

‎llvm/lib/Analysis/CallGraphSCCPass.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,17 @@ bool CGPassManager::RunPassOnSCC(Pass *P, CallGraphSCC &CurSCC,
130130
}
131131

132132
{
133+
unsigned InstrCount = 0;
134+
bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
133135
TimeRegion PassTimer(getPassTimer(CGSP));
134-
unsigned InstrCount = initSizeRemarkInfo(M);
136+
if (EmitICRemark)
137+
InstrCount = initSizeRemarkInfo(M);
135138
Changed = CGSP->runOnSCC(CurSCC);
136139

137140
// If the pass modified the module, it may have modified the instruction
138141
// count of the module. Try emitting a remark.
139-
emitInstrCountChangedRemark(P, M, InstrCount);
142+
if (EmitICRemark)
143+
emitInstrCountChangedRemark(P, M, InstrCount);
140144
}
141145

142146
// After the CGSCCPass is done, when assertions are enabled, use

‎llvm/lib/Analysis/LoopPass.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ bool LPPassManager::runOnFunction(Function &F) {
193193
}
194194

195195
// Walk Loops
196+
unsigned InstrCount = 0;
197+
bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
196198
while (!LQ.empty()) {
197199
CurrentLoopDeleted = false;
198200
CurrentLoop = LQ.back();
@@ -210,9 +212,11 @@ bool LPPassManager::runOnFunction(Function &F) {
210212
{
211213
PassManagerPrettyStackEntry X(P, *CurrentLoop->getHeader());
212214
TimeRegion PassTimer(getPassTimer(P));
213-
unsigned InstrCount = initSizeRemarkInfo(M);
215+
if (EmitICRemark)
216+
InstrCount = initSizeRemarkInfo(M);
214217
Changed |= P->runOnLoop(CurrentLoop, *this);
215-
emitInstrCountChangedRemark(P, M, InstrCount);
218+
if (EmitICRemark)
219+
emitInstrCountChangedRemark(P, M, InstrCount);
216220
}
217221

218222
if (Changed)

‎llvm/lib/IR/LegacyPassManager.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,11 @@ bool PMDataManager::isPassDebuggingExecutionsOrMore() const {
137137

138138
unsigned PMDataManager::initSizeRemarkInfo(Module &M) {
139139
// Only calculate getInstructionCount if the size-info remark is requested.
140-
if (M.getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled("size-info"))
141-
return M.getInstructionCount();
142-
return 0;
140+
return M.getInstructionCount();
143141
}
144142

145143
void PMDataManager::emitInstrCountChangedRemark(Pass *P, Module &M,
146144
unsigned CountBefore) {
147-
// Did the user request the remark? If not, quit.
148-
if (!M.getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled("size-info"))
149-
return;
150-
151145
// We need a function containing at least one basic block in order to output
152146
// remarks. Since it's possible that the first function in the module doesn't
153147
// actually contain a basic block, we have to go and find one that's suitable
@@ -1349,6 +1343,8 @@ bool BBPassManager::runOnFunction(Function &F) {
13491343
bool Changed = doInitialization(F);
13501344
Module &M = *F.getParent();
13511345

1346+
unsigned InstrCount = 0;
1347+
bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
13521348
for (BasicBlock &BB : F)
13531349
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
13541350
BasicBlockPass *BP = getContainedPass(Index);
@@ -1363,9 +1359,11 @@ bool BBPassManager::runOnFunction(Function &F) {
13631359
// If the pass crashes, remember this.
13641360
PassManagerPrettyStackEntry X(BP, BB);
13651361
TimeRegion PassTimer(getPassTimer(BP));
1366-
unsigned InstrCount = initSizeRemarkInfo(M);
1362+
if (EmitICRemark)
1363+
InstrCount = initSizeRemarkInfo(M);
13671364
LocalChanged |= BP->runOnBasicBlock(BB);
1368-
emitInstrCountChangedRemark(BP, M, InstrCount);
1365+
if (EmitICRemark)
1366+
emitInstrCountChangedRemark(BP, M, InstrCount);
13691367
}
13701368

13711369
Changed |= LocalChanged;
@@ -1569,6 +1567,8 @@ bool FPPassManager::runOnFunction(Function &F) {
15691567
// Collect inherited analysis from Module level pass manager.
15701568
populateInheritedAnalysis(TPM->activeStack);
15711569

1570+
unsigned InstrCount = 0;
1571+
bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
15721572
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
15731573
FunctionPass *FP = getContainedPass(Index);
15741574
bool LocalChanged = false;
@@ -1581,9 +1581,11 @@ bool FPPassManager::runOnFunction(Function &F) {
15811581
{
15821582
PassManagerPrettyStackEntry X(FP, F);
15831583
TimeRegion PassTimer(getPassTimer(FP));
1584-
unsigned InstrCount = initSizeRemarkInfo(M);
1584+
if (EmitICRemark)
1585+
InstrCount = initSizeRemarkInfo(M);
15851586
LocalChanged |= FP->runOnFunction(F);
1586-
emitInstrCountChangedRemark(FP, M, InstrCount);
1587+
if (EmitICRemark)
1588+
emitInstrCountChangedRemark(FP, M, InstrCount);
15871589
}
15881590

15891591
Changed |= LocalChanged;
@@ -1647,6 +1649,8 @@ MPPassManager::runOnModule(Module &M) {
16471649
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
16481650
Changed |= getContainedPass(Index)->doInitialization(M);
16491651

1652+
unsigned InstrCount = 0;
1653+
bool EmitICRemark = M.shouldEmitInstrCountChangedRemark();
16501654
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
16511655
ModulePass *MP = getContainedPass(Index);
16521656
bool LocalChanged = false;
@@ -1660,9 +1664,11 @@ MPPassManager::runOnModule(Module &M) {
16601664
PassManagerPrettyStackEntry X(MP, M);
16611665
TimeRegion PassTimer(getPassTimer(MP));
16621666

1663-
unsigned InstrCount = initSizeRemarkInfo(M);
1667+
if (EmitICRemark)
1668+
InstrCount = initSizeRemarkInfo(M);
16641669
LocalChanged |= MP->runOnModule(M);
1665-
emitInstrCountChangedRemark(MP, M, InstrCount);
1670+
if (EmitICRemark)
1671+
emitInstrCountChangedRemark(MP, M, InstrCount);
16661672
}
16671673

16681674
Changed |= LocalChanged;

0 commit comments

Comments
 (0)
Please sign in to comment.