[flang-commits] [flang] [llvm] [mlir] [Flang] [OpenMP] [MLIR] Add lowering support for OMP ALLOCATE directives and its clauses (PR #187167)
via flang-commits
flang-commits at lists.llvm.org
Tue Mar 17 18:15:32 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- flang/lib/Lower/OpenMP/ClauseProcessor.cpp flang/lib/Lower/OpenMP/ClauseProcessor.h flang/lib/Lower/OpenMP/OpenMP.cpp llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp mlir/lib/Target/LLVMIR/ModuleTranslation.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index 7008df741..4f4453df9 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -325,8 +325,7 @@ static void collectIteratorIVs(
// ClauseProcessor unique clauses
//===----------------------------------------------------------------------===//
-bool ClauseProcessor::processAlign(
- mlir::omp::AlignClauseOps &result) const {
+bool ClauseProcessor::processAlign(mlir::omp::AlignClauseOps &result) const {
if (auto *clause = findUniqueClause<omp::clause::Align>()) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
const std::optional<std::int64_t> align = evaluate::ToInt64(clause->v);
@@ -336,7 +335,9 @@ bool ClauseProcessor::processAlign(
return false;
}
-bool ClauseProcessor::processAllocator(lower::StatementContext &stmtCtx, mlir::omp::AllocatorClauseOps &result) const {
+bool ClauseProcessor::processAllocator(
+ lower::StatementContext &stmtCtx,
+ mlir::omp::AllocatorClauseOps &result) const {
if (auto *clause = findUniqueClause<omp::clause::Allocator>()) {
result.allocator = fir::getBase(converter.genExprValue(clause->v, stmtCtx));
return true;
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h b/flang/lib/Lower/OpenMP/ClauseProcessor.h
index 62436e2a1..b9ea3f472 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.h
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h
@@ -58,7 +58,8 @@ public:
// 'Unique' clauses: They can appear at most once in the clause list.
bool processAlign(mlir::omp::AlignClauseOps &result) const;
- bool processAllocator(lower::StatementContext &stmtCtx, mlir::omp::AllocatorClauseOps &result) const;
+ bool processAllocator(lower::StatementContext &stmtCtx,
+ mlir::omp::AllocatorClauseOps &result) const;
bool processBare(mlir::omp::BareClauseOps &result) const;
bool processBind(mlir::omp::BindClauseOps &result) const;
bool processCancelDirectiveName(
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 9784765fe..6ea434983 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1494,12 +1494,12 @@ static OpTy genWrapperOp(lower::AbstractConverter &converter,
//===----------------------------------------------------------------------===//
static void genAllocateClauses(lower::AbstractConverter &converter,
- semantics::SemanticsContext &semaCtx,
- lower::StatementContext &stmtCtx,
- const ObjectList &objects,
- const List<Clause> &clauses, mlir::Location loc,
- llvm::SmallVectorImpl<mlir::Value> &operandRange,
- mlir::omp::AllocateDirOperands &clauseOps) {
+ semantics::SemanticsContext &semaCtx,
+ lower::StatementContext &stmtCtx,
+ const ObjectList &objects,
+ const List<Clause> &clauses, mlir::Location loc,
+ llvm::SmallVectorImpl<mlir::Value> &operandRange,
+ mlir::omp::AllocateDirOperands &clauseOps) {
if (!objects.empty())
genObjectList(objects, converter, operandRange);
@@ -1914,16 +1914,19 @@ static void genWsloopClauses(
//===----------------------------------------------------------------------===//
// Code generation functions for leaf constructs
//===----------------------------------------------------------------------===//
-static mlir::omp::AllocateDirOp
-genAllocateDirOp(lower::AbstractConverter &converter,
- semantics::SemanticsContext &semaCtx, lower::StatementContext &stmtCtx, lower::pft::Evaluation &eval,
- mlir::Location loc, const ObjectList &objects, const ConstructQueue &queue, ConstructQueue::const_iterator item) {
+static mlir::omp::AllocateDirOp genAllocateDirOp(
+ lower::AbstractConverter &converter, semantics::SemanticsContext &semaCtx,
+ lower::StatementContext &stmtCtx, lower::pft::Evaluation &eval,
+ mlir::Location loc, const ObjectList &objects, const ConstructQueue &queue,
+ ConstructQueue::const_iterator item) {
llvm::SmallVector<mlir::Value> operandRange;
mlir::omp::AllocateDirOperands clauseOps;
genAllocateClauses(converter, semaCtx, stmtCtx, objects, item->clauses, loc,
- operandRange, clauseOps);
+ operandRange, clauseOps);
- return mlir::omp::AllocateDirOp::create(converter.getFirOpBuilder(), loc, operandRange, clauseOps.align, clauseOps.allocator);
+ return mlir::omp::AllocateDirOp::create(converter.getFirOpBuilder(), loc,
+ operandRange, clauseOps.align,
+ clauseOps.allocator);
}
static mlir::omp::BarrierOp
@@ -3832,8 +3835,8 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
converter.getFirOpBuilder().getModule(), semaCtx, eval, allocate.source,
llvm::omp::Directive::OMPD_allocate, clauses)};
- genAllocateDirOp(converter, semaCtx, stmtCtx, eval, loc, objects,
- queue, queue.begin());
+ genAllocateDirOp(converter, semaCtx, stmtCtx, eval, loc, objects, queue,
+ queue.begin());
}
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index f18075c14..2fc7b3113 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -3201,8 +3201,9 @@ public:
///
/// \returns CallInst to the OMP_Align_Alloc call
LLVM_ABI CallInst *createOMPAlignedAlloc(const LocationDescription &Loc,
- Value *Align, Value *Size, Value *Allocator,
- std::string Name = "");
+ Value *Align, Value *Size,
+ Value *Allocator,
+ std::string Name = "");
/// Create a runtime call for kmpc_free
///
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index ef8828980..32817e8f2 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -7620,8 +7620,9 @@ CallInst *OpenMPIRBuilder::createOMPAlloc(const LocationDescription &Loc,
}
CallInst *OpenMPIRBuilder::createOMPAlignedAlloc(const LocationDescription &Loc,
- Value *Align, Value *Size, Value *Allocator,
- std::string Name) {
+ Value *Align, Value *Size,
+ Value *Allocator,
+ std::string Name) {
IRBuilder<>::InsertPointGuard IPG(Builder);
updateToLocation(Loc);
diff --git a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
index f07308100..243cca883 100644
--- a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
+++ b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
@@ -518,8 +518,7 @@ private:
DenseMap<BlockAddressAttr, llvm::BasicBlock *> blockAddressToLLVMMapping;
/// Pending __kmpc_free calls per block, emitted before the terminator.
- DenseMap<Block *,
- llvm::SmallVector<std::pair<llvm::Value *, llvm::Value *>>>
+ DenseMap<Block *, llvm::SmallVector<std::pair<llvm::Value *, llvm::Value *>>>
pendingOmpAllocateFrees;
/// Stack of user-specified state elements, useful when translating operations
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 0ce9c55f8..c82e6568c 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -7448,7 +7448,7 @@ convertTargetAllocMemOp(Operation &opInst, llvm::IRBuilderBase &builder,
static LogicalResult
convertAllocateDirOp(Operation &opInst, llvm::IRBuilderBase &builder,
- LLVM::ModuleTranslation &moduleTranslation) {
+ LLVM::ModuleTranslation &moduleTranslation) {
auto allocateDirOp = cast<omp::AllocateDirOp>(opInst);
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
@@ -7464,8 +7464,8 @@ convertAllocateDirOp(Operation &opInst, llvm::IRBuilderBase &builder,
if (allocator->getType()->isIntegerTy())
allocator = builder.CreateIntToPtr(allocator, builder.getPtrTy());
else if (allocator->getType()->isPointerTy())
- allocator =
- builder.CreatePointerBitCastOrAddrSpaceCast(allocator, builder.getPtrTy());
+ allocator = builder.CreatePointerBitCastOrAddrSpaceCast(
+ allocator, builder.getPtrTy());
} else {
allocator = llvm::ConstantPointerNull::get(builder.getPtrTy());
}
@@ -7482,8 +7482,7 @@ convertAllocateDirOp(Operation &opInst, llvm::IRBuilderBase &builder,
Value baseVar = getBaseValueForTypeLookup(var);
if (Operation *globalOp = getGlobalOpFromValue(baseVar)) {
if (auto gop = dyn_cast<LLVM::GlobalOp>(globalOp))
- typeToInspect =
- moduleTranslation.convertType(gop.getGlobalType());
+ typeToInspect = moduleTranslation.convertType(gop.getGlobalType());
}
}
@@ -7497,8 +7496,8 @@ convertAllocateDirOp(Operation &opInst, llvm::IRBuilderBase &builder,
currentType = nestedArrTy->getElementType();
}
uint64_t elemSizeInBits = dataLayout.getTypeSizeInBits(currentType);
- size = builder.CreateMul(elementCount,
- builder.getInt64(elemSizeInBits / 8));
+ size =
+ builder.CreateMul(elementCount, builder.getInt64(elemSizeInBits / 8));
} else {
size = builder.getInt64(
dataLayout.getTypeStoreSize(typeToInspect).getFixedValue());
@@ -7518,9 +7517,11 @@ convertAllocateDirOp(Operation &opInst, llvm::IRBuilderBase &builder,
llvm::CallInst *allocCall;
if (alignAttr.has_value()) {
allocCall = ompBuilder->createOMPAlignedAlloc(
- ompLoc, builder.getInt64(alignAttr.value()), size, allocator, allocName);
+ ompLoc, builder.getInt64(alignAttr.value()), size, allocator,
+ allocName);
} else {
- allocCall = ompBuilder->createOMPAlloc(ompLoc, size, allocator, allocName);
+ allocCall =
+ ompBuilder->createOMPAlloc(ompLoc, size, allocator, allocName);
}
allocatedVars.push_back({allocCall, allocator});
}
@@ -7529,7 +7530,7 @@ convertAllocateDirOp(Operation &opInst, llvm::IRBuilderBase &builder,
Block *block = allocateDirOp->getBlock();
for (auto &alloc : allocatedVars)
moduleTranslation.registerPendingOmpAllocateFree(block, alloc.first,
- alloc.second);
+ alloc.second);
return success();
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/187167
More information about the flang-commits
mailing list