@@ -107,6 +107,18 @@ class OpenACCClauseCIREmitter final
107107 .CaseLower (" radeon" , mlir::acc::DeviceType::Radeon);
108108 }
109109
110+ mlir::acc::GangArgType decodeGangType (OpenACCGangKind gk) {
111+ switch (gk) {
112+ case OpenACCGangKind::Num:
113+ return mlir::acc::GangArgType::Num;
114+ case OpenACCGangKind::Dim:
115+ return mlir::acc::GangArgType::Dim;
116+ case OpenACCGangKind::Static:
117+ return mlir::acc::GangArgType::Static;
118+ }
119+ llvm_unreachable (" unknown gang kind" );
120+ }
121+
110122public:
111123 OpenACCClauseCIREmitter (OpTy &operation, CIRGen::CIRGenFunction &cgf,
112124 CIRGen::CIRGenBuilderTy &builder,
@@ -424,6 +436,42 @@ class OpenACCClauseCIREmitter final
424436 return clauseNotImplemented (clause);
425437 }
426438 }
439+
440+ void VisitGangClause (const OpenACCGangClause &clause) {
441+ if constexpr (isOneOfTypes<OpTy, mlir::acc::LoopOp>) {
442+ if (clause.getNumExprs () == 0 ) {
443+ operation.addEmptyGang (builder.getContext (), lastDeviceTypeValues);
444+ } else {
445+ llvm::SmallVector<mlir::Value> values;
446+ llvm::SmallVector<mlir::acc::GangArgType> argTypes;
447+ for (unsigned i : llvm::index_range (0u , clause.getNumExprs ())) {
448+ auto [kind, expr] = clause.getExpr (i);
449+ mlir::Location exprLoc = cgf.cgm .getLoc (expr->getBeginLoc ());
450+ argTypes.push_back (decodeGangType (kind));
451+ if (kind == OpenACCGangKind::Dim) {
452+ llvm::APInt curValue =
453+ expr->EvaluateKnownConstInt (cgf.cgm .getASTContext ());
454+ // The value is 1, 2, or 3, but the type isn't necessarily smaller
455+ // than 64.
456+ curValue = curValue.sextOrTrunc (64 );
457+ values.push_back (
458+ createConstantInt (exprLoc, 64 , curValue.getSExtValue ()));
459+ } else if (isa<OpenACCAsteriskSizeExpr>(expr)) {
460+ values.push_back (createConstantInt (exprLoc, 64 , -1 ));
461+ } else {
462+ values.push_back (createIntExpr (expr));
463+ }
464+ }
465+
466+ operation.addGangOperands (builder.getContext (), lastDeviceTypeValues,
467+ argTypes, values);
468+ }
469+ } else {
470+ // TODO: When we've implemented this for everything, switch this to an
471+ // unreachable. Combined constructs remain.
472+ return clauseNotImplemented (clause);
473+ }
474+ }
427475};
428476
429477template <typename OpTy>
0 commit comments