[PATCH] D113858: [llvm-reduce] Allow writing temporary files as bitcode.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 14 11:32:51 PST 2021


fhahn created this revision.
fhahn added reviewers: aeubanks, dblaikie, lebedev.ri, Meinersbur.
fhahn requested review of this revision.
Herald added a project: LLVM.

Textual LLVM IR files are much bigger and take longer to write to disk.
To avoid the extra cost incurred by serializing to text, this patch adds
an option to save temporary files as bitcode instead.

IMO writing bitcode would ideally be the default, as it is more
efficient and for most uses cases the temporary files will likely be
consumed by other LLVM tools that support bitcode.

But using textual IR allows for convenient use of FileCheck in the
tests, so all test would need updating.

I am also not sure how to best add a unit test using bitcode temporary
files. Python script that somehow also takes the patch to llvm-as as
argument somehow?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113858

Files:
  llvm/tools/llvm-reduce/deltas/Delta.cpp


Index: llvm/tools/llvm-reduce/deltas/Delta.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ llvm/tools/llvm-reduce/deltas/Delta.cpp
@@ -40,6 +40,11 @@
              "disables parallelism. Maximum capped to 32."),
     cl::init(1));
 
+static cl::opt<bool> TmpFilesAsBitcode(
+    "write-tmp-files-as-bitcode",
+    cl::desc("Write temporary files as bitcode, instead of textual IR"),
+    cl::init(false));
+
 void writeOutput(ReducerWorkItem &M, llvm::StringRef Message);
 
 bool isReduced(ReducerWorkItem &M, TestRunner &Test,
@@ -47,12 +52,26 @@
   // Write ReducerWorkItem to tmp file
   int FD;
   std::error_code EC = sys::fs::createTemporaryFile(
-      "llvm-reduce", M.isMIR() ? "mir" : "ll", FD, CurrentFilepath);
+      "llvm-reduce", M.isMIR() ? "mir" : (TmpFilesAsBitcode ? "bc" : "ll"), FD,
+      CurrentFilepath);
   if (EC) {
     errs() << "Error making unique filename: " << EC.message() << "!\n";
     exit(1);
   }
 
+  if (TmpFilesAsBitcode) {
+    llvm::raw_fd_ostream OutStream(FD, true);
+    WriteBitcodeToFile(M, OutStream);
+    OutStream.close();
+    if (OutStream.has_error()) {
+      errs() << "Error emitting bitcode to file '" << CurrentFilepath << "'!\n";
+      sys::fs::remove(CurrentFilepath);
+      exit(1);
+    }
+    bool Res = Test.run(CurrentFilepath);
+    sys::fs::remove(CurrentFilepath);
+    return Res;
+  }
   ToolOutputFile Out(CurrentFilepath, FD);
   M.print(Out.os(), /*AnnotationWriter=*/nullptr);
   Out.os().close();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113858.387119.patch
Type: text/x-patch
Size: 1548 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211114/9cb7e791/attachment.bin>


More information about the llvm-commits mailing list