================ @@ -57,31 +75,90 @@ class OpenACCClauseCIREmitter final } } + mlir::acc::DeviceType decodeDeviceType(const IdentifierInfo *II) { + + // '*' case leaves no identifier-info, just a nullptr. + if (!II) + return mlir::acc::DeviceType::Star; + return llvm::StringSwitch<mlir::acc::DeviceType>(II->getName()) + .CaseLower("default", mlir::acc::DeviceType::Default) + .CaseLower("host", mlir::acc::DeviceType::Host) + .CaseLower("multicore", mlir::acc::DeviceType::Multicore) + .CasesLower("nvidia", "acc_device_nvidia", + mlir::acc::DeviceType::Nvidia) + .CaseLower("radeon", mlir::acc::DeviceType::Radeon); + } + + void VisitDeviceTypeClause(const OpenACCDeviceTypeClause &clause) { + + switch (dirKind) { + case OpenACCDirectiveKind::Init: + 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: + return clauseNotImplemented(clause); + } + } + // Apply any of the clauses that resulted in an 'attribute'. - template <typename Op> void applyAttributes(Op &op) { - if (attrData.defaultVal.has_value()) - op.setDefaultAttr(*attrData.defaultVal); + 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. + 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. + 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 { + cgm.errorNYI(dirLoc, "OpenACC 'device_type' clause lowering for ", ---------------- andykaylor wrote:
Is this really "NYI"? It feels more like we shouldn't get here. In either case, since the condition is static, can this be a static compile error? https://github.com/llvm/llvm-project/pull/135102 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits