parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context,
DiagnosticHandlerFunction DiagnosticHandler = nullptr);
- /// WriteBitcodeToFile - Write the specified module to the specified
- /// raw output stream. For streams where it matters, the given stream
- /// should be in "binary" mode.
- void WriteBitcodeToFile(const Module *M, raw_ostream &Out);
-
+ /// \brief Write the specified module to the specified raw output stream.
+ ///
+ /// For streams where it matters, the given stream should be in "binary"
+ /// mode.
+ ///
+ /// If \c ShouldPreserveUseListOrder, encode the use-list order for each \a
+ /// Value in \c M. These will be reconstructed exactly when \a M is
+ /// deserialized.
+ void WriteBitcodeToFile(const Module *M, raw_ostream &Out,
+ bool ShouldPreserveUseListOrder = false);
/// isBitcodeWrapper - Return true if the given bytes are the magic bytes
/// for an LLVM IR bitcode wrapper.
}
/// WriteModule - Emit the specified module to the bitstream.
-static void WriteModule(const Module *M, BitstreamWriter &Stream) {
+static void WriteModule(const Module *M, BitstreamWriter &Stream,
+ bool ShouldPreserveUseListOrder) {
Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3);
SmallVector<unsigned, 1> Vals;
Stream.EmitRecord(bitc::MODULE_CODE_VERSION, Vals);
// Analyze the module, enumerating globals, functions, etc.
- ValueEnumerator VE(*M, shouldPreserveBitcodeUseListOrder());
+ ValueEnumerator VE(*M, ShouldPreserveUseListOrder);
// Emit blockinfo, which defines the standard abbreviations etc.
WriteBlockInfo(VE, Stream);
/// WriteBitcodeToFile - Write the specified module to the specified output
/// stream.
-void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) {
+void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out,
+ bool ShouldPreserveUseListOrder) {
SmallVector<char, 0> Buffer;
Buffer.reserve(256*1024);
Stream.Emit(0xD, 4);
// Emit the module.
- WriteModule(M, Stream);
+ WriteModule(M, Stream, ShouldPreserveUseListOrder);
}
if (TT.isOSDarwin())
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
+#include "llvm/IR/UseListOrder.h"
#include "llvm/Pass.h"
using namespace llvm;
PreservedAnalyses BitcodeWriterPass::run(Module &M) {
- WriteBitcodeToFile(&M, OS);
+ WriteBitcodeToFile(&M, OS, shouldPreserveBitcodeUseListOrder());
return PreservedAnalyses::all();
}
const char *getPassName() const override { return "Bitcode Writer"; }
bool runOnModule(Module &M) override {
- WriteBitcodeToFile(&M, OS);
+ WriteBitcodeToFile(&M, OS, shouldPreserveBitcodeUseListOrder());
return false;
}
};
}
// write bitcode to it
- WriteBitcodeToFile(IRLinker.getModule(), Out.os());
+ WriteBitcodeToFile(IRLinker.getModule(), Out.os(),
+ shouldPreserveBitcodeUseListOrder());
Out.os().close();
if (Out.os().has_error()) {
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
+#include "llvm/IR/UseListOrder.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
/// file. If an error occurs, true is returned.
///
static bool writeProgramToFileAux(tool_output_file &Out, const Module *M) {
- WriteBitcodeToFile(M, Out.os());
+ WriteBitcodeToFile(M, Out.os(), shouldPreserveBitcodeUseListOrder());
Out.os().close();
if (!Out.os().has_error()) {
Out.keep();
tool_output_file InFile(InputFilename, InputFD);
- WriteBitcodeToFile(Program, InFile.os());
+ WriteBitcodeToFile(Program, InFile.os(), shouldPreserveBitcodeUseListOrder());
InFile.os().close();
if (InFile.os().has_error()) {
errs() << "Error writing bitcode file: " << InputFilename << "\n";
passes.run(M);
}
-static void saveBCFile(StringRef Path, Module &M) {
+static void saveBCFile(StringRef Path, Module &M,
+ bool ShouldPreserveUseListOrder) {
std::error_code EC;
raw_fd_ostream OS(Path, EC, sys::fs::OpenFlags::F_None);
if (EC)
message(LDPL_FATAL, "Failed to write the output file.");
- WriteBitcodeToFile(&M, OS);
+ WriteBitcodeToFile(&M, OS, /* ShouldPreserveUseListOrder */ true);
}
static void codegen(Module &M) {
}
if (Force || !CheckBitcodeOutputToConsole(Out->os(), true))
- WriteBitcodeToFile(M, Out->os());
+ WriteBitcodeToFile(M, Out->os(), shouldPreserveBitcodeUseListOrder());
// Declare success.
Out->keep();
if (OutputAssembly) {
Out.os() << *Composite;
} else if (Force || !CheckBitcodeOutputToConsole(Out.os(), true))
- WriteBitcodeToFile(Composite.get(), Out.os());
+ WriteBitcodeToFile(Composite.get(), Out.os(),
+ shouldPreserveBitcodeUseListOrder());
// Declare success.
Out.keep();
return true;
}
- WriteBitcodeToFile(&M, OS);
+ WriteBitcodeToFile(&M, OS, /* ShouldPreserveUseListOrder */ true);
return false;
}
outs() << "*** verify-uselistorder ***\n";
// Can't verify if order isn't preserved.
- if (!shouldPreserveBitcodeUseListOrder()) {
- errs() << "warning: forcing -preserve-bc-uselistorder\n";
- setPreserveBitcodeUseListOrder(true);
- }
if (!shouldPreserveAssemblyUseListOrder()) {
errs() << "warning: forcing -preserve-ll-uselistorder\n";
setPreserveAssemblyUseListOrder(true);