[PATCH] D50099: [DebugInfo][OpenCL] Address post-commit review of D49930

2018-08-06 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

When I went to mark these as static I noticed they use 
`CGDebugInfo::CreateMemberType` which uses a couple other non-static member 
functions, and it starts to become difficult to tease things out into nice 
clean static functions.




Comment at: lib/CodeGen/CGDebugInfo.cpp:997
   llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
   unsigned LineNo = 0;
 

echristo wrote:
> Just noticed that LineNo is 0... for the entire function.
What should it be instead? My understanding is that LineNo=0 indicates there is 
no corresponding source, and these fields seem to be implementation details.


https://reviews.llvm.org/D50099



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


[PATCH] D50099: [DebugInfo][OpenCL] Address post-commit review of D49930

2018-08-06 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:997
   llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
   unsigned LineNo = 0;
 

echristo wrote:
> scott.linder wrote:
> > echristo wrote:
> > > Just noticed that LineNo is 0... for the entire function.
> > What should it be instead? My understanding is that LineNo=0 indicates 
> > there is no corresponding source, and these fields seem to be 
> > implementation details.
> Could probably just replace it with a constant 0 in the calls rather than 
> having the local?
Oh, I see what you mean; I will make that change, and I am also working out how 
to enable ASan correctly to check the patch, then I will post a new diff.


https://reviews.llvm.org/D50099



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


[PATCH] D50099: [DebugInfo][OpenCL] Address post-commit review of D49930

2018-08-07 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 159512.
scott.linder added a comment.

Address feedback


https://reviews.llvm.org/D50099

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  test/CodeGenOpenCL/blocks.cl

Index: test/CodeGenOpenCL/blocks.cl
===
--- test/CodeGenOpenCL/blocks.cl
+++ test/CodeGenOpenCL/blocks.cl
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple spir-unknown-unknown | FileCheck -check-prefixes=COMMON,SPIR %s
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=COMMON,AMDGCN %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck -check-prefixes=COMMON,SPIR %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=COMMON,AMDGCN %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple spir-unknown-unknown | FileCheck -check-prefixes=CHECK-DEBUG %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=CHECK-DEBUG %s
 
 // COMMON: @__block_literal_global = internal addrspace(1) constant { i32, i32 } { i32 8, i32 4 }
 // COMMON-NOT: .str
@@ -61,10 +63,10 @@
 
 // COMMON-NOT: define{{.*}}@__foo_block_invoke_kernel
 
-// COMMON: !DIDerivedType(tag: DW_TAG_member, name: "__size"
-// COMMON: !DIDerivedType(tag: DW_TAG_member, name: "__align"
+// CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__size"
+// CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__align"
 
-// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__isa"
-// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__flags"
-// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__reserved"
-// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__FuncPtr"
+// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__isa"
+// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__flags"
+// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__reserved"
+// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__FuncPtr"
Index: lib/CodeGen/CGDebugInfo.h
===
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -311,6 +311,22 @@
   void AppendAddressSpaceXDeref(unsigned AddressSpace,
 SmallVectorImpl &Expr) const;
 
+  /// A helper function to collect debug info for the default elements of a
+  /// block.
+  ///
+  /// \returns The next available field offset after the default elements.
+  uint64_t collectDefaultElementTypesForBlockPointer(
+  const BlockPointerType *Ty, llvm::DIFile *Unit,
+  llvm::DIDerivedType *DescTy, unsigned LineNo,
+  SmallVectorImpl &EltTys);
+
+  /// A helper function to collect debug info for the default fields of a
+  /// block.
+  void collectDefaultFieldsForBlockLiteralDeclare(
+  const CGBlockInfo &Block, const ASTContext &Context, SourceLocation Loc,
+  const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
+  SmallVectorImpl &Fields);
+
 public:
   CGDebugInfo(CodeGenModule &CGM);
   ~CGDebugInfo();
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -942,12 +942,47 @@
   return Cache;
 }
 
+uint64_t CGDebugInfo::collectDefaultElementTypesForBlockPointer(
+const BlockPointerType *Ty, llvm::DIFile *Unit, llvm::DIDerivedType *DescTy,
+unsigned LineNo, SmallVectorImpl &EltTys) {
+  QualType FType;
+
+  // Advanced by calls to CreateMemberType in increments of FType, then
+  // returned as the overall size of the default elements.
+  uint64_t FieldOffset = 0;
+
+  // Blocks in OpenCL have unique constraints which make the standard fields
+  // redundant while requiring size and align fields for enqueue_kernel. See
+  // initializeForBlockHeader in CGBlocks.cpp
+  if (CGM.getLangOpts().OpenCL) {
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__align", &FieldOffset));
+  } else {
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset));
+FType = CGM.getContext().getPointerType(Ty->getPointeeType());
+EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+uint64_t FieldSize 

[PATCH] D50099: [DebugInfo][OpenCL] Address post-commit review of D49930

2018-08-08 Thread Scott Linder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339265: [DebugInfo][OpenCL] Address post-commit review for 
r338299 (authored by scott.linder, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50099?vs=159512&id=159734#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50099

Files:
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.h
  cfe/trunk/test/CodeGenOpenCL/blocks.cl

Index: cfe/trunk/lib/CodeGen/CGDebugInfo.h
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h
@@ -311,6 +311,22 @@
   void AppendAddressSpaceXDeref(unsigned AddressSpace,
 SmallVectorImpl &Expr) const;
 
+  /// A helper function to collect debug info for the default elements of a
+  /// block.
+  ///
+  /// \returns The next available field offset after the default elements.
+  uint64_t collectDefaultElementTypesForBlockPointer(
+  const BlockPointerType *Ty, llvm::DIFile *Unit,
+  llvm::DIDerivedType *DescTy, unsigned LineNo,
+  SmallVectorImpl &EltTys);
+
+  /// A helper function to collect debug info for the default fields of a
+  /// block.
+  void collectDefaultFieldsForBlockLiteralDeclare(
+  const CGBlockInfo &Block, const ASTContext &Context, SourceLocation Loc,
+  const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
+  SmallVectorImpl &Fields);
+
 public:
   CGDebugInfo(CodeGenModule &CGM);
   ~CGDebugInfo();
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -942,12 +942,47 @@
   return Cache;
 }
 
+uint64_t CGDebugInfo::collectDefaultElementTypesForBlockPointer(
+const BlockPointerType *Ty, llvm::DIFile *Unit, llvm::DIDerivedType *DescTy,
+unsigned LineNo, SmallVectorImpl &EltTys) {
+  QualType FType;
+
+  // Advanced by calls to CreateMemberType in increments of FType, then
+  // returned as the overall size of the default elements.
+  uint64_t FieldOffset = 0;
+
+  // Blocks in OpenCL have unique constraints which make the standard fields
+  // redundant while requiring size and align fields for enqueue_kernel. See
+  // initializeForBlockHeader in CGBlocks.cpp
+  if (CGM.getLangOpts().OpenCL) {
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__align", &FieldOffset));
+  } else {
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset));
+FType = CGM.getContext().getPointerType(Ty->getPointeeType());
+EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+uint64_t FieldSize = CGM.getContext().getTypeSize(Ty);
+uint32_t FieldAlign = CGM.getContext().getTypeAlign(Ty);
+EltTys.push_back(DBuilder.createMemberType(
+Unit, "__descriptor", nullptr, LineNo, FieldSize, FieldAlign,
+FieldOffset, llvm::DINode::FlagZero, DescTy));
+FieldOffset += FieldSize;
+  }
+
+  return FieldOffset;
+}
+
 llvm::DIType *CGDebugInfo::CreateType(const BlockPointerType *Ty,
   llvm::DIFile *Unit) {
   SmallVector EltTys;
   QualType FType;
-  uint64_t FieldSize, FieldOffset;
-  uint32_t FieldAlign;
+  uint64_t FieldOffset;
   llvm::DINodeArray Elements;
 
   FieldOffset = 0;
@@ -959,46 +994,26 @@
   EltTys.clear();
 
   llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
-  unsigned LineNo = 0;
 
   auto *EltTy =
-  DBuilder.createStructType(Unit, "__block_descriptor", nullptr, LineNo,
+  DBuilder.createStructType(Unit, "__block_descriptor", nullptr, 0,
 FieldOffset, 0, Flags, nullptr, Elements);
 
   // Bit size, align and offset of the type.
   uint64_t Size = CGM.getContext().getTypeSize(Ty);
 
   auto *DescTy = DBuilder.createPointerType(EltTy, Size);
 
-  FieldOffset = 0;
-  if (CGM.getLangOpts().OpenCL) {
-FType = CGM.getContext().IntTy;
-EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
-EltTys.push_back(CreateMemberType(Unit, FType, "__align", &FieldOffset));
-  } else {
-FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
-EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
-FType = CGM.getContext().IntTy;
-EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
-EltTys.push_back(Cre

[PATCH] D51223: Update tests for new YAMLIO polymorphic traits

2018-08-24 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added a reviewer: klimek.
Herald added a subscriber: cfe-commits.

See https://reviews.llvm.org/D48144 for the LLVM patch.


Repository:
  rC Clang

https://reviews.llvm.org/D51223

Files:
  unittests/Tooling/DiagnosticsYamlTest.cpp
  unittests/Tooling/RefactoringActionRulesTest.cpp


Index: unittests/Tooling/RefactoringActionRulesTest.cpp
===
--- unittests/Tooling/RefactoringActionRulesTest.cpp
+++ unittests/Tooling/RefactoringActionRulesTest.cpp
@@ -117,8 +117,8 @@
  "Key: 'input.cpp:30'\n"
  "FilePath:input.cpp\n"
  "Error:   ''\n"
- "InsertedHeaders: \n"
- "RemovedHeaders:  \n"
+ "InsertedHeaders: []\n"
+ "RemovedHeaders:  []\n"
  "Replacements:\n" // Extra whitespace here!
  "  - FilePath:input.cpp\n"
  "Offset:  30\n"
Index: unittests/Tooling/DiagnosticsYamlTest.cpp
===
--- unittests/Tooling/DiagnosticsYamlTest.cpp
+++ unittests/Tooling/DiagnosticsYamlTest.cpp
@@ -82,7 +82,7 @@
 "Message: 'message #3'\n"
 "FileOffset:  72\n"
 "FilePath:path/to/source2.cpp\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n",
 YamlContentStream.str());
 }
@@ -113,7 +113,7 @@
 "Message: 'message #3'\n"
 "FileOffset:  98\n"
 "FilePath:path/to/source.cpp\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n";
   TranslationUnitDiagnostics TUDActual;
   yaml::Input YAML(YamlContent);


Index: unittests/Tooling/RefactoringActionRulesTest.cpp
===
--- unittests/Tooling/RefactoringActionRulesTest.cpp
+++ unittests/Tooling/RefactoringActionRulesTest.cpp
@@ -117,8 +117,8 @@
  "Key: 'input.cpp:30'\n"
  "FilePath:input.cpp\n"
  "Error:   ''\n"
- "InsertedHeaders: \n"
- "RemovedHeaders:  \n"
+ "InsertedHeaders: []\n"
+ "RemovedHeaders:  []\n"
  "Replacements:\n" // Extra whitespace here!
  "  - FilePath:input.cpp\n"
  "Offset:  30\n"
Index: unittests/Tooling/DiagnosticsYamlTest.cpp
===
--- unittests/Tooling/DiagnosticsYamlTest.cpp
+++ unittests/Tooling/DiagnosticsYamlTest.cpp
@@ -82,7 +82,7 @@
 "Message: 'message #3'\n"
 "FileOffset:  72\n"
 "FilePath:path/to/source2.cpp\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n",
 YamlContentStream.str());
 }
@@ -113,7 +113,7 @@
 "Message: 'message #3'\n"
 "FileOffset:  98\n"
 "FilePath:path/to/source.cpp\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n";
   TranslationUnitDiagnostics TUDActual;
   yaml::Input YAML(YamlContent);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51434: [HIP] Add -amdgpu-internalize-symbols option to opt

2018-08-29 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a reviewer: arsenm.
scott.linder added a comment.

+Matt to confirm, but our executable format is a shared object and we 
eventually want to support preemptible symbols through the PLT. We already 
generate GOT entries for globals.

Currently we work around the lack of PLT support by internalizing all 
non-kernel functions, so for now this patch is required.


https://reviews.llvm.org/D51434



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


[PATCH] D49930: [DebugInfo][OpenCL] Generate correct block literal debug info for OpenCL

2018-07-27 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added reviewers: Anastasia, echristo.
Herald added subscribers: cfe-commits, JDevlieghere, aprantl, yaxunl.

OpenCL block literal structs have different fields which are now correctly 
identified in the debug info.


Repository:
  rC Clang

https://reviews.llvm.org/D49930

Files:
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGenOpenCL/blocks.cl

Index: test/CodeGenOpenCL/blocks.cl
===
--- test/CodeGenOpenCL/blocks.cl
+++ test/CodeGenOpenCL/blocks.cl
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck -check-prefixes=COMMON,SPIR %s
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=COMMON,AMDGCN %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple spir-unknown-unknown | FileCheck -check-prefixes=COMMON,SPIR %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=COMMON,AMDGCN %s
 
 // COMMON: @__block_literal_global = internal addrspace(1) constant { i32, i32 } { i32 8, i32 4 }
 // COMMON-NOT: .str
@@ -60,3 +60,11 @@
 // AMDGCN:  %[[block_capture:.*]] = load i32, i32* %[[block_capture_addr]]
 
 // COMMON-NOT: define{{.*}}@__foo_block_invoke_kernel
+
+// COMMON: !DIDerivedType(tag: DW_TAG_member, name: "__size"
+// COMMON: !DIDerivedType(tag: DW_TAG_member, name: "__align"
+
+// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__isa"
+// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__flags"
+// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__reserved"
+// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__FuncPtr"
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -971,20 +971,25 @@
   auto *DescTy = DBuilder.createPointerType(EltTy, Size);
 
   FieldOffset = 0;
-  FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
-  EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
-  FType = CGM.getContext().IntTy;
-  EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
-  EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset));
-  FType = CGM.getContext().getPointerType(Ty->getPointeeType());
-  EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
-
-  FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
-  FieldSize = CGM.getContext().getTypeSize(Ty);
-  FieldAlign = CGM.getContext().getTypeAlign(Ty);
-  EltTys.push_back(DBuilder.createMemberType(
-  Unit, "__descriptor", nullptr, LineNo, FieldSize, FieldAlign, FieldOffset,
-  llvm::DINode::FlagZero, DescTy));
+  if (CGM.getLangOpts().OpenCL) {
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__align", &FieldOffset));
+  } else {
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset));
+FType = CGM.getContext().getPointerType(Ty->getPointeeType());
+EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+FieldSize = CGM.getContext().getTypeSize(Ty);
+FieldAlign = CGM.getContext().getTypeAlign(Ty);
+EltTys.push_back(DBuilder.createMemberType(
+Unit, "__descriptor", nullptr, LineNo, FieldSize, FieldAlign, FieldOffset,
+llvm::DINode::FlagZero, DescTy));
+  }
 
   FieldOffset += FieldSize;
   Elements = DBuilder.getOrCreateArray(EltTys);
@@ -3847,26 +3852,35 @@
   CGM.getDataLayout().getStructLayout(block.StructureType);
 
   SmallVector fields;
-  fields.push_back(createFieldType("__isa", C.VoidPtrTy, loc, AS_public,
-   blockLayout->getElementOffsetInBits(0),
-   tunit, tunit));
-  fields.push_back(createFieldType("__flags", C.IntTy, loc, AS_public,
-   blockLayout->getElementOffsetInBits(1),
-   tunit, tunit));
-  fields.push_back(createFieldType("__reserved", C.IntTy, loc, AS_public,
-   blockLayout->getElementOffsetInBits(2),
-   tunit, tunit));
-  auto *FnTy = block.getBlockExpr()->getFunctionType();
-  auto FnPtrType = CGM.getContext().getPointerType(FnTy->desugar());
-  fields.push_back(createFieldType("__FuncPtr", FnPtrType, loc, AS_publi

[PATCH] D49930: [DebugInfo][OpenCL] Generate correct block literal debug info for OpenCL

2018-07-30 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Thank you for taking a look @yaxunl. Should I wait for another reviewer or can 
I commit this?


Repository:
  rC Clang

https://reviews.llvm.org/D49930



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


[PATCH] D49930: [DebugInfo][OpenCL] Generate correct block literal debug info for OpenCL

2018-07-30 Thread Scott Linder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL338299: [DebugInfo][OpenCL] Generate correct block literal 
debug info for OpenCL (authored by scott.linder, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D49930?vs=157737&id=158060#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D49930

Files:
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/test/CodeGenOpenCL/blocks.cl

Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -971,20 +971,25 @@
   auto *DescTy = DBuilder.createPointerType(EltTy, Size);
 
   FieldOffset = 0;
-  FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
-  EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
-  FType = CGM.getContext().IntTy;
-  EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
-  EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset));
-  FType = CGM.getContext().getPointerType(Ty->getPointeeType());
-  EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
-
-  FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
-  FieldSize = CGM.getContext().getTypeSize(Ty);
-  FieldAlign = CGM.getContext().getTypeAlign(Ty);
-  EltTys.push_back(DBuilder.createMemberType(
-  Unit, "__descriptor", nullptr, LineNo, FieldSize, FieldAlign, FieldOffset,
-  llvm::DINode::FlagZero, DescTy));
+  if (CGM.getLangOpts().OpenCL) {
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__align", &FieldOffset));
+  } else {
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset));
+FType = CGM.getContext().getPointerType(Ty->getPointeeType());
+EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+FieldSize = CGM.getContext().getTypeSize(Ty);
+FieldAlign = CGM.getContext().getTypeAlign(Ty);
+EltTys.push_back(DBuilder.createMemberType(
+Unit, "__descriptor", nullptr, LineNo, FieldSize, FieldAlign, FieldOffset,
+llvm::DINode::FlagZero, DescTy));
+  }
 
   FieldOffset += FieldSize;
   Elements = DBuilder.getOrCreateArray(EltTys);
@@ -3847,26 +3852,35 @@
   CGM.getDataLayout().getStructLayout(block.StructureType);
 
   SmallVector fields;
