Skip to content
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
3 changes: 1 addition & 2 deletions clang/lib/CIR/CodeGen/CIRGenDeclOpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ void CIRGenFunction::emitOpenACCDeclare(const OpenACCDeclareDecl &d) {
builder, exprLoc, mlir::acc::DeclareTokenType::get(&cgm.getMLIRContext()),
{});

emitOpenACCClauses(enterOp, OpenACCDirectiveKind::Declare, d.getBeginLoc(),
d.clauses());
emitOpenACCClauses(enterOp, OpenACCDirectiveKind::Declare, d.clauses());

ehStack.pushCleanup<OpenACCDeclareCleanup>(CleanupKind::NormalCleanup,
enterOp);
Expand Down
16 changes: 7 additions & 9 deletions clang/lib/CIR/CodeGen/CIRGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1968,25 +1968,23 @@ class CIRGenFunction : public CIRGenTypeCache {
private:
template <typename Op>
Op emitOpenACCOp(mlir::Location start, OpenACCDirectiveKind dirKind,
SourceLocation dirLoc,
llvm::ArrayRef<const OpenACCClause *> clauses);
// Function to do the basic implementation of an operation with an Associated
// Statement. Models AssociatedStmtConstruct.
template <typename Op, typename TermOp>
mlir::LogicalResult emitOpenACCOpAssociatedStmt(
mlir::Location start, mlir::Location end, OpenACCDirectiveKind dirKind,
SourceLocation dirLoc, llvm::ArrayRef<const OpenACCClause *> clauses,
const Stmt *associatedStmt);
mlir::LogicalResult
emitOpenACCOpAssociatedStmt(mlir::Location start, mlir::Location end,
OpenACCDirectiveKind dirKind,
llvm::ArrayRef<const OpenACCClause *> clauses,
const Stmt *associatedStmt);

template <typename Op, typename TermOp>
mlir::LogicalResult emitOpenACCOpCombinedConstruct(
mlir::Location start, mlir::Location end, OpenACCDirectiveKind dirKind,
SourceLocation dirLoc, llvm::ArrayRef<const OpenACCClause *> clauses,
const Stmt *loopStmt);
llvm::ArrayRef<const OpenACCClause *> clauses, const Stmt *loopStmt);

template <typename Op>
void emitOpenACCClauses(Op &op, OpenACCDirectiveKind dirKind,
SourceLocation dirLoc,
ArrayRef<const OpenACCClause *> clauses);
// The second template argument doesn't need to be a template, since it should
// always be an mlir::acc::LoopOp, but as this is a template anyway, we make
Expand All @@ -1996,7 +1994,7 @@ class CIRGenFunction : public CIRGenTypeCache {
// instantiated 3x.
template <typename ComputeOp, typename LoopOp>
void emitOpenACCClauses(ComputeOp &op, LoopOp &loopOp,
OpenACCDirectiveKind dirKind, SourceLocation dirLoc,
OpenACCDirectiveKind dirKind,
ArrayRef<const OpenACCClause *> clauses);

// The OpenACC LoopOp requires that we have auto, seq, or independent on all
Expand Down
69 changes: 21 additions & 48 deletions clang/lib/CIR/CodeGen/CIRGenOpenACCClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ class OpenACCClauseCIREmitter final
// This is necessary since a few of the clauses emit differently based on the
// directive kind they are attached to.
OpenACCDirectiveKind dirKind;
// TODO(cir): This source location should be able to go away once the NYI
// diagnostics are gone.
SourceLocation dirLoc;

llvm::SmallVector<mlir::acc::DeviceType> lastDeviceTypeValues;
// Keep track of the async-clause so that we can shortcut updating the data
Expand All @@ -72,10 +69,6 @@ class OpenACCClauseCIREmitter final
// Keep track of the data operands so that we can update their async clauses.
llvm::SmallVector<mlir::Operation *> dataOperands;

void clauseNotImplemented(const OpenACCClause &c) {
cgf.cgm.errorNYI(c.getSourceRange(), "OpenACC Clause", c.getClauseKind());
}

void setLastDeviceTypeClause(const OpenACCDeviceTypeClause &clause) {
lastDeviceTypeValues.clear();

Expand Down Expand Up @@ -150,7 +143,7 @@ class OpenACCClauseCIREmitter final
mlir::OpBuilder::InsertionGuard guardCase(builder);
builder.setInsertionPoint(operation.loopOp);
OpenACCClauseCIREmitter<mlir::acc::LoopOp> loopEmitter{
operation.loopOp, recipeInsertLocation, cgf, builder, dirKind, dirLoc};
operation.loopOp, recipeInsertLocation, cgf, builder, dirKind};
loopEmitter.lastDeviceTypeValues = lastDeviceTypeValues;
loopEmitter.Visit(&c);
}
Expand All @@ -161,12 +154,7 @@ class OpenACCClauseCIREmitter final
mlir::OpBuilder::InsertionGuard guardCase(builder);
builder.setInsertionPoint(operation.computeOp);
OpenACCClauseCIREmitter<typename OpTy::ComputeOpTy> computeEmitter{
operation.computeOp,
recipeInsertLocation,
cgf,
builder,
dirKind,
dirLoc};
operation.computeOp, recipeInsertLocation, cgf, builder, dirKind};

