File tree Expand file tree Collapse file tree 9 files changed +46
-13
lines changed Expand file tree Collapse file tree 9 files changed +46
-13
lines changed Original file line number Diff line number Diff line change @@ -254,6 +254,24 @@ inline void createHLFIRToFIRPassPipeline(
254254 pm.addPass (hlfir::createConvertHLFIRtoFIRPass ());
255255}
256256
257+ // / Create a pass pipeline for handling certain OpenMP transformations needed
258+ // / prior to FIR lowering.
259+ // /
260+ // / WARNING: These passes must be run immediately after the lowering to ensure
261+ // / that the FIR is correct with respect to OpenMP operations/attributes.
262+ // /
263+ // / \param pm - MLIR pass manager that will hold the pipeline definition.
264+ // / \param isTargetDevice - Whether code is being generated for a target device
265+ // / rather than the host device.
266+ inline void createOpenMPFIRPassPipeline (
267+ mlir::PassManager &pm, bool isTargetDevice) {
268+ pm.addPass (fir::createOMPMarkDeclareTargetPass ());
269+ if (isTargetDevice) {
270+ pm.addPass (fir::createOMPEarlyOutliningPass ());
271+ pm.addPass (fir::createOMPFunctionFilteringPass ());
272+ }
273+ }
274+
257275#if !defined(FLANG_EXCLUDE_CODEGEN)
258276inline void createDebugPasses (
259277 mlir::PassManager &pm, llvm::codegenoptions::DebugInfoKind debugLevel) {
Original file line number Diff line number Diff line change 7070#include < memory>
7171#include < system_error>
7272
73+ #include " flang/Tools/CLOptions.inc"
74+
7375using namespace Fortran ::frontend;
7476
7577// Declare plugin extension function declarations.
@@ -313,12 +315,10 @@ bool CodeGenAction::beginSourceFileAction() {
313315 if (auto offloadMod = llvm::dyn_cast<mlir::omp::OffloadModuleInterface>(
314316 mlirModule->getOperation ()))
315317 isDevice = offloadMod.getIsTargetDevice ();
316-
317- pm.addPass (fir::createOMPMarkDeclareTargetPass ());
318- if (isDevice) {
319- pm.addPass (fir::createOMPEarlyOutliningPass ());
320- pm.addPass (fir::createOMPFunctionFilteringPass ());
321- }
318+ // WARNING: This pipeline must be run immediately after the lowering to
319+ // ensure that the FIR is correct with respect to OpenMP operations/
320+ // attributes.
321+ fir::createOpenMPFIRPassPipeline (pm, isDevice);
322322 }
323323
324324 pm.enableVerifier (/* verifyPasses=*/ true );
@@ -651,8 +651,6 @@ void GetSymbolsSourcesAction::executeAction() {
651651
652652CodeGenAction::~CodeGenAction () = default ;
653653
654- #include " flang/Tools/CLOptions.inc"
655-
656654static llvm::OptimizationLevel
657655mapToLevel (const Fortran::frontend::CodeGenOptions &opts) {
658656 switch (opts.OptimizationLevel ) {
Original file line number Diff line number Diff line change 11! This test checks that when compiling an OpenMP program for the target device
22! CSE is not done across target op region boundaries. It also checks that when
33! compiling for the host CSE is done.
4- ! RUN: %flang_fc1 -fopenmp-is-device -emit-mlir -fopenmp %s -o - | fir-opt -cse | FileCheck %s -check-prefix=CHECK-DEVICE
4+ ! RUN: %flang_fc1 -fopenmp-is-target- device -emit-mlir -fopenmp %s -o - | fir-opt -cse | FileCheck %s -check-prefix=CHECK-DEVICE
55! RUN: %flang_fc1 -emit-mlir -fopenmp %s -o - | fir-opt -cse | FileCheck %s -check-prefix=CHECK-HOST
6+ ! RUN: bbc -fopenmp-is-target-device -emit-fir -fopenmp %s -o - | fir-opt -cse | FileCheck %s -check-prefix=CHECK-DEVICE
7+ ! RUN: bbc -emit-fir -fopenmp %s -o - | fir-opt -cse | FileCheck %s -check-prefix=CHECK-HOST
68
79! Constant should be present inside target region.
810! CHECK-DEVICE: omp.target
@@ -19,7 +21,7 @@ subroutine writeIndex(sum)
1921 integer :: myconst1
2022 integer :: myconst2
2123 myconst1 = 10
22- ! $omp target map(from:new_len )
24+ ! $omp target map(from:myconst2 )
2325 myconst2 = 10
2426! $omp end target
2527 sum = myconst2 + myconst2
Original file line number Diff line number Diff line change 11! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
2- ! RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DEVICE
2+ ! RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefix=DEVICE
3+ ! RUN: bbc -emit-fir -fopenmp %s -o - | FileCheck %s
4+ ! RUN: bbc -emit-fir -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefix=DEVICE
35
46! CHECK-LABEL: func.func @_QPimplicitly_captured
57! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}}
Original file line number Diff line number Diff line change 11! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
22! RUN: %flang_fc1 -emit-fir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s --check-prefix=DEVICE
3+ ! RUN: bbc -emit-fir -fopenmp %s -o - | FileCheck %s
4+ ! RUN: bbc -emit-fir -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefix=DEVICE
35
46! DEVICE-LABEL: func.func @_QPimplicit_capture
57! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}}
Original file line number Diff line number Diff line change 22! RUN: %flang_fc1 -fopenmp -emit-mlir %s -o - | FileCheck --check-prefix=MLIR %s
33! RUN: %flang_fc1 -fopenmp -fopenmp-is-target-device -emit-llvm %s -o - | FileCheck --check-prefix=LLVM %s
44! RUN: %flang_fc1 -fopenmp -fopenmp-is-target-device -emit-mlir %s -o - | FileCheck --check-prefix=MLIR %s
5+ ! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck --check-prefixes=MLIR-HOST,MLIR-ALL %s
6+ ! RUN: bbc -fopenmp -fopenmp-is-target-device -emit-fir %s -o - | FileCheck --check-prefixes=MLIR-DEVICE,MLIR-ALL %s
57
68! MLIR: func.func @{{.*}}implicit_invocation() attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>}
79! MLIR: return
Original file line number Diff line number Diff line change 22! RUN: %flang_fc1 -fopenmp -emit-mlir %s -o - | FileCheck --check-prefixes=MLIR-HOST,MLIR-ALL %s
33! RUN: %flang_fc1 -fopenmp -fopenmp-is-target-device -emit-llvm %s -o - | FileCheck --check-prefixes=LLVM-DEVICE,LLVM-ALL %s
44! RUN: %flang_fc1 -fopenmp -fopenmp-is-target-device -emit-mlir %s -o - | FileCheck --check-prefixes=MLIR-DEVICE,MLIR-ALL %s
5+ ! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck --check-prefixes=MLIR-HOST,MLIR-ALL %s
6+ ! RUN: bbc -fopenmp -fopenmp-is-target-device -emit-fir %s -o - | FileCheck --check-prefixes=MLIR-DEVICE,MLIR-ALL %s
57
68! Check that the correct LLVM IR functions are kept for the host and device
79! after running the whole set of translation and transformation passes from
Original file line number Diff line number Diff line change 11! REQUIRES: amdgpu-registered-target
22
3- ! RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -emit-fir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s
4- ! RUN: %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-fir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s
3+ ! RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -emit-fir -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s
4+ ! RUN: %flang_fc1 -triple x86_64-unknown-linux-gnu -emit-fir -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s
5+ ! RUN: bbc -emit-fir -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s
6+ ! RUN: bbc -emit-fir -fopenmp -fopenmp-is-gpu -fopenmp-is-target-device %s -o - | FileCheck %s
57
68! CHECK: func.func @_QPtarget_function
79
Original file line number Diff line number Diff line change @@ -329,6 +329,11 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
329329 // Otherwise run the default passes.
330330 mlir::PassManager pm (mlirModule->getName (),
331331 mlir::OpPassManager::Nesting::Implicit);
332+ if (enableOpenMP)
333+ // WARNING: This pipeline must be run immediately after the lowering to
334+ // ensure that the FIR is correct with respect to OpenMP operations/
335+ // attributes.
336+ fir::createOpenMPFIRPassPipeline (pm, enableOpenMPDevice);
332337 pm.enableVerifier (/* verifyPasses=*/ true );
333338 (void )mlir::applyPassManagerCLOptions (pm);
334339 if (passPipeline.hasAnyOccurrences ()) {
You can’t perform that action at this time.
0 commit comments