Skip to content

Commit 0c0892e

Browse files
committed
[OpenACC][CIR] Basic infrastructure for OpenACC lowering
This is the first of a few patches that will do infrastructure work to enable the OpenACC lowering via the OpenACC dialect. At the moment this just gets the various function calls that will end up generating OpenACC, plus some tests to validate that we're doing the diagnostics in OpenACC specific locations. Additionally, this adds Stmt and Decl files for CIRGen.
1 parent 9965f3d commit 0c0892e

16 files changed

+293
-5
lines changed

clang/include/clang/AST/DeclOpenACC.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class OpenACCConstructDecl : public Decl {
5959
}
6060

6161
ArrayRef<const OpenACCClause *> clauses() const { return Clauses; }
62+
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
63+
static bool classofKind(Kind K);
6264
};
6365

6466
class OpenACCDeclareDecl final

clang/include/clang/AST/GlobalDecl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/AST/Attr.h"
1818
#include "clang/AST/DeclCXX.h"
1919
#include "clang/AST/DeclObjC.h"
20+
#include "clang/AST/DeclOpenACC.h"
2021
#include "clang/AST/DeclOpenMP.h"
2122
#include "clang/AST/DeclTemplate.h"
2223
#include "clang/Basic/ABI.h"
@@ -86,6 +87,8 @@ class GlobalDecl {
8687
GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
8788
GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
8889
GlobalDecl(const OMPDeclareMapperDecl *D) { Init(D); }
90+
GlobalDecl(const OpenACCRoutineDecl *D) { Init(D); }
91+
GlobalDecl(const OpenACCDeclareDecl *D) { Init(D); }
8992
GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {}
9093
GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {}
9194
GlobalDecl(const VarDecl *D, DynamicInitKind StubKind)

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,4 +849,9 @@ def warn_missing_include_dirs : Warning<
849849

850850
def err_drv_malformed_warning_suppression_mapping : Error<
851851
"failed to process suppression mapping file '%0': %1">;
852+
853+
def warn_drv_openacc_without_cir
854+
: Warning<"OpenACC directives will result in no runtime behavior, use "
855+
"-fclangir to enable runtime effect">,
856+
InGroup<SourceUsesOpenACC>;
852857
}

clang/lib/AST/DeclOpenACC.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
using namespace clang;
1919

20+
bool OpenACCConstructDecl::classofKind(Kind K) {
21+
return OpenACCDeclareDecl::classofKind(K) ||
22+
OpenACCRoutineDecl::classofKind(K);
23+
}
24+
2025
OpenACCDeclareDecl *
2126
OpenACCDeclareDecl::Create(ASTContext &Ctx, DeclContext *DC,
2227
SourceLocation StartLoc, SourceLocation DirLoc,

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "mlir/IR/Location.h"
1616
#include "clang/AST/Attr.h"
1717
#include "clang/AST/Decl.h"
18+
#include "clang/AST/DeclOpenACC.h"
1819
#include "clang/AST/Expr.h"
1920
#include "clang/AST/ExprCXX.h"
2021
#include "clang/CIR/MissingFeatures.h"
@@ -266,6 +267,12 @@ void CIRGenFunction::emitDecl(const Decl &d) {
266267
emitVarDecl(vd);
267268
return;
268269
}
270+
case Decl::OpenACCDeclare:
271+
emitOpenACCDeclare(cast<OpenACCDeclareDecl>(d));
272+
return;
273+
case Decl::OpenACCRoutine:
274+
emitOpenACCRoutine(cast<OpenACCRoutineDecl>(d));
275+
return;
269276
default:
270277
cgm.errorNYI(d.getSourceRange(), "emitDecl: unhandled decl type");
271278
}

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,36 @@ class CIRGenFunction : public CIRGenTypeCache {
509509
public:
510510
Address createTempAlloca(mlir::Type ty, CharUnits align, mlir::Location loc,
511511
const Twine &name, bool insertIntoFnEntryBlock);
512+
513+
//===--------------------------------------------------------------------===//
514+
// OpenACC Emission
515+
//===--------------------------------------------------------------------===//
516+
public:
517+
mlir::LogicalResult
518+
emitOpenACCComputeConstruct(const OpenACCComputeConstruct &S);
519+
mlir::LogicalResult emitOpenACCLoopConstruct(const OpenACCLoopConstruct &S);
520+
mlir::LogicalResult
521+
emitOpenACCCombinedConstruct(const OpenACCCombinedConstruct &S);
522+
mlir::LogicalResult emitOpenACCDataConstruct(const OpenACCDataConstruct &S);
523+
mlir::LogicalResult
524+
emitOpenACCEnterDataConstruct(const OpenACCEnterDataConstruct &S);
525+
mlir::LogicalResult
526+
emitOpenACCExitDataConstruct(const OpenACCExitDataConstruct &S);
527+
mlir::LogicalResult
528+
emitOpenACCHostDataConstruct(const OpenACCHostDataConstruct &S);
529+
mlir::LogicalResult emitOpenACCWaitConstruct(const OpenACCWaitConstruct &S);
530+
mlir::LogicalResult emitOpenACCInitConstruct(const OpenACCInitConstruct &S);
531+
mlir::LogicalResult
532+
emitOpenACCShutdownConstruct(const OpenACCShutdownConstruct &S);
533+
mlir::LogicalResult emitOpenACCSetConstruct(const OpenACCSetConstruct &S);
534+
mlir::LogicalResult
535+
emitOpenACCUpdateConstruct(const OpenACCUpdateConstruct &S);
536+
mlir::LogicalResult
537+
emitOpenACCAtomicConstruct(const OpenACCAtomicConstruct &S);
538+
mlir::LogicalResult emitOpenACCCacheConstruct(const OpenACCCacheConstruct &S);
539+
540+
void emitOpenACCDeclare(const OpenACCDeclareDecl &D);
541+
void emitOpenACCRoutine(const OpenACCRoutineDecl &D);
512542
};
513543

