Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flang/include/flang/Optimizer/Passes/Pipelines.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "mlir/Conversion/SCFToControlFlow/SCFToControlFlow.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
#include "mlir/Dialect/OpenMP/Transforms/Passes.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "mlir/Transforms/Passes.h"
Expand Down
6 changes: 6 additions & 0 deletions flang/lib/Optimizer/Passes/Pipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ void createMLIRToLLVMPassPipeline(mlir::PassManager &pm,

// Add codegen pass pipeline.
fir::createDefaultFIRCodeGenPassPipeline(pm, config, inputFilename);

// Run a pass to prepare for translation of delayed privatization in the
// context of deferred target tasks.
addPassConditionally(pm, disableFirToLlvmIr, [&]() {
return mlir::omp::createPrepareForOMPOffloadPrivatizationPass();
});
}

} // namespace fir
1 change: 1 addition & 0 deletions flang/test/Fir/basic-program.fir
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,5 @@ func.func @_QQmain() {
// PASSES-NEXT: LowerNontemporalPass
// PASSES-NEXT: FIRToLLVMLowering
// PASSES-NEXT: ReconcileUnrealizedCasts
// PASSES-NEXT: PrepareForOMPOffloadPrivatizationPass
// PASSES-NEXT: LLVMIRLoweringPass
2 changes: 2 additions & 0 deletions mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
add_subdirectory(Transforms)

set(LLVM_TARGET_DEFINITIONS ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend/OpenMP/OMP.td)
mlir_tablegen(OmpCommon.td --gen-directive-decl --directives-dialect=OpenMP)
add_mlir_dialect_tablegen_target(omp_common_td)
Expand Down
5 changes: 5 additions & 0 deletions mlir/include/mlir/Dialect/OpenMP/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name OpenMP)
add_public_tablegen_target(MLIROpenMPPassIncGen)

add_mlir_doc(Passes OpenMPPasses ./ -gen-pass-doc)
26 changes: 26 additions & 0 deletions mlir/include/mlir/Dialect/OpenMP/Transforms/Passes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===- Passes.h - OpenMP Pass Construction and Registration -----*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_DIALECT_OPENMP_TRANSFORMS_PASSES_H
#define MLIR_DIALECT_OPENMP_TRANSFORMS_PASSES_H

#include "mlir/Pass/Pass.h"

namespace mlir {

namespace omp {

/// Generate the code for registering conversion passes.
#define GEN_PASS_DECL
#define GEN_PASS_REGISTRATION
#include "mlir/Dialect/OpenMP/Transforms/Passes.h.inc"

} // namespace omp
} // namespace mlir

#endif // MLIR_DIALECT_LLVMIR_TRANSFORMS_PASSES_H
26 changes: 26 additions & 0 deletions mlir/include/mlir/Dialect/OpenMP/Transforms/Passes.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===-- Passes.td - OpenMP pass definition file ------------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_DIALECT_OPENMP_TRANSFORMS_PASSES
#define MLIR_DIALECT_OPENMP_TRANSFORMS_PASSES

include "mlir/Pass/PassBase.td"

def PrepareForOMPOffloadPrivatizationPass : Pass<"omp-offload-privatization-prepare", "ModuleOp"> {
let summary = "Prepare OpenMP maps for privatization for deferred target tasks";
let description = [{
When generating LLVMIR for privatized variables in an OpenMP offloading directive (eg. omp::TargetOp)
that creates a deferred target task (when the nowait clause is used), we need to copy the privatized
variable out of the stack of the generating task and into the heap so that the deferred target task
can still access it. However, if such a privatized variable is also mapped, typically the case for
allocatables, then the corresponding `omp::MapInfoOp` needs to be fixed up to map the new heap-allocated
variable and not the original variable.
}];
let dependentDialects = ["LLVM::LLVMDialect"];
}
#endif // MLIR_DIALECT_OPENMP_TRANSFORMS_PASSES
1 change: 1 addition & 0 deletions mlir/lib/Dialect/LLVMIR/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ add_mlir_dialect_library(MLIRLLVMIRTransforms
MLIRPass
MLIRTransforms
MLIRNVVMDialect
MLIROpenMPDialect
)
2 changes: 2 additions & 0 deletions mlir/lib/Dialect/OpenMP/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
add_subdirectory(Transforms)

add_mlir_dialect_library(MLIROpenMPDialect
IR/OpenMPDialect.cpp

Expand Down
14 changes: 14 additions & 0 deletions mlir/lib/Dialect/OpenMP/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_mlir_dialect_library(MLIROpenMPTransforms
OpenMPOffloadPrivatizationPrepare.cpp

DEPENDS
MLIROpenMPPassIncGen

LINK_LIBS PUBLIC
MLIRIR
MLIRFuncDialect
MLIRLLVMDialect
MLIROpenMPDialect
MLIRPass
MLIRTransforms
)
Loading