Skip to content

Commit 94c1d56

Browse files
committed
[SYCL] Don't add SYCL stream class to kernel arguments list.
Signed-off-by: Vladimir Lazarev <vladimir.lazarev@intel.com>
1 parent 70774e8 commit 94c1d56

File tree

1 file changed

+55
-50
lines changed

1 file changed

+55
-50
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -113,59 +113,62 @@ CompoundStmt *CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelHelper,
113113
auto TargetFunc = dyn_cast<FunctionDecl>(DC);
114114
auto TargetFuncParam =
115115
TargetFunc->param_begin(); // Iterator to ParamVarDecl (VarDecl)
116-
for (auto Field : LC->fields()) {
117-
QualType ParamType = (*TargetFuncParam)->getOriginalType();
118-
auto DRE = DeclRefExpr::Create(
119-
S.Context, NestedNameSpecifierLoc(), SourceLocation(),
120-
*TargetFuncParam, false, DeclarationNameInfo(), ParamType, VK_LValue);
121-
122-
CXXRecordDecl *CRD = Field->getType()->getAsCXXRecordDecl();
123-
if (CRD) {
124-
llvm::SmallVector<Expr *, 16> ParamStmts;
125-
DeclAccessPair FieldDAP = DeclAccessPair::make(Field, AS_none);
126-
auto AccessorME = MemberExpr::Create(
127-
S.Context, LambdaDRE, false, SourceLocation(),
128-
NestedNameSpecifierLoc(), SourceLocation(), Field, FieldDAP,
129-
DeclarationNameInfo(Field->getDeclName(), SourceLocation()),
130-
nullptr, Field->getType(), VK_LValue, OK_Ordinary);
131-
132-
for (auto Method : CRD->methods()) {
133-
if (Method->getNameInfo().getName().getAsString() ==
134-
"__set_pointer") {
135-
DeclAccessPair MethodDAP = DeclAccessPair::make(Method, AS_none);
136-
auto ME = MemberExpr::Create(
137-
S.Context, AccessorME, false, SourceLocation(),
138-
NestedNameSpecifierLoc(), SourceLocation(), Method, MethodDAP,
139-
Method->getNameInfo(), nullptr, Method->getType(), VK_LValue,
140-
OK_Ordinary);
141-
142-
// Not referenced -> not emitted
143-
S.MarkFunctionReferenced(SourceLocation(), Method, true);
144-
145-
QualType ResultTy = Method->getReturnType();
146-
ExprValueKind VK = Expr::getValueKindForType(ResultTy);
147-
ResultTy = ResultTy.getNonLValueExprType(S.Context);
148-
149-
// __set_pointer needs one parameter
150-
QualType paramTy = (*(Method->param_begin()))->getOriginalType();
151-
152-
// C++ address space attribute != opencl address space attribute
153-
Expr *qualifiersCast = ImplicitCastExpr::Create(
154-
S.Context, paramTy, CK_NoOp, DRE, nullptr, VK_LValue);
155-
Expr *Res =
156-
ImplicitCastExpr::Create(S.Context, paramTy, CK_LValueToRValue,
157-
qualifiersCast, nullptr, VK_RValue);
158-
159-
ParamStmts.push_back(Res);
160-
161-
// lambda.accessor.__set_pointer(kernel_parameter)
162-
CXXMemberCallExpr *Call = CXXMemberCallExpr::Create(
163-
S.Context, ME, ParamStmts, ResultTy, VK, SourceLocation());
164-
BodyStmts.push_back(Call);
116+
if (TargetFuncParam) {
117+
for (auto Field : LC->fields()) {
118+
QualType ParamType = (*TargetFuncParam)->getOriginalType();
119+
auto DRE =
120+
DeclRefExpr::Create(S.Context, NestedNameSpecifierLoc(),
121+
SourceLocation(), *TargetFuncParam, false,
122+
DeclarationNameInfo(), ParamType, VK_LValue);
123+
124+
CXXRecordDecl *CRD = Field->getType()->getAsCXXRecordDecl();
125+
if (CRD) {
126+
llvm::SmallVector<Expr *, 16> ParamStmts;
127+
DeclAccessPair FieldDAP = DeclAccessPair::make(Field, AS_none);
128+
auto AccessorME = MemberExpr::Create(
129+
S.Context, LambdaDRE, false, SourceLocation(),
130+
NestedNameSpecifierLoc(), SourceLocation(), Field, FieldDAP,
131+
DeclarationNameInfo(Field->getDeclName(), SourceLocation()),
132+
nullptr, Field->getType(), VK_LValue, OK_Ordinary);
133+
134+
for (auto Method : CRD->methods()) {
135+
if (Method->getNameInfo().getName().getAsString() ==
136+
"__set_pointer") {
137+
DeclAccessPair MethodDAP = DeclAccessPair::make(Method, AS_none);
138+
auto ME = MemberExpr::Create(
139+
S.Context, AccessorME, false, SourceLocation(),
140+
NestedNameSpecifierLoc(), SourceLocation(), Method, MethodDAP,
141+
Method->getNameInfo(), nullptr, Method->getType(), VK_LValue,
142+
OK_Ordinary);
143+
144+
// Not referenced -> not emitted
145+
S.MarkFunctionReferenced(SourceLocation(), Method, true);
146+
147+
QualType ResultTy = Method->getReturnType();
148+
ExprValueKind VK = Expr::getValueKindForType(ResultTy);
149+
ResultTy = ResultTy.getNonLValueExprType(S.Context);
150+
151+
// __set_pointer needs one parameter
152+
QualType paramTy = (*(Method->param_begin()))->getOriginalType();
153+
154+
// C++ address space attribute != opencl address space attribute
155+
Expr *qualifiersCast = ImplicitCastExpr::Create(
156+
S.Context, paramTy, CK_NoOp, DRE, nullptr, VK_LValue);
157+
Expr *Res = ImplicitCastExpr::Create(
158+
S.Context, paramTy, CK_LValueToRValue, qualifiersCast,
159+
nullptr, VK_RValue);
160+
161+
ParamStmts.push_back(Res);
162+
163+
// lambda.accessor.__set_pointer(kernel_parameter)
164+
CXXMemberCallExpr *Call = new (S.Context) CXXMemberCallExpr(
165+
S.Context, ME, ParamStmts, ResultTy, VK, SourceLocation());
166+
BodyStmts.push_back(Call);
167+
}
165168
}
166169
}
170+
TargetFuncParam++;
167171
}
168-
TargetFuncParam++;
169172
}
170173

171174
// In function from headers lambda is function parameter, we need
@@ -216,6 +219,8 @@ void BuildArgTys(ASTContext &Context,
216219
Context.getQualifiedType(PointerType.getUnqualifiedType(), Quals);
217220
}
218221
}
222+
} else if (std::string(Name) == "stream") {
223+
continue;
219224
}
220225
DeclContext *DC = Context.getTranslationUnitDecl();
221226

0 commit comments

Comments
 (0)