--- /dev/null
+"""
+Script to disassembles a bitcode file and run FileCheck on the output with the
+provided arguments. The first 2 arguments are the paths to the llvm-dis and
+FileCheck binaries, followed by arguments to be passed to FileCheck. The last
+argument is the bitcode file to disassemble.
+
+Usage:
+ python llvm-dis-and-filecheck.py
+ <path to llvm-dis> <path to FileCheck>
+ [arguments passed to FileCheck] <path to bitcode file>
+
+"""
+
+
+import sys
+import subprocess
+
+llvm_dis = sys.argv[1]
+filecheck = sys.argv[2]
+filecheck_args = [filecheck, ]
+filecheck_args.extend(sys.argv[3:-1])
+bitcode_file = sys.argv[-1]
+
+disassemble = subprocess.Popen([llvm_dis, "-o", "-", bitcode_file],
+ stdout=subprocess.PIPE)
+check = subprocess.Popen(filecheck_args, stdin=disassemble.stdout)
+disassemble.stdout.close()
+check.communicate()
+sys.exit(check.returncode)
--- /dev/null
+; RUN: llvm-reduce -write-tmp-files-as-bitcode --delta-passes=basic-blocks %s -o %t \
+; RUN: --test %python --test-arg %p/Inputs/llvm-dis-and-filecheck.py --test-arg llvm-dis --test-arg FileCheck --test-arg --check-prefixes=CHECK-ALL,CHECK-INTERESTINGNESS --test-arg %s
+; RUN: cat %t | FileCheck --check-prefixes=CHECK-ALL,CHECK-FINAL %s
+
+; CHECK-INTERESTINGNESS: @callee(
+; CHECK-FINAL: declare void @callee()
+define void @callee() {
+ ret void
+}
+
+; CHECK-ALL: define void @caller()
+define void @caller() {
+entry:
+; CHECK-ALL: call void @callee()
+; CHECK-ALL: ret void
+ call void @callee()
+ ret void
+}
#include "Delta.h"
#include "ReducerWorkItem.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ToolOutputFile.h"
"starting-granularity-level",
cl::desc("Number of times to divide chunks prior to first test"));
+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,
// 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();