Skip to content

Commit 336368c

Browse files
committed
Step towards implementation of pass manager with doInitialization and doFinalization per module detangled from runOn?? calls, still has temporary code not to break ASAN to be removed when that pass conforms to the proposed model
Patch by Pedro Artigas, with feedback from by Chandler Carruth. llvm-svn: 168635
1 parent 8559a35 commit 336368c

File tree

12 files changed

+33
-81
lines changed

12 files changed

+33
-81
lines changed

llvm/include/llvm/CodeGen/MachineModuleInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ class MachineModuleInfo : public ImmutablePass {
180180
const MCObjectFileInfo *MOFI);
181181
~MachineModuleInfo();
182182

183+
using ModulePass::doInitialization;
183184
bool doInitialization();
185+
186+
using ModulePass::doFinalization;
184187
bool doFinalization();
185188

186189
/// EndFunction - Discard function meta information.

llvm/include/llvm/Pass.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class ModulePass : public Pass {
230230
/// doInitialization - Virtual method overridden by subclasses to do
231231
/// any necessary initialization.
232232
///
233-
virtual bool doInitialization() { return false; }
233+
virtual bool doInitialization(Module &) { return false; }
234234

235235
/// runOnModule - Virtual method overriden by subclasses to process the module
236236
/// being operated on.
@@ -239,7 +239,7 @@ class ModulePass : public Pass {
239239
/// doFinalization - Virtual method overriden by subclasses to do any post
240240
/// processing needed after all passes have run.
241241
///
242-
virtual bool doFinalization() { return false; }
242+
virtual bool doFinalization(Module &) { return false; }
243243

244244
virtual void assignPassManager(PMStack &PMS,
245245
PassManagerType T);

llvm/include/llvm/PassManager.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ class PassManager : public PassManagerBase {
5858
/// whether any of the passes modifies the module, and if so, return true.
5959
bool run(Module &M);
6060

61-
/// doInitialization - Run all of the initializers for the module passes.
62-
///
63-
bool doInitialization();
64-
65-
/// doFinalization - Run all of the finalizers for the module passes.
66-
///
67-
bool doFinalization();
68-
6961
private:
7062
/// PassManagerImpl_New is the actual class. PassManager is just the
7163
/// wraper to publish simple pass manager interface

llvm/include/llvm/PassManagers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ class FPPassManager : public ModulePass, public PMDataManager {
462462
virtual PassManagerType getPassManagerType() const {
463463
return PMT_FunctionPassManager;
464464
}
465+
466+
protected:
467+
// FIXME: due to limitation in AddressSanitizer
468+
bool RunFinalization;
465469
};
466470

467471
Timer *getPassTimer(Pass *);

llvm/lib/VMCore/PassManager.cpp

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,11 +1528,13 @@ bool FPPassManager::runOnFunction(Function &F) {
15281528
}
15291529

15301530
bool FPPassManager::runOnModule(Module &M) {
1531-
bool Changed = doInitialization(M);
1531+
bool Changed = false;
15321532

15331533
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
15341534
Changed |= runOnFunction(*I);
15351535

1536+
// FIXME: doFinalization still needed here due to assumption in
1537+
// AddressSanitizer
15361538
return doFinalization(M) || Changed;
15371539
}
15381540

@@ -1542,14 +1544,25 @@ bool FPPassManager::doInitialization(Module &M) {
15421544
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
15431545
Changed |= getContainedPass(Index)->doInitialization(M);
15441546

1547+
// FIXME: mark Finalization as needed here due to assumption in
1548+
// AddressSanitizer
1549+
RunFinalization = true;
1550+
15451551
return Changed;
15461552
}
15471553

15481554
bool FPPassManager::doFinalization(Module &M) {
15491555
bool Changed = false;
1550-
1556+
1557+
// FIXME: due to limitation in AddressSanitizer
1558+
if (!RunFinalization)
1559+
return Changed;
1560+
15511561
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
15521562
Changed |= getContainedPass(Index)->doFinalization(M);
1563+
1564+
// FIXME: due to limitation in AddressSanitizer
1565+
RunFinalization = false;
15531566

15541567
return Changed;
15551568
}
@@ -1572,6 +1585,10 @@ MPPassManager::runOnModule(Module &M) {
15721585
Changed |= FPP->doInitialization(M);
15731586
}
15741587

1588+
// Initialize module passes
1589+
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1590+
Changed |= getContainedPass(Index)->doInitialization(M);
1591+
15751592
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
15761593
ModulePass *MP = getContainedPass(Index);
15771594
bool LocalChanged = false;
@@ -1600,6 +1617,10 @@ MPPassManager::runOnModule(Module &M) {
16001617
removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG);
16011618
}
16021619

1620+
// Finalize module passes
1621+
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1622+
Changed |= getContainedPass(Index)->doFinalization(M);
1623+
16031624
// Finalize on-the-fly passes
16041625
for (std::map<Pass *, FunctionPassManagerImpl *>::iterator
16051626
I = OnTheFlyManagers.begin(), E = OnTheFlyManagers.end();
@@ -1610,29 +1631,7 @@ MPPassManager::runOnModule(Module &M) {
16101631
FPP->releaseMemoryOnTheFly();
16111632
Changed |= FPP->doFinalization(M);
16121633
}
1613-
1614-
return Changed;
1615-
}
1616-
1617-
/// Run all of the initializers for the module passes.
1618-
///
1619-
bool MPPassManager::doInitialization() {
1620-
bool Changed = false;
1621-
1622-
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1623-
Changed |= getContainedPass(Index)->doInitialization();
1624-
1625-
return Changed;
1626-
}
1627-
1628-
/// Run all of the finalizers for the module passes.
1629-
///
1630-
bool MPPassManager::doFinalization() {
1631-
bool Changed = false;
1632-
1633-
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index)
1634-
Changed |= getContainedPass(Index)->doFinalization();
1635-
1634+
16361635
return Changed;
16371636
}
16381637

@@ -1692,24 +1691,6 @@ Pass* MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI, Function &F){
16921691
//===----------------------------------------------------------------------===//
16931692
// PassManagerImpl implementation
16941693

1695-
bool PassManagerImpl::doInitialization() {
1696-
bool Changed = false;
1697-
1698-
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
1699-
Changed |= getContainedManager(Index)->doInitialization();
1700-
1701-
return Changed;
1702-
}
1703-
1704-
bool PassManagerImpl::doFinalization() {
1705-
bool Changed = false;
1706-
1707-
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
1708-
Changed |= getContainedManager(Index)->doFinalization();
1709-
1710-
return Changed;
1711-
}
1712-
17131694
//
17141695
/// run - Execute all of the passes scheduled for execution. Keep track of
17151696
/// whether any of the passes modifies the module, and if so, return true.
@@ -1754,18 +1735,6 @@ bool PassManager::run(Module &M) {
17541735
return PM->run(M);
17551736
}
17561737

1757-
/// doInitialization - Run all of the initializers for the module passes.
1758-
///
1759-
bool PassManager::doInitialization() {
1760-
return PM->doInitialization();
1761-
}
1762-
1763-
/// doFinalization - Run all of the finalizers for the module passes.
1764-
///
1765-
bool PassManager::doFinalization() {
1766-
return PM->doFinalization();
1767-
}
1768-
17691738
//===----------------------------------------------------------------------===//
17701739
// TimingInfo Class - This class is used to calculate information about the
17711740
// amount of time each pass takes to execute. This only happens with

llvm/tools/bugpoint/CrashDebugger.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,7 @@ bool ReduceCrashingInstructions::TestInsts(std::vector<const Instruction*>
412412
// Verify that this is still valid.
413413
PassManager Passes;
414414
Passes.add(createVerifierPass());
415-
Passes.doInitialization();
416415
Passes.run(*M);
417-
Passes.doFinalization();
418416

419417
// Try running on the hacked up program...
420418
if (TestFn(BD, M)) {

llvm/tools/llc/llc.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,7 @@ int main(int argc, char **argv) {
359359
// Before executing passes, print the final values of the LLVM options.
360360
cl::PrintOptionValues();
361361

362-
PM.doInitialization();
363362
PM.run(*mod);
364-
PM.doFinalization();
365363
}
366364

367365
// Declare success.

llvm/tools/llvm-extract/llvm-extract.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,7 @@ int main(int argc, char **argv) {
276276
else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
277277
Passes.add(createBitcodeWriterPass(Out.os()));
278278

279-
Passes.doInitialization();
280279
Passes.run(*M.get());
281-
Passes.doFinalization();
282280

283281
// Declare success.
284282
Out.keep();

llvm/tools/llvm-prof/llvm-prof.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,7 @@ int main(int argc, char **argv) {
287287
PassManager PassMgr;
288288
PassMgr.add(createProfileLoaderPass(ProfileDataFile));
289289
PassMgr.add(new ProfileInfoPrinterPass(PIL));
290-
PassMgr.doInitialization();
291290
PassMgr.run(*M);
292-
PassMgr.doFinalization();
293291

294292
return 0;
295293
}

llvm/tools/llvm-stress/llvm-stress.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,9 +713,7 @@ int main(int argc, char **argv) {
713713
PassManager Passes;
714714
Passes.add(createVerifierPass());
715715
Passes.add(createPrintModulePass(&Out->os()));
716-
Passes.doInitialization();
717716
Passes.run(*M.get());
718-
Passes.doFinalization();
719717
Out->keep();
720718

721719
return 0;

llvm/tools/lto/LTOCodeGenerator.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,7 @@ void LTOCodeGenerator::applyScopeRestrictions() {
342342
passes.add(createInternalizePass(mustPreserveList));
343343

344344
// apply scope restrictions
345-
passes.doInitialization();
346345
passes.run(*mergedModule);
347-
passes.doFinalization();
348346

349347
_scopeRestrictionsDone = true;
350348
}
@@ -399,9 +397,7 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out,
399397
}
400398

401399
// Run our queue of passes all at once now, efficiently.
402-
passes.doInitialization();
403400
passes.run(*mergedModule);
404-
passes.doFinalization();
405401

406402
// Run the code generator, and write assembly file
407403
codeGenPasses->doInitialization();

llvm/tools/opt/opt.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,7 @@ int main(int argc, char **argv) {
820820
cl::PrintOptionValues();
821821

822822
// Now that we have all of the passes ready, run them.
823-
Passes.doInitialization();
824823
Passes.run(*M.get());
825-
Passes.doFinalization();
826824

827825
// Declare success.
828826
if (!NoOutput || PrintBreakpoints)

0 commit comments

Comments
 (0)