-  fields.push_back(createFieldType("__isa", C.VoidPtrTy, loc, AS_public,
-   blockLayout->getElementOffsetInBits(0),
-   tunit, tunit));
-  fields.push_back(createFieldType("__flags", C.IntTy, loc, AS_public,
-   blockLayout->getElementOffsetInBits(1),
-   tunit, tunit));
-  fields.push_back(createFieldType("__reserved", C.IntTy, loc, AS_public,
-   blockLayout->getElementOffsetInBits(2),
-   tunit, tunit));
-  auto *FnTy = block.getBlockExpr()->getFunctionType();
-  auto FnPtrType = CGM.getContext().getPointerType(FnTy->desugar());
-  fields.push_back(createFieldType("__FuncPtr", FnPtrType, loc, AS_public,
-   blockLayout->getElementOffsetInBits(3),
-   tunit, tunit));
-  fields.push_back(createFieldType(
-  "__descriptor",
-  C.getPointerType(block.NeedsCopyDispose
-   ? C.getBlockDescriptorExtendedType()
-   : C.getBlockDescriptorType()),
-  loc, AS_public, blockLayout->getElementOffsetInBits(4), tunit, tunit));
+  if (CGM.getLangOpts().OpenCL) {
+fields.push_back(createFieldType("__size", C.IntTy, loc, AS_public,
+ blockLayout->getElementOffsetInBits(0),
+ tunit, tunit));
+fields.push_back(createFieldType("__align", C.IntTy, loc, AS_public,
+ blockLayout->getElementOffsetInBits(1),
+ tunit, tunit));
+  } else {
+fields.push_back(createFieldType("__isa", C.VoidPtrTy, loc, AS_public,
+ blockLayout->getElementOffsetInBits(0),
+ tunit, tunit));
+fields.push_back(createFieldType("__flags", C.IntTy, loc, AS_public,
+ blockLayout->getElementOffsetInBits(1),
+ 

[PATCH] D49930: [DebugInfo][OpenCL] Generate correct block literal debug info for OpenCL

2018-07-30 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Sorry, I didn't see the additional comments until after I committed. I will 
make those changes; is it OK to update this review, or should I create a new 
one?

As for choosing limited it was just what the function adding the debug info 
checked for as a minimum; what would you generally choose instead?


Repository:
  rL LLVM

https://reviews.llvm.org/D49930



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


[PATCH] D50099: [DebugInfo][OpenCL] Address post-commit review of D49930

2018-07-31 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added reviewers: echristo, Anastasia, yaxunl.
Herald added subscribers: cfe-commits, JDevlieghere, aprantl.

Refactor collection of member debug info into helper functions and add separate 
debug-info tests.

The reason for `-debug-info-kind=limited` in the tests is because they invoke 
`cc1`. I am just following the existing tests, but I can change this to just 
`clang` with `-g`.


Repository:
  rC Clang

https://reviews.llvm.org/D50099

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  test/CodeGenOpenCL/blocks.cl

Index: test/CodeGenOpenCL/blocks.cl
===
--- test/CodeGenOpenCL/blocks.cl
+++ test/CodeGenOpenCL/blocks.cl
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple spir-unknown-unknown | FileCheck -check-prefixes=COMMON,SPIR %s
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=COMMON,AMDGCN %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck -check-prefixes=COMMON,SPIR %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=COMMON,AMDGCN %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple spir-unknown-unknown | FileCheck -check-prefixes=CHECK-DEBUG %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=CHECK-DEBUG %s
 
 // COMMON: @__block_literal_global = internal addrspace(1) constant { i32, i32 } { i32 8, i32 4 }
 // COMMON-NOT: .str
@@ -61,10 +63,10 @@
 
 // COMMON-NOT: define{{.*}}@__foo_block_invoke_kernel
 
-// COMMON: !DIDerivedType(tag: DW_TAG_member, name: "__size"
-// COMMON: !DIDerivedType(tag: DW_TAG_member, name: "__align"
+// CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__size"
+// CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__align"
 
-// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__isa"
-// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__flags"
-// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__reserved"
-// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__FuncPtr"
+// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__isa"
+// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__flags"
+// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__reserved"
+// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__FuncPtr"
Index: lib/CodeGen/CGDebugInfo.h
===
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -311,6 +311,22 @@
   void AppendAddressSpaceXDeref(unsigned AddressSpace,
 SmallVectorImpl &Expr) const;
 
+  /// A helper function to collect debug info for the default elements of a
+  /// block.
+  ///
+  /// \returns The next available field offset after the default elements.
+  uint64_t collectDefaultElementTypesForBlockPointer(
+  const BlockPointerType *Ty, llvm::DIFile *Unit,
+  llvm::DIDerivedType *DescTy, unsigned LineNo,
+  SmallVectorImpl &EltTys);
+
+  /// A helper function to collect debug info for the default fields of a
+  /// block.
+  void collectDefaultFieldsForBlockLiteralDeclare(
+  const CGBlockInfo &Block, const ASTContext &Context, SourceLocation Loc,
+  const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
+  SmallVectorImpl &Fields);
+
 public:
   CGDebugInfo(CodeGenModule &CGM);
   ~CGDebugInfo();
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -942,12 +942,41 @@
   return Cache;
 }
 
+uint64_t CGDebugInfo::collectDefaultElementTypesForBlockPointer(
+const BlockPointerType *Ty, llvm::DIFile *Unit, llvm::DIDerivedType *DescTy,
+unsigned LineNo, SmallVectorImpl &EltTys) {
+  QualType FType;
+  uint64_t FieldOffset = 0;
+
+  if (CGM.getLangOpts().OpenCL) {
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__align", &FieldOffset));
+  } else {
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset));
+FType = CGM.getContext().getPointerType(Ty->getPointeeType());
+EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+  

[PATCH] D50104: [OpenCL] Always emit alloca in entry block for enqueue_kernel builtin

2018-07-31 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added reviewers: yaxunl, Anastasia, arsenm.
Herald added subscribers: cfe-commits, wdng.

Ensures the statically sized alloca is not converted to DYNAMIC_STACKALLOC 
later because it is not in the entry block.

I believe it is valid to insert the alloca in the entry block, but I'm not 
confident the way I accomplish it is correct.


Repository:
  rC Clang

https://reviews.llvm.org/D50104

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl


Index: test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -emit-llvm -o - -triple amdgcn | 
FileCheck %s --check-prefixes=COMMON,AMDGPU
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -emit-llvm -o - -triple 
"spir-unknown-unknown" | FileCheck %s --check-prefixes=COMMON,SPIR32
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -emit-llvm -o - -triple 
"spir64-unknown-unknown" | FileCheck %s --check-prefixes=COMMON,SPIR64
+
+typedef struct {int a;} ndrange_t;
+
+kernel void test(int i) {
+// COMMON-LABEL: define {{.*}} void @test
+// COMMON-LABEL: entry:
+// AMDGPU: alloca [1 x i64]
+// SPIR32: alloca [1 x i32]
+// SPIR64: alloca [1 x i64]
+// COMMON-LABEL: if.then:
+// COMMON-NOT: alloca
+// COMMON-LABEL: if.end
+  queue_t default_queue;
+  unsigned flags = 0;
+  ndrange_t ndrange;
+  if (i)
+enqueue_kernel(default_queue, flags, ndrange, ^(local void *a) { }, 32);
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -3339,7 +3339,16 @@
 // for the block. \p First is the position of the first size argument.
 auto CreateArrayForSizeVar = [=](unsigned First) {
   auto *AT = llvm::ArrayType::get(SizeTy, NumArgs - First);
+  // Always insert the alloca in the entry block so it remains static in
+  // the SelectionDAG.
+  BasicBlock *Begin = nullptr;
+  if (Instruction *Entry = CurFn->getEntryBlock().getTerminator()) {
+Begin = Builder.GetInsertBlock();
+Builder.SetInsertPoint(Entry);
+  }
   auto *Arr = Builder.CreateAlloca(AT);
+  if (Begin)
+Builder.SetInsertPoint(Begin);
   llvm::Value *Ptr;
   // Each of the following arguments specifies the size of the 
corresponding
   // argument passed to the enqueued block.


Index: test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -emit-llvm -o - -triple amdgcn | FileCheck %s --check-prefixes=COMMON,AMDGPU
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir-unknown-unknown" | FileCheck %s --check-prefixes=COMMON,SPIR32
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefixes=COMMON,SPIR64
+
+typedef struct {int a;} ndrange_t;
+
+kernel void test(int i) {
+// COMMON-LABEL: define {{.*}} void @test
+// COMMON-LABEL: entry:
+// AMDGPU: alloca [1 x i64]
+// SPIR32: alloca [1 x i32]
+// SPIR64: alloca [1 x i64]
+// COMMON-LABEL: if.then:
+// COMMON-NOT: alloca
+// COMMON-LABEL: if.end
+  queue_t default_queue;
+  unsigned flags = 0;
+  ndrange_t ndrange;
+  if (i)
+enqueue_kernel(default_queue, flags, ndrange, ^(local void *a) { }, 32);
+}
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -3339,7 +3339,16 @@
 // for the block. \p First is the position of the first size argument.
 auto CreateArrayForSizeVar = [=](unsigned First) {
   auto *AT = llvm::ArrayType::get(SizeTy, NumArgs - First);
+  // Always insert the alloca in the entry block so it remains static in
+  // the SelectionDAG.
+  BasicBlock *Begin = nullptr;
+  if (Instruction *Entry = CurFn->getEntryBlock().getTerminator()) {
+Begin = Builder.GetInsertBlock();
+Builder.SetInsertPoint(Entry);
+  }
   auto *Arr = Builder.CreateAlloca(AT);
+  if (Begin)
+Builder.SetInsertPoint(Begin);
   llvm::Value *Ptr;
   // Each of the following arguments specifies the size of the corresponding
   // argument passed to the enqueued block.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50099: [DebugInfo][OpenCL] Address post-commit review of D49930

2018-08-01 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 158532.
scott.linder added a comment.

Add comments to explain OpenCL case


https://reviews.llvm.org/D50099

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  test/CodeGenOpenCL/blocks.cl

Index: test/CodeGenOpenCL/blocks.cl
===
--- test/CodeGenOpenCL/blocks.cl
+++ test/CodeGenOpenCL/blocks.cl
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple spir-unknown-unknown | FileCheck -check-prefixes=COMMON,SPIR %s
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=COMMON,AMDGCN %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck -check-prefixes=COMMON,SPIR %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=COMMON,AMDGCN %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple spir-unknown-unknown | FileCheck -check-prefixes=CHECK-DEBUG %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -debug-info-kind=limited -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=CHECK-DEBUG %s
 
 // COMMON: @__block_literal_global = internal addrspace(1) constant { i32, i32 } { i32 8, i32 4 }
 // COMMON-NOT: .str
@@ -61,10 +63,10 @@
 
 // COMMON-NOT: define{{.*}}@__foo_block_invoke_kernel
 
-// COMMON: !DIDerivedType(tag: DW_TAG_member, name: "__size"
-// COMMON: !DIDerivedType(tag: DW_TAG_member, name: "__align"
+// CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__size"
+// CHECK-DEBUG: !DIDerivedType(tag: DW_TAG_member, name: "__align"
 
-// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__isa"
-// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__flags"
-// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__reserved"
-// COMMON-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__FuncPtr"
+// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__isa"
+// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__flags"
+// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__reserved"
+// CHECK-DEBUG-NOT: !DIDerivedType(tag: DW_TAG_member, name: "__FuncPtr"
Index: lib/CodeGen/CGDebugInfo.h
===
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -311,6 +311,22 @@
   void AppendAddressSpaceXDeref(unsigned AddressSpace,
 SmallVectorImpl &Expr) const;
 
+  /// A helper function to collect debug info for the default elements of a
+  /// block.
+  ///
+  /// \returns The next available field offset after the default elements.
+  uint64_t collectDefaultElementTypesForBlockPointer(
+  const BlockPointerType *Ty, llvm::DIFile *Unit,
+  llvm::DIDerivedType *DescTy, unsigned LineNo,
+  SmallVectorImpl &EltTys);
+
+  /// A helper function to collect debug info for the default fields of a
+  /// block.
+  void collectDefaultFieldsForBlockLiteralDeclare(
+  const CGBlockInfo &Block, const ASTContext &Context, SourceLocation Loc,
+  const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
+  SmallVectorImpl &Fields);
+
 public:
   CGDebugInfo(CodeGenModule &CGM);
   ~CGDebugInfo();
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -942,12 +942,47 @@
   return Cache;
 }
 
+uint64_t CGDebugInfo::collectDefaultElementTypesForBlockPointer(
+const BlockPointerType *Ty, llvm::DIFile *Unit, llvm::DIDerivedType *DescTy,
+unsigned LineNo, SmallVectorImpl &EltTys) {
+  QualType FType;
+
+  // Advanced by calls to CreateMemberType in increments of FType, then
+  // returned as the overall size of the default elements.
+  uint64_t FieldOffset = 0;
+
+  // Blocks in OpenCL have unique constraints which make the standard fields
+  // redundant while requiring size and align fields for enqueue_kernel. See
+  // initializeForBlockHeader in CGBlocks.cpp
+  if (CGM.getLangOpts().OpenCL) {
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__align", &FieldOffset));
+  } else {
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
+FType = CGM.getContext().IntTy;
+EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
+EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset));
+FType = CGM.getContext().getPointerType(Ty->getPointeeType());
+EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
+FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+

[PATCH] D50104: [OpenCL] Always emit alloca in entry block for enqueue_kernel builtin

2018-08-01 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 158545.
scott.linder added a comment.

Address feedback; I hope I understood correctly what debug info to check for.

I don't see where in CreateMemTemp and friends EmitLifetimeStart gets called, 
and I don't see any lifetime intrinsics in the IR even at -O1.


https://reviews.llvm.org/D50104

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl


Index: test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple amdgcn < %s | 
FileCheck %s --check-prefixes=COMMON,AMDGPU
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple 
"spir-unknown-unknown" < %s | FileCheck %s --check-prefixes=COMMON,SPIR32
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple 
"spir64-unknown-unknown" < %s | FileCheck %s --check-prefixes=COMMON,SPIR64
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -debug-info-kind=limited -emit-llvm -o - 
-triple amdgcn < %s | FileCheck %s --check-prefixes=CHECK-DEBUG
+
+// Check that the enqueue_kernel array temporary is in the entry block to avoid
+// a dynamic alloca
+
+typedef struct {int a;} ndrange_t;
+
+kernel void test(int i) {
+// COMMON-LABEL: define {{.*}} void @test
+// COMMON-LABEL: entry:
+// AMDGPU: %block_sizes = alloca [1 x i64]
+// SPIR32: %block_sizes = alloca [1 x i32]
+// SPIR64: %block_sizes = alloca [1 x i64]
+// COMMON-LABEL: if.then:
+// COMMON-NOT: alloca
+// CHECK-DEBUG: getelementptr {{.*}} %block_sizes, {{.*}} !dbg !34
+// COMMON-LABEL: if.end
+  queue_t default_queue;
+  unsigned flags = 0;
+  ndrange_t ndrange;
+  if (i)
+enqueue_kernel(default_queue, flags, ndrange, ^(local void *a) { }, 32);
+}
+
+// Check that the temporary is scoped to the `if`
+
+// CHECK-DEBUG: !32 = distinct !DILexicalBlock(scope: !7, file: !1, line: 24)
+// CHECK-DEBUG: !34 = !DILocation(line: 25, scope: !32)
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -3338,15 +3338,18 @@
 // Create a temporary array to hold the sizes of local pointer arguments
 // for the block. \p First is the position of the first size argument.
 auto CreateArrayForSizeVar = [=](unsigned First) {
-  auto *AT = llvm::ArrayType::get(SizeTy, NumArgs - First);
-  auto *Arr = Builder.CreateAlloca(AT);
+  llvm::APInt ArraySize(32, NumArgs - First);
+  QualType SizeArrayTy = getContext().getConstantArrayType(
+  getContext().getSizeType(), ArraySize, ArrayType::Normal,
+  /*IndexTypeQuals=*/0);
+  auto Tmp = CreateMemTemp(SizeArrayTy, "block_sizes");
   llvm::Value *Ptr;
   // Each of the following arguments specifies the size of the 
corresponding
   // argument passed to the enqueued block.
   auto *Zero = llvm::ConstantInt::get(IntTy, 0);
   for (unsigned I = First; I < NumArgs; ++I) {
 auto *Index = llvm::ConstantInt::get(IntTy, I - First);
-auto *GEP = Builder.CreateGEP(Arr, {Zero, Index});
+auto *GEP = Builder.CreateGEP(Tmp.getPointer(), {Zero, Index});
 if (I == First)
   Ptr = GEP;
 auto *V =


Index: test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple amdgcn < %s | FileCheck %s --check-prefixes=COMMON,AMDGPU
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir-unknown-unknown" < %s | FileCheck %s --check-prefixes=COMMON,SPIR32
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir64-unknown-unknown" < %s | FileCheck %s --check-prefixes=COMMON,SPIR64
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -debug-info-kind=limited -emit-llvm -o - -triple amdgcn < %s | FileCheck %s --check-prefixes=CHECK-DEBUG
+
+// Check that the enqueue_kernel array temporary is in the entry block to avoid
+// a dynamic alloca
+
+typedef struct {int a;} ndrange_t;
+
+kernel void test(int i) {
+// COMMON-LABEL: define {{.*}} void @test
+// COMMON-LABEL: entry:
+// AMDGPU: %block_sizes = alloca [1 x i64]
+// SPIR32: %block_sizes = alloca [1 x i32]
+// SPIR64: %block_sizes = alloca [1 x i64]
+// COMMON-LABEL: if.then:
+// COMMON-NOT: alloca
+// CHECK-DEBUG: getelementptr {{.*}} %block_sizes, {{.*}} !dbg !34
+// COMMON-LABEL: if.end
+  queue_t default_queue;
+  unsigned flags = 0;
+  ndrange_t ndrange;
+  if (i)
+enqueue_kernel(default_queue, flags, ndrange, ^(local void *a) { }, 32);
+}
+
+// Check that the temporary is scoped to the `if`
+
+// CHECK-DEBUG: !32 = distinct !DILexicalBlock(scope: !7, file: !1, line: 24)
+// CHECK-DEBUG: !34 = !DILocation(line: 25, scope: !32)
Index: lib/

[PATCH] D50104: [OpenCL] Always emit alloca in entry block for enqueue_kernel builtin

2018-08-01 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 158618.
scott.linder added a comment.

Update test


https://reviews.llvm.org/D50104

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl

Index: test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple amdgcn < %s | FileCheck %s --check-prefixes=COMMON,AMDGPU
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir-unknown-unknown" < %s | FileCheck %s --check-prefixes=COMMON,SPIR32
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir64-unknown-unknown" < %s | FileCheck %s --check-prefixes=COMMON,SPIR64
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -debug-info-kind=limited -emit-llvm -o - -triple amdgcn < %s | FileCheck %s --check-prefixes=CHECK-DEBUG
+
+// Check that the enqueue_kernel array temporary is in the entry block to avoid
+// a dynamic alloca
+
+typedef struct {int a;} ndrange_t;
+
+kernel void test(int i) {
+// COMMON-LABEL: define {{.*}} void @test
+// COMMON-LABEL: entry:
+// AMDGPU: %block_sizes = alloca [1 x i64]
+// SPIR32: %block_sizes = alloca [1 x i32]
+// SPIR64: %block_sizes = alloca [1 x i64]
+// COMMON-LABEL: if.then:
+// COMMON-NOT: alloca
+// CHECK-DEBUG: getelementptr {{.*}} %block_sizes, {{.*}} !dbg !34
+// COMMON-LABEL: if.end
+  queue_t default_queue;
+  unsigned flags = 0;
+  ndrange_t ndrange;
+  if (i)
+enqueue_kernel(default_queue, flags, ndrange, ^(local void *a) { }, 32);
+}
+
+// Check that the temporary is scoped to the `if`
+
+// CHECK-DEBUG: !32 = distinct !DILexicalBlock(scope: !7, file: !1, line: 24)
+// CHECK-DEBUG: !34 = !DILocation(line: 25, scope: !32)
Index: test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -46,8 +46,24 @@
   // COMMON: %event_wait_list2 = alloca [1 x %opencl.clk_event_t*]
   clk_event_t event_wait_list2[] = {clk_event};
 
-  // Emits block literal on stack and block kernel [[INVLK1]].
   // COMMON: [[NDR:%[a-z0-9]+]] = alloca %struct.ndrange_t, align 4
+
+  // B32: %[[BLOCK_SIZES1:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES1:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES2:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES2:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES3:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES3:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES4:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES4:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES5:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES5:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES6:.*]] = alloca [3 x i32]
+  // B64: %[[BLOCK_SIZES6:.*]] = alloca [3 x i64]
+  // B32: %[[BLOCK_SIZES7:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES7:.*]] = alloca [1 x i64]
+
+  // Emits block literal on stack and block kernel [[INVLK1]].
   // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue
   // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
   // B32: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block to void ()*
@@ -73,48 +89,44 @@
   // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]],  %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t{{.*}}* addrspace(4)* [[WAIT_EVNT]], %opencl.clk_event_t{{.*}}* addrspace(4)* [[EVNT]],
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVLK2:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* [[BL_I8]])
-
   enqueue_kernel(default_queue, flags, ndrange, 2, &event_wait_list, &clk_event,
  ^(void) {
a[i] = b[i];
  });
 
   // Emits global block literal [[BLG1]] and block kernel [[INVGK1]].
   // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue
   // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
-  // B32: %[[TMP:.*]] = alloca [1 x i32]
-  // B32: %[[TMP1:.*]] = getelementptr [1 x i32], [1 x i32]* %[[TMP]], i32 0, i32 0
-  // B32: store i32 256, i32* %[[TMP1]], align 4
-  // B64: %[[TMP:.*]] = alloca [1 x i64]
-  // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, i32 0
-  // B64: store i64 256, i64* %[[TMP1]], align 8
+  // B32: %[[TMP:.*]] = getelementptr [1 x i32], [1 x i32]* %[[BLOCK_SIZES1]], i32 0, i32 0
+  // B32: store i32 256, i32* %[[TMP]], align 4
+  // B64: %[[TMP:.*]] = getelementptr [1 x i64], [1 x i64]* %[[BLOCK_SIZES1]], i32 0, i32 0
+  // B64: store i64 256, i64* %[[TMP]], align 8
   // COMMON-LABEL: call i32 @__enqueue_kernel_varargs(
   // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]]

[PATCH] D50104: [OpenCL] Always emit alloca in entry block for enqueue_kernel builtin

2018-08-02 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

I still don't quite see what you describe; with that change all of the 
lifetime.end calls pile up just before the enclosing function returns, not 
after each call to enqueue_kernel. Looking at 
https://clang.llvm.org/doxygen/EHScopeStack_8h_source.html#l00078 I don't see 
any option which isn't based on scope. The lifetime.start calls do occur where 
I would expect, though, so I will update the patch.


https://reviews.llvm.org/D50104



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


[PATCH] D50104: [OpenCL] Always emit alloca in entry block for enqueue_kernel builtin

2018-08-02 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 158816.
scott.linder added a comment.

Emit lifetime intrinsics for the sizes temp, and update test


https://reviews.llvm.org/D50104

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl

Index: test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple amdgcn < %s | FileCheck %s --check-prefixes=COMMON,AMDGPU
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir-unknown-unknown" < %s | FileCheck %s --check-prefixes=COMMON,SPIR32
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir64-unknown-unknown" < %s | FileCheck %s --check-prefixes=COMMON,SPIR64
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -debug-info-kind=limited -emit-llvm -o - -triple amdgcn < %s | FileCheck %s --check-prefixes=CHECK-DEBUG
+
+// Check that the enqueue_kernel array temporary is in the entry block to avoid
+// a dynamic alloca
+
+typedef struct {int a;} ndrange_t;
+
+kernel void test(int i) {
+// COMMON-LABEL: define {{.*}} void @test
+// COMMON-LABEL: entry:
+// AMDGPU: %block_sizes = alloca [1 x i64]
+// SPIR32: %block_sizes = alloca [1 x i32]
+// SPIR64: %block_sizes = alloca [1 x i64]
+// COMMON-LABEL: if.then:
+// COMMON-NOT: alloca
+// CHECK-DEBUG: getelementptr {{.*}} %block_sizes, {{.*}} !dbg !34
+// COMMON-LABEL: if.end
+  queue_t default_queue;
+  unsigned flags = 0;
+  ndrange_t ndrange;
+  if (i)
+enqueue_kernel(default_queue, flags, ndrange, ^(local void *a) { }, 32);
+}
+
+// Check that the temporary is scoped to the `if`
+
+// CHECK-DEBUG: !32 = distinct !DILexicalBlock(scope: !7, file: !1, line: 24)
+// CHECK-DEBUG: !34 = !DILocation(line: 25, scope: !32)
Index: test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o - -triple "spir-unknown-unknown" | FileCheck %s --check-prefix=COMMON --check-prefix=B32
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefix=COMMON --check-prefix=B64
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O1 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefix=CHECK-LIFETIMES
 
 #pragma OPENCL EXTENSION cl_khr_subgroups : enable
 
@@ -46,8 +47,31 @@
   // COMMON: %event_wait_list2 = alloca [1 x %opencl.clk_event_t*]
   clk_event_t event_wait_list2[] = {clk_event};
 
-  // Emits block literal on stack and block kernel [[INVLK1]].
   // COMMON: [[NDR:%[a-z0-9]+]] = alloca %struct.ndrange_t, align 4
+
+  // B32: %[[BLOCK_SIZES1:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES1:.*]] = alloca [1 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES1:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES2:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES2:.*]] = alloca [1 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES2:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES3:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES3:.*]] = alloca [1 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES3:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES4:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES4:.*]] = alloca [1 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES4:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES5:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES5:.*]] = alloca [1 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES5:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES6:.*]] = alloca [3 x i32]
+  // B64: %[[BLOCK_SIZES6:.*]] = alloca [3 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES6:.*]] = alloca [3 x i64]
+  // B32: %[[BLOCK_SIZES7:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES7:.*]] = alloca [1 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES7:.*]] = alloca [1 x i64]
+
+  // Emits block literal on stack and block kernel [[INVLK1]].
   // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue
   // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
   // B32: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block to void ()*
@@ -73,48 +97,54 @@
   // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]],  %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t{{.*}}* addrspace(4)* [[WAIT_EVNT]], %opencl.clk_event_t{{.*}}* addrspace(4)* [[EVNT]],
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVLK2:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* [[BL_I8]])
-
   enqueue_kernel(default_queue, flags, ndrange, 2, &event_wait_list, &clk_event,
   

[PATCH] D50104: [OpenCL] Always emit alloca in entry block for enqueue_kernel builtin

2018-08-03 Thread Scott Linder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL338899: [OpenCL] Always emit alloca in entry block for 
enqueue_kernel builtin (authored by scott.linder, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50104?vs=158816&id=159021#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50104

Files:
  cfe/trunk/lib/CodeGen/CGBuiltin.cpp
  cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  cfe/trunk/test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl

Index: cfe/trunk/test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
===
--- cfe/trunk/test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
+++ cfe/trunk/test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple amdgcn < %s | FileCheck %s --check-prefixes=COMMON,AMDGPU
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir-unknown-unknown" < %s | FileCheck %s --check-prefixes=COMMON,SPIR32
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -emit-llvm -o - -triple "spir64-unknown-unknown" < %s | FileCheck %s --check-prefixes=COMMON,SPIR64
+// RUN: %clang_cc1 -cl-std=CL2.0 -O0 -debug-info-kind=limited -emit-llvm -o - -triple amdgcn < %s | FileCheck %s --check-prefixes=CHECK-DEBUG
+
+// Check that the enqueue_kernel array temporary is in the entry block to avoid
+// a dynamic alloca
+
+typedef struct {int a;} ndrange_t;
+
+kernel void test(int i) {
+// COMMON-LABEL: define {{.*}} void @test
+// COMMON-LABEL: entry:
+// AMDGPU: %block_sizes = alloca [1 x i64]
+// SPIR32: %block_sizes = alloca [1 x i32]
+// SPIR64: %block_sizes = alloca [1 x i64]
+// COMMON-LABEL: if.then:
+// COMMON-NOT: alloca
+// CHECK-DEBUG: getelementptr {{.*}} %block_sizes, {{.*}} !dbg !34
+// COMMON-LABEL: if.end
+  queue_t default_queue;
+  unsigned flags = 0;
+  ndrange_t ndrange;
+  if (i)
+enqueue_kernel(default_queue, flags, ndrange, ^(local void *a) { }, 32);
+}
+
+// Check that the temporary is scoped to the `if`
+
+// CHECK-DEBUG: !32 = distinct !DILexicalBlock(scope: !7, file: !1, line: 24)
+// CHECK-DEBUG: !34 = !DILocation(line: 25, scope: !32)
Index: cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o - -triple "spir-unknown-unknown" | FileCheck %s --check-prefix=COMMON --check-prefix=B32
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefix=COMMON --check-prefix=B64
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O1 -emit-llvm -o - -triple "spir64-unknown-unknown" | FileCheck %s --check-prefix=CHECK-LIFETIMES
 
 #pragma OPENCL EXTENSION cl_khr_subgroups : enable
 
@@ -46,8 +47,31 @@
   // COMMON: %event_wait_list2 = alloca [1 x %opencl.clk_event_t*]
   clk_event_t event_wait_list2[] = {clk_event};
 
-  // Emits block literal on stack and block kernel [[INVLK1]].
   // COMMON: [[NDR:%[a-z0-9]+]] = alloca %struct.ndrange_t, align 4
+
+  // B32: %[[BLOCK_SIZES1:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES1:.*]] = alloca [1 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES1:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES2:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES2:.*]] = alloca [1 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES2:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES3:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES3:.*]] = alloca [1 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES3:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES4:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES4:.*]] = alloca [1 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES4:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES5:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES5:.*]] = alloca [1 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES5:.*]] = alloca [1 x i64]
+  // B32: %[[BLOCK_SIZES6:.*]] = alloca [3 x i32]
+  // B64: %[[BLOCK_SIZES6:.*]] = alloca [3 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES6:.*]] = alloca [3 x i64]
+  // B32: %[[BLOCK_SIZES7:.*]] = alloca [1 x i32]
+  // B64: %[[BLOCK_SIZES7:.*]] = alloca [1 x i64]
+  // CHECK-LIFETIMES: %[[BLOCK_SIZES7:.*]] = alloca [1 x i64]
+
+  // Emits block literal on stack and block kernel [[INVLK1]].
   // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue
   // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
   // B32: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block to void ()*
@@ -73,48 +97,54 @@
   // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]],  %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t{{.

[PATCH] D43044: [DebugInfo] Update Checksum handling in CGDebugInfo

2018-02-07 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added reviewers: aprantl, JDevlieghere.
Herald added a subscriber: cfe-commits.
scott.linder added a dependency: D43043: [DebugInfo] Unify ChecksumKind and 
Checksum value in DIFile.

Update to match new DIFile API.


Repository:
  rC Clang

https://reviews.llvm.org/D43044

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h

Index: lib/CodeGen/CGDebugInfo.h
===
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -499,8 +499,8 @@
   std::string remapDIPath(StringRef) const;
 
   /// Compute the file checksum debug info for input file ID.
-  llvm::DIFile::ChecksumKind computeChecksum(FileID FID,
- SmallString<32> &Checksum) const;
+  Optional
+  computeChecksum(FileID FID, SmallString<32> &Checksum) const;
 
   /// Get the file debug info descriptor for the input location.
   llvm::DIFile *getOrCreateFile(SourceLocation Loc);
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -361,19 +361,19 @@
   return StringRef();
 }
 
-llvm::DIFile::ChecksumKind
+Optional
 CGDebugInfo::computeChecksum(FileID FID, SmallString<32> &Checksum) const {
   Checksum.clear();
 
   if (!CGM.getCodeGenOpts().EmitCodeView &&
   CGM.getCodeGenOpts().DwarfVersion < 5)
-return llvm::DIFile::CSK_None;
+return None;
 
   SourceManager &SM = CGM.getContext().getSourceManager();
   bool Invalid;
   llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, &Invalid);
   if (Invalid)
-return llvm::DIFile::CSK_None;
+return None;
 
   llvm::MD5 Hash;
   llvm::MD5::MD5Result Result;
@@ -390,7 +390,6 @@
 // If Location is not valid then use main input file.
 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
remapDIPath(TheCU->getDirectory()),
-   TheCU->getFile()->getChecksumKind(),
TheCU->getFile()->getChecksum());
 
   SourceManager &SM = CGM.getContext().getSourceManager();
@@ -400,7 +399,6 @@
 // If the location is not valid then use main input file.
 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
remapDIPath(TheCU->getDirectory()),
-   TheCU->getFile()->getChecksumKind(),
TheCU->getFile()->getChecksum());
 
   // Cache the results.
@@ -414,21 +412,23 @@
   }
 
   SmallString<32> Checksum;
-  llvm::DIFile::ChecksumKind CSKind =
+  Optional CSKind =
   computeChecksum(SM.getFileID(Loc), Checksum);
+  Optional> CSInfo;
+  if (CSKind)
+CSInfo.emplace(*CSKind, Checksum);
 
   llvm::DIFile *F = DBuilder.createFile(remapDIPath(PLoc.getFilename()),
 remapDIPath(getCurrentDirname()),
-CSKind, Checksum);
+CSInfo);
 
   DIFileCache[fname].reset(F);
   return F;
 }
 
 llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
   return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
  remapDIPath(TheCU->getDirectory()),
- TheCU->getFile()->getChecksumKind(),
  TheCU->getFile()->getChecksum());
 }
 
@@ -473,7 +473,8 @@
 
 void CGDebugInfo::CreateCompileUnit() {
   SmallString<32> Checksum;
-  llvm::DIFile::ChecksumKind CSKind = llvm::DIFile::CSK_None;
+  Optional CSKind;
+  Optional> CSInfo;
 
   // Should we be asking the SourceManager for the main file name, instead of
   // accepting it as an argument? This just causes the main file name to
@@ -552,13 +553,16 @@
 break;
   }
 
+  if (CSKind)
+CSInfo.emplace(*CSKind, Checksum);
+
   // Create new compile unit.
   // FIXME - Eliminate TheCU.
   auto &CGOpts = CGM.getCodeGenOpts();
   TheCU = DBuilder.createCompileUnit(
   LangTag,
   DBuilder.createFile(remapDIPath(MainFileName),
-  remapDIPath(getCurrentDirname()), CSKind, Checksum),
+  remapDIPath(getCurrentDirname()), CSInfo),
   Producer, LO.Optimize || CGOpts.PrepareForLTO || CGOpts.EmitSummaryIndex,
   CGOpts.DwarfDebugFlags, RuntimeVers,
   CGOpts.EnableSplitDwarf ? "" : CGOpts.SplitDwarfFile, EmissionKind,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43044: [DebugInfo] Update Checksum handling in CGDebugInfo

2018-02-12 Thread Scott Linder via Phabricator via cfe-commits
scott.linder closed this revision.
scott.linder added a comment.

Closed by https://reviews.llvm.org/rC324929


Repository:
  rC Clang

https://reviews.llvm.org/D43044



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


[PATCH] D42766: [DebugInfo] Support DWARFv5 source code embedding extension

2018-02-23 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

With https://reviews.llvm.org/D42765 committed I think this is ready for review.


Repository:
  rC Clang

https://reviews.llvm.org/D42766



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


[PATCH] D42766: [DebugInfo] Support DWARFv5 source code embedding extension

2018-02-26 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 135909.
scott.linder added a comment.

New diff addresses feedback. I committed the refactoring as NFC and rebased, 
then clarified the extension comment.


https://reviews.llvm.org/D42766

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/Driver/ToolChains/AMDGPU.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/debug-info-embed-source.c
  test/CodeGen/debug-info-embed-source.c
  test/Driver/amdgpu-toolchain.c
  test/Driver/debug-options.c

Index: test/Driver/debug-options.c
===
--- test/Driver/debug-options.c
+++ test/Driver/debug-options.c
@@ -245,3 +245,13 @@
 // RUN: %clang -###  %s 2>&1 | FileCheck -check-prefix=NOMACRO %s
 // MACRO: "-debug-info-macro"
 // NOMACRO-NOT: "-debug-info-macro"
+//
+// RUN: %clang -### -gdwarf-5 -gembed-source %s 2>&1 | FileCheck -check-prefix=GEMBED_5 %s
+// RUN: %clang -### -gdwarf-2 -gembed-source %s 2>&1 | FileCheck -check-prefix=GEMBED_2 %s
+// RUN: %clang -### -gdwarf-5 -gno-embed-source %s 2>&1 | FileCheck -check-prefix=NOGEMBED_5 %s
+// RUN: %clang -### -gdwarf-2 -gno-embed-source %s 2>&1 | FileCheck -check-prefix=NOGEMBED_2 %s
+//
+// GEMBED_5:  "-gembed-source"
+// GEMBED_2:  error: invalid argument '-gembed-source' only allowed with '-gdwarf-5'
+// NOGEMBED_5-NOT:  "-gembed-source"
+// NOGEMBED_2-NOT:  error: invalid argument '-gembed-source' only allowed with '-gdwarf-5'
Index: test/Driver/amdgpu-toolchain.c
===
--- test/Driver/amdgpu-toolchain.c
+++ test/Driver/amdgpu-toolchain.c
@@ -3,4 +3,4 @@
 // AS_LINK: ld.lld{{.*}} "-shared"
 
 // RUN: %clang -### -g -target amdgcn--amdhsa -mcpu=kaveri %s 2>&1 | FileCheck -check-prefix=DWARF_VER %s
-// DWARF_VER: "-dwarf-version=2"
+// DWARF_VER: "-dwarf-version=5"
Index: test/CodeGen/debug-info-embed-source.c
===
--- /dev/null
+++ test/CodeGen/debug-info-embed-source.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1-debug-info-kind=limited -emit-llvm %p/Inputs/debug-info-embed-source.c -o - | FileCheck %s --check-prefix=NOEMBED
+// RUN: %clang_cc1 -gembed-source -debug-info-kind=limited -emit-llvm %p/Inputs/debug-info-embed-source.c -o - | FileCheck %s --check-prefix=EMBED
+
+// NOEMBED-NOT: !DIFile({{.*}}source:
+// EMBED: !DIFile({{.*}}source: "void foo() { }\0A"
Index: test/CodeGen/Inputs/debug-info-embed-source.c
===
--- /dev/null
+++ test/CodeGen/Inputs/debug-info-embed-source.c
@@ -0,0 +1 @@
+void foo() { }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -545,6 +545,7 @@
   Opts.DebugTypeExtRefs = Args.hasArg(OPT_dwarf_ext_refs);
   Opts.DebugExplicitImport = Args.hasArg(OPT_dwarf_explicit_import);
   Opts.DebugFwdTemplateParams = Args.hasArg(OPT_debug_forward_template_params);
+  Opts.EmbedSource = Args.hasArg(OPT_gembed_source);
 
   for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ))
 Opts.DebugPrefixMap.insert(StringRef(Arg).split('='));
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3024,6 +3024,18 @@
   if (DebugInfoKind == codegenoptions::LimitedDebugInfo && NeedFullDebug)
 DebugInfoKind = codegenoptions::FullDebugInfo;
 
+  if (Args.hasFlag(options::OPT_gembed_source, options::OPT_gno_embed_source, false)) {
+// Source embedding is a vendor extension to DWARF v5. By now we have
+// checked if a DWARF version was stated explicitly, and have otherwise
+// fallen back to the target default, so if this is still not at least 5 we
+// emit an error.
+if (DWARFVersion < 5)
+  D.Diag(diag::err_drv_argument_only_allowed_with)
+  << Args.getLastArg(options::OPT_gembed_source)->getAsString(Args)
+  << "-gdwarf-5";
+CmdArgs.push_back("-gembed-source");
+  }
+
   RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, DWARFVersion,
   DebuggerTuning);
 
