Skip to content

Commit 658675f

Browse files
authored
[OpenACC][CIR] 'device_resident' clause lowering for local declare (#169389)
Just like the last handful of clauses, this is a pretty simple one, doing device_resident (Entry op: declare_device_resident, and exit: delete). This should be the last of the 'local' declare patches.
1 parent 4a0d485 commit 658675f

File tree

3 files changed

+219
-8
lines changed

3 files changed

+219
-8
lines changed

clang/lib/CIR/CodeGen/CIRGenDeclOpenACC.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ using namespace clang::CIRGen;
1919

2020
namespace {
2121
struct OpenACCDeclareCleanup final : EHScopeStack::Cleanup {
22-
SourceRange declareRange;
2322
mlir::acc::DeclareEnterOp enterOp;
2423

25-
OpenACCDeclareCleanup(SourceRange declareRange,
26-
mlir::acc::DeclareEnterOp enterOp)
27-
: declareRange(declareRange), enterOp(enterOp) {}
24+
OpenACCDeclareCleanup(mlir::acc::DeclareEnterOp enterOp) : enterOp(enterOp) {}
2825

2926
template <typename OutTy, typename InTy>
3027
void createOutOp(CIRGenFunction &cgf, InTy inOp) {
@@ -78,16 +75,19 @@ struct OpenACCDeclareCleanup final : EHScopeStack::Cleanup {
7875
createOutOp<mlir::acc::DeleteOp>(cgf, create);
7976
break;
8077
}
81-
} else if (auto create = val.getDefiningOp<mlir::acc::PresentOp>()) {
82-
createOutOp<mlir::acc::DeleteOp>(cgf, create);
78+
} else if (auto present = val.getDefiningOp<mlir::acc::PresentOp>()) {
79+
createOutOp<mlir::acc::DeleteOp>(cgf, present);
80+
} else if (auto dev_res =
81+
val.getDefiningOp<mlir::acc::DeclareDeviceResidentOp>()) {
82+
createOutOp<mlir::acc::DeleteOp>(cgf, dev_res);
8383
} else if (val.getDefiningOp<mlir::acc::DeclareLinkOp>()) {
8484
// Link has no exit clauses, and shouldn't be copied.
8585
continue;
8686
} else if (val.getDefiningOp<mlir::acc::DevicePtrOp>()) {
8787
// DevicePtr has no exit clauses, and shouldn't be copied.
8888
continue;
8989
} else {
90-
cgf.cgm.errorNYI(declareRange, "OpenACC local declare clause cleanup");
90+
llvm_unreachable("OpenACC local declare clause unexpected defining op");
9191
continue;
9292
}
9393
exitOp.getDataClauseOperandsMutable().append(val);
@@ -106,7 +106,7 @@ void CIRGenFunction::emitOpenACCDeclare(const OpenACCDeclareDecl &d) {
106106
d.clauses());
107107

108108
ehStack.pushCleanup<OpenACCDeclareCleanup>(CleanupKind::NormalCleanup,
109-
d.getSourceRange(), enterOp);
109+
enterOp);
110110
}
111111

112112
void CIRGenFunction::emitOpenACCRoutine(const OpenACCRoutineDecl &d) {

clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,18 @@ class OpenACCClauseCIREmitter final
11351135
llvm_unreachable("Unknown construct kind in VisitReductionClause");
11361136
}
11371137
}
1138+
1139+
void VisitDeviceResidentClause(const OpenACCDeviceResidentClause &clause) {
1140+
if constexpr (isOneOfTypes<OpTy, mlir::acc::DeclareEnterOp>) {
1141+
for (const Expr *var : clause.getVarList())
1142+
addDataOperand<mlir::acc::DeclareDeviceResidentOp>(
1143+
var, mlir::acc::DataClause::acc_declare_device_resident, {},
1144+
/*structured=*/true,
1145+
/*implicit=*/false);
1146+
} else {
1147+
llvm_unreachable("Unknown construct kind in VisitDeviceResidentClause");
1148+
}
1149+
}
11381150
};
11391151

11401152
template <typename OpTy>

0 commit comments

Comments
 (0)