[PM] Simplify the interface exposed for IR printing passes.

Nothing was using the ability of the pass to delete the raw_ostream it
printed to, and nothing was trying to pass it a pointer to the
raw_ostream. Also, the function variant had a different order of
arguments from all of the others which was just really confusing. Now
the interface accepts a reference, doesn't offer to delete it, and uses
a consistent order. The implementation of the printing passes haven't
been updated with this simplification, this is just the API switch.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199044 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chandler Carruth 2014-01-12 11:30:46 +00:00
parent 2ad3b87c4e
commit a5ced5ed37
9 changed files with 34 additions and 33 deletions

View File

@ -29,21 +29,26 @@ class raw_ostream;
/// \brief Create and return a pass that writes the module to the specified
/// \c raw_ostream.
ModulePass *createPrintModulePass(raw_ostream *OS, bool DeleteStream = false,
ModulePass *createPrintModulePass(raw_ostream &OS,
const std::string &Banner = "");
/// \brief Create and return a pass that prints functions to the specified
/// \c raw_ostream as they are processed.
FunctionPass *createPrintFunctionPass(const std::string &Banner,
raw_ostream *OS,
bool DeleteStream = false);
FunctionPass *createPrintFunctionPass(raw_ostream &OS,
const std::string &Banner = "");
/// \brief Create and return a pass that writes the BB to the specified
/// \c raw_ostream.
BasicBlockPass *createPrintBasicBlockPass(raw_ostream *OS,
bool DeleteStream = false,
BasicBlockPass *createPrintBasicBlockPass(raw_ostream &OS,
const std::string &Banner = "");
/// \brief Pass for printing a Module as LLVM's text IR assembly.
///
/// NOTE: This pass is for use with the new pass manager. Use the create...Pass
/// functions above to create passes for use with the legacy pass manager.
class AOEUPrintModulePass {
};
} // End llvm namespace
#endif

View File

@ -139,9 +139,9 @@ namespace {
(void) llvm::createMetaRenamerPass();
(void) llvm::createFunctionAttrsPass();
(void) llvm::createMergeFunctionsPass();
(void) llvm::createPrintModulePass(0);
(void) llvm::createPrintFunctionPass("", 0);
(void) llvm::createPrintBasicBlockPass(0);
(void) llvm::createPrintModulePass(*(llvm::raw_ostream*)0);
(void) llvm::createPrintFunctionPass(*(llvm::raw_ostream*)0);
(void) llvm::createPrintBasicBlockPass(*(llvm::raw_ostream*)0);
(void) llvm::createModuleDebugInfoPrinterPass();
(void) llvm::createPartialInliningPass();
(void) llvm::createLintPass();

View File

@ -154,7 +154,7 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
// machine-level pass), and whatever other information is needed to
// deserialize the code and resume compilation. For now, just write the
// LLVM IR.
PM.add(createPrintModulePass(&Out));
PM.add(createPrintModulePass(Out));
return false;
}

View File

@ -389,7 +389,7 @@ void TargetPassConfig::addIRPasses() {
if (getOptLevel() != CodeGenOpt::None && !DisableLSR) {
addPass(createLoopStrengthReducePass());
if (PrintLSR)
addPass(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &dbgs()));
addPass(createPrintFunctionPass(dbgs(), "\n\n*** Code after LSR ***\n"));
}
addPass(createGCLoweringPass());
@ -440,9 +440,8 @@ void TargetPassConfig::addISelPrepare() {
addPass(createStackProtectorPass(TM));
if (PrintISelInput)
addPass(createPrintFunctionPass("\n\n"
"*** Final LLVM Code input to ISel ***\n",
&dbgs()));
addPass(createPrintFunctionPass(
dbgs(), "\n\n*** Final LLVM Code input to ISel ***\n"));
// All passes which modify the LLVM IR are now complete; run the verifier
// to ensure that the IR is valid.

View File

@ -113,20 +113,17 @@ char PrintBasicBlockPass::ID = 0;
INITIALIZE_PASS(PrintBasicBlockPass, "print-bb", "Print BB to stderr", false,
false)
ModulePass *llvm::createPrintModulePass(llvm::raw_ostream *OS,
bool DeleteStream,
ModulePass *llvm::createPrintModulePass(llvm::raw_ostream &OS,
const std::string &Banner) {
return new PrintModulePass(Banner, OS, DeleteStream);
return new PrintModulePass(Banner, &OS, false);
}
FunctionPass *llvm::createPrintFunctionPass(const std::string &Banner,
llvm::raw_ostream *OS,
bool DeleteStream) {
return new PrintFunctionPass(Banner, OS, DeleteStream);
FunctionPass *llvm::createPrintFunctionPass(llvm::raw_ostream &OS,
const std::string &Banner) {
return new PrintFunctionPass(Banner, &OS, false);
}
BasicBlockPass *llvm::createPrintBasicBlockPass(llvm::raw_ostream *OS,
bool DeleteStream,
BasicBlockPass *llvm::createPrintBasicBlockPass(llvm::raw_ostream &OS,
const std::string &Banner) {
return new PrintBasicBlockPass(Banner, OS, DeleteStream);
return new PrintBasicBlockPass(Banner, &OS, false);
}

View File

@ -235,7 +235,7 @@ public:
/// createPrinterPass - Get a function printer pass.
Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const {
return createPrintFunctionPass(Banner, &O);
return createPrintFunctionPass(O, Banner);
}
// Prepare for running an on the fly pass, freeing memory if needed
@ -304,7 +304,7 @@ public:
/// createPrinterPass - Get a module printer pass.
Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const {
return createPrintModulePass(&O, false, Banner);
return createPrintModulePass(O, Banner);
}
/// run - Execute all of the passes scheduled for execution. Keep track of
@ -404,7 +404,7 @@ public:
/// createPrinterPass - Get a module printer pass.
Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const {
return createPrintModulePass(&O, false, Banner);
return createPrintModulePass(O, Banner);
}
/// run - Execute all of the passes scheduled for execution. Keep track of

View File

@ -35,7 +35,7 @@ ModulePass::~ModulePass() { }
Pass *ModulePass::createPrinterPass(raw_ostream &O,
const std::string &Banner) const {
return createPrintModulePass(&O, false, Banner);
return createPrintModulePass(O, Banner);
}
PassManagerType ModulePass::getPotentialPassManagerType() const {
@ -130,7 +130,7 @@ void ImmutablePass::initializePass() {
Pass *FunctionPass::createPrinterPass(raw_ostream &O,
const std::string &Banner) const {
return createPrintFunctionPass(Banner, &O);
return createPrintFunctionPass(O, Banner);
}
PassManagerType FunctionPass::getPotentialPassManagerType() const {
@ -143,7 +143,7 @@ PassManagerType FunctionPass::getPotentialPassManagerType() const {
Pass *BasicBlockPass::createPrinterPass(raw_ostream &O,
const std::string &Banner) const {
return createPrintBasicBlockPass(&O, false, Banner);
return createPrintBasicBlockPass(O, Banner);
}
bool BasicBlockPass::doInitialization(Function &) {

View File

@ -272,7 +272,7 @@ int main(int argc, char **argv) {
}
if (OutputAssembly)
Passes.add(createPrintModulePass(&Out.os()));
Passes.add(createPrintModulePass(Out.os()));
else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
Passes.add(createBitcodeWriterPass(Out.os()));

View File

@ -823,7 +823,7 @@ int main(int argc, char **argv) {
}
if (PrintEachXForm)
Passes.add(createPrintModulePass(&errs()));
Passes.add(createPrintModulePass(errs()));
}
// If -std-compile-opts was specified at the end of the pass list, add them.
@ -866,7 +866,7 @@ int main(int argc, char **argv) {
// Write bitcode or assembly to the output as the last step...
if (!NoOutput && !AnalyzeOnly) {
if (OutputAssembly)
Passes.add(createPrintModulePass(&Out->os()));
Passes.add(createPrintModulePass(Out->os()));
else
Passes.add(createBitcodeWriterPass(Out->os()));
}