Skip to content

Commit 172a536

Browse files
committed
Build a dedicated fir-test-opt for testing
Rather than having different passes inside `fir-opt` depending on the value of `FLANG_INCLUDE_TESTS`, build two separate executables: regular `fir-opt` tool that is going to be installed, and a `fir-test-opt` to be used in the test suite. This ensures that `fir-opt` behaves consistently independently of `FLANG_INCLUDE_TESTS` value used during the build, and a test-enabled build can be used on production. Fixes #121202
1 parent 6dc356d commit 172a536

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

flang/tools/fir-opt/CMakeLists.txt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@ llvm_update_compile_flags(fir-opt)
33
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
44
get_property(extension_libs GLOBAL PROPERTY MLIR_EXTENSION_LIBS)
55

6-
if(FLANG_INCLUDE_TESTS)
7-
set(test_libs
8-
FIRTestAnalysis
9-
FIRTestOpenACCInterfaces
10-
MLIRTestIR
11-
)
12-
endif()
6+
add_library(fir-opt-common INTERFACE)
7+
target_link_libraries(fir-opt PRIVATE fir-opt-common)
138

14-
target_link_libraries(fir-opt PRIVATE
9+
target_link_libraries(fir-opt-common INTERFACE
1510
CUFAttrs
1611
CUFDialect
1712
FIRDialect
@@ -23,10 +18,9 @@ target_link_libraries(fir-opt PRIVATE
2318
FIROpenACCSupport
2419
FlangOpenMPTransforms
2520
FIRAnalysis
26-
${test_libs}
2721
)
2822

29-
mlir_target_link_libraries(fir-opt PRIVATE
23+
mlir_target_link_libraries(fir-opt-common INTERFACE
3024
${dialect_libs}
3125
${extension_libs}
3226

@@ -45,3 +39,15 @@ mlir_target_link_libraries(fir-opt PRIVATE
4539
MLIRVectorToLLVM
4640
MLIROptLib
4741
)
42+
43+
if(FLANG_INCLUDE_TESTS)
44+
add_flang_executable(fir-test-opt fir-opt.cpp)
45+
llvm_update_compile_flags(fir-test-opt)
46+
target_compile_definitions(fir-test-opt PRIVATE FIR_TEST_OPT)
47+
target_link_libraries(fir-test-opt PRIVATE
48+
fir-opt-common
49+
FIRTestAnalysis
50+
FIRTestOpenACCInterfaces
51+
MLIRTestIR
52+
)
53+
endif()

flang/tools/fir-opt/fir-opt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int main(int argc, char **argv) {
3737
fir::registerOptTransformPasses();
3838
hlfir::registerHLFIRPasses();
3939
flangomp::registerFlangOpenMPPasses();
40-
#ifdef FLANG_INCLUDE_TESTS
40+
#ifdef FIR_TEST_OPT
4141
fir::test::registerTestFIRAliasAnalysisPass();
4242
fir::test::registerTestFIROpenACCInterfacesPass();
4343
mlir::registerSideEffectTestPasses();

0 commit comments

Comments
 (0)