Put LLVM IR verification behind a default-disabled flag
Verification can take upwards of 10% of a dEQP test's execution time.
Verification is enabled for Kokoro builds and unit tests as silently regressing would be a Bad Thing.
Verification is also enabled for debug (!NDEBUG) builds.
Bug: b/135609394
Change-Id: I6c354c40f524e1e8f3e08f24129b7e008163b4bd
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/33215
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
index c448aec..1e9ed6e 100644
--- a/.vscode/c_cpp_properties.json
+++ b/.vscode/c_cpp_properties.json
@@ -3,7 +3,8 @@
{
"name": "Linux",
"defines": [
- "ENABLE_RR_DEBUG_INFO=1"
+ "ENABLE_RR_DEBUG_INFO=1",
+ "VERIFY_LLVM_IR=1"
],
"includePath": [
"${workspaceFolder}/src",
@@ -19,7 +20,8 @@
{
"name": "Mac",
"defines": [
- "ENABLE_RR_DEBUG_INFO=1"
+ "ENABLE_RR_DEBUG_INFO=1",
+ "VERIFY_LLVM_IR=1"
],
"includePath": [
"${workspaceFolder}/src",
@@ -35,7 +37,8 @@
{
"name": "Win32",
"defines": [
- "ENABLE_RR_DEBUG_INFO=1"
+ "ENABLE_RR_DEBUG_INFO=1",
+ "VERIFY_LLVM_IR=1"
],
"includePath": [
"${workspaceFolder}/src",
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index 37da9b3..2a7e260 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -69,7 +69,8 @@
"-GNinja",
"-DCMAKE_BUILD_TYPE=${input:buildType}",
"-DWARNINGS_AS_ERRORS=1",
- "-DDCHECK_ALWAYS_ON=1"
+ "-DDCHECK_ALWAYS_ON=1",
+ "-DREACTOR_VERIFY_LLVM_IR=1",
],
"options": {
"cwd": "${workspaceRoot}/build"
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ad6b2cb..087a6d7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -89,6 +89,7 @@
option(DCHECK_ALWAYS_ON "Check validation macros even in release builds" 0)
option(REACTOR_EMIT_DEBUG_INFO "Emit debug info for JIT functions" 0)
option(REACTOR_EMIT_PRINT_LOCATION "Emit printing of location info for JIT functions" 0)
+option(REACTOR_VERIFY_LLVM_IR "Check reactor-generated LLVM IR is valid even in release builds" 0)
if(ARCH STREQUAL "arm")
set(DEFAULT_REACTOR_BACKEND "Subzero")
@@ -464,6 +465,10 @@
list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DENABLE_RR_DEBUG_INFO")
endif()
+if(REACTOR_VERIFY_LLVM_IR)
+ list(APPEND SWIFTSHADER_COMPILE_OPTIONS "-DENABLE_RR_LLVM_IR_VERIFICATION")
+endif()
+
if(WIN32)
add_definitions(-DWINVER=0x501 -DNOMINMAX -DSTRICT)
set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "" "lib")
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp
index d19cf52..a65f843 100644
--- a/src/Reactor/LLVMReactor.cpp
+++ b/src/Reactor/LLVMReactor.cpp
@@ -1051,14 +1051,13 @@
::module->print(file, 0);
}
- // FIXME: Disable for release builds once heavy development is over.
- bool verifyIR = true;
- if(verifyIR)
+#if defined(ENABLE_RR_LLVM_IR_VERIFICATION) || !defined(NDEBUG)
{
llvm::legacy::PassManager pm;
pm.add(llvm::createVerifierPass());
pm.run(*::module);
}
+#endif // defined(ENABLE_RR_LLVM_IR_VERIFICATION) || !defined(NDEBUG)
if(runOptimizations)
{
diff --git a/tests/kokoro/gcp_ubuntu/continuous.sh b/tests/kokoro/gcp_ubuntu/continuous.sh
index e56abe1..bc443c5 100644
--- a/tests/kokoro/gcp_ubuntu/continuous.sh
+++ b/tests/kokoro/gcp_ubuntu/continuous.sh
@@ -15,7 +15,7 @@
REACTOR_BACKEND="LLVM"
fi
-cmake .. "-DREACTOR_BACKEND=${REACTOR_BACKEND}"
+cmake .. "-DREACTOR_BACKEND=${REACTOR_BACKEND}" "-DREACTOR_VERIFY_LLVM_IR=1"
make --jobs=$(nproc)
# Run the reactor unit tests.
diff --git a/tests/kokoro/gcp_windows/continuous.bat b/tests/kokoro/gcp_windows/continuous.bat
index 3e3ca2f..5334068 100644
--- a/tests/kokoro/gcp_windows/continuous.bat
+++ b/tests/kokoro/gcp_windows/continuous.bat
@@ -17,7 +17,7 @@
cd %SRC%\build
if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL!
-cmake .. -G "Visual Studio 15 2017 Win64" -Thost=x64 "-DREACTOR_BACKEND=%REACTOR_BACKEND%"
+cmake .. -G "Visual Studio 15 2017 Win64" -Thost=x64 "-DREACTOR_BACKEND=%REACTOR_BACKEND%" "-DREACTOR_VERIFY_LLVM_IR=1"
if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL!
%MSBUILD% /p:Configuration=%CONFIG% SwiftShader.sln
diff --git a/tests/kokoro/macos/continuous.sh b/tests/kokoro/macos/continuous.sh
index 7aeb0ca..9dc1d85 100755
--- a/tests/kokoro/macos/continuous.sh
+++ b/tests/kokoro/macos/continuous.sh
@@ -15,7 +15,7 @@
REACTOR_BACKEND="LLVM"
fi
-cmake .. "-DASAN=ON -DREACTOR_BACKEND=${REACTOR_BACKEND} -DCMAKE_BUILD_TYPE=RelWithDebInfo"
+cmake .. "-DASAN=ON -DREACTOR_BACKEND=${REACTOR_BACKEND} -DCMAKE_BUILD_TYPE=RelWithDebInfo -DREACTOR_VERIFY_LLVM_IR=1"
make -j$(sysctl -n hw.logicalcpu)
# Run the reactor unit tests.
diff --git a/tests/regres/main.go b/tests/regres/main.go
index 973e635..5de20b3 100644
--- a/tests/regres/main.go
+++ b/tests/regres/main.go
@@ -720,6 +720,7 @@
if err := shell.Shell(buildTimeout, t.r.cmake, t.buildDir,
"-DCMAKE_BUILD_TYPE=Release",
"-DDCHECK_ALWAYS_ON=1",
+ "-DREACTOR_VERIFY_LLVM_IR=1",
".."); err != nil {
return err
}