Add syntactic equality check to alive-tv
MODIFY
tests/alive-tv/params/dbg.src.ll
tests/alive-tv/params/dbg.src.ll
define i16 @test(i16) {
%v = add i16 %0, %0
+ add i16 0, 0 ; dummy
ret i16 %v
}

MODIFY
tests/lit/lit/formats/alive2test.py
tests/lit/lit/formats/alive2test.py
@@ -34,7 +34,7 @@ def is_timeout(str):
return str.find('ERROR: Timeout') > 0
def id_check(fn, cmd, args):
- out, err, exitCode = executeCommand(cmd + args)
+ out, err, exitCode = executeCommand(cmd + args + ["-always-verify"])
str = out + err
if not is_timeout(str) and (exitCode != 0 or str.find(ok_string) < 0):
raise Exception(fn + ' identity check fail: ' + str)

MODIFY
tools/alive-tv.cpp
tools/alive-tv.cpp
#include <fstream>
#include <iostream>
+#include <sstream>
#include <utility>
using namespace tools;
@@ -117,6 +118,12 @@ static llvm::cl::opt<bool> opt_print_dot(
llvm::cl::desc("Alive: print .dot files of each function"),
llvm::cl::cat(opt_alive), llvm::cl::init(false));
+static llvm::cl::opt<bool> opt_always_verify(
+ "always-verify",
+ llvm::cl::desc("Alive: verify the pair even if they are syntactically"
+ " equivalent"),
+ llvm::cl::cat(opt_alive), llvm::cl::init(false));
+
static llvm::cl::opt<bool> opt_smt_stats(
"smt-stats", llvm::cl::desc("Show SMT statistics"),
llvm::cl::cat(opt_alive), llvm::cl::init(false));
@@ -306,6 +313,17 @@ static void compareFunctions(llvm::Function &F1, llvm::Function &F2,
Func2->writeDot("tgt");
}
+ if (!opt_always_verify) {
+ stringstream ss1, ss2;
+ Func1->print(ss1);
+ Func2->print(ss2);
+ if (ss1.str() == ss2.str()) {
+ cout << "Transformation seems to be correct! (syntactically equal)\n\n";
+ ++goodCount;
+ return;
+ }
+ }
+
smt_init->reset();
Transform t;
t.src = move(*Func1);

Add syntactic equality check to alive-tv (#653)