Skip to content
Open
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
938091d
[Flang][mlir] - Translation of delayed privatization for deferred tar…
bhandarkar-pranav Jun 17, 2025
f72152a
Add some comments and clean up some codoe
bhandarkar-pranav Aug 26, 2025
c859bbc
Fix CHECK stmts in test to account for constant folding done by the g…
bhandarkar-pranav Aug 26, 2025
697cc4f
Fix clang-format issues
bhandarkar-pranav Aug 27, 2025
bc107cd
Checkpoint commit, working with operaiton->walk
bhandarkar-pranav Sep 5, 2025
f7dacb3
Address more comments from tblah and meinersbur
bhandarkar-pranav Sep 8, 2025
f4a13ea
Handle boxchars
bhandarkar-pranav Sep 10, 2025
c8fad74
fix testcases
bhandarkar-pranav Sep 11, 2025
e74fa7d
Revert "Fix CHECK stmts in test to account for constant folding done …
bhandarkar-pranav Sep 11, 2025
343f7ec
Fix more testcases
bhandarkar-pranav Sep 11, 2025
41bb5b2
Reset some tests back to their old states
bhandarkar-pranav Sep 11, 2025
3264bfe
Undo empty line removal
bhandarkar-pranav Sep 11, 2025
b9fb8ce
Add back some CHECK statements in flang/test/Fir/target.fir and flang…
bhandarkar-pranav Sep 11, 2025
7032cae
use the init region to initialize the heap allocated private variable
bhandarkar-pranav Sep 17, 2025
269c575
use the copy region to copy the private variable into its heap alloca…
bhandarkar-pranav Sep 17, 2025
3109e4f
Fix for boxchars is working
bhandarkar-pranav Sep 18, 2025
d5b9c27
Adjust mlir/test/Dialect/LLVMIR/omp-offload-privatization-prepare.mli…
bhandarkar-pranav Sep 18, 2025
8bd4359
Address minor review comments
bhandarkar-pranav Sep 18, 2025
a393ff1
Handle the case where varPtr is a blockargument. - Take the varType f…
bhandarkar-pranav Sep 24, 2025
28ec66a
clean up the pass a little bit
bhandarkar-pranav Sep 24, 2025
d95799d
Do not include OpenMPOffloadPrivatizationPrepare.h in Pipelines.h. In…
bhandarkar-pranav Sep 24, 2025
0829719
Move PrepareForOMPOffloadPrivatizationPass from Transforms in LLVMIR …
bhandarkar-pranav Sep 25, 2025
01d1f69
Add a lit test for boxchars
bhandarkar-pranav Sep 25, 2025
d595572
Make createFuncForRegionAndCallIt take an arrayref as argumen
bhandarkar-pranav Sep 26, 2025
bf949fa
clean up
bhandarkar-pranav Sep 26, 2025
72a769f
make clang-format happy
bhandarkar-pranav Sep 26, 2025
061669f
Add some more comments and fix a typo
bhandarkar-pranav Sep 29, 2025
e036923
Checkpoint commit - dealloc working - need to fix lit testcase to tes…
bhandarkar-pranav Oct 4, 2025
5b78bab
fix lit testcase for dealloc region generation
bhandarkar-pranav Oct 5, 2025
b34b0e0
fix clang-format problems
bhandarkar-pranav Oct 6, 2025
4c5d8d8
Update test for differences between downstream and upstream
bhandarkar-pranav Oct 6, 2025
6288da9
Make changes requested by reviewers - Formatting changes requested by…
bhandarkar-pranav Oct 15, 2025
0a4ef58
Update test (again) for differences between downstream and upstream
bhandarkar-pranav Oct 15, 2025
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
8 changes: 8 additions & 0 deletions flang/lib/Optimizer/Passes/Pipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/// common to flang and the test tools.

#include "flang/Optimizer/Passes/Pipelines.h"
#include "mlir/Dialect/OpenMP/Transforms/OpenMPOffloadPrivatizationPrepare.h"
#include "llvm/Support/CommandLine.h"

/// Force setting the no-alias attribute on fuction arguments when possible.
Expand Down Expand Up @@ -411,6 +412,13 @@ 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.
addNestedPassConditionally<mlir::LLVM::LLVMFuncOp>(
pm, disableFirToLlvmIr, [&]() {
return mlir::omp::createPrepareForOMPOffloadPrivatizationPass();
});
}

} // namespace fir
2 changes: 2 additions & 0 deletions flang/test/Fir/basic-program.fir
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,6 @@ func.func @_QQmain() {
// PASSES-NEXT: LowerNontemporalPass
// PASSES-NEXT: FIRToLLVMLowering
// PASSES-NEXT: ReconcileUnrealizedCasts
// PASSES-NEXT: 'llvm.func' Pipeline
// 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_public_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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===- OpenMPOffloadPrivatizationPrepare.h -*- 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_PREPAREFOROMPOFFLOADPRIVATIZATIONPASS_H
#define MLIR_DIALECT_OPENMP_TRANSFORMS_PREPAREFOROMPOFFLOADPRIVATIZATIONPASS_H

#include <memory>

namespace mlir {
class Pass;
namespace omp {
#define GEN_PASS_DECL_PREPAREFOROMPOFFLOADPRIVATIZATIONPASS
#include "mlir/Dialect/OpenMP/Transforms/Passes.h.inc"
} // namespace omp
} // namespace mlir

#endif // MLIR_DIALECT_OPENMP_TRANSFORMS_PREPAREFOROMPOFFLOADPRIVATIZATIONPASS_H
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 - LLVM Pass Construction and Registration -----------------===//
//
// 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 - LLVM 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", "::mlir::LLVM::LLVMFuncOp"> {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a module pass instead since the pass modifies the parent module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will change.

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"];
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to add mlir::omp::OpenMPDialect as well.

}
#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