514544
} // namespace clang::CIRGen

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/AST/ASTContext.h"
1818
#include "clang/AST/DeclBase.h"
1919
#include "clang/AST/GlobalDecl.h"
20+
#include "clang/AST/DeclOpenACC.h"
2021
#include "clang/Basic/SourceManager.h"
2122
#include "clang/CIR/Dialect/IR/CIRDialect.h"
2223
#include "clang/CIR/MissingFeatures.h"
@@ -91,6 +92,11 @@ mlir::Location CIRGenModule::getLoc(SourceRange cRange) {
9192
}
9293

9394
void CIRGenModule::emitGlobal(clang::GlobalDecl gd) {
95+
if (const auto *cd = dyn_cast<clang::OpenACCConstructDecl>(gd.getDecl())) {
96+
emitGlobalOpenACCDecl(cd);
97+
return;
98+
}
99+
94100
const auto *global = cast<ValueDecl>(gd.getDecl());
95101

96102
if (const auto *fd = dyn_cast<FunctionDecl>(global)) {
@@ -423,6 +429,12 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
423429
emitGlobal(vd);
424430
break;
425431
}
432+
case Decl::OpenACCRoutine:
433+
emitGlobalOpenACCDecl(cast<OpenACCRoutineDecl>(decl));
434+
break;
435+
case Decl::OpenACCDeclare:
436+
emitGlobalOpenACCDecl(cast<OpenACCDeclareDecl>(decl));
437+
break;
426438
}
427439
}
428440

