[Mlir-commits] [mlir] [mlir][acc] Introduce createAndPopulate for recipe creation (PR #162917)
Valentin Clement バレンタイン クレメン
llvmlistbot at llvm.org
Fri Oct 10 17:31:07 PDT 2025
================
@@ -1080,6 +1287,67 @@ LogicalResult acc::FirstprivateRecipeOp::verifyRegions() {
return success();
}
+std::optional<FirstprivateRecipeOp>
+FirstprivateRecipeOp::createAndPopulate(OpBuilder &builder, Location loc,
+ StringRef recipeName, Value var,
+ StringRef varName, ValueRange bounds) {
+
+ Type varType = var.getType();
+
+ // First, validate that we can handle this variable type
+ bool isMappable = isa<MappableType>(varType);
+ bool isPointerLike = isa<PointerLikeType>(varType);
+
+ if (!isMappable && !isPointerLike) {
+ // Unsupported type
+ return std::nullopt;
+ }
+
+ // Create init, copy, and destroy blocks using shared helpers
+ OpBuilder::InsertionGuard guard(builder);
+
+ // Save the original insertion point for creating the recipe operation later
+ auto originalInsertionPoint = builder.saveInsertionPoint();
+
+ bool needsFree = false;
+ auto initBlock =
+ createInitRegion(builder, loc, var, varName, bounds, varType, needsFree);
+ if (!initBlock) {
+ return std::nullopt;
+ }
+
+ auto copyBlock = createCopyRegion(builder, loc, bounds, varType);
+ if (!copyBlock) {
+ return std::nullopt;
+ }
+
+ // Only create destroy region if the allocation needs deallocation
+ std::unique_ptr<Block> destroyBlock;
+ if (needsFree) {
+ // Extract the allocated value from the init block's yield operation
+ auto yieldOp = cast<acc::YieldOp>(initBlock->getTerminator());
+ Value allocRes = yieldOp.getOperand(0);
+
+ destroyBlock = createDestroyRegion(builder, loc, allocRes, bounds, varType);
+ if (!destroyBlock) {
+ return std::nullopt;
+ }
----------------
clementval wrote:
no brace
https://github.com/llvm/llvm-project/pull/162917
More information about the Mlir-commits
mailing list