Skip to content

[OpenACC][CIR] Basic infrastructure for OpenACC lowering #134717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/AST/DeclOpenACC.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class OpenACCConstructDecl : public Decl {
}

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

class OpenACCDeclareDecl final
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/AST/GlobalDecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "clang/AST/Attr.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclOpenACC.h"
#include "clang/AST/DeclOpenMP.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/Basic/ABI.h"
Expand Down Expand Up @@ -86,6 +87,8 @@ class GlobalDecl {
GlobalDecl(const ObjCMethodDecl *D) { Init(D); }
GlobalDecl(const OMPDeclareReductionDecl *D) { Init(D); }
GlobalDecl(const OMPDeclareMapperDecl *D) { Init(D); }
GlobalDecl(const OpenACCRoutineDecl *D) { Init(D); }
GlobalDecl(const OpenACCDeclareDecl *D) { Init(D); }
GlobalDecl(const CXXConstructorDecl *D, CXXCtorType Type) : Value(D, Type) {}
GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {}
GlobalDecl(const VarDecl *D, DynamicInitKind StubKind)
Expand Down
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -849,4 +849,9 @@ def warn_missing_include_dirs : Warning<

def err_drv_malformed_warning_suppression_mapping : Error<
"failed to process suppression mapping file '%0': %1">;

def warn_drv_openacc_without_cir
: Warning<"OpenACC directives will result in no runtime behavior; use "
"-fclangir to enable runtime effect">,
InGroup<SourceUsesOpenACC>;
}
5 changes: 5 additions & 0 deletions clang/lib/AST/DeclOpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

using namespace clang;

bool OpenACCConstructDecl::classofKind(Kind K) {
return OpenACCDeclareDecl::classofKind(K) ||
OpenACCRoutineDecl::classofKind(K);
}

OpenACCDeclareDecl *
OpenACCDeclareDecl::Create(ASTContext &Ctx, DeclContext *DC,
SourceLocation StartLoc, SourceLocation DirLoc,
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "mlir/IR/Location.h"
#include "clang/AST/Attr.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclOpenACC.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
#include "clang/CIR/MissingFeatures.h"
Expand Down Expand Up @@ -266,6 +267,12 @@ void CIRGenFunction::emitDecl(const Decl &d) {
emitVarDecl(vd);
return;
}
case Decl::OpenACCDeclare:
emitOpenACCDeclare(cast<OpenACCDeclareDecl>(d));
return;
case Decl::OpenACCRoutine:
emitOpenACCRoutine(cast<OpenACCRoutineDecl>(d));
return;
default:
cgm.errorNYI(d.getSourceRange(), "emitDecl: unhandled decl type");
}
Expand Down
34 changes: 34 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenDeclOpenACC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This contains code to emit Decl nodes as CIR code.
//
//===----------------------------------------------------------------------===//

#include "CIRGenFunction.h"
#include "clang/AST/DeclOpenACC.h"

using namespace clang;
using namespace clang::CIRGen;

void CIRGenFunction::emitOpenACCDeclare(const OpenACCDeclareDecl &d) {
getCIRGenModule().errorNYI(d.getSourceRange(), "OpenACC Declare Construct");
}

void CIRGenFunction::emitOpenACCRoutine(const OpenACCRoutineDecl &d) {
getCIRGenModule().errorNYI(d.getSourceRange(), "OpenACC Routine Construct");
}

void CIRGenModule::emitGlobalOpenACCDecl(const OpenACCConstructDecl *d) {
if (isa<OpenACCRoutineDecl>(d))
errorNYI(d->getSourceRange(), "OpenACC Routine Construct");
else if (isa<OpenACCDeclareDecl>(d))
errorNYI(d->getSourceRange(), "OpenACC Declare Construct");
else
llvm_unreachable("unknown OpenACC declaration kind?");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be an errorNYI or llvm_unreachable call for the case where this is neither of the above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, unreachable. I'll add it.

30 changes: 30 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,36 @@ class CIRGenFunction : public CIRGenTypeCache {
public:
Address createTempAlloca(mlir::Type ty, CharUnits align, mlir::Location loc,
const Twine &name, bool insertIntoFnEntryBlock);

//===--------------------------------------------------------------------===//
// OpenACC Emission
//===--------------------------------------------------------------------===//
public:
mlir::LogicalResult
emitOpenACCComputeConstruct(const OpenACCComputeConstruct &s);
mlir::LogicalResult emitOpenACCLoopConstruct(const OpenACCLoopConstruct &s);
mlir::LogicalResult
emitOpenACCCombinedConstruct(const OpenACCCombinedConstruct &s);
mlir::LogicalResult emitOpenACCDataConstruct(const OpenACCDataConstruct &s);
mlir::LogicalResult
emitOpenACCEnterDataConstruct(const OpenACCEnterDataConstruct &s);
mlir::LogicalResult
emitOpenACCExitDataConstruct(const OpenACCExitDataConstruct &s);
mlir::LogicalResult
emitOpenACCHostDataConstruct(const OpenACCHostDataConstruct &s);
mlir::LogicalResult emitOpenACCWaitConstruct(const OpenACCWaitConstruct &s);
mlir::LogicalResult emitOpenACCInitConstruct(const OpenACCInitConstruct &s);
mlir::LogicalResult
emitOpenACCShutdownConstruct(const OpenACCShutdownConstruct &s);
mlir::LogicalResult emitOpenACCSetConstruct(const OpenACCSetConstruct &s);
mlir::LogicalResult
emitOpenACCUpdateConstruct(const OpenACCUpdateConstruct &s);
mlir::LogicalResult
emitOpenACCAtomicConstruct(const OpenACCAtomicConstruct &s);
mlir::LogicalResult emitOpenACCCacheConstruct(const OpenACCCacheConstruct &s);

void emitOpenACCDeclare(const OpenACCDeclareDecl &d);
void emitOpenACCRoutine(const OpenACCRoutineDecl &d);
};

} // namespace clang::CIRGen
Expand Down
12 changes: 12 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclOpenACC.h"
#include "clang/AST/GlobalDecl.h"
#include "clang/Basic/SourceManager.h"
#include "clang/CIR/Dialect/IR/CIRDialect.h"
Expand Down Expand Up @@ -91,6 +92,11 @@ mlir::Location CIRGenModule::getLoc(SourceRange cRange) {
}

