Skip to content

Commit 77db154

Browse files
committed
[OpenACC][CIR] implement basic 'set' lowering with device_type clause
The 'set' lowering is pretty trivial. 'device_type' is a little more restricted since both the MLIR-Dialect and language limit it to only 1 value (as confirmed by standards-discussion). This patch implements 'set', with 'device_type', since 'set' requires at least 1 clause, and this is the least difficult to implement at the moment.
1 parent f4203ca commit 77db154

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

clang/lib/CIR/CodeGen/CIRGenStmtOpenACC.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class OpenACCClauseCIREmitter final
9292

9393
switch (dirKind) {
9494
case OpenACCDirectiveKind::Init:
95+
case OpenACCDirectiveKind::Set:
9596
case OpenACCDirectiveKind::Shutdown: {
9697
// Device type has a list that is either a 'star' (emitted as 'star'),
9798
// or an identifer list, all of which get added for attributes.
@@ -133,6 +134,11 @@ class OpenACCClauseCIREmitter final
133134

134135
op.setDeviceTypesAttr(
135136
mlir::ArrayAttr::get(builder.getContext(), deviceTypes));
137+
} else if constexpr (isOneOfTypes<Op, SetOp>) {
138+
assert(attrData.deviceTypeArchs.size() <= 1 &&
139+
"Set can only have a single architecture");
140+
if (!attrData.deviceTypeArchs.empty())
141+
op.setDeviceType(attrData.deviceTypeArchs[0]);
136142
} else {
137143
cgm.errorNYI(dirLoc, "OpenACC 'device_type' clause lowering for ",
138144
dirKind);
@@ -232,6 +238,13 @@ CIRGenFunction::emitOpenACCInitConstruct(const OpenACCInitConstruct &s) {
232238
s.clauses());
233239
}
234240

241+
mlir::LogicalResult
242+
CIRGenFunction::emitOpenACCSetConstruct(const OpenACCSetConstruct &s) {
243+
mlir::Location start = getLoc(s.getSourceRange().getEnd());
244+
return emitOpenACCOp<SetOp>(start, s.getDirectiveKind(), s.getDirectiveLoc(),
245+
s.clauses());
246+
}
247+
235248
mlir::LogicalResult CIRGenFunction::emitOpenACCShutdownConstruct(
236249
const OpenACCShutdownConstruct &s) {
237250
mlir::Location start = getLoc(s.getSourceRange().getEnd());
@@ -270,11 +283,6 @@ CIRGenFunction::emitOpenACCWaitConstruct(const OpenACCWaitConstruct &s) {
270283
return mlir::failure();
271284
}
272285
mlir::LogicalResult
273-
CIRGenFunction::emitOpenACCSetConstruct(const OpenACCSetConstruct &s) {
274-
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Set Construct");
275-
return mlir::failure();
276-
}
277-
mlir::LogicalResult
278286
CIRGenFunction::emitOpenACCUpdateConstruct(const OpenACCUpdateConstruct &s) {
279287
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Update Construct");
280288
return mlir::failure();

clang/test/CIR/CodeGenOpenACC/set.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -fopenacc -emit-cir -fclangir %s -o - | FileCheck %s
2+
3+
void acc_set(void) {
4+
// CHECK: cir.func @acc_set() {
5+
6+
#pragma acc set device_type(*)
7+
// CHECK-NEXT: acc.set attributes {device_type = #acc.device_type<star>}
8+
9+
// Set doesn't allow multiple device_type clauses, so no need to test them.
10+
#pragma acc set device_type(radeon)
11+
// CHECK-NEXT: acc.set attributes {device_type = #acc.device_type<radeon>}
12+
13+
// CHECK-NEXT: cir.return
14+
}

0 commit comments

Comments
 (0)