| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This contains code to emit Decl nodes as CIR code. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "CIRGenFunction.h" |
| 14 | #include "CIRGenOpenACCHelpers.h" |
| 15 | |
| 16 | #include "mlir/Dialect/OpenACC/OpenACC.h" |
| 17 | #include "clang/AST/DeclOpenACC.h" |
| 18 | #include "llvm/Support/SaveAndRestore.h" |
| 19 | |
| 20 | using namespace clang; |
| 21 | using namespace clang::CIRGen; |
| 22 | |
| 23 | namespace { |
| 24 | struct OpenACCDeclareCleanup final : EHScopeStack::Cleanup { |
| 25 | mlir::acc::DeclareEnterOp enterOp; |
| 26 | |
| 27 | OpenACCDeclareCleanup(mlir::acc::DeclareEnterOp enterOp) : enterOp(enterOp) {} |
| 28 | |
| 29 | template <typename OutTy, typename InTy> |
| 30 | void createOutOp(CIRGenFunction &cgf, InTy inOp) { |
| 31 | if constexpr (std::is_same_v<OutTy, mlir::acc::DeleteOp>) { |
| 32 | auto outOp = |
| 33 | OutTy::create(cgf.getBuilder(), inOp.getLoc(), inOp, |
| 34 | inOp.getStructured(), inOp.getImplicit(), |
| 35 | llvm::Twine(inOp.getNameAttr()), inOp.getBounds()); |
| 36 | outOp.setDataClause(inOp.getDataClause()); |
| 37 | outOp.setModifiers(inOp.getModifiers()); |
| 38 | } else { |
| 39 | auto outOp = |
| 40 | OutTy::create(cgf.getBuilder(), inOp.getLoc(), inOp, inOp.getVarPtr(), |
| 41 | inOp.getStructured(), inOp.getImplicit(), |
| 42 | llvm::Twine(inOp.getNameAttr()), inOp.getBounds()); |
| 43 | outOp.setDataClause(inOp.getDataClause()); |
| 44 | outOp.setModifiers(inOp.getModifiers()); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | void emit(CIRGenFunction &cgf, Flags flags) override { |
| 49 | auto exitOp = mlir::acc::DeclareExitOp::create( |
| 50 | builder&: cgf.getBuilder(), location: enterOp.getLoc(), token: enterOp, dataClauseOperands: {}); |
| 51 | |
| 52 | // Some data clauses need to be referenced in 'exit', AND need to have an |
| 53 | // operation after the exit. Copy these from the enter operation. |
| 54 | for (mlir::Value val : enterOp.getDataClauseOperands()) { |
| 55 | if (auto copyin = val.getDefiningOp<mlir::acc::CopyinOp>()) { |
| 56 | switch (copyin.getDataClause()) { |
| 57 | default: |
| 58 | llvm_unreachable( |
| 59 | "OpenACC local declare clause copyin unexpected data clause" ); |
| 60 | break; |
| 61 | case mlir::acc::DataClause::acc_copy: |
| 62 | createOutOp<mlir::acc::CopyoutOp>(cgf, inOp: copyin); |
| 63 | break; |
| 64 | case mlir::acc::DataClause::acc_copyin: |
| 65 | createOutOp<mlir::acc::DeleteOp>(cgf, inOp: copyin); |
| 66 | break; |
| 67 | } |
| 68 | } else if (auto create = val.getDefiningOp<mlir::acc::CreateOp>()) { |
| 69 | switch (create.getDataClause()) { |
| 70 | default: |
| 71 | llvm_unreachable( |
| 72 | "OpenACC local declare clause create unexpected data clause" ); |
| 73 | break; |
| 74 | case mlir::acc::DataClause::acc_copyout: |
| 75 | createOutOp<mlir::acc::CopyoutOp>(cgf, inOp: create); |
| 76 | break; |
| 77 | case mlir::acc::DataClause::acc_create: |
| 78 | createOutOp<mlir::acc::DeleteOp>(cgf, inOp: create); |
| 79 | break; |
| 80 | } |
| 81 | } else if (auto present = val.getDefiningOp<mlir::acc::PresentOp>()) { |
| 82 | createOutOp<mlir::acc::DeleteOp>(cgf, inOp: present); |
| 83 | } else if (auto dev_res = |
| 84 | val.getDefiningOp<mlir::acc::DeclareDeviceResidentOp>()) { |
| 85 | createOutOp<mlir::acc::DeleteOp>(cgf, inOp: dev_res); |
| 86 | } else if (val.getDefiningOp<mlir::acc::DeclareLinkOp>()) { |
| 87 | // Link has no exit clauses, and shouldn't be copied. |
| 88 | continue; |
| 89 | } else if (val.getDefiningOp<mlir::acc::DevicePtrOp>()) { |
| 90 | // DevicePtr has no exit clauses, and shouldn't be copied. |
| 91 | continue; |
| 92 | } else { |
| 93 | llvm_unreachable("OpenACC local declare clause unexpected defining op" ); |
| 94 | continue; |
| 95 | } |
| 96 | exitOp.getDataClauseOperandsMutable().append(values: val); |
| 97 | } |
| 98 | } |
| 99 | }; |
| 100 | } // namespace |
| 101 | |
| 102 | void CIRGenModule::emitGlobalOpenACCDecl(const OpenACCConstructDecl *d) { |
| 103 | if (const auto *rd = dyn_cast<OpenACCRoutineDecl>(Val: d)) |
| 104 | emitGlobalOpenACCRoutineDecl(cd: rd); |
| 105 | else |
| 106 | emitGlobalOpenACCDeclareDecl(cd: cast<OpenACCDeclareDecl>(Val: d)); |
| 107 | } |
| 108 | |
| 109 | void CIRGenFunction::emitOpenACCDeclare(const OpenACCDeclareDecl &d) { |
| 110 | mlir::Location exprLoc = cgm.getLoc(cLoc: d.getBeginLoc()); |
| 111 | auto enterOp = mlir::acc::DeclareEnterOp::create( |
| 112 | builder, location: exprLoc, token: mlir::acc::DeclareTokenType::get(ctx: &cgm.getMLIRContext()), |
| 113 | dataClauseOperands: {}); |
| 114 | |
| 115 | emitOpenACCClauses(op&: enterOp, dirKind: OpenACCDirectiveKind::Declare, clauses: d.clauses()); |
| 116 | |
| 117 | ehStack.pushCleanup<OpenACCDeclareCleanup>(kind: CleanupKind::NormalCleanup, |
| 118 | a: enterOp); |
| 119 | } |
| 120 | |
| 121 | // Helper function that gets the declaration referenced by the declare clause. |
| 122 | // This is a simplified verison of the work that `getOpenACCDataOperandInfo` |
| 123 | // does, as it only has to get forms that 'declare' does. |
| 124 | static const Decl *getDeclareReferencedDecl(const Expr *e) { |
| 125 | const Expr *curVarExpr = e->IgnoreParenImpCasts(); |
| 126 | |
| 127 | // Since we allow array sections, we have to unpack the array sections here. |
| 128 | // We don't have to worry about other bounds, since only variable or array |
| 129 | // name (plus array sections as an extension) are permitted. |
| 130 | while (const auto *ase = dyn_cast<ArraySectionExpr>(Val: curVarExpr)) |
| 131 | curVarExpr = ase->getBase()->IgnoreParenImpCasts(); |
| 132 | |
| 133 | if (const auto *dre = dyn_cast<DeclRefExpr>(Val: curVarExpr)) |
| 134 | return dre->getFoundDecl()->getCanonicalDecl(); |
| 135 | |
| 136 | // MemberExpr is allowed when it is implicit 'this'. |
| 137 | return cast<MemberExpr>(Val: curVarExpr)->getMemberDecl()->getCanonicalDecl(); |
| 138 | } |
| 139 | |
| 140 | template <typename BeforeOpTy, typename DataClauseTy> |
| 141 | void CIRGenModule::emitGlobalOpenACCDeclareDataOperands( |
| 142 | const Expr *varOperand, DataClauseTy dataClause, |
| 143 | OpenACCModifierKind modifiers, bool structured, bool implicit, |
| 144 | bool requiresDtor) { |
| 145 | // This is a template argument so that we don't have to include all of |
| 146 | // mlir::acc into CIRGenModule. |
| 147 | static_assert(std::is_same_v<DataClauseTy, mlir::acc::DataClause>); |
| 148 | mlir::Location exprLoc = getLoc(cLoc: varOperand->getBeginLoc()); |
| 149 | const Decl *refedDecl = getDeclareReferencedDecl(e: varOperand); |
| 150 | StringRef varName = getMangledName(gd: GlobalDecl{cast<VarDecl>(Val: refedDecl)}); |
| 151 | |
| 152 | // We have to emit two separate functions in this case, an acc_ctor and an |
| 153 | // acc_dtor. These two sections are/should remain reasonably equal, however |
| 154 | // the order of the clauses/vs-enter&exit in them makes combining these two |
| 155 | // sections not particularly attractive, so we have a bit of repetition. |
| 156 | { |
| 157 | mlir::OpBuilder::InsertionGuard guardCase(builder); |
| 158 | auto ctorOp = mlir::acc::GlobalConstructorOp::create( |
| 159 | builder, location: exprLoc, sym_name: (varName + "_acc_ctor" ).str(), |
| 160 | /*sym_visibility=*/nullptr); |
| 161 | getModule().push_back(op: ctorOp); |
| 162 | mlir::Block *block = builder.createBlock(parent: &ctorOp.getRegion(), |
| 163 | insertPt: ctorOp.getRegion().end(), argTypes: {}, locs: {}); |
| 164 | builder.setInsertionPointToEnd(block); |
| 165 | // These things are close enough to a function handling-wise we can just |
| 166 | // create this here. |
| 167 | CIRGenFunction cgf{*this, builder, true}; |
| 168 | llvm::SaveAndRestore<CIRGenFunction *> savedCGF(curCGF, &cgf); |
| 169 | cgf.curFn = ctorOp; |
| 170 | CIRGenFunction::SourceLocRAIIObject fnLoc{cgf, |
| 171 | varOperand->getSourceRange()}; |
| 172 | |
| 173 | // This gets the information we need, PLUS emits the bounds correctly, so we |
| 174 | // have to do this in both enter and exit. |
| 175 | CIRGenFunction::OpenACCDataOperandInfo inf = |
| 176 | cgf.getOpenACCDataOperandInfo(e: varOperand); |
| 177 | auto beforeOp = |
| 178 | BeforeOpTy::create(builder, exprLoc, inf.varValue, structured, implicit, |
| 179 | inf.name, inf.bounds); |
| 180 | beforeOp.setDataClause(dataClause); |
| 181 | beforeOp.setModifiers(convertOpenACCModifiers(modifiers)); |
| 182 | |
| 183 | mlir::acc::DeclareEnterOp::create( |
| 184 | builder, exprLoc, mlir::acc::DeclareTokenType::get(ctx: &getMLIRContext()), |
| 185 | beforeOp.getResult()); |
| 186 | |
| 187 | mlir::acc::TerminatorOp::create(builder, location: exprLoc); |
| 188 | } |
| 189 | |
| 190 | // copyin, create, and device_resident require a destructor, link does not. In |
| 191 | // the case of the first three, they are all a 'getdeviceptr', followed by the |
| 192 | // declare_exit, followed by a delete op in the destructor region. |
| 193 | if (requiresDtor) { |
| 194 | mlir::OpBuilder::InsertionGuard guardCase(builder); |
| 195 | auto ctorOp = mlir::acc::GlobalDestructorOp::create( |
| 196 | builder, location: exprLoc, sym_name: (varName + "_acc_dtor" ).str(), |
| 197 | /*sym_visibility=*/nullptr); |
| 198 | getModule().push_back(op: ctorOp); |
| 199 | mlir::Block *block = builder.createBlock(parent: &ctorOp.getRegion(), |
| 200 | insertPt: ctorOp.getRegion().end(), argTypes: {}, locs: {}); |
| 201 | builder.setInsertionPointToEnd(block); |
| 202 | |
| 203 | // These things are close enough to a function handling-wise we can just |
| 204 | // create this here. |
| 205 | CIRGenFunction cgf{*this, builder, true}; |
| 206 | llvm::SaveAndRestore<CIRGenFunction *> savedCGF(curCGF, &cgf); |
| 207 | cgf.curFn = ctorOp; |
| 208 | CIRGenFunction::SourceLocRAIIObject fnLoc{cgf, |
| 209 | varOperand->getSourceRange()}; |
| 210 | |
| 211 | CIRGenFunction::OpenACCDataOperandInfo inf = |
| 212 | cgf.getOpenACCDataOperandInfo(e: varOperand); |
| 213 | auto getDevPtr = mlir::acc::GetDevicePtrOp::create( |
| 214 | builder, location: exprLoc, var: inf.varValue, structured, implicit, name: inf.name, |
| 215 | bounds: inf.bounds); |
| 216 | getDevPtr.setDataClause(dataClause); |
| 217 | getDevPtr.setModifiers(convertOpenACCModifiers(modifiers)); |
| 218 | |
| 219 | mlir::acc::DeclareExitOp::create(builder, location: exprLoc, /*token=*/mlir::Value{}, |
| 220 | dataClauseOperands: getDevPtr.getResult()); |
| 221 | auto deleteOp = mlir::acc::DeleteOp::create( |
| 222 | builder, location: exprLoc, accVar: getDevPtr, structured, implicit, name: inf.name, bounds: {}); |
| 223 | deleteOp.setDataClause(dataClause); |
| 224 | deleteOp.setModifiers(convertOpenACCModifiers(modifiers)); |
| 225 | mlir::acc::TerminatorOp::create(builder, location: exprLoc); |
| 226 | } |
| 227 | } |
| 228 | namespace { |
| 229 | // This class emits all of the information for a 'declare' at a global/ns/class |
| 230 | // scope. Each clause results in its own acc_ctor and acc_dtor for the variable. |
| 231 | // This class creates those and emits them properly. |
| 232 | // This behavior is unique/special enough from the emission of statement-level |
| 233 | // clauses that it doesn't really make sense to use that clause visitor. |
| 234 | class OpenACCGlobalDeclareClauseEmitter final |
| 235 | : public OpenACCClauseVisitor<OpenACCGlobalDeclareClauseEmitter> { |
| 236 | CIRGenModule &cgm; |
| 237 | |
| 238 | public: |
| 239 | OpenACCGlobalDeclareClauseEmitter(CIRGenModule &cgm) : cgm(cgm) {} |
| 240 | |
| 241 | void VisitClause(const OpenACCClause &clause) { |
| 242 | llvm_unreachable("Invalid OpenACC clause on global Declare" ); |
| 243 | } |
| 244 | |
| 245 | void emitClauses(ArrayRef<const OpenACCClause *> clauses) { |
| 246 | this->VisitClauseList(List: clauses); |
| 247 | } |
| 248 | |
| 249 | void VisitCopyInClause(const OpenACCCopyInClause &clause) { |
| 250 | for (const Expr *var : clause.getVarList()) |
| 251 | cgm.emitGlobalOpenACCDeclareDataOperands<mlir::acc::CopyinOp>( |
| 252 | varOperand: var, dataClause: mlir::acc::DataClause::acc_copyin, modifiers: clause.getModifierList(), |
| 253 | /*structured=*/true, |
| 254 | /*implicit=*/false, /*requiresDtor=*/true); |
| 255 | } |
| 256 | |
| 257 | void VisitCreateClause(const OpenACCCreateClause &clause) { |
| 258 | for (const Expr *var : clause.getVarList()) |
| 259 | cgm.emitGlobalOpenACCDeclareDataOperands<mlir::acc::CreateOp>( |
| 260 | varOperand: var, dataClause: mlir::acc::DataClause::acc_create, modifiers: clause.getModifierList(), |
| 261 | /*structured=*/true, |
| 262 | /*implicit=*/false, /*requiresDtor=*/true); |
| 263 | } |
| 264 | |
| 265 | void VisitDeviceResidentClause(const OpenACCDeviceResidentClause &clause) { |
| 266 | for (const Expr *var : clause.getVarList()) |
| 267 | cgm.emitGlobalOpenACCDeclareDataOperands< |
| 268 | mlir::acc::DeclareDeviceResidentOp>( |
| 269 | varOperand: var, dataClause: mlir::acc::DataClause::acc_declare_device_resident, modifiers: {}, |
| 270 | /*structured=*/true, |
| 271 | /*implicit=*/false, /*requiresDtor=*/true); |
| 272 | } |
| 273 | |
| 274 | void VisitLinkClause(const OpenACCLinkClause &clause) { |
| 275 | for (const Expr *var : clause.getVarList()) |
| 276 | cgm.emitGlobalOpenACCDeclareDataOperands<mlir::acc::DeclareLinkOp>( |
| 277 | varOperand: var, dataClause: mlir::acc::DataClause::acc_declare_link, modifiers: {}, |
| 278 | /*structured=*/true, |
| 279 | /*implicit=*/false, /*requiresDtor=*/false); |
| 280 | } |
| 281 | }; |
| 282 | } // namespace |
| 283 | |
| 284 | void CIRGenModule::emitGlobalOpenACCDeclareDecl(const OpenACCDeclareDecl *d) { |
| 285 | // Declare creates 1 'acc_ctor' and 0-1 'acc_dtor' per clause, since it needs |
| 286 | // a unique one on a per-variable basis. We can just use a clause emitter to |
| 287 | // do all the work. |
| 288 | mlir::OpBuilder::InsertionGuard guardCase(builder); |
| 289 | OpenACCGlobalDeclareClauseEmitter em{*this}; |
| 290 | em.emitClauses(clauses: d->clauses()); |
| 291 | } |
| 292 | |
| 293 | void CIRGenFunction::emitOpenACCRoutine(const OpenACCRoutineDecl &d) { |
| 294 | // Do nothing here. The OpenACCRoutineDeclAttr handles the implicit name |
| 295 | // cases, and the end-of-TU handling manages the named cases. This is |
| 296 | // necessary because these references aren't necessarily emitted themselves, |
| 297 | // but can be named anywhere. |
| 298 | } |
| 299 | |
| 300 | void CIRGenModule::emitGlobalOpenACCRoutineDecl(const OpenACCRoutineDecl *d) { |
| 301 | // Do nothing here. The OpenACCRoutineDeclAttr handles the implicit name |
| 302 | // cases, and the end-of-TU handling manages the named cases. This is |
| 303 | // necessary because these references aren't necessarily emitted themselves, |
| 304 | // but can be named anywhere. |
| 305 | } |
| 306 | |
| 307 | namespace { |
| 308 | class OpenACCRoutineClauseEmitter final |
| 309 | : public OpenACCClauseVisitor<OpenACCRoutineClauseEmitter> { |
| 310 | CIRGenModule &cgm; |
| 311 | CIRGen::CIRGenBuilderTy &builder; |
| 312 | mlir::acc::RoutineOp routineOp; |
| 313 | const clang::FunctionDecl *funcDecl; |
| 314 | llvm::SmallVector<mlir::acc::DeviceType> lastDeviceTypeValues; |
| 315 | |
| 316 | public: |
| 317 | OpenACCRoutineClauseEmitter(CIRGenModule &cgm, |
| 318 | CIRGen::CIRGenBuilderTy &builder, |
| 319 | mlir::acc::RoutineOp routineOp, |
| 320 | const clang::FunctionDecl *funcDecl) |
| 321 | : cgm(cgm), builder(builder), routineOp(routineOp), funcDecl(funcDecl) {} |
| 322 | |
| 323 | void emitClauses(ArrayRef<const OpenACCClause *> clauses) { |
| 324 | this->VisitClauseList(List: clauses); |
| 325 | } |
| 326 | |
| 327 | void VisitClause(const OpenACCClause &clause) { |
| 328 | llvm_unreachable("Invalid OpenACC clause on routine" ); |
| 329 | } |
| 330 | |
| 331 | void VisitSeqClause(const OpenACCSeqClause &clause) { |
| 332 | routineOp.addSeq(builder.getContext(), lastDeviceTypeValues); |
| 333 | } |
| 334 | void VisitWorkerClause(const OpenACCWorkerClause &clause) { |
| 335 | routineOp.addWorker(builder.getContext(), lastDeviceTypeValues); |
| 336 | } |
| 337 | void VisitVectorClause(const OpenACCVectorClause &clause) { |
| 338 | routineOp.addVector(builder.getContext(), lastDeviceTypeValues); |
| 339 | } |
| 340 | |
| 341 | void VisitNoHostClause(const OpenACCNoHostClause &clause) { |
| 342 | routineOp.setNohost(/*attrValue=*/true); |
| 343 | } |
| 344 | |
| 345 | void VisitGangClause(const OpenACCGangClause &clause) { |
| 346 | // Gang has an optional 'dim' value, which is a constant int of 1, 2, or 3. |
| 347 | // If we don't store any expressions in the clause, there are none, else we |
| 348 | // expect there is 1, since Sema should enforce that the single 'dim' is the |
| 349 | // only valid value. |
| 350 | if (clause.getNumExprs() == 0) { |
| 351 | routineOp.addGang(builder.getContext(), lastDeviceTypeValues); |
| 352 | } else { |
| 353 | assert(clause.getNumExprs() == 1); |
| 354 | auto [kind, expr] = clause.getExpr(I: 0); |
| 355 | assert(kind == OpenACCGangKind::Dim); |
| 356 | |
| 357 | llvm::APSInt curValue = expr->EvaluateKnownConstInt(Ctx: cgm.getASTContext()); |
| 358 | // The value is 1, 2, or 3, but 64 bit seems right enough. |
| 359 | curValue = curValue.sextOrTrunc(width: 64); |
| 360 | routineOp.addGang(builder.getContext(), lastDeviceTypeValues, |
| 361 | curValue.getZExtValue()); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | void VisitDeviceTypeClause(const OpenACCDeviceTypeClause &clause) { |
| 366 | lastDeviceTypeValues.clear(); |
| 367 | |
| 368 | for (const DeviceTypeArgument &arg : clause.getArchitectures()) |
| 369 | lastDeviceTypeValues.push_back(Elt: decodeDeviceType(ii: arg.getIdentifierInfo())); |
| 370 | } |
| 371 | |
| 372 | void VisitBindClause(const OpenACCBindClause &clause) { |
| 373 | if (clause.isStringArgument()) { |
| 374 | mlir::StringAttr value = |
| 375 | builder.getStringAttr(bytes: clause.getStringArgument()->getString()); |
| 376 | |
| 377 | routineOp.addBindStrName(builder.getContext(), lastDeviceTypeValues, |
| 378 | value); |
| 379 | } else { |
| 380 | assert(clause.isIdentifierArgument()); |
| 381 | std::string bindName = cgm.getOpenACCBindMangledName( |
| 382 | bindName: clause.getIdentifierArgument(), attachedFunction: funcDecl); |
| 383 | |
| 384 | routineOp.addBindIDName( |
| 385 | builder.getContext(), lastDeviceTypeValues, |
| 386 | mlir::SymbolRefAttr::get(ctx: builder.getContext(), value: bindName)); |
| 387 | } |
| 388 | } |
| 389 | }; |
| 390 | } // namespace |
| 391 | |
| 392 | void CIRGenModule::emitOpenACCRoutineDecl( |
| 393 | const clang::FunctionDecl *funcDecl, cir::FuncOp func, |
| 394 | SourceLocation pragmaLoc, ArrayRef<const OpenACCClause *> clauses) { |
| 395 | mlir::OpBuilder::InsertionGuard guardCase(builder); |
| 396 | // These need to appear at the global module. |
| 397 | builder.setInsertionPointToEnd(&getModule().getBodyRegion().front()); |
| 398 | |
| 399 | mlir::Location routineLoc = getLoc(cLoc: pragmaLoc); |
| 400 | |
| 401 | std::stringstream routineNameSS; |
| 402 | // This follows the same naming format as Flang. |
| 403 | routineNameSS << "acc_routine_" << routineCounter++; |
| 404 | std::string routineName = routineNameSS.str(); |
| 405 | |
| 406 | // There isn't a good constructor for RoutineOp that just takes a location + |
| 407 | // name + function, so we use one that creates an otherwise RoutineOp and |
| 408 | // count on the visitor/emitter to fill these in. |
| 409 | auto routineOp = mlir::acc::RoutineOp::create( |
| 410 | builder, location: routineLoc, sym_name: routineName, |
| 411 | func_name: mlir::SymbolRefAttr::get(ctx: builder.getContext(), value: func.getName()), |
| 412 | /*implicit=*/false); |
| 413 | |
| 414 | // We have to add a pointer going the other direction via an acc.routine_info, |
| 415 | // from the func to the routine. |
| 416 | llvm::SmallVector<mlir::SymbolRefAttr> funcRoutines; |
| 417 | if (auto routineInfo = |
| 418 | func.getOperation()->getAttrOfType<mlir::acc::RoutineInfoAttr>( |
| 419 | name: mlir::acc::getRoutineInfoAttrName())) |
| 420 | funcRoutines.append(in_start: routineInfo.getAccRoutines().begin(), |
| 421 | in_end: routineInfo.getAccRoutines().end()); |
| 422 | |
| 423 | funcRoutines.push_back( |
| 424 | Elt: mlir::SymbolRefAttr::get(ctx: builder.getContext(), value: routineName)); |
| 425 | func.getOperation()->setAttr( |
| 426 | name: mlir::acc::getRoutineInfoAttrName(), |
| 427 | value: mlir::acc::RoutineInfoAttr::get(context: func.getContext(), accRoutines: funcRoutines)); |
| 428 | |
| 429 | OpenACCRoutineClauseEmitter emitter{*this, builder, routineOp, funcDecl}; |
| 430 | emitter.emitClauses(clauses); |
| 431 | } |
| 432 | |