Skip to content

Commit 505a7e7

Browse files
committed
[OpenACC][CIR] Support for init and shutdown lowering
These two are very simple. they don't require any clauses and don't have an associated statement, so they have very simple output. This patch implements them, but none of the associated clauses.
1 parent 9dc6551 commit 505a7e7

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,10 @@ class CIRGenFunction : public CIRGenTypeCache {
571571
// OpenACC Emission
572572
//===--------------------------------------------------------------------===//
573573
private:
574+
template <typename Op>
575+
mlir::LogicalResult
576+
emitOpenACCOp(mlir::Location start,
577+
llvm::ArrayRef<const OpenACCClause *> clauses);
574578
// Function to do the basic implementation of an operation with an Associated
575579
// Statement. Models AssociatedStmtConstruct.
576580
template <typename Op, typename TermOp>

clang/lib/CIR/CodeGen/CIRGenStmtOpenACC.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ mlir::LogicalResult CIRGenFunction::emitOpenACCOpAssociatedStmt(
9494
return res;
9595
}
9696

97+
template <typename Op>
98+
mlir::LogicalResult
99+
CIRGenFunction::emitOpenACCOp(mlir::Location start,
100+
llvm::ArrayRef<const OpenACCClause *> clauses) {
101+
mlir::LogicalResult res = mlir::success();
102+
103+
llvm::SmallVector<mlir::Type> retTy;
104+
llvm::SmallVector<mlir::Value> operands;
105+
106+
// Clause-emitter must be here because it might modify operands.
107+
OpenACCClauseCIREmitter clauseEmitter(getCIRGenModule());
108+
clauseEmitter.VisitClauseList(clauses);
109+
110+
builder.create<Op>(start, retTy, operands);
111+
return res;
112+
}
113+
97114
mlir::LogicalResult
98115
CIRGenFunction::emitOpenACCComputeConstruct(const OpenACCComputeConstruct &s) {
99116
mlir::Location start = getLoc(s.getSourceRange().getEnd());
@@ -123,6 +140,17 @@ CIRGenFunction::emitOpenACCDataConstruct(const OpenACCDataConstruct &s) {
123140
start, end, s.clauses(), s.getStructuredBlock());
124141
}
125142

143+
mlir::LogicalResult
144+
CIRGenFunction::emitOpenACCInitConstruct(const OpenACCInitConstruct &s) {
145+
mlir::Location start = getLoc(s.getSourceRange().getEnd());
146+
return emitOpenACCOp<InitOp>(start, s.clauses());
147+
}
148+
mlir::LogicalResult CIRGenFunction::emitOpenACCShutdownConstruct(
149+
const OpenACCShutdownConstruct &s) {
150+
mlir::Location start = getLoc(s.getSourceRange().getEnd());
151+
return emitOpenACCOp<ShutdownOp>(start, s.clauses());
152+
}
153+
126154
mlir::LogicalResult
127155
CIRGenFunction::emitOpenACCLoopConstruct(const OpenACCLoopConstruct &s) {
128156
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Loop Construct");
@@ -154,16 +182,6 @@ CIRGenFunction::emitOpenACCWaitConstruct(const OpenACCWaitConstruct &s) {
154182
return mlir::failure();
155183
}
156184
mlir::LogicalResult
157-
CIRGenFunction::emitOpenACCInitConstruct(const OpenACCInitConstruct &s) {
158-
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Init Construct");
159-
return mlir::failure();
160-
}
161-
mlir::LogicalResult CIRGenFunction::emitOpenACCShutdownConstruct(
162-
const OpenACCShutdownConstruct &s) {
163-
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Shutdown Construct");
164-
return mlir::failure();
165-
}
166-
mlir::LogicalResult
167185
CIRGenFunction::emitOpenACCSetConstruct(const OpenACCSetConstruct &s) {
168186
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Set Construct");
169187
return mlir::failure();

clang/test/CIR/CodeGenOpenACC/init.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %clang_cc1 -fopenacc -emit-cir -fclangir %s -o - | FileCheck %s
2+
3+
void acc_init(void) {
4+
// CHECK: cir.func @acc_init() {
5+
#pragma acc init
6+
// CHECK-NEXT: acc.init loc(#{{[a-zA-Z0-9]+}}){{$}}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %clang_cc1 -fopenacc -emit-cir -fclangir %s -o - | FileCheck %s
2+
3+
void acc_shutdown(void) {
4+
// CHECK: cir.func @acc_shutdown() {
5+
#pragma acc shutdown
6+
// CHECK-NEXT: acc.shutdown loc(#{{[a-zA-Z0-9]+}}){{$}}
7+
}

0 commit comments

Comments
 (0)