forked from OSchip/llvm-project
uselistorder: Pull bit through BitcodeWriterPass
Now the callers of `BitcodeWriterPass` decide whether or not to preserve bitcode use-list order. llvm-svn: 234959
This commit is contained in:
parent
e406c84e30
commit
679db3345c
|
@ -26,7 +26,11 @@ class PreservedAnalyses;
|
||||||
/// \brief Create and return a pass that writes the module to the specified
|
/// \brief Create and return a pass that writes the module to the specified
|
||||||
/// ostream. Note that this pass is designed for use with the legacy pass
|
/// ostream. Note that this pass is designed for use with the legacy pass
|
||||||
/// manager.
|
/// manager.
|
||||||
ModulePass *createBitcodeWriterPass(raw_ostream &Str);
|
///
|
||||||
|
/// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
|
||||||
|
/// reproduced when deserialized.
|
||||||
|
ModulePass *createBitcodeWriterPass(raw_ostream &Str,
|
||||||
|
bool ShouldPreserveUseListOrder = false);
|
||||||
|
|
||||||
/// \brief Pass for writing a module of IR out to a bitcode file.
|
/// \brief Pass for writing a module of IR out to a bitcode file.
|
||||||
///
|
///
|
||||||
|
@ -34,10 +38,16 @@ ModulePass *createBitcodeWriterPass(raw_ostream &Str);
|
||||||
/// a pass for the legacy pass manager, use the function above.
|
/// a pass for the legacy pass manager, use the function above.
|
||||||
class BitcodeWriterPass {
|
class BitcodeWriterPass {
|
||||||
raw_ostream &OS;
|
raw_ostream &OS;
|
||||||
|
bool ShouldPreserveUseListOrder;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// \brief Construct a bitcode writer pass around a particular output stream.
|
/// \brief Construct a bitcode writer pass around a particular output stream.
|
||||||
explicit BitcodeWriterPass(raw_ostream &OS) : OS(OS) {}
|
///
|
||||||
|
/// If \c ShouldPreserveUseListOrder, encode use-list order so it can be
|
||||||
|
/// reproduced when deserialized.
|
||||||
|
explicit BitcodeWriterPass(raw_ostream &OS,
|
||||||
|
bool ShouldPreserveUseListOrder = false)
|
||||||
|
: OS(OS), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
|
||||||
|
|
||||||
/// \brief Run the bitcode writer pass, and output the module to the selected
|
/// \brief Run the bitcode writer pass, and output the module to the selected
|
||||||
/// output stream.
|
/// output stream.
|
||||||
|
|
|
@ -20,22 +20,25 @@
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
PreservedAnalyses BitcodeWriterPass::run(Module &M) {
|
PreservedAnalyses BitcodeWriterPass::run(Module &M) {
|
||||||
WriteBitcodeToFile(&M, OS, shouldPreserveBitcodeUseListOrder());
|
WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder);
|
||||||
return PreservedAnalyses::all();
|
return PreservedAnalyses::all();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class WriteBitcodePass : public ModulePass {
|
class WriteBitcodePass : public ModulePass {
|
||||||
raw_ostream &OS; // raw_ostream to print on
|
raw_ostream &OS; // raw_ostream to print on
|
||||||
|
bool ShouldPreserveUseListOrder;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID; // Pass identification, replacement for typeid
|
static char ID; // Pass identification, replacement for typeid
|
||||||
explicit WriteBitcodePass(raw_ostream &o)
|
explicit WriteBitcodePass(raw_ostream &o, bool ShouldPreserveUseListOrder)
|
||||||
: ModulePass(ID), OS(o) {}
|
: ModulePass(ID), OS(o),
|
||||||
|
ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}
|
||||||
|
|
||||||
const char *getPassName() const override { return "Bitcode Writer"; }
|
const char *getPassName() const override { return "Bitcode Writer"; }
|
||||||
|
|
||||||
bool runOnModule(Module &M) override {
|
bool runOnModule(Module &M) override {
|
||||||
WriteBitcodeToFile(&M, OS, shouldPreserveBitcodeUseListOrder());
|
WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -43,6 +46,7 @@ namespace {
|
||||||
|
|
||||||
char WriteBitcodePass::ID = 0;
|
char WriteBitcodePass::ID = 0;
|
||||||
|
|
||||||
ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str) {
|
ModulePass *llvm::createBitcodeWriterPass(raw_ostream &Str,
|
||||||
return new WriteBitcodePass(Str);
|
bool ShouldPreserveUseListOrder) {
|
||||||
|
return new WriteBitcodePass(Str, ShouldPreserveUseListOrder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,7 +272,8 @@ int main(int argc, char **argv) {
|
||||||
if (OutputAssembly)
|
if (OutputAssembly)
|
||||||
Passes.add(createPrintModulePass(Out.os()));
|
Passes.add(createPrintModulePass(Out.os()));
|
||||||
else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
|
else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
|
||||||
Passes.add(createBitcodeWriterPass(Out.os()));
|
Passes.add(
|
||||||
|
createBitcodeWriterPass(Out.os(), shouldPreserveBitcodeUseListOrder()));
|
||||||
|
|
||||||
Passes.run(*M.get());
|
Passes.run(*M.get());
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,8 @@ static cl::opt<bool>
|
||||||
bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
|
bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
|
||||||
TargetMachine *TM, tool_output_file *Out,
|
TargetMachine *TM, tool_output_file *Out,
|
||||||
StringRef PassPipeline, OutputKind OK,
|
StringRef PassPipeline, OutputKind OK,
|
||||||
VerifierKind VK) {
|
VerifierKind VK,
|
||||||
|
bool ShouldPreserveBitcodeUseListOrder) {
|
||||||
PassBuilder PB(TM);
|
PassBuilder PB(TM);
|
||||||
|
|
||||||
FunctionAnalysisManager FAM(DebugPM);
|
FunctionAnalysisManager FAM(DebugPM);
|
||||||
|
@ -80,7 +81,8 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
|
||||||
MPM.addPass(PrintModulePass(Out->os()));
|
MPM.addPass(PrintModulePass(Out->os()));
|
||||||
break;
|
break;
|
||||||
case OK_OutputBitcode:
|
case OK_OutputBitcode:
|
||||||
MPM.addPass(BitcodeWriterPass(Out->os()));
|
MPM.addPass(
|
||||||
|
BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,8 @@ enum VerifierKind {
|
||||||
bool runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
|
bool runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
|
||||||
TargetMachine *TM, tool_output_file *Out,
|
TargetMachine *TM, tool_output_file *Out,
|
||||||
StringRef PassPipeline, opt_tool::OutputKind OK,
|
StringRef PassPipeline, opt_tool::OutputKind OK,
|
||||||
opt_tool::VerifierKind VK);
|
opt_tool::VerifierKind VK,
|
||||||
|
bool ShouldPreserveBitcodeUseListOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -431,7 +431,8 @@ int main(int argc, char **argv) {
|
||||||
// string. Hand off the rest of the functionality to the new code for that
|
// string. Hand off the rest of the functionality to the new code for that
|
||||||
// layer.
|
// layer.
|
||||||
return runPassPipeline(argv[0], Context, *M, TM.get(), Out.get(),
|
return runPassPipeline(argv[0], Context, *M, TM.get(), Out.get(),
|
||||||
PassPipeline, OK, VK)
|
PassPipeline, OK, VK,
|
||||||
|
shouldPreserveBitcodeUseListOrder())
|
||||||
? 0
|
? 0
|
||||||
: 1;
|
: 1;
|
||||||
}
|
}
|
||||||
|
@ -594,7 +595,8 @@ int main(int argc, char **argv) {
|
||||||
if (OutputAssembly)
|
if (OutputAssembly)
|
||||||
Passes.add(createPrintModulePass(Out->os()));
|
Passes.add(createPrintModulePass(Out->os()));
|
||||||
else
|
else
|
||||||
Passes.add(createBitcodeWriterPass(Out->os()));
|
Passes.add(createBitcodeWriterPass(Out->os(),
|
||||||
|
shouldPreserveBitcodeUseListOrder()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before executing passes, print the final values of the LLVM options.
|
// Before executing passes, print the final values of the LLVM options.
|
||||||
|
|
Loading…
Reference in New Issue