computeEmitter.lastDeviceTypeValues = lastDeviceTypeValues;

Expand Down Expand Up @@ -342,12 +330,12 @@ class OpenACCClauseCIREmitter final
mlir::OpBuilder::InsertPoint &recipeInsertLocation,
CIRGen::CIRGenFunction &cgf,
CIRGen::CIRGenBuilderTy &builder,
OpenACCDirectiveKind dirKind, SourceLocation dirLoc)
OpenACCDirectiveKind dirKind)
: operation(operation), recipeInsertLocation(recipeInsertLocation),
cgf(cgf), builder(builder), dirKind(dirKind), dirLoc(dirLoc) {}
cgf(cgf), builder(builder), dirKind(dirKind) {}

void VisitClause(const OpenACCClause &clause) {
clauseNotImplemented(clause);
llvm_unreachable("Unknown/unhandled clause kind");
}

// The entry point for the CIR emitter. All users should use this rather than
Expand Down Expand Up @@ -406,9 +394,7 @@ class OpenACCClauseCIREmitter final
// Nothing to do here either, combined constructs are just going to use
// 'lastDeviceTypeValues' to set the value for the child visitor.
} else {
// TODO: When we've implemented this for everything, switch this to an
// unreachable. routine construct remains.
return clauseNotImplemented(clause);
llvm_unreachable("Unknown construct kind in VisitDeviceTypeClause");
}
}

Expand Down Expand Up @@ -472,9 +458,7 @@ class OpenACCClauseCIREmitter final
} else if constexpr (isCombinedType<OpTy>) {
applyToComputeOp(clause);
} else {
// TODO: When we've implemented this for everything, switch this to an
// unreachable. Combined constructs remain. update construct remains.
return clauseNotImplemented(clause);
llvm_unreachable("Unknown construct kind in VisitAsyncClause");
}
}

Expand Down Expand Up @@ -601,7 +585,7 @@ class OpenACCClauseCIREmitter final
} else {
// TODO: When we've implemented this for everything, switch this to an
// unreachable. update construct remains.
return clauseNotImplemented(clause);
llvm_unreachable("Unknown construct kind in VisitWaitClause");
}
}

Expand All @@ -620,9 +604,7 @@ class OpenACCClauseCIREmitter final
} else if constexpr (isCombinedType<OpTy>) {
applyToLoopOp(clause);
} else {
// TODO: When we've implemented this for everything, switch this to an
// unreachable. Routine construct remains.
return clauseNotImplemented(clause);
llvm_unreachable("Unknown construct kind in VisitSeqClause");
}
}

Expand All @@ -632,9 +614,7 @@ class OpenACCClauseCIREmitter final
} else if constexpr (isCombinedType<OpTy>) {
applyToLoopOp(clause);
} else {
// TODO: When we've implemented this for everything, switch this to an
// unreachable. Routine, construct remains.
return clauseNotImplemented(clause);
llvm_unreachable("Unknown construct kind in VisitAutoClause");
}
}

Expand All @@ -644,9 +624,7 @@ class OpenACCClauseCIREmitter final
} else if constexpr (isCombinedType<OpTy>) {
applyToLoopOp(clause);
} else {
// TODO: When we've implemented this for everything, switch this to an
// unreachable. Routine construct remains.
return clauseNotImplemented(clause);
llvm_unreachable("Unknown construct kind in VisitIndependentClause");
}
}

