[PATCH] D25796: [CUDA] Create __host__ and device variants of standard allocator declarations.

2016-12-06 Thread Artem Belevich via Phabricator via cfe-commits
tra closed this revision.
tra added a comment.

Landed in r284879.


https://reviews.llvm.org/D25796



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25796: [CUDA] Create __host__ and device variants of standard allocator declarations.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar accepted this revision.
jlebar added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Sema/SemaExprCXX.cpp:2596
 
-  QualType FnType = Context.getFunctionType(Return, Params, EPI);
-  FunctionDecl *Alloc =
-FunctionDecl::Create(Context, GlobalCtx, SourceLocation(),
- SourceLocation(), Name,
- FnType, /*TInfo=*/nullptr, SC_None, false, true);
-  Alloc->setImplicit();
+  auto CreateAllocationFunctionDecl = [&](Attr *ExtraAttr) {
+QualType FnType = Context.getFunctionType(Return, Params, EPI);

Oh, I like this way better than a bool arg.


https://reviews.llvm.org/D25796



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25796: [CUDA] Create __host__ and device variants of standard allocator declarations.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added inline comments.



Comment at: lib/Sema/SemaExprCXX.cpp:2596
 
-  QualType FnType = Context.getFunctionType(Return, Params, EPI);
-  FunctionDecl *Alloc =
-FunctionDecl::Create(Context, GlobalCtx, SourceLocation(),
- SourceLocation(), Name,
- FnType, /*TInfo=*/nullptr, SC_None, false, true);
-  Alloc->setImplicit();
+  auto CreateAllocationFunctionDecl = [&]() {
+QualType FnType = Context.getFunctionType(Return, Params, EPI);

Nit, no need for empty parens.



Comment at: lib/Sema/SemaExprCXX.cpp:2622
   Context.getTranslationUnitDecl()->addDecl(Alloc);
   IdResolver.tryAddTopLevelDecl(Alloc, Name);
+

I kind of feel like it would be easier to add a boolean parameter to 
CreateAllocationFunctionDecl, then you don't need to repeat these two lines.


https://reviews.llvm.org/D25796



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25796: [CUDA] Create __host__ and device variants of standard allocator declarations.

2016-10-21 Thread Justin Lebar via cfe-commits
jlebar added a comment.

Is it not possible to write a testcase for this?


https://reviews.llvm.org/D25796



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25796: [CUDA] Create __host__ and device variants of standard allocator declarations.

2016-10-19 Thread Artem Belevich via cfe-commits
tra created this revision.
tra added a reviewer: jlebar.
tra added a subscriber: cfe-commits.

Implicit functions are treated as if they were __host__ __device__ and clang 
does not allow overloading 
those with __host__ or __device__ variants.

In order for users to provide their own standard allocators, we must create 
__host__ and __device__ variants of these declarations during CUDA compilation.


https://reviews.llvm.org/D25796

Files:
  lib/Sema/SemaExprCXX.cpp


Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2593,28 +2593,40 @@
 getLangOpts().CPlusPlus11 ? EST_BasicNoexcept : EST_DynamicNone;
   }
 
-  QualType FnType = Context.getFunctionType(Return, Params, EPI);
-  FunctionDecl *Alloc =
-FunctionDecl::Create(Context, GlobalCtx, SourceLocation(),
- SourceLocation(), Name,
- FnType, /*TInfo=*/nullptr, SC_None, false, true);
-  Alloc->setImplicit();
+  auto CreateAllocationFunctionDecl = [&]() {
+QualType FnType = Context.getFunctionType(Return, Params, EPI);
+FunctionDecl *Alloc = FunctionDecl::Create(
+Context, GlobalCtx, SourceLocation(), SourceLocation(), Name,
+FnType, /*TInfo=*/nullptr, SC_None, false, true);
+Alloc->setImplicit();
 
-  // Implicit sized deallocation functions always have default visibility.
-  Alloc->addAttr(VisibilityAttr::CreateImplicit(Context,
-VisibilityAttr::Default));
+// Implicit sized deallocation functions always have default visibility.
+Alloc->addAttr(
+VisibilityAttr::CreateImplicit(Context, VisibilityAttr::Default));
 
-  llvm::SmallVector ParamDecls;
-  for (QualType T : Params) {
-ParamDecls.push_back(
-ParmVarDecl::Create(Context, Alloc, SourceLocation(), SourceLocation(),
-nullptr, T, /*TInfo=*/nullptr, SC_None, nullptr));
-ParamDecls.back()->setImplicit();
-  }
-  Alloc->setParams(ParamDecls);
+llvm::SmallVector ParamDecls;
+for (QualType T : Params) {
+  ParamDecls.push_back(ParmVarDecl::Create(
+  Context, Alloc, SourceLocation(), SourceLocation(), nullptr, T,
+  /*TInfo=*/nullptr, SC_None, nullptr));
+  ParamDecls.back()->setImplicit();
+}
+Alloc->setParams(ParamDecls);
+return Alloc;
+  };
 
+  FunctionDecl *Alloc = CreateAllocationFunctionDecl();
+  if (LangOpts.CUDA)
+Alloc->addAttr(CUDAHostAttr::CreateImplicit(Context));
   Context.getTranslationUnitDecl()->addDecl(Alloc);
   IdResolver.tryAddTopLevelDecl(Alloc, Name);
+
+  if (LangOpts.CUDA) {
+Alloc = CreateAllocationFunctionDecl();
+Alloc->addAttr(CUDADeviceAttr::CreateImplicit(Context));
+Context.getTranslationUnitDecl()->addDecl(Alloc);
+IdResolver.tryAddTopLevelDecl(Alloc, Name);
+  }
 }
 
 FunctionDecl *Sema::FindUsualDeallocationFunction(SourceLocation StartLoc,


Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -2593,28 +2593,40 @@
 getLangOpts().CPlusPlus11 ? EST_BasicNoexcept : EST_DynamicNone;
   }
 
-  QualType FnType = Context.getFunctionType(Return, Params, EPI);
-  FunctionDecl *Alloc =
-FunctionDecl::Create(Context, GlobalCtx, SourceLocation(),
- SourceLocation(), Name,
- FnType, /*TInfo=*/nullptr, SC_None, false, true);
-  Alloc->setImplicit();
+  auto CreateAllocationFunctionDecl = [&]() {
+QualType FnType = Context.getFunctionType(Return, Params, EPI);
+FunctionDecl *Alloc = FunctionDecl::Create(
+Context, GlobalCtx, SourceLocation(), SourceLocation(), Name,
+FnType, /*TInfo=*/nullptr, SC_None, false, true);
+Alloc->setImplicit();
 
-  // Implicit sized deallocation functions always have default visibility.
-  Alloc->addAttr(VisibilityAttr::CreateImplicit(Context,
-VisibilityAttr::Default));
+// Implicit sized deallocation functions always have default visibility.
+Alloc->addAttr(
+VisibilityAttr::CreateImplicit(Context, VisibilityAttr::Default));
 
-  llvm::SmallVector ParamDecls;
-  for (QualType T : Params) {
-ParamDecls.push_back(
-ParmVarDecl::Create(Context, Alloc, SourceLocation(), SourceLocation(),
-nullptr, T, /*TInfo=*/nullptr, SC_None, nullptr));
-ParamDecls.back()->setImplicit();
-  }
-  Alloc->setParams(ParamDecls);
+llvm::SmallVector ParamDecls;
+for (QualType T : Params) {
+  ParamDecls.push_back(ParmVarDecl::Create(
+  Context, Alloc, SourceLocation(), SourceLocation(), nullptr, T,
+  /*TInfo=*/nullptr, SC_None, nullptr));
+  ParamDecls.back()->setImplicit();
+}
+Alloc->setParams(ParamDecls);
+return Alloc;
+  };
 
+