[clang] [OpenACC][CIR] Implement 'device_type' clause lowering for 'init'/'sh… (PR #135102)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 10 10:29:17 PDT 2025
================
@@ -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>)
----------------
erichkeane wrote:
yep, `ParallelOp` is `mlir::acc::ParallelOp`. We have a `using namespace mlir::acc` above. I'll add the comment.
https://github.com/llvm/llvm-project/pull/135102
More information about the cfe-commits
mailing list