Expand Down Expand Up @@ -706,9 +684,7 @@ class OpenACCClauseCIREmitter final
} else if constexpr (isCombinedType<OpTy>) {
applyToLoopOp(clause);
} else {
// TODO: When we've implemented this for everything, switch this to an
// unreachable. Combined constructs remain.
return clauseNotImplemented(clause);
llvm_unreachable("Unknown construct kind in VisitWorkerClause");
}
}

Expand All @@ -724,9 +700,7 @@ class OpenACCClauseCIREmitter final
} else if constexpr (isCombinedType<OpTy>) {
applyToLoopOp(clause);
} else {
// TODO: When we've implemented this for everything, switch this to an
// unreachable. Combined constructs remain.
return clauseNotImplemented(clause);
llvm_unreachable("Unknown construct kind in VisitVectorClause");
}
}

Expand Down Expand Up @@ -1128,29 +1102,28 @@ auto makeClauseEmitter(OpTy &op,
mlir::OpBuilder::InsertPoint &recipeInsertLocation,
CIRGen::CIRGenFunction &cgf,
CIRGen::CIRGenBuilderTy &builder,
OpenACCDirectiveKind dirKind, SourceLocation dirLoc) {
OpenACCDirectiveKind dirKind) {
return OpenACCClauseCIREmitter<OpTy>(op, recipeInsertLocation, cgf, builder,
dirKind, dirLoc);
dirKind);
}
} // namespace

template <typename Op>
void CIRGenFunction::emitOpenACCClauses(
Op &op, OpenACCDirectiveKind dirKind, SourceLocation dirLoc,
Op &op, OpenACCDirectiveKind dirKind,
ArrayRef<const OpenACCClause *> clauses) {
mlir::OpBuilder::InsertionGuard guardCase(builder);

// Sets insertion point before the 'op', since every new expression needs to
// be before the operation.
builder.setInsertionPoint(op);
makeClauseEmitter(op, lastRecipeLocation, *this, builder, dirKind, dirLoc)
makeClauseEmitter(op, lastRecipeLocation, *this, builder, dirKind)
.emitClauses(clauses);
}

#define EXPL_SPEC(N) \
template void CIRGenFunction::emitOpenACCClauses<N>( \
N &, OpenACCDirectiveKind, SourceLocation, \
ArrayRef<const OpenACCClause *>);
N &, OpenACCDirectiveKind, ArrayRef<const OpenACCClause *>);
EXPL_SPEC(mlir::acc::ParallelOp)
EXPL_SPEC(mlir::acc::SerialOp)
EXPL_SPEC(mlir::acc::KernelsOp)
Expand All @@ -1174,20 +1147,20 @@ EXPL_SPEC(mlir::acc::DeclareEnterOp)
template <typename ComputeOp, typename LoopOp>
void CIRGenFunction::emitOpenACCClauses(
ComputeOp &op, LoopOp &loopOp, OpenACCDirectiveKind dirKind,
SourceLocation dirLoc, ArrayRef<const OpenACCClause *> clauses) {
ArrayRef<const OpenACCClause *> clauses) {
static_assert(std::is_same_v<mlir::acc::LoopOp, LoopOp>);

CombinedConstructClauseInfo<ComputeOp> inf{op, loopOp};
// We cannot set the insertion point here and do so in the emitter, but make
// sure we reset it with the 'guard' anyway.
mlir::OpBuilder::InsertionGuard guardCase(builder);
makeClauseEmitter(inf, lastRecipeLocation, *this, builder, dirKind, dirLoc)
makeClauseEmitter(inf, lastRecipeLocation, *this, builder, dirKind)
.emitClauses(clauses);
}

#define EXPL_SPEC(N) \
template void CIRGenFunction::emitOpenACCClauses<N, mlir::acc::LoopOp>( \
N &, mlir::acc::LoopOp &, OpenACCDirectiveKind, SourceLocation, \
N &, mlir::acc::LoopOp &, OpenACCDirectiveKind, \
ArrayRef<const OpenACCClause *>);

EXPL_SPEC(mlir::acc::ParallelOp)
Expand Down
Loading
Loading