Skip to content

[Flang-RT] Make implicit PPC intrinsic uses explicit - #206493

Merged
Meinersbur merged 4 commits into
llvm:mainfrom
Meinersbur:flangrt_ppc-implicit-deps
Jun 29, 2026
Merged

[Flang-RT] Make implicit PPC intrinsic uses explicit#206493
Meinersbur merged 4 commits into
llvm:mainfrom
Meinersbur:flangrt_ppc-implicit-deps

Conversation

@Meinersbur

@Meinersbur Meinersbur commented Jun 29, 2026

Copy link
Copy Markdown
Member

The PPC-specific builtin moduls have implicit dependencies insert by flang. For CMake to correctly setup the build order, they must be made explicit.

This replicates the implicit module uses from

} else if (frontModule &&
std::get<parser::Statement<parser::ModuleStmt>>(frontModule->value().t)
.statement.v.source == "__ppc_types") {
// Don't try to read the UsePPCBuiltinTypesModule() we are currently
// building, but __fortran_builtins is needed to build it.
context_.UseFortranBuiltinsModule();
} else if (frontModule &&
(std::get<parser::Statement<parser::ModuleStmt>>(frontModule->value().t)
.statement.v.source == "__ppc_intrinsics" ||
std::get<parser::Statement<parser::ModuleStmt>>(
frontModule->value().t)
.statement.v.source == "mma")) {
// The derived type definition for the vectors is needed.
context_.UsePPCBuiltinTypesModule();

in the modules themselves. The PPC-specific modules compiled by Flang-RT are listed here:
if (LLVM_TARGET_TRIPLE MATCHES "^ppc|^powerpc")
list(APPEND module_sources
__ppc_types.f90
__ppc_intrinsics.f90
mma.f90
)
endif ()

This should fix the intermittend build error mentioned in #205634 (comment). Unfortunately I do not have a PowerPC (cross-)compilation build environment ready to test, nor does the Premerge-CI build it.

@kkwli

kkwli commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for a quick fix. Let me try it.

@kkwli

kkwli commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

I still various errors in a scratch build.

[123/197] Building Fortran object flang-r...keFiles/flang-rt-mod.dir/cudadevice.f90.o
FAILED: flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/cudadevice.f90.o /scratch/kli/wrk/f/build-flang-local/lib/clang/23/finclude/flang/powerpc64le-unknown-linux-gnu/cudadevice.mod 
/scratch/kli/wrk/f/build-flang-local/./bin/flang --target=powerpc64le-unknown-linux-gnu -I/scratch/kli/llvm-project/flang-rt/lib/runtime -I/scratch/kli/llvm-project/flang-rt/include -I/scratch/kli/llvm-project/flang-rt/../flang/include -I/scratch/kli/wrk/f/build-flang-local/runtimes/runtimes-bins/flang-rt -I/scratch/kli/llvm-project/cmake/Modules/../../libc -O3 -module-dir/scratch/kli/wrk/f/build-flang-local/lib/clang/23/finclude/flang/powerpc64le-unknown-linux-gnu -fPIC -cpp -mmlir -ignore-missing-type-desc -fno-lto -fintrinsic-modules-path=/scratch/kli/wrk/f/build-flang-local/lib/clang/23/finclude/flang/powerpc64le-unknown-linux-gnu -Xflang -fno-reformat --offload-host-only -xcuda -ffixed-line-length-72 -c flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/cudadevice.f90-pp.f90 -o flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/cudadevice.f90.o
error: Semantic errors in flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/cudadevice.f90-pp.f90
error: Cannot read required CUDA intrinsic module '__cuda_builtins'; check -fintrinsic-modules-path or rebuild the Fortran intrinsic modules
[132/197] Building Fortran object flang-r...s/flang-rt-mod.dir/__ppc_intrinsics.f90.o
FAILED: flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/__ppc_intrinsics.f90.o /scratch/kli/wrk/f/build-flang-local/lib/clang/23/finclude/flang/powerpc64le-unknown-linux-gnu/__ppc_intrinsics.mod 
/scratch/kli/wrk/f/build-flang-local/./bin/flang --target=powerpc64le-unknown-linux-gnu -I/scratch/kli/llvm-project/flang-rt/lib/runtime -I/scratch/kli/llvm-project/flang-rt/include -I/scratch/kli/llvm-project/flang-rt/../flang/include -I/scratch/kli/wrk/f/build-flang-local/runtimes/runtimes-bins/flang-rt -I/scratch/kli/llvm-project/cmake/Modules/../../libc -O3 -module-dir/scratch/kli/wrk/f/build-flang-local/lib/clang/23/finclude/flang/powerpc64le-unknown-linux-gnu -fPIC -cpp -mmlir -ignore-missing-type-desc -fno-lto -fintrinsic-modules-path=/scratch/kli/wrk/f/build-flang-local/lib/clang/23/finclude/flang/powerpc64le-unknown-linux-gnu -Xflang -fno-reformat -ffixed-line-length-72 -c flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/__ppc_intrinsics.f90-pp.f90 -o flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/__ppc_intrinsics.f90.o
error: Could not parse flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/__ppc_intrinsics.f90-pp.f90
flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/__ppc_intrinsics.f90-pp.f90:2:23: error: expected ', ONLY :'
  use __fortran_builtins, __ppc_types
                        ^
flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/__ppc_intrinsics.f90-pp.f90:2:1: in the context: declaration construct
  use __fortran_builtins, __ppc_types
  ^
flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/__ppc_intrinsics.f90-pp.f90:1:1: in the context: module
  module __ppc_intrinsics
  ^
[133/197] Building Fortran object flang-r...ime/CMakeFiles/flang-rt-mod.dir/mma.f90.o
FAILED: flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/mma.f90.o /scratch/kli/wrk/f/build-flang-local/lib/clang/23/finclude/flang/powerpc64le-unknown-linux-gnu/mma.mod 
/scratch/kli/wrk/f/build-flang-local/./bin/flang --target=powerpc64le-unknown-linux-gnu -I/scratch/kli/llvm-project/flang-rt/lib/runtime -I/scratch/kli/llvm-project/flang-rt/include -I/scratch/kli/llvm-project/flang-rt/../flang/include -I/scratch/kli/wrk/f/build-flang-local/runtimes/runtimes-bins/flang-rt -I/scratch/kli/llvm-project/cmake/Modules/../../libc -O3 -module-dir/scratch/kli/wrk/f/build-flang-local/lib/clang/23/finclude/flang/powerpc64le-unknown-linux-gnu -fPIC -cpp -mmlir -ignore-missing-type-desc -fno-lto -fintrinsic-modules-path=/scratch/kli/wrk/f/build-flang-local/lib/clang/23/finclude/flang/powerpc64le-unknown-linux-gnu -Xflang -fno-reformat -ffixed-line-length-72 -c flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/mma.f90-pp.f90 -o flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/mma.f90.o
error: Could not parse flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/mma.f90-pp.f90
flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/mma.f90-pp.f90:2:23: error: expected ', ONLY :'
  use __fortran_builtins, __ppc_types
                        ^
flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/mma.f90-pp.f90:2:1: in the context: declaration construct
  use __fortran_builtins, __ppc_types
  ^
flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/mma.f90-pp.f90:1:1: in the context: module
  module mma
  ^
flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/mma.f90-pp.f90:3:14: error: IMPLICIT statements must follow USE and IMPORT and precede all other declarations
  implicit none
               ^
flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/mma.f90-pp.f90:3:1: in the context: declaration construct
  implicit none
  ^
flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/mma.f90-pp.f90:2:1: in the context: specification part
  use __fortran_builtins, __ppc_types
  ^
[185/197] Building CXX object flang-rt/li...g_rt.runtime.dir/extrema-minloc-dim.cpp.o
ninja: build stopped: subcommand failed.

Comment thread flang-rt/lib/runtime/__ppc_intrinsics.f90 Outdated
@kkwli

kkwli commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

After the fix of the syntax issue, I still see this error:

[118/197] Building Fortran object flang-r...keFiles/flang-rt-mod.dir/cudadevice.f90.o
FAILED: flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/cudadevice.f90.o /scratch/kli/wrk/f/build-flang-local/lib/clang/23/finclude/flang/powerpc64le-unknown-linux-gnu/cudadevice.mod 
/scratch/kli/wrk/f/build-flang-local/./bin/flang --target=powerpc64le-unknown-linux-gnu -I/scratch/kli/llvm-project/flang-rt/lib/runtime -I/scratch/kli/llvm-project/flang-rt/include -I/scratch/kli/llvm-project/flang-rt/../flang/include -I/scratch/kli/wrk/f/build-flang-local/runtimes/runtimes-bins/flang-rt -I/scratch/kli/llvm-project/cmake/Modules/../../libc -O3 -module-dir/scratch/kli/wrk/f/build-flang-local/lib/clang/23/finclude/flang/powerpc64le-unknown-linux-gnu -fPIC -cpp -mmlir -ignore-missing-type-desc -fno-lto -fintrinsic-modules-path=/scratch/kli/wrk/f/build-flang-local/lib/clang/23/finclude/flang/powerpc64le-unknown-linux-gnu -Xflang -fno-reformat --offload-host-only -xcuda -ffixed-line-length-72 -c flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/cudadevice.f90-pp.f90 -o flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/cudadevice.f90.o
error: Semantic errors in flang-rt/lib/runtime/CMakeFiles/flang-rt-mod.dir/cudadevice.f90-pp.f90
error: Cannot read required CUDA intrinsic module '__cuda_builtins'; check -fintrinsic-modules-path or rebuild the Fortran intrinsic modules

@Meinersbur

Meinersbur commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

@kkwli This was fixed in #205895. Unfortunately this PR was based on a sha1 before that. I just updated the branch.

Comment thread flang-rt/lib/runtime/__ppc_intrinsics.f90 Outdated

@DanielCChen DanielCChen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Thanks!

@kkwli kkwli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG. I tried several scratch builds. The intermittent failure no longer appears. Thanks.

@eugeneepshteyn eugeneepshteyn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Meinersbur
Meinersbur merged commit c4bb83e into llvm:main Jun 29, 2026
11 checks passed
LouisLu060211 pushed a commit to LouisLu060211/llvm-project that referenced this pull request Jun 30, 2026
The PPC-specific builtin moduls have implicit dependencies insert by
flang. For CMake to correctly setup the build order, they must be made
explicit.

This replicates the implicit module uses from

https://github.com/llvm/llvm-project/blob/12b20b36737094b1c521adff0c8f58aaaf2f41fb/flang/lib/Semantics/semantics.cpp#L680-L693
in the modules themselves. The PPC-specific modules compiled by Flang-RT
are listed here:

https://github.com/llvm/llvm-project/blob/12b20b36737094b1c521adff0c8f58aaaf2f41fb/flang-rt/lib/runtime/CMakeLists.txt#L213-L219

This should fix the intermittend build error mentioned in
llvm#205634 (comment).
Unfortunately I do not have a PowerPC (cross-)compilation build
environment ready to test, nor does the Premerge-CI build it.
maarcosrmz pushed a commit to maarcosrmz/llvm-project that referenced this pull request Jul 1, 2026
The PPC-specific builtin moduls have implicit dependencies insert by
flang. For CMake to correctly setup the build order, they must be made
explicit.

This replicates the implicit module uses from

https://github.com/llvm/llvm-project/blob/12b20b36737094b1c521adff0c8f58aaaf2f41fb/flang/lib/Semantics/semantics.cpp#L680-L693
in the modules themselves. The PPC-specific modules compiled by Flang-RT
are listed here:

https://github.com/llvm/llvm-project/blob/12b20b36737094b1c521adff0c8f58aaaf2f41fb/flang-rt/lib/runtime/CMakeLists.txt#L213-L219

This should fix the intermittend build error mentioned in
llvm#205634 (comment).
Unfortunately I do not have a PowerPC (cross-)compilation build
environment ready to test, nor does the Premerge-CI build it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants