[llvm] [mlir] [OMPIRBuilder] Replace getAllocatedType with getAllocationSize (PR #181844)
Jameson Nash via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 20 10:46:20 PST 2026
https://github.com/vtjnash updated https://github.com/llvm/llvm-project/pull/181844
>From 797af6358e8da5a9e80df045e9f6f8fb4f68b065 Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash+github at gmail.com>
Date: Tue, 17 Feb 2026 01:38:43 +0000
Subject: [PATCH] [NFCI][OMPIRBuilder] Replace getAllocatedType with
getAllocationSize
Replace size queries using getTypeStoreSize(getAllocatedType()) with
getAllocationSize(DL) in createTaskloop, createTask, emitTargetTask, and
emitTargetTaskProxyFunction. For GEP type arguments in
emitNonContiguousDescriptor and emitOffloadingArrays, use the local
ArrayTy/PointerArrayType variables already in scope instead of
re-querying the alloca.
The store size of a struct is the same as the allocation size, so this
should be NFC, and removes unnecessary uses of getAllocatedType, in
pursuit of the eventual deprecation of the getAllocatedType interface.
Co-Authored-By: Claude Sonnet 4.5 <noreply at anthropic.com>
---
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 54 +++++++++----------
.../openmp-taskloop-no-context-struct.mlir | 6 +--
2 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 25f4da7c90d90..2ae0d70acdec7 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2179,7 +2179,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTaskloop(
OI.PostOutlineCB = [this, Ident, LBVal, UBVal, StepVal, Untied,
TaskloopAllocaBB, CLI, Loc, TaskDupFn, ToBeDeleted,
IfCond, GrainSize, NoGroup, Sched, FakeLB, FakeUB,
- FakeStep, Final, Mergeable, Priority,
+ FakeStep, FakeSharedsTy, Final, Mergeable, Priority,
NumOfCollapseLoops](Function &OutlinedFn) mutable {
// Replace the Stale CI by appropriate RTL function call.
assert(OutlinedFn.hasOneUse() &&
@@ -2240,12 +2240,11 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTaskloop(
assert(ArgStructAlloca &&
"Unable to find the alloca instruction corresponding to arguments "
"for extracted function");
- StructType *ArgStructType =
- dyn_cast<StructType>(ArgStructAlloca->getAllocatedType());
- assert(ArgStructType && "Unable to find struct type corresponding to "
- "arguments for extracted function");
- Value *SharedsSize =
- Builder.getInt64(M.getDataLayout().getTypeStoreSize(ArgStructType));
+ std::optional<TypeSize> ArgAllocSize =
+ ArgStructAlloca->getAllocationSize(M.getDataLayout());
+ assert(ArgAllocSize &&
+ "Unable to determine size of arguments for extracted function");
+ Value *SharedsSize = Builder.getInt64(ArgAllocSize->getFixedValue());
// Emit the @__kmpc_omp_task_alloc runtime call
// The runtime call returns a pointer to an area where the task captured
@@ -2263,13 +2262,13 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTaskloop(
// Get the pointer to loop lb, ub, step from task ptr
// and set up the lowerbound,upperbound and step values
llvm::Value *Lb = Builder.CreateGEP(
- ArgStructType, TaskShareds, {Builder.getInt32(0), Builder.getInt32(0)});
+ FakeSharedsTy, TaskShareds, {Builder.getInt32(0), Builder.getInt32(0)});
llvm::Value *Ub = Builder.CreateGEP(
- ArgStructType, TaskShareds, {Builder.getInt32(0), Builder.getInt32(1)});
+ FakeSharedsTy, TaskShareds, {Builder.getInt32(0), Builder.getInt32(1)});
llvm::Value *Step = Builder.CreateGEP(
- ArgStructType, TaskShareds, {Builder.getInt32(0), Builder.getInt32(2)});
+ FakeSharedsTy, TaskShareds, {Builder.getInt32(0), Builder.getInt32(2)});
llvm::Value *Loadstep = Builder.CreateLoad(Builder.getInt64Ty(), Step);
// set up the arguments for emitting kmpc_taskloop runtime call
@@ -2540,12 +2539,11 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask(
assert(ArgStructAlloca &&
"Unable to find the alloca instruction corresponding to arguments "
"for extracted function");
- StructType *ArgStructType =
- dyn_cast<StructType>(ArgStructAlloca->getAllocatedType());
- assert(ArgStructType && "Unable to find struct type corresponding to "
- "arguments for extracted function");
- SharedsSize =
- Builder.getInt64(M.getDataLayout().getTypeStoreSize(ArgStructType));
+ std::optional<TypeSize> ArgAllocSize =
+ ArgStructAlloca->getAllocationSize(M.getDataLayout());
+ assert(ArgAllocSize &&
+ "Unable to determine size of arguments for extracted function");
+ SharedsSize = Builder.getInt64(ArgAllocSize->getFixedValue());
}
// Emit the @__kmpc_omp_task_alloc runtime call
// The runtime call returns a pointer to an area where the task captured
@@ -8652,12 +8650,16 @@ static Function *emitTargetTaskProxyFunction(
"Unable to find the alloca instruction corresponding to arguments "
"for extracted function");
auto *ArgStructType = cast<StructType>(ArgStructAlloca->getAllocatedType());
+ std::optional<TypeSize> ArgAllocSize =
+ ArgStructAlloca->getAllocationSize(M.getDataLayout());
+ assert(ArgStructType && ArgAllocSize &&
+ "Unable to determine size of arguments for extracted function");
+ uint64_t StructSize = ArgAllocSize->getFixedValue();
AllocaInst *NewArgStructAlloca =
Builder.CreateAlloca(ArgStructType, nullptr, "structArg");
- Value *SharedsSize =
- Builder.getInt64(M.getDataLayout().getTypeStoreSize(ArgStructType));
+ Value *SharedsSize = Builder.getInt64(StructSize);
LoadInst *LoadShared = loadSharedDataFromTaskDescriptor(
OMPBuilder, Builder, TaskWithPrivates, TaskWithPrivatesTy);
@@ -8996,12 +8998,11 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask(
assert(ArgStructAlloca &&
"Unable to find the alloca instruction corresponding to arguments "
"for extracted function");
- auto *ArgStructType =
- dyn_cast<StructType>(ArgStructAlloca->getAllocatedType());
- assert(ArgStructType && "Unable to find struct type corresponding to "
- "arguments for extracted function");
- SharedsSize =
- Builder.getInt64(M.getDataLayout().getTypeStoreSize(ArgStructType));
+ std::optional<TypeSize> ArgAllocSize =
+ ArgStructAlloca->getAllocationSize(M.getDataLayout());
+ assert(ArgAllocSize &&
+ "Unable to determine size of arguments for extracted function");
+ SharedsSize = Builder.getInt64(ArgAllocSize->getFixedValue());
}
// Argument - `flags`
@@ -9594,8 +9595,7 @@ void OpenMPIRBuilder::emitNonContiguousDescriptor(InsertPointTy AllocaIP,
for (unsigned II = 0, EE = NonContigInfo.Dims[I]; II < EE; ++II) {
unsigned RevIdx = EE - II - 1;
Value *DimsLVal = Builder.CreateInBoundsGEP(
- DimsAddr->getAllocatedType(), DimsAddr,
- {Builder.getInt64(0), Builder.getInt64(II)});
+ ArrayTy, DimsAddr, {Builder.getInt64(0), Builder.getInt64(II)});
// Offset
Value *OffsetLVal = Builder.CreateStructGEP(DimTy, DimsLVal, OffsetFD);
Builder.CreateAlignedStore(
@@ -10091,7 +10091,7 @@ Error OpenMPIRBuilder::emitOffloadingArrays(
MFunc = Builder.CreatePointerCast(*CustomMFunc, PtrTy);
Value *MAddr = Builder.CreateInBoundsGEP(
- MappersArray->getAllocatedType(), MappersArray,
+ PointerArrayType, MappersArray,
{Builder.getIntN(IndexSize, 0), Builder.getIntN(IndexSize, I)});
Builder.CreateAlignedStore(
MFunc, MAddr, M.getDataLayout().getPrefTypeAlign(MAddr->getType()));
diff --git a/mlir/test/Target/LLVMIR/openmp-taskloop-no-context-struct.mlir b/mlir/test/Target/LLVMIR/openmp-taskloop-no-context-struct.mlir
index 69a2edb2a7c0f..9544c0a7ce5fb 100644
--- a/mlir/test/Target/LLVMIR/openmp-taskloop-no-context-struct.mlir
+++ b/mlir/test/Target/LLVMIR/openmp-taskloop-no-context-struct.mlir
@@ -48,9 +48,9 @@ llvm.func @_QPtest() {
// CHECK: %[[VAL_15:.*]] = call ptr @__kmpc_omp_task_alloc(ptr @1, i32 %[[VAL_14]], i32 1, i64 40, i64 24, ptr @_QPtest..omp_par)
// CHECK: %[[VAL_16:.*]] = load ptr, ptr %[[VAL_15]], align 8
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 1 %[[VAL_16]], ptr align 1 %[[STRUCTARG]], i64 24, i1 false)
-// CHECK: %[[VAL_17:.*]] = getelementptr { i64, i64, i64 }, ptr %[[VAL_16]], i32 0, i32 0
-// CHECK: %[[VAL_18:.*]] = getelementptr { i64, i64, i64 }, ptr %[[VAL_16]], i32 0, i32 1
-// CHECK: %[[VAL_19:.*]] = getelementptr { i64, i64, i64 }, ptr %[[VAL_16]], i32 0, i32 2
+// CHECK: %[[VAL_17:.*]] = getelementptr { i64, i64, i64, ptr }, ptr %[[VAL_16]], i32 0, i32 0
+// CHECK: %[[VAL_18:.*]] = getelementptr { i64, i64, i64, ptr }, ptr %[[VAL_16]], i32 0, i32 1
+// CHECK: %[[VAL_19:.*]] = getelementptr { i64, i64, i64, ptr }, ptr %[[VAL_16]], i32 0, i32 2
// CHECK: %[[VAL_20:.*]] = load i64, ptr %[[VAL_19]], align 4
// CHECK: call void @__kmpc_taskloop(ptr @1, i32 %[[VAL_14]], ptr %[[VAL_15]], i32 1, ptr %[[VAL_17]], ptr %[[VAL_18]], i64 %[[VAL_20]], i32 1, i32 0, i64 0, ptr null)
// CHECK: call void @__kmpc_end_taskgroup(ptr @1, i32 %[[VAL_14]])
More information about the llvm-commits
mailing list