Skip to content

Commit d542dce

Browse files
authored
[OpenACC][CIR] copyin lowering for func-local- declare (llvm#169336)
This is exactly like the 'copy', except the exit operation is a 'delete' instead of a 'copyout'. Also, creating the 'delete' op has one less argument to it, so we have to do some special handling when creating that.
1 parent 71952df commit d542dce

File tree

3 files changed

+224
-9
lines changed

3 files changed

+224
-9
lines changed

clang/lib/CIR/CodeGen/CIRGenDeclOpenACC.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,21 @@ struct OpenACCDeclareCleanup final : EHScopeStack::Cleanup {
2828

2929
template <typename OutTy, typename InTy>
3030
void createOutOp(CIRGenFunction &cgf, InTy inOp) {
31-
auto outOp =
32-
OutTy::create(cgf.getBuilder(), inOp.getLoc(), inOp, inOp.getVarPtr(),
33-
inOp.getStructured(), inOp.getImplicit(),
34-
llvm::Twine(inOp.getNameAttr()), inOp.getBounds());
35-
outOp.setDataClause(inOp.getDataClause());
36-
outOp.setModifiers(inOp.getModifiers());
31+
if constexpr (std::is_same_v<OutTy, mlir::acc::DeleteOp>) {
32+
auto outOp =
33+
OutTy::create(cgf.getBuilder(), inOp.getLoc(), inOp,
34+
inOp.getStructured(), inOp.getImplicit(),
35+
llvm::Twine(inOp.getNameAttr()), inOp.getBounds());
36+
outOp.setDataClause(inOp.getDataClause());
37+
outOp.setModifiers(inOp.getModifiers());
38+
} else {
39+
auto outOp =
40+
OutTy::create(cgf.getBuilder(), inOp.getLoc(), inOp, inOp.getVarPtr(),
41+
inOp.getStructured(), inOp.getImplicit(),
42+
llvm::Twine(inOp.getNameAttr()), inOp.getBounds());
43+
outOp.setDataClause(inOp.getDataClause());
44+
outOp.setModifiers(inOp.getModifiers());
45+
}
3746
}
3847

3948
void emit(CIRGenFunction &cgf) override {
@@ -52,6 +61,9 @@ struct OpenACCDeclareCleanup final : EHScopeStack::Cleanup {
5261
case mlir::acc::DataClause::acc_copy:
5362
createOutOp<mlir::acc::CopyoutOp>(cgf, copyin);
5463
break;
64+
case mlir::acc::DataClause::acc_copyin:
65+
createOutOp<mlir::acc::DeleteOp>(cgf, copyin);
66+
break;
5567
}
5668
} else if (val.getDefiningOp<mlir::acc::DeclareLinkOp>()) {
5769
// Link has no exit clauses, and shouldn't be copied.

clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,12 +826,16 @@ class OpenACCClauseCIREmitter final
826826
addDataOperand<mlir::acc::CopyinOp>(
827827
var, mlir::acc::DataClause::acc_copyin, clause.getModifierList(),
828828
/*structured=*/false, /*implicit=*/false);
829+
} else if constexpr (isOneOfTypes<OpTy, mlir::acc::DeclareEnterOp>) {
830+
for (const Expr *var : clause.getVarList())
831+
addDataOperand<mlir::acc::CopyinOp>(
832+
var, mlir::acc::DataClause::acc_copyin, clause.getModifierList(),
833+
/*structured=*/true,
834+
/*implicit=*/false);
829835
} else if constexpr (isCombinedType<OpTy>) {
830836
applyToComputeOp(clause);
831837
} else {
832-
// TODO: When we've implemented this for everything, switch this to an
833-
// unreachable. declare construct remains.
834-
return clauseNotImplemented(clause);
838+
llvm_unreachable("Unknown construct kind in VisitCopyInClause");
835839
}
836840
}
837841

0 commit comments

Comments
 (0)