Index: lib/Driver/ToolChains/AMDGPU.h
===
--- lib/Driver/ToolChains/AMDGPU.h
+++ lib/Driver/ToolChains/AMDGPU.h
@@ -56,7 +56,7 @@
 public:
   AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args);
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
   bool IsIntegratedAssemblerDefault() const override { return t

[PATCH] D42766: [DebugInfo] Support DWARFv5 source code embedding extension

2018-02-26 Thread Scott Linder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326102: [DebugInfo] Support DWARF v5 source code embedding 
extension (authored by scott.linder, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42766?vs=135909&id=135918#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42766

Files:
  cfe/trunk/docs/ClangCommandLineReference.rst
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Frontend/CodeGenOptions.def
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.h
  cfe/trunk/lib/Driver/ToolChains/AMDGPU.h
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/Inputs/debug-info-embed-source.c
  cfe/trunk/test/CodeGen/debug-info-embed-source.c
  cfe/trunk/test/Driver/amdgpu-toolchain.c
  cfe/trunk/test/Driver/debug-options.c

Index: cfe/trunk/test/CodeGen/Inputs/debug-info-embed-source.c
===
--- cfe/trunk/test/CodeGen/Inputs/debug-info-embed-source.c
+++ cfe/trunk/test/CodeGen/Inputs/debug-info-embed-source.c
@@ -0,0 +1 @@
+void foo() { }
Index: cfe/trunk/test/CodeGen/debug-info-embed-source.c
===
--- cfe/trunk/test/CodeGen/debug-info-embed-source.c
+++ cfe/trunk/test/CodeGen/debug-info-embed-source.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1-debug-info-kind=limited -emit-llvm %p/Inputs/debug-info-embed-source.c -o - | FileCheck %s --check-prefix=NOEMBED
+// RUN: %clang_cc1 -gembed-source -debug-info-kind=limited -emit-llvm %p/Inputs/debug-info-embed-source.c -o - | FileCheck %s --check-prefix=EMBED
+
+// NOEMBED-NOT: !DIFile({{.*}}source:
+// EMBED: !DIFile({{.*}}source: "void foo() { }\0A"
Index: cfe/trunk/test/Driver/debug-options.c
===
--- cfe/trunk/test/Driver/debug-options.c
+++ cfe/trunk/test/Driver/debug-options.c
@@ -245,3 +245,13 @@
 // RUN: %clang -###  %s 2>&1 | FileCheck -check-prefix=NOMACRO %s
 // MACRO: "-debug-info-macro"
 // NOMACRO-NOT: "-debug-info-macro"
+//
+// RUN: %clang -### -gdwarf-5 -gembed-source %s 2>&1 | FileCheck -check-prefix=GEMBED_5 %s
+// RUN: %clang -### -gdwarf-2 -gembed-source %s 2>&1 | FileCheck -check-prefix=GEMBED_2 %s
+// RUN: %clang -### -gdwarf-5 -gno-embed-source %s 2>&1 | FileCheck -check-prefix=NOGEMBED_5 %s
+// RUN: %clang -### -gdwarf-2 -gno-embed-source %s 2>&1 | FileCheck -check-prefix=NOGEMBED_2 %s
+//
+// GEMBED_5:  "-gembed-source"
+// GEMBED_2:  error: invalid argument '-gembed-source' only allowed with '-gdwarf-5'
+// NOGEMBED_5-NOT:  "-gembed-source"
+// NOGEMBED_2-NOT:  error: invalid argument '-gembed-source' only allowed with '-gdwarf-5'
Index: cfe/trunk/test/Driver/amdgpu-toolchain.c
===
--- cfe/trunk/test/Driver/amdgpu-toolchain.c
+++ cfe/trunk/test/Driver/amdgpu-toolchain.c
@@ -3,4 +3,4 @@
 // AS_LINK: ld.lld{{.*}} "-shared"
 
 // RUN: %clang -### -g -target amdgcn--amdhsa -mcpu=kaveri %s 2>&1 | FileCheck -check-prefix=DWARF_VER %s
-// DWARF_VER: "-dwarf-version=2"
+// DWARF_VER: "-dwarf-version=5"
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.h
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h
@@ -502,6 +502,9 @@
   Optional
   computeChecksum(FileID FID, SmallString<32> &Checksum) const;
 
+  /// Get the source of the given file ID.
+  Optional getSource(const SourceManager &SM, FileID FID);
+
   /// Get the file debug info descriptor for the input location.
   llvm::DIFile *getOrCreateFile(SourceLocation Loc);
 
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -385,6 +385,19 @@
   return llvm::DIFile::CSK_MD5;
 }
 
+Optional CGDebugInfo::getSource(const SourceManager &SM, FileID FID) {
+  if (!CGM.getCodeGenOpts().EmbedSource)
+return None;
+
+  bool SourceInvalid = false;
+  StringRef Source = SM.getBufferData(FID, &SourceInvalid);
+
+  if (SourceInvalid)
+return None;
+
+  return Source;
+}
+
 llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
   if (!Loc.isValid())
 // If Location is not valid then use main input file.
@@ -416,16 +429,19 @@
 
   llvm::DIFile *F = DBuilder.createFile(remapDIPath(PLoc.getFilename()),
 remapDIPath(getCurrentDirname()),
-CSInfo);
+CSInfo,
+getSource(SM, SM.getFileID(Loc)));
 
   DIFileCache[fname].reset(F);
   return F;
 }
 
 llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
-  return DBuilder.createFile

[PATCH] D53153: [OpenCL] Mark namespace scope variables and kernel functions with default visibility

2018-10-11 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added reviewers: yaxunl, arsenm, kzhuravl, Anastasia.
Herald added subscribers: cfe-commits, wdng.

The rationale for this is that OpenCL provides programmatic access to these 
symbols, but not to e.g. non-kernel functions. These symbols should have 
default visibility even when e.g. `-fvisibility hidden` is present.

This is an alternative approach to achieving the same goals as 
https://reviews.llvm.org/D52891


Repository:
  rC Clang

https://reviews.llvm.org/D53153

Files:
  lib/AST/Decl.cpp
  test/CodeGenOpenCL/visibility.cl


Index: test/CodeGenOpenCL/visibility.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/visibility.cl
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fvisibility default -triple amdgcn-unknown-unknown -S 
-emit-llvm -o - %s | FileCheck --check-prefix=FVIS-DEFAULT %s
+// RUN: %clang_cc1 -fvisibility protected -triple amdgcn-unknown-unknown -S 
-emit-llvm -o - %s | FileCheck --check-prefix=FVIS-PROTECTED %s
+// RUN: %clang_cc1 -fvisibility hidden -triple amdgcn-unknown-unknown -S 
-emit-llvm -o - %s | FileCheck --check-prefix=FVIS-HIDDEN %s
+
+// REQUIRES: amdgpu-registered-target
+
+// FVIS-DEFAULT: @globl = local_unnamed_addr
+// FVIS-PROTECTED: @globl = local_unnamed_addr
+// FVIS-HIDDEN: @globl = local_unnamed_addr
+__constant int globl = 0;
+// FVIS-DEFAULT: @default_globl = local_unnamed_addr
+// FVIS-PROTECTED: @default_globl = local_unnamed_addr
+// FVIS-HIDDEN: @default_globl = local_unnamed_addr
+__attribute__((visibility("default"))) __constant int default_globl = 0;
+// FVIS-DEFAULT: @protected_globl = protected local_unnamed_addr
+// FVIS-PROTECTED: @protected_globl = protected local_unnamed_addr
+// FVIS-HIDDEN: @protected_globl = protected local_unnamed_addr
+__attribute__((visibility("protected"))) __constant int protected_globl = 0;
+// FVIS-DEFAULT: @hidden_globl = hidden local_unnamed_addr
+// FVIS-PROTECTED: @hidden_globl = hidden local_unnamed_addr
+// FVIS-HIDDEN: @hidden_globl = hidden local_unnamed_addr
+__attribute__((visibility("hidden"))) __constant int hidden_globl = 0;
+
+// FVIS-DEFAULT: define amdgpu_kernel void @kern()
+// FVIS-PROTECTED: define amdgpu_kernel void @kern()
+// FVIS-HIDDEN: define amdgpu_kernel void @kern()
+kernel void kern() {}
+// FVIS-DEFAULT: define amdgpu_kernel void @default_kern()
+// FVIS-PROTECTED: define amdgpu_kernel void @default_kern()
+// FVIS-HIDDEN: define amdgpu_kernel void @default_kern()
+__attribute__((visibility("default"))) kernel void default_kern() {}
+// FVIS-DEFAULT: define protected amdgpu_kernel void @protected_kern()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @protected_kern()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @protected_kern()
+__attribute__((visibility("protected"))) kernel void protected_kern() {}
+// FVIS-DEFAULT: define hidden amdgpu_kernel void @hidden_kern()
+// FVIS-PROTECTED: define hidden amdgpu_kernel void @hidden_kern()
+// FVIS-HIDDEN: define hidden amdgpu_kernel void @hidden_kern()
+__attribute__((visibility("hidden"))) kernel void hidden_kern() {}
+
+// FVIS-DEFAULT: define void @func()
+// FVIS-PROTECTED: define protected void @func()
+// FVIS-HIDDEN: define hidden void @func()
+void func() {}
+// FVIS-DEFAULT: define void @default_func()
+// FVIS-PROTECTED: define void @default_func()
+// FVIS-HIDDEN: define void @default_func()
+__attribute__((visibility("default"))) void default_func() {}
+// FVIS-DEFAULT: define protected void @protected_func()
+// FVIS-PROTECTED: define protected void @protected_func()
+// FVIS-HIDDEN: define protected void @protected_func()
+__attribute__((visibility("protected"))) void protected_func() {}
+// FVIS-DEFAULT: define hidden void @hidden_func()
+// FVIS-PROTECTED: define hidden void @hidden_func()
+// FVIS-HIDDEN: define hidden void @hidden_func()
+__attribute__((visibility("hidden"))) void hidden_func() {}
Index: lib/AST/Decl.cpp
===
--- lib/AST/Decl.cpp
+++ lib/AST/Decl.cpp
@@ -556,6 +556,15 @@
 FD->hasBody(Def) && Def->isInlined() && !Def->hasAttr();
 }
 
+static bool useOpenCLVisibilityDefault(const NamedDecl *D) {
+  const LangOptions &Opts = D->getASTContext().getLangOpts();
+  if (!Opts.OpenCL)
+return false;
+  if (const auto *FD = dyn_cast(D))
+return FD->hasAttr();
+  return dyn_cast(D);
+}
+
 template  static bool isFirstInExternCContext(T *D) {
   const T *First = D->getFirstDecl();
   return First->isInExternCContext();
@@ -713,6 +722,9 @@
   }
 }
 
+if (!LV.isVisibilityExplicit() && useOpenCLVisibilityDefault(D))
+  LV.mergeVisibility(DefaultVisibility, true);
+
 // Add in global settings if the above didn't give us direct visibility.
 if (!LV.isVisibilityExplicit()) {
   // Use global type/value visibility as appropriate.


Index: test/CodeGenOpenCL/visibility.cl
=

[PATCH] D53153: [OpenCL] Mark namespace scope variables and kernel functions with default visibility

2018-10-12 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 169417.
scott.linder added a comment.

Address feedback


https://reviews.llvm.org/D53153

Files:
  lib/AST/Decl.cpp
  test/CodeGenOpenCL/visibility.cl


Index: test/CodeGenOpenCL/visibility.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/visibility.cl
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fvisibility default -triple amdgcn-unknown-unknown -S 
-emit-llvm -o - %s | FileCheck --check-prefix=FVIS-DEFAULT %s
+// RUN: %clang_cc1 -fvisibility protected -triple amdgcn-unknown-unknown -S 
-emit-llvm -o - %s | FileCheck --check-prefix=FVIS-PROTECTED %s
+// RUN: %clang_cc1 -fvisibility hidden -triple amdgcn-unknown-unknown -S 
-emit-llvm -o - %s | FileCheck --check-prefix=FVIS-HIDDEN %s
+
+// REQUIRES: amdgpu-registered-target
+
+// FVIS-DEFAULT: @globl = local_unnamed_addr
+// FVIS-PROTECTED: @globl = local_unnamed_addr
+// FVIS-HIDDEN: @globl = local_unnamed_addr
+__constant int globl = 0;
+// FVIS-DEFAULT: @default_globl = local_unnamed_addr
+// FVIS-PROTECTED: @default_globl = local_unnamed_addr
+// FVIS-HIDDEN: @default_globl = local_unnamed_addr
+__attribute__((visibility("default"))) __constant int default_globl = 0;
+// FVIS-DEFAULT: @protected_globl = protected local_unnamed_addr
+// FVIS-PROTECTED: @protected_globl = protected local_unnamed_addr
+// FVIS-HIDDEN: @protected_globl = protected local_unnamed_addr
+__attribute__((visibility("protected"))) __constant int protected_globl = 0;
+// FVIS-DEFAULT: @hidden_globl = hidden local_unnamed_addr
+// FVIS-PROTECTED: @hidden_globl = hidden local_unnamed_addr
+// FVIS-HIDDEN: @hidden_globl = hidden local_unnamed_addr
+__attribute__((visibility("hidden"))) __constant int hidden_globl = 0;
+
+// FVIS-DEFAULT: define amdgpu_kernel void @kern()
+// FVIS-PROTECTED: define amdgpu_kernel void @kern()
+// FVIS-HIDDEN: define amdgpu_kernel void @kern()
+kernel void kern() {}
+// FVIS-DEFAULT: define amdgpu_kernel void @default_kern()
+// FVIS-PROTECTED: define amdgpu_kernel void @default_kern()
+// FVIS-HIDDEN: define amdgpu_kernel void @default_kern()
+__attribute__((visibility("default"))) kernel void default_kern() {}
+// FVIS-DEFAULT: define protected amdgpu_kernel void @protected_kern()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @protected_kern()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @protected_kern()
+__attribute__((visibility("protected"))) kernel void protected_kern() {}
+// FVIS-DEFAULT: define hidden amdgpu_kernel void @hidden_kern()
+// FVIS-PROTECTED: define hidden amdgpu_kernel void @hidden_kern()
+// FVIS-HIDDEN: define hidden amdgpu_kernel void @hidden_kern()
+__attribute__((visibility("hidden"))) kernel void hidden_kern() {}
+
+// FVIS-DEFAULT: define void @func()
+// FVIS-PROTECTED: define protected void @func()
+// FVIS-HIDDEN: define hidden void @func()
+void func() {}
+// FVIS-DEFAULT: define void @default_func()
+// FVIS-PROTECTED: define void @default_func()
+// FVIS-HIDDEN: define void @default_func()
+__attribute__((visibility("default"))) void default_func() {}
+// FVIS-DEFAULT: define protected void @protected_func()
+// FVIS-PROTECTED: define protected void @protected_func()
+// FVIS-HIDDEN: define protected void @protected_func()
+__attribute__((visibility("protected"))) void protected_func() {}
+// FVIS-DEFAULT: define hidden void @hidden_func()
+// FVIS-PROTECTED: define hidden void @hidden_func()
+// FVIS-HIDDEN: define hidden void @hidden_func()
+__attribute__((visibility("hidden"))) void hidden_func() {}
Index: lib/AST/Decl.cpp
===
--- lib/AST/Decl.cpp
+++ lib/AST/Decl.cpp
@@ -556,6 +556,15 @@
 FD->hasBody(Def) && Def->isInlined() && !Def->hasAttr();
 }
 
+static bool useOpenCLVisibilityDefault(const NamedDecl *D) {
+  const LangOptions &Opts = D->getASTContext().getLangOpts();
+  if (!Opts.OpenCL)
+return false;
+  if (const auto *FD = dyn_cast(D))
+return FD->hasAttr();
+  return isa(D);
+}
+
 template  static bool isFirstInExternCContext(T *D) {
   const T *First = D->getFirstDecl();
   return First->isInExternCContext();
@@ -713,6 +722,9 @@
   }
 }
 
+if (!LV.isVisibilityExplicit() && useOpenCLVisibilityDefault(D))
+  LV.mergeVisibility(DefaultVisibility, true);
+
 // Add in global settings if the above didn't give us direct visibility.
 if (!LV.isVisibilityExplicit()) {
   // Use global type/value visibility as appropriate.


Index: test/CodeGenOpenCL/visibility.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/visibility.cl
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fvisibility default -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-DEFAULT %s
+// RUN: %clang_cc1 -fvisibility protected -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-PROTECTED %s
+// RUN: %clang_cc1 -fvisibili

[PATCH] D53153: [OpenCL] Mark namespace scope variables and kernel functions with default visibility

2018-10-12 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

The rationale is that `-fvisibility` only affects the default, and already does 
not apply in many cases. For example, see the rest of the conditions above the 
fvisibility check in `getLVForNamespaceScopeDecl`: when `Var->getStorageClass() 
== SC_Static` the linkage is (usually) internal and the visibility is default. 
In cases where individual symbols need unique visibility an `__attribute__` can 
be used.

I think one question is whether OpenCL language semantics allow us to make 
these visibility determinations; I am going off of the APIs available to access 
symbols.


https://reviews.llvm.org/D53153



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


[PATCH] D53153: [OpenCL] Mark namespace scope variables and kernel functions with default visibility

2018-10-12 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

That's my understanding, at least.

Take for example:

  $ cat foo.c 
  static void foo() { }
  void bar() { }
  
  void baz() { bar(); foo(); }
  $ clang -fvisibility=protected -O0 -S -emit-llvm foo.c -o - 
  ...
  
  ; Function Attrs: noinline nounwind optnone uwtable
  define protected void @bar() #0 {
  entry:
ret void
  }
  
  ; Function Attrs: noinline nounwind optnone uwtable
  define protected void @baz() #0 {
  entry:
call void @bar()
call void @foo()
ret void
  }
  
  ; Function Attrs: noinline nounwind optnone uwtable
  define internal void @foo() #0 {
  entry:
ret void
  }
  
  ...

Here `foo` has default visibility, while the user asked for protected. I still 
do not completely understand the interaction between linkage and visibility, as 
Clang gives default visibility to any symbol with internal linkage.


https://reviews.llvm.org/D53153



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


[PATCH] D53153: [OpenCL] Mark namespace scope variables and kernel functions with default visibility

2018-10-12 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a subscriber: b-sumner.
scott.linder added a comment.

In https://reviews.llvm.org/D53153#1263804, @rsmith wrote:

> In https://reviews.llvm.org/D53153#1263771, @scott.linder wrote:
>
> > The rationale is that `-fvisibility` only affects the default, and already 
> > does not apply in many cases. For example, see the rest of the conditions 
> > above the fvisibility check in `getLVForNamespaceScopeDecl`: when 
> > `Var->getStorageClass() == SC_Static` the linkage is (usually) internal and 
> > the visibility is default.
>
>
> Visibility is meaningless for an internal-linkage declaration.
>
> > I think one question is whether OpenCL language semantics allow us to make 
> > these visibility determinations; I am going off of the APIs available to 
> > access symbols.
>
> `-fvisibility` is not governed by the OpenCL specification; it's a Clang / 
> GCC extension, and we get to determine its semantics, which generally 
> override the rules from the language model we're implementing.
>
> I'm a little surprised that symbol visibility is even meaningful when 
> compiling GPU code. Can you give some more background on that?
>
> To the extent that visibility is meaningful, it does seem to make sense for 
> `kernel` to imply default visibility in the same way an attribute would, 
> since it's an unambiguous marker that the function is intended to be called 
> from outside the DSO.  It's less obvious to me that the same is true for 
> global variables; is there no distinction in OpenCL between global variables 
> that can be accessed by the host and global variables that are internal to 
> the device-side computation?


This makes more sense, thank you for the explanation. Ignore my last post, it 
makes sense that visibility is defaulted and ignored when a symbol is assigned 
internal linkage.

I am still not confident about globals; maybe @b-sumner has more insight? We 
have APIs for accessing global variable symbols form the host, but this may be 
AMD-specific, not general to OpenCL.


https://reviews.llvm.org/D53153



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


[PATCH] D53153: [OpenCL] Mark namespace scope variables and kernel functions with default visibility

2018-10-12 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In https://reviews.llvm.org/D53153#1263835, @yaxunl wrote:

> In https://reviews.llvm.org/D53153#1263810, @scott.linder wrote:
>
> > In https://reviews.llvm.org/D53153#1263804, @rsmith wrote:
> >
> > > In https://reviews.llvm.org/D53153#1263771, @scott.linder wrote:
> > >
> > > > The rationale is that `-fvisibility` only affects the default, and 
> > > > already does not apply in many cases. For example, see the rest of the 
> > > > conditions above the fvisibility check in `getLVForNamespaceScopeDecl`: 
> > > > when `Var->getStorageClass() == SC_Static` the linkage is (usually) 
> > > > internal and the visibility is default.
> > >
> > >
> > > Visibility is meaningless for an internal-linkage declaration.
> > >
> > > > I think one question is whether OpenCL language semantics allow us to 
> > > > make these visibility determinations; I am going off of the APIs 
> > > > available to access symbols.
> > >
> > > `-fvisibility` is not governed by the OpenCL specification; it's a Clang 
> > > / GCC extension, and we get to determine its semantics, which generally 
> > > override the rules from the language model we're implementing.
> > >
> > > I'm a little surprised that symbol visibility is even meaningful when 
> > > compiling GPU code. Can you give some more background on that?
> > >
> > > To the extent that visibility is meaningful, it does seem to make sense 
> > > for `kernel` to imply default visibility in the same way an attribute 
> > > would, since it's an unambiguous marker that the function is intended to 
> > > be called from outside the DSO.  It's less obvious to me that the same is 
> > > true for global variables; is there no distinction in OpenCL between 
> > > global variables that can be accessed by the host and global variables 
> > > that are internal to the device-side computation?
> >
> >
> > This makes more sense, thank you for the explanation. Ignore my last post, 
> > it makes sense that visibility is defaulted and ignored when a symbol is 
> > assigned internal linkage.
> >
> > I am still not confident about globals; maybe @b-sumner has more insight? 
> > We have APIs for accessing global variable symbols form the host, but this 
> > may be AMD-specific, not general to OpenCL.
>
>
> One thing I can think of the global variables is their initialization. If 
> their initialization must be done by the runtime, then they have to be 
> visible to the runtime.


Tony mentioned that in one of the CL2.X standards there is support for dynamic 
initialization of global variables, but I don't have a standard reference for 
that.


https://reviews.llvm.org/D53153



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


[PATCH] D53153: [OpenCL] Mark namespace scope variables and kernel functions with default visibility

2018-10-12 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Beyond constructors/destructors I believe an API which we implement through 
access to dynamic symbols for global variable is `clGetProgramBuildInfo(..., 
CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, ...)` which is defined as "The 
total amount of storage, in bytes, used by program variables in the global 
address space."

As for kernels, an example of an API which we implement through access to 
kernel symbols is `clGetProgramInfo(..., CL_PROGRAM_KERNEL_NAMES, ...)`

Both of these are defined at 
https://www.khronos.org/registry/OpenCL/specs/2.2/html/OpenCL_API.html#_program_object_queries


https://reviews.llvm.org/D53153



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


[PATCH] D53153: [OpenCL] Mark namespace scope variables and kernel functions with default visibility

2018-10-23 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 170637.
scott.linder added a comment.

Don't mark namespace-scope global variable declarations in OpenCL with explicit 
default visibility


https://reviews.llvm.org/D53153

Files:
  lib/AST/Decl.cpp
  test/CodeGenOpenCL/visibility.cl


Index: test/CodeGenOpenCL/visibility.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/visibility.cl
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fvisibility default -triple amdgcn-unknown-unknown -S 
-emit-llvm -o - %s | FileCheck --check-prefix=FVIS-DEFAULT %s
+// RUN: %clang_cc1 -fvisibility protected -triple amdgcn-unknown-unknown -S 
-emit-llvm -o - %s | FileCheck --check-prefix=FVIS-PROTECTED %s
+// RUN: %clang_cc1 -fvisibility hidden -triple amdgcn-unknown-unknown -S 
-emit-llvm -o - %s | FileCheck --check-prefix=FVIS-HIDDEN %s
+
+// REQUIRES: amdgpu-registered-target
+
+// FVIS-DEFAULT: @globl = local_unnamed_addr
+// FVIS-PROTECTED: @globl = protected local_unnamed_addr
+// FVIS-HIDDEN: @globl = hidden local_unnamed_addr
+__constant int globl = 0;
+// FVIS-DEFAULT: @default_globl = local_unnamed_addr
+// FVIS-PROTECTED: @default_globl = local_unnamed_addr
+// FVIS-HIDDEN: @default_globl = local_unnamed_addr
+__attribute__((visibility("default"))) __constant int default_globl = 0;
+// FVIS-DEFAULT: @protected_globl = protected local_unnamed_addr
+// FVIS-PROTECTED: @protected_globl = protected local_unnamed_addr
+// FVIS-HIDDEN: @protected_globl = protected local_unnamed_addr
+__attribute__((visibility("protected"))) __constant int protected_globl = 0;
+// FVIS-DEFAULT: @hidden_globl = hidden local_unnamed_addr
+// FVIS-PROTECTED: @hidden_globl = hidden local_unnamed_addr
+// FVIS-HIDDEN: @hidden_globl = hidden local_unnamed_addr
+__attribute__((visibility("hidden"))) __constant int hidden_globl = 0;
+
+// FVIS-DEFAULT: define amdgpu_kernel void @kern()
+// FVIS-PROTECTED: define amdgpu_kernel void @kern()
+// FVIS-HIDDEN: define amdgpu_kernel void @kern()
+kernel void kern() {}
+// FVIS-DEFAULT: define amdgpu_kernel void @default_kern()
+// FVIS-PROTECTED: define amdgpu_kernel void @default_kern()
+// FVIS-HIDDEN: define amdgpu_kernel void @default_kern()
+__attribute__((visibility("default"))) kernel void default_kern() {}
+// FVIS-DEFAULT: define protected amdgpu_kernel void @protected_kern()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @protected_kern()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @protected_kern()
+__attribute__((visibility("protected"))) kernel void protected_kern() {}
+// FVIS-DEFAULT: define hidden amdgpu_kernel void @hidden_kern()
+// FVIS-PROTECTED: define hidden amdgpu_kernel void @hidden_kern()
+// FVIS-HIDDEN: define hidden amdgpu_kernel void @hidden_kern()
+__attribute__((visibility("hidden"))) kernel void hidden_kern() {}
+
+// FVIS-DEFAULT: define void @func()
+// FVIS-PROTECTED: define protected void @func()
+// FVIS-HIDDEN: define hidden void @func()
+void func() {}
+// FVIS-DEFAULT: define void @default_func()
+// FVIS-PROTECTED: define void @default_func()
+// FVIS-HIDDEN: define void @default_func()
+__attribute__((visibility("default"))) void default_func() {}
+// FVIS-DEFAULT: define protected void @protected_func()
+// FVIS-PROTECTED: define protected void @protected_func()
+// FVIS-HIDDEN: define protected void @protected_func()
+__attribute__((visibility("protected"))) void protected_func() {}
+// FVIS-DEFAULT: define hidden void @hidden_func()
+// FVIS-PROTECTED: define hidden void @hidden_func()
+// FVIS-HIDDEN: define hidden void @hidden_func()
+__attribute__((visibility("hidden"))) void hidden_func() {}
Index: lib/AST/Decl.cpp
===
--- lib/AST/Decl.cpp
+++ lib/AST/Decl.cpp
@@ -556,6 +556,13 @@
 FD->hasBody(Def) && Def->isInlined() && !Def->hasAttr();
 }
 
+static bool useOpenCLVisibilityDefault(const NamedDecl *D) {
+  if (!D->getASTContext().getLangOpts().OpenCL)
+return false;
+  const auto *FD = dyn_cast(D);
+  return FD && FD->hasAttr();
+}
+
 template  static bool isFirstInExternCContext(T *D) {
   const T *First = D->getFirstDecl();
   return First->isInExternCContext();
@@ -713,6 +720,9 @@
   }
 }
 
+if (!LV.isVisibilityExplicit() && useOpenCLVisibilityDefault(D))
+  LV.mergeVisibility(DefaultVisibility, true);
+
 // Add in global settings if the above didn't give us direct visibility.
 if (!LV.isVisibilityExplicit()) {
   // Use global type/value visibility as appropriate.


Index: test/CodeGenOpenCL/visibility.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/visibility.cl
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -fvisibility default -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-DEFAULT %s
+// RUN: %clang_cc1 -fvisibility protected -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=F

[PATCH] D53153: [OpenCL] Mark namespace scope variables and kernel functions with default visibility

2018-10-23 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In https://reviews.llvm.org/D53153#1263882, @rsmith wrote:

> In https://reviews.llvm.org/D53153#1263848, @scott.linder wrote:
>
> > Beyond constructors/destructors I believe an API which we implement through 
> > access to dynamic symbols for global variable is 
> > `clGetProgramBuildInfo(..., CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, 
> > ...)` which is defined as "The total amount of storage, in bytes, used by 
> > program variables in the global address space."
>
>
> Presumably this is looking at the size of a certain section / segment of the 
> image. It's unclear to me why symbol visibility would affect this in any way.


You're right, the OpenCL APIs do not seem to require access to these symbols, 
as inspecting !X segments is sufficient. I removed global variable declarations 
from the patch.

>> As for kernels, an example of an API which we implement through access to 
>> kernel symbols is `clGetProgramInfo(..., CL_PROGRAM_KERNEL_NAMES, ...)`
> 
> Sure. `kernel`, like `dllexport` or `visibility(default)`, seems to act as 
> declaring a function to be part of the external interface of the code, and it 
> makes sense for all of those to override a command-line `-fvisibility` flag.
> 
> But it's still unclear to me what effect someone would expect 
> `-fvisibility=hidden` to have when compiling OpenCL code. What are these 
> symbols being hidden-by-default *from*, if not the host-side OpenCL runtime? 
> Is there ever actually have a device-side dynamic linker?

Currently for AMDGPU it is an optimization, because if the symbol is 
non-preemptible we can emit a static PCREL relocation and avoid a load from the 
GOT. We do not currently support device-side dynamic linking for e.g. lazy 
binding, so hiding non-kernel symbols is OK. When we begin to support 
device-side linking we can reconsider the blanket directive. In general I think 
someone compiling OpenCL code with this option would not expect `kernel` 
symbols to be hidden, as you mention; as far as what they intend to hide the 
symbols from I think that depends on how the implementation handles linking.


https://reviews.llvm.org/D53153



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


[PATCH] D53768: Add VerboseOutputStream to CompilerInstance

2018-10-26 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added a reviewer: rsmith.
Herald added a subscriber: cfe-commits.

An attempt at removing one instance of a hardcoded output stream in 
`CompilerInstance::ExecuteAction`. There are still other cases of output being 
hard-coded to standard streams in `ExecuteCompilerInvocation`, but this patch 
attempts to cover some cases when no specific flags (e.g. -version or -help) 
are passed, namely the "X warnings and Y errors generated." diagnostic.


Repository:
  rC Clang

https://reviews.llvm.org/D53768

Files:
  include/clang/Frontend/CompilerInstance.h
  lib/Frontend/CompilerInstance.cpp
  unittests/Frontend/OutputStreamTest.cpp

Index: unittests/Frontend/OutputStreamTest.cpp
===
--- unittests/Frontend/OutputStreamTest.cpp
+++ unittests/Frontend/OutputStreamTest.cpp
@@ -10,6 +10,7 @@
 #include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/CodeGenAction.h"
 #include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
 #include "clang/FrontendTool/Utils.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "gtest/gtest.h"
@@ -43,4 +44,29 @@
   EXPECT_TRUE(!IRBuffer.empty());
   EXPECT_TRUE(StringRef(IRBuffer.data()).startswith("BC"));
 }
