Add an argument that makes an array initializer omitted if it has more than the given number of elements
MODIFY
llvm_util/llvm2alive.cpp
llvm_util/llvm2alive.cpp
@@ -978,6 +978,11 @@ public:
if (!gv->isConstant() || !gv->hasDefinitiveInitializer())
continue;
+ auto *init_ty = gv->getInitializer()->getType();
+ if (init_ty->isArrayTy() &&
+ init_ty->getArrayNumElements() > omit_array_size)
+ continue;
+
auto storedval = get_operand(gv->getInitializer());
if (!storedval) {
*out << "ERROR: Unsupported constant: " << *gv->getInitializer()
@@ -1005,6 +1010,9 @@ public:
namespace llvm_util {
+unsigned omit_array_size = -1;
+
+
initializer::initializer(ostream &os, const llvm::DataLayout &DL) {
out = &os;
init_llvm_utils(os, DL);

MODIFY
llvm_util/llvm2alive.h
llvm_util/llvm2alive.h
@@ -17,6 +17,11 @@ class TargetLibraryInfo;
namespace llvm_util {
+// The maximum number of elements of an array initializer to explicitly store.
+// If longer, the initializer will simply be omitted.
+extern unsigned omit_array_size;
+
+
struct initializer {
initializer(std::ostream &os, const llvm::DataLayout &DL);
};

RENAME
tests/alive-tv/glbconstchk.src.ll
tests/alive-tv/globals/glbconstchk.src.ll
RENAME
tests/alive-tv/glbconstchk.tgt.ll
tests/alive-tv/globals/glbconstchk.tgt.ll
RENAME
tests/alive-tv/glbconstchk2.src.ll
tests/alive-tv/globals/glbconstchk2.src.ll
RENAME
tests/alive-tv/glbconstchk2.tgt.ll
tests/alive-tv/globals/glbconstchk2.tgt.ll
RENAME
tests/alive-tv/glbsizechk.src.ll
tests/alive-tv/globals/glbsizechk.src.ll
RENAME
tests/alive-tv/glbsizechk.tgt.ll
tests/alive-tv/globals/glbsizechk.tgt.ll
RENAME
tests/alive-tv/globalopt.src.ll
tests/alive-tv/globals/globalopt.src.ll
RENAME
tests/alive-tv/globalopt.tgt.ll
tests/alive-tv/globals/globalopt.tgt.ll
ADD
tests/alive-tv/params/omit-array.srctgt.ll
+; TEST-ARGS: -omit-array-size=140
+@s = constant [141 x i8] c"1111111111111111111122222222222222222222333333333333333333334444444444444444444455555555555555555555666666666666666666677777777777777777777\0"
+
+define i8 @src() {
+ %p = bitcast [141 x i8]* @s to i8*
+ %one = load i8, i8* %p
+ ret i8 %one
+}
+
+define i8 @tgt() {
+ %p = bitcast [141 x i8]* @s to i8*
+ %one = load i8, i8* %p
+ ret i8 %one
+}

MODIFY
tools/alive-tv.cpp
tools/alive-tv.cpp
@@ -88,6 +88,12 @@ static llvm::cl::opt<bool> opt_succinct(
"succinct", llvm::cl::desc("Make the output succinct"),
llvm::cl::cat(opt_alive), llvm::cl::init(false));
+static llvm::cl::opt<unsigned> opt_omit_array_size(
+ "omit-array-size",
+ llvm::cl::desc("Omit an array initializer if it has elements more than "
+ "this number"),
+ llvm::cl::cat(opt_alive), llvm::cl::init(-1));
+
static llvm::cl::opt<unsigned> opt_max_mem(
"max-mem", llvm::cl::desc("Max memory (approx)"),
llvm::cl::cat(opt_alive), llvm::cl::init(1024), llvm::cl::value_desc("MB"));
@@ -234,6 +240,8 @@ static void compareFunctions(llvm::Function &F1, llvm::Function &F2,
TransformPrintOpts print_opts;
+ omit_array_size = opt_omit_array_size;
+
auto Func1 = llvm2alive(F1, llvm::TargetLibraryInfoWrapperPass(targetTriple)
.getTLI(F1));
if (!Func1) {

MODIFY
tv/tv.cpp
tv/tv.cpp
@@ -93,6 +93,12 @@ llvm::cl::opt<bool> opt_debug(
llvm::cl::desc("Alive: Show debug data"),
llvm::cl::init(false), llvm::cl::Hidden);
+llvm::cl::opt<unsigned> opt_omit_array_size(
+ "tv-omit-array-size",
+ llvm::cl::desc("Omit an array initializer if it has elements more than "
+ "this number"),
+ llvm::cl::init(-1));
+
ostream *out;
ofstream out_file;
string report_filename;
@@ -234,6 +240,7 @@ struct TVPass final : public llvm::FunctionPass {
config::disable_undef_input = opt_disable_undef_input;
config::disable_poison_input = opt_disable_poison_input;
config::debug = opt_debug;
+ llvm_util::omit_array_size = opt_omit_array_size;
llvm_util_init.emplace(*out, module.getDataLayout());
smt_init.emplace();

Add an argument that makes an array initializer omitted if it has more than the given number of elements (#354)