clang/lib/CIR/CodeGen/CIRGenModule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class CIRGenModule : public CIRGenTypeCache {
113113
void emitGlobalVarDefinition(const clang::VarDecl *vd,
114114
bool isTentative = false);
115115

116+
void emitGlobalOpenACCDecl(const clang::OpenACCConstructDecl *cd);
117+
116118
/// Return the result of value-initializing the given type, i.e. a null
117119
/// expression of the given type.
118120
mlir::Value emitNullConstant(QualType t, mlir::Location loc);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This contains code to emit Decl nodes as CIR code.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "CIRGenFunction.h"
14+
#include "clang/AST/DeclOpenACC.h"
15+
16+
using namespace clang;
17+
using namespace clang::CIRGen;
18+
19+
void CIRGenFunction::emitOpenACCDeclare(const OpenACCDeclareDecl &d) {
20+
getCIRGenModule().errorNYI(d.getSourceRange(), "OpenACC Declare Construct");
21+
}
22+
23+
void CIRGenFunction::emitOpenACCRoutine(const OpenACCRoutineDecl &d) {
24+
getCIRGenModule().errorNYI(d.getSourceRange(), "OpenACC Routine Construct");
25+
}
26+
27+
void CIRGenModule::emitGlobalOpenACCDecl(const OpenACCConstructDecl *d) {
28+
if (isa<OpenACCRoutineDecl>(d))
29+
errorNYI(d->getSourceRange(), "OpenACC Routine Construct");
30+
else if (isa<OpenACCDeclareDecl>(d))
31+
errorNYI(d->getSourceRange(), "OpenACC Declare Construct");
32+
33+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Emit OpenACC Stmt nodes as CIR code.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "CIRGenBuilder.h"
14+
#include "CIRGenFunction.h"
15+
#include "clang/AST/StmtOpenACC.h"
16+
17+
using namespace clang;
18+
using namespace clang::CIRGen;
19+
using namespace cir;
20+
21+
mlir::LogicalResult
22+
CIRGenFunction::emitOpenACCComputeConstruct(const OpenACCComputeConstruct &s) {
23+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Compute Construct");
24+
return mlir::failure();
25+
}
26+
27+
mlir::LogicalResult
28+
CIRGenFunction::emitOpenACCLoopConstruct(const OpenACCLoopConstruct &s) {
29+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Loop Construct");
30+
return mlir::failure();
31+
}
32+
mlir::LogicalResult CIRGenFunction::emitOpenACCCombinedConstruct(
33+
const OpenACCCombinedConstruct &s) {
34+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Combined Construct");
35+
return mlir::failure();
36+
}
37+
mlir::LogicalResult
38+
CIRGenFunction::emitOpenACCDataConstruct(const OpenACCDataConstruct &s) {
39+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Data Construct");
40+
return mlir::failure();
41+
}
42+
mlir::LogicalResult CIRGenFunction::emitOpenACCEnterDataConstruct(
43+
const OpenACCEnterDataConstruct &s) {
44+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC EnterData Construct");
45+
return mlir::failure();
46+
}
47+
mlir::LogicalResult CIRGenFunction::emitOpenACCExitDataConstruct(
48+
const OpenACCExitDataConstruct &s) {
49+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC ExitData Construct");
50+
return mlir::failure();
51+
}
52+
mlir::LogicalResult CIRGenFunction::emitOpenACCHostDataConstruct(
53+
const OpenACCHostDataConstruct &s) {
54+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC HostData Construct");
55+
return mlir::failure();
56+
}
57+
mlir::LogicalResult
58+
CIRGenFunction::emitOpenACCWaitConstruct(const OpenACCWaitConstruct &s) {
59+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Wait Construct");
60+
return mlir::failure();
61+
}
62+
mlir::LogicalResult
63+
CIRGenFunction::emitOpenACCInitConstruct(const OpenACCInitConstruct &s) {
64+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Init Construct");
65+
return mlir::failure();
66+
}
67+
mlir::LogicalResult CIRGenFunction::emitOpenACCShutdownConstruct(
68+
const OpenACCShutdownConstruct &s) {
69+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Shutdown Construct");
70+
return mlir::failure();
71+
}
72+
mlir::LogicalResult
73+
CIRGenFunction::emitOpenACCSetConstruct(const OpenACCSetConstruct &s) {
74+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Set Construct");
75+
return mlir::failure();
76+
}
77+
mlir::LogicalResult
78+
CIRGenFunction::emitOpenACCUpdateConstruct(const OpenACCUpdateConstruct &s) {
79+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Update Construct");
80+
return mlir::failure();
81+
}
82+
mlir::LogicalResult
83+
CIRGenFunction::emitOpenACCAtomicConstruct(const OpenACCAtomicConstruct &s) {
84+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Atomic Construct");
85+
return mlir::failure();
86+
}
87+
mlir::LogicalResult
88+
CIRGenFunction::emitOpenACCCacheConstruct(const OpenACCCacheConstruct &s) {
89+
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Cache Construct");
90+
return mlir::failure();
91+
}

0 commit comments

Comments
 (0)