+
+TEST(FrontendOutputTests, TestVerboseOutputStream) {
+  auto Invocation = std::make_shared();
+  Invocation->getPreprocessorOpts().addRemappedFile(
+  "test.cc", MemoryBuffer::getMemBuffer("invalid").release());
+  Invocation->getFrontendOpts().Inputs.push_back(
+  FrontendInputFile("test.cc", InputKind::CXX));
+  Invocation->getFrontendOpts().ProgramAction = EmitBC;
+  Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu";
+  CompilerInstance Compiler;
+
+  std::string VerboseBuffer;
+  raw_string_ostream VerboseStream(VerboseBuffer);
+
+  Compiler.setInvocation(std::move(Invocation));
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  Compiler.createDiagnostics(
+  new TextDiagnosticPrinter(llvm::nulls(), &*DiagOpts), true);
+  Compiler.setVerboseOutputStream(VerboseStream);
+
+  bool Success = ExecuteCompilerInvocation(&Compiler);
+  EXPECT_FALSE(Success);
+  EXPECT_TRUE(!VerboseStream.str().empty());
+  EXPECT_TRUE(StringRef(VerboseBuffer.data()).contains("errors generated"));
+}
 }
Index: lib/Frontend/CompilerInstance.cpp
===
--- lib/Frontend/CompilerInstance.cpp
+++ lib/Frontend/CompilerInstance.cpp
@@ -70,6 +70,8 @@
 
 CompilerInstance::~CompilerInstance() {
   assert(OutputFiles.empty() && "Still output files in flight?");
+  if (OwnsVerboseOutputStream)
+delete VerboseOutputStream;
 }
 
 void CompilerInstance::setInvocation(
@@ -88,6 +90,12 @@
   Diagnostics = Value;
 }
 
+void CompilerInstance::setVerboseOutputStream(raw_ostream &Value,
+  bool OwnsOutputStream) {
+  OwnsVerboseOutputStream = OwnsOutputStream;
+  VerboseOutputStream = &Value;
+}
+
 void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; }
 void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; }
 
@@ -907,9 +915,7 @@
   assert(!getFrontendOpts().ShowHelp && "Client must handle '-help'!");
   assert(!getFrontendOpts().ShowVersion && "Client must handle '-version'!");
 
-  // FIXME: Take this as an argument, once all the APIs we used have moved to
-  // taking it as an input instead of hard-coding llvm::errs.
-  raw_ostream &OS = llvm::errs();
+  raw_ostream &OS = getVerboseOutputStream();
 
   if (!Act.PrepareToExecute(*this))
 return false;
Index: include/clang/Frontend/CompilerInstance.h
===
--- include/clang/Frontend/CompilerInstance.h
+++ include/clang/Frontend/CompilerInstance.h
@@ -161,6 +161,12 @@
   /// One or more modules failed to build.
   bool ModuleBuildFailed = false;
 
+  /// Whether we should delete VerboseOutputStream on destruction.
+  bool OwnsVerboseOutputStream = false;
+
+  /// The stream for verbose output.
+  raw_ostream *VerboseOutputStream = &llvm::errs();
+
   /// Holds information about the output file.
   ///
   /// If TempFilename is not empty we must rename it to Filename at the end.
@@ -223,9 +229,6 @@
   /// \param Act - The action to execute.
   /// \return - True on success.
   //
-  // FIXME: This function should take the stream to write any debugging /
-  // verbose output to as an argument.
-  //
   // FIXME: Eliminate the llvm_shutdown requirement, that should either be part
   // of the context or else not CompilerInstance specific.
   bool ExecuteAction(FrontendAction &Act);
@@ -356,6 +359,21 @@
   }
 
   /// }
+  /// @name VerboseOutputStream
+  /// }
+
+  /// Replace the current stream for verbose output.
+  ///
+  /// If not set, this stream defaults to \c llvm::errs().
+  void setVerboseOutputStream(raw_ostream &Value,
+  bool Owns

[PATCH] D53153: [OpenCL] Mark kernel functions with default visibility

2019-01-14 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D53153#1355718 , @rjmccall wrote:

> In D53153#1353256 , @scott.linder 
> wrote:
>
> > In D53153#1317977 , @rjmccall 
> > wrote:
> >
> > > I think `-fvisibility=hidden` isn't good enough because you want to infer 
> > > hidden visibility even for external symbol references, and that's just 
> > > not how global visibility works.  But after this discussion, I'm prepared 
> > > to accept that (1) we should have some sort of single-image compiler mode 
> > > that implies that all symbols are defined within the image and (2) you 
> > > can make your toolchain imply that together with `-fvisibility=hidden` 
> > > and then have specific symbols opt in to non-hidden visibility if they 
> > > need to be accessible to whatever loader / runtime you have.
> >
> >
> > It seems that explicit visibility attributes on external symbol references 
> > (e.g. `__attribute__((visibility("hidden"))) extern int foo;`) are 
> > respected in Clang, so I don't understand the rationale for global 
> > visibility controls not applying to them as well. Can you describe why this 
> > is the case?
>
>
> Well, one answer is that that's the behavior that GCC defined when they added 
> global visibility controls, and it would be unreasonable for Clang to deviate 
> in such a fundamental way.  However, we do deviate in some other ways in our 
> interpretation of visibility attributes, so that's not a totally satisfactory 
> answer.
>
> The stronger answer is that GCC has a very good reason for this behavior.  
> Global visibility controls apply to all code in the translation unit.  While 
> programmers often mentally distinguish between "project" headers (which they 
> control) and "library" headers (which they do not), that is not a difference 
> that is known to the compiler.  Therefore, if global visibility controls 
> applied to external symbols, the compiler would end up assuming that all 
> external symbols not annotated as `default` are provided by the current 
> image.  That assumption would have been incompatible with essentially all 
> existing headers for dynamic libraries on GCC's core targets, including 
> system headers; in other words, it would have caused ubiquitous miscompiles.* 
>  It would be completely unreasonable to expect all those headers to be 
> changed just for the benefit of a single new compiler feature.  Therefore, 
> global visibility controls do not apply to external symbols because doing so 
> would make it impossible to actually enable global visibility controls.
>
> - GCC's rule helps a great deal even in C++, which is generally more 
> sensitive to global visibility: you can typically use an unannotated C++ 
> header under `-fvisibility=hidden` and have no problems unless you start 
> using its types as exceptions (and GCC tries to work around that, too) or 
> comparing the addresses of inline functions or template instantiations.
>
>   John.


Thank you for the context, that makes sense.

In terms of implementation of the above, currently at the AST level the 
LinkageComputer seems to assign global visibility to extern declarations, then 
during CodeGen this is simply not copied to the IR level unless the visibility 
was set explicitly. At first I was confused that the visibility of e.g. a 
`clang::Decl` and its `llvm::GlobalValue` could differ. Is there a reason why 
the implementation of LinkageComputer does not calculate the correct visibility 
here from the start? If the logic for extern declarations can be moved into the 
AST would it then be reasonable to add a distinct global visibility for extern 
declarations (something like `-fextern-visibility=`)? We could pair this with 
the existing global value visibility to effectively get the single-image 
compilation mode.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53153/new/

https://reviews.llvm.org/D53153



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


[PATCH] D53329: Generate DIFile with main program if source is not available

2019-01-14 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D53329#1356381 , @yonghong-song 
wrote:

> @dblaikie @scott.linder Have you got time to look at this issue? Looks like a 
> trivial test case will be able to reproduce the problem. I have the simple 
> example in the previous comments. Practically, `-gdwarf-5 -gembed-source` is 
> broken now.


Sorry, I haven't had a chance to look into the issue yet. I don't know if I 
will have a chance this week, and I'm on vacation next week, but I hope to be 
able to soon.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53329/new/

https://reviews.llvm.org/D53329



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


[PATCH] D53153: [OpenCL] Mark kernel functions with default visibility

2019-01-15 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

It sounds like `-fextern-visiblity=` isn't something we really want, then? I 
think it would have to be implemented in the abstract linkage computer.

Would a patch to add an option to apply the normal visibility calculations to 
extern decls be reasonable, then? This change could be done entirely in CodeGen.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53153/new/

https://reviews.llvm.org/D53153



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


[PATCH] D53153: [OpenCL] Mark kernel functions with default visibility

2019-01-17 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

I think we need the option to be in the driver, not just -cc1. We are moving 
towards the clang driver being the authority on how we do offline compilation 
for AMDGPU, and hiding this in cc1 doesn't help us.

I also don't think this is unreasonable to expose in general. As you note the 
behavior of `-fvisibility` wrt. declarations is just a practical measure, and 
even in the world of e.g. x86 it seems like there are cases where the option is 
useful.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53153/new/

https://reviews.llvm.org/D53153



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


[PATCH] D56871: [AMDGPU] Require at least protected visibility for certain symbols

2019-01-17 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added reviewers: b-sumner, arsenm, kzhuravl, t-tye, yaxunl.
Herald added subscribers: cfe-commits, tpr, dstuttard, wdng.

This allows the global visibility controls to be restrictive while still 
populating the dynamic symbol table where required. Depends in-part on a patch 
to apply global symbol visibility to declarations, although this patch is 
conservatively correct without that change.


Repository:
  rC Clang

https://reviews.llvm.org/D56871

Files:
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  test/CodeGenOpenCL/visibility.cl

Index: test/CodeGenOpenCL/visibility.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/visibility.cl
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -std=cl2.0 -fvisibility default -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-DEFAULT %s
+// RUN: %clang_cc1 -std=cl2.0 -fvisibility protected -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-PROTECTED %s
+// RUN: %clang_cc1 -std=cl2.0 -fvisibility hidden -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-HIDDEN %s
+
+// REQUIRES: amdgpu-registered-target
+
+// FVIS-DEFAULT:  @glob = local_unnamed_addr
+// FVIS-PROTECTED: @glob = protected local_unnamed_addr
+// FVIS-HIDDEN: @glob = hidden local_unnamed_addr
+int glob = 0;
+// FVIS-DEFAULT:  @glob_hidden = hidden local_unnamed_addr
+// FVIS-PROTECTED: @glob_hidden = hidden local_unnamed_addr
+// FVIS-HIDDEN: @glob_hidden = hidden local_unnamed_addr
+__attribute__((visibility("hidden"))) int glob_hidden = 0;
+// FVIS-DEFAULT:  @glob_protected = protected local_unnamed_addr
+// FVIS-PROTECTED: @glob_protected = protected local_unnamed_addr
+// FVIS-HIDDEN: @glob_protected = protected local_unnamed_addr
+__attribute__((visibility("protected"))) int glob_protected = 0;
+// FVIS-DEFAULT:  @glob_default = local_unnamed_addr
+// FVIS-PROTECTED: @glob_default = local_unnamed_addr
+// FVIS-HIDDEN: @glob_default = local_unnamed_addr
+__attribute__((visibility("default"))) int glob_default = 0;
+
+// FVIS-DEFAULT:  @ext = external local_unnamed_addr
+// FVIS-PROTECTED: @ext = external local_unnamed_addr
+// FVIS-HIDDEN: @ext = external local_unnamed_addr
+extern int ext;
+// FVIS-DEFAULT:  @ext_hidden = external hidden local_unnamed_addr
+// FVIS-PROTECTED: @ext_hidden = external hidden local_unnamed_addr
+// FVIS-HIDDEN: @ext_hidden = external hidden local_unnamed_addr
+__attribute__((visibility("hidden"))) extern int ext_hidden;
+// FVIS-DEFAULT:  @ext_protected = external protected local_unnamed_addr
+// FVIS-PROTECTED: @ext_protected = external protected local_unnamed_addr
+// FVIS-HIDDEN: @ext_protected = external protected local_unnamed_addr
+__attribute__((visibility("protected"))) extern int ext_protected;
+// FVIS-DEFAULT:  @ext_default = external local_unnamed_addr
+// FVIS-PROTECTED: @ext_default = external local_unnamed_addr
+// FVIS-HIDDEN: @ext_default = external local_unnamed_addr
+__attribute__((visibility("default"))) extern int ext_default;
+
+// FVIS-DEFAULT: define amdgpu_kernel void @kern()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @kern()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @kern()
+kernel void kern() {}
+// FVIS-DEFAULT: define protected amdgpu_kernel void @kern_hidden()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @kern_hidden()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @kern_hidden()
+__attribute__((visibility("hidden"))) kernel void kern_hidden() {}
+// FVIS-DEFAULT: define protected amdgpu_kernel void @kern_protected()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @kern_protected()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @kern_protected()
+__attribute__((visibility("protected"))) kernel void kern_protected() {}
+// FVIS-DEFAULT: define amdgpu_kernel void @kern_default()
+// FVIS-PROTECTED: define amdgpu_kernel void @kern_default()
+// FVIS-HIDDEN: define amdgpu_kernel void @kern_default()
+__attribute__((visibility("default"))) kernel void kern_default() {}
+
+// FVIS-DEFAULT: define void @func()
+// FVIS-PROTECTED: define protected void @func()
+// FVIS-HIDDEN: define hidden void @func()
+void func() {}
+// FVIS-DEFAULT: define hidden void @func_hidden()
+// FVIS-PROTECTED: define hidden void @func_hidden()
+// FVIS-HIDDEN: define hidden void @func_hidden()
+__attribute__((visibility("hidden"))) void func_hidden() {}
+// FVIS-DEFAULT: define protected void @func_protected()
+// FVIS-PROTECTED: define protected void @func_protected()
+// FVIS-HIDDEN: define protected void @func_protected()
+__attribute__((visibility("protected"))) void func_protected() {}
+// FVIS-DEFAULT: define void @func_default()
+// FVIS-PROTECTED: define void @func_default()
+// FVIS-HIDDEN: define void @func_default()
+__attribute__((visibility("default"))) void func_default() {}
+
+void use() {
+ 

[PATCH] D52891: [AMDGPU] Add -fvisibility-amdgpu-non-kernel-functions

2019-01-17 Thread Scott Linder via Phabricator via cfe-commits
scott.linder abandoned this revision.
scott.linder added a comment.

Will be superseded by either https://reviews.llvm.org/D53153 or 
https://reviews.llvm.org/D56871


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D52891/new/

https://reviews.llvm.org/D52891



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


[PATCH] D53153: [OpenCL] Mark kernel functions with default visibility

2019-01-17 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

That sounds reasonable to me. I had already posted a patch with the Driver 
options, but I will update it to only include the -cc1 version.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53153/new/

https://reviews.llvm.org/D53153



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


[PATCH] D56868: Add -fset-visibility-for-decls for -cc1

2019-01-17 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 182390.
scott.linder retitled this revision from "Add -f[no-]set-visibility-for-decls" 
to "Add -fset-visibility-for-decls for -cc1".
scott.linder added a comment.

Remove driver options


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56868/new/

https://reviews.llvm.org/D56868

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Driver/CC1Options.td
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/ToolChains/AMDGPU.cpp
  lib/Driver/ToolChains/HIP.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/set-visibility-for-decls.c
  test/Driver/amdgpu-visibility.cl
  test/Driver/hip-toolchain-no-rdc.hip
  test/Driver/hip-toolchain-rdc.hip

Index: test/Driver/hip-toolchain-rdc.hip
===
--- test/Driver/hip-toolchain-rdc.hip
+++ test/Driver/hip-toolchain-rdc.hip
@@ -12,10 +12,11 @@
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck %s
 
-// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa" 
+// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx803"
 // CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fvisibility" "hidden"
+// CHECK-SAME: "-fset-visibility-for-decls"
 // CHECK-SAME: {{.*}} "-o" [[A_BC:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]]
 
@@ -23,6 +24,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" {{.*}} "-target-cpu" "gfx803"
 // CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fvisibility" "hidden"
+// CHECK-SAME: "-fset-visibility-for-decls"
 // CHECK-SAME: {{.*}} "-o" [[B_BC:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[B_SRC:".*b.hip"]]
 
Index: test/Driver/hip-toolchain-no-rdc.hip
===
--- test/Driver/hip-toolchain-no-rdc.hip
+++ test/Driver/hip-toolchain-no-rdc.hip
@@ -20,6 +20,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx803"
 // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden"
+// CHECK-SAME: "-fset-visibility-for-decls"
 // CHECK-SAME: {{.*}} "-o" [[A_BC_803:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]]
 
@@ -47,6 +48,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx900"
 // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden"
+// CHECK-SAME: "-fset-visibility-for-decls"
 // CHECK-SAME: {{.*}} "-o" [[A_BC_900:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[A_SRC]]
 
@@ -89,6 +91,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" {{.*}} "-target-cpu" "gfx803"
 // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden"
+// CHECK-SAME: "-fset-visibility-for-decls"
 // CHECK-SAME: {{.*}} "-o" [[B_BC_803:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[B_SRC:".*b.hip"]]
 
@@ -116,6 +119,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" {{.*}} "-target-cpu" "gfx900"
 // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden"
+// CHECK-SAME: "-fset-visibility-for-decls"
 // CHECK-SAME: {{.*}} "-o" [[B_BC_900:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[B_SRC]]
 
Index: test/Driver/amdgpu-visibility.cl
===
--- test/Driver/amdgpu-visibility.cl
+++ test/Driver/amdgpu-visibility.cl
@@ -2,6 +2,14 @@
 // RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility=protected  %s 2>&1 | FileCheck -check-prefix=OVERRIDE-PROTECTED  %s
 // RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility-ms-compat  %s 2>&1 | FileCheck -check-prefix=OVERRIDE-MS  %s
 
-// DEFAULT: "-fvisibility" "hidden"
+// DEFAULT-DAG: "-fvisibility" "hidden"
+// DEFAULT-DAG: "-fset-visibility-for-decls"
+
+// OVERRIDE-PROTECTED-NOT: "-fset-visibility-for-decls"
 // OVERRIDE-PROTECTED: "-fvisibility" "protected"
-// OVERRIDE-MS:  "-fvisibility" "hidden" "-ftype-visibility" "default"
+// OVERRIDE-PROTECTED-NOT: "-fset-visibility-for-decls"
+
+// OVERRIDE-MS-NOT: "-fset-visibility-for-decls"
+// OVERRIDE-MS-DAG: "-fvisibility" "hidden"
+// OVERRIDE-MS-DAG: "-ftype-visibility" "default"
+// OVERRIDE-MS-NOT: "-fset-visibility-for-decls"
Index: test/CodeGen/set-visibility-for-decls.c
===
--- /dev/null
+++ test/CodeGen/set-visibility-for-decls.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -std=c11 -triple=x86_64-pc-linux -fvisibility hidden -fset-visibility-for-decls -emit-llvm -o - | FileCheck --check-prefix=CHECK-HIDDEN %s
+// RUN: %clang_cc1 %s -std=c1

[PATCH] D56871: [AMDGPU] Require at least protected visibility for certain symbols

2019-01-17 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 182394.
scott.linder added a comment.

Add missing flag to tests


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56871/new/

https://reviews.llvm.org/D56871

Files:
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  test/CodeGenOpenCL/visibility.cl

Index: test/CodeGenOpenCL/visibility.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/visibility.cl
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -std=cl2.0 -fset-visibility-for-decls -fvisibility default -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-DEFAULT %s
+// RUN: %clang_cc1 -std=cl2.0 -fset-visibility-for-decls -fvisibility protected -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-PROTECTED %s
+// RUN: %clang_cc1 -std=cl2.0 -fset-visibility-for-decls -fvisibility hidden -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-HIDDEN %s
+
+// REQUIRES: amdgpu-registered-target
+
+// FVIS-DEFAULT:  @glob = local_unnamed_addr
+// FVIS-PROTECTED: @glob = protected local_unnamed_addr
+// FVIS-HIDDEN: @glob = hidden local_unnamed_addr
+int glob = 0;
+// FVIS-DEFAULT:  @glob_hidden = hidden local_unnamed_addr
+// FVIS-PROTECTED: @glob_hidden = hidden local_unnamed_addr
+// FVIS-HIDDEN: @glob_hidden = hidden local_unnamed_addr
+__attribute__((visibility("hidden"))) int glob_hidden = 0;
+// FVIS-DEFAULT:  @glob_protected = protected local_unnamed_addr
+// FVIS-PROTECTED: @glob_protected = protected local_unnamed_addr
+// FVIS-HIDDEN: @glob_protected = protected local_unnamed_addr
+__attribute__((visibility("protected"))) int glob_protected = 0;
+// FVIS-DEFAULT:  @glob_default = local_unnamed_addr
+// FVIS-PROTECTED: @glob_default = local_unnamed_addr
+// FVIS-HIDDEN: @glob_default = local_unnamed_addr
+__attribute__((visibility("default"))) int glob_default = 0;
+
+// FVIS-DEFAULT:  @ext = external local_unnamed_addr
+// FVIS-PROTECTED: @ext = external protected local_unnamed_addr
+// FVIS-HIDDEN: @ext = external hidden local_unnamed_addr
+extern int ext;
+// FVIS-DEFAULT:  @ext_hidden = external hidden local_unnamed_addr
+// FVIS-PROTECTED: @ext_hidden = external hidden local_unnamed_addr
+// FVIS-HIDDEN: @ext_hidden = external hidden local_unnamed_addr
+__attribute__((visibility("hidden"))) extern int ext_hidden;
+// FVIS-DEFAULT:  @ext_protected = external protected local_unnamed_addr
+// FVIS-PROTECTED: @ext_protected = external protected local_unnamed_addr
+// FVIS-HIDDEN: @ext_protected = external protected local_unnamed_addr
+__attribute__((visibility("protected"))) extern int ext_protected;
+// FVIS-DEFAULT:  @ext_default = external local_unnamed_addr
+// FVIS-PROTECTED: @ext_default = external local_unnamed_addr
+// FVIS-HIDDEN: @ext_default = external local_unnamed_addr
+__attribute__((visibility("default"))) extern int ext_default;
+
+// FVIS-DEFAULT: define amdgpu_kernel void @kern()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @kern()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @kern()
+kernel void kern() {}
+// FVIS-DEFAULT: define protected amdgpu_kernel void @kern_hidden()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @kern_hidden()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @kern_hidden()
+__attribute__((visibility("hidden"))) kernel void kern_hidden() {}
+// FVIS-DEFAULT: define protected amdgpu_kernel void @kern_protected()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @kern_protected()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @kern_protected()
+__attribute__((visibility("protected"))) kernel void kern_protected() {}
+// FVIS-DEFAULT: define amdgpu_kernel void @kern_default()
+// FVIS-PROTECTED: define amdgpu_kernel void @kern_default()
+// FVIS-HIDDEN: define amdgpu_kernel void @kern_default()
+__attribute__((visibility("default"))) kernel void kern_default() {}
+
+// FVIS-DEFAULT: define void @func()
+// FVIS-PROTECTED: define protected void @func()
+// FVIS-HIDDEN: define hidden void @func()
+void func() {}
+// FVIS-DEFAULT: define hidden void @func_hidden()
+// FVIS-PROTECTED: define hidden void @func_hidden()
+// FVIS-HIDDEN: define hidden void @func_hidden()
+__attribute__((visibility("hidden"))) void func_hidden() {}
+// FVIS-DEFAULT: define protected void @func_protected()
+// FVIS-PROTECTED: define protected void @func_protected()
+// FVIS-HIDDEN: define protected void @func_protected()
+__attribute__((visibility("protected"))) void func_protected() {}
+// FVIS-DEFAULT: define void @func_default()
+// FVIS-PROTECTED: define void @func_default()
+// FVIS-HIDDEN: define void @func_default()
+__attribute__((visibility("default"))) void func_default() {}
+
+void use() {
+glob = ext + ext_hidden + ext_protected + ext_default;
+}
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
++

[PATCH] D56868: Add -fextern-visibility for -cc1

2019-01-18 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 182528.
scott.linder retitled this revision from "Add -fset-visibility-for-decls for 
-cc1" to "Add -fextern-visibility for -cc1".
scott.linder added a comment.

Update the -cc1 option name and docs; also update the LangOpt and docs.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56868/new/

https://reviews.llvm.org/D56868

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Driver/CC1Options.td
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/ToolChains/AMDGPU.cpp
  lib/Driver/ToolChains/HIP.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/set-visibility-for-decls.c
  test/Driver/amdgpu-visibility.cl
  test/Driver/hip-toolchain-no-rdc.hip
  test/Driver/hip-toolchain-rdc.hip

Index: test/Driver/hip-toolchain-rdc.hip
===
--- test/Driver/hip-toolchain-rdc.hip
+++ test/Driver/hip-toolchain-rdc.hip
@@ -12,10 +12,11 @@
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck %s
 
-// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa" 
+// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx803"
 // CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fvisibility" "hidden"
+// CHECK-SAME: "-fextern-visibility"
 // CHECK-SAME: {{.*}} "-o" [[A_BC:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]]
 
@@ -23,6 +24,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" {{.*}} "-target-cpu" "gfx803"
 // CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fvisibility" "hidden"
+// CHECK-SAME: "-fextern-visibility"
 // CHECK-SAME: {{.*}} "-o" [[B_BC:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[B_SRC:".*b.hip"]]
 
Index: test/Driver/hip-toolchain-no-rdc.hip
===
--- test/Driver/hip-toolchain-no-rdc.hip
+++ test/Driver/hip-toolchain-no-rdc.hip
@@ -20,6 +20,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx803"
 // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden"
+// CHECK-SAME: "-fextern-visibility"
 // CHECK-SAME: {{.*}} "-o" [[A_BC_803:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]]
 
@@ -47,6 +48,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx900"
 // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden"
+// CHECK-SAME: "-fextern-visibility"
 // CHECK-SAME: {{.*}} "-o" [[A_BC_900:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[A_SRC]]
 
@@ -89,6 +91,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" {{.*}} "-target-cpu" "gfx803"
 // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden"
+// CHECK-SAME: "-fextern-visibility"
 // CHECK-SAME: {{.*}} "-o" [[B_BC_803:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[B_SRC:".*b.hip"]]
 
@@ -116,6 +119,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" {{.*}} "-target-cpu" "gfx900"
 // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden"
+// CHECK-SAME: "-fextern-visibility"
 // CHECK-SAME: {{.*}} "-o" [[B_BC_900:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[B_SRC]]
 
Index: test/Driver/amdgpu-visibility.cl
===
--- test/Driver/amdgpu-visibility.cl
+++ test/Driver/amdgpu-visibility.cl
@@ -2,6 +2,14 @@
 // RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility=protected  %s 2>&1 | FileCheck -check-prefix=OVERRIDE-PROTECTED  %s
 // RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility-ms-compat  %s 2>&1 | FileCheck -check-prefix=OVERRIDE-MS  %s
 
-// DEFAULT: "-fvisibility" "hidden"
+// DEFAULT-DAG: "-fvisibility" "hidden"
+// DEFAULT-DAG: "-fextern-visibility"
+
+// OVERRIDE-PROTECTED-NOT: "-fextern-visibility"
 // OVERRIDE-PROTECTED: "-fvisibility" "protected"
-// OVERRIDE-MS:  "-fvisibility" "hidden" "-ftype-visibility" "default"
+// OVERRIDE-PROTECTED-NOT: "-fextern-visibility"
+
+// OVERRIDE-MS-NOT: "-fextern-visibility"
+// OVERRIDE-MS-DAG: "-fvisibility" "hidden"
+// OVERRIDE-MS-DAG: "-ftype-visibility" "default"
+// OVERRIDE-MS-NOT: "-fextern-visibility"
Index: test/CodeGen/set-visibility-for-decls.c
===
--- /dev/null
+++ test/CodeGen/set-visibility-for-decls.c
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -std=c11 -triple=x86_64-pc-linux -fvisibility hidden -fextern-visibility -emit-llvm -o - | FileCheck --check-prefix=CHECK-HIDDEN %s
+// RUN: %clang_cc1 %s -std=c11 -triple=x86_64-pc-linux -fvisibilit

[PATCH] D56871: [AMDGPU] Require at least protected visibility for certain symbols

2019-01-18 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 182532.
scott.linder added a comment.

Update option name


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56871/new/

https://reviews.llvm.org/D56871

Files:
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  test/CodeGenOpenCL/visibility.cl

Index: test/CodeGenOpenCL/visibility.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/visibility.cl
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -std=cl2.0 -fextern-visibility -fvisibility default -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-DEFAULT %s
+// RUN: %clang_cc1 -std=cl2.0 -fextern-visibility -fvisibility protected -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-PROTECTED %s
+// RUN: %clang_cc1 -std=cl2.0 -fextern-visibility -fvisibility hidden -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-HIDDEN %s
+
+// REQUIRES: amdgpu-registered-target
+
+// FVIS-DEFAULT:  @glob = local_unnamed_addr
+// FVIS-PROTECTED: @glob = protected local_unnamed_addr
+// FVIS-HIDDEN: @glob = hidden local_unnamed_addr
+int glob = 0;
+// FVIS-DEFAULT:  @glob_hidden = hidden local_unnamed_addr
+// FVIS-PROTECTED: @glob_hidden = hidden local_unnamed_addr
+// FVIS-HIDDEN: @glob_hidden = hidden local_unnamed_addr
+__attribute__((visibility("hidden"))) int glob_hidden = 0;
+// FVIS-DEFAULT:  @glob_protected = protected local_unnamed_addr
+// FVIS-PROTECTED: @glob_protected = protected local_unnamed_addr
+// FVIS-HIDDEN: @glob_protected = protected local_unnamed_addr
+__attribute__((visibility("protected"))) int glob_protected = 0;
+// FVIS-DEFAULT:  @glob_default = local_unnamed_addr
+// FVIS-PROTECTED: @glob_default = local_unnamed_addr
+// FVIS-HIDDEN: @glob_default = local_unnamed_addr
+__attribute__((visibility("default"))) int glob_default = 0;
+
+// FVIS-DEFAULT:  @ext = external local_unnamed_addr
+// FVIS-PROTECTED: @ext = external protected local_unnamed_addr
+// FVIS-HIDDEN: @ext = external hidden local_unnamed_addr
+extern int ext;
+// FVIS-DEFAULT:  @ext_hidden = external hidden local_unnamed_addr
+// FVIS-PROTECTED: @ext_hidden = external hidden local_unnamed_addr
+// FVIS-HIDDEN: @ext_hidden = external hidden local_unnamed_addr
+__attribute__((visibility("hidden"))) extern int ext_hidden;
+// FVIS-DEFAULT:  @ext_protected = external protected local_unnamed_addr
+// FVIS-PROTECTED: @ext_protected = external protected local_unnamed_addr
+// FVIS-HIDDEN: @ext_protected = external protected local_unnamed_addr
+__attribute__((visibility("protected"))) extern int ext_protected;
+// FVIS-DEFAULT:  @ext_default = external local_unnamed_addr
+// FVIS-PROTECTED: @ext_default = external local_unnamed_addr
+// FVIS-HIDDEN: @ext_default = external local_unnamed_addr
+__attribute__((visibility("default"))) extern int ext_default;
+
+// FVIS-DEFAULT: define amdgpu_kernel void @kern()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @kern()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @kern()
+kernel void kern() {}
+// FVIS-DEFAULT: define protected amdgpu_kernel void @kern_hidden()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @kern_hidden()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @kern_hidden()
+__attribute__((visibility("hidden"))) kernel void kern_hidden() {}
+// FVIS-DEFAULT: define protected amdgpu_kernel void @kern_protected()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @kern_protected()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @kern_protected()
+__attribute__((visibility("protected"))) kernel void kern_protected() {}
+// FVIS-DEFAULT: define amdgpu_kernel void @kern_default()
+// FVIS-PROTECTED: define amdgpu_kernel void @kern_default()
+// FVIS-HIDDEN: define amdgpu_kernel void @kern_default()
+__attribute__((visibility("default"))) kernel void kern_default() {}
+
+// FVIS-DEFAULT: define void @func()
+// FVIS-PROTECTED: define protected void @func()
+// FVIS-HIDDEN: define hidden void @func()
+void func() {}
+// FVIS-DEFAULT: define hidden void @func_hidden()
+// FVIS-PROTECTED: define hidden void @func_hidden()
+// FVIS-HIDDEN: define hidden void @func_hidden()
+__attribute__((visibility("hidden"))) void func_hidden() {}
+// FVIS-DEFAULT: define protected void @func_protected()
+// FVIS-PROTECTED: define protected void @func_protected()
+// FVIS-HIDDEN: define protected void @func_protected()
+__attribute__((visibility("protected"))) void func_protected() {}
+// FVIS-DEFAULT: define void @func_default()
+// FVIS-PROTECTED: define void @func_default()
+// FVIS-HIDDEN: define void @func_default()
+__attribute__((visibility("default"))) void func_default() {}
+
+void use() {
+glob = ext + ext_hidden + ext_protected + ext_default;
+}
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp

[PATCH] D56868: Add -fapply-global-visibility-to-externs for -cc1

2019-01-18 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 182559.
scott.linder retitled this revision from "Add -fextern-visibility for -cc1" to 
"Add -fapply-global-visibility-to-externs for -cc1".
scott.linder added a comment.

No worries, I agree that we don't gain much with a shorter flag here; explicit 
seems preferable.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56868/new/

https://reviews.llvm.org/D56868

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Driver/CC1Options.td
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/ToolChains/AMDGPU.cpp
  lib/Driver/ToolChains/HIP.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/set-visibility-for-decls.c
  test/Driver/amdgpu-visibility.cl
  test/Driver/hip-toolchain-no-rdc.hip
  test/Driver/hip-toolchain-rdc.hip

Index: test/Driver/hip-toolchain-rdc.hip
===
--- test/Driver/hip-toolchain-rdc.hip
+++ test/Driver/hip-toolchain-rdc.hip
@@ -12,10 +12,11 @@
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck %s
 
-// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa" 
+// CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx803"
 // CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fvisibility" "hidden"
+// CHECK-SAME: "-fapply-global-visibility-to-externs"
 // CHECK-SAME: {{.*}} "-o" [[A_BC:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]]
 
@@ -23,6 +24,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" {{.*}} "-target-cpu" "gfx803"
 // CHECK-SAME: "-fcuda-is-device" "-fgpu-rdc" "-fvisibility" "hidden"
+// CHECK-SAME: "-fapply-global-visibility-to-externs"
 // CHECK-SAME: {{.*}} "-o" [[B_BC:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[B_SRC:".*b.hip"]]
 
Index: test/Driver/hip-toolchain-no-rdc.hip
===
--- test/Driver/hip-toolchain-no-rdc.hip
+++ test/Driver/hip-toolchain-no-rdc.hip
@@ -20,6 +20,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx803"
 // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden"
+// CHECK-SAME: "-fapply-global-visibility-to-externs"
 // CHECK-SAME: {{.*}} "-o" [[A_BC_803:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[A_SRC:".*a.cu"]]
 
@@ -47,6 +48,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" {{.*}} "-target-cpu" "gfx900"
 // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden"
+// CHECK-SAME: "-fapply-global-visibility-to-externs"
 // CHECK-SAME: {{.*}} "-o" [[A_BC_900:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[A_SRC]]
 
@@ -89,6 +91,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" {{.*}} "-target-cpu" "gfx803"
 // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden"
+// CHECK-SAME: "-fapply-global-visibility-to-externs"
 // CHECK-SAME: {{.*}} "-o" [[B_BC_803:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[B_SRC:".*b.hip"]]
 
@@ -116,6 +119,7 @@
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu" "-emit-llvm-bc"
 // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" {{.*}} "-target-cpu" "gfx900"
 // CHECK-SAME: "-fcuda-is-device" "-fvisibility" "hidden"
+// CHECK-SAME: "-fapply-global-visibility-to-externs"
 // CHECK-SAME: {{.*}} "-o" [[B_BC_900:".*bc"]] "-x" "hip"
 // CHECK-SAME: {{.*}} [[B_SRC]]
 
Index: test/Driver/amdgpu-visibility.cl
===
--- test/Driver/amdgpu-visibility.cl
+++ test/Driver/amdgpu-visibility.cl
@@ -2,6 +2,14 @@
 // RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility=protected  %s 2>&1 | FileCheck -check-prefix=OVERRIDE-PROTECTED  %s
 // RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility-ms-compat  %s 2>&1 | FileCheck -check-prefix=OVERRIDE-MS  %s
 
-// DEFAULT: "-fvisibility" "hidden"
+// DEFAULT-DAG: "-fvisibility" "hidden"
+// DEFAULT-DAG: "-fapply-global-visibility-to-externs"
+
+// OVERRIDE-PROTECTED-NOT: "-fapply-global-visibility-to-externs"
 // OVERRIDE-PROTECTED: "-fvisibility" "protected"
-// OVERRIDE-MS:  "-fvisibility" "hidden" "-ftype-visibility" "default"
+// OVERRIDE-PROTECTED-NOT: "-fapply-global-visibility-to-externs"
+
+// OVERRIDE-MS-NOT: "-fapply-global-visibility-to-externs"
+// OVERRIDE-MS-DAG: "-fvisibility" "hidden"
+// OVERRIDE-MS-DAG: "-ftype-visibility" "default"
+// OVERRIDE-MS-NOT: "-fapply-global-visibility-to-externs"
Index: test/CodeGen/set-visibility-for-decls.c
===
--- /dev/null
+++ test/CodeGen/set-visibility-for-decls.c
@@ -0,0 +1,42 @@

[PATCH] D56871: [AMDGPU] Require at least protected visibility for certain symbols

2019-01-18 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 182561.
scott.linder added a comment.

Update option name


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56871/new/

https://reviews.llvm.org/D56871

Files:
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  test/CodeGenOpenCL/visibility.cl

Index: test/CodeGenOpenCL/visibility.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/visibility.cl
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -std=cl2.0 -fapply-global-visibility-to-externs -fvisibility default -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-DEFAULT %s
+// RUN: %clang_cc1 -std=cl2.0 -fapply-global-visibility-to-externs -fvisibility protected -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-PROTECTED %s
+// RUN: %clang_cc1 -std=cl2.0 -fapply-global-visibility-to-externs -fvisibility hidden -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-HIDDEN %s
+
+// REQUIRES: amdgpu-registered-target
+
+// FVIS-DEFAULT:  @glob = local_unnamed_addr
+// FVIS-PROTECTED: @glob = protected local_unnamed_addr
+// FVIS-HIDDEN: @glob = hidden local_unnamed_addr
+int glob = 0;
+// FVIS-DEFAULT:  @glob_hidden = hidden local_unnamed_addr
+// FVIS-PROTECTED: @glob_hidden = hidden local_unnamed_addr
+// FVIS-HIDDEN: @glob_hidden = hidden local_unnamed_addr
+__attribute__((visibility("hidden"))) int glob_hidden = 0;
+// FVIS-DEFAULT:  @glob_protected = protected local_unnamed_addr
+// FVIS-PROTECTED: @glob_protected = protected local_unnamed_addr
+// FVIS-HIDDEN: @glob_protected = protected local_unnamed_addr
+__attribute__((visibility("protected"))) int glob_protected = 0;
+// FVIS-DEFAULT:  @glob_default = local_unnamed_addr
+// FVIS-PROTECTED: @glob_default = local_unnamed_addr
+// FVIS-HIDDEN: @glob_default = local_unnamed_addr
+__attribute__((visibility("default"))) int glob_default = 0;
+
+// FVIS-DEFAULT:  @ext = external local_unnamed_addr
+// FVIS-PROTECTED: @ext = external protected local_unnamed_addr
+// FVIS-HIDDEN: @ext = external hidden local_unnamed_addr
+extern int ext;
+// FVIS-DEFAULT:  @ext_hidden = external hidden local_unnamed_addr
+// FVIS-PROTECTED: @ext_hidden = external hidden local_unnamed_addr
+// FVIS-HIDDEN: @ext_hidden = external hidden local_unnamed_addr
+__attribute__((visibility("hidden"))) extern int ext_hidden;
+// FVIS-DEFAULT:  @ext_protected = external protected local_unnamed_addr
+// FVIS-PROTECTED: @ext_protected = external protected local_unnamed_addr
+// FVIS-HIDDEN: @ext_protected = external protected local_unnamed_addr
+__attribute__((visibility("protected"))) extern int ext_protected;
+// FVIS-DEFAULT:  @ext_default = external local_unnamed_addr
+// FVIS-PROTECTED: @ext_default = external local_unnamed_addr
+// FVIS-HIDDEN: @ext_default = external local_unnamed_addr
+__attribute__((visibility("default"))) extern int ext_default;
+
+// FVIS-DEFAULT: define amdgpu_kernel void @kern()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @kern()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @kern()
+kernel void kern() {}
+// FVIS-DEFAULT: define protected amdgpu_kernel void @kern_hidden()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @kern_hidden()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @kern_hidden()
+__attribute__((visibility("hidden"))) kernel void kern_hidden() {}
+// FVIS-DEFAULT: define protected amdgpu_kernel void @kern_protected()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @kern_protected()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @kern_protected()
+__attribute__((visibility("protected"))) kernel void kern_protected() {}
+// FVIS-DEFAULT: define amdgpu_kernel void @kern_default()
+// FVIS-PROTECTED: define amdgpu_kernel void @kern_default()
+// FVIS-HIDDEN: define amdgpu_kernel void @kern_default()
+__attribute__((visibility("default"))) kernel void kern_default() {}
+
+// FVIS-DEFAULT: define void @func()
+// FVIS-PROTECTED: define protected void @func()
+// FVIS-HIDDEN: define hidden void @func()
+void func() {}
+// FVIS-DEFAULT: define hidden void @func_hidden()
+// FVIS-PROTECTED: define hidden void @func_hidden()
+// FVIS-HIDDEN: define hidden void @func_hidden()
+__attribute__((visibility("hidden"))) void func_hidden() {}
+// FVIS-DEFAULT: define protected void @func_protected()
+// FVIS-PROTECTED: define protected void @func_protected()
+// FVIS-HIDDEN: define protected void @func_protected()
+__attribute__((visibility("protected"))) void func_protected() {}
+// FVIS-DEFAULT: define void @func_default()
+// FVIS-PROTECTED: define void @func_default()
+// FVIS-HIDDEN: define void @func_default()
+__attribute__((visibility("default"))) void func_default() {}
+
+void use() {
+glob = ext + ext_hidden + ext_protected + ext_default;
+}
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/Co

[PATCH] D56868: Add -fapply-global-visibility-to-externs for -cc1

2019-01-28 Thread Scott Linder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL352391: Add -fapply-global-visibility-to-externs for -cc1 
(authored by scott.linder, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D56868?vs=182559&id=183886#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56868/new/

https://reviews.llvm.org/D56868

Files:
  cfe/trunk/include/clang/Basic/LangOptions.def
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/Driver/ToolChains/AMDGPU.cpp
  cfe/trunk/lib/Driver/ToolChains/HIP.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/set-visibility-for-decls.c
  cfe/trunk/test/Driver/amdgpu-visibility.cl
  cfe/trunk/test/Driver/hip-toolchain-no-rdc.hip
  cfe/trunk/test/Driver/hip-toolchain-rdc.hip

Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -731,9 +731,11 @@
   }
   if (!D)
 return;
-  // Set visibility for definitions.
+  // Set visibility for definitions, and for declarations if requested globally
+  // or set explicitly.
   LinkageInfo LV = D->getLinkageAndVisibility();
-  if (LV.isVisibilityExplicit() || !GV->isDeclarationForLinker())
+  if (LV.isVisibilityExplicit() || getLangOpts().SetVisibilityForExternDecls ||
+  !GV->isDeclarationForLinker())
 GV->setVisibility(GetLLVMVisibility(LV.getVisibility()));
 }
 
Index: cfe/trunk/lib/Driver/ToolChains/HIP.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/HIP.cpp
+++ cfe/trunk/lib/Driver/ToolChains/HIP.cpp
@@ -293,8 +293,10 @@
   // Default to "hidden" visibility, as object level linking will not be
   // supported for the foreseeable future.
   if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
- options::OPT_fvisibility_ms_compat))
+ options::OPT_fvisibility_ms_compat)) {
 CC1Args.append({"-fvisibility", "hidden"});
+CC1Args.push_back("-fapply-global-visibility-to-externs");
+  }
 }
 
 llvm::opt::DerivedArgList *
