From 94c1d5662cf7d7ed1137c8d1567ffa43d7144c0c Mon Sep 17 00:00:00 2001 From: Vladimir Lazarev Date: Fri, 28 Dec 2018 21:55:16 +0300 Subject: [PATCH] [SYCL] Don't add SYCL stream class to kernel arguments list. Signed-off-by: Vladimir Lazarev --- clang/lib/Sema/SemaSYCL.cpp | 105 +++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 50 deletions(-) diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 1a46b82e0392e..fde50287df2df 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -113,59 +113,62 @@ CompoundStmt *CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelHelper, auto TargetFunc = dyn_cast(DC); auto TargetFuncParam = TargetFunc->param_begin(); // Iterator to ParamVarDecl (VarDecl) - for (auto Field : LC->fields()) { - QualType ParamType = (*TargetFuncParam)->getOriginalType(); - auto DRE = DeclRefExpr::Create( - S.Context, NestedNameSpecifierLoc(), SourceLocation(), - *TargetFuncParam, false, DeclarationNameInfo(), ParamType, VK_LValue); - - CXXRecordDecl *CRD = Field->getType()->getAsCXXRecordDecl(); - if (CRD) { - llvm::SmallVector ParamStmts; - DeclAccessPair FieldDAP = DeclAccessPair::make(Field, AS_none); - auto AccessorME = MemberExpr::Create( - S.Context, LambdaDRE, false, SourceLocation(), - NestedNameSpecifierLoc(), SourceLocation(), Field, FieldDAP, - DeclarationNameInfo(Field->getDeclName(), SourceLocation()), - nullptr, Field->getType(), VK_LValue, OK_Ordinary); - - for (auto Method : CRD->methods()) { - if (Method->getNameInfo().getName().getAsString() == - "__set_pointer") { - DeclAccessPair MethodDAP = DeclAccessPair::make(Method, AS_none); - auto ME = MemberExpr::Create( - S.Context, AccessorME, false, SourceLocation(), - NestedNameSpecifierLoc(), SourceLocation(), Method, MethodDAP, - Method->getNameInfo(), nullptr, Method->getType(), VK_LValue, - OK_Ordinary); - - // Not referenced -> not emitted - S.MarkFunctionReferenced(SourceLocation(), Method, true); - - QualType ResultTy = Method->getReturnType(); - ExprValueKind VK = Expr::getValueKindForType(ResultTy); - ResultTy = ResultTy.getNonLValueExprType(S.Context); - - // __set_pointer needs one parameter - QualType paramTy = (*(Method->param_begin()))->getOriginalType(); - - // C++ address space attribute != opencl address space attribute - Expr *qualifiersCast = ImplicitCastExpr::Create( - S.Context, paramTy, CK_NoOp, DRE, nullptr, VK_LValue); - Expr *Res = - ImplicitCastExpr::Create(S.Context, paramTy, CK_LValueToRValue, - qualifiersCast, nullptr, VK_RValue); - - ParamStmts.push_back(Res); - - // lambda.accessor.__set_pointer(kernel_parameter) - CXXMemberCallExpr *Call = CXXMemberCallExpr::Create( - S.Context, ME, ParamStmts, ResultTy, VK, SourceLocation()); - BodyStmts.push_back(Call); + if (TargetFuncParam) { + for (auto Field : LC->fields()) { + QualType ParamType = (*TargetFuncParam)->getOriginalType(); + auto DRE = + DeclRefExpr::Create(S.Context, NestedNameSpecifierLoc(), + SourceLocation(), *TargetFuncParam, false, + DeclarationNameInfo(), ParamType, VK_LValue); + + CXXRecordDecl *CRD = Field->getType()->getAsCXXRecordDecl(); + if (CRD) { + llvm::SmallVector ParamStmts; + DeclAccessPair FieldDAP = DeclAccessPair::make(Field, AS_none); + auto AccessorME = MemberExpr::Create( + S.Context, LambdaDRE, false, SourceLocation(), + NestedNameSpecifierLoc(), SourceLocation(), Field, FieldDAP, + DeclarationNameInfo(Field->getDeclName(), SourceLocation()), + nullptr, Field->getType(), VK_LValue, OK_Ordinary); + + for (auto Method : CRD->methods()) { + if (Method->getNameInfo().getName().getAsString() == + "__set_pointer") { + DeclAccessPair MethodDAP = DeclAccessPair::make(Method, AS_none); + auto ME = MemberExpr::Create( + S.Context, AccessorME, false, SourceLocation(), + NestedNameSpecifierLoc(), SourceLocation(), Method, MethodDAP, + Method->getNameInfo(), nullptr, Method->getType(), VK_LValue, + OK_Ordinary); + + // Not referenced -> not emitted + S.MarkFunctionReferenced(SourceLocation(), Method, true); + + QualType ResultTy = Method->getReturnType(); + ExprValueKind VK = Expr::getValueKindForType(ResultTy); + ResultTy = ResultTy.getNonLValueExprType(S.Context); + + // __set_pointer needs one parameter + QualType paramTy = (*(Method->param_begin()))->getOriginalType(); + + // C++ address space attribute != opencl address space attribute + Expr *qualifiersCast = ImplicitCastExpr::Create( + S.Context, paramTy, CK_NoOp, DRE, nullptr, VK_LValue); + Expr *Res = ImplicitCastExpr::Create( + S.Context, paramTy, CK_LValueToRValue, qualifiersCast, + nullptr, VK_RValue); + + ParamStmts.push_back(Res); + + // lambda.accessor.__set_pointer(kernel_parameter) + CXXMemberCallExpr *Call = new (S.Context) CXXMemberCallExpr( + S.Context, ME, ParamStmts, ResultTy, VK, SourceLocation()); + BodyStmts.push_back(Call); + } } } + TargetFuncParam++; } - TargetFuncParam++; } // In function from headers lambda is function parameter, we need @@ -216,6 +219,8 @@ void BuildArgTys(ASTContext &Context, Context.getQualifiedType(PointerType.getUnqualifiedType(), Quals); } } + } else if (std::string(Name) == "stream") { + continue; } DeclContext *DC = Context.getTranslationUnitDecl();