[PATCH] D137001: llvm-reduce: Write bitcode temporary files for bitcode inputs

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 28 18:55:58 PDT 2022


arsenm created this revision.
arsenm added reviewers: aeubanks, regehr.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

Most tools accept .ll or .bc inputs interchangably, but some don't.
Default to writing temporary files that match the input. This
will also aid reducing deserialization bugs.


https://reviews.llvm.org/D137001

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


Index: llvm/tools/llvm-reduce/llvm-reduce.cpp
===================================================================
--- llvm/tools/llvm-reduce/llvm-reduce.cpp
+++ llvm/tools/llvm-reduce/llvm-reduce.cpp
@@ -163,7 +163,8 @@
 
   // Initialize test environment
   TestRunner Tester(TestFilename, TestArguments, std::move(OriginalProgram),
-                    std::move(TM), Argv[0], OutputFilename, OutputBitcode);
+                    std::move(TM), Argv[0], OutputFilename, InputIsBitcode,
+                    OutputBitcode);
 
   // This parses and writes out the testcase into a temporary file copy for the
   // test, rather than evaluating the source IR directly. This is for the
Index: llvm/tools/llvm-reduce/deltas/Delta.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ llvm/tools/llvm-reduce/deltas/Delta.cpp
@@ -47,7 +47,7 @@
 
 static cl::opt<bool> TmpFilesAsBitcode(
     "write-tmp-files-as-bitcode",
-    cl::desc("Write temporary files as bitcode, instead of textual IR"),
+    cl::desc("Always write temporary files as bitcode instead of textual IR"),
     cl::init(false), cl::cat(LLVMReduceOptions));
 
 #ifdef LLVM_ENABLE_THREADS
@@ -66,11 +66,14 @@
                  const char *ToolName);
 
 bool isReduced(ReducerWorkItem &M, TestRunner &Test) {
+  const bool UseBitcode = Test.inputIsBitcode() || TmpFilesAsBitcode;
+
   SmallString<128> CurrentFilepath;
+
   // Write ReducerWorkItem to tmp file
   int FD;
   std::error_code EC = sys::fs::createTemporaryFile(
-      "llvm-reduce", M.isMIR() ? "mir" : (TmpFilesAsBitcode ? "bc" : "ll"), FD,
+      "llvm-reduce", M.isMIR() ? "mir" : (UseBitcode ? "bc" : "ll"), FD,
       CurrentFilepath);
   if (EC) {
     errs() << "Error making unique filename: " << EC.message() << "!\n";
Index: llvm/tools/llvm-reduce/TestRunner.h
===================================================================
--- llvm/tools/llvm-reduce/TestRunner.h
+++ llvm/tools/llvm-reduce/TestRunner.h
@@ -29,7 +29,7 @@
   TestRunner(StringRef TestName, const std::vector<std::string> &TestArgs,
              std::unique_ptr<ReducerWorkItem> Program,
              std::unique_ptr<TargetMachine> TM, const char *ToolName,
-             StringRef OutputFilename, bool OutputBitcode);
+             StringRef OutputFilename, bool InputIsBitcode, bool OutputBitcode);
 
   /// Runs the interesting-ness test for the specified file
   /// @returns 0 if test was successful, 1 if otherwise
@@ -46,6 +46,10 @@
 
   void writeOutput(StringRef Message);
 
+  bool inputIsBitcode() const {
+    return InputIsBitcode;
+  }
+
 private:
   StringRef TestName;
   const char *ToolName;
@@ -53,6 +57,7 @@
   std::unique_ptr<ReducerWorkItem> Program;
   std::unique_ptr<TargetMachine> TM;
   StringRef OutputFilename;
+  const bool InputIsBitcode;
   bool EmitBitcode;
 };
 
Index: llvm/tools/llvm-reduce/TestRunner.cpp
===================================================================
--- llvm/tools/llvm-reduce/TestRunner.cpp
+++ llvm/tools/llvm-reduce/TestRunner.cpp
@@ -22,10 +22,12 @@
                        const std::vector<std::string> &TestArgs,
                        std::unique_ptr<ReducerWorkItem> Program,
                        std::unique_ptr<TargetMachine> TM, const char *ToolName,
-                       StringRef OutputName, bool OutputBitcode)
+                       StringRef OutputName, bool InputIsBitcode,
+                       bool OutputBitcode)
     : TestName(TestName), ToolName(ToolName), TestArgs(TestArgs),
       Program(std::move(Program)), TM(std::move(TM)),
-      OutputFilename(OutputName), EmitBitcode(OutputBitcode) {
+      OutputFilename(OutputName), InputIsBitcode(InputIsBitcode),
+      EmitBitcode(OutputBitcode) {
   assert(this->Program && "Initialized with null program?");
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137001.471703.patch
Type: text/x-patch
Size: 3834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221029/a51801d0/attachment.bin>


More information about the llvm-commits mailing list