void CIRGenModule::emitGlobal(clang::GlobalDecl gd) {
if (const auto *cd = dyn_cast<clang::OpenACCConstructDecl>(gd.getDecl())) {
emitGlobalOpenACCDecl(cd);
return;
}

const auto *global = cast<ValueDecl>(gd.getDecl());

if (const auto *fd = dyn_cast<FunctionDecl>(global)) {
Expand Down Expand Up @@ -423,6 +429,12 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
emitGlobal(vd);
break;
}
case Decl::OpenACCRoutine:
emitGlobalOpenACCDecl(cast<OpenACCRoutineDecl>(decl));
break;
case Decl::OpenACCDeclare:
emitGlobalOpenACCDecl(cast<OpenACCDeclareDecl>(decl));
break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class CIRGenModule : public CIRGenTypeCache {
void emitGlobalVarDefinition(const clang::VarDecl *vd,
bool isTentative = false);

void emitGlobalOpenACCDecl(const clang::OpenACCConstructDecl *cd);

/// Return the result of value-initializing the given type, i.e. a null
/// expression of the given type.
mlir::Value emitNullConstant(QualType t, mlir::Location loc);
Expand Down
44 changes: 29 additions & 15 deletions clang/lib/CIR/CodeGen/CIRGenStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "mlir/IR/Builders.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/Stmt.h"
#include "clang/AST/StmtOpenACC.h"

using namespace clang;
using namespace clang::CIRGen;
Expand Down Expand Up @@ -85,7 +86,34 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
return emitWhileStmt(cast<WhileStmt>(*s));
case Stmt::DoStmtClass:
return emitDoStmt(cast<DoStmt>(*s));

case Stmt::OpenACCComputeConstructClass:
return emitOpenACCComputeConstruct(cast<OpenACCComputeConstruct>(*s));
case Stmt::OpenACCLoopConstructClass:
return emitOpenACCLoopConstruct(cast<OpenACCLoopConstruct>(*s));
case Stmt::OpenACCCombinedConstructClass:
return emitOpenACCCombinedConstruct(cast<OpenACCCombinedConstruct>(*s));
case Stmt::OpenACCDataConstructClass:
return emitOpenACCDataConstruct(cast<OpenACCDataConstruct>(*s));
case Stmt::OpenACCEnterDataConstructClass:
return emitOpenACCEnterDataConstruct(cast<OpenACCEnterDataConstruct>(*s));
case Stmt::OpenACCExitDataConstructClass:
return emitOpenACCExitDataConstruct(cast<OpenACCExitDataConstruct>(*s));
case Stmt::OpenACCHostDataConstructClass:
return emitOpenACCHostDataConstruct(cast<OpenACCHostDataConstruct>(*s));
case Stmt::OpenACCWaitConstructClass:
return emitOpenACCWaitConstruct(cast<OpenACCWaitConstruct>(*s));
case Stmt::OpenACCInitConstructClass:
return emitOpenACCInitConstruct(cast<OpenACCInitConstruct>(*s));
case Stmt::OpenACCShutdownConstructClass:
return emitOpenACCShutdownConstruct(cast<OpenACCShutdownConstruct>(*s));
case Stmt::OpenACCSetConstructClass:
return emitOpenACCSetConstruct(cast<OpenACCSetConstruct>(*s));
case Stmt::OpenACCUpdateConstructClass:
return emitOpenACCUpdateConstruct(cast<OpenACCUpdateConstruct>(*s));
case Stmt::OpenACCCacheConstructClass:
return emitOpenACCCacheConstruct(cast<OpenACCCacheConstruct>(*s));
case Stmt::OpenACCAtomicConstructClass:
return emitOpenACCAtomicConstruct(cast<OpenACCAtomicConstruct>(*s));
case Stmt::OMPScopeDirectiveClass:
case Stmt::OMPErrorDirectiveClass:
case Stmt::NoStmtClass:
Expand Down Expand Up @@ -192,20 +220,6 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
case Stmt::OMPAssumeDirectiveClass:
case Stmt::OMPMaskedDirectiveClass:
case Stmt::OMPStripeDirectiveClass:
case Stmt::OpenACCComputeConstructClass:
case Stmt::OpenACCLoopConstructClass:
case Stmt::OpenACCCombinedConstructClass:
case Stmt::OpenACCDataConstructClass:
case Stmt::OpenACCEnterDataConstructClass:
case Stmt::OpenACCExitDataConstructClass:
case Stmt::OpenACCHostDataConstructClass:
case Stmt::OpenACCWaitConstructClass:
case Stmt::OpenACCInitConstructClass:
case Stmt::OpenACCShutdownConstructClass:
case Stmt::OpenACCSetConstructClass:
case Stmt::OpenACCUpdateConstructClass:
case Stmt::OpenACCCacheConstructClass:
case Stmt::OpenACCAtomicConstructClass:
case Stmt::ObjCAtCatchStmtClass:
case Stmt::ObjCAtFinallyStmtClass:
cgm.errorNYI(s->getSourceRange(),
Expand Down
91 changes: 91 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenStmtOpenACC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Emit OpenACC Stmt nodes as CIR code.
//
//===----------------------------------------------------------------------===//

#include "CIRGenBuilder.h"
#include "CIRGenFunction.h"
#include "clang/AST/StmtOpenACC.h"

using namespace clang;
using namespace clang::CIRGen;
using namespace cir;

mlir::LogicalResult
CIRGenFunction::emitOpenACCComputeConstruct(const OpenACCComputeConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Compute Construct");
return mlir::failure();
}

mlir::LogicalResult
CIRGenFunction::emitOpenACCLoopConstruct(const OpenACCLoopConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Loop Construct");
return mlir::failure();
}
mlir::LogicalResult CIRGenFunction::emitOpenACCCombinedConstruct(
const OpenACCCombinedConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Combined Construct");
return mlir::failure();
}
mlir::LogicalResult
CIRGenFunction::emitOpenACCDataConstruct(const OpenACCDataConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Data Construct");
return mlir::failure();
}
mlir::LogicalResult CIRGenFunction::emitOpenACCEnterDataConstruct(
const OpenACCEnterDataConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC EnterData Construct");
return mlir::failure();
}
mlir::LogicalResult CIRGenFunction::emitOpenACCExitDataConstruct(
const OpenACCExitDataConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC ExitData Construct");
return mlir::failure();
}
mlir::LogicalResult CIRGenFunction::emitOpenACCHostDataConstruct(
const OpenACCHostDataConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC HostData Construct");
return mlir::failure();
}
mlir::LogicalResult
CIRGenFunction::emitOpenACCWaitConstruct(const OpenACCWaitConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Wait Construct");
return mlir::failure();
}
mlir::LogicalResult
CIRGenFunction::emitOpenACCInitConstruct(const OpenACCInitConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Init Construct");
return mlir::failure();
}
mlir::LogicalResult CIRGenFunction::emitOpenACCShutdownConstruct(
const OpenACCShutdownConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Shutdown Construct");
return mlir::failure();
}
mlir::LogicalResult
CIRGenFunction::emitOpenACCSetConstruct(const OpenACCSetConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Set Construct");
return mlir::failure();
}
mlir::LogicalResult
CIRGenFunction::emitOpenACCUpdateConstruct(const OpenACCUpdateConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Update Construct");
return mlir::failure();
}
mlir::LogicalResult
CIRGenFunction::emitOpenACCAtomicConstruct(const OpenACCAtomicConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Atomic Construct");
return mlir::failure();
}
mlir::LogicalResult
CIRGenFunction::emitOpenACCCacheConstruct(const OpenACCCacheConstruct &s) {
getCIRGenModule().errorNYI(s.getSourceRange(), "OpenACC Cache Construct");
return mlir::failure();
}
2 changes: 2 additions & 0 deletions clang/lib/CIR/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
add_clang_library(clangCIR
CIRGenerator.cpp
CIRGenDecl.cpp
CIRGenDeclOpenACC.cpp
CIRGenExpr.cpp
CIRGenExprAggregate.cpp
CIRGenExprConstant.cpp
CIRGenExprScalar.cpp
CIRGenFunction.cpp
CIRGenModule.cpp
CIRGenStmt.cpp
CIRGenStmtOpenACC.cpp
CIRGenTypes.cpp

DEPENDS
Expand Down
Loading