Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
50 changes: 42 additions & 8 deletions clang/lib/CIR/CodeGen/CIRGenDeclOpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,52 @@ using namespace clang::CIRGen;

namespace {
struct OpenACCDeclareCleanup final : EHScopeStack::Cleanup {
SourceRange declareRange;
mlir::acc::DeclareEnterOp enterOp;

OpenACCDeclareCleanup(mlir::acc::DeclareEnterOp enterOp) : enterOp(enterOp) {}
OpenACCDeclareCleanup(SourceRange declareRange,
mlir::acc::DeclareEnterOp enterOp)
: declareRange(declareRange), enterOp(enterOp) {}

template <typename OutTy, typename InTy>
void createOutOp(CIRGenFunction &cgf, InTy inOp) {
auto outOp =
OutTy::create(cgf.getBuilder(), inOp.getLoc(), inOp, inOp.getVarPtr(),
inOp.getStructured(), inOp.getImplicit(),
inOp.getName() ? *inOp.getName() : "", inOp.getBounds());
Copy link
Member

@bcardosolopes bcardosolopes Nov 22, 2025

Choose a reason for hiding this comment

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

Is inOp.getName() a StringAttr? If so Twine(inOp.getName()) could be more readable here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its an optional<StringRef>. So the goofy dereference is caused by that. That said, I COULD just do inOp.getNameAttr wrapped in a Twine? I didn't realize that would work, I'll give it a shot!

outOp.setDataClause(inOp.getDataClause());
outOp.setModifiers(inOp.getModifiers());
}

void emit(CIRGenFunction &cgf) override {
mlir::acc::DeclareExitOp::create(cgf.getBuilder(), enterOp.getLoc(),
enterOp, {});
auto exitOp = mlir::acc::DeclareExitOp::create(
cgf.getBuilder(), enterOp.getLoc(), enterOp, {});

// TODO(OpenACC): Some clauses require that we add info about them to the
// DeclareExitOp. However, we don't have any of those implemented yet, so
// we should add infrastructure here to do that once we have one
// implemented.
// Some data clauses need to be referenced in 'exit', AND need to have an
// operation after the exit. Copy these from the enter operation.
for (mlir::Value val : enterOp.getDataClauseOperands()) {
if (auto copyin = val.getDefiningOp<mlir::acc::CopyinOp>()) {
switch (copyin.getDataClause()) {
default:
cgf.cgm.errorNYI(declareRange,
"OpenACC local declare clause copyin cleanup");
break;
case mlir::acc::DataClause::acc_copy:
createOutOp<mlir::acc::CopyoutOp>(cgf, copyin);
break;
}
} else if (val.getDefiningOp<mlir::acc::DeclareLinkOp>()) {
// Link has no exit clauses, and shouldn't be copied.
continue;
} else if (val.getDefiningOp<mlir::acc::DevicePtrOp>()) {
// DevicePtr has no exit clauses, and shouldn't be copied.
continue;
} else {
cgf.cgm.errorNYI(declareRange, "OpenACC local declare clause cleanup");
continue;
}
exitOp.getDataClauseOperandsMutable().append(val);
}
}
};
} // namespace
Expand All @@ -45,7 +79,7 @@ void CIRGenFunction::emitOpenACCDeclare(const OpenACCDeclareDecl &d) {
d.clauses());

ehStack.pushCleanup<OpenACCDeclareCleanup>(CleanupKind::NormalCleanup,
enterOp);
d.getSourceRange(), enterOp);
}

void CIRGenFunction::emitOpenACCRoutine(const OpenACCRoutineDecl &d) {
Expand Down
10 changes: 7 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,12 +800,16 @@ class OpenACCClauseCIREmitter final
var, mlir::acc::DataClause::acc_copy, clause.getModifierList(),
/*structured=*/true,
/*implicit=*/false);
} else if constexpr (isOneOfTypes<OpTy, mlir::acc::DeclareEnterOp>) {
for (const Expr *var : clause.getVarList())
addDataOperand<mlir::acc::CopyinOp>(
var, mlir::acc::DataClause::acc_copy, clause.getModifierList(),
/*structured=*/true,
/*implicit=*/false);
} else if constexpr (isCombinedType<OpTy>) {
applyToComputeOp(clause);
} else {
// TODO: When we've implemented this for everything, switch this to an
// unreachable. declare construct remains.
return clauseNotImplemented(clause);
llvm_unreachable("Unknown construct kind in VisitCopyClause");
}
}

Expand Down
Loading