@@ -62,14 +62,15 @@ CompoundStmt *CreateSYCLKernelBody(Sema &S, CXXMemberCallExpr *e,
62
62
if (LE) {
63
63
// Create Lambda object
64
64
CXXRecordDecl *LC = LE->getLambdaClass ();
65
- auto Lambda_VD = VarDecl::Create (
65
+ auto LambdaVD = VarDecl::Create (
66
66
S.Context , DC, SourceLocation (), SourceLocation (), LC->getIdentifier (),
67
67
QualType (LC->getTypeForDecl (), 0 ), LC->getLambdaTypeInfo (), SC_None);
68
+
68
69
Stmt *DS = new (S.Context )
69
- DeclStmt (DeclGroupRef (Lambda_VD ), SourceLocation (), SourceLocation ());
70
+ DeclStmt (DeclGroupRef (LambdaVD ), SourceLocation (), SourceLocation ());
70
71
BodyStmts.push_back (DS);
71
- auto Lambda_DRE = DeclRefExpr::Create (
72
- S.Context , NestedNameSpecifierLoc (), SourceLocation (), Lambda_VD , false ,
72
+ auto LambdaDRE = DeclRefExpr::Create (
73
+ S.Context , NestedNameSpecifierLoc (), SourceLocation (), LambdaVD , false ,
73
74
DeclarationNameInfo (), QualType (LC->getTypeForDecl (), 0 ), VK_LValue);
74
75
75
76
// Init Lambda fields
@@ -78,37 +79,66 @@ CompoundStmt *CreateSYCLKernelBody(Sema &S, CXXMemberCallExpr *e,
78
79
auto TargetFunc = dyn_cast<FunctionDecl>(DC);
79
80
auto TargetFuncParam =
80
81
TargetFunc->param_begin (); // Iterator to ParamVarDecl (VarDecl)
81
- for (auto CaptureField : LE->captures ()) {
82
- VarDecl *CapturedVar =
83
- CaptureField
84
- .getCapturedVar (); // accessor, need to do setInit for this
82
+ for (auto Field : LC->fields ()) {
85
83
QualType ParamType = (*TargetFuncParam)->getOriginalType ();
86
84
auto DRE = DeclRefExpr::Create (
87
85
S.Context , NestedNameSpecifierLoc (), SourceLocation (),
88
86
*TargetFuncParam, false , DeclarationNameInfo (), ParamType, VK_LValue);
89
87
90
- Expr *Res = ImplicitCastExpr::Create (
91
- S.Context , ParamType, CK_LValueToRValue, DRE, nullptr , VK_RValue);
88
+ CXXRecordDecl *CRD = Field->getType ()->getAsCXXRecordDecl ();
89
+ if (CRD) {
90
+ llvm::SmallVector<Expr *, 16 > ParamStmts;
91
+ DeclAccessPair FieldDAP = DeclAccessPair::make (Field, AS_none);
92
+ auto AccessorME = MemberExpr::Create (
93
+ S.Context , LambdaDRE, false , SourceLocation (),
94
+ NestedNameSpecifierLoc (), SourceLocation (), Field, FieldDAP,
95
+ DeclarationNameInfo (Field->getDeclName (), SourceLocation ()),
96
+ nullptr , Field->getType (), VK_LValue, OK_Ordinary);
97
+
98
+ for (auto Method : CRD->methods ()) {
99
+ if (Method->getNameInfo ().getName ().getAsString () ==
100
+ " __set_pointer" ) {
101
+ DeclAccessPair MethodDAP = DeclAccessPair::make (Method, AS_none);
102
+ auto ME = MemberExpr::Create (
103
+ S.Context , AccessorME, false , SourceLocation (),
104
+ NestedNameSpecifierLoc (), SourceLocation (), Method, MethodDAP,
105
+ Method->getNameInfo (), nullptr , Method->getType (), VK_LValue,
106
+ OK_Ordinary);
107
+
108
+ // Not referenced -> not emitted
109
+ S.MarkFunctionReferenced (SourceLocation (), Method, true );
110
+
111
+ QualType ResultTy = Method->getReturnType ();
112
+ ExprValueKind VK = Expr::getValueKindForType (ResultTy);
113
+ ResultTy = ResultTy.getNonLValueExprType (S.Context );
114
+
115
+ // __set_pointer needs one parameter
116
+ QualType paramTy = (*(Method->param_begin ()))->getOriginalType ();
92
117
93
- Expr *InitCapture = new (S.Context ) InitListExpr (
94
- S.Context , SourceLocation (), /* initExprs*/ Res, SourceLocation ());
95
- CapturedVar->setInit (InitCapture);
96
- InitCapture->setType (CapturedVar->getType ());
97
- InitCaptures.push_back (InitCapture);
118
+ // C++ address space attribute != opencl address space attribute
119
+ Expr *qualifiersCast = ImplicitCastExpr::Create (
120
+ S.Context , paramTy, CK_NoOp, DRE, nullptr , VK_LValue);
121
+ Expr *Res =
122
+ ImplicitCastExpr::Create (S.Context , paramTy, CK_LValueToRValue,
123
+ qualifiersCast, nullptr , VK_RValue);
124
+
125
+ ParamStmts.push_back (Res);
126
+
127
+ // lambda.accessor.__set_pointer(kernel_parameter)
128
+ CXXMemberCallExpr *Call = CXXMemberCallExpr::Create (
129
+ S.Context , ME, ParamStmts, ResultTy, VK, SourceLocation ());
130
+ BodyStmts.push_back (Call);
131
+ }
132
+ }
133
+ }
98
134
TargetFuncParam++;
99
135
}
100
136
101
- Expr *InitLambdaCaptures = new (S.Context )
102
- InitListExpr (S.Context , SourceLocation (), /* initExprs*/ InitCaptures,
103
- SourceLocation ());
104
- InitLambdaCaptures->setType (Lambda_VD->getType ());
105
- Lambda_VD->setInit (InitLambdaCaptures);
106
-
107
137
// Create Lambda operator () call
108
138
FunctionDecl *LO = LE->getCallOperator ();
109
139
ArrayRef<ParmVarDecl *> Args = LO->parameters ();
110
140
llvm::SmallVector<Expr *, 16 > ParamStmts (1 );
111
- ParamStmts[0 ] = dyn_cast<Expr>(Lambda_DRE );
141
+ ParamStmts[0 ] = dyn_cast<Expr>(LambdaDRE );
112
142
113
143
// Collect arguments for () operator
114
144
for (auto Arg : Args) {
0 commit comments