|
26 | 26 |
|
27 | 27 | using namespace clang;
|
28 | 28 |
|
29 |
| -typedef llvm::DenseMap<DeclaratorDecl *, DeclaratorDecl *> DeclMap; |
30 |
| - |
31 | 29 | using KernelParamKind = SYCLIntegrationHeader::kernel_param_kind_t;
|
32 | 30 |
|
33 | 31 | enum target {
|
@@ -376,27 +374,25 @@ class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
|
376 | 374 |
|
377 | 375 | class KernelBodyTransform : public TreeTransform<KernelBodyTransform> {
|
378 | 376 | public:
|
379 |
| - KernelBodyTransform(llvm::DenseMap<DeclaratorDecl *, DeclaratorDecl *> &Map, |
| 377 | + KernelBodyTransform(std::pair<DeclaratorDecl *, DeclaratorDecl *> &MPair, |
380 | 378 | Sema &S)
|
381 |
| - : TreeTransform<KernelBodyTransform>(S), DMap(Map), SemaRef(S) {} |
| 379 | + : TreeTransform<KernelBodyTransform>(S), MappingPair(MPair), SemaRef(S) {} |
382 | 380 | bool AlwaysRebuild() { return true; }
|
383 | 381 |
|
384 | 382 | ExprResult TransformDeclRefExpr(DeclRefExpr *DRE) {
|
385 | 383 | auto Ref = dyn_cast<DeclaratorDecl>(DRE->getDecl());
|
386 |
| - if (Ref) { |
387 |
| - auto NewDecl = DMap[Ref]; |
388 |
| - if (NewDecl) { |
389 |
| - return DeclRefExpr::Create( |
390 |
| - SemaRef.getASTContext(), DRE->getQualifierLoc(), |
391 |
| - DRE->getTemplateKeywordLoc(), NewDecl, false, DRE->getNameInfo(), |
392 |
| - NewDecl->getType(), DRE->getValueKind()); |
393 |
| - } |
| 384 | + if (Ref && Ref == MappingPair.first) { |
| 385 | + auto NewDecl = MappingPair.second; |
| 386 | + return DeclRefExpr::Create( |
| 387 | + SemaRef.getASTContext(), DRE->getQualifierLoc(), |
| 388 | + DRE->getTemplateKeywordLoc(), NewDecl, false, DRE->getNameInfo(), |
| 389 | + NewDecl->getType(), DRE->getValueKind()); |
394 | 390 | }
|
395 | 391 | return DRE;
|
396 | 392 | }
|
397 | 393 |
|
398 | 394 | private:
|
399 |
| - DeclMap DMap; |
| 395 | + std::pair<DeclaratorDecl *, DeclaratorDecl *> MappingPair; |
400 | 396 | Sema &SemaRef;
|
401 | 397 | };
|
402 | 398 |
|
@@ -618,21 +614,23 @@ CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelCallerFunc, DeclContext *Kerne
|
618 | 614 | KernelFuncParam++;
|
619 | 615 | }
|
620 | 616 | }
|
621 |
| - // In function from headers lambda is function parameter, we need |
622 |
| - // to replace all refs to this lambda with our vardecl. |
623 |
| - // I used TreeTransform here, but I'm not sure that it is good solution |
624 |
| - // Also I used map and I'm not sure about it too. |
625 |
| - // TODO SYCL review the above design concerns |
| 617 | + |
| 618 | + // In kernel caller function lambda/functior is function parameter, we need |
| 619 | + // to replace all refs to this lambda/functor with our kernel object clone |
| 620 | + // declared inside kernel body. |
626 | 621 | Stmt *FunctionBody = KernelCallerFunc->getBody();
|
627 |
| - DeclMap DMap; |
628 | 622 | ParmVarDecl *KernelObjParam = *(KernelCallerFunc->param_begin());
|
| 623 | + |
629 | 624 | // DeclRefExpr with valid source location but with decl which is not marked
|
630 | 625 | // as used is invalid.
|
631 | 626 | KernelObjClone->setIsUsed();
|
632 |
| - DMap[KernelObjParam] = KernelObjClone; |
633 |
| - // Without PushFunctionScope I had segfault. Maybe we also need to do pop. |
| 627 | + std::pair<DeclaratorDecl *, DeclaratorDecl *> MappingPair; |
| 628 | + MappingPair.first = KernelObjParam; |
| 629 | + MappingPair.second = KernelObjClone; |
| 630 | + |
| 631 | + // Function scope might be empty, so we do push |
634 | 632 | S.PushFunctionScope();
|
635 |
| - KernelBodyTransform KBT(DMap, S); |
| 633 | + KernelBodyTransform KBT(MappingPair, S); |
636 | 634 | Stmt *NewBody = KBT.TransformStmt(FunctionBody).get();
|
637 | 635 | BodyStmts.push_back(NewBody);
|
638 | 636 | return CompoundStmt::Create(S.Context, BodyStmts, SourceLocation(),
|
|
0 commit comments