Index: cfe/trunk/lib/Driver/ToolChains/AMDGPU.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/AMDGPU.cpp
+++ cfe/trunk/lib/Driver/ToolChains/AMDGPU.cpp
@@ -108,5 +108,6 @@
  options::OPT_fvisibility_ms_compat)) {
 CC1Args.push_back("-fvisibility");
 CC1Args.push_back("hidden");
+CC1Args.push_back("-fapply-global-visibility-to-externs");
   }
 }
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -2501,6 +2501,9 @@
   if (Args.hasArg(OPT_fvisibility_global_new_delete_hidden))
 Opts.GlobalAllocationFunctionVisibilityHidden = 1;
 
+  if (Args.hasArg(OPT_fapply_global_visibility_to_externs))
+Opts.SetVisibilityForExternDecls = 1;
+
   if (Args.hasArg(OPT_ftrapv)) {
 Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping);
 // Set the handler, if one is specified.
Index: cfe/trunk/include/clang/Driver/CC1Options.td
===
--- cfe/trunk/include/clang/Driver/CC1Options.td
+++ cfe/trunk/include/clang/Driver/CC1Options.td
@@ -702,6 +702,8 @@
   HelpText<"Default type and symbol visibility">;
 def ftype_visibility : Separate<["-"], "ftype-visibility">,
   HelpText<"Default type visibility">;
+def fapply_global_visibility_to_externs : Flag<["-"], "fapply-global-visibility-to-externs">,
+  HelpText<"Apply global symbol visibility to external declarations without an explicit visibility">;
 def ftemplate_depth : Separate<["-"], "ftemplate-depth">,
   HelpText<"Maximum depth of recursive template instantiation">;
 def foperator_arrow_depth : Separate<["-"], "foperator-arrow-depth">,
Index: cfe/trunk/include/clang/Basic/LangOptions.def
===
--- cfe/trunk/include/clang/Basic/LangOptions.def
+++ cfe/trunk/include/clang/Basic/LangOptions.def
@@ -261,6 +261,8 @@
  "default visibility for functions and variables [-fvisibility]")
 ENUM_LANGOPT(TypeVisibilityMode, Visibility, 3, DefaultVisibility,
  "default visibility for types [-ftype-visibility]")
+LANGOPT(SetVisibilityForExternDecls, 1, 0,
+"apply global symbol visibility to external declarations without an explicit visibility")
 ENUM_LANGOPT(StackProtector, StackProtectorMode, 2, SSPOff,
  "stack protector mode")
 ENUM_LANGOPT(TrivialAutoVarInit, TrivialAutoVarInitKind, 2, TrivialAutoVarInitKind::Uninitialized,
Index: cfe/trunk/test/CodeGen/set-visibility-for-decls.c
==

[PATCH] D56871: [AMDGPU] Require at least protected visibility for certain symbols

2019-01-28 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Ping


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56871/new/

https://reviews.llvm.org/D56871



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


[PATCH] D51223: Update tests for new YAMLIO polymorphic traits

2018-10-31 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 171936.
scott.linder added a comment.

Rebase

@klimek is there anyone I should add to take a look at this? As far as the YAML 
is concerned I believe this is a non-functional change.


https://reviews.llvm.org/D51223

Files:
  unittests/Tooling/DiagnosticsYamlTest.cpp
  unittests/Tooling/RefactoringActionRulesTest.cpp


Index: unittests/Tooling/RefactoringActionRulesTest.cpp
===
--- unittests/Tooling/RefactoringActionRulesTest.cpp
+++ unittests/Tooling/RefactoringActionRulesTest.cpp
@@ -117,8 +117,8 @@
  "Key: 'input.cpp:30'\n"
  "FilePath:input.cpp\n"
  "Error:   ''\n"
- "InsertedHeaders: \n"
- "RemovedHeaders:  \n"
+ "InsertedHeaders: []\n"
+ "RemovedHeaders:  []\n"
  "Replacements:\n" // Extra whitespace here!
  "  - FilePath:input.cpp\n"
  "Offset:  30\n"
Index: unittests/Tooling/DiagnosticsYamlTest.cpp
===
--- unittests/Tooling/DiagnosticsYamlTest.cpp
+++ unittests/Tooling/DiagnosticsYamlTest.cpp
@@ -82,7 +82,7 @@
 "Message: 'message #3'\n"
 "FileOffset:  72\n"
 "FilePath:'path/to/source2.cpp'\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n",
 YamlContentStream.str());
 }
@@ -113,7 +113,7 @@
 "Message: 'message #3'\n"
 "FileOffset:  98\n"
 "FilePath:path/to/source.cpp\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n";
   TranslationUnitDiagnostics TUDActual;
   yaml::Input YAML(YamlContent);


Index: unittests/Tooling/RefactoringActionRulesTest.cpp
===
--- unittests/Tooling/RefactoringActionRulesTest.cpp
+++ unittests/Tooling/RefactoringActionRulesTest.cpp
@@ -117,8 +117,8 @@
  "Key: 'input.cpp:30'\n"
  "FilePath:input.cpp\n"
  "Error:   ''\n"
- "InsertedHeaders: \n"
- "RemovedHeaders:  \n"
+ "InsertedHeaders: []\n"
+ "RemovedHeaders:  []\n"
  "Replacements:\n" // Extra whitespace here!
  "  - FilePath:input.cpp\n"
  "Offset:  30\n"
Index: unittests/Tooling/DiagnosticsYamlTest.cpp
===
--- unittests/Tooling/DiagnosticsYamlTest.cpp
+++ unittests/Tooling/DiagnosticsYamlTest.cpp
@@ -82,7 +82,7 @@
 "Message: 'message #3'\n"
 "FileOffset:  72\n"
 "FilePath:'path/to/source2.cpp'\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n",
 YamlContentStream.str());
 }
@@ -113,7 +113,7 @@
 "Message: 'message #3'\n"
 "FileOffset:  98\n"
 "FilePath:path/to/source.cpp\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n";
   TranslationUnitDiagnostics TUDActual;
   yaml::Input YAML(YamlContent);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53768: Add VerboseOutputStream to CompilerInstance

2018-11-05 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Ping


Repository:
  rC Clang

https://reviews.llvm.org/D53768



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


[PATCH] D53153: [OpenCL] Mark namespace scope variables and kernel functions with default visibility

2018-11-05 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Ping


https://reviews.llvm.org/D53153



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


[PATCH] D53153: [OpenCL] Mark kernel functions with default visibility

2018-11-06 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

I don't believe that is currently the case (the unrestricted linking of OCL 
code to OCL code via a dynamic linker), but we do have the notion of a static 
link step, followed by dynamic linking at runtime. The static link step is 
currently via IR, but we plan to support linking object files. Maybe I 
misunderstand the distinction between linkage and visibility, but it seems 
reasonable that a user would want to have e.g. a non-kernel function 
participate in static linking, but not be preemptible in the final shared 
object. The intention with this patch is to allow this with something like 
`-fvisibility hidden` without disrupting kernel symbols, which must appear in 
the dynsym for the reasons mentioned earlier in the thread.


https://reviews.llvm.org/D53153



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


[PATCH] D54489: Implement -frecord-gcc-switches

2018-11-13 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
Herald added a subscriber: cfe-commits.

See the parent revision https://reviews.llvm.org/D54487 for differences between 
this implementation and the equivalent GCC option.


Repository:
  rC Clang

https://reviews.llvm.org/D54489

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/clang_f_opts.c

Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -538,3 +538,10 @@
 // RUN: %clang -### -S -fomit-frame-pointer -fno-omit-frame-pointer -pg %s 2>&1 | FileCheck -check-prefix=CHECK-MIX-NO-OMIT-FP-PG %s
 // CHECK-NO-MIX-OMIT-FP-PG: '-fomit-frame-pointer' not allowed with '-pg'
 // CHECK-MIX-NO-OMIT-FP-PG-NOT: '-fomit-frame-pointer' not allowed with '-pg'
+
+// RUN: %clang -### -S -frecord-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -fno-record-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -fno-record-gcc-switches -frecord-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -frecord-gcc-switches -fno-record-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// CHECK-RECORD-GCC-SWITCHES: "-record-command-line"
+// CHECK-NO-RECORD-GCC-SWITCHES-NOT: "-record-command-line"
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -627,6 +627,7 @@
   Args.hasFlag(OPT_ffine_grained_bitfield_accesses,
OPT_fno_fine_grained_bitfield_accesses, false);
   Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
+  Opts.RecordCommandLine = Args.getLastArgValue(OPT_record_command_line);
   Opts.MergeAllConstants = Args.hasArg(OPT_fmerge_all_constants);
   Opts.NoCommon = Args.hasArg(OPT_fno_common);
   Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4985,14 +4985,18 @@
 
   const char *Exec = D.getClangProgramPath();
 
-  // Optionally embed the -cc1 level arguments into the debug info, for build
-  // analysis.
+  // Optionally embed the -cc1 level arguments into the debug info or a
+  // section, for build analysis.
   // Also record command line arguments into the debug info if
   // -grecord-gcc-switches options is set on.
   // By default, -gno-record-gcc-switches is set on and no recording.
-  if (TC.UseDwarfDebugFlags() ||
+  auto GRecordSwitches =
   Args.hasFlag(options::OPT_grecord_gcc_switches,
-   options::OPT_gno_record_gcc_switches, false)) {
+   options::OPT_gno_record_gcc_switches, false);
+  auto FRecordSwitches =
+  Args.hasFlag(options::OPT_frecord_gcc_switches,
+   options::OPT_fno_record_gcc_switches, false);
+  if (TC.UseDwarfDebugFlags() || GRecordSwitches || FRecordSwitches) {
 ArgStringList OriginalArgs;
 for (const auto &Arg : Args)
   Arg->render(Args, OriginalArgs);
@@ -5005,8 +5009,15 @@
   Flags += " ";
   Flags += EscapedArg;
 }
-CmdArgs.push_back("-dwarf-debug-flags");
-CmdArgs.push_back(Args.MakeArgString(Flags));
+auto FlagsArgString = Args.MakeArgString(Flags);
+if (TC.UseDwarfDebugFlags() || GRecordSwitches) {
+  CmdArgs.push_back("-dwarf-debug-flags");
+  CmdArgs.push_back(FlagsArgString);
+}
+if (FRecordSwitches) {
+  CmdArgs.push_back("-record-command-line");
+  CmdArgs.push_back(FlagsArgString);
+}
   }
 
   // Host-side cuda compilation receives all device-side outputs in a single
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -1402,6 +1402,9 @@
   /// Emit the Clang version as llvm.ident metadata.
   void EmitVersionIdentMetadata();
 
+  /// Emit the Clang commandline as llvm.commandline metadata.
+  void EmitCommandLineMetadata();
+
   /// Emits target specific Metadata for global declarations.
   void EmitTargetMetadata();
 
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -587,6 +587,9 @@
   if (getCodeGenOpts().EmitVersionIdentMetadata)
 EmitVersionIdentMetadata();
 
+  if (!getCodeGenOpts().RecordCommandLine.empty())
+EmitCommandLineMetadata();
+
   EmitTargetMeta

[PATCH] D54489: Implement -frecord-gcc-switches

2018-11-13 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In https://reviews.llvm.org/D54489#1297504, @troyj wrote:

> I realize that you're probably striving for option compatibility with gcc, 
> but continuing to name it -frecord-gcc-switches when it actually records 
> Clang switches seems weird to me.  It almost sounds like something that would 
> dump gcc equivalents of all Clang options, or maybe let you know which Clang 
> options you've used that match gcc options.  Either way, by the name -- if 
> you aren't familiar with the gcc option -- it doesn't read like it records 
> Clang options.
>
> Would it be that bad to name it -frecord-clang-switches?  Or just 
> -frecord-switches?


I agree, and this was my original plan, but then I noticed that Clang already 
implements -grecord-gcc-switches and so I decided to mirror the naming for the 
-f variant as well.

If anything I think dropping the -gcc- altogether would make the most sense. I 
don't understand why GCC includes it in the first place.


Repository:
  rC Clang

https://reviews.llvm.org/D54489



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


[PATCH] D48144: [Support] Teach YAMLIO about polymorphic types

2018-11-14 Thread Scott Linder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC346884: [Support] Teach YAMLIO about polymorphic types 
(authored by scott.linder, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48144?vs=171918&id=174078#toc

Repository:
  rC Clang

https://reviews.llvm.org/D48144

Files:
  unittests/Tooling/DiagnosticsYamlTest.cpp
  unittests/Tooling/RefactoringActionRulesTest.cpp


Index: unittests/Tooling/DiagnosticsYamlTest.cpp
===
--- unittests/Tooling/DiagnosticsYamlTest.cpp
+++ unittests/Tooling/DiagnosticsYamlTest.cpp
@@ -82,7 +82,7 @@
 "Message: 'message #3'\n"
 "FileOffset:  72\n"
 "FilePath:'path/to/source2.cpp'\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n",
 YamlContentStream.str());
 }
@@ -113,7 +113,7 @@
 "Message: 'message #3'\n"
 "FileOffset:  98\n"
 "FilePath:path/to/source.cpp\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n";
   TranslationUnitDiagnostics TUDActual;
   yaml::Input YAML(YamlContent);
Index: unittests/Tooling/RefactoringActionRulesTest.cpp
===
--- unittests/Tooling/RefactoringActionRulesTest.cpp
+++ unittests/Tooling/RefactoringActionRulesTest.cpp
@@ -117,8 +117,8 @@
  "Key: 'input.cpp:30'\n"
  "FilePath:input.cpp\n"
  "Error:   ''\n"
- "InsertedHeaders: \n"
- "RemovedHeaders:  \n"
+ "InsertedHeaders: []\n"
+ "RemovedHeaders:  []\n"
  "Replacements:\n" // Extra whitespace here!
  "  - FilePath:input.cpp\n"
  "Offset:  30\n"


Index: unittests/Tooling/DiagnosticsYamlTest.cpp
===
--- unittests/Tooling/DiagnosticsYamlTest.cpp
+++ unittests/Tooling/DiagnosticsYamlTest.cpp
@@ -82,7 +82,7 @@
 "Message: 'message #3'\n"
 "FileOffset:  72\n"
 "FilePath:'path/to/source2.cpp'\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n",
 YamlContentStream.str());
 }
@@ -113,7 +113,7 @@
 "Message: 'message #3'\n"
 "FileOffset:  98\n"
 "FilePath:path/to/source.cpp\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n";
   TranslationUnitDiagnostics TUDActual;
   yaml::Input YAML(YamlContent);
Index: unittests/Tooling/RefactoringActionRulesTest.cpp
===
--- unittests/Tooling/RefactoringActionRulesTest.cpp
+++ unittests/Tooling/RefactoringActionRulesTest.cpp
@@ -117,8 +117,8 @@
  "Key: 'input.cpp:30'\n"
  "FilePath:input.cpp\n"
  "Error:   ''\n"
- "InsertedHeaders: \n"
- "RemovedHeaders:  \n"
+ "InsertedHeaders: []\n"
+ "RemovedHeaders:  []\n"
  "Replacements:\n" // Extra whitespace here!
  "  - FilePath:input.cpp\n"
  "Offset:  30\n"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53768: Add VerboseOutputStream to CompilerInstance

2018-11-14 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Ping


Repository:
  rC Clang

https://reviews.llvm.org/D53768



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


[PATCH] D54489: Implement -frecord-command-line (-frecord-gcc-switches)

2018-11-14 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 174104.
scott.linder retitled this revision from "Implement -frecord-gcc-switches" to 
"Implement -frecord-command-line (-frecord-gcc-switches)".
scott.linder added a comment.

Change canonical option name to -frecord-command-line and add an alias from 
-frecord-gcc-switches

Do the same for -grecord-command-line/-grecord-gcc-switches


https://reviews.llvm.org/D54489

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/clang_f_opts.c
  test/Driver/debug-options.c

Index: test/Driver/debug-options.c
===
--- test/Driver/debug-options.c
+++ test/Driver/debug-options.c
@@ -149,6 +149,17 @@
 // RUN: %clang -### -c -O3 -ffunction-sections -grecord-gcc-switches %s 2>&1 \
 // | FileCheck -check-prefix=GRECORD_OPT %s
 //
+// RUN: %clang -### -c -grecord-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GRECORD %s
+// RUN: %clang -### -c -gno-record-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GNO_RECORD %s
+// RUN: %clang -### -c -grecord-command-line -gno-record-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GNO_RECORD %s/
+// RUN: %clang -### -c -grecord-command-line -o - %s 2>&1 \
+// | FileCheck -check-prefix=GRECORD_O %s
+// RUN: %clang -### -c -O3 -ffunction-sections -grecord-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GRECORD_OPT %s
+//
 // RUN: %clang -### -c -gstrict-dwarf -gno-strict-dwarf %s 2>&1 \
 // RUN:| FileCheck -check-prefix=GIGNORE %s
 //
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -538,3 +538,14 @@
 // RUN: %clang -### -S -fomit-frame-pointer -fno-omit-frame-pointer -pg %s 2>&1 | FileCheck -check-prefix=CHECK-MIX-NO-OMIT-FP-PG %s
 // CHECK-NO-MIX-OMIT-FP-PG: '-fomit-frame-pointer' not allowed with '-pg'
 // CHECK-MIX-NO-OMIT-FP-PG-NOT: '-fomit-frame-pointer' not allowed with '-pg'
+
+// RUN: %clang -### -S -frecord-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -fno-record-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -fno-record-gcc-switches -frecord-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -frecord-gcc-switches -fno-record-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -fno-record-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -fno-record-command-line -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -frecord-command-line -fno-record-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// CHECK-RECORD-GCC-SWITCHES: "-record-command-line"
+// CHECK-NO-RECORD-GCC-SWITCHES-NOT: "-record-command-line"
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -627,6 +627,7 @@
   Args.hasFlag(OPT_ffine_grained_bitfield_accesses,
OPT_fno_fine_grained_bitfield_accesses, false);
   Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
+  Opts.RecordCommandLine = Args.getLastArgValue(OPT_record_command_line);
   Opts.MergeAllConstants = Args.hasArg(OPT_fmerge_all_constants);
   Opts.NoCommon = Args.hasArg(OPT_fno_common);
   Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4985,14 +4985,18 @@
 
   const char *Exec = D.getClangProgramPath();
 
-  // Optionally embed the -cc1 level arguments into the debug info, for build
-  // analysis.
+  // Optionally embed the -cc1 level arguments into the debug info or a
+  // section, for build analysis.
   // Also record command line arguments into the debug info if
   // -grecord-gcc-switches options is set on.
   // By default, -gno-record-gcc-switches is set on and no recording.
-  if (TC.UseDwarfDebugFlags() ||
-  Args.hasFlag(options::OPT_grecord_gcc_switches,
-   options::OPT_gno_record_gcc_switches, false)) {
+  auto GRecordSwitches =
+  Args.hasFlag(options::OPT_grecord_command_line,
+   options::OPT_gno_record_c

[PATCH] D54489: Implement -frecord-command-line (-frecord-gcc-switches)

2018-11-15 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added inline comments.



Comment at: docs/ClangCommandLineReference.rst:797
+
+Generate a section .LLVM.command.line containing the clang driver command line.
+

rjmccall wrote:
> 1. Is this section always called `.LLVM.command.line`, or does it differ by 
> target object-file format?
> 2. For that matter, is this actually supported by all object-file formats?
> 3. Please describe the format of the section.  Is it just a flat C string?  
> Is it nul-terminated?  Are different options combined with spaces, and if so, 
> does that mean that interior spaces in command line arguments are impossible 
> to distinguish?  If the latter, I assume that this is required behavior for 
> backward compatibility; please at least apologize for that in the 
> documentation. :)
For (1) I think the answer should be that we emit `.LLVM.command.line` (or 
whatever name we land on) for every object-file format with the concept of 
names for sections.

For (2), I have only implemented this for ELF so far in LLVM. I don't know how 
reasonable that is, and if it isn't I can look at adding it to other common 
object-file formats that LLVM supports.

For (3), my current proposal for the format is the same as the `.comment` 
section for idents: null-surrounded strings. Interior spaces are escaped, in 
the same manner as for the -g variant. There may still be more thought to put 
into the format, as the GCC version null-terminates each individual option; the 
reason I avoided this is that during object linking the options of many 
command-lines simply get mixed together, which seems less than useful.

As an example, for ELF `clang -frecord-command-line -S "foo .c"` produces the 
ASM:

```
.section.LLVM.command.line,"MS",@progbits,1
.zero   1
.ascii  "/usr/local/bin/clang-8 -frecord-command-line -S foo\\ .c"
.zero   1
```

And for multiple command-lines in a single object (e.g. linking three objects 
with recorded command-lines) this would be:

```
.section.LLVM.command.line,"MS",@progbits,1
.zero   1
.ascii  "/usr/local/bin/clang-8 -frecord-command-line -c foo\\ .c"
.zero   1
.ascii  "/usr/local/bin/clang-8 -frecord-command-line -some -unique -options -c 
bar.c"
.zero   1
.ascii  "/usr/local/bin/clang-8 -frecord-command-line -something -else -c baz.c"
.zero   1
```

I will try to capture more of this in the documentation.


https://reviews.llvm.org/D54489



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


[PATCH] D54489: Implement -frecord-command-line (-frecord-gcc-switches)

2018-11-15 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Looking a bit further, it seems some other object-file formats have conventions 
for naming (e.g. Mach-O sections are `_snake_case`) and so `.LLVM.command.line` 
may not end up being what we want universally.

Additionally it seems things like `.ident` are not supported by all object-file 
formats in LLVM; using Mach-O as an example again, it uses the default of "no 
.ident support", and I don't see the ident in the .S or .o


https://reviews.llvm.org/D54489



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


[PATCH] D51223: Update tests for new YAMLIO polymorphic traits

2018-11-15 Thread Scott Linder via Phabricator via cfe-commits
scott.linder accepted this revision.
scott.linder added a comment.
This revision is now accepted and ready to land.

r346884


https://reviews.llvm.org/D51223



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


[PATCH] D51223: Update tests for new YAMLIO polymorphic traits

2018-11-15 Thread Scott Linder via Phabricator via cfe-commits
scott.linder closed this revision.
scott.linder added a comment.

r346884


https://reviews.llvm.org/D51223



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


[PATCH] D53329: Generate DIFile with main program if source is not available

2018-11-16 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In https://reviews.llvm.org/D53329#1300435, @dblaikie wrote:

> Thanks!
>
> So I can see where/how this fails now - the LLVM backend seems to require 
> that if any file has embedded source, they all do. Would you be able to/would 
> you mind adding a debug info verifier check for this? That'd help make this 
> fail sooner. (@scott.linder - perhaps you'd be able to/interested in doing 
> this - looks like you wrote the initial implementation?)
>
> Beyond that, then the question is whether this fix is the right way to 
> satisfy that requirement (I'm assuming the requirement is reasonable - though 
> I've not looked at the embedded source support & have no idea if there's a 
> way/it's reasonable to support some embedded source and some not). My big 
> question & I've tried to do some debugging to better understand this - but 
> don't have the time to dive much further into it (& haven't really figured it 
> out as yet): Why is this source not accessible through this API at this 
> point? is the fallback to the main file always accurate?
>
> (as far as I got was figuring out that SourceManager::getBufferData had an 
> SLoc with isFile == true for the header, but isFile was false for the SLocs 
> related to the .cpp file. Can't say I know why that is/what that means & 
> would like to understand that (or someone else more familiar with this stuff 
> who already knows can review this code) before approving this patch - if you 
> could help explain this, that'd be great)


I can certainly update the verifier; my initial implementation should have 
included tests for this case so I would have noticed how unpleasantly it fails. 
I might be a bit slow to get a patch up, as I'm on vacation all next week.

The decision to require "all or nothing" for embedded source came after quite a 
bit of discussion, and the original proposal does include a boolean flag (see 
http://dwarfstd.org/ShowIssue.php?issue=180201.1). LLVM is still the only 
implementation I know of, and it is not in any actual DWARF standard yet, so if 
there are strong use-cases for allowing some sources be absent this could still 
be changed.


Repository:
  rC Clang

https://reviews.llvm.org/D53329



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


[PATCH] D54489: Implement -frecord-command-line (-frecord-gcc-switches)

2018-11-16 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 174429.
scott.linder added a comment.

Update documentation for new option and error in the driver when generating for 
unsupported object-file format.


https://reviews.llvm.org/D54489

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/clang_f_opts.c
  test/Driver/debug-options.c

Index: test/Driver/debug-options.c
===
--- test/Driver/debug-options.c
+++ test/Driver/debug-options.c
@@ -157,6 +157,17 @@
 // RUN: %clang -### -c -O3 -ffunction-sections -grecord-gcc-switches %s 2>&1 \
 // | FileCheck -check-prefix=GRECORD_OPT %s
 //
+// RUN: %clang -### -c -grecord-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GRECORD %s
+// RUN: %clang -### -c -gno-record-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GNO_RECORD %s
+// RUN: %clang -### -c -grecord-command-line -gno-record-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GNO_RECORD %s/
+// RUN: %clang -### -c -grecord-command-line -o - %s 2>&1 \
+// | FileCheck -check-prefix=GRECORD_O %s
+// RUN: %clang -### -c -O3 -ffunction-sections -grecord-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GRECORD_OPT %s
+//
 // RUN: %clang -### -c -gstrict-dwarf -gno-strict-dwarf %s 2>&1 \
 // RUN:| FileCheck -check-prefix=GIGNORE %s
 //
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -538,3 +538,18 @@
 // RUN: %clang -### -S -fomit-frame-pointer -fno-omit-frame-pointer -pg %s 2>&1 | FileCheck -check-prefix=CHECK-MIX-NO-OMIT-FP-PG %s
 // CHECK-NO-MIX-OMIT-FP-PG: '-fomit-frame-pointer' not allowed with '-pg'
 // CHECK-MIX-NO-OMIT-FP-PG-NOT: '-fomit-frame-pointer' not allowed with '-pg'
+
+// RUN: %clang -### -S -target x86_64-unknown-linux -frecord-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-gcc-switches -frecord-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -frecord-gcc-switches -fno-record-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-command-line -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -frecord-command-line -fno-record-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// Test with a couple examples of non-ELF object file formats
+// RUN: %clang -### -S -target x86_64-unknown-macosx -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
+// RUN: %clang -### -S -target x86_64-unknown-windows -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
+// CHECK-RECORD-GCC-SWITCHES: "-record-command-line"
+// CHECK-NO-RECORD-GCC-SWITCHES-NOT: "-record-command-line"
+// CHECK-RECORD-GCC-SWITCHES-ERROR: error: unsupported option '-frecord-command-line' for target
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -644,6 +644,7 @@
   Args.hasFlag(OPT_ffine_grained_bitfield_accesses,
OPT_fno_fine_grained_bitfield_accesses, false);
   Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
+  Opts.RecordCommandLine = Args.getLastArgValue(OPT_record_command_line);
   Opts.MergeAllConstants = Args.hasArg(OPT_fmerge_all_constants);
   Opts.NoCommon = Args.hasArg(OPT_fno_common);
   Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -5033,14 +5033,22 @@
 
   const char *Exec = D.getClangProgramPath();
 
-  // Optionally embed the -cc1 level arguments into the debug info, for build
-  // analysis.
+  // Optionally embed the -cc1 level arguments into the debug info or a
+

[PATCH] D53329: Generate DIFile with main program if source is not available

2018-11-27 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

See https://reviews.llvm.org/D54953 for the Verifier work.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53329/new/

https://reviews.llvm.org/D53329



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


[PATCH] D54489: Implement -frecord-command-line (-frecord-gcc-switches)

2018-11-27 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 175540.
scott.linder added a comment.

Update documentation for new option


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54489/new/

https://reviews.llvm.org/D54489

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/clang_f_opts.c
  test/Driver/debug-options.c

Index: test/Driver/debug-options.c
===
--- test/Driver/debug-options.c
+++ test/Driver/debug-options.c
@@ -157,6 +157,17 @@
 // RUN: %clang -### -c -O3 -ffunction-sections -grecord-gcc-switches %s 2>&1 \
 // | FileCheck -check-prefix=GRECORD_OPT %s
 //
+// RUN: %clang -### -c -grecord-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GRECORD %s
+// RUN: %clang -### -c -gno-record-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GNO_RECORD %s
+// RUN: %clang -### -c -grecord-command-line -gno-record-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GNO_RECORD %s/
+// RUN: %clang -### -c -grecord-command-line -o - %s 2>&1 \
+// | FileCheck -check-prefix=GRECORD_O %s
+// RUN: %clang -### -c -O3 -ffunction-sections -grecord-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GRECORD_OPT %s
+//
 // RUN: %clang -### -c -gstrict-dwarf -gno-strict-dwarf %s 2>&1 \
 // RUN:| FileCheck -check-prefix=GIGNORE %s
 //
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -538,3 +538,18 @@
 // RUN: %clang -### -S -fomit-frame-pointer -fno-omit-frame-pointer -pg %s 2>&1 | FileCheck -check-prefix=CHECK-MIX-NO-OMIT-FP-PG %s
 // CHECK-NO-MIX-OMIT-FP-PG: '-fomit-frame-pointer' not allowed with '-pg'
 // CHECK-MIX-NO-OMIT-FP-PG-NOT: '-fomit-frame-pointer' not allowed with '-pg'
+
+// RUN: %clang -### -S -target x86_64-unknown-linux -frecord-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-gcc-switches -frecord-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -frecord-gcc-switches -fno-record-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-command-line -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -frecord-command-line -fno-record-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// Test with a couple examples of non-ELF object file formats
+// RUN: %clang -### -S -target x86_64-unknown-macosx -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
+// RUN: %clang -### -S -target x86_64-unknown-windows -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
+// CHECK-RECORD-GCC-SWITCHES: "-record-command-line"
+// CHECK-NO-RECORD-GCC-SWITCHES-NOT: "-record-command-line"
+// CHECK-RECORD-GCC-SWITCHES-ERROR: error: unsupported option '-frecord-command-line' for target
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -644,6 +644,7 @@
   Args.hasFlag(OPT_ffine_grained_bitfield_accesses,
OPT_fno_fine_grained_bitfield_accesses, false);
   Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
+  Opts.RecordCommandLine = Args.getLastArgValue(OPT_record_command_line);
   Opts.MergeAllConstants = Args.hasArg(OPT_fmerge_all_constants);
   Opts.NoCommon = Args.hasArg(OPT_fno_common);
   Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -5057,14 +5057,22 @@
 
   const char *Exec = D.getClangProgramPath();
 
-  // Optionally embed the -cc1 level arguments into the debug info, for build
-  // analysis.
+  // Optionally embed the -cc1 level arguments into the debug info or a
+  // sectio

[PATCH] D53153: [OpenCL] Mark kernel functions with default visibility

2018-11-30 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D53153#1291348 , @rjmccall wrote:

> In D53153#1289380 , @scott.linder 
> wrote:
>
> > I don't believe that is currently the case (the unrestricted linking of OCL 
> > code to OCL code via a dynamic linker), but we do have the notion of a 
> > static link step, followed by dynamic linking at runtime. The static link 
> > step is currently via IR, but we plan to support linking object files. 
> > Maybe I misunderstand the distinction between linkage and visibility, but 
> > it seems reasonable that a user would want to have e.g. a non-kernel 
> > function participate in static linking, but not be preemptible in the final 
> > shared object. The intention with this patch is to allow this with 
> > something like `-fvisibility hidden` without disrupting kernel symbols, 
> > which must appear in the dynsym for the reasons mentioned earlier in the 
> > thread.
>
>
> Okay, this still doesn't need user-controlled symbol visibility.  The basic 
> question here is whether there is any need for anything other than kernel 
> functions to have dynamic linkage.  If not, then you really just need to mark 
> everything as hidden except for kernels.  You *could* do that marking in 
> Sema, but frankly that seems like an implementation detail escaping into the 
> AST, and it's just going to cause you unwanted pain and sub-optimality.  (For 
> example: `-fvisibility=hidden` doesn't actually change the visibility of 
> external declarations for reasons that make a lot of sense for 
> general-purpose environments but probably don't matter to you at all.  If 
> you're doing this to get better code-generation for references to external 
> entities that are going to end up within the image, you actually need to add 
> a visibility attribute to every single top-level declaration to get that 
> effect.  It's much easier to just do it in a pass on the module.)


If such a pass were to mark all non-kernel symbols as hidden, for example, how 
would it support languages other than OpenCL where the runtime constraints 
differ? AMDGPU supports other languages where the assumption that only kernel 
functions must be visible is not valid. Can a module pass override visibility 
without making assumptions about the source language? I may just be unfamiliar 
with Clang, and not know where this sort of pass would live.

I think a pass which only overrides kernel function visibility (i.e. by forcing 
it to be default) would always be correct, but touching other symbol visibility 
begins to make assumptions which are not necessarily valid for all languages.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53153/new/

https://reviews.llvm.org/D53153



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


[PATCH] D53329: Generate DIFile with main program if source is not available

2018-11-30 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

The Verifier patch has landed as https://reviews.llvm.org/rL348022

I do not have any more knowledge than the reviewers of the right way to handle 
providing source for remapped files, but at least compilation will warn and 
strip debug-info rather than segfault when source is provided inconsistently.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53329/new/

https://reviews.llvm.org/D53329



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


[PATCH] D53153: [OpenCL] Mark kernel functions with default visibility

2018-11-30 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D53153#1314798 , @rjmccall wrote:

> You still have the same linkage model for those other languages, right?  
> Ultimately there's something like a kernel function that has to be declared 
> specially and which becomes the only public interface of the code?


I don't think this is true for all languages targeting AMDGPU. For example, HIP 
has APIs like `hipMemcpyToSymbol` which accept a string identifying a symbol 
for a variable in global/constant address space. @yaxunl is my understanding 
about the HIP runtime requiring dynamic symbols for global variables correct 
here?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53153/new/

https://reviews.llvm.org/D53153



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


[PATCH] D53768: Add VerboseOutputStream to CompilerInstance

2018-12-03 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Ping


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53768/new/

https://reviews.llvm.org/D53768



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


[PATCH] D53153: [OpenCL] Mark kernel functions with default visibility

2018-12-03 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D53153#1315109 , @rjmccall wrote:

> Okay.  So it's still the case that all symbols will be defined within the 
> linkage unit; it's just that some things might need to get exposed outside of 
> it.
>
> LLVM does provide a `dso_local` attribute which you could use unconditionally 
> on every symbol without actually changing visibility.


It seems like `dso_local` is an IR concept, and is a guarantee of 
non-preemptability? Marking e.g. a global variable as `dso_local` in IR doesn't 
seem to affect what LLD infers about it;`computeIsPreemptible` in the ELF 
writer still believes it is preemptable, and so LLD complains when it attempts 
to generate a dynamic relocation in a read-only section (i.e. text). Is 
`dso_local` meant to convey anything to the linker?

If this is the intended behavior we could still tell LLD to assume all defined 
symbols are not preemptable with something like `-Bsymbolic`. If we support 
dynamic linking/preemption in the future we will have to revisit this, but at 
that time visibility will be meaningful.

I suppose one approach is then:

- Remove the implicit `-fvisibility=hidden` in the AMDGPU Clang toolchain
- Add a module pass to mark all global values with `dso_local`
- Add an implicit `-Bsymbolic` to the linker commandline


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53153/new/

https://reviews.llvm.org/D53153



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


[PATCH] D54489: Implement -frecord-command-line (-frecord-gcc-switches)

2018-12-10 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

There may be changes to some details in the LLVM patch; once they are finalized 
I will update the Clang patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54489/new/

https://reviews.llvm.org/D54489



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


[PATCH] D59008: [AMDGPU] Switch default dwarf version to 5

2019-03-05 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added reviewers: kzhuravl, t-tye.
Herald added subscribers: cfe-commits, tpr, dstuttard, yaxunl, nhaehnle, wdng, 
jvesely.
Herald added a project: clang.

Reverts r337612.  The issues that cropped up with the last attempt appear to 
have gone away.


Repository:
  rC Clang

https://reviews.llvm.org/D59008

Files:
  lib/Driver/ToolChains/AMDGPU.h
  test/Driver/amdgpu-toolchain.c


Index: test/Driver/amdgpu-toolchain.c
===
--- test/Driver/amdgpu-toolchain.c
+++ test/Driver/amdgpu-toolchain.c
@@ -3,4 +3,4 @@
 // AS_LINK: ld.lld{{.*}} "-shared"
 
 // RUN: %clang -### -g -target amdgcn--amdhsa -mcpu=kaveri %s 2>&1 | FileCheck 
-check-prefix=DWARF_VER %s
-// DWARF_VER: "-dwarf-version=2"
+// DWARF_VER: "-dwarf-version=5"
Index: lib/Driver/ToolChains/AMDGPU.h
===
--- lib/Driver/ToolChains/AMDGPU.h
+++ lib/Driver/ToolChains/AMDGPU.h
@@ -55,7 +55,7 @@
 public:
   AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args);
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
   llvm::opt::DerivedArgList *
   TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,


Index: test/Driver/amdgpu-toolchain.c
===
--- test/Driver/amdgpu-toolchain.c
+++ test/Driver/amdgpu-toolchain.c
@@ -3,4 +3,4 @@
 // AS_LINK: ld.lld{{.*}} "-shared"
 
 // RUN: %clang -### -g -target amdgcn--amdhsa -mcpu=kaveri %s 2>&1 | FileCheck -check-prefix=DWARF_VER %s
-// DWARF_VER: "-dwarf-version=2"
+// DWARF_VER: "-dwarf-version=5"
Index: lib/Driver/ToolChains/AMDGPU.h
===
--- lib/Driver/ToolChains/AMDGPU.h
+++ lib/Driver/ToolChains/AMDGPU.h
@@ -55,7 +55,7 @@
 public:
   AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args);
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
   llvm::opt::DerivedArgList *
   TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59008: [AMDGPU] Switch default dwarf version to 5

2019-03-25 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Ping


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59008/new/

https://reviews.llvm.org/D59008



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


[PATCH] D59008: [AMDGPU] Switch default dwarf version to 5

2019-03-28 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 192688.
scott.linder added a comment.

Add a test to confirm split-dwarf is supported for the amdhsa OS in the driver.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59008/new/

https://reviews.llvm.org/D59008

Files:
  lib/Driver/ToolChains/AMDGPU.h
  test/Driver/amdgpu-toolchain.c
  test/Driver/split-debug.c


Index: test/Driver/split-debug.c
===
--- test/Driver/split-debug.c
+++ test/Driver/split-debug.c
@@ -38,6 +38,9 @@
 // RUN: %clang -target x86_64-pc-freebsd12 -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-OPTION < %t %s
 //
+// RUN: %clang -target amdgcn-amd-amdhsa -gsplit-dwarf -c -### %s 2> %t
+// RUN: FileCheck -check-prefix=CHECK-OPTION < %t %s
+//
 // CHECK-OPTION: "-split-dwarf-file" "split-debug.dwo"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -S -### %s 2> %t
Index: test/Driver/amdgpu-toolchain.c
===
--- test/Driver/amdgpu-toolchain.c
+++ test/Driver/amdgpu-toolchain.c
@@ -3,4 +3,4 @@
 // AS_LINK: ld.lld{{.*}} "-shared"
 
 // RUN: %clang -### -g -target amdgcn--amdhsa -mcpu=kaveri %s 2>&1 | FileCheck 
-check-prefix=DWARF_VER %s
-// DWARF_VER: "-dwarf-version=2"
+// DWARF_VER: "-dwarf-version=5"
Index: lib/Driver/ToolChains/AMDGPU.h
===
--- lib/Driver/ToolChains/AMDGPU.h
+++ lib/Driver/ToolChains/AMDGPU.h
@@ -55,7 +55,7 @@
 public:
   AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args);
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
   llvm::opt::DerivedArgList *
   TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,


Index: test/Driver/split-debug.c
===
--- test/Driver/split-debug.c
+++ test/Driver/split-debug.c
@@ -38,6 +38,9 @@
 // RUN: %clang -target x86_64-pc-freebsd12 -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-OPTION < %t %s
 //
+// RUN: %clang -target amdgcn-amd-amdhsa -gsplit-dwarf -c -### %s 2> %t
+// RUN: FileCheck -check-prefix=CHECK-OPTION < %t %s
+//
 // CHECK-OPTION: "-split-dwarf-file" "split-debug.dwo"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -S -### %s 2> %t
Index: test/Driver/amdgpu-toolchain.c
===
--- test/Driver/amdgpu-toolchain.c
+++ test/Driver/amdgpu-toolchain.c
@@ -3,4 +3,4 @@
 // AS_LINK: ld.lld{{.*}} "-shared"
 
 // RUN: %clang -### -g -target amdgcn--amdhsa -mcpu=kaveri %s 2>&1 | FileCheck -check-prefix=DWARF_VER %s
-// DWARF_VER: "-dwarf-version=2"
+// DWARF_VER: "-dwarf-version=5"
Index: lib/Driver/ToolChains/AMDGPU.h
===
--- lib/Driver/ToolChains/AMDGPU.h
+++ lib/Driver/ToolChains/AMDGPU.h
@@ -55,7 +55,7 @@
 public:
   AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args);
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
   llvm::opt::DerivedArgList *
   TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59008: [AMDGPU] Switch default dwarf version to 5

2019-03-29 Thread Scott Linder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC357285: [AMDGPU] Switch default DWARF version to 5 (authored 
by scott.linder, committed by ).

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59008/new/

https://reviews.llvm.org/D59008

Files:
  lib/Driver/ToolChains/AMDGPU.h
  test/Driver/amdgpu-toolchain.c
  test/Driver/split-debug.c


Index: test/Driver/split-debug.c
===
--- test/Driver/split-debug.c
+++ test/Driver/split-debug.c
@@ -38,6 +38,9 @@
 // RUN: %clang -target x86_64-pc-freebsd12 -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-OPTION < %t %s
 //
+// RUN: %clang -target amdgcn-amd-amdhsa -gsplit-dwarf -c -### %s 2> %t
+// RUN: FileCheck -check-prefix=CHECK-OPTION < %t %s
+//
 // CHECK-OPTION: "-split-dwarf-file" "split-debug.dwo"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -S -### %s 2> %t
Index: test/Driver/amdgpu-toolchain.c
===
--- test/Driver/amdgpu-toolchain.c
+++ test/Driver/amdgpu-toolchain.c
@@ -3,4 +3,4 @@
 // AS_LINK: ld.lld{{.*}} "-shared"
 
 // RUN: %clang -### -g -target amdgcn--amdhsa -mcpu=kaveri %s 2>&1 | FileCheck 
-check-prefix=DWARF_VER %s
-// DWARF_VER: "-dwarf-version=2"
+// DWARF_VER: "-dwarf-version=5"
Index: lib/Driver/ToolChains/AMDGPU.h
===
--- lib/Driver/ToolChains/AMDGPU.h
+++ lib/Driver/ToolChains/AMDGPU.h
@@ -55,7 +55,7 @@
 public:
   AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args);
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
   llvm::opt::DerivedArgList *
   TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,


Index: test/Driver/split-debug.c
===
--- test/Driver/split-debug.c
+++ test/Driver/split-debug.c
@@ -38,6 +38,9 @@
 // RUN: %clang -target x86_64-pc-freebsd12 -gsplit-dwarf -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-OPTION < %t %s
 //
+// RUN: %clang -target amdgcn-amd-amdhsa -gsplit-dwarf -c -### %s 2> %t
+// RUN: FileCheck -check-prefix=CHECK-OPTION < %t %s
+//
 // CHECK-OPTION: "-split-dwarf-file" "split-debug.dwo"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -S -### %s 2> %t
Index: test/Driver/amdgpu-toolchain.c
===
--- test/Driver/amdgpu-toolchain.c
+++ test/Driver/amdgpu-toolchain.c
@@ -3,4 +3,4 @@
 // AS_LINK: ld.lld{{.*}} "-shared"
 
 // RUN: %clang -### -g -target amdgcn--amdhsa -mcpu=kaveri %s 2>&1 | FileCheck -check-prefix=DWARF_VER %s
-// DWARF_VER: "-dwarf-version=2"
+// DWARF_VER: "-dwarf-version=5"
Index: lib/Driver/ToolChains/AMDGPU.h
===
--- lib/Driver/ToolChains/AMDGPU.h
+++ lib/Driver/ToolChains/AMDGPU.h
@@ -55,7 +55,7 @@
 public:
   AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args);
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
   llvm::opt::DerivedArgList *
   TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60967: Move setTargetAttributes after setGVProperties in SetFunctionAttributes

2019-04-22 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added reviewers: atanasyan, rjmccall, yaxunl.
Herald added subscribers: cfe-commits, arichardson, tpr, sdardis.
Herald added a project: clang.

AMDGPU relies on global properties being set before setTargetProperties is 
called. Existing targets like MIPS which rely on setTargetProperties do not 
seem to rely on the current behavior, so this patch moves the call later in 
SetFunctionAttributes.


Repository:
  rC Clang

https://reviews.llvm.org/D60967

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenOpenCL/visibility.cl


Index: test/CodeGenOpenCL/visibility.cl
===
--- test/CodeGenOpenCL/visibility.cl
+++ test/CodeGenOpenCL/visibility.cl
@@ -72,6 +72,57 @@
 // FVIS-HIDDEN: define void @func_default()
 __attribute__((visibility("default"))) void func_default() {}
 
+extern kernel void ext_kern();
+__attribute__((visibility("hidden"))) extern kernel void ext_kern_hidden();
+__attribute__((visibility("protected"))) extern kernel void 
ext_kern_protected();
+__attribute__((visibility("default"))) extern kernel void ext_kern_default();
+
+extern void ext_func();
+__attribute__((visibility("hidden"))) extern void ext_func_hidden();
+__attribute__((visibility("protected"))) extern void ext_func_protected();
+__attribute__((visibility("default"))) extern void ext_func_default();
+
 void use() {
 glob = ext + ext_hidden + ext_protected + ext_default;
+ext_kern();
+ext_kern_hidden();
+ext_kern_protected();
+ext_kern_default();
+ext_func();
+ext_func_hidden();
+ext_func_protected();
+ext_func_default();
 }
+
+// FVIS-DEFAULT: declare amdgpu_kernel void @ext_kern()
+// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern()
+// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern()
+
+// FVIS-DEFAULT: declare protected amdgpu_kernel void @ext_kern_hidden()
+// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern_hidden()
+// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern_hidden()
+
+// FVIS-DEFAULT: declare protected amdgpu_kernel void @ext_kern_protected()
+// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern_protected()
+// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern_protected()
+
+// FVIS-DEFAULT: declare amdgpu_kernel void @ext_kern_default()
+// FVIS-PROTECTED: declare amdgpu_kernel void @ext_kern_default()
+// FVIS-HIDDEN: declare amdgpu_kernel void @ext_kern_default()
+
+
+// FVIS-DEFAULT: declare void @ext_func()
+// FVIS-PROTECTED: declare protected void @ext_func()
+// FVIS-HIDDEN: declare hidden void @ext_func()
+
+// FVIS-DEFAULT: declare hidden void @ext_func_hidden()
+// FVIS-PROTECTED: declare hidden void @ext_func_hidden()
+// FVIS-HIDDEN: declare hidden void @ext_func_hidden()
+
+// FVIS-DEFAULT: declare protected void @ext_func_protected()
+// FVIS-PROTECTED: declare protected void @ext_func_protected()
+// FVIS-HIDDEN: declare protected void @ext_func_protected()
+
+// FVIS-DEFAULT: declare void @ext_func_default()
+// FVIS-PROTECTED: declare void @ext_func_default()
+// FVIS-HIDDEN: declare void @ext_func_default()
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1558,12 +1558,8 @@
 
   const auto *FD = cast(GD.getDecl());
 
-  if (!IsIncompleteFunction) {
+  if (!IsIncompleteFunction)
 SetLLVMFunctionAttributes(GD, getTypes().arrangeGlobalDeclaration(GD), F);
-// Setup target-specific attributes.
-if (F->isDeclaration())
-  getTargetCodeGenInfo().setTargetAttributes(FD, F, *this);
-  }
 
   // Add the Returned attribute for "this", except for iOS 5 and earlier
   // where substantial code, including the libstdc++ dylib, was compiled with
@@ -1583,6 +1579,10 @@
   setLinkageForGV(F, FD);
   setGVProperties(F, FD);
 
+  // Setup target-specific attributes.
+  if (!IsIncompleteFunction && F->isDeclaration())
+getTargetCodeGenInfo().setTargetAttributes(FD, F, *this);
+
   if (const auto *CSA = FD->getAttr())
 F->setSection(CSA->getName());
   else if (const auto *SA = FD->getAttr())


Index: test/CodeGenOpenCL/visibility.cl
===
--- test/CodeGenOpenCL/visibility.cl
+++ test/CodeGenOpenCL/visibility.cl
@@ -72,6 +72,57 @@
 // FVIS-HIDDEN: define void @func_default()
 __attribute__((visibility("default"))) void func_default() {}
 
+extern kernel void ext_kern();
+__attribute__((visibility("hidden"))) extern kernel void ext_kern_hidden();
+__attribute__((visibility("protected"))) extern kernel void ext_kern_protected();
+__attribute__((visibility("default"))) extern kernel void ext_kern_default();
+
+extern void ext_func();
+__attribute__((visibility("hidden"))) extern void ext_func_hidden();
+__attribute__((visibility("protected"))) extern void ext_func_protected();
+__attribu

[PATCH] D60967: Move setTargetAttributes after setGVProperties in SetFunctionAttributes

2019-04-23 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D60967#1475925 , @rjmccall wrote:

> It seems reasonable to me for target hooks to run after global hooks, but can 
> I ask why AMDGPU specifically relies on this?


We want to ensure certain symbols have a meaningful visibility. For example, 
kernel symbols must not have hidden visibility. It's reasonable for the user to 
arrange for a kernel symbol to have either protected or default visibility, 
though, so we want our hook to be run after the global hooks have already 
calculated the global visibility.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60967/new/

https://reviews.llvm.org/D60967



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


[PATCH] D60967: Move setTargetAttributes after setGVProperties in SetFunctionAttributes

2019-04-23 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D60967#1476029 , @rjmccall wrote:

> Shouldn't it be an error if the user tries to give it hidden visibility?


We effectively consider the user explicitly specifying that a symbol is e.g. a 
`kernel` to also carry with it visibility information. We don't want to require 
the user to redundantly specify that a kernel is not hidden, when it is never 
meaningful for it to be hidden.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60967/new/

https://reviews.llvm.org/D60967



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


[PATCH] D60967: Move setTargetAttributes after setGVProperties in SetFunctionAttributes

2019-04-23 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D60967#1476069 , @rjmccall wrote:

> In D60967#1476057 , @scott.linder 
> wrote:
>
> > In D60967#1476029 , @rjmccall 
> > wrote:
> >
> > > Shouldn't it be an error if the user tries to give it hidden visibility?
> >
> >
> > We effectively consider the user explicitly specifying that a symbol is 
> > e.g. a `kernel` to also carry with it visibility information. We don't want 
> > to require the user to redundantly specify that a kernel is not hidden, 
> > when it is never meaningful for it to be hidden.
>
>
> I understand, but if the user explicitly gives it hidden visibility, you 
> should still diagnose that.
>
> Also, shouldn't you just handle this by treating the kernel attribute as a 
> source of explicit visibility at the Sema/AST level?


I agree that we should diagnose it, and I can update the patch accordingly, but 
I'm unsure how to go about emitting a diagnostic from this callback. As far as 
doing this at the AST level, this was my original approach in 
https://reviews.llvm.org/D53153, however this is really more of an AMDGPU 
implementation detail. I don't think it is necessarily the case that every 
OpenCL and Cuda implementation wants/needs require these symbols not have 
hidden visibility.

If we can involve the target in the AST linkage calculations, or agree that in 
general the `kernel` specifier should affect the visibility in this way, along 
with the `__device__` specifier on a variable and the `__global__` specifier on 
a function for Cuda, then moving this up to the AST level makes sense to me.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60967/new/

https://reviews.llvm.org/D60967



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


[PATCH] D60967: Move setTargetAttributes after setGVProperties in SetFunctionAttributes

2019-04-23 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D60967#1476226 , @rjmccall wrote:

> I suspect that other OpenCL and CUDA implementations don't care at all about 
> symbol visibility for device-side code generation, and giving kernel 
> functions default visibility seems like the right thing to do for the 
> (relatively few) things at the AST level that are sensitive to that, like 
> template visibility.  Would you mind reaching out to other implementors about 
> that?
>
> This patch seems fine to me regardless.


Yes, I can certainly identify who would be interested in terms of OpenCL and 
Cuda and work on moving this up to the AST.

If you don't object to this patch then is it reasonable for me to submit it? It 
will get us the required behavior for AMDGPU while I work on the more general 
solution.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60967/new/

https://reviews.llvm.org/D60967



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


[PATCH] D60967: Move setTargetAttributes after setGVProperties in SetFunctionAttributes

2019-04-23 Thread Scott Linder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC359039: Move setTargetAttributes after setGVProperties in 
SetFunctionAttributes (authored by scott.linder, committed by ).

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60967/new/

https://reviews.llvm.org/D60967

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenOpenCL/visibility.cl


Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1558,12 +1558,8 @@
 
   const auto *FD = cast(GD.getDecl());
 
-  if (!IsIncompleteFunction) {
+  if (!IsIncompleteFunction)
 SetLLVMFunctionAttributes(GD, getTypes().arrangeGlobalDeclaration(GD), F);
-// Setup target-specific attributes.
-if (F->isDeclaration())
-  getTargetCodeGenInfo().setTargetAttributes(FD, F, *this);
-  }
 
   // Add the Returned attribute for "this", except for iOS 5 and earlier
   // where substantial code, including the libstdc++ dylib, was compiled with
@@ -1583,6 +1579,10 @@
   setLinkageForGV(F, FD);
   setGVProperties(F, FD);
 
+  // Setup target-specific attributes.
+  if (!IsIncompleteFunction && F->isDeclaration())
+getTargetCodeGenInfo().setTargetAttributes(FD, F, *this);
+
   if (const auto *CSA = FD->getAttr())
 F->setSection(CSA->getName());
   else if (const auto *SA = FD->getAttr())
Index: test/CodeGenOpenCL/visibility.cl
===
--- test/CodeGenOpenCL/visibility.cl
+++ test/CodeGenOpenCL/visibility.cl
@@ -72,6 +72,57 @@
 // FVIS-HIDDEN: define void @func_default()
 __attribute__((visibility("default"))) void func_default() {}
 
+extern kernel void ext_kern();
+__attribute__((visibility("hidden"))) extern kernel void ext_kern_hidden();
+__attribute__((visibility("protected"))) extern kernel void 
ext_kern_protected();
+__attribute__((visibility("default"))) extern kernel void ext_kern_default();
+
+extern void ext_func();
+__attribute__((visibility("hidden"))) extern void ext_func_hidden();
+__attribute__((visibility("protected"))) extern void ext_func_protected();
+__attribute__((visibility("default"))) extern void ext_func_default();
+
 void use() {
 glob = ext + ext_hidden + ext_protected + ext_default;
+ext_kern();
+ext_kern_hidden();
+ext_kern_protected();
+ext_kern_default();
+ext_func();
+ext_func_hidden();
+ext_func_protected();
+ext_func_default();
 }
+
+// FVIS-DEFAULT: declare amdgpu_kernel void @ext_kern()
+// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern()
+// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern()
+
+// FVIS-DEFAULT: declare protected amdgpu_kernel void @ext_kern_hidden()
+// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern_hidden()
+// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern_hidden()
+
+// FVIS-DEFAULT: declare protected amdgpu_kernel void @ext_kern_protected()
+// FVIS-PROTECTED: declare protected amdgpu_kernel void @ext_kern_protected()
+// FVIS-HIDDEN: declare protected amdgpu_kernel void @ext_kern_protected()
+
+// FVIS-DEFAULT: declare amdgpu_kernel void @ext_kern_default()
+// FVIS-PROTECTED: declare amdgpu_kernel void @ext_kern_default()
+// FVIS-HIDDEN: declare amdgpu_kernel void @ext_kern_default()
+
+
+// FVIS-DEFAULT: declare void @ext_func()
+// FVIS-PROTECTED: declare protected void @ext_func()
+// FVIS-HIDDEN: declare hidden void @ext_func()
+
+// FVIS-DEFAULT: declare hidden void @ext_func_hidden()
+// FVIS-PROTECTED: declare hidden void @ext_func_hidden()
+// FVIS-HIDDEN: declare hidden void @ext_func_hidden()
+
+// FVIS-DEFAULT: declare protected void @ext_func_protected()
+// FVIS-PROTECTED: declare protected void @ext_func_protected()
+// FVIS-HIDDEN: declare protected void @ext_func_protected()
+
+// FVIS-DEFAULT: declare void @ext_func_default()
+// FVIS-PROTECTED: declare void @ext_func_default()
+// FVIS-HIDDEN: declare void @ext_func_default()


Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -1558,12 +1558,8 @@
 
   const auto *FD = cast(GD.getDecl());
 
-  if (!IsIncompleteFunction) {
+  if (!IsIncompleteFunction)
 SetLLVMFunctionAttributes(GD, getTypes().arrangeGlobalDeclaration(GD), F);
-// Setup target-specific attributes.
-if (F->isDeclaration())
-  getTargetCodeGenInfo().setTargetAttributes(FD, F, *this);
-  }
 
   // Add the Returned attribute for "this", except for iOS 5 and earlier
   // where substantial code, including the libstdc++ dylib, was compiled with
@@ -1583,6 +1579,10 @@
   setLinkageForGV(F, FD);
   setGVProperties(F, FD);
 
+  // Setup target-specific attributes.
+  if (!IsIncompleteFunction && F->isDeclaration())
+getTargetCodeGenInfo().setTargetAttributes(FD, F, *this);
+
   if (const au

[PATCH] D60967: Move setTargetAttributes after setGVProperties in SetFunctionAttributes

2019-04-24 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

@rjmccall Would you expect similar conflicts in explicit visibility to result 
in diagnostics? For example, marking a `static` variable with an explicit 
visibility attribute doesn't warn, instead the explicit visibility attribute is 
silently ignored. GCC 7.3 complains with `warning: ‘__visibility__’ attribute 
ignored [-Wattributes]`


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60967/new/

https://reviews.llvm.org/D60967



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


[PATCH] D61097: [Sema] Emit warning for visibility attribute on internal-linkage declaration

2019-04-24 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added reviewers: rjmccall, espindola.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

GCC warns on these cases, but we currently just silently ignore the attribute.


Repository:
  rC Clang

https://reviews.llvm.org/D61097

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/attr-visibility.c
  test/SemaCXX/ast-print.cpp
  test/SemaCXX/attr-visibility.cpp


Index: test/SemaCXX/attr-visibility.cpp
===
--- test/SemaCXX/attr-visibility.cpp
+++ test/SemaCXX/attr-visibility.cpp
@@ -18,3 +18,9 @@
 struct x3 {
   static int y;
 } __attribute((visibility("default"))); // expected-warning {{attribute 
'visibility' after definition is ignored}}
+
+const int test4 __attribute__((visibility("default"))) = 0; // 
expected-warning {{'visibility' attribute ignored}}
+
+namespace {
+  int test5 __attribute__((visibility("default"))); // expected-warning 
{{'visibility' attribute ignored}}
+};
Index: test/SemaCXX/ast-print.cpp
===
--- test/SemaCXX/ast-print.cpp
+++ test/SemaCXX/ast-print.cpp
@@ -209,10 +209,8 @@
 }
 }
 
-namespace {
 // CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S;
 struct [[gnu::visibility("hidden")]] S;
-}
 
 // CHECK:  struct CXXFunctionalCastExprPrint {
 // CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};
Index: test/Sema/attr-visibility.c
===
--- test/Sema/attr-visibility.c
+++ test/Sema/attr-visibility.c
@@ -26,3 +26,9 @@
 int x __attribute__((type_visibility("default"))); // expected-error 
{{'type_visibility' attribute only applies to types and namespaces}}
 
 int PR17105 __attribute__((visibility(hidden))); // expected-error 
{{'visibility' attribute requires a string}}
+
+static int test8 __attribute__((visibility("default"))); // expected-warning 
{{'visibility' attribute ignored}}
+static int test9 __attribute__((visibility("hidden"))); // expected-warning 
{{'visibility' attribute ignored}}
+static int test10 __attribute__((visibility("internal"))); // expected-warning 
{{'visibility' attribute ignored}}
+
+static int test11() __attribute__((visibility("default"))); // 
expected-warning {{'visibility' attribute ignored}}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -2615,6 +2615,14 @@
 return;
   }
 
+  // Visibility attributes have no effect on symbols with internal linkage.
+  if (auto ND = dyn_cast(D)) {
+if (!ND->isExternallyVisible()) {
+  S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL;
+  return;
+}
+  }
+
   // Check that the argument is a string literal.
   StringRef TypeStr;
   SourceLocation LiteralLoc;


Index: test/SemaCXX/attr-visibility.cpp
===
--- test/SemaCXX/attr-visibility.cpp
+++ test/SemaCXX/attr-visibility.cpp
@@ -18,3 +18,9 @@
 struct x3 {
   static int y;
 } __attribute((visibility("default"))); // expected-warning {{attribute 'visibility' after definition is ignored}}
+
+const int test4 __attribute__((visibility("default"))) = 0; // expected-warning {{'visibility' attribute ignored}}
+
+namespace {
+  int test5 __attribute__((visibility("default"))); // expected-warning {{'visibility' attribute ignored}}
+};
Index: test/SemaCXX/ast-print.cpp
===
--- test/SemaCXX/ast-print.cpp
+++ test/SemaCXX/ast-print.cpp
@@ -209,10 +209,8 @@
 }
 }
 
-namespace {
 // CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S;
 struct [[gnu::visibility("hidden")]] S;
-}
 
 // CHECK:  struct CXXFunctionalCastExprPrint {
 // CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};
Index: test/Sema/attr-visibility.c
===
--- test/Sema/attr-visibility.c
+++ test/Sema/attr-visibility.c
@@ -26,3 +26,9 @@
 int x __attribute__((type_visibility("default"))); // expected-error {{'type_visibility' attribute only applies to types and namespaces}}
 
 int PR17105 __attribute__((visibility(hidden))); // expected-error {{'visibility' attribute requires a string}}
+
+static int test8 __attribute__((visibility("default"))); // expected-warning {{'visibility' attribute ignored}}
+static int test9 __attribute__((visibility("hidden"))); // expected-warning {{'visibility' attribute ignored}}
+static int test10 __attribute__((visibility("internal"))); // expected-warning {{'visibility' attribute ignored}}
+
+static int test11() __attribute__((visibility("default"))); // expected-warning {{'visibility' attribute ignored}}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -2615,6 +2615

[PATCH] D61097: [Sema] Emit warning for visibility attribute on internal-linkage declaration

2019-04-26 Thread Scott Linder via Phabricator via cfe-commits
scott.linder marked 3 inline comments as done.
scott.linder added inline comments.



Comment at: lib/Sema/SemaDeclAttr.cpp:2621
+if (!ND->isExternallyVisible()) {
+  S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL;
+  return;

aaron.ballman wrote:
> I think it would be more helpful for users if we introduced a new diagnostic 
> here that explained why the attribute is being ignored, otherwise the 
> diagnostic is somewhat indecipherable.
Sure, I am amenable to anything here. GCC uses the same short message, but it 
does seem to indicate e.g. that the keyword `static` played some role by using 
additional source ranges. I don't know how we would go about that with the 
Sema/AST split? We could just go with a more explicit message. Do you have any 
thoughts on the wording?

```
warning: 'visibility' attribute ignored on non-external symbol
```



Comment at: lib/Sema/SemaDeclAttr.cpp:2622
+  S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL;
+  return;
+}

aaron.ballman wrote:
> We shouldn't early return here (it's not an error, just a warning), so that 
> the other diagnostics can also trigger if needed.
Should I also fix the other early-return-on-warning's in the same function, 
e.g. the function begins with:

```
// Visibility attributes don't mean anything on a typedef.
if (isa(D)) {
  S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL;
  return;
}
```

I suppose the difference is that the attribute "can" be placed on the symbol in 
this case, but it is ignored just the same.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61097/new/

https://reviews.llvm.org/D61097



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


[PATCH] D61097: [Sema] Emit warning for visibility attribute on internal-linkage declaration

2019-04-26 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 196853.
scott.linder added a comment.

Clean up use of `auto`


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61097/new/

https://reviews.llvm.org/D61097

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/attr-visibility.c
  test/SemaCXX/ast-print.cpp
  test/SemaCXX/attr-visibility.cpp


Index: test/SemaCXX/attr-visibility.cpp
===
--- test/SemaCXX/attr-visibility.cpp
+++ test/SemaCXX/attr-visibility.cpp
@@ -18,3 +18,9 @@
 struct x3 {
   static int y;
 } __attribute((visibility("default"))); // expected-warning {{attribute 
'visibility' after definition is ignored}}
+
+const int test4 __attribute__((visibility("default"))) = 0; // 
expected-warning {{'visibility' attribute ignored}}
+
+namespace {
+  int test5 __attribute__((visibility("default"))); // expected-warning 
{{'visibility' attribute ignored}}
+};
Index: test/SemaCXX/ast-print.cpp
===
--- test/SemaCXX/ast-print.cpp
+++ test/SemaCXX/ast-print.cpp
@@ -209,10 +209,8 @@
 }
 }
 
-namespace {
 // CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S;
 struct [[gnu::visibility("hidden")]] S;
-}
 
 // CHECK:  struct CXXFunctionalCastExprPrint {
 // CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};
Index: test/Sema/attr-visibility.c
===
--- test/Sema/attr-visibility.c
+++ test/Sema/attr-visibility.c
@@ -26,3 +26,9 @@
 int x __attribute__((type_visibility("default"))); // expected-error 
{{'type_visibility' attribute only applies to types and namespaces}}
 
 int PR17105 __attribute__((visibility(hidden))); // expected-error 
{{'visibility' attribute requires a string}}
+
+static int test8 __attribute__((visibility("default"))); // expected-warning 
{{'visibility' attribute ignored}}
+static int test9 __attribute__((visibility("hidden"))); // expected-warning 
{{'visibility' attribute ignored}}
+static int test10 __attribute__((visibility("internal"))); // expected-warning 
{{'visibility' attribute ignored}}
+
+static int test11() __attribute__((visibility("default"))); // 
expected-warning {{'visibility' attribute ignored}}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -2615,6 +2615,14 @@
 return;
   }
 
+  // Visibility attributes have no effect on symbols with internal linkage.
+  if (const auto *ND = dyn_cast(D)) {
+if (!ND->isExternallyVisible()) {
+  S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL;
+  return;
+}
+  }
+
   // Check that the argument is a string literal.
   StringRef TypeStr;
   SourceLocation LiteralLoc;


Index: test/SemaCXX/attr-visibility.cpp
===
--- test/SemaCXX/attr-visibility.cpp
+++ test/SemaCXX/attr-visibility.cpp
@@ -18,3 +18,9 @@
 struct x3 {
   static int y;
 } __attribute((visibility("default"))); // expected-warning {{attribute 'visibility' after definition is ignored}}
+
+const int test4 __attribute__((visibility("default"))) = 0; // expected-warning {{'visibility' attribute ignored}}
+
+namespace {
+  int test5 __attribute__((visibility("default"))); // expected-warning {{'visibility' attribute ignored}}
+};
Index: test/SemaCXX/ast-print.cpp
===
--- test/SemaCXX/ast-print.cpp
+++ test/SemaCXX/ast-print.cpp
@@ -209,10 +209,8 @@
 }
 }
 
-namespace {
 // CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S;
 struct [[gnu::visibility("hidden")]] S;
-}
 
 // CHECK:  struct CXXFunctionalCastExprPrint {
 // CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};
Index: test/Sema/attr-visibility.c
===
--- test/Sema/attr-visibility.c
+++ test/Sema/attr-visibility.c
@@ -26,3 +26,9 @@
 int x __attribute__((type_visibility("default"))); // expected-error {{'type_visibility' attribute only applies to types and namespaces}}
 
 int PR17105 __attribute__((visibility(hidden))); // expected-error {{'visibility' attribute requires a string}}
+
+static int test8 __attribute__((visibility("default"))); // expected-warning {{'visibility' attribute ignored}}
+static int test9 __attribute__((visibility("hidden"))); // expected-warning {{'visibility' attribute ignored}}
+static int test10 __attribute__((visibility("internal"))); // expected-warning {{'visibility' attribute ignored}}
+
+static int test11() __attribute__((visibility("default"))); // expected-warning {{'visibility' attribute ignored}}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -2615,6 +2615,14 @@
 return;
   }
 
+  // Visibility attributes have no effect on symbols wit

[PATCH] D60967: Move setTargetAttributes after setGVProperties in SetFunctionAttributes

2019-04-26 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

@rjmccall I'm not sure if this is the right place to continue discussing this, 
but I don't have a patch I am happy with and I would rather not post something 
half-baked.

Currently for AMDGPU we have the behavior that the user can set the visibility 
of these symbols with explicit attributes. If we consider the `kernel` 
attribute itself as an explicit visibility declaration how do we support this 
flexibility when we will have effectively mandated a single visibility that the 
user cannot interact with? Even if we are OK with mandating something like 
default visibility, we do not currently support preemptible symbols so 
`protected` is the optimal visibility. This may not be true of other targets, 
and it may not even be true of AMDGPU in the future, so hardcoding the 
visibility of `kernel` symbols to anything doesn't seem correct. Is something 
like "not-hidden" reasonable?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60967/new/

https://reviews.llvm.org/D60967



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


[PATCH] D61274: [Sema][AST] Explicit visibility for OpenCL/CUDA kernels/variables

2019-04-29 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added reviewers: Anastasia, tra, yaxunl, rjmccall.
Herald added subscribers: cfe-commits, tpr.
Herald added a project: clang.

For AMDGPU the visibility of these symbols (OpenCL kernels, CUDA `__global__` 
functions, and CUDA `__device__` variables) must not be hidden, as we rely on 
them being available in the dynamic symbol table in the final DSO.

This patch implements this by considering language attributes as a source of 
explicit visibility, but rather than attributing any one visibility to them 
they are simply coerced to be a non-hidden visibility. This allows for the 
optimization of using protected visibility when these symbols are known to be 
`dso_local`.

This patch also adds diagnostics for explicitly setting a hidden visibility on 
these symbols.

I imagine there are a number of issues with the patch in its current state, but 
I wanted to get something implemented before reaching out to OpenCL/CUDA 
maintainers to see if this is a reasonable change. @Anastasia and @tra I wasn't 
certain if you would be good candidates to discuss this change, so please let 
me know if I need to keep looking.


Repository:
  rC Clang

https://reviews.llvm.org/D61274

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/Visibility.h
  lib/AST/Decl.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/SemaCUDA/visibility-diagnostics.cu
  test/SemaOpenCL/visibility-diagnostics.cl

Index: test/SemaOpenCL/visibility-diagnostics.cl
===
--- /dev/null
+++ test/SemaOpenCL/visibility-diagnostics.cl
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -std=cl2.0 -verify -pedantic -fsyntax-only %s
+
+__attribute__((visibility("hidden"))) kernel void kern_hidden() {} // expected-warning {{'hidden' visibility on function with incompatible language attribute will be ignored}}
+__attribute__((visibility("protected"))) kernel void kern_protected();
+__attribute__((visibility("default"))) kernel void kern_default();
+kernel void kern();
+
+__attribute__((visibility("hidden"))) extern kernel void ext_kern_hidden(); // expected-warning {{'hidden' visibility on function with incompatible language attribute will be ignored}}
+__attribute__((visibility("protected"))) extern kernel void ext_kern_protected();
+__attribute__((visibility("default"))) extern kernel void ext_kern_default();
+extern kernel void ext_kern();
Index: test/SemaCUDA/visibility-diagnostics.cu
===
--- /dev/null
+++ test/SemaCUDA/visibility-diagnostics.cu
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+#include "Inputs/cuda.h"
+
+__attribute__((visibility("hidden"))) __global__ void global_func_hidden() {} // expected-warning {{'hidden' visibility on function with incompatible language attribute will be ignored}}
+__attribute__((visibility("protected"))) __global__ void global_func_protected() {}
+__attribute__((visibility("default"))) __global__ void global_func_default() {}
+__global__ void global_func() {}
+
+__attribute__((visibility("hidden"))) __device__ int device_var_hidden; // expected-warning {{'hidden' visibility on variable with incompatible language attribute will be ignored}}
+__attribute__((visibility("protected"))) __device__ int device_var_protected;
+__attribute__((visibility("default"))) __device__ int device_var_default;
+__device__ int device_var;
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -7375,6 +7375,16 @@
 Diag(D->getLocation(), diag::err_designated_init_attr_non_init);
 D->dropAttr();
   }
+
+  if ((D->hasAttr() &&
+   D->getAttr()->getVisibility() ==
+   VisibilityAttr::Hidden) &&
+  (D->hasAttr() ||
+   (isa(D) && D->hasAttr()) ||
+   (isa(D) && D->hasAttr( {
+Diag(D->getLocation(), diag::warn_attribute_hidden_visibility)
+<< (isa(D) ? 0 : 1);
+  }
 }
 
 // Helper for delayed processing TransparentUnion attribute.
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -7840,23 +7840,8 @@
 };
 }
 
-static bool requiresAMDGPUProtectedVisibility(const Decl *D,
-  llvm::GlobalValue *GV) {
-  if (GV->getVisibility() != llvm::GlobalValue::HiddenVisibility)
-return false;
-
-  return D->hasAttr() ||
- (isa(D) && D->hasAttr()) ||
- (isa(D) && D->hasAttr());
-}
-
 void AMDGPUTargetCodeGenInfo::setTargetAttributes(
 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
-  if (requiresAMDGPUProtectedVisibility(D, GV)) {
-GV->setVisibility(llvm::GlobalValue::ProtectedVisibility);
-GV->setDSOLocal(true);
-  }
-
   if (GV->isDeclaration())
 return;
   const F

[PATCH] D61097: [Sema] Emit warning for visibility attribute on internal-linkage declaration

2019-05-01 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 197570.
scott.linder added a comment.

Use distinct sema diagnostic and do not return early.

I am going to bump `DIAG_SIZE_SEMA` in another patch, as it seems like we have 
hit the current limit.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61097/new/

https://reviews.llvm.org/D61097

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/attr-visibility.c
  test/SemaCXX/ast-print.cpp
  test/SemaCXX/attr-visibility.cpp


Index: test/SemaCXX/attr-visibility.cpp
===
--- test/SemaCXX/attr-visibility.cpp
+++ test/SemaCXX/attr-visibility.cpp
@@ -18,3 +18,9 @@
 struct x3 {
   static int y;
 } __attribute((visibility("default"))); // expected-warning {{attribute 
'visibility' after definition is ignored}}
+
+const int test4 __attribute__((visibility("default"))) = 0; // 
expected-warning {{'visibility' attribute is ignored on a non-external symbol}}
+
+namespace {
+  int test5 __attribute__((visibility("default"))); // expected-warning 
{{'visibility' attribute is ignored on a non-external symbol}}
+};
Index: test/SemaCXX/ast-print.cpp
===
--- test/SemaCXX/ast-print.cpp
+++ test/SemaCXX/ast-print.cpp
@@ -209,10 +209,8 @@
 }
 }
 
-namespace {
 // CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S;
 struct [[gnu::visibility("hidden")]] S;
-}
 
 // CHECK:  struct CXXFunctionalCastExprPrint {
 // CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};
Index: test/Sema/attr-visibility.c
===
--- test/Sema/attr-visibility.c
+++ test/Sema/attr-visibility.c
@@ -26,3 +26,9 @@
 int x __attribute__((type_visibility("default"))); // expected-error 
{{'type_visibility' attribute only applies to types and namespaces}}
 
 int PR17105 __attribute__((visibility(hidden))); // expected-error 
{{'visibility' attribute requires a string}}
+
+static int test8 __attribute__((visibility("default"))); // expected-warning 
{{'visibility' attribute is ignored on a non-external symbol}}
+static int test9 __attribute__((visibility("hidden"))); // expected-warning 
{{'visibility' attribute is ignored on a non-external symbol}}
+static int test10 __attribute__((visibility("internal"))); // expected-warning 
{{'visibility' attribute is ignored on a non-external symbol}}
+
+static int test11() __attribute__((visibility("default"))); // 
expected-warning {{'visibility' attribute is ignored on a non-external symbol}}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -2615,6 +2615,14 @@
 return;
   }
 
+  // Visibility attributes have no effect on symbols with internal linkage.
+  if (const auto *ND = dyn_cast(D)) {
+if (!ND->isExternallyVisible())
+  S.Diag(AL.getRange().getBegin(),
+ diag::warn_attribute_ignored_on_non_external)
+  << AL;
+  }
+
   // Check that the argument is a string literal.
   StringRef TypeStr;
   SourceLocation LiteralLoc;
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -2778,6 +2778,9 @@
 def warn_attribute_ignored_on_inline :
   Warning<"%0 attribute ignored on inline function">,
   InGroup;
+def warn_attribute_ignored_on_non_external :
+  Warning<"%0 attribute is ignored on a non-external symbol">,
+  InGroup;
 def warn_nocf_check_attribute_ignored :
   Warning<"'nocf_check' attribute ignored; use -fcf-protection to enable the 
attribute">,
   InGroup;


Index: test/SemaCXX/attr-visibility.cpp
===
--- test/SemaCXX/attr-visibility.cpp
+++ test/SemaCXX/attr-visibility.cpp
@@ -18,3 +18,9 @@
 struct x3 {
   static int y;
 } __attribute((visibility("default"))); // expected-warning {{attribute 'visibility' after definition is ignored}}
+
+const int test4 __attribute__((visibility("default"))) = 0; // expected-warning {{'visibility' attribute is ignored on a non-external symbol}}
+
+namespace {
+  int test5 __attribute__((visibility("default"))); // expected-warning {{'visibility' attribute is ignored on a non-external symbol}}
+};
Index: test/SemaCXX/ast-print.cpp
===
--- test/SemaCXX/ast-print.cpp
+++ test/SemaCXX/ast-print.cpp
@@ -209,10 +209,8 @@
 }
 }
 
-namespace {
 // CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S;
 struct [[gnu::visibility("hidden")]] S;
-}
 
 // CHECK:  struct CXXFunctionalCastExprPrint {
 // CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};
Index: test/Sema/attr-visibility.c
===
--- test/Sema/attr-visibilit

[PATCH] D61097: [Sema] Emit warning for visibility attribute on internal-linkage declaration

2019-05-02 Thread Scott Linder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL359814: [Sema] Emit warning for visibility attribute on 
internal-linkage declaration (authored by scott.linder, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61097?vs=197570&id=197838#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61097/new/

https://reviews.llvm.org/D61097

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/test/Sema/attr-visibility.c
  cfe/trunk/test/SemaCXX/ast-print.cpp
  cfe/trunk/test/SemaCXX/attr-visibility.cpp


Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp
@@ -2615,6 +2615,14 @@
 return;
   }
 
+  // Visibility attributes have no effect on symbols with internal linkage.
+  if (const auto *ND = dyn_cast(D)) {
+if (!ND->isExternallyVisible())
+  S.Diag(AL.getRange().getBegin(),
+ diag::warn_attribute_ignored_on_non_external)
+  << AL;
+  }
+
   // Check that the argument is a string literal.
   StringRef TypeStr;
   SourceLocation LiteralLoc;
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2778,6 +2778,9 @@
 def warn_attribute_ignored_on_inline :
   Warning<"%0 attribute ignored on inline function">,
   InGroup;
+def warn_attribute_ignored_on_non_external :
+  Warning<"%0 attribute is ignored on a non-external symbol">,
+  InGroup;
 def warn_nocf_check_attribute_ignored :
   Warning<"'nocf_check' attribute ignored; use -fcf-protection to enable the 
attribute">,
   InGroup;
Index: cfe/trunk/test/SemaCXX/ast-print.cpp
===
--- cfe/trunk/test/SemaCXX/ast-print.cpp
+++ cfe/trunk/test/SemaCXX/ast-print.cpp
@@ -209,10 +209,8 @@
 }
 }
 
-namespace {
 // CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S;
 struct [[gnu::visibility("hidden")]] S;
-}
 
 // CHECK:  struct CXXFunctionalCastExprPrint {
 // CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};
Index: cfe/trunk/test/SemaCXX/attr-visibility.cpp
===
--- cfe/trunk/test/SemaCXX/attr-visibility.cpp
+++ cfe/trunk/test/SemaCXX/attr-visibility.cpp
@@ -18,3 +18,9 @@
 struct x3 {
   static int y;
 } __attribute((visibility("default"))); // expected-warning {{attribute 
'visibility' after definition is ignored}}
+
+const int test4 __attribute__((visibility("default"))) = 0; // 
expected-warning {{'visibility' attribute is ignored on a non-external symbol}}
+
+namespace {
+  int test5 __attribute__((visibility("default"))); // expected-warning 
{{'visibility' attribute is ignored on a non-external symbol}}
+};
Index: cfe/trunk/test/Sema/attr-visibility.c
===
--- cfe/trunk/test/Sema/attr-visibility.c
+++ cfe/trunk/test/Sema/attr-visibility.c
@@ -26,3 +26,9 @@
 int x __attribute__((type_visibility("default"))); // expected-error 
{{'type_visibility' attribute only applies to types and namespaces}}
 
 int PR17105 __attribute__((visibility(hidden))); // expected-error 
{{'visibility' attribute requires a string}}
+
+static int test8 __attribute__((visibility("default"))); // expected-warning 
{{'visibility' attribute is ignored on a non-external symbol}}
+static int test9 __attribute__((visibility("hidden"))); // expected-warning 
{{'visibility' attribute is ignored on a non-external symbol}}
+static int test10 __attribute__((visibility("internal"))); // expected-warning 
{{'visibility' attribute is ignored on a non-external symbol}}
+
+static int test11() __attribute__((visibility("default"))); // 
expected-warning {{'visibility' attribute is ignored on a non-external symbol}}


Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp
@@ -2615,6 +2615,14 @@
 return;
   }
 
+  // Visibility attributes have no effect on symbols with internal linkage.
+  if (const auto *ND = dyn_cast(D)) {
+if (!ND->isExternallyVisible())
+  S.Diag(AL.getRange().getBegin(),
+ diag::warn_attribute_ignored_on_non_external)
+  << AL;
+  }
+
   // Check that the argument is a string literal.
   StringRef TypeStr;
   SourceLocation LiteralLoc;
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/Diagno

[PATCH] D61097: [Sema] Emit warning for visibility attribute on internal-linkage declaration

2019-05-03 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Richard Smith on cfe-dev pointed out some cases where this patch is incorrect, 
stemming from trying to calculate the linkage too early; the warning will 
either have to work without the use of `isExternallyVisible` or will have to be 
emitted later. This was reverted in `r359858` for now.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61097/new/

https://reviews.llvm.org/D61097



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


[PATCH] D52891: [AMDGPU] Add -fvisibility-amdgpu-non-kernel-functions

2018-10-04 Thread Scott Linder via Phabricator via cfe-commits
scott.linder created this revision.
scott.linder added reviewers: yaxunl, kzhuravl, arsenm.
Herald added subscribers: cfe-commits, Anastasia, tpr, dstuttard, nhaehnle, 
wdng, jvesely.

Controls the visibility of non-kernel functions when compiling for AMDGPU 
targets. Defaults to the default value visibility (-fvisibility), and is set in 
the AMDGPU toolchain to be "hidden" if not set explicitly.

This is a more fine-grained knob than "-fvisibility hidden", and allows the 
default visibility of functions to be controlled independent of kernels. This 
is useful for languages like OpenCL where kernel symbols are externally 
visible, but function symbols are not.


Repository:
  rC Clang

https://reviews.llvm.org/D52891

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/ToolChains/AMDGPU.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/visibility-amdgpu-non-kernel-functions.cl
  test/Driver/amdgpu-visibility.cl

Index: test/Driver/amdgpu-visibility.cl
===
--- test/Driver/amdgpu-visibility.cl
+++ test/Driver/amdgpu-visibility.cl
@@ -1,7 +1,11 @@
 // RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm %s 2>&1 | FileCheck -check-prefix=DEFAULT %s
-// RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility=protected  %s 2>&1 | FileCheck -check-prefix=OVERRIDE-PROTECTED  %s
-// RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility-ms-compat  %s 2>&1 | FileCheck -check-prefix=OVERRIDE-MS  %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility=hidden %s 2>&1 | FileCheck -check-prefix=VISIBILITY-HIDDEN %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility-amdgpu-non-kernel-functions=hidden  %s 2>&1 | FileCheck -check-prefix=AMDGPU-HIDDEN  %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility-amdgpu-non-kernel-functions=default  %s 2>&1 | FileCheck -check-prefix=AMDGPU-DEFAULT  %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility=hidden -fvisibility-amdgpu-non-kernel-functions=default  %s 2>&1 | FileCheck -check-prefix=VISIBILITY-HIDDEN-AMDGPU-DEFAULT  %s
 
-// DEFAULT: "-fvisibility" "hidden"
-// OVERRIDE-PROTECTED: "-fvisibility" "protected"
-// OVERRIDE-MS:  "-fvisibility" "hidden" "-ftype-visibility" "default"
+// DEFAULT: "-fvisibility-amdgpu-non-kernel-functions" "hidden"
+// VISIBILITY-HIDDEN: "-fvisibility-amdgpu-non-kernel-functions" "hidden"
+// AMDGPU-HIDDEN: "-fvisibility-amdgpu-non-kernel-functions" "hidden"
+// AMDGPU-DEFAULT: "-fvisibility-amdgpu-non-kernel-functions" "default"
+// VISIBILITY-HIDDEN-AMDGPU-DEFAULT: "-fvisibility-amdgpu-non-kernel-functions" "default"
Index: test/CodeGen/visibility-amdgpu-non-kernel-functions.cl
===
--- /dev/null
+++ test/CodeGen/visibility-amdgpu-non-kernel-functions.cl
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -fvisibility hidden -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS_HIDDEN %s
+// RUN: %clang_cc1 -fvisibility-amdgpu-non-kernel-functions hidden -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS_AMDGPU_HIDDEN %s
+// RUN: %clang_cc1 -fvisibility-amdgpu-non-kernel-functions default -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS_AMDGPU_DEFAULT %s
+// RUN: %clang_cc1 -fvisibility hidden -fvisibility-amdgpu-non-kernel-functions default -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS_AMDGPU_OVERRIDE %s
+
+// FVIS_HIDDEN: define hidden amdgpu_kernel void @kern()
+// FVIS_AMDGPU_HIDDEN: define amdgpu_kernel void @kern()
+// FVIS_AMDGPU_DEFAULT: define amdgpu_kernel void @kern()
+// FVIS_AMDGPU_OVERRIDE: define hidden amdgpu_kernel void @kern()
+kernel void kern() {}
+// FVIS_HIDDEN: define amdgpu_kernel void @default_kern()
+// FVIS_AMDGPU_HIDDEN: define amdgpu_kernel void @default_kern()
+// FVIS_AMDGPU_DEFAULT: define amdgpu_kernel void @default_kern()
+// FVIS_AMDGPU_OVERRIDE: define amdgpu_kernel void @default_kern()
+__attribute__((visibility("default"))) kernel void default_kern() {}
+// FVIS_HIDDEN: define hidden amdgpu_kernel void @hidden_kern()
+// FVIS_AMDGPU_HIDDEN: define hidden amdgpu_kernel void @hidden_kern()
+// FVIS_AMDGPU_DEFAULT: define hidden amdgpu_kernel void @hidden_kern()
+// FVIS_AMDGPU_OVERRIDE: define hidden amdgpu_kernel void @hidden_kern()
+__attribute__((visibility("hidden"))) kernel void hidden_kern() {}
+// FVIS_HIDDEN: define protected amdgpu_kernel void @protected_kern()
+// FVIS_AMDGPU_HIDDEN: define protected amdgpu_kernel void @protected_kern()
+// FVIS_AMDGPU_DEFAULT: define protected amdgpu_kernel void @protected_kern()
+// FVIS_AMDGPU_OVERRIDE: define p

[PATCH] D52891: [AMDGPU] Add -fvisibility-amdgpu-non-kernel-functions

2018-10-04 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

I don't know who else to add as a reviewer; Sam, is there someone else outside 
of AMD that would be interested in reviewing this?


Repository:
  rC Clang

https://reviews.llvm.org/D52891



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


[PATCH] D52891: [AMDGPU] Add -fvisibility-amdgpu-non-kernel-functions

2018-10-04 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 168314.
scott.linder added a comment.

Update docs


https://reviews.llvm.org/D52891

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Basic/LangOptions.def
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/ToolChains/AMDGPU.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/visibility-amdgpu-non-kernel-functions.cl
  test/Driver/amdgpu-visibility.cl

Index: test/Driver/amdgpu-visibility.cl
===
--- test/Driver/amdgpu-visibility.cl
+++ test/Driver/amdgpu-visibility.cl
@@ -1,7 +1,11 @@
 // RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm %s 2>&1 | FileCheck -check-prefix=DEFAULT %s
-// RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility=protected  %s 2>&1 | FileCheck -check-prefix=OVERRIDE-PROTECTED  %s
-// RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility-ms-compat  %s 2>&1 | FileCheck -check-prefix=OVERRIDE-MS  %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility=hidden %s 2>&1 | FileCheck -check-prefix=VISIBILITY-HIDDEN %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility-amdgpu-non-kernel-functions=hidden  %s 2>&1 | FileCheck -check-prefix=AMDGPU-HIDDEN  %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility-amdgpu-non-kernel-functions=default  %s 2>&1 | FileCheck -check-prefix=AMDGPU-DEFAULT  %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -x cl -c -emit-llvm -fvisibility=hidden -fvisibility-amdgpu-non-kernel-functions=default  %s 2>&1 | FileCheck -check-prefix=VISIBILITY-HIDDEN-AMDGPU-DEFAULT  %s
 
-// DEFAULT: "-fvisibility" "hidden"
-// OVERRIDE-PROTECTED: "-fvisibility" "protected"
-// OVERRIDE-MS:  "-fvisibility" "hidden" "-ftype-visibility" "default"
+// DEFAULT: "-fvisibility-amdgpu-non-kernel-functions" "hidden"
+// VISIBILITY-HIDDEN: "-fvisibility-amdgpu-non-kernel-functions" "hidden"
+// AMDGPU-HIDDEN: "-fvisibility-amdgpu-non-kernel-functions" "hidden"
+// AMDGPU-DEFAULT: "-fvisibility-amdgpu-non-kernel-functions" "default"
+// VISIBILITY-HIDDEN-AMDGPU-DEFAULT: "-fvisibility-amdgpu-non-kernel-functions" "default"
Index: test/CodeGen/visibility-amdgpu-non-kernel-functions.cl
===
--- /dev/null
+++ test/CodeGen/visibility-amdgpu-non-kernel-functions.cl
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -fvisibility hidden -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS_HIDDEN %s
+// RUN: %clang_cc1 -fvisibility-amdgpu-non-kernel-functions hidden -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS_AMDGPU_HIDDEN %s
+// RUN: %clang_cc1 -fvisibility-amdgpu-non-kernel-functions default -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS_AMDGPU_DEFAULT %s
+// RUN: %clang_cc1 -fvisibility hidden -fvisibility-amdgpu-non-kernel-functions default -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS_AMDGPU_OVERRIDE %s
+
+// FVIS_HIDDEN: define hidden amdgpu_kernel void @kern()
+// FVIS_AMDGPU_HIDDEN: define amdgpu_kernel void @kern()
+// FVIS_AMDGPU_DEFAULT: define amdgpu_kernel void @kern()
+// FVIS_AMDGPU_OVERRIDE: define hidden amdgpu_kernel void @kern()
+kernel void kern() {}
+// FVIS_HIDDEN: define amdgpu_kernel void @default_kern()
+// FVIS_AMDGPU_HIDDEN: define amdgpu_kernel void @default_kern()
+// FVIS_AMDGPU_DEFAULT: define amdgpu_kernel void @default_kern()
+// FVIS_AMDGPU_OVERRIDE: define amdgpu_kernel void @default_kern()
+__attribute__((visibility("default"))) kernel void default_kern() {}
+// FVIS_HIDDEN: define hidden amdgpu_kernel void @hidden_kern()
+// FVIS_AMDGPU_HIDDEN: define hidden amdgpu_kernel void @hidden_kern()
+// FVIS_AMDGPU_DEFAULT: define hidden amdgpu_kernel void @hidden_kern()
+// FVIS_AMDGPU_OVERRIDE: define hidden amdgpu_kernel void @hidden_kern()
+__attribute__((visibility("hidden"))) kernel void hidden_kern() {}
+// FVIS_HIDDEN: define protected amdgpu_kernel void @protected_kern()
+// FVIS_AMDGPU_HIDDEN: define protected amdgpu_kernel void @protected_kern()
+// FVIS_AMDGPU_DEFAULT: define protected amdgpu_kernel void @protected_kern()
+// FVIS_AMDGPU_OVERRIDE: define protected amdgpu_kernel void @protected_kern()
+__attribute__((visibility("protected"))) kernel void protected_kern() {}
+
+// FVIS_HIDDEN: define hidden void @func()
+// FVIS_AMDGPU_HIDDEN: define hidden void @func()
+// FVIS_AMDGPU_DEFAULT: define void @func()
+// FVIS_AMDGPU_OVERRIDE: define void @func()
+void func() {}
+// FVIS_HIDDEN: define void @default_func()
+// FVIS_AMDGPU_HIDDEN: define void @default_func()
+// FVIS_AMDGPU_DEFAULT: define void @default_func()
+// FVIS_AMDGPU_OVERRIDE: define void @default_func()
+__attribute__((visibility("defaul

[PATCH] D52891: [AMDGPU] Add -fvisibility-amdgpu-non-kernel-functions

2018-10-08 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

I will update the patch to modify the HIP toolchain and to add tests for global 
variables.

As far as the semantics are concerned, are we OK with this being AMDGPU only? I 
do not see a means of determining what is a "kernel" in a language-agnostic way 
other than checking for our AMDGPU-specific calling convention. If there is a 
more general mechanism, this could be implemented in 
`LinkageComputer::getLVForNamespaceScopeDecl` instead. As it stands, it sounds 
like being AMDGPU specific, but omitting `amdgpu` from the option name is 
preferred?

What about:

  -fvisibility-non-offload-functions=
  
  Set the default symbol visibility for non-offload function declarations 
(AMDGPU only)

I cannot think of a way to avoid `non` or something similar ending up in the 
name.


https://reviews.llvm.org/D52891



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


[PATCH] D53153: [OpenCL] Mark kernel functions with default visibility

2019-02-01 Thread Scott Linder via Phabricator via cfe-commits
scott.linder abandoned this revision.
scott.linder added a comment.

See https://reviews.llvm.org/D56871


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53153/new/

https://reviews.llvm.org/D53153



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


[PATCH] D56871: [AMDGPU] Require at least protected visibility for certain symbols

2019-02-11 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Ping


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56871/new/

https://reviews.llvm.org/D56871



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


[PATCH] D56871: [AMDGPU] Require at least protected visibility for certain symbols

2019-02-12 Thread Scott Linder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL353870: [AMDGPU] Require at least protected visibility for 
certain symbols (authored by scott.linder, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D56871?vs=182561&id=186512#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56871/new/

https://reviews.llvm.org/D56871

Files:
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/TargetInfo.cpp
  cfe/trunk/test/CodeGenOpenCL/visibility.cl

Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -3212,6 +3212,9 @@
 return getTargetCodeGenInfo().performAddrSpaceCast(*this, GV, AddrSpace,
ExpectedAS, Ty);
 
+  if (GV->isDeclaration())
+getTargetCodeGenInfo().setTargetAttributes(D, GV, *this);
+
   return GV;
 }
 
Index: cfe/trunk/lib/CodeGen/TargetInfo.cpp
===
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp
@@ -7763,8 +7763,23 @@
 };
 }
 
+static bool requiresAMDGPUProtectedVisibility(const Decl *D,
+  llvm::GlobalValue *GV) {
+  if (GV->getVisibility() != llvm::GlobalValue::HiddenVisibility)
+return false;
+
+  return D->hasAttr() ||
+ (isa(D) && D->hasAttr()) ||
+ (isa(D) && D->hasAttr());
+}
+
 void AMDGPUTargetCodeGenInfo::setTargetAttributes(
 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (requiresAMDGPUProtectedVisibility(D, GV)) {
+GV->setVisibility(llvm::GlobalValue::ProtectedVisibility);
+GV->setDSOLocal(true);
+  }
+
   if (GV->isDeclaration())
 return;
   const FunctionDecl *FD = dyn_cast_or_null(D);
Index: cfe/trunk/test/CodeGenOpenCL/visibility.cl
===
--- cfe/trunk/test/CodeGenOpenCL/visibility.cl
+++ cfe/trunk/test/CodeGenOpenCL/visibility.cl
@@ -0,0 +1,77 @@
+// RUN: %clang_cc1 -std=cl2.0 -fapply-global-visibility-to-externs -fvisibility default -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-DEFAULT %s
+// RUN: %clang_cc1 -std=cl2.0 -fapply-global-visibility-to-externs -fvisibility protected -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-PROTECTED %s
+// RUN: %clang_cc1 -std=cl2.0 -fapply-global-visibility-to-externs -fvisibility hidden -triple amdgcn-unknown-unknown -S -emit-llvm -o - %s | FileCheck --check-prefix=FVIS-HIDDEN %s
+
+// REQUIRES: amdgpu-registered-target
+
+// FVIS-DEFAULT:  @glob = local_unnamed_addr
+// FVIS-PROTECTED: @glob = protected local_unnamed_addr
+// FVIS-HIDDEN: @glob = hidden local_unnamed_addr
+int glob = 0;
+// FVIS-DEFAULT:  @glob_hidden = hidden local_unnamed_addr
+// FVIS-PROTECTED: @glob_hidden = hidden local_unnamed_addr
+// FVIS-HIDDEN: @glob_hidden = hidden local_unnamed_addr
+__attribute__((visibility("hidden"))) int glob_hidden = 0;
+// FVIS-DEFAULT:  @glob_protected = protected local_unnamed_addr
+// FVIS-PROTECTED: @glob_protected = protected local_unnamed_addr
+// FVIS-HIDDEN: @glob_protected = protected local_unnamed_addr
+__attribute__((visibility("protected"))) int glob_protected = 0;
+// FVIS-DEFAULT:  @glob_default = local_unnamed_addr
+// FVIS-PROTECTED: @glob_default = local_unnamed_addr
+// FVIS-HIDDEN: @glob_default = local_unnamed_addr
+__attribute__((visibility("default"))) int glob_default = 0;
+
+// FVIS-DEFAULT:  @ext = external local_unnamed_addr
+// FVIS-PROTECTED: @ext = external protected local_unnamed_addr
+// FVIS-HIDDEN: @ext = external hidden local_unnamed_addr
+extern int ext;
+// FVIS-DEFAULT:  @ext_hidden = external hidden local_unnamed_addr
+// FVIS-PROTECTED: @ext_hidden = external hidden local_unnamed_addr
+// FVIS-HIDDEN: @ext_hidden = external hidden local_unnamed_addr
+__attribute__((visibility("hidden"))) extern int ext_hidden;
+// FVIS-DEFAULT:  @ext_protected = external protected local_unnamed_addr
+// FVIS-PROTECTED: @ext_protected = external protected local_unnamed_addr
+// FVIS-HIDDEN: @ext_protected = external protected local_unnamed_addr
+__attribute__((visibility("protected"))) extern int ext_protected;
+// FVIS-DEFAULT:  @ext_default = external local_unnamed_addr
+// FVIS-PROTECTED: @ext_default = external local_unnamed_addr
+// FVIS-HIDDEN: @ext_default = external local_unnamed_addr
+__attribute__((visibility("default"))) extern int ext_default;
+
+// FVIS-DEFAULT: define amdgpu_kernel void @kern()
+// FVIS-PROTECTED: define protected amdgpu_kernel void @kern()
+// FVIS-HIDDEN: define protected amdgpu_kernel void @kern()
+kernel void kern() {}
+// FVIS-DEFAULT: define protected am

[PATCH] D54489: Implement -frecord-command-line (-frecord-gcc-switches)

2018-12-13 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 178082.
scott.linder added a comment.

Update documentation to match section naming change, and to explicitly note 
that the section format differs from the equivalent GCC format.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54489/new/

https://reviews.llvm.org/D54489

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Basic/CodeGenOptions.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/clang_f_opts.c
  test/Driver/debug-options.c

Index: test/Driver/debug-options.c
===
--- test/Driver/debug-options.c
+++ test/Driver/debug-options.c
@@ -157,6 +157,17 @@
 // RUN: %clang -### -c -O3 -ffunction-sections -grecord-gcc-switches %s 2>&1 \
 // | FileCheck -check-prefix=GRECORD_OPT %s
 //
+// RUN: %clang -### -c -grecord-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GRECORD %s
+// RUN: %clang -### -c -gno-record-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GNO_RECORD %s
+// RUN: %clang -### -c -grecord-command-line -gno-record-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GNO_RECORD %s/
+// RUN: %clang -### -c -grecord-command-line -o - %s 2>&1 \
+// | FileCheck -check-prefix=GRECORD_O %s
+// RUN: %clang -### -c -O3 -ffunction-sections -grecord-command-line %s 2>&1 \
+// | FileCheck -check-prefix=GRECORD_OPT %s
+//
 // RUN: %clang -### -c -gstrict-dwarf -gno-strict-dwarf %s 2>&1 \
 // RUN:| FileCheck -check-prefix=GIGNORE %s
 //
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -542,3 +542,18 @@
 // RUN: %clang -### -S -fomit-frame-pointer -fno-omit-frame-pointer -pg %s 2>&1 | FileCheck -check-prefix=CHECK-MIX-NO-OMIT-FP-PG %s
 // CHECK-NO-MIX-OMIT-FP-PG: '-fomit-frame-pointer' not allowed with '-pg'
 // CHECK-MIX-NO-OMIT-FP-PG-NOT: '-fomit-frame-pointer' not allowed with '-pg'
+
+// RUN: %clang -### -S -target x86_64-unknown-linux -frecord-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-gcc-switches -frecord-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -frecord-gcc-switches -fno-record-gcc-switches %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-command-line -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
+// RUN: %clang -### -S -target x86_64-unknown-linux -frecord-command-line -fno-record-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
+// Test with a couple examples of non-ELF object file formats
+// RUN: %clang -### -S -target x86_64-unknown-macosx -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
+// RUN: %clang -### -S -target x86_64-unknown-windows -frecord-command-line %s 2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
+// CHECK-RECORD-GCC-SWITCHES: "-record-command-line"
+// CHECK-NO-RECORD-GCC-SWITCHES-NOT: "-record-command-line"
+// CHECK-RECORD-GCC-SWITCHES-ERROR: error: unsupported option '-frecord-command-line' for target
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -755,6 +755,7 @@
   Args.hasFlag(OPT_ffine_grained_bitfield_accesses,
OPT_fno_fine_grained_bitfield_accesses, false);
   Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
+  Opts.RecordCommandLine = Args.getLastArgValue(OPT_record_command_line);
   Opts.MergeAllConstants = Args.hasArg(OPT_fmerge_all_constants);
   Opts.NoCommon = Args.hasArg(OPT_fno_common);
   Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -5063,14 +5063,22 @@
 
   const char *Exec = D.getClangProgramPath();
 
-  // Optionally embed the -cc1 level arguments into the debug info, for build

[PATCH] D54489: Implement -frecord-command-line (-frecord-gcc-switches)

2018-12-13 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

In D54489#1330255 , @rjmccall wrote:

> So we're using the same command line option as GCC to produce something in 
> the same section as GCC but formatting that section incompatibly with GCC?  
> That combination of choices does not seem like a good idea.


From the GCC man page -frecord-gcc-switches "is only implemented on some 
targets and the exact format of the recording is target and binary file format 
dependent, but it usually takes the form of a section containing ASCII text"

In the LLVM portion of this review it was decided that the implications of this 
is that well-behaved consumers should not make assumptions about the format. 
They should also not make assumptions about the name of the section, but we are 
effectively backwards-compatible in that we are a section with ASCII text, so 
tools which just e.g. dump the section for uses will continue to work with our 
implementation.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54489/new/

https://reviews.llvm.org/D54489



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


[PATCH] D54489: Implement -frecord-command-line (-frecord-gcc-switches)

2018-12-14 Thread Scott Linder via Phabricator via cfe-commits
scott.linder closed this revision.
scott.linder added a comment.

rL349155 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54489/new/

https://reviews.llvm.org/D54489



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


  1   2   3   >