From 4a266f60462e26884a39a09fb147c351368770ca Mon Sep 17 00:00:00 2001 From: Sebastian Kreutzer Date: Thu, 21 Aug 2025 15:49:27 +0200 Subject: [PATCH 1/3] [NFC] Refactor CGPatch CMake --- CMakeLists.txt | 31 ------------------------------- tools/CMakeLists.txt | 17 +++++++++++++++++ tools/cgpatch/CMakeLists.txt | 14 ++++++++++++-- 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e43a59d2..c7867e80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,25 +110,6 @@ if(METACG_BUILD_CGCOLLECTOR) add_subdirectory(cgcollector) endif() -# Build CGPatch: cgpatch-pass, cgpatch-runtime, wrappers, tests -option( - METACG_BUILD_CGPATCH - "On or off" - OFF -) -if(METACG_BUILD_CGPATCH) - if(NOT METACG_BUILD_GRAPH_TOOLS) - message(FATAL_ERROR "CGPatch requires to build with METACG_BUILD_GRAPH_TOOLS=ON") - endif() - if(${LLVM_PACKAGE_VERSION} - GREATER - 14 - ) - add_subdirectory(tools/cgpatch/) - else() - message(STATUS "Skipping CGPatch: requires LLVM version 15 or higher") - endif() -endif() # PIRA analyzer Should PGIS be built option( METACG_BUILD_PGIS @@ -155,18 +136,6 @@ option( OFF ) -# Enable MPI for CGPatch -option( - CGPATCH_USE_MPI - "On or Off" - ON -) - -if(METACG_BUILD_CGPATCH AND CGPATCH_USE_MPI) - find_package(MPI REQUIRED) - message(STATUS "MPI VERSION: ${MPI_C_VERSION}") -endif() - # Build MetaCG's Python interface option( METACG_BUILD_PYMETACG diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 01f07f11..c7fb4a3c 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,3 +1,20 @@ +# Build CGPatch: cgpatch-pass, cgpatch-runtime, wrappers, tests +option( + METACG_BUILD_CGPATCH + "On or off" + OFF +) +if(METACG_BUILD_CGPATCH) + if(${LLVM_PACKAGE_VERSION} + GREATER + 14 + ) + add_subdirectory(cgpatch) + else() + message(WARNING "Skipping CGPatch: requires LLVM version 15 or higher") + endif() +endif() + add_subdirectory(cgmerge2) add_subdirectory(cgconvert) add_subdirectory(cgformat) diff --git a/tools/cgpatch/CMakeLists.txt b/tools/cgpatch/CMakeLists.txt index 36232b49..ed821f43 100644 --- a/tools/cgpatch/CMakeLists.txt +++ b/tools/cgpatch/CMakeLists.txt @@ -1,7 +1,17 @@ -project(CGPatch) - include(GNUInstallDirs) +# Enable MPI for CGPatch +option( + CGPATCH_USE_MPI + "On or Off" + ON +) + +if(CGPATCH_USE_MPI) + find_package(MPI REQUIRED) + message(STATUS "MPI VERSION: ${MPI_C_VERSION}") +endif() + # LLVM option( USE_FNO_RTTI From 5737d7625e88df44fd3c2eb8150f1f2637e3fb5e Mon Sep 17 00:00:00 2001 From: Sebastian Kreutzer Date: Thu, 21 Aug 2025 16:04:20 +0200 Subject: [PATCH 2/3] Add MPI include directories to CGPatch runtime --- tools/cgpatch/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/cgpatch/CMakeLists.txt b/tools/cgpatch/CMakeLists.txt index ed821f43..9b1962b5 100644 --- a/tools/cgpatch/CMakeLists.txt +++ b/tools/cgpatch/CMakeLists.txt @@ -43,6 +43,7 @@ foreach(tgt cgpatch-call-analysis cgpatch-inst-pass) endforeach() if(CGPATCH_USE_MPI) + target_include_directories(cgpatch-runtime PRIVATE ${MPI_C_INCLUDE_DIRS}) target_compile_definitions(cgpatch-runtime PRIVATE USE_MPI=1) endif() From f80a3a0769524b273d755820edcad7951ca6f03c Mon Sep 17 00:00:00 2001 From: "silas.martens" Date: Mon, 1 Sep 2025 21:38:50 +0200 Subject: [PATCH 3/3] Fix integration tests --- .../test/integration/CGPIntegrationRunner.sh.in | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/cgpatch/test/integration/CGPIntegrationRunner.sh.in b/tools/cgpatch/test/integration/CGPIntegrationRunner.sh.in index baa8f6f7..2049fb51 100755 --- a/tools/cgpatch/test/integration/CGPIntegrationRunner.sh.in +++ b/tools/cgpatch/test/integration/CGPIntegrationRunner.sh.in @@ -53,6 +53,13 @@ cgmerge2Exe="$buildDir/tools/cgmerge2/cgmerge2" outputDir=$buildDir/tools/cgpatch/test/integration +if [ "$CGPATCH_USE_MPI" == "ON" ]; then + compiler=mpicxx +else + compiler=clang++ +fi + + if [ ! -d "${logDir}" ]; then mkdir "${logDir}" fi @@ -71,14 +78,14 @@ function build_and_run_mpi_testcase { local testDir="$3" local testExe="$outputDir/${testName}.out" local testPG="$outputDir/${testName}.pg" - local testGT="$test_root/input/mpi/{testName}.gtpg" + local testGT="$test_root/input/mpi/${testName}.gtpg" local testMCG="$outputDir/${testName}.mcg" - local testSCG="$test_root/input/general/${testName}.ipcg" + local testSCG="$test_root/input/mpi/${testName}.ipcg" export CGPATCH_CG_NAME="${testPG}" log "Compiling MPI testcase: $testSources" - $cgpatchExe mpicxx $testSources -o "$testExe" >> "$logFile" + $cgpatchExe $compiler $testSources -o "$testExe" >> "$logFile" if [ $? -ne 0 ]; then echo "Compilation failed for $testName" fails=$((fails + 1)) @@ -109,7 +116,7 @@ function build_and_run_regular_testcase { export CGPATCH_CG_NAME="${testPG}" log "Compiling regular testcase: $testSources" - $cgpatchExe clang++ $testSources -o "$testExe" >> "$logFile" + $cgpatchExe $compiler $testSources -o "$testExe" >> "$logFile" if [ $? -ne 0 ]; then echo "Compilation failed for $testName" fails=$((fails + 1))