From 30d652a447839340ccd4d1b3c49de832abf88ee2 Mon Sep 17 00:00:00 2001 From: Yaxun Liu Date: Tue, 15 Aug 2017 16:02:49 +0000 Subject: [OpenCL] Support variable memory scope in atomic builtins Differential Revision: https://reviews.llvm.org/D36580 llvm-svn: 310924 --- clang/lib/Sema/SemaChecking.cpp | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) (limited to 'clang/lib/Sema/SemaChecking.cpp') diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e75c15a37cd..31700e78939 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -3145,27 +3145,6 @@ ExprResult Sema::SemaAtomicOpsOverloaded(ExprResult TheCallResult, TheCall->setArg(i, Arg.get()); } - Expr *Scope; - if (Form != Init) { - if (IsOpenCL) { - Scope = TheCall->getArg(TheCall->getNumArgs() - 1); - llvm::APSInt Result(32); - if (!Scope->isIntegerConstantExpr(Result, Context)) - Diag(Scope->getLocStart(), - diag::err_atomic_op_has_non_constant_synch_scope) - << Scope->getSourceRange(); - else if (!isValidSyncScopeValue(Result.getZExtValue())) - Diag(Scope->getLocStart(), diag::err_atomic_op_has_invalid_synch_scope) - << Scope->getSourceRange(); - } else { - Scope = IntegerLiteral::Create( - Context, - llvm::APInt(Context.getTypeSize(Context.IntTy), - static_cast(SyncScope::OpenCLAllSVMDevices)), - Context.IntTy, SourceLocation()); - } - } - // Permute the arguments into a 'consistent' order. SmallVector SubExprs; SubExprs.push_back(Ptr); @@ -3176,33 +3155,28 @@ ExprResult Sema::SemaAtomicOpsOverloaded(ExprResult TheCallResult, break; case Load: SubExprs.push_back(TheCall->getArg(1)); // Order - SubExprs.push_back(Scope); // Scope break; case LoadCopy: case Copy: case Arithmetic: case Xchg: SubExprs.push_back(TheCall->getArg(2)); // Order - SubExprs.push_back(Scope); // Scope SubExprs.push_back(TheCall->getArg(1)); // Val1 break; case GNUXchg: // Note, AtomicExpr::getVal2() has a special case for this atomic. SubExprs.push_back(TheCall->getArg(3)); // Order - SubExprs.push_back(Scope); // Scope SubExprs.push_back(TheCall->getArg(1)); // Val1 SubExprs.push_back(TheCall->getArg(2)); // Val2 break; case C11CmpXchg: SubExprs.push_back(TheCall->getArg(3)); // Order - SubExprs.push_back(Scope); // Scope SubExprs.push_back(TheCall->getArg(1)); // Val1 SubExprs.push_back(TheCall->getArg(4)); // OrderFail SubExprs.push_back(TheCall->getArg(2)); // Val2 break; case GNUCmpXchg: SubExprs.push_back(TheCall->getArg(4)); // Order - SubExprs.push_back(Scope); // Scope SubExprs.push_back(TheCall->getArg(1)); // Val1 SubExprs.push_back(TheCall->getArg(5)); // OrderFail SubExprs.push_back(TheCall->getArg(2)); // Val2 @@ -3219,6 +3193,17 @@ ExprResult Sema::SemaAtomicOpsOverloaded(ExprResult TheCallResult, << SubExprs[1]->getSourceRange(); } + if (auto ScopeModel = AtomicExpr::getScopeModel(Op)) { + auto *Scope = TheCall->getArg(TheCall->getNumArgs() - 1); + llvm::APSInt Result(32); + if (Scope->isIntegerConstantExpr(Result, Context) && + !ScopeModel->isValid(Result.getZExtValue())) { + Diag(Scope->getLocStart(), diag::err_atomic_op_has_invalid_synch_scope) + << Scope->getSourceRange(); + } + SubExprs.push_back(Scope); + } + AtomicExpr *AE = new (Context) AtomicExpr(TheCall->getCallee()->getLocStart(), SubExprs, ResultType, Op, TheCall->getRParenLoc()); -- cgit v1.2.3