-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FLANG] allow -fopenmp= #86816
[FLANG] allow -fopenmp= #86816
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,8 +38,6 @@ void Flang::addFortranDialectOptions(const ArgList &Args, | |
Args.addAllArgs(CmdArgs, {options::OPT_ffixed_form, | ||
options::OPT_ffree_form, | ||
options::OPT_ffixed_line_length_EQ, | ||
options::OPT_fopenmp, | ||
options::OPT_fopenmp_version_EQ, | ||
options::OPT_fopenacc, | ||
options::OPT_finput_charset_EQ, | ||
options::OPT_fimplicit_none, | ||
|
@@ -764,6 +762,32 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA, | |
// Add other compile options | ||
addOtherOptions(Args, CmdArgs); | ||
|
||
// Forward flags for OpenMP. We don't do this if the current action is an | ||
// device offloading action other than OpenMP. | ||
if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ, | ||
options::OPT_fno_openmp, false) && | ||
(JA.isDeviceOffloading(Action::OFK_None) || | ||
JA.isDeviceOffloading(Action::OFK_OpenMP))) { | ||
switch (D.getOpenMPRuntime(Args)) { | ||
case Driver::OMPRT_OMP: | ||
case Driver::OMPRT_IOMP5: | ||
// Clang can generate useful OpenMP code for these two runtime libraries. | ||
CmdArgs.push_back("-fopenmp"); | ||
Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ); | ||
|
||
// FIXME: Clang supports a whole bunch more flags here. | ||
tblah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
break; | ||
default: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we produce some sort of error in this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify, clang::Driver::getOpenMPRuntime does output an error (which we should test for), but currently we appear not to support libgomp, which clang does and so an error would not be produced in this case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what Clang does in this place. I'm not sure I understand why. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, it definitely is done this way on purpose - see clang/test/Driver/fopenmp.c (only "interesting" lines)
We can certainly add a warning or error, but Clang doesn't... :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clang might work differently internally. If we don't pass -fopenmp to the flang frontend driver, the parser will treat the openmp directives as comments. Which in many programs won't lead to any compilation errors but the program could produce different results (e.g. reductions won't happen) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was leaving out OMPRT_GOMP deliberate? If so, please could you comment here or in the commit message explaining why and update the test not to be checking for libgomp. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, behaving the same way as clang here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If OMPRT_GOMP doesn't need |
||
// By default, if Clang doesn't know how to generate useful OpenMP code | ||
// for a specific runtime library, we just don't pass the '-fopenmp' flag | ||
// down to the actual compilation. | ||
// FIXME: It would be better to have a mode which *only* omits IR | ||
// generation based on the OpenMP support so that we get consistent | ||
// semantic analysis, etc. | ||
break; | ||
} | ||
} | ||
|
||
// Offloading related options | ||
addOffloadOptions(C, Inputs, JA, Args, CmdArgs); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
! RUN: %flang -target x86_64-linux-gnu -fopenmp=libomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-OPENMP | ||
! RUN: %flang -target x86_64-linux-gnu -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-NO-OPENMP | ||
! RUN: %flang -target x86_64-linux-gnu -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-OPENMP | ||
! RUN: %flang -target x86_64-apple-darwin -fopenmp=libomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-OPENMP | ||
! RUN: %flang -target x86_64-apple-darwin -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-NO-OPENMP | ||
! RUN: %flang -target x86_64-apple-darwin -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-OPENMP | ||
! RUN: %flang -target x86_64-freebsd -fopenmp=libomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-OPENMP | ||
! RUN: %flang -target x86_64-freebsd -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-NO-OPENMP | ||
! RUN: %flang -target x86_64-freebsd -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-OPENMP | ||
! RUN: %flang -target x86_64-windows-gnu -fopenmp=libomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-OPENMP | ||
! RUN: %flang -target x86_64-windows-gnu -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-NO-OPENMP | ||
! RUN: %flang -target x86_64-windows-gnu -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-FC1-OPENMP | ||
|
||
! CHECK-FC1-OPENMP: "-fc1" | ||
! CHECK-FC1-OPENMP: "-fopenmp" | ||
! | ||
! CHECK-FC1-NO-OPENMP: "-fc1" | ||
! CHECK-FC1-NO-OPENMP-NOT: "-fopenmp" | ||
! | ||
! RUN: %flang -target x86_64-linux-gnu -fopenmp=libomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-OMP | ||
! RUN: %flang -target x86_64-linux-gnu -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-RT | ||
! RUN: %flang -target x86_64-linux-gnu -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5 | ||
! | ||
! RUN: %flang -target x86_64-darwin -fopenmp=libomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-OMP | ||
! RUN: %flang -target x86_64-darwin -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT | ||
! RUN: %flang -target x86_64-darwin -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5 | ||
! | ||
! RUN: %flang -target x86_64-freebsd -fopenmp=libomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-OMP | ||
! RUN: %flang -target x86_64-freebsd -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT | ||
! RUN: %flang -target x86_64-freebsd -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5 | ||
! | ||
! RUN: %flang -target x86_64-windows-gnu -fopenmp=libomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-OMP | ||
! RUN: %flang -target x86_64-windows-gnu -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-GOMP --check-prefix=CHECK-LD-GOMP-NO-RT | ||
! RUN: %flang -target x86_64-windows-gnu -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5MD | ||
! | ||
! CHECK-LD-OMP: "{{.*}}ld{{(.exe)?}}" | ||
! CHECK-LD-OMP: "-lomp" | ||
! | ||
! CHECK-LD-GOMP: "{{.*}}ld{{(.exe)?}}" | ||
! CHECK-LD-GOMP: "-lgomp" | ||
! CHECK-LD-GOMP-RT: "-lrt" | ||
! CHECK-LD-GOMP-NO-RT-NOT: "-lrt" | ||
! | ||
! CHECK-LD-IOMP5: "{{.*}}ld{{(.exe)?}}" | ||
! CHECK-LD-IOMP5: "-liomp5" | ||
! | ||
! CHECK-LD-IOMP5MD: "{{.*}}ld{{(.exe)?}}" | ||
! CHECK-LD-IOMP5MD: "-liomp5md" | ||
! | ||
! We'd like to check that the default is sane, but until we have the ability | ||
! to *always* semantically analyze OpenMP without always generating runtime | ||
! calls (in the event of an unsupported runtime), we don't have a good way to | ||
! test the CC1 invocation. Instead, just ensure we do eventually link *some* | ||
! OpenMP runtime. | ||
! | ||
! CHECK-LD-ANY: "{{.*}}ld{{(.exe)?}}" | ||
! CHECK-LD-ANY: "-l{{(omp|gomp|iomp5)}}" | ||
! | ||
! CHECK-LD-ANYMD: "{{.*}}ld{{(.exe)?}}" | ||
! CHECK-LD-ANYMD: "-l{{(omp|gomp|iomp5md)}}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
-fno-openmp
is visible in the flang driver. Maybe it should be.