make redis optional
MODIFY
.github/workflows/build.yml
.github/workflows/build.yml
@@ -17,11 +17,11 @@ jobs:
- os: ubuntu-22.04
compiler: g++-11
build_type: Release
- cache: redis
+ cache: Redis
- os: ubuntu-22.04
compiler: g++-11
build_type: Debug
- cache: redis
+ cache: Redis
- os: macos-12
compiler: clang++
build_type: Release
@@ -51,7 +51,7 @@ jobs:
if [[ ${{ matrix.compiler }} == "clang++-16" ]]; then
sudo apt-get install clang++-16
fi
- if [[ ${{ matrix.cache }} == "redis" ]]; then
+ if [[ ${{ matrix.cache }} == "Redis" ]]; then
sudo apt-get install libhiredis-dev
fi

MODIFY
CMakeLists.txt
CMakeLists.txt
@@ -125,9 +125,9 @@ add_library(tools STATIC ${TOOLS_SRCS})
set(UTIL_SRCS
"${PROJECT_BINARY_DIR}/version_gen.h"
- util/version.cpp
util/compiler.cpp
util/config.cpp
+ util/crc.cpp
util/errors.cpp
util/file.cpp
util/parallel.cpp
@@ -139,6 +139,7 @@ set(UTIL_SRCS
util/stopwatch.cpp
util/symexec.cpp
util/unionfind.cpp
+ util/version.cpp
)
add_library(util STATIC ${UTIL_SRCS})
@@ -146,6 +147,20 @@ add_dependencies(util generate_version)
set(ALIVE_LIBS ir smt tools util)
+find_package(hiredis)
+if (HIREDIS_LIBRARIES)
+ include_directories(${HIREDIS_INCLUDE_DIR})
+
+ set(CACHE_SRCS
+ cache/cache.cpp
+ )
+ add_library(cache STATIC ${CACHE_SRCS})
+ string(APPEND ALIVE_LIBS cache)
+else()
+ set(HIREDIS_LIBRARIES $<0:''>)
+ add_compile_definitions(NO_REDIS_SUPPORT)
+endif()
+
if (BUILD_LLVM_UTILS OR BUILD_TV)
find_package(LLVM REQUIRED CONFIG)
@@ -167,12 +182,7 @@ if (BUILD_LLVM_UTILS OR BUILD_TV)
include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
- find_package(hiredis REQUIRED)
- include_directories(${HIREDIS_INCLUDE_DIR})
-
set(LLVM_UTIL_SRCS
- "llvm_util/cache.cpp"
- "llvm_util/crc.cpp"
"llvm_util/known_fns.cpp"
"llvm_util/llvm_optimizer.cpp"
"llvm_util/llvm2alive.cpp"
@@ -233,25 +243,12 @@ add_executable(alive-jobserver
if (BUILD_LLVM_UTILS OR BUILD_TV)
llvm_map_components_to_libnames(llvm_libs support core irreader analysis passes transformutils)
# target_link_libraries(alive2 PRIVATE ${llvm_libs})
- target_link_libraries(alive-tv PRIVATE ${ALIVE_LIBS_LLVM} ${llvm_libs})
- target_link_libraries(alive-exec PRIVATE ${ALIVE_LIBS_LLVM} ${llvm_libs})
+ target_link_libraries(alive-tv PRIVATE ${ALIVE_LIBS_LLVM} ${Z3_LIBRARIES} ${HIREDIS_LIBRARIES} ${llvm_libs})
+ target_link_libraries(alive-exec PRIVATE ${ALIVE_LIBS_LLVM} ${Z3_LIBRARIES} ${HIREDIS_LIBRARIES} ${llvm_libs})
endif()
-if (CYGWIN)
- # cmake on cygwin doesn't seem to know about dlls..
- get_filename_component(Z3_LIB_DIR "${Z3_LIBRARIES}" DIRECTORY)
- get_filename_component(HIREDIS_LIB_DIR "${HIREDIS_LIBRARIES}" DIRECTORY)
- set(CMAKE_EXE_LINKER_FLAGS "-L${Z3_LIB_DIR} -lz3 -L${HIREDIS_LIB_DIR} -lhiredis")
- set(CMAKE_SHARED_LINKER_FLAGS "-L${Z3_LIB_DIR} -lz3 -L${HIREDIS_LIB_DIR} -lhiredis")
- file(COPY "${Z3_LIBRARIES} ${HIREDIS_LIBRARIES}" DESTINATION "${PROJECT_BINARY_DIR}")
-else()
target_link_libraries(alive PRIVATE ${Z3_LIBRARIES} ${HIREDIS_LIBRARIES})
#target_link_libraries(alive2 PRIVATE ${Z3_LIBRARIES} ${HIREDIS_LIBRARIES})
- if (BUILD_LLVM_UTILS OR BUILD_TV)
- target_link_libraries(alive-tv PRIVATE ${Z3_LIBRARIES} ${HIREDIS_LIBRARIES})
- target_link_libraries(alive-exec PRIVATE ${Z3_LIBRARIES} ${HIREDIS_LIBRARIES})
- endif()
-endif()
if (NOT DEFINED TEST_NTHREADS)
ProcessorCount(TEST_NTHREADS)

RENAME
llvm_util/cache.cpp
cache/cache.cpp
+// Copyright (c) 2018-present The Alive2 Authors.
+// Distributed under the MIT license that can be found in the LICENSE file.
+
#include "cache.h"
-#include "crc.h"
-#include "util/errors.h"
+#include "util/crc.h"
#include "util/version.h"
-
#include <cassert>
+#include <hiredis/hiredis.h>
#include <iostream>
-#include <sstream>
#include <string>
-#include <vector>
using namespace std;
-static string redis_reply_string(int reply_type) {
+static const char* redis_reply_string(int reply_type) {
switch (reply_type) {
case REDIS_REPLY_STRING:
return "STRING";
@@ -97,15 +97,15 @@ Cache::Cache(unsigned port, bool allow_version_mismatch) {
exit(-1);
}
if (ctx->err) {
- cerr << "Redis connection error: " << ctx->errstr << "\n";
+ cerr << "Redis connection error: " << ctx->errstr << '\n';
exit(-1);
}
string version;
if (remote_get("Alive2_version", version, ctx)) {
if (version != util::alive_version) {
- cerr << "Cache version mismatch!\n";
- cerr << "This version of Alive2 is " << util::alive_version << "\n";
- cerr << "But the cache was created by version " << version << "\n";
+ cerr << "Cache version mismatch!\n"
+ "This version of Alive2 is " << util::alive_version << "\n"
+ "But the cache was created by version " << version << '\n';
if (!allow_version_mismatch)
exit(-1);
}
@@ -114,7 +114,6 @@ Cache::Cache(unsigned port, bool allow_version_mismatch) {
}
}
-
Cache::~Cache() {
redisFree(ctx);
}

RENAME
llvm_util/cache.h
cache/cache.h
#pragma once
-#include <hiredis/hiredis.h>
-#include <memory>
+// Copyright (c) 2018-present The Alive2 Authors.
+// Distributed under the MIT license that can be found in the LICENSE file.
+
#include <string>
-#include <string_view>
+
+struct redisContext;
class Cache {
redisContext *ctx = nullptr;
public:
Cache(unsigned port, bool allow_version_mismatch);
+#ifndef NO_REDIS_SUPPORT
~Cache();
+#endif
bool lookup(const std::string &s);
};

MODIFY
cmake/Findhiredis.cmake
cmake/Findhiredis.cmake
find_path(HIREDIS_INCLUDE_DIR NAMES hiredis/hiredis.h)
find_library(HIREDIS_LIBRARIES NAMES hiredis)
-if(NOT HIREDIS_INCLUDE_DIR)
- message(FATAL_ERROR "hiredis include directory not found")
-endif()
-
-if(NOT HIREDIS_LIBRARIES)
- message(FATAL_ERROR "hiredis library not found")
-endif()
-
message(STATUS "hiredis: ${HIREDIS_INCLUDE_DIR} ${HIREDIS_LIBRARIES}")

MODIFY
llvm_util/cmd_args_def.h
llvm_util/cmd_args_def.h
@@ -78,3 +78,13 @@ if (!opt_outputfile.empty()) {
}
util::config::set_debug(*out);
+
+
+if (opt_cache) {
+#ifdef NO_REDIS_SUPPORT
+ cerr << "REDIS support not compiled in!\n";
+ exit(1);
+#else
+ cache = make_unique<Cache>(opt_cache_port, opt_cache_allow_version_mismatch);
+#endif
+}

MODIFY
tools/alive-exec.cpp
tools/alive-exec.cpp
@@ -83,7 +83,7 @@ void execFunction(llvm::Function &F, llvm::TargetLibraryInfoWrapperPass &TLI,
t.src = std::move(*Func);
t.tgt = *llvm2alive(F, TLI.getTLI(F), false);
t.preprocess();
- TransformVerify verifier(t, false, nullptr);
+ TransformVerify verifier(t, nullptr, false);
if (!opt_quiet)
t.src.print(cout << "\n----------------------------------------\n");

MODIFY
tools/alive-tv.cpp
tools/alive-tv.cpp
// Copyright (c) 2018-present The Alive2 Authors.
// Distributed under the MIT license that can be found in the LICENSE file.
-#include "llvm_util/cache.h"
+#include "cache/cache.h"
#include "llvm_util/llvm2alive.h"
#include "llvm_util/llvm_optimizer.h"
#include "smt/smt.h"
@@ -88,6 +88,7 @@ std::unique_ptr<llvm::Module> openInputFile(llvm::LLVMContext &Context,
}
optional<smt::smt_initializer> smt_init;
+unique_ptr<Cache> cache;
struct Results {
Transform t;
@@ -110,8 +111,6 @@ struct Results {
}
};
-static unique_ptr<Cache> cache;
-
Results verify(llvm::Function &F1, llvm::Function &F2,
llvm::TargetLibraryInfoWrapperPass &TLI,
bool print_transform = false,
@@ -144,7 +143,7 @@ Results verify(llvm::Function &F1, llvm::Function &F2,
smt_init->reset();
r.t.preprocess();
- TransformVerify verifier(r.t, false, &*cache);
+ TransformVerify verifier(r.t, cache.get(), false);
if (print_transform)
r.t.print(*out, {});
@@ -299,10 +298,6 @@ convenient way to demonstrate an existing optimizer bug.
llvm::cl::HideUnrelatedOptions(alive_cmdargs);
llvm::cl::ParseCommandLineOptions(argc, argv, Usage);
- if (opt_cache)
- cache = make_unique<Cache>(opt_cache_port,
- opt_cache_allow_version_mismatch);
-
auto M1 = openInputFile(Context, opt_file1);
if (!M1.get()) {
cerr << "Could not read bitcode from '" << opt_file1 << "'\n";

MODIFY
tools/alive.cpp
tools/alive.cpp
@@ -116,7 +116,7 @@ int main(int argc, char **argv) {
t.print(cout, print_opts);
cout << '\n';
- TransformVerify tv(t, !root_only, nullptr);
+ TransformVerify tv(t, nullptr, !root_only);
auto types = tv.getTypings();
if (!types) {
cerr << "Doesn't type check!\n";

MODIFY
tools/transform.cpp
tools/transform.cpp
@@ -1094,9 +1094,9 @@ static void calculateAndInitConstants(Transform &t) {
namespace tools {
-TransformVerify::TransformVerify(Transform &t, bool check_each_var,
- Cache *cache) :
- t(t), check_each_var(check_each_var), cache(cache) {
+TransformVerify::TransformVerify(Transform &t, Cache *cache,
+ bool check_each_var)
+ : t(t), cache(cache), check_each_var(check_each_var) {
if (check_each_var) {
for (auto &i : t.tgt.instrs()) {
tgt_instrs.emplace(i.getName(), &i);

MODIFY
tools/transform.h
tools/transform.h
@@ -52,11 +52,11 @@ public:
class TransformVerify {
Transform &t;
std::unordered_map<std::string, const IR::Instr*> tgt_instrs;
- bool check_each_var;
Cache *cache;
+ bool check_each_var;
public:
- TransformVerify(Transform &t, bool check_each_var, Cache *cache);
+ TransformVerify(Transform &t, Cache *cache, bool check_each_var);
std::pair<std::unique_ptr<IR::State>,std::unique_ptr<IR::State>> exec() const;
util::Errors verify() const;
TypingAssignments getTypings() const;

MODIFY
tv/CMakeLists.txt
tv/CMakeLists.txt
-# add_llvm_loadable_module was removed in https://reviews.llvm.org/D51748
-if (COMMAND add_llvm_loadable_module)
- add_llvm_loadable_module(tv tv.cpp)
-else()
add_llvm_library(tv MODULE tv.cpp)
-endif()
configure_file(
${CMAKE_SOURCE_DIR}/scripts/alivecc.in
@@ -26,8 +21,7 @@ configure_file(
@ONLY
)
-target_link_libraries(tv PRIVATE ${ALIVE_LIBS_LLVM} ${Z3_LIBRARIES} ${HIREDIS_LIBRARIES}
- $<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:stdc++fs>)
+target_link_libraries(tv PRIVATE ${ALIVE_LIBS_LLVM} ${Z3_LIBRARIES} ${HIREDIS_LIBRARIES})
if(APPLE)
set_target_properties(tv PROPERTIES

MODIFY
tv/tv.cpp
tv/tv.cpp
// Copyright (c) 2018-present The Alive2 Authors.
// Distributed under the MIT license that can be found in the LICENSE file.
+#include "cache/cache.h"
#include "ir/memory.h"
-#include "llvm_util/cache.h"
#include "llvm_util/llvm2alive.h"
#include "llvm_util/utils.h"
#include "smt/smt.h"
@@ -257,7 +257,7 @@ struct TVLegacyPass final : public llvm::ModulePass {
// to do this before forking. Anyway, this is fast.
if (cache && cache->lookup(src_tostr + "===\n" + tgt_tostr)) {
*out << "Skipping repeated query\n\n";
- return false;
+ return;
}
if (parallelMgr) {
@@ -304,7 +304,7 @@ struct TVLegacyPass final : public llvm::ModulePass {
smt_init->reset();
t.preprocess();
- TransformVerify verifier(t, false, &*cache);
+ TransformVerify verifier(t, cache.get(), false);
if (!opt_quiet)
t.print(*out, print_opts);
@@ -377,10 +377,6 @@ struct TVLegacyPass final : public llvm::ModulePass {
}
}
- if (opt_cache)
- cache = make_unique<Cache>(opt_cache_port,
- opt_cache_allow_version_mismatch);
-
showed_stats = false;
llvm_util_init.emplace(*out, module.getDataLayout());
smt_init.emplace();

RENAME
llvm_util/crc.cpp
util/crc.cpp
RENAME
llvm_util/crc.h
util/crc.h
make redis optional