[clang] [OpenACC][CIR] Implement 'self' lowering on compute constructs (PR #135851)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 15 14:16:23 PDT 2025
================
@@ -89,64 +95,70 @@ class OpenACCClauseCIREmitter final
}
void VisitDeviceTypeClause(const OpenACCDeviceTypeClause &clause) {
+ if constexpr (isOneOfTypes<OpTy, InitOp, ShutdownOp>) {
+ llvm::SmallVector<mlir::Attribute> deviceTypes;
+ std::optional<mlir::ArrayAttr> existingDeviceTypes =
+ operation.getDeviceTypes();
+
+ // Ensure we keep the existing ones, and in the correct 'new' order.
+ if (existingDeviceTypes) {
+ for (const mlir::Attribute &Attr : *existingDeviceTypes)
+ deviceTypes.push_back(mlir::acc::DeviceTypeAttr::get(
+ builder.getContext(),
+ cast<mlir::acc::DeviceTypeAttr>(Attr).getValue()));
+ }
- switch (dirKind) {
- case OpenACCDirectiveKind::Init:
- case OpenACCDirectiveKind::Set:
- case OpenACCDirectiveKind::Shutdown: {
- // Device type has a list that is either a 'star' (emitted as 'star'),
- // or an identifer list, all of which get added for attributes.
-
- for (const DeviceTypeArgument &arg : clause.getArchitectures())
- attrData.deviceTypeArchs.push_back(decodeDeviceType(arg.first));
- break;
- }
- default:
+ for (const DeviceTypeArgument &arg : clause.getArchitectures()) {
+ deviceTypes.push_back(mlir::acc::DeviceTypeAttr::get(
+ builder.getContext(), decodeDeviceType(arg.first)));
+ }
+ operation.removeDeviceTypesAttr();
+ operation.setDeviceTypesAttr(
+ mlir::ArrayAttr::get(builder.getContext(), deviceTypes));
+ } else if constexpr (isOneOfTypes<OpTy, SetOp>) {
+ assert(!operation.getDeviceTypeAttr() && "already have device-type?");
+ assert(clause.getArchitectures().size() <= 1);
+
+ if (!clause.getArchitectures().empty())
+ operation.setDeviceType(
+ decodeDeviceType(clause.getArchitectures()[0].first));
+ } else {
return clauseNotImplemented(clause);
}
}
- // Apply any of the clauses that resulted in an 'attribute'.
- template <typename Op>
- void applyAttributes(CIRGenBuilderTy &builder, Op &op) {
-
- if (attrData.defaultVal.has_value()) {
- // FIXME: OpenACC: as we implement this for other directive kinds, we have
- // to expand this list.
- // This type-trait checks if 'op'(the first arg) is one of the mlir::acc
- // operations listed in the rest of the arguments.
- if constexpr (isOneOfTypes<Op, ParallelOp, SerialOp, KernelsOp, DataOp>)
- op.setDefaultAttr(*attrData.defaultVal);
- else
- cgm.errorNYI(dirLoc, "OpenACC 'default' clause lowering for ", dirKind);
- }
-
- if (!attrData.deviceTypeArchs.empty()) {
- // FIXME: OpenACC: as we implement this for other directive kinds, we have
- // to expand this list, or more likely, have a 'noop' branch as most other
- // uses of this apply to the operands instead.
- // This type-trait checks if 'op'(the first arg) is one of the mlir::acc
- if constexpr (isOneOfTypes<Op, InitOp, ShutdownOp>) {
- llvm::SmallVector<mlir::Attribute> deviceTypes;
- for (mlir::acc::DeviceType DT : attrData.deviceTypeArchs)
- deviceTypes.push_back(
- mlir::acc::DeviceTypeAttr::get(builder.getContext(), DT));
-
- op.setDeviceTypesAttr(
- mlir::ArrayAttr::get(builder.getContext(), deviceTypes));
- } else if constexpr (isOneOfTypes<Op, SetOp>) {
- assert(attrData.deviceTypeArchs.size() <= 1 &&
- "Set can only have a single architecture");
- if (!attrData.deviceTypeArchs.empty())
- op.setDeviceType(attrData.deviceTypeArchs[0]);
+ void VisitSelfClause(const OpenACCSelfClause &clause) {
+ if constexpr (isOneOfTypes<OpTy, ParallelOp, SerialOp, KernelsOp>) {
+ if (clause.isEmptySelfClause()) {
+ operation.setSelfAttr(true);
+ } else if (clause.isConditionExprClause()) {
+ assert(clause.hasConditionExpr());
+ mlir::Value condition =
+ cgf.evaluateExprAsBool(clause.getConditionExpr());
+
+ mlir::Location exprLoc = cgf.getCIRGenModule().getLoc(
+ clause.getConditionExpr()->getBeginLoc());
+ mlir::IntegerType targetType = mlir::IntegerType::get(
+ &cgf.getMLIRContext(), /*width=*/1,
+ mlir::IntegerType::SignednessSemantics::Signless);
+ auto ConversionOp = builder.create<mlir::UnrealizedConversionCastOp>(
----------------
erichkeane wrote:
I will one day internalize the variable spelling in this half of the project, and not get this wrong again. Today is not that day :D
https://github.com/llvm/llvm-project/pull/135851
More information about the cfe-commits
mailing list