[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-09-23 Thread Scott Linder via cfe-commits


@@ -1755,6 +1755,56 @@ As part of the AMDGPU MC layer, AMDGPU provides the 
following target specific
 
  === = 

 
+Function Resource Usage
+---
+
+The function resource information (e.g., number of VGPRs) required depends on
+all of its callees' function resources. The expression to denote these
+resources should, therefore, be described as the propagative of its callees'
+equivalent expressions. Said expressions are generated and emitted (as symbols)
+by the compiler when compiling to either assembly or object format and should
+not be overwritten or redefined.
+
+The following describes all emitted function resource usage information:

slinder1 wrote:

Here too I think "information" could be replaced with "symbols". Then there are 
only two terms to keep track of:

* "Resource usage": The concept
* "Resource usage symbols": The interface we expose to access the usage

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-09-23 Thread Scott Linder via cfe-commits


@@ -1755,6 +1755,56 @@ As part of the AMDGPU MC layer, AMDGPU provides the 
following target specific
 
  === = 

 
+Function Resource Usage
+---
+
+The function resource information (e.g., number of VGPRs) required depends on
+all of its callees' function resources. The expression to denote these
+resources should, therefore, be described as the propagative of its callees'
+equivalent expressions. Said expressions are generated and emitted (as symbols)
+by the compiler when compiling to either assembly or object format and should
+not be overwritten or redefined.
+
+The following describes all emitted function resource usage information:
+
+  .. table:: Function Resource Usage:
+ :name: function-usage-table
+
+ = = 
= 
===
+ SymbolType  Description   
Example
+ = = 
= 
===
+ .num_vgpr  Integer   Number of VGPRs used by 
,  .set foo.num_vgpr, max(32, bar.num_vgpr, baz.num_vgpr)
+ worst case of itself and 
its callees'
+ VGPR use
+ .num_agpr  Integer   Number of AGPRs used by 
,  .set foo.num_agpr, max(35, bar.num_agpr)
+ worst case of itself and 
its callees'
+ AGPR use
+ .numbered_sgpr Integer   Number of SGPRs used by 
,  .set foo.num_sgpr, 21
+ worst case of itself and 
its callees'
+ SGPR use (without any of 
the implicitly
+ used SGPRs)
+ .private_seg_size  Integer   Total stack size required 
for .set foo.private_seg_size, 16+max(bar.private_seg_size, 
baz.private_seg_size)
+ , 
expression is the
+ locally used stack size + 
the worst case
+ callee
+ .uses_vcc  Bool  Whether , 
or any of its.set foo.uses_vcc, or(0, bar.uses_vcc)
+ callees, uses vcc or not
+ .uses_flat_scratch Bool  Whether , 
or any of its.set foo.uses_flat_scratch, 1
+ callees, uses flat 
scratch or not
+ .has_dyn_sized_stack   Bool  Whether  
stack is  .set foo.has_dyn_sized_stack, 1

slinder1 wrote:

Is this the only property without the callee propagation property? If so, it 
may be worth noting that explicitly

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-09-23 Thread Scott Linder via cfe-commits


@@ -1755,6 +1755,56 @@ As part of the AMDGPU MC layer, AMDGPU provides the 
following target specific
 
  === = 

 
+Function Resource Usage
+---
+
+The function resource information (e.g., number of VGPRs) required depends on
+all of its callees' function resources. The expression to denote these
+resources should, therefore, be described as the propagative of its callees'
+equivalent expressions. Said expressions are generated and emitted (as symbols)
+by the compiler when compiling to either assembly or object format and should
+not be overwritten or redefined.
+
+The following describes all emitted function resource usage information:
+
+  .. table:: Function Resource Usage:
+ :name: function-usage-table
+
+ = = 
= 
===
+ SymbolType  Description   
Example
+ = = 
= 
===
+ .num_vgpr  Integer   Number of VGPRs used by 
,  .set foo.num_vgpr, max(32, bar.num_vgpr, baz.num_vgpr)
+ worst case of itself and 
its callees'
+ VGPR use
+ .num_agpr  Integer   Number of AGPRs used by 
,  .set foo.num_agpr, max(35, bar.num_agpr)
+ worst case of itself and 
its callees'
+ AGPR use
+ .numbered_sgpr Integer   Number of SGPRs used by 
,  .set foo.num_sgpr, 21
+ worst case of itself and 
its callees'
+ SGPR use (without any of 
the implicitly
+ used SGPRs)
+ .private_seg_size  Integer   Total stack size required 
for .set foo.private_seg_size, 16+max(bar.private_seg_size, 
baz.private_seg_size)
+ , 
expression is the
+ locally used stack size + 
the worst case
+ callee
+ .uses_vcc  Bool  Whether , 
or any of its.set foo.uses_vcc, or(0, bar.uses_vcc)
+ callees, uses vcc or not

slinder1 wrote:

The "or not" could probably be dropped

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-09-23 Thread Scott Linder via cfe-commits


@@ -1755,6 +1755,56 @@ As part of the AMDGPU MC layer, AMDGPU provides the 
following target specific
 
  === = 

 
+Function Resource Usage
+---
+
+The function resource information (e.g., number of VGPRs) required depends on
+all of its callees' function resources. The expression to denote these
+resources should, therefore, be described as the propagative of its callees'
+equivalent expressions. Said expressions are generated and emitted (as symbols)

slinder1 wrote:

"generated and emitted" could probably be just "emitted", and the parenthesis 
are not needed around "as symbols":

```
Said expressions are emitted as symbols by the compiler ...
```

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-09-23 Thread Scott Linder via cfe-commits


@@ -1755,6 +1755,56 @@ As part of the AMDGPU MC layer, AMDGPU provides the 
following target specific
 
  === = 

 
+Function Resource Usage
+---
+
+The function resource information (e.g., number of VGPRs) required depends on

slinder1 wrote:

Nit, I would use an indefinite article to start this sentence, since it is 
talking about "any"/"every" function rather than a particular function. I also 
think consistently referring to "resource usage" rather than "resource 
information" would help, and the parenthetical example breaks things up too 
much IMO.

```
A function's resource usage depends on each of its callees' resource usage. The 
expressions used to denote resource usage reflect this by propagating each 
callees' equivalent expressions. Said expressions ...
```

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-09-23 Thread Scott Linder via cfe-commits


@@ -1755,6 +1755,56 @@ As part of the AMDGPU MC layer, AMDGPU provides the 
following target specific
 
  === = 

 
+Function Resource Usage
+---
+
+The function resource information (e.g., number of VGPRs) required depends on
+all of its callees' function resources. The expression to denote these
+resources should, therefore, be described as the propagative of its callees'
+equivalent expressions. Said expressions are generated and emitted (as symbols)
+by the compiler when compiling to either assembly or object format and should
+not be overwritten or redefined.
+
+The following describes all emitted function resource usage information:
+
+  .. table:: Function Resource Usage:
+ :name: function-usage-table
+
+ = = 
= 
===
+ SymbolType  Description   
Example
+ = = 
= 
===
+ .num_vgpr  Integer   Number of VGPRs used by 
,  .set foo.num_vgpr, max(32, bar.num_vgpr, baz.num_vgpr)
+ worst case of itself and 
its callees'
+ VGPR use
+ .num_agpr  Integer   Number of AGPRs used by 
,  .set foo.num_agpr, max(35, bar.num_agpr)
+ worst case of itself and 
its callees'
+ AGPR use
+ .numbered_sgpr Integer   Number of SGPRs used by 
,  .set foo.num_sgpr, 21
+ worst case of itself and 
its callees'
+ SGPR use (without any of 
the implicitly
+ used SGPRs)
+ .private_seg_size  Integer   Total stack size required 
for .set foo.private_seg_size, 16+max(bar.private_seg_size, 
baz.private_seg_size)
+ , 
expression is the
+ locally used stack size + 
the worst case
+ callee
+ .uses_vcc  Bool  Whether , 
or any of its.set foo.uses_vcc, or(0, bar.uses_vcc)
+ callees, uses vcc or not
+ .uses_flat_scratch Bool  Whether , 
or any of its.set foo.uses_flat_scratch, 1
+ callees, uses flat 
scratch or not
+ .has_dyn_sized_stack   Bool  Whether  
stack is  .set foo.has_dyn_sized_stack, 1
+ dynamically sized
+ .has_recursion Bool  Whether , 
or any of its.set foo.has_recursion, 0
+ callees, contains 
recursion
+ .has_indirect_call Bool  Whether , 
or any of its.set foo.has_indirect_call, max(0, bar.has_indirect_call)
+ callees, contains an 
indirect call
+ = = 
= 
===
+
+Futhermore, three symbols are additionally emitted describing the compilation
+unit's worst case (i.e, maxima) ``num_vgpr``, ``num_agpr``, and
+``numbered_sgpr`` which may be referenced and used by the aforementioned
+symbolic expressions. These three symbols are ``max_num_vgpr``,

slinder1 wrote:

I didn't notice these symbols before, but do we want to also prefix these to 
reduce the chance for collisions? What about `.amdgcn.max_*`, to match the 
existing `.set .amdgcn.next_free_*` symbols?

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-09-23 Thread Scott Linder via cfe-commits

https://github.com/slinder1 edited 
https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-09-23 Thread Scott Linder via cfe-commits

https://github.com/slinder1 requested changes to this pull request.

Thank you for writing this up! I have some stylistic comments, but otherwise 
LGTM

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-09-17 Thread Scott Linder via cfe-commits


@@ -0,0 +1,220 @@
+//===- AMDGPUMCResourceInfo.cpp --- MC Resource Info 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+/// \file
+/// \brief MC infrastructure to propagate the function level resource usage
+/// info.
+///
+//===--===//
+
+#include "AMDGPUMCResourceInfo.h"
+#include "Utils/AMDGPUBaseInfo.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCSymbol.h"
+
+using namespace llvm;
+
+MCSymbol *MCResourceInfo::getSymbol(StringRef FuncName, ResourceInfoKind RIK) {
+  switch (RIK) {
+  case RIK_NumVGPR:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".num_vgpr"));

slinder1 wrote:

The names seem fine to me, but we should write down which symbols are 
"reserved" or "well known" or however we want to define it relative to how they 
are intended to be used. Can you document them in AMDGPUUsage maybe?

My original question was more around how a user could technically contrive a 
conflict with an `__asm__(("foo.num_vgpr"))` definition, which is outlandish 
and easy enough for us to say "don't do that". I just want to make sure we 
write down the spirit of "don't do that", in a similar way to how C/C++ (I 
believe?) define symbols starting with "__" as reserved for implementation use.

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-08-16 Thread Scott Linder via cfe-commits


@@ -0,0 +1,220 @@
+//===- AMDGPUMCResourceInfo.cpp --- MC Resource Info 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+/// \file
+/// \brief MC infrastructure to propagate the function level resource usage
+/// info.
+///
+//===--===//
+
+#include "AMDGPUMCResourceInfo.h"
+#include "Utils/AMDGPUBaseInfo.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCSymbol.h"
+
+using namespace llvm;
+
+MCSymbol *MCResourceInfo::getSymbol(StringRef FuncName, ResourceInfoKind RIK) {
+  switch (RIK) {
+  case RIK_NumVGPR:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".num_vgpr"));
+  case RIK_NumAGPR:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".num_agpr"));
+  case RIK_NumSGPR:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".num_sgpr"));
+  case RIK_PrivateSegSize:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".private_seg_size"));
+  case RIK_UsesVCC:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".uses_vcc"));
+  case RIK_UsesFlatScratch:
+return OutContext.getOrCreateSymbol(FuncName + 
Twine(".uses_flat_scratch"));
+  case RIK_HasDynSizedStack:
+return OutContext.getOrCreateSymbol(FuncName +
+Twine(".has_dyn_sized_stack"));
+  case RIK_HasRecursion:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".has_recursion"));
+  case RIK_HasIndirectCall:
+return OutContext.getOrCreateSymbol(FuncName + 
Twine(".has_indirect_call"));
+  }
+  llvm_unreachable("Unexpected ResourceInfoKind.");
+}
+
+const MCExpr *MCResourceInfo::getSymRefExpr(StringRef FuncName,
+ResourceInfoKind RIK,
+MCContext &Ctx) {
+  return MCSymbolRefExpr::create(getSymbol(FuncName, RIK), Ctx);
+}
+
+void MCResourceInfo::assignMaxRegs() {
+  // Assign expression to get the max register use to the max_num_Xgpr symbol.
+  MCSymbol *MaxVGPRSym = getMaxVGPRSymbol();
+  MCSymbol *MaxAGPRSym = getMaxAGPRSymbol();
+  MCSymbol *MaxSGPRSym = getMaxSGPRSymbol();
+
+  auto assignMaxRegSym = [this](MCSymbol *Sym, int32_t RegCount) {
+const MCExpr *MaxExpr = MCConstantExpr::create(RegCount, OutContext);
+Sym->setVariableValue(MaxExpr);
+  };
+
+  assignMaxRegSym(MaxVGPRSym, MaxVGPR);
+  assignMaxRegSym(MaxAGPRSym, MaxAGPR);
+  assignMaxRegSym(MaxSGPRSym, MaxSGPR);
+}
+
+void MCResourceInfo::finalize() {
+  assert(!finalized && "Cannot finalize ResourceInfo again.");
+  finalized = true;
+  assignMaxRegs();
+}
+
+MCSymbol *MCResourceInfo::getMaxVGPRSymbol() {
+  return OutContext.getOrCreateSymbol("max_num_vgpr");
+}
+
+MCSymbol *MCResourceInfo::getMaxAGPRSymbol() {
+  return OutContext.getOrCreateSymbol("max_num_agpr");
+}
+
+MCSymbol *MCResourceInfo::getMaxSGPRSymbol() {
+  return OutContext.getOrCreateSymbol("max_num_sgpr");
+}
+
+void MCResourceInfo::assignResourceInfoExpr(
+int64_t localValue, ResourceInfoKind RIK, AMDGPUMCExpr::VariantKind Kind,
+const MachineFunction &MF,
+const SmallVectorImpl &Callees) {
+  const MCConstantExpr *localConstExpr =
+  MCConstantExpr::create(localValue, OutContext);
+  const MCExpr *SymVal = localConstExpr;
+  if (!Callees.empty()) {
+SmallVector ArgExprs;
+// Avoid recursive symbol assignment.
+SmallSet Seen;
+ArgExprs.push_back(localConstExpr);
+Seen.insert(MF.getName());

slinder1 wrote:

Is there not a guarantee that the mapping from MF<->name is 1:1 ?

A SmallPtrSet would avoid string comparisons

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-08-16 Thread Scott Linder via cfe-commits


@@ -0,0 +1,220 @@
+//===- AMDGPUMCResourceInfo.cpp --- MC Resource Info 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+/// \file
+/// \brief MC infrastructure to propagate the function level resource usage
+/// info.
+///
+//===--===//
+
+#include "AMDGPUMCResourceInfo.h"
+#include "Utils/AMDGPUBaseInfo.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCSymbol.h"
+
+using namespace llvm;
+
+MCSymbol *MCResourceInfo::getSymbol(StringRef FuncName, ResourceInfoKind RIK) {
+  switch (RIK) {
+  case RIK_NumVGPR:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".num_vgpr"));
+  case RIK_NumAGPR:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".num_agpr"));
+  case RIK_NumSGPR:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".num_sgpr"));
+  case RIK_PrivateSegSize:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".private_seg_size"));
+  case RIK_UsesVCC:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".uses_vcc"));
+  case RIK_UsesFlatScratch:
+return OutContext.getOrCreateSymbol(FuncName + 
Twine(".uses_flat_scratch"));
+  case RIK_HasDynSizedStack:
+return OutContext.getOrCreateSymbol(FuncName +
+Twine(".has_dyn_sized_stack"));
+  case RIK_HasRecursion:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".has_recursion"));
+  case RIK_HasIndirectCall:
+return OutContext.getOrCreateSymbol(FuncName + 
Twine(".has_indirect_call"));
+  }
+  llvm_unreachable("Unexpected ResourceInfoKind.");
+}
+
+const MCExpr *MCResourceInfo::getSymRefExpr(StringRef FuncName,
+ResourceInfoKind RIK,
+MCContext &Ctx) {
+  return MCSymbolRefExpr::create(getSymbol(FuncName, RIK), Ctx);
+}
+
+void MCResourceInfo::assignMaxRegs() {
+  // Assign expression to get the max register use to the max_num_Xgpr symbol.
+  MCSymbol *MaxVGPRSym = getMaxVGPRSymbol();
+  MCSymbol *MaxAGPRSym = getMaxAGPRSymbol();
+  MCSymbol *MaxSGPRSym = getMaxSGPRSymbol();
+
+  auto assignMaxRegSym = [this](MCSymbol *Sym, int32_t RegCount) {
+const MCExpr *MaxExpr = MCConstantExpr::create(RegCount, OutContext);
+Sym->setVariableValue(MaxExpr);
+  };
+
+  assignMaxRegSym(MaxVGPRSym, MaxVGPR);
+  assignMaxRegSym(MaxAGPRSym, MaxAGPR);
+  assignMaxRegSym(MaxSGPRSym, MaxSGPR);
+}
+
+void MCResourceInfo::finalize() {
+  assert(!finalized && "Cannot finalize ResourceInfo again.");
+  finalized = true;
+  assignMaxRegs();
+}
+
+MCSymbol *MCResourceInfo::getMaxVGPRSymbol() {
+  return OutContext.getOrCreateSymbol("max_num_vgpr");
+}
+
+MCSymbol *MCResourceInfo::getMaxAGPRSymbol() {
+  return OutContext.getOrCreateSymbol("max_num_agpr");
+}
+
+MCSymbol *MCResourceInfo::getMaxSGPRSymbol() {
+  return OutContext.getOrCreateSymbol("max_num_sgpr");
+}
+
+void MCResourceInfo::assignResourceInfoExpr(
+int64_t localValue, ResourceInfoKind RIK, AMDGPUMCExpr::VariantKind Kind,

slinder1 wrote:

s/localValue/LocalValue/

Similar changes elsewhere

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-08-16 Thread Scott Linder via cfe-commits


@@ -0,0 +1,220 @@
+//===- AMDGPUMCResourceInfo.cpp --- MC Resource Info 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+/// \file
+/// \brief MC infrastructure to propagate the function level resource usage
+/// info.
+///
+//===--===//
+
+#include "AMDGPUMCResourceInfo.h"
+#include "Utils/AMDGPUBaseInfo.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCSymbol.h"
+
+using namespace llvm;
+
+MCSymbol *MCResourceInfo::getSymbol(StringRef FuncName, ResourceInfoKind RIK) {
+  switch (RIK) {
+  case RIK_NumVGPR:
+return OutContext.getOrCreateSymbol(FuncName + Twine(".num_vgpr"));

slinder1 wrote:

Are these names guaranteed to be unique? Do we reserve any symbol with a '.' in 
it?

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-08-16 Thread Scott Linder via cfe-commits


@@ -0,0 +1,220 @@
+//===- AMDGPUMCResourceInfo.cpp --- MC Resource Info 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+/// \file
+/// \brief MC infrastructure to propagate the function level resource usage
+/// info.
+///
+//===--===//
+
+#include "AMDGPUMCResourceInfo.h"
+#include "Utils/AMDGPUBaseInfo.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCSymbol.h"
+
+using namespace llvm;
+
+MCSymbol *MCResourceInfo::getSymbol(StringRef FuncName, ResourceInfoKind RIK) {
+  switch (RIK) {

slinder1 wrote:

Nit: the `OutContext.getOrCreateSymbol(FuncName + Suffix)`  bit seems like it 
might be worth factoring out to keep the case arms focused

```
auto GOCS = [this](StringRef Suffix) {
  return OutContext.getOrCreateSymbol(FuncName + Suffix);
};
switch (RIK) {
case RIK_NumAGPR: return GOCS(".num_agpr");
case RIK_NumSGPR: return GOCS(".num_sgpr");
// ...
}
```

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-08-16 Thread Scott Linder via cfe-commits

https://github.com/slinder1 commented:

LGTM, with some nits

The expressions look pretty reasonable to me, although I didn't really go 
through validating that they are correct

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-08-16 Thread Scott Linder via cfe-commits

https://github.com/slinder1 edited 
https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-08-14 Thread Scott Linder via cfe-commits

slinder1 wrote:

Is it best to leave comments on the commit from the PR comment, i.e. currently 
https://github.com/llvm/llvm-project/commit/51f72f115b340a092c2c9f8569911b944a4efb6d
 ?

I can't seem to start a review, so it will be individual comments (I think). Is 
there another way to handle this?

https://github.com/llvm/llvm-project/pull/102913
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [libcxx] [compiler-rt] [llvm] [lldb] [flang] [lld] [YAMLParser] Unfold multi-line scalar values (PR #70898)

2023-11-06 Thread Scott Linder via cfe-commits


@@ -2030,187 +2030,219 @@ bool Node::failed() const {
 }
 
 StringRef ScalarNode::getValue(SmallVectorImpl &Storage) const {
-  // TODO: Handle newlines properly. We need to remove leading whitespace.
-  if (Value[0] == '"') { // Double quoted.
-// Pull off the leading and trailing "s.
-StringRef UnquotedValue = Value.substr(1, Value.size() - 2);
-// Search for characters that would require unescaping the value.
-StringRef::size_type i = UnquotedValue.find_first_of("\\\r\n");
-if (i != StringRef::npos)
-  return unescapeDoubleQuoted(UnquotedValue, i, Storage);
+  if (Value[0] == '"')
+return getDoubleQuotedValue(Value, Storage);
+  if (Value[0] == '\'')
+return getSingleQuotedValue(Value, Storage);
+  return getPlainValue(Value, Storage);
+}
+
+static StringRef
+parseScalarValue(StringRef UnquotedValue, SmallVectorImpl &Storage,
+ StringRef LookupChars,

slinder1 wrote:

That "\x0A\x0D" must be a part of `LookupChars` but cannot be handled by 
`UnescapeCallback` (or at least those characters will never reach the callback) 
is probably worthy of a comment, as it didn't follow for me immediately upon a 
first read.

https://github.com/llvm/llvm-project/pull/70898
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [lldb] [clang] [llvm] [lld] [clang-tools-extra] [libcxx] [compiler-rt] [YAMLParser] Unfold multi-line scalar values (PR #70898)

2023-11-06 Thread Scott Linder via cfe-commits


@@ -2030,187 +2030,219 @@ bool Node::failed() const {
 }
 
 StringRef ScalarNode::getValue(SmallVectorImpl &Storage) const {
-  // TODO: Handle newlines properly. We need to remove leading whitespace.
-  if (Value[0] == '"') { // Double quoted.
-// Pull off the leading and trailing "s.
-StringRef UnquotedValue = Value.substr(1, Value.size() - 2);
-// Search for characters that would require unescaping the value.
-StringRef::size_type i = UnquotedValue.find_first_of("\\\r\n");
-if (i != StringRef::npos)
-  return unescapeDoubleQuoted(UnquotedValue, i, Storage);
+  if (Value[0] == '"')
+return getDoubleQuotedValue(Value, Storage);
+  if (Value[0] == '\'')
+return getSingleQuotedValue(Value, Storage);
+  return getPlainValue(Value, Storage);
+}
+
+static StringRef
+parseScalarValue(StringRef UnquotedValue, SmallVectorImpl &Storage,
+ StringRef LookupChars,
+ std::function &)>
+ UnescapeCallback) {
+  size_t I = UnquotedValue.find_first_of(LookupChars);
+  if (I == StringRef::npos)
 return UnquotedValue;
-  } else if (Value[0] == '\'') { // Single quoted.
-// Pull off the leading and trailing 's.
-StringRef UnquotedValue = Value.substr(1, Value.size() - 2);
-StringRef::size_type i = UnquotedValue.find('\'');
-if (i != StringRef::npos) {
-  // We're going to need Storage.
-  Storage.clear();
-  Storage.reserve(UnquotedValue.size());
-  for (; i != StringRef::npos; i = UnquotedValue.find('\'')) {
-StringRef Valid(UnquotedValue.begin(), i);
-llvm::append_range(Storage, Valid);
-Storage.push_back('\'');
-UnquotedValue = UnquotedValue.substr(i + 2);
-  }
-  llvm::append_range(Storage, UnquotedValue);
-  return StringRef(Storage.begin(), Storage.size());
-}
-return UnquotedValue;
-  }
-  // Plain.
-  // Trim whitespace ('b-char' and 's-white').
-  // NOTE: Alternatively we could change the scanner to not include whitespace
-  //   here in the first place.
-  return Value.rtrim("\x0A\x0D\x20\x09");
-}
 
-StringRef ScalarNode::unescapeDoubleQuoted( StringRef UnquotedValue
-  , StringRef::size_type i
-  , SmallVectorImpl &Storage)
-  const {
-  // Use Storage to build proper value.
   Storage.clear();
   Storage.reserve(UnquotedValue.size());
-  for (; i != StringRef::npos; i = UnquotedValue.find_first_of("\\\r\n")) {
-// Insert all previous chars into Storage.
-StringRef Valid(UnquotedValue.begin(), i);
-llvm::append_range(Storage, Valid);
-// Chop off inserted chars.
-UnquotedValue = UnquotedValue.substr(i);
-
-assert(!UnquotedValue.empty() && "Can't be empty!");
-
-// Parse escape or line break.
-switch (UnquotedValue[0]) {
-case '\r':
-case '\n':
-  Storage.push_back('\n');
-  if (   UnquotedValue.size() > 1
-  && (UnquotedValue[1] == '\r' || UnquotedValue[1] == '\n'))
-UnquotedValue = UnquotedValue.substr(1);
-  UnquotedValue = UnquotedValue.substr(1);
-  break;
-default:
-  if (UnquotedValue.size() == 1) {
-Token T;
-T.Range = StringRef(UnquotedValue.begin(), 1);
-setError("Unrecognized escape code", T);
-return "";
-  }
-  UnquotedValue = UnquotedValue.substr(1);
-  switch (UnquotedValue[0]) {
-  default: {
-  Token T;
-  T.Range = StringRef(UnquotedValue.begin(), 1);
-  setError("Unrecognized escape code", T);
-  return "";
-}
-  case '\r':
-  case '\n':
-// Remove the new line.
-if (   UnquotedValue.size() > 1
-&& (UnquotedValue[1] == '\r' || UnquotedValue[1] == '\n'))
-  UnquotedValue = UnquotedValue.substr(1);
-// If this was just a single byte newline, it will get skipped
-// below.
-break;
-  case '0':
-Storage.push_back(0x00);
-break;
-  case 'a':
-Storage.push_back(0x07);
-break;
-  case 'b':
-Storage.push_back(0x08);
-break;
-  case 't':
-  case 0x09:
-Storage.push_back(0x09);
-break;
-  case 'n':
-Storage.push_back(0x0A);
-break;
-  case 'v':
-Storage.push_back(0x0B);
-break;
-  case 'f':
-Storage.push_back(0x0C);
-break;
-  case 'r':
-Storage.push_back(0x0D);
-break;
-  case 'e':
-Storage.push_back(0x1B);
-break;
+  char LastNewLineAddedAs = '\0';
+  for (; I != StringRef::npos; I = UnquotedValue.find_first_of(LookupChars)) {
+if (UnquotedValue[I] != '\x0D' && UnquotedValue[I] != '\x0A') {

slinder1 wrote:

Is there a reason to change from the "mnemonic" escape to a codepoint value 
one? E.g. is there a case where `'\r' != '\x0D'`, or is this just a stylistic 
c

[libcxx] [flang] [compiler-rt] [clang-tools-extra] [lldb] [llvm] [lld] [clang] [YAMLParser] Unfold multi-line scalar values (PR #70898)

2023-11-06 Thread Scott Linder via cfe-commits

https://github.com/slinder1 edited 
https://github.com/llvm/llvm-project/pull/70898
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [libcxx] [llvm] [flang] [lldb] [compiler-rt] [lld] [YAMLParser] Unfold multi-line scalar values (PR #70898)

2023-11-06 Thread Scott Linder via cfe-commits


@@ -2030,187 +2030,219 @@ bool Node::failed() const {
 }
 
 StringRef ScalarNode::getValue(SmallVectorImpl &Storage) const {
-  // TODO: Handle newlines properly. We need to remove leading whitespace.
-  if (Value[0] == '"') { // Double quoted.
-// Pull off the leading and trailing "s.
-StringRef UnquotedValue = Value.substr(1, Value.size() - 2);
-// Search for characters that would require unescaping the value.
-StringRef::size_type i = UnquotedValue.find_first_of("\\\r\n");
-if (i != StringRef::npos)
-  return unescapeDoubleQuoted(UnquotedValue, i, Storage);
+  if (Value[0] == '"')
+return getDoubleQuotedValue(Value, Storage);
+  if (Value[0] == '\'')
+return getSingleQuotedValue(Value, Storage);
+  return getPlainValue(Value, Storage);
+}
+
+static StringRef
+parseScalarValue(StringRef UnquotedValue, SmallVectorImpl &Storage,
+ StringRef LookupChars,
+ std::function &)>
+ UnescapeCallback) {
+  size_t I = UnquotedValue.find_first_of(LookupChars);
+  if (I == StringRef::npos)
 return UnquotedValue;
-  } else if (Value[0] == '\'') { // Single quoted.
-// Pull off the leading and trailing 's.
-StringRef UnquotedValue = Value.substr(1, Value.size() - 2);
-StringRef::size_type i = UnquotedValue.find('\'');
-if (i != StringRef::npos) {
-  // We're going to need Storage.
-  Storage.clear();
-  Storage.reserve(UnquotedValue.size());
-  for (; i != StringRef::npos; i = UnquotedValue.find('\'')) {
-StringRef Valid(UnquotedValue.begin(), i);
-llvm::append_range(Storage, Valid);
-Storage.push_back('\'');
-UnquotedValue = UnquotedValue.substr(i + 2);
-  }
-  llvm::append_range(Storage, UnquotedValue);
-  return StringRef(Storage.begin(), Storage.size());
-}
-return UnquotedValue;
-  }
-  // Plain.
-  // Trim whitespace ('b-char' and 's-white').
-  // NOTE: Alternatively we could change the scanner to not include whitespace
-  //   here in the first place.
-  return Value.rtrim("\x0A\x0D\x20\x09");
-}
 
-StringRef ScalarNode::unescapeDoubleQuoted( StringRef UnquotedValue
-  , StringRef::size_type i
-  , SmallVectorImpl &Storage)
-  const {
-  // Use Storage to build proper value.
   Storage.clear();
   Storage.reserve(UnquotedValue.size());
-  for (; i != StringRef::npos; i = UnquotedValue.find_first_of("\\\r\n")) {
-// Insert all previous chars into Storage.
-StringRef Valid(UnquotedValue.begin(), i);
-llvm::append_range(Storage, Valid);
-// Chop off inserted chars.
-UnquotedValue = UnquotedValue.substr(i);
-
-assert(!UnquotedValue.empty() && "Can't be empty!");
-
-// Parse escape or line break.
-switch (UnquotedValue[0]) {
-case '\r':
-case '\n':
-  Storage.push_back('\n');
-  if (   UnquotedValue.size() > 1
-  && (UnquotedValue[1] == '\r' || UnquotedValue[1] == '\n'))
-UnquotedValue = UnquotedValue.substr(1);
-  UnquotedValue = UnquotedValue.substr(1);
-  break;
-default:
-  if (UnquotedValue.size() == 1) {
-Token T;
-T.Range = StringRef(UnquotedValue.begin(), 1);
-setError("Unrecognized escape code", T);
-return "";
-  }
-  UnquotedValue = UnquotedValue.substr(1);
-  switch (UnquotedValue[0]) {
-  default: {
-  Token T;
-  T.Range = StringRef(UnquotedValue.begin(), 1);
-  setError("Unrecognized escape code", T);
-  return "";
-}
-  case '\r':
-  case '\n':
-// Remove the new line.
-if (   UnquotedValue.size() > 1
-&& (UnquotedValue[1] == '\r' || UnquotedValue[1] == '\n'))
-  UnquotedValue = UnquotedValue.substr(1);
-// If this was just a single byte newline, it will get skipped
-// below.
-break;
-  case '0':
-Storage.push_back(0x00);
-break;
-  case 'a':
-Storage.push_back(0x07);
-break;
-  case 'b':
-Storage.push_back(0x08);
-break;
-  case 't':
-  case 0x09:
-Storage.push_back(0x09);
-break;
-  case 'n':
-Storage.push_back(0x0A);
-break;
-  case 'v':
-Storage.push_back(0x0B);
-break;
-  case 'f':
-Storage.push_back(0x0C);
-break;
-  case 'r':
-Storage.push_back(0x0D);
-break;
-  case 'e':
-Storage.push_back(0x1B);
-break;
+  char LastNewLineAddedAs = '\0';
+  for (; I != StringRef::npos; I = UnquotedValue.find_first_of(LookupChars)) {
+if (UnquotedValue[I] != '\x0D' && UnquotedValue[I] != '\x0A') {
+  llvm::append_range(Storage, UnquotedValue.take_front(I));
+  UnquotedValue = UnescapeCallback(UnquotedValue.drop_front(I), Storage);
+  LastNewLineAddedAs = '\0';
+  contin

[clang-tools-extra] [llvm] [lld] [compiler-rt] [libcxx] [flang] [lldb] [clang] [YAMLParser] Unfold multi-line scalar values (PR #70898)

2023-11-06 Thread Scott Linder via cfe-commits


@@ -2030,187 +2030,219 @@ bool Node::failed() const {
 }
 
 StringRef ScalarNode::getValue(SmallVectorImpl &Storage) const {
-  // TODO: Handle newlines properly. We need to remove leading whitespace.
-  if (Value[0] == '"') { // Double quoted.
-// Pull off the leading and trailing "s.
-StringRef UnquotedValue = Value.substr(1, Value.size() - 2);
-// Search for characters that would require unescaping the value.
-StringRef::size_type i = UnquotedValue.find_first_of("\\\r\n");
-if (i != StringRef::npos)
-  return unescapeDoubleQuoted(UnquotedValue, i, Storage);
+  if (Value[0] == '"')
+return getDoubleQuotedValue(Value, Storage);
+  if (Value[0] == '\'')
+return getSingleQuotedValue(Value, Storage);
+  return getPlainValue(Value, Storage);
+}
+
+static StringRef
+parseScalarValue(StringRef UnquotedValue, SmallVectorImpl &Storage,
+ StringRef LookupChars,
+ std::function &)>
+ UnescapeCallback) {
+  size_t I = UnquotedValue.find_first_of(LookupChars);
+  if (I == StringRef::npos)
 return UnquotedValue;
-  } else if (Value[0] == '\'') { // Single quoted.
-// Pull off the leading and trailing 's.
-StringRef UnquotedValue = Value.substr(1, Value.size() - 2);
-StringRef::size_type i = UnquotedValue.find('\'');
-if (i != StringRef::npos) {
-  // We're going to need Storage.
-  Storage.clear();
-  Storage.reserve(UnquotedValue.size());
-  for (; i != StringRef::npos; i = UnquotedValue.find('\'')) {
-StringRef Valid(UnquotedValue.begin(), i);
-llvm::append_range(Storage, Valid);
-Storage.push_back('\'');
-UnquotedValue = UnquotedValue.substr(i + 2);
-  }
-  llvm::append_range(Storage, UnquotedValue);
-  return StringRef(Storage.begin(), Storage.size());
-}
-return UnquotedValue;
-  }
-  // Plain.
-  // Trim whitespace ('b-char' and 's-white').
-  // NOTE: Alternatively we could change the scanner to not include whitespace
-  //   here in the first place.
-  return Value.rtrim("\x0A\x0D\x20\x09");
-}
 
-StringRef ScalarNode::unescapeDoubleQuoted( StringRef UnquotedValue
-  , StringRef::size_type i
-  , SmallVectorImpl &Storage)
-  const {
-  // Use Storage to build proper value.
   Storage.clear();
   Storage.reserve(UnquotedValue.size());
-  for (; i != StringRef::npos; i = UnquotedValue.find_first_of("\\\r\n")) {
-// Insert all previous chars into Storage.
-StringRef Valid(UnquotedValue.begin(), i);
-llvm::append_range(Storage, Valid);
-// Chop off inserted chars.
-UnquotedValue = UnquotedValue.substr(i);
-
-assert(!UnquotedValue.empty() && "Can't be empty!");
-
-// Parse escape or line break.
-switch (UnquotedValue[0]) {
-case '\r':
-case '\n':
-  Storage.push_back('\n');
-  if (   UnquotedValue.size() > 1
-  && (UnquotedValue[1] == '\r' || UnquotedValue[1] == '\n'))
-UnquotedValue = UnquotedValue.substr(1);
-  UnquotedValue = UnquotedValue.substr(1);
-  break;
-default:
-  if (UnquotedValue.size() == 1) {
-Token T;
-T.Range = StringRef(UnquotedValue.begin(), 1);
-setError("Unrecognized escape code", T);
-return "";
-  }
-  UnquotedValue = UnquotedValue.substr(1);
-  switch (UnquotedValue[0]) {
-  default: {
-  Token T;
-  T.Range = StringRef(UnquotedValue.begin(), 1);
-  setError("Unrecognized escape code", T);
-  return "";
-}
-  case '\r':
-  case '\n':
-// Remove the new line.
-if (   UnquotedValue.size() > 1
-&& (UnquotedValue[1] == '\r' || UnquotedValue[1] == '\n'))
-  UnquotedValue = UnquotedValue.substr(1);
-// If this was just a single byte newline, it will get skipped
-// below.
-break;
-  case '0':
-Storage.push_back(0x00);
-break;
-  case 'a':
-Storage.push_back(0x07);
-break;
-  case 'b':
-Storage.push_back(0x08);
-break;
-  case 't':
-  case 0x09:
-Storage.push_back(0x09);
-break;
-  case 'n':
-Storage.push_back(0x0A);
-break;
-  case 'v':
-Storage.push_back(0x0B);
-break;
-  case 'f':
-Storage.push_back(0x0C);
-break;
-  case 'r':
-Storage.push_back(0x0D);
-break;
-  case 'e':
-Storage.push_back(0x1B);
-break;
+  char LastNewLineAddedAs = '\0';
+  for (; I != StringRef::npos; I = UnquotedValue.find_first_of(LookupChars)) {
+if (UnquotedValue[I] != '\x0D' && UnquotedValue[I] != '\x0A') {
+  llvm::append_range(Storage, UnquotedValue.take_front(I));
+  UnquotedValue = UnescapeCallback(UnquotedValue.drop_front(I), Storage);
+  LastNewLineAddedAs = '\0';
+  contin

[clang] [llvm] [clang-tools-extra] [lldb] [flang] [compiler-rt] [libcxx] [lld] [YAMLParser] Unfold multi-line scalar values (PR #70898)

2023-11-06 Thread Scott Linder via cfe-commits

https://github.com/slinder1 requested changes to this pull request.

I don't mean to make existing debt your problem, but if it isn't too much work 
could you post a pre-patch that just adds the `FileCheck`s to the existing 
tests where the behavior changes, so the test diff is more self-documenting?

I left some comments but not so much about spec compliance as I don't have the 
time right now to work through it right now.

Either way, thank you for the work, and I'm happy to see the parser move 
towards more compliant parsing!

https://github.com/llvm/llvm-project/pull/70898
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 97ba3c2 - [Clang][AMDGPU] Set LTO CG opt level based on Clang option

2023-02-15 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2023-02-15T17:34:35Z
New Revision: 97ba3c2bec48ca55cc842c6499b19b0b8a271951

URL: 
https://github.com/llvm/llvm-project/commit/97ba3c2bec48ca55cc842c6499b19b0b8a271951
DIFF: 
https://github.com/llvm/llvm-project/commit/97ba3c2bec48ca55cc842c6499b19b0b8a271951.diff

LOG: [Clang][AMDGPU] Set LTO CG opt level based on Clang option

For AMDGCN default to mapping --lto-O# to --lto-CGO# in a 1:1 manner
(i.e. clang -O implies --lto-O and --lto-CGO).

Ensure there is a means to override this via -Xoffload-linker and begin
to claim these arguments to avoid incorrect warnings that they are not
used.

Reviewed By: yaxunl, MaskRay

Differential Revision: https://reviews.llvm.org/D142499

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/HIPAMD.cpp
clang/test/Driver/hip-toolchain-opt.hip

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index e6360fd8edc13..c179c4152cee4 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -567,6 +567,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const 
ArgList &Args,
   ArgStringList &CmdArgs, const InputInfo &Output,
   const InputInfo &Input, bool IsThinLTO) {
   const bool IsOSAIX = ToolChain.getTriple().isOSAIX();
+  const bool IsAMDGCN = ToolChain.getTriple().isAMDGCN();
   const char *Linker = Args.MakeArgString(ToolChain.GetLinkerPath());
   const Driver &D = ToolChain.getDriver();
   if (llvm::sys::path::filename(Linker) != "ld.lld" &&
@@ -631,9 +632,12 @@ void tools::addLTOOptions(const ToolChain &ToolChain, 
const ArgList &Args,
 OOpt = "2";
 } else if (A->getOption().matches(options::OPT_O0))
   OOpt = "0";
-if (!OOpt.empty())
+if (!OOpt.empty()) {
   CmdArgs.push_back(
   Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash + "O" + OOpt));
+  if (IsAMDGCN)
+CmdArgs.push_back(Args.MakeArgString(Twine("--lto-CGO") + OOpt));
+}
   }
 
   if (Args.hasArg(options::OPT_gsplit_dwarf))

diff  --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index ff797e5959a49..3131c8ed24639 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -152,8 +152,10 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, 
const JobAction &JA,
 
   addLinkerCompressDebugSectionsOption(TC, Args, LldArgs);
 
-  for (auto *Arg : Args.filtered(options::OPT_Xoffload_linker))
+  for (auto *Arg : Args.filtered(options::OPT_Xoffload_linker)) {
 LldArgs.push_back(Arg->getValue(1));
+Arg->claim();
+  }
 
   LldArgs.append({"-o", Output.getFilename()});
   for (auto Input : Inputs)

diff  --git a/clang/test/Driver/hip-toolchain-opt.hip 
b/clang/test/Driver/hip-toolchain-opt.hip
index a82323d3da966..501f9654a2580 100644
--- a/clang/test/Driver/hip-toolchain-opt.hip
+++ b/clang/test/Driver/hip-toolchain-opt.hip
@@ -57,6 +57,14 @@
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck --check-prefixes=ALL,Og %s
 
+// RUN: %clang -### -O0 \
+// RUN:   -Xoffload-linker --lto-CGO2 \
+// RUN:   --target=x86_64-unknown-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx900 \
+// RUN:   -c -nogpulib \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck --check-prefixes=ALL,O0-CGO2 %s
+
 // ALL: "-cc1" "-triple" "amdgcn-amd-amdhsa"
 // DEFAULT-NOT: "-O{{.}}"
 // O0-SAME: "-O0"
@@ -66,6 +74,8 @@
 // Os-SAME: "-Os"
 // Oz-SAME: "-Oz"
 // Og-SAME: "-Og"
+// O0-CGO2-SAME: "-O0"
+// O0-CGO2-NOT: "--lto-CGO2"
 
 // ALL-NOT: "{{.*}}opt"
 
@@ -74,12 +84,22 @@
 // ALL: "{{.*}}lld{{.*}}" {{.*}} "-plugin-opt=mcpu=gfx900"
 // DEFAULT-NOT: "-plugin-opt=O{{.*}}"
 // O0-SAME: "-plugin-opt=O0"
+// O0-SAME: "--lto-CGO0"
 // O1-SAME: "-plugin-opt=O1"
+// O1-SAME: "--lto-CGO1"
 // O2-SAME: "-plugin-opt=O2"
+// O2-SAME: "--lto-CGO2"
 // O3-SAME: "-plugin-opt=O3"
+// O3-SAME: "--lto-CGO3"
 // Os-SAME: "-plugin-opt=O2"
+// Os-SAME: "--lto-CGO2"
 // Oz-SAME: "-plugin-opt=O2"
+// Oz-SAME: "--lto-CGO2"
 // Og-SAME: "-plugin-opt=O1"
+// Og-SAME: "--lto-CGO1"
+// O0-CGO2-SAME: "-plugin-opt=O0"
+// O0-CGO2-SAME: "--lto-CGO0"
+// O0-CGO2-SAME: "--lto-CGO2"
 
 // ALL: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
 // DEFAULT-NOT: "-O{{.}}"
@@ -90,3 +110,5 @@
 // Os-SAME: "-Os"
 // Oz-SAME: "-Oz"
 // Og-SAME: "-Og"
+// O0-CGO2-SAME: "-O0"
+// O0-CGO2-NOT: "--lto-CGO2"



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


[clang] 25c0ea2 - [NFC] Consolidate llvm::CodeGenOpt::Level handling

2023-01-23 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2023-01-23T22:50:49Z
New Revision: 25c0ea2a5370813f46686918a84e0de27e107d08

URL: 
https://github.com/llvm/llvm-project/commit/25c0ea2a5370813f46686918a84e0de27e107d08
DIFF: 
https://github.com/llvm/llvm-project/commit/25c0ea2a5370813f46686918a84e0de27e107d08.diff

LOG: [NFC] Consolidate llvm::CodeGenOpt::Level handling

Add free functions llvm::CodeGenOpt::{getLevel,getID,parseLevel} to
provide common implementations for functionality that has been
duplicated in many places across the codebase.

Differential Revision: https://reviews.llvm.org/D141968

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
flang/lib/Frontend/FrontendActions.cpp
llvm/include/llvm/Support/CodeGen.h
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/tools/gold/gold-plugin.cpp
llvm/tools/llc/llc.cpp
llvm/tools/lli/lli.cpp
llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
llvm/tools/llvm-lto2/llvm-lto2.cpp
llvm/tools/lto/lto.cpp
openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index ecc727d6dd281..10d6bff25e6d6 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -300,21 +300,6 @@ static TargetLibraryInfoImpl *createTLII(llvm::Triple 
&TargetTriple,
   return TLII;
 }
 
-static CodeGenOpt::Level getCGOptLevel(const CodeGenOptions &CodeGenOpts) {
-  switch (CodeGenOpts.OptimizationLevel) {
-  default:
-llvm_unreachable("Invalid optimization level!");
-  case 0:
-return CodeGenOpt::None;
-  case 1:
-return CodeGenOpt::Less;
-  case 2:
-return CodeGenOpt::Default; // O2/Os/Oz
-  case 3:
-return CodeGenOpt::Aggressive;
-  }
-}
-
 static std::optional
 getCodeModel(const CodeGenOptions &CodeGenOpts) {
   unsigned CodeModel = llvm::StringSwitch(CodeGenOpts.CodeModel)
@@ -579,7 +564,10 @@ void EmitAssemblyHelper::CreateTargetMachine(bool 
MustCreateTM) {
   std::string FeaturesStr =
   llvm::join(TargetOpts.Features.begin(), TargetOpts.Features.end(), ",");
   llvm::Reloc::Model RM = CodeGenOpts.RelocationModel;
-  CodeGenOpt::Level OptLevel = getCGOptLevel(CodeGenOpts);
+  std::optional OptLevelOrNone =
+  CodeGenOpt::getLevel(CodeGenOpts.OptimizationLevel);
+  assert(OptLevelOrNone && "Invalid optimization level!");
+  CodeGenOpt::Level OptLevel = *OptLevelOrNone;
 
   llvm::TargetOptions Options;
   if (!initTargetOptions(Diags, Options, CodeGenOpts, TargetOpts, LangOpts,
@@ -1161,7 +1149,10 @@ static void runThinLTOBackend(
   Conf.CodeModel = getCodeModel(CGOpts);
   Conf.MAttrs = TOpts.Features;
   Conf.RelocModel = CGOpts.RelocationModel;
-  Conf.CGOptLevel = getCGOptLevel(CGOpts);
+  std::optional OptLevelOrNone =
+  CodeGenOpt::getLevel(CGOpts.OptimizationLevel);
+  assert(OptLevelOrNone && "Invalid optimization level!");
+  Conf.CGOptLevel = *OptLevelOrNone;
   Conf.OptLevel = CGOpts.OptimizationLevel;
   initTargetOptions(Diags, Conf.Options, CGOpts, TOpts, LOpts, HeaderOpts);
   Conf.SampleProfile = std::move(SampleProfile);

diff  --git a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp 
b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
index 5c9066c148d61..06df39dcdc479 100644
--- a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
+++ b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
@@ -54,14 +54,11 @@ getOptLevel(const std::vector &ExtraArgs) {
   CodeGenOpt::Level OLvl = CodeGenOpt::Default;
   for (auto &A : ExtraArgs) {
 if (A[0] == '-' && A[1] == 'O') {
-  switch(A[2]) {
-case '0': OLvl = CodeGenOpt::None; break;
-case '1': OLvl = CodeGenOpt::Less; break;
-case '2': OLvl = CodeGenOpt::Default; break;
-case '3': OLvl = CodeGenOpt::Aggressive; break;
-default:
-  errs() << "error: opt level must be between 0 and 3.\n";
-  std::exit(1);
+  if (auto Level = CodeGenOpt::parseLevel(A[2])) {
+OLvl = *Level;
+  } else {
+errs() << "error: opt level must be between 0 and 3.\n";
+std::exit(1);
   }
 }
   }

diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 5cae73ef543eb..57603ccef01f9 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -491,20 +491,6 @@ std::vector 
getTargetFeatures(ArrayRef InputFiles) {
   return UnifiedFeatures;
 }
 
-CodeGenOpt::Level getCGOptLevel(unsigned OptLevel) {
-  switch (OptLevel) {
-  case 0:
-return CodeGenOpt::None;
-  case 1:
-return CodeGenOpt::Less;
-  case 2:
-return CodeGenOpt::Default;
-  case 3:
-return CodeGenOpt::Aggressive;
-  }
-  llvm_unr

[clang] 09f33a4 - [AMDGPU][OpenCL] Remove "printf and hostcall" diagnostic

2022-04-05 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2022-04-05T19:10:23Z
New Revision: 09f33a430b72fffe06fde9e07c0acd5c4cd2e59e

URL: 
https://github.com/llvm/llvm-project/commit/09f33a430b72fffe06fde9e07c0acd5c4cd2e59e
DIFF: 
https://github.com/llvm/llvm-project/commit/09f33a430b72fffe06fde9e07c0acd5c4cd2e59e.diff

LOG: [AMDGPU][OpenCL] Remove "printf and hostcall" diagnostic

The diagnostic is unreliable, and triggers even for dead uses of
hostcall that may exist when linking the device-libs at lower
optimization levels.

Eliminate the diagnostic, and directly document the limitation for
OpenCL before code object V5.

Make some NFC changes to clarify the related code in the
MetadataStreamer.

Add a clang test to tie OCL sources containing printf to the backend IR
tests for this situation.

Reviewed By: sameerds, arsenm, yaxunl

Differential Revision: https://reviews.llvm.org/D121951

Added: 
clang/test/CodeGenOpenCL/amdgpu-printf.cl
llvm/test/CodeGen/AMDGPU/opencl-printf-and-hostcall.ll

Modified: 
llvm/docs/AMDGPUUsage.rst
llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp

Removed: 
llvm/test/CodeGen/AMDGPU/opencl-printf-no-hostcall.ll



diff  --git a/clang/test/CodeGenOpenCL/amdgpu-printf.cl 
b/clang/test/CodeGenOpenCL/amdgpu-printf.cl
new file mode 100644
index 0..0659fdfc54fe1
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/amdgpu-printf.cl
@@ -0,0 +1,46 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -cl-std=CL1.2 -triple amdgcn-amd-amdhsa 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s
+
+int printf(__constant const char* st, ...) __attribute__((format(printf, 1, 
2)));
+
+// CHECK-LABEL: @test_printf_noargs(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = call i32 (i8 addrspace(4)*, ...) @printf(i8 
addrspace(4)* noundef getelementptr inbounds ([1 x i8], [1 x i8] addrspace(4)* 
@.str, i64 0, i64 0)) #[[ATTR4:[0-9]+]]
+// CHECK-NEXT:ret void
+//
+__kernel void test_printf_noargs() {
+printf("");
+}
+
+// CHECK-LABEL: @test_printf_int(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[I_ADDR:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:store i32 [[I:%.*]], i32 addrspace(5)* [[I_ADDR]], align 4, 
!tbaa [[TBAA8:![0-9]+]]
+// CHECK-NEXT:[[TMP0:%.*]] = load i32, i32 addrspace(5)* [[I_ADDR]], align 
4, !tbaa [[TBAA8]]
+// CHECK-NEXT:[[CALL:%.*]] = call i32 (i8 addrspace(4)*, ...) @printf(i8 
addrspace(4)* noundef getelementptr inbounds ([3 x i8], [3 x i8] addrspace(4)* 
@.str.1, i64 0, i64 0), i32 noundef [[TMP0]]) #[[ATTR4]]
+// CHECK-NEXT:ret void
+//
+__kernel void test_printf_int(int i) {
+printf("%d", i);
+}
+
+// CHECK-LABEL: @test_printf_str_int(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[I_ADDR:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[S:%.*]] = alloca [4 x i8], align 1, addrspace(5)
+// CHECK-NEXT:store i32 [[I:%.*]], i32 addrspace(5)* [[I_ADDR]], align 4, 
!tbaa [[TBAA8]]
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast [4 x i8] addrspace(5)* [[S]] to i8 
addrspace(5)*
+// CHECK-NEXT:call void @llvm.lifetime.start.p5i8(i64 4, i8 addrspace(5)* 
[[TMP0]]) #[[ATTR5:[0-9]+]]
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast [4 x i8] addrspace(5)* [[S]] to i8 
addrspace(5)*
+// CHECK-NEXT:call void @llvm.memcpy.p5i8.p4i8.i64(i8 addrspace(5)* align 
1 [[TMP1]], i8 addrspace(4)* align 1 getelementptr inbounds ([4 x i8], [4 x i8] 
addrspace(4)* @__const.test_printf_str_int.s, i32 0, i32 0), i64 4, i1 false)
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [4 x i8], [4 x 
i8] addrspace(5)* [[S]], i64 0, i64 0
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, i32 addrspace(5)* [[I_ADDR]], align 
4, !tbaa [[TBAA8]]
+// CHECK-NEXT:[[CALL:%.*]] = call i32 (i8 addrspace(4)*, ...) @printf(i8 
addrspace(4)* noundef getelementptr inbounds ([6 x i8], [6 x i8] addrspace(4)* 
@.str.2, i64 0, i64 0), i8 addrspace(5)* noundef [[ARRAYDECAY]], i32 noundef 
[[TMP2]]) #[[ATTR4]]
+// CHECK-NEXT:[[TMP3:%.*]] = bitcast [4 x i8] addrspace(5)* [[S]] to i8 
addrspace(5)*
+// CHECK-NEXT:call void @llvm.lifetime.end.p5i8(i64 4, i8 addrspace(5)* 
[[TMP3]]) #[[ATTR5]]
+// CHECK-NEXT:ret void
+//
+__kernel void test_printf_str_int(int i) {
+char s[] = "foo";
+printf("%s:%d", s, i);
+}

diff  --git a/llvm/docs/AMDGPUUsage.rst b/llvm/docs/AMDGPUUsage.rst
index a590d468afd97..63ca37811d89f 100644
--- a/llvm/docs/AMDGPUUsage.rst
+++ b/llvm/docs/AMDGPUUsage.rst
@@ -2823,12 +2823,16 @@ non-AMD key names should be prefixed by 
"*vendor-name*.".
 "HiddenPrintfBuffer"
   A global address space 
pointer
   to the runtime printf buffer
-  is passed in k

[clang] 635c5ba - [AMDGPU][HIP] Switch default DWARF version to 5

2021-08-02 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2021-08-02T18:04:01Z
New Revision: 635c5ba45baee5c6a8841fbac06f6868ddae5a6d

URL: 
https://github.com/llvm/llvm-project/commit/635c5ba45baee5c6a8841fbac06f6868ddae5a6d
DIFF: 
https://github.com/llvm/llvm-project/commit/635c5ba45baee5c6a8841fbac06f6868ddae5a6d.diff

LOG: [AMDGPU][HIP] Switch default DWARF version to 5

Another attempt at changing this default, now that tooling has greater
support for DWARF 5.

Differential Revision: https://reviews.llvm.org/D107190

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPU.h
clang/lib/Driver/ToolChains/HIP.h
clang/test/Driver/amdgpu-toolchain.c
clang/test/Driver/hip-toolchain-dwarf.hip

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.h 
b/clang/lib/Driver/ToolChains/AMDGPU.h
index a4bcf315ca76..b93d554683ff 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -60,7 +60,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public 
Generic_ELF {
 public:
   AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args);
-  unsigned GetDefaultDwarfVersion() const override { return 4; }
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
   bool IsMathErrnoDefault() const override { return false; }
 

diff  --git a/clang/lib/Driver/ToolChains/HIP.h 
b/clang/lib/Driver/ToolChains/HIP.h
index 3cced0a320dc..00df4a5addb0 100644
--- a/clang/lib/Driver/ToolChains/HIP.h
+++ b/clang/lib/Driver/ToolChains/HIP.h
@@ -92,7 +92,7 @@ class LLVM_LIBRARY_VISIBILITY HIPToolChain final : public 
ROCMToolChain {
   computeMSVCVersion(const Driver *D,
  const llvm::opt::ArgList &Args) const override;
 
-  unsigned GetDefaultDwarfVersion() const override { return 4; }
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
 
   const ToolChain &HostTC;
   void checkTargetID(const llvm::opt::ArgList &DriverArgs) const override;

diff  --git a/clang/test/Driver/amdgpu-toolchain.c 
b/clang/test/Driver/amdgpu-toolchain.c
index ac558e0e26eb..cb92744eee6a 100644
--- a/clang/test/Driver/amdgpu-toolchain.c
+++ b/clang/test/Driver/amdgpu-toolchain.c
@@ -8,7 +8,7 @@
 // AS_LINK: clang{{.*}} "-cc1as"
 // AS_LINK: ld.lld{{.*}} "-shared"
 
-// DWARF_VER: "-dwarf-version=4"
+// DWARF_VER: "-dwarf-version=5"
 
 // RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
 // RUN:   -flto %s 2>&1 | FileCheck -check-prefix=LTO %s

diff  --git a/clang/test/Driver/hip-toolchain-dwarf.hip 
b/clang/test/Driver/hip-toolchain-dwarf.hip
index 44d66fe52e04..c853d5cf07cf 100644
--- a/clang/test/Driver/hip-toolchain-dwarf.hip
+++ b/clang/test/Driver/hip-toolchain-dwarf.hip
@@ -6,4 +6,4 @@
 // RUN:   -x hip --cuda-gpu-arch=gfx803 %s \
 // RUN:   -Xarch_gfx803 -g 2>&1 | FileCheck %s -check-prefix=DWARF_VER
 
-// DWARF_VER: "-dwarf-version=4"
+// DWARF_VER: "-dwarf-version=5"



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


[clang] af5247c - [ADT] Factor out in_place_t and expose in Optional ctor

2021-05-17 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2021-05-17T22:25:39Z
New Revision: af5247c9347dcf1e30443786bdddf23ca705867a

URL: 
https://github.com/llvm/llvm-project/commit/af5247c9347dcf1e30443786bdddf23ca705867a
DIFF: 
https://github.com/llvm/llvm-project/commit/af5247c9347dcf1e30443786bdddf23ca705867a.diff

LOG: [ADT] Factor out in_place_t and expose in Optional ctor

Differential Revision: https://reviews.llvm.org/D100671

Added: 


Modified: 
clang/include/clang/Basic/DirectoryEntry.h
llvm/include/llvm/ADT/Optional.h
llvm/include/llvm/ADT/STLForwardCompat.h
llvm/unittests/ADT/OptionalTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DirectoryEntry.h 
b/clang/include/clang/Basic/DirectoryEntry.h
index e0f4ae28321a3..edb8031a20b80 100644
--- a/clang/include/clang/Basic/DirectoryEntry.h
+++ b/clang/include/clang/Basic/DirectoryEntry.h
@@ -120,8 +120,7 @@ template  class MapEntryOptionalStorage {
   MapEntryOptionalStorage() : MaybeRef(optional_none_tag()) {}
 
   template 
-  explicit MapEntryOptionalStorage(llvm::optional_detail::in_place_t,
-   ArgTypes &&...Args)
+  explicit MapEntryOptionalStorage(llvm::in_place_t, ArgTypes &&...Args)
   : MaybeRef(std::forward(Args)...) {}
 
   void reset() { MaybeRef = optional_none_tag(); }

diff  --git a/llvm/include/llvm/ADT/Optional.h 
b/llvm/include/llvm/ADT/Optional.h
index 67bd1f5f1a542..cdbf2e3532419 100644
--- a/llvm/include/llvm/ADT/Optional.h
+++ b/llvm/include/llvm/ADT/Optional.h
@@ -17,6 +17,7 @@
 
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/None.h"
+#include "llvm/ADT/STLForwardCompat.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/type_traits.h"
 #include 
@@ -30,8 +31,6 @@ class raw_ostream;
 
 namespace optional_detail {
 
-struct in_place_t {};
-
 /// Storage for any type.
 //
 // The specialization condition intentionally uses
@@ -245,13 +244,16 @@ template  class Optional {
   constexpr Optional() {}
   constexpr Optional(NoneType) {}
 
-  constexpr Optional(const T &y) : Storage(optional_detail::in_place_t{}, y) {}
+  constexpr Optional(const T &y) : Storage(in_place, y) {}
   constexpr Optional(const Optional &O) = default;
 
-  constexpr Optional(T &&y)
-  : Storage(optional_detail::in_place_t{}, std::move(y)) {}
+  constexpr Optional(T &&y) : Storage(in_place, std::move(y)) {}
   constexpr Optional(Optional &&O) = default;
 
+  template 
+  constexpr Optional(in_place_t, ArgTypes &&...Args)
+  : Storage(in_place, std::forward(Args)...) {}
+
   Optional &operator=(T &&y) {
 Storage = std::move(y);
 return *this;

diff  --git a/llvm/include/llvm/ADT/STLForwardCompat.h 
b/llvm/include/llvm/ADT/STLForwardCompat.h
index 83ce6d3f68694..440b29df260ca 100644
--- a/llvm/include/llvm/ADT/STLForwardCompat.h
+++ b/llvm/include/llvm/ADT/STLForwardCompat.h
@@ -44,6 +44,25 @@ template 
 struct disjunction
 : std::conditional>::type {};
 
+struct in_place_t // NOLINT(readability-identifier-naming)
+{
+  explicit in_place_t() = default;
+};
+/// \warning This must not be odr-used, as it cannot be made \c inline in 
C++14.
+constexpr in_place_t in_place; // NOLINT(readability-identifier-naming)
+
+template 
+struct in_place_type_t // NOLINT(readability-identifier-naming)
+{
+  explicit in_place_type_t() = default;
+};
+
+template 
+struct in_place_index_t // NOLINT(readability-identifier-naming)
+{
+  explicit in_place_index_t() = default;
+};
+
 
//===--===//
 // Features from C++20
 
//===--===//

diff  --git a/llvm/unittests/ADT/OptionalTest.cpp 
b/llvm/unittests/ADT/OptionalTest.cpp
index 2c5d65f80d977..debeb78e8fab7 100644
--- a/llvm/unittests/ADT/OptionalTest.cpp
+++ b/llvm/unittests/ADT/OptionalTest.cpp
@@ -195,6 +195,14 @@ TEST(OptionalTest, NullCopyConstructionTest) {
   EXPECT_EQ(0u, NonDefaultConstructible::Destructions);
 }
 
+TEST(OptionalTest, InPlaceConstructionNonDefaultConstructibleTest) {
+  NonDefaultConstructible::ResetCounts();
+  { Optional A{in_place, 1}; }
+  EXPECT_EQ(0u, NonDefaultConstructible::CopyConstructions);
+  EXPECT_EQ(0u, NonDefaultConstructible::CopyAssignments);
+  EXPECT_EQ(1u, NonDefaultConstructible::Destructions);
+}
+
 TEST(OptionalTest, GetValueOr) {
   Optional A;
   EXPECT_EQ(42, A.getValueOr(42));
@@ -214,6 +222,11 @@ struct MultiArgConstructor {
   MultiArgConstructor &operator=(const MultiArgConstructor &) = delete;
   MultiArgConstructor &operator=(MultiArgConstructor &&) = delete;
 
+  friend bool operator==(const MultiArgConstructor &LHS,
+ const MultiArgConstructor &RHS) {
+return LHS.x == RHS.x && LHS.y == RHS.y;
+  }
+
   static unsigned Destructions;
   ~MultiArgConstructor() {
 ++Destructions;
@@ -244,6 +257,34 @@ TEST(OptionalTest, Emplace) {
   EXPECT_EQ(1u,

[clang] cab19d8 - [NFC] Refactor ExecuteAssembler in cc1as_main.cpp

2021-04-30 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2021-04-30T17:11:50Z
New Revision: cab19d84ce85cbceec7fde515cc686d6a83a5f9d

URL: 
https://github.com/llvm/llvm-project/commit/cab19d84ce85cbceec7fde515cc686d6a83a5f9d
DIFF: 
https://github.com/llvm/llvm-project/commit/cab19d84ce85cbceec7fde515cc686d6a83a5f9d.diff

LOG: [NFC] Refactor ExecuteAssembler in cc1as_main.cpp

Introduce an extra scope (another static function) to replace calls to
`unique_ptr::reset` with implicit destructors via RAII.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D101542

Added: 


Modified: 
clang/tools/driver/cc1as_main.cpp

Removed: 




diff  --git a/clang/tools/driver/cc1as_main.cpp 
b/clang/tools/driver/cc1as_main.cpp
index 083fc0846ac18..d4fa60c963d78 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -333,8 +333,8 @@ getOutputStream(StringRef Path, DiagnosticsEngine &Diags, 
bool Binary) {
   return Out;
 }
 
-static bool ExecuteAssembler(AssemblerInvocation &Opts,
- DiagnosticsEngine &Diags) {
+static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
+ DiagnosticsEngine &Diags) {
   // Get the target specific parser.
   std::string Error;
   const Target *TheTarget = TargetRegistry::lookupTarget(Opts.Triple, Error);
@@ -531,12 +531,12 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
 Failed = Parser->Run(Opts.NoInitialTextSection);
   }
 
-  // Parser has a reference to the output stream (Str), so close Parser first.
-  Parser.reset();
-  Str.reset();
-  // Close the output stream early.
-  BOS.reset();
-  FDOS.reset();
+  return Failed;
+}
+
+static bool ExecuteAssembler(AssemblerInvocation &Opts,
+ DiagnosticsEngine &Diags) {
+  bool Failed = ExecuteAssemblerImpl(Opts, Diags);
 
   // Delete output file if there were errors.
   if (Failed) {



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


[clang] c15b0e2 - [Clang][Docs] Fix ambiguity in clang-offload-bundler docs

2021-01-11 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2021-01-11T17:23:24Z
New Revision: c15b0e2229ea04d1c36fafaa1f717f433a995e9a

URL: 
https://github.com/llvm/llvm-project/commit/c15b0e2229ea04d1c36fafaa1f717f433a995e9a
DIFF: 
https://github.com/llvm/llvm-project/commit/c15b0e2229ea04d1c36fafaa1f717f433a995e9a.diff

LOG: [Clang][Docs] Fix ambiguity in clang-offload-bundler docs

Differential Revision: https://reviews.llvm.org/D94338

Added: 


Modified: 
clang/docs/ClangOffloadBundler.rst

Removed: 




diff  --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index 050925be993b..68c5116b235f 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -44,7 +44,7 @@ The layout of a bundled code object is defined by the 
following table:
 Field   TypeSize in BytesDescription
 === ===  
===
 Magic Stringstring  24   
``__CLANG_OFFLOAD_BUNDLE__``
-Number Of Code Objects  integer 8Number od 
bundled code objects.
+Number Of Bundle Entriesinteger 8Number of 
bundle entries.
 1st Bundle Entry Code Object Offset integer 8Byte offset 
from beginning of
  bundled code 
object to 1st code
  object.
@@ -208,4 +208,4 @@ Target specific information is available for the following:
   features `_
   supported.
 
-Most other targets do not support target IDs.
\ No newline at end of file
+Most other targets do not support target IDs.



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


[clang] ffba47d - Revert "[AMDGPU][HIP] Switch default DWARF version to 5"

2020-12-21 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2020-12-21T21:43:51Z
New Revision: ffba47df76460905965df4b54cf6ba945d2eb1ce

URL: 
https://github.com/llvm/llvm-project/commit/ffba47df76460905965df4b54cf6ba945d2eb1ce
DIFF: 
https://github.com/llvm/llvm-project/commit/ffba47df76460905965df4b54cf6ba945d2eb1ce.diff

LOG: Revert "[AMDGPU][HIP] Switch default DWARF version to 5"

This reverts commit c4d10e7e9bb47b77fad43d8ddcfa328298f36c88.

Differential Revision: https://reviews.llvm.org/D93648

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPU.h
clang/lib/Driver/ToolChains/HIP.h
clang/test/Driver/amdgpu-toolchain.c
clang/test/Driver/hip-toolchain-dwarf.hip

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.h 
b/clang/lib/Driver/ToolChains/AMDGPU.h
index f5448b76aee5..55ef6e01967e 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -60,7 +60,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public 
Generic_ELF {
 public:
   AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args);
-  unsigned GetDefaultDwarfVersion() const override { return 5; }
+  unsigned GetDefaultDwarfVersion() const override { return 4; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
   bool IsMathErrnoDefault() const override { return false; }
 

diff  --git a/clang/lib/Driver/ToolChains/HIP.h 
b/clang/lib/Driver/ToolChains/HIP.h
index ff58c5451b0b..5e2be7138579 100644
--- a/clang/lib/Driver/ToolChains/HIP.h
+++ b/clang/lib/Driver/ToolChains/HIP.h
@@ -99,7 +99,7 @@ class LLVM_LIBRARY_VISIBILITY HIPToolChain final : public 
ROCMToolChain {
   computeMSVCVersion(const Driver *D,
  const llvm::opt::ArgList &Args) const override;
 
-  unsigned GetDefaultDwarfVersion() const override { return 5; }
+  unsigned GetDefaultDwarfVersion() const override { return 4; }
 
   const ToolChain &HostTC;
 

diff  --git a/clang/test/Driver/amdgpu-toolchain.c 
b/clang/test/Driver/amdgpu-toolchain.c
index cb92744eee6a..ac558e0e26eb 100644
--- a/clang/test/Driver/amdgpu-toolchain.c
+++ b/clang/test/Driver/amdgpu-toolchain.c
@@ -8,7 +8,7 @@
 // AS_LINK: clang{{.*}} "-cc1as"
 // AS_LINK: ld.lld{{.*}} "-shared"
 
-// DWARF_VER: "-dwarf-version=5"
+// DWARF_VER: "-dwarf-version=4"
 
 // RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
 // RUN:   -flto %s 2>&1 | FileCheck -check-prefix=LTO %s

diff  --git a/clang/test/Driver/hip-toolchain-dwarf.hip 
b/clang/test/Driver/hip-toolchain-dwarf.hip
index c853d5cf07cf..44d66fe52e04 100644
--- a/clang/test/Driver/hip-toolchain-dwarf.hip
+++ b/clang/test/Driver/hip-toolchain-dwarf.hip
@@ -6,4 +6,4 @@
 // RUN:   -x hip --cuda-gpu-arch=gfx803 %s \
 // RUN:   -Xarch_gfx803 -g 2>&1 | FileCheck %s -check-prefix=DWARF_VER
 
-// DWARF_VER: "-dwarf-version=5"
+// DWARF_VER: "-dwarf-version=4"



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


[clang] c4d10e7 - [AMDGPU][HIP] Switch default DWARF version to 5

2020-10-16 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2020-10-16T17:53:27Z
New Revision: c4d10e7e9bb47b77fad43d8ddcfa328298f36c88

URL: 
https://github.com/llvm/llvm-project/commit/c4d10e7e9bb47b77fad43d8ddcfa328298f36c88
DIFF: 
https://github.com/llvm/llvm-project/commit/c4d10e7e9bb47b77fad43d8ddcfa328298f36c88.diff

LOG: [AMDGPU][HIP] Switch default DWARF version to 5

Another attempt at this, see D59008 for previous attempt.

Reviewed By: kzhuravl, t-tye

Differential Revision: https://reviews.llvm.org/D89484

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPU.h
clang/lib/Driver/ToolChains/HIP.h
clang/test/Driver/amdgpu-toolchain.c
clang/test/Driver/hip-toolchain-dwarf.hip

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.h 
b/clang/lib/Driver/ToolChains/AMDGPU.h
index 55ef6e01967e..f5448b76aee5 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -60,7 +60,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public 
Generic_ELF {
 public:
   AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args);
-  unsigned GetDefaultDwarfVersion() const override { return 4; }
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
   bool IsMathErrnoDefault() const override { return false; }
 

diff  --git a/clang/lib/Driver/ToolChains/HIP.h 
b/clang/lib/Driver/ToolChains/HIP.h
index 5e2be7138579..ff58c5451b0b 100644
--- a/clang/lib/Driver/ToolChains/HIP.h
+++ b/clang/lib/Driver/ToolChains/HIP.h
@@ -99,7 +99,7 @@ class LLVM_LIBRARY_VISIBILITY HIPToolChain final : public 
ROCMToolChain {
   computeMSVCVersion(const Driver *D,
  const llvm::opt::ArgList &Args) const override;
 
-  unsigned GetDefaultDwarfVersion() const override { return 4; }
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
 
   const ToolChain &HostTC;
 

diff  --git a/clang/test/Driver/amdgpu-toolchain.c 
b/clang/test/Driver/amdgpu-toolchain.c
index ac558e0e26eb..cb92744eee6a 100644
--- a/clang/test/Driver/amdgpu-toolchain.c
+++ b/clang/test/Driver/amdgpu-toolchain.c
@@ -8,7 +8,7 @@
 // AS_LINK: clang{{.*}} "-cc1as"
 // AS_LINK: ld.lld{{.*}} "-shared"
 
-// DWARF_VER: "-dwarf-version=4"
+// DWARF_VER: "-dwarf-version=5"
 
 // RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
 // RUN:   -flto %s 2>&1 | FileCheck -check-prefix=LTO %s

diff  --git a/clang/test/Driver/hip-toolchain-dwarf.hip 
b/clang/test/Driver/hip-toolchain-dwarf.hip
index 44d66fe52e04..c853d5cf07cf 100644
--- a/clang/test/Driver/hip-toolchain-dwarf.hip
+++ b/clang/test/Driver/hip-toolchain-dwarf.hip
@@ -6,4 +6,4 @@
 // RUN:   -x hip --cuda-gpu-arch=gfx803 %s \
 // RUN:   -Xarch_gfx803 -g 2>&1 | FileCheck %s -check-prefix=DWARF_VER
 
-// DWARF_VER: "-dwarf-version=4"
+// DWARF_VER: "-dwarf-version=5"



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


[clang] 40cef5a - [clang] Add a test for CGDebugInfo treatment of blocks

2020-10-09 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2020-10-09T19:03:21Z
New Revision: 40cef5a00eb83f44e946912b74be83e8dc02effb

URL: 
https://github.com/llvm/llvm-project/commit/40cef5a00eb83f44e946912b74be83e8dc02effb
DIFF: 
https://github.com/llvm/llvm-project/commit/40cef5a00eb83f44e946912b74be83e8dc02effb.diff

LOG: [clang] Add a test for CGDebugInfo treatment of blocks

There doesn't seem to be a direct test of this, and I'm planning to make
future changes which will affect it.

I'm not particularly familiar with the blocks extension, so suggestions
for better tests are welcome.

Differential Revision: https://reviews.llvm.org/D88754

Added: 
clang/test/CodeGen/debug-info-block-expr.c

Modified: 


Removed: 




diff  --git a/clang/test/CodeGen/debug-info-block-expr.c 
b/clang/test/CodeGen/debug-info-block-expr.c
new file mode 100644
index ..009e7800b6ee
--- /dev/null
+++ b/clang/test/CodeGen/debug-info-block-expr.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fblocks -debug-info-kind=limited -emit-llvm -o - %s | 
FileCheck %s
+// Verify that the desired DIExpression are generated for blocks.
+
+void test() {
+// CHECK: call void @llvm.dbg.declare({{.*}}!DIExpression(DW_OP_plus_uconst, 
{{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
+  __block int i;
+// CHECK: call void @llvm.dbg.declare({{.*}}!DIExpression(DW_OP_deref, 
DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}, 
DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
+  ^ { i = 1; }();
+}



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


[clang] 340feac - [Driver] Escape the program path for -frecord-command-line

2020-02-21 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2020-02-21T19:16:59-05:00
New Revision: 340feac6721e840f88c1e77dd79931eea5eaccf3

URL: 
https://github.com/llvm/llvm-project/commit/340feac6721e840f88c1e77dd79931eea5eaccf3
DIFF: 
https://github.com/llvm/llvm-project/commit/340feac6721e840f88c1e77dd79931eea5eaccf3.diff

LOG: [Driver] Escape the program path for -frecord-command-line

Similar to the rest of the command line that is recorded, the program
path must also have spaces and backslashes escaped. Without this
parsing the recorded command line becomes hard on platforms like
Windows where spaces and backslashes are common.

This was originally reverted in
577d9ce35532439203411c999deefc9c80e04c69; this version makes a test
agnostic to the presence of backslashes in paths on some platforms.

Patch By: Ravi Ramaseshan
Differential Revision: https://reviews.llvm.org/D74811

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/clang_f_opts.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1091db691858..fc2bb9c60d68 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5882,7 +5882,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Arg->render(Args, OriginalArgs);
 
 SmallString<256> Flags;
-Flags += Exec;
+EscapeSpacesAndBackslashes(Exec, Flags);
 for (const char *OriginalArg : OriginalArgs) {
   SmallString<128> EscapedArg;
   EscapeSpacesAndBackslashes(OriginalArg, EscapedArg);
@@ -6790,7 +6790,7 @@ void ClangAs::ConstructJob(Compilation &C, const 
JobAction &JA,
 
 SmallString<256> Flags;
 const char *Exec = getToolChain().getDriver().getClangProgramPath();
-Flags += Exec;
+EscapeSpacesAndBackslashes(Exec, Flags);
 for (const char *OriginalArg : OriginalArgs) {
   SmallString<128> EscapedArg;
   EscapeSpacesAndBackslashes(OriginalArg, EscapedArg);

diff  --git a/clang/test/Driver/clang_f_opts.c 
b/clang/test/Driver/clang_f_opts.c
index 6fb820a9938d..f628f5f40de3 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -572,6 +572,11 @@
 // 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
+// Test when clang is in a path containing a space.
+// RUN: mkdir -p "%t.r/with spaces"
+// RUN: cp %clang "%t.r/with spaces/clang"
+// RUN: "%t.r/with spaces/clang" -### -S -target x86_64-unknown-linux 
-frecord-gcc-switches %s 2>&1 | FileCheck 
-check-prefix=CHECK-RECORD-GCC-SWITCHES-ESCAPED %s
+// CHECK-RECORD-GCC-SWITCHES-ESCAPED: "-record-command-line" "{{.+}}with\\ 
spaces{{.+}}"
 
 // RUN: %clang -### -S -ftrivial-auto-var-init=uninitialized %s 2>&1 | 
FileCheck -check-prefix=CHECK-TRIVIAL-UNINIT %s
 // RUN: %clang -### -S -ftrivial-auto-var-init=pattern %s 2>&1 | FileCheck 
-check-prefix=CHECK-TRIVIAL-PATTERN %s



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


[clang] 577d9ce - Revert "[Driver] Escape the program path for -frecord-command-line"

2020-02-20 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2020-02-20T17:36:56-05:00
New Revision: 577d9ce35532439203411c999deefc9c80e04c69

URL: 
https://github.com/llvm/llvm-project/commit/577d9ce35532439203411c999deefc9c80e04c69
DIFF: 
https://github.com/llvm/llvm-project/commit/577d9ce35532439203411c999deefc9c80e04c69.diff

LOG: Revert "[Driver] Escape the program path for -frecord-command-line"

This reverts commit 6123074d0c0de3614f1552f2f2d6b9db7b32cebe.

Quoting/escaping rules seem host specific, so the test is failing on
some bots.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/clang_f_opts.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index fc2bb9c60d68..1091db691858 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5882,7 +5882,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Arg->render(Args, OriginalArgs);
 
 SmallString<256> Flags;
-EscapeSpacesAndBackslashes(Exec, Flags);
+Flags += Exec;
 for (const char *OriginalArg : OriginalArgs) {
   SmallString<128> EscapedArg;
   EscapeSpacesAndBackslashes(OriginalArg, EscapedArg);
@@ -6790,7 +6790,7 @@ void ClangAs::ConstructJob(Compilation &C, const 
JobAction &JA,
 
 SmallString<256> Flags;
 const char *Exec = getToolChain().getDriver().getClangProgramPath();
-EscapeSpacesAndBackslashes(Exec, Flags);
+Flags += Exec;
 for (const char *OriginalArg : OriginalArgs) {
   SmallString<128> EscapedArg;
   EscapeSpacesAndBackslashes(OriginalArg, EscapedArg);

diff  --git a/clang/test/Driver/clang_f_opts.c 
b/clang/test/Driver/clang_f_opts.c
index ce58467d2156..6fb820a9938d 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -572,11 +572,6 @@
 // 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
-// Test when clang is in a path containing a space.
-// RUN: mkdir -p "%t.r/with spaces"
-// RUN: cp %clang "%t.r/with spaces/clang"
-// RUN: "%t.r/with spaces/clang" -### -S -target x86_64-unknown-linux 
-frecord-gcc-switches %s 2>&1 | FileCheck 
-check-prefix=CHECK-RECORD-GCC-SWITCHES-ESCAPED %s
-// CHECK-RECORD-GCC-SWITCHES-ESCAPED: "-record-command-line" "{{.+}}/with\\ 
spaces/clang {{.+}}"
 
 // RUN: %clang -### -S -ftrivial-auto-var-init=uninitialized %s 2>&1 | 
FileCheck -check-prefix=CHECK-TRIVIAL-UNINIT %s
 // RUN: %clang -### -S -ftrivial-auto-var-init=pattern %s 2>&1 | FileCheck 
-check-prefix=CHECK-TRIVIAL-PATTERN %s



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


[clang] 6123074 - [Driver] Escape the program path for -frecord-command-line

2020-02-20 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2020-02-20T16:31:17-05:00
New Revision: 6123074d0c0de3614f1552f2f2d6b9db7b32cebe

URL: 
https://github.com/llvm/llvm-project/commit/6123074d0c0de3614f1552f2f2d6b9db7b32cebe
DIFF: 
https://github.com/llvm/llvm-project/commit/6123074d0c0de3614f1552f2f2d6b9db7b32cebe.diff

LOG: [Driver] Escape the program path for -frecord-command-line

Similar to the rest of the command line that is recorded, the program
path must also have spaces and backslashes escaped. Without this
parsing the recorded command line becomes hard on platforms like
Windows where spaces and backslashes are common.

Patch By: Ravi Ramaseshan
Differential Revision: https://reviews.llvm.org/D74811

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/clang_f_opts.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1091db691858..fc2bb9c60d68 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5882,7 +5882,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Arg->render(Args, OriginalArgs);
 
 SmallString<256> Flags;
-Flags += Exec;
+EscapeSpacesAndBackslashes(Exec, Flags);
 for (const char *OriginalArg : OriginalArgs) {
   SmallString<128> EscapedArg;
   EscapeSpacesAndBackslashes(OriginalArg, EscapedArg);
@@ -6790,7 +6790,7 @@ void ClangAs::ConstructJob(Compilation &C, const 
JobAction &JA,
 
 SmallString<256> Flags;
 const char *Exec = getToolChain().getDriver().getClangProgramPath();
-Flags += Exec;
+EscapeSpacesAndBackslashes(Exec, Flags);
 for (const char *OriginalArg : OriginalArgs) {
   SmallString<128> EscapedArg;
   EscapeSpacesAndBackslashes(OriginalArg, EscapedArg);

diff  --git a/clang/test/Driver/clang_f_opts.c 
b/clang/test/Driver/clang_f_opts.c
index 6fb820a9938d..ce58467d2156 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -572,6 +572,11 @@
 // 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
+// Test when clang is in a path containing a space.
+// RUN: mkdir -p "%t.r/with spaces"
+// RUN: cp %clang "%t.r/with spaces/clang"
+// RUN: "%t.r/with spaces/clang" -### -S -target x86_64-unknown-linux 
-frecord-gcc-switches %s 2>&1 | FileCheck 
-check-prefix=CHECK-RECORD-GCC-SWITCHES-ESCAPED %s
+// CHECK-RECORD-GCC-SWITCHES-ESCAPED: "-record-command-line" "{{.+}}/with\\ 
spaces/clang {{.+}}"
 
 // RUN: %clang -### -S -ftrivial-auto-var-init=uninitialized %s 2>&1 | 
FileCheck -check-prefix=CHECK-TRIVIAL-UNINIT %s
 // RUN: %clang -### -S -ftrivial-auto-var-init=pattern %s 2>&1 | FileCheck 
-check-prefix=CHECK-TRIVIAL-PATTERN %s



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


[clang] d96ea47 - [AMDGPU][HIP] Improve opt-level handling

2019-12-05 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2019-12-05T11:27:12-05:00
New Revision: d96ea47c75fdf4a62358eae49a0026bcf031bde6

URL: 
https://github.com/llvm/llvm-project/commit/d96ea47c75fdf4a62358eae49a0026bcf031bde6
DIFF: 
https://github.com/llvm/llvm-project/commit/d96ea47c75fdf4a62358eae49a0026bcf031bde6.diff

LOG: [AMDGPU][HIP] Improve opt-level handling

Summary:
The HIP toolchain invokes `llc` without an explicit opt-level, meaning
it always uses the default (-O2). This makes it impossible to use -O1,
for example. The HIP toolchain also coerces -Os/-Oz to -O2 even when
invoking opt, and it coerces -Og to -O2 rather than -O1.

Forward the opt-level to `llc` as well as `opt`, and only coerce levels
where it is required.

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70987

Added: 
clang/test/Driver/hip-toolchain-opt.hip

Modified: 
clang/lib/Driver/ToolChains/HIP.cpp
clang/test/Driver/hip-toolchain-mllvm.hip
clang/test/Driver/hip-toolchain-no-rdc.hip
clang/test/Driver/hip-toolchain-rdc.hip

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/HIP.cpp 
b/clang/lib/Driver/ToolChains/HIP.cpp
index d1f570e75a9b..f68b5cd68184 100644
--- a/clang/lib/Driver/ToolChains/HIP.cpp
+++ b/clang/lib/Driver/ToolChains/HIP.cpp
@@ -62,6 +62,34 @@ static const char *getOutputFileName(Compilation &C, 
StringRef Base,
   }
   return OutputFileName;
 }
+
+static void addOptLevelArgs(const llvm::opt::ArgList &Args,
+llvm::opt::ArgStringList &CmdArgs,
+bool IsLlc = false) {
+  if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
+StringRef OOpt = "3";
+if (A->getOption().matches(options::OPT_O4) ||
+A->getOption().matches(options::OPT_Ofast))
+  OOpt = "3";
+else if (A->getOption().matches(options::OPT_O0))
+  OOpt = "0";
+else if (A->getOption().matches(options::OPT_O)) {
+  // Clang and opt support -Os/-Oz; llc only supports -O0, -O1, -O2 and -O3
+  // so we map -Os/-Oz to -O2.
+  // Only clang supports -Og, and maps it to -O1.
+  // We map anything else to -O2.
+  OOpt = llvm::StringSwitch(A->getValue())
+ .Case("1", "1")
+ .Case("2", "2")
+ .Case("3", "3")
+ .Case("s", IsLlc ? "2" : "s")
+ .Case("z", IsLlc ? "2" : "z")
+ .Case("g", "1")
+ .Default("2");
+}
+CmdArgs.push_back(Args.MakeArgString("-O" + OOpt));
+  }
+}
 } // namespace
 
 const char *AMDGCN::Linker::constructLLVMLinkCommand(
@@ -93,25 +121,7 @@ const char *AMDGCN::Linker::constructOptCommand(
   // The input to opt is the output from llvm-link.
   OptArgs.push_back(InputFileName);
   // Pass optimization arg to opt.
-  if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
-StringRef OOpt = "3";
-if (A->getOption().matches(options::OPT_O4) ||
-A->getOption().matches(options::OPT_Ofast))
-  OOpt = "3";
-else if (A->getOption().matches(options::OPT_O0))
-  OOpt = "0";
-else if (A->getOption().matches(options::OPT_O)) {
-  // -Os, -Oz, and -O(anything else) map to -O2
-  OOpt = llvm::StringSwitch(A->getValue())
- .Case("1", "1")
- .Case("2", "2")
- .Case("3", "3")
- .Case("s", "2")
- .Case("z", "2")
- .Default("2");
-}
-OptArgs.push_back(Args.MakeArgString("-O" + OOpt));
-  }
+  addOptLevelArgs(Args, OptArgs);
   OptArgs.push_back("-mtriple=amdgcn-amd-amdhsa");
   OptArgs.push_back(Args.MakeArgString("-mcpu=" + SubArchName));
 
@@ -136,10 +146,15 @@ const char *AMDGCN::Linker::constructLlcCommand(
 llvm::StringRef OutputFilePrefix, const char *InputFileName,
 bool OutputIsAsm) const {
   // Construct llc command.
-  ArgStringList LlcArgs{
-  InputFileName, "-mtriple=amdgcn-amd-amdhsa",
-  Args.MakeArgString(Twine("-filetype=") + (OutputIsAsm ? "asm" : "obj")),
-  Args.MakeArgString("-mcpu=" + SubArchName)};
+  ArgStringList LlcArgs;
+  // The input to llc is the output from opt.
+  LlcArgs.push_back(InputFileName);
+  // Pass optimization arg to llc.
+  addOptLevelArgs(Args, LlcArgs, /*IsLlc=*/true);
+  LlcArgs.push_back("-mtriple=amdgcn-amd-amdhsa");
+  LlcArgs.push_back(Args.MakeArgString("-mcpu=" + SubArchName));
+  LlcArgs.push_back(
+  Args.MakeArgString(Twine("-filetype=") + (OutputIsAsm ? "asm" : "obj")));
 
   // Extract all the -m options
   std::vector Features;

diff  --git a/clang/test/Driver/hip-toolchain-mllvm.hip 
b/clang/test/Driver/hip-toolchain-mllvm.hip
index d8f9c0bbf530..ab665055f482 100644
--- a/clang/test/Driver/hip-toolchain-mllvm.hip
+++ b/clang/test/Driver/hip-toolchain-mllvm.hip
@@ -18,8 +18,9 @@
 // CHECK-SAME: "-o" [[OPT_803_BC:".*-gfx803-optimized.*bc"]]
 
 // CHECK: [[LLC: ".*llc"]] [[OPT_803_BC]]
-// CHECK-SAME

[clang] c9de002 - [AMDGPU][HIP] Change default DWARF version to 4

2019-11-14 Thread Scott Linder via cfe-commits

Author: Scott Linder
Date: 2019-11-14T11:51:11-05:00
New Revision: c9de002a2cf02b1a00abe5caaa05fd722583218a

URL: 
https://github.com/llvm/llvm-project/commit/c9de002a2cf02b1a00abe5caaa05fd722583218a
DIFF: 
https://github.com/llvm/llvm-project/commit/c9de002a2cf02b1a00abe5caaa05fd722583218a.diff

LOG: [AMDGPU][HIP] Change default DWARF version to 4

Summary:
Tooling around DWARF 5 is still not mature enough for this to be a sane
default, and the AMDGPU and HIP toolchains should agree on a single
default.

Subscribers: kzhuravl, jvesely, wdng, nhaehnle, yaxunl, aprantl, dstuttard, 
tpr, t-tye, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70191

Added: 
clang/test/Driver/hip-toolchain-dwarf.hip

Modified: 
clang/lib/Driver/ToolChains/AMDGPU.h
clang/lib/Driver/ToolChains/HIP.h
clang/test/Driver/amdgpu-toolchain.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.h 
b/clang/lib/Driver/ToolChains/AMDGPU.h
index 5585cc534861..f4c78bea5cc9 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -55,7 +55,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public 
Generic_ELF {
 public:
   AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args);
-  unsigned GetDefaultDwarfVersion() const override { return 5; }
+  unsigned GetDefaultDwarfVersion() const override { return 4; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
   bool IsMathErrnoDefault() const override { return false; }
 

diff  --git a/clang/lib/Driver/ToolChains/HIP.h 
b/clang/lib/Driver/ToolChains/HIP.h
index 2d146ce5cc6f..c4f944e458bf 100644
--- a/clang/lib/Driver/ToolChains/HIP.h
+++ b/clang/lib/Driver/ToolChains/HIP.h
@@ -113,7 +113,7 @@ class LLVM_LIBRARY_VISIBILITY HIPToolChain : public 
ToolChain {
   computeMSVCVersion(const Driver *D,
  const llvm::opt::ArgList &Args) const override;
 
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
+  unsigned GetDefaultDwarfVersion() const override { return 4; }
 
   const ToolChain &HostTC;
 

diff  --git a/clang/test/Driver/amdgpu-toolchain.c 
b/clang/test/Driver/amdgpu-toolchain.c
index e51b7b53170c..c058ef249ef2 100644
--- a/clang/test/Driver/amdgpu-toolchain.c
+++ b/clang/test/Driver/amdgpu-toolchain.c
@@ -8,4 +8,4 @@
 // AS_LINK: clang{{.*}} "-cc1as"
 // AS_LINK: ld.lld{{.*}} "-shared"
 
-// DWARF_VER: "-dwarf-version=5"
+// DWARF_VER: "-dwarf-version=4"

diff  --git a/clang/test/Driver/hip-toolchain-dwarf.hip 
b/clang/test/Driver/hip-toolchain-dwarf.hip
new file mode 100644
index ..44d66fe52e04
--- /dev/null
+++ b/clang/test/Driver/hip-toolchain-dwarf.hip
@@ -0,0 +1,9 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -### -c -target x86_64-linux-gnu -fgpu-rdc \
+// RUN:   -x hip --cuda-gpu-arch=gfx803 %s \
+// RUN:   -Xarch_gfx803 -g 2>&1 | FileCheck %s -check-prefix=DWARF_VER
+
+// DWARF_VER: "-dwarf-version=4"



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


r375442 - [Clang] Add VerboseOutputStream to CompilerInstance

2019-10-21 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Mon Oct 21 12:04:56 2019
New Revision: 375442

URL: http://llvm.org/viewvc/llvm-project?rev=375442&view=rev
Log:
[Clang] Add VerboseOutputStream to CompilerInstance

Remove 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 covers the case when no flags like -version or -help are
passed, namely the "X warnings and Y errors generated." diagnostic.

Differential Revision: https://reviews.llvm.org/D53768

Modified:
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/unittests/Frontend/OutputStreamTest.cpp

Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=375442&r1=375441&r2=375442&view=diff
==
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Mon Oct 21 12:04:56 2019
@@ -155,6 +155,12 @@ class CompilerInstance : public ModuleLo
   /// One or more modules failed to build.
   bool ModuleBuildFailed = false;
 
+  /// The stream for verbose output if owned, otherwise nullptr.
+  std::unique_ptr OwnedVerboseOutputStream;
+
+  /// 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.
@@ -217,9 +223,6 @@ public:
   /// \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);
@@ -350,6 +353,21 @@ public:
   }
 
   /// }
+  /// @name VerboseOutputStream
+  /// }
+
+  /// Replace the current stream for verbose output.
+  void setVerboseOutputStream(raw_ostream &Value);
+
+  /// Replace the current stream for verbose output.
+  void setVerboseOutputStream(std::unique_ptr Value);
+
+  /// Get the current stream for verbose output.
+  raw_ostream &getVerboseOutputStream() {
+return *VerboseOutputStream;
+  }
+
+  /// }
   /// @name Target Info
   /// {
 

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=375442&r1=375441&r2=375442&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Mon Oct 21 12:04:56 2019
@@ -84,6 +84,16 @@ void CompilerInstance::setDiagnostics(Di
   Diagnostics = Value;
 }
 
+void CompilerInstance::setVerboseOutputStream(raw_ostream &Value) {
+  OwnedVerboseOutputStream.release();
+  VerboseOutputStream = &Value;
+}
+
+void CompilerInstance::setVerboseOutputStream(std::unique_ptr 
Value) {
+  OwnedVerboseOutputStream.swap(Value);
+  VerboseOutputStream = OwnedVerboseOutputStream.get();
+}
+
 void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; }
 void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; }
 
@@ -896,9 +906,7 @@ bool CompilerInstance::ExecuteAction(Fro
   // DesiredStackSpace available.
   noteBottomOfStack();
 
-  // 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;

Modified: cfe/trunk/unittests/Frontend/OutputStreamTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Frontend/OutputStreamTest.cpp?rev=375442&r1=375441&r2=375442&view=diff
==
--- cfe/trunk/unittests/Frontend/OutputStreamTest.cpp (original)
+++ cfe/trunk/unittests/Frontend/OutputStreamTest.cpp Mon Oct 21 12:04:56 2019
@@ -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,58 @@ TEST(FrontendOutputTests, TestOutputStre
   EXPECT_TRUE(!IRBuffer.empty());
   EXPECT_TRUE(StringRef(IRBuffer.data()).startswith("BC"));
 }
+
+TEST(FrontendOutputTests, TestVerboseOutputStreamShared) {
+  auto Invocation = std::make_shared();
+  Invocation->getPreprocessorOpts().addRemappedFile(
+  "test.cc", MemoryBuffer::getMemB

r359814 - [Sema] Emit warning for visibility attribute on internal-linkage declaration

2019-05-02 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Thu May  2 12:03:57 2019
New Revision: 359814

URL: http://llvm.org/viewvc/llvm-project?rev=359814&view=rev
Log:
[Sema] Emit warning for visibility attribute on internal-linkage declaration

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

Differential Revision: https://reviews.llvm.org/D61097

Modified:
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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=359814&r1=359813&r2=359814&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu May  2 12:03:57 
2019
@@ -2778,6 +2778,9 @@ def warn_attribute_ignored : Warning<"%0
 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;

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=359814&r1=359813&r2=359814&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu May  2 12:03:57 2019
@@ -2615,6 +2615,14 @@ static void handleVisibilityAttr(Sema &S
 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;

Modified: cfe/trunk/test/Sema/attr-visibility.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-visibility.c?rev=359814&r1=359813&r2=359814&view=diff
==
--- cfe/trunk/test/Sema/attr-visibility.c (original)
+++ cfe/trunk/test/Sema/attr-visibility.c Thu May  2 12:03:57 2019
@@ -26,3 +26,9 @@ typedef int __attribute__((visibility("d
 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}}

Modified: cfe/trunk/test/SemaCXX/ast-print.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ast-print.cpp?rev=359814&r1=359813&r2=359814&view=diff
==
--- cfe/trunk/test/SemaCXX/ast-print.cpp (original)
+++ cfe/trunk/test/SemaCXX/ast-print.cpp Thu May  2 12:03:57 2019
@@ -209,10 +209,8 @@ void test(int i) {
 }
 }
 
-namespace {
 // CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S;
 struct [[gnu::visibility("hidden")]] S;
-}
 
 // CHECK:  struct CXXFunctionalCastExprPrint {
 // CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};

Modified: cfe/trunk/test/SemaCXX/attr-visibility.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-visibility.cpp?rev=359814&r1=359813&r2=359814&view=diff
==
--- cfe/trunk/test/SemaCXX/attr-visibility.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-visibility.cpp Thu May  2 12:03:57 2019
@@ -18,3 +18,9 @@ void foo() {
 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 
{{'visibili

r359702 - Bump DIAG_SIZE_SEMA, as we've hit it.

2019-05-01 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Wed May  1 09:45:49 2019
New Revision: 359702

URL: http://llvm.org/viewvc/llvm-project?rev=359702&view=rev
Log:
Bump DIAG_SIZE_SEMA, as we've hit it.

$ grep 'DIAG_SIZE_SEMA  =' include/clang/Basic/DiagnosticIDs.h
  DIAG_SIZE_SEMA  = 4000,
$ grep DIAG $(build)/tools/clang/include/clang/Basic/DiagnosticSemaKinds.inc | 
wc -l
3499

Modified:
cfe/trunk/include/clang/Basic/DiagnosticIDs.h

Modified: cfe/trunk/include/clang/Basic/DiagnosticIDs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticIDs.h?rev=359702&r1=359701&r2=359702&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticIDs.h (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticIDs.h Wed May  1 09:45:49 2019
@@ -36,7 +36,7 @@ namespace clang {
   DIAG_SIZE_AST   =  150,
   DIAG_SIZE_COMMENT   =  100,
   DIAG_SIZE_CROSSTU   =  100,
-  DIAG_SIZE_SEMA  = 3500,
+  DIAG_SIZE_SEMA  = 4000,
   DIAG_SIZE_ANALYSIS  =  100,
   DIAG_SIZE_REFACTORING   = 1000,
 };


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


r359039 - Move setTargetAttributes after setGVProperties in SetFunctionAttributes

2019-04-23 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Tue Apr 23 14:50:11 2019
New Revision: 359039

URL: http://llvm.org/viewvc/llvm-project?rev=359039&view=rev
Log:
Move setTargetAttributes after setGVProperties in SetFunctionAttributes

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

Differential Revision: https://reviews.llvm.org/D60967

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

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=359039&r1=359038&r2=359039&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Apr 23 14:50:11 2019
@@ -1558,12 +1558,8 @@ void CodeGenModule::SetFunctionAttribute
 
   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 @@ void CodeGenModule::SetFunctionAttribute
   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())

Modified: cfe/trunk/test/CodeGenOpenCL/visibility.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/visibility.cl?rev=359039&r1=359038&r2=359039&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/visibility.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/visibility.cl Tue Apr 23 14:50:11 2019
@@ -72,6 +72,57 @@ __attribute__((visibility("protected")))
 // 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()


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


r357285 - [AMDGPU] Switch default DWARF version to 5

2019-03-29 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Fri Mar 29 10:45:40 2019
New Revision: 357285

URL: http://llvm.org/viewvc/llvm-project?rev=357285&view=rev
Log:
[AMDGPU] Switch default DWARF version to 5

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

Differential Revision: https://reviews.llvm.org/D59008

Modified:
cfe/trunk/lib/Driver/ToolChains/AMDGPU.h
cfe/trunk/test/Driver/amdgpu-toolchain.c
cfe/trunk/test/Driver/split-debug.c

Modified: cfe/trunk/lib/Driver/ToolChains/AMDGPU.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/AMDGPU.h?rev=357285&r1=357284&r2=357285&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/AMDGPU.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/AMDGPU.h Fri Mar 29 10:45:40 2019
@@ -55,7 +55,7 @@ protected:
 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,

Modified: cfe/trunk/test/Driver/amdgpu-toolchain.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/amdgpu-toolchain.c?rev=357285&r1=357284&r2=357285&view=diff
==
--- cfe/trunk/test/Driver/amdgpu-toolchain.c (original)
+++ cfe/trunk/test/Driver/amdgpu-toolchain.c Fri Mar 29 10:45:40 2019
@@ -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"

Modified: cfe/trunk/test/Driver/split-debug.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/split-debug.c?rev=357285&r1=357284&r2=357285&view=diff
==
--- cfe/trunk/test/Driver/split-debug.c (original)
+++ cfe/trunk/test/Driver/split-debug.c Fri Mar 29 10:45:40 2019
@@ -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


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


r353870 - [AMDGPU] Require at least protected visibility for certain symbols

2019-02-12 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Tue Feb 12 10:30:38 2019
New Revision: 353870

URL: http://llvm.org/viewvc/llvm-project?rev=353870&view=rev
Log:
[AMDGPU] Require at least protected visibility for certain symbols

This allows the global visibility controls to be restrictive while still
populating the dynamic symbol table where required.

Differential Revision: https://reviews.llvm.org/D56871

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

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=353870&r1=353869&r2=353870&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Feb 12 10:30:38 2019
@@ -3212,6 +3212,9 @@ CodeGenModule::GetOrCreateLLVMGlobal(Str
 return getTargetCodeGenInfo().performAddrSpaceCast(*this, GV, AddrSpace,
ExpectedAS, Ty);
 
+  if (GV->isDeclaration())
+getTargetCodeGenInfo().setTargetAttributes(D, GV, *this);
+
   return GV;
 }
 

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=353870&r1=353869&r2=353870&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Tue Feb 12 10:30:38 2019
@@ -7763,8 +7763,23 @@ public:
 };
 }
 
+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);

Added: cfe/trunk/test/CodeGenOpenCL/visibility.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/visibility.cl?rev=353870&view=auto
==
--- cfe/trunk/test/CodeGenOpenCL/visibility.cl (added)
+++ cfe/trunk/test/CodeGenOpenCL/visibility.cl Tue Feb 12 10:30:38 2019
@@ -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:  @ex

r352391 - Add -fapply-global-visibility-to-externs for -cc1

2019-01-28 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Mon Jan 28 09:12:19 2019
New Revision: 352391

URL: http://llvm.org/viewvc/llvm-project?rev=352391&view=rev
Log:
Add -fapply-global-visibility-to-externs for -cc1

Introduce an option to request global visibility settings be applied to
declarations without a definition or an explicit visibility, rather than
the existing behavior of giving these default visibility. When the
visibility of all or most extern definitions are known this allows for
the same optimisations -fvisibility permits without updating source code
to annotate all declarations.

Differential Revision: https://reviews.llvm.org/D56868

Added:
cfe/trunk/test/CodeGen/set-visibility-for-decls.c
Modified:
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/Driver/amdgpu-visibility.cl
cfe/trunk/test/Driver/hip-toolchain-no-rdc.hip
cfe/trunk/test/Driver/hip-toolchain-rdc.hip

Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=352391&r1=352390&r2=352391&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Mon Jan 28 09:12:19 2019
@@ -261,6 +261,8 @@ ENUM_LANGOPT(ValueVisibilityMode, Visibi
  "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,

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=352391&r1=352390&r2=352391&view=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Jan 28 09:12:19 2019
@@ -702,6 +702,8 @@ def fvisibility : Separate<["-"], "fvisi
   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">,

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=352391&r1=352390&r2=352391&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Jan 28 09:12:19 2019
@@ -731,9 +731,11 @@ void CodeGenModule::setGlobalVisibility(
   }
   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()));
 }
 

Modified: cfe/trunk/lib/Driver/ToolChains/AMDGPU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/AMDGPU.cpp?rev=352391&r1=352390&r2=352391&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/AMDGPU.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/AMDGPU.cpp Mon Jan 28 09:12:19 2019
@@ -108,5 +108,6 @@ void AMDGPUToolChain::addClangTargetOpti
  options::OPT_fvisibility_ms_compat)) {
 CC1Args.push_back("-fvisibility");
 CC1Args.push_back("hidden");
+CC1Args.push_back("-fapply-global-visibility-to-externs");
   }
 }

Modified: cfe/trunk/lib/Driver/ToolChains/HIP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/HIP.cpp?rev=352391&r1=352390&r2=352391&view=diff
==
--- cfe/t

r349155 - Implement -frecord-command-line (-frecord-gcc-switches)

2018-12-14 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Fri Dec 14 07:38:15 2018
New Revision: 349155

URL: http://llvm.org/viewvc/llvm-project?rev=349155&view=rev
Log:
Implement -frecord-command-line (-frecord-gcc-switches)

Implement options in clang to enable recording the driver command-line
in an ELF section.

Implement a new special named metadata, llvm.commandline, to support
frontends embedding their command-line options in IR/ASM/ELF.

This differs from the GCC implementation in some key ways:

* In GCC there is only one command-line possible per compilation-unit,
  in LLVM it mirrors llvm.ident and multiple are allowed.
* In GCC individual options are separated by NULL bytes, in LLVM entire
  command-lines are separated by NULL bytes. The advantage of the GCC
  approach is to clearly delineate options in the face of embedded
  spaces. The advantage of the LLVM approach is to support merging
  multiple command-lines unambiguously, while handling embedded spaces
  with escaping.

Differential Revision: https://reviews.llvm.org/D54487
Clang Differential Revision: https://reviews.llvm.org/D54489

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

Modified: cfe/trunk/docs/ClangCommandLineReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangCommandLineReference.rst?rev=349155&r1=349154&r2=349155&view=diff
==
--- cfe/trunk/docs/ClangCommandLineReference.rst (original)
+++ cfe/trunk/docs/ClangCommandLineReference.rst Fri Dec 14 07:38:15 2018
@@ -792,6 +792,16 @@ Don't use blacklist file for sanitizers
 
 .. option:: -fparse-all-comments
 
+.. option:: -frecord-command-line, -frecord-gcc-switches, 
-fno-record-command-line, -fno-record-gcc-switches
+
+Generate a section named ".GCC.command.line" containing the clang driver
+command-line. After linking, the section may contain multiple command lines,
+which will be individually terminated by null bytes. Separate arguments within
+a command line are combined with spaces; spaces and backslashes within an
+argument are escaped with backslashes. This format differs from the format of
+the equivalent section produced by GCC with the -frecord-gcc-switches flag.
+This option is currently only supported on ELF targets.
+
 .. option:: -fsanitize-address-field-padding=
 
 Level of field padding for AddressSanitizer
@@ -2831,7 +2841,7 @@ Embed source text in DWARF debug section
 
 .. option:: -gpubnames, -gno-pubnames
 
-.. option:: -grecord-gcc-switches, -gno-record-gcc-switches
+.. option:: -grecord-command-line, -grecord-gcc-switches, 
-gno-record-command-line, -gno-record-gcc-switches
 
 .. option:: -gsplit-dwarf
 

Modified: cfe/trunk/include/clang/Basic/CodeGenOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CodeGenOptions.h?rev=349155&r1=349154&r2=349155&view=diff
==
--- cfe/trunk/include/clang/Basic/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Basic/CodeGenOptions.h Fri Dec 14 07:38:15 2018
@@ -148,6 +148,10 @@ public:
   /// non-empty.
   std::string DwarfDebugFlags;
 
+  /// The string containing the commandline for the llvm.commandline metadata,
+  /// if non-empty.
+  std::string RecordCommandLine;
+
   std::map DebugPrefixMap;
 
   /// The ABI to use for passing floating point arguments.

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=349155&r1=349154&r2=349155&view=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Dec 14 07:38:15 2018
@@ -167,6 +167,8 @@ def fdebug_compilation_dir : Separate<["
   HelpText<"The compilation directory to embed in the debug info.">;
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">;
 def compress_debug_sections : Flag<["-", "--"], "compress-debug-sections">,
 HelpText<"DWARF debug sections compression">;
 def compress_debug_sections_EQ : Joined<["-"], "compress-debug-sections=">,

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=349155&r1=349154&r2=349155&view=diff
==

[clang-tools-extra] r346884 - [Support] Teach YAMLIO about polymorphic types

2018-11-14 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Wed Nov 14 11:39:59 2018
New Revision: 346884

URL: http://llvm.org/viewvc/llvm-project?rev=346884&view=rev
Log:
[Support] Teach YAMLIO about polymorphic types

Add support for "polymorphic" types to YAMLIO.

PolymorphicTraits can dynamically switch between other traits (Scalar, Map, or
Sequence). When inputting, the PolymorphicTraits type is told which type to
become, and when outputting the PolymorphicTraits type is asked which type it
currently is.

Also add support for TaggedScalarTraits to allow dynamically differentiating
between multiple scalar types using YAML tags.

Serialize empty maps as "{}" and empty sequences as "[]", so that types
are preserved when round-tripping PolymorphicTraits. This change has
equivalent semantics, but may break e.g. tests which compare output
verbatim.

Differential Revision: https://reviews.llvm.org/D48144

Modified:
clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp

Modified: clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp?rev=346884&r1=346883&r2=346884&view=diff
==
--- clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-doc/YAMLGeneratorTest.cpp Wed Nov 
14 11:39:59 2018
@@ -58,7 +58,7 @@ ChildRecords:
 ChildFunctions:  
   - USR: ''
 Name:'OneFunction'
-ReturnType:  
+ReturnType:  {}
 ChildEnums:  
   - USR: ''
 Name:'OneEnum'
@@ -123,7 +123,7 @@ ChildRecords:
 ChildFunctions:  
   - USR: ''
 Name:'OneFunction'
-ReturnType:  
+ReturnType:  {}
 ChildEnums:  
   - USR: ''
 Name:'OneEnum'


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


r346884 - [Support] Teach YAMLIO about polymorphic types

2018-11-14 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Wed Nov 14 11:39:59 2018
New Revision: 346884

URL: http://llvm.org/viewvc/llvm-project?rev=346884&view=rev
Log:
[Support] Teach YAMLIO about polymorphic types

Add support for "polymorphic" types to YAMLIO.

PolymorphicTraits can dynamically switch between other traits (Scalar, Map, or
Sequence). When inputting, the PolymorphicTraits type is told which type to
become, and when outputting the PolymorphicTraits type is asked which type it
currently is.

Also add support for TaggedScalarTraits to allow dynamically differentiating
between multiple scalar types using YAML tags.

Serialize empty maps as "{}" and empty sequences as "[]", so that types
are preserved when round-tripping PolymorphicTraits. This change has
equivalent semantics, but may break e.g. tests which compare output
verbatim.

Differential Revision: https://reviews.llvm.org/D48144

Modified:
cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp
cfe/trunk/unittests/Tooling/RefactoringActionRulesTest.cpp

Modified: cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp?rev=346884&r1=346883&r2=346884&view=diff
==
--- cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/DiagnosticsYamlTest.cpp Wed Nov 14 11:39:59 2018
@@ -82,7 +82,7 @@ TEST(DiagnosticsYamlTest, serializesDiag
 "Message: 'message #3'\n"
 "FileOffset:  72\n"
 "FilePath:'path/to/source2.cpp'\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n",
 YamlContentStream.str());
 }
@@ -113,7 +113,7 @@ TEST(DiagnosticsYamlTest, deserializesDi
 "Message: 'message #3'\n"
 "FileOffset:  98\n"
 "FilePath:path/to/source.cpp\n"
-"Replacements:\n"
+"Replacements:[]\n"
 "...\n";
   TranslationUnitDiagnostics TUDActual;
   yaml::Input YAML(YamlContent);

Modified: cfe/trunk/unittests/Tooling/RefactoringActionRulesTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RefactoringActionRulesTest.cpp?rev=346884&r1=346883&r2=346884&view=diff
==
--- cfe/trunk/unittests/Tooling/RefactoringActionRulesTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RefactoringActionRulesTest.cpp Wed Nov 14 
11:39:59 2018
@@ -117,8 +117,8 @@ TEST_F(RefactoringActionRulesTest, MyFir
  "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


r339265 - [DebugInfo][OpenCL] Address post-commit review for r338299

2018-08-08 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Wed Aug  8 08:56:12 2018
New Revision: 339265

URL: http://llvm.org/viewvc/llvm-project?rev=339265&view=rev
Log:
[DebugInfo][OpenCL] Address post-commit review for r338299

NFC refactor of code to generate debug info for OpenCL 2.X blocks.

Differential Revision: https://reviews.llvm.org/D50099

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

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=339265&r1=339264&r2=339265&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Aug  8 08:56:12 2018
@@ -942,12 +942,47 @@ llvm::DIType *CGDebugInfo::getOrCreateSt
   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,10 +994,9 @@ llvm::DIType *CGDebugInfo::CreateType(co
   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.
@@ -970,27 +1004,8 @@ llvm::DIType *CGDebugInfo::CreateType(co
 
   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(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;
-  }
+  FieldOffset = collectDefaultElementTypesForBlockPointer(Ty, Unit, DescTy,
+  0, EltTys);
 
   Elements = DBuilder.getOrCreateArray(EltTys);
 
@@ -998,7 +1013,7 @@ llvm::DIType *CGDebugInfo::CreateType(co
   // DW_AT_APPLE_BLOC

r339150 - [OpenCL] Restore r338899 (reverted in r338904), fixing stack-use-after-return

2018-08-07 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Tue Aug  7 08:52:49 2018
New Revision: 339150

URL: http://llvm.org/viewvc/llvm-project?rev=339150&view=rev
Log:
[OpenCL] Restore r338899 (reverted in r338904), fixing stack-use-after-return

Always emit alloca in entry block for enqueue_kernel builtin.

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

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

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=339150&r1=339149&r2=339150&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Aug  7 08:52:49 2018
@@ -3337,24 +3337,31 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 
 // 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::Value *Ptr;
+auto CreateArrayForSizeVar = [=](unsigned First)
+-> std::tuple {
+  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 *TmpPtr = Tmp.getPointer();
+  llvm::Value *TmpSize = EmitLifetimeStart(
+  CGM.getDataLayout().getTypeAllocSize(Tmp.getElementType()), TmpPtr);
+  llvm::Value *ElemPtr;
   // 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(TmpPtr, {Zero, Index});
 if (I == First)
-  Ptr = GEP;
+  ElemPtr = GEP;
 auto *V =
 Builder.CreateZExtOrTrunc(EmitScalarExpr(E->getArg(I)), SizeTy);
 Builder.CreateAlignedStore(
 V, GEP, CGM.getDataLayout().getPrefTypeAlignment(SizeTy));
   }
-  return Ptr;
+  return std::tie(ElemPtr, TmpSize, TmpPtr);
 };
 
 // Could have events and/or varargs.
@@ -3366,24 +3373,27 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   llvm::Value *Kernel =
   Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy);
   auto *Block = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
-  auto *PtrToSizeArray = CreateArrayForSizeVar(4);
+  llvm::Value *ElemPtr, *TmpSize, *TmpPtr;
+  std::tie(ElemPtr, TmpSize, TmpPtr) = CreateArrayForSizeVar(4);
 
   // Create a vector of the arguments, as well as a constant value to
   // express to the runtime the number of variadic arguments.
   std::vector Args = {
   Queue,  Flags, Range,
   Kernel, Block, ConstantInt::get(IntTy, NumArgs - 4),
-  PtrToSizeArray};
+  ElemPtr};
   std::vector ArgTys = {
-  QueueTy,  IntTy,RangeTy,
-  GenericVoidPtrTy, GenericVoidPtrTy, IntTy,
-  PtrToSizeArray->getType()};
+  QueueTy,  IntTy, RangeTy,   GenericVoidPtrTy,
+  GenericVoidPtrTy, IntTy, ElemPtr->getType()};
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(
   Int32Ty, llvm::ArrayRef(ArgTys), false);
-  return RValue::get(
-  Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name),
- llvm::ArrayRef(Args)));
+  auto Call =
+  RValue::get(Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name),
+ llvm::ArrayRef(Args)));
+  if (TmpSize)
+EmitLifetimeEnd(TmpSize, TmpPtr);
+  return Call;
 }
 // Any calls now have event arguments passed.
 if (NumArgs >= 7) {
@@ -3430,15 +3440,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   ArgTys.push_back(Int32Ty);
   Name = "__enqueue_kernel_events_varargs";
 
-  auto *PtrToSizeArray = CreateArrayForSizeVar(7);
-  Args.push_back(PtrToSizeArray);
-  ArgTys.push_back(PtrToSizeArray->getType());
+  llvm::Value *ElemPtr, *TmpSize, *TmpPtr;
+  std::tie(ElemPtr, TmpSize, TmpPtr) = CreateArrayForSizeVar(7);
+  Args.push_back(ElemPtr);
+  ArgTys.push_back(ElemPtr->getType());
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(
   Int32Ty, llvm::ArrayRef(ArgTys), false);

r338899 - [OpenCL] Always emit alloca in entry block for enqueue_kernel builtin

2018-08-03 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Fri Aug  3 08:50:52 2018
New Revision: 338899

URL: http://llvm.org/viewvc/llvm-project?rev=338899&view=rev
Log:
[OpenCL] Always emit alloca in entry block for enqueue_kernel builtin

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

Differential Revision: https://reviews.llvm.org/D50104


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

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=338899&r1=338898&r2=338899&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Aug  3 08:50:52 2018
@@ -3338,23 +3338,29 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 // 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::Value *Ptr;
+  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 *TmpPtr = Tmp.getPointer();
+  llvm::Value *TmpSize = EmitLifetimeStart(
+  CGM.getDataLayout().getTypeAllocSize(Tmp.getElementType()), TmpPtr);
+  llvm::Value *ElemPtr;
   // 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(TmpPtr, {Zero, Index});
 if (I == First)
-  Ptr = GEP;
+  ElemPtr = GEP;
 auto *V =
 Builder.CreateZExtOrTrunc(EmitScalarExpr(E->getArg(I)), SizeTy);
 Builder.CreateAlignedStore(
 V, GEP, CGM.getDataLayout().getPrefTypeAlignment(SizeTy));
   }
-  return Ptr;
+  return std::tie(ElemPtr, TmpSize, TmpPtr);
 };
 
 // Could have events and/or varargs.
@@ -3366,24 +3372,27 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   llvm::Value *Kernel =
   Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy);
   auto *Block = Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy);
-  auto *PtrToSizeArray = CreateArrayForSizeVar(4);
+  llvm::Value *ElemPtr, *TmpSize, *TmpPtr;
+  std::tie(ElemPtr, TmpSize, TmpPtr) = CreateArrayForSizeVar(4);
 
   // Create a vector of the arguments, as well as a constant value to
   // express to the runtime the number of variadic arguments.
   std::vector Args = {
   Queue,  Flags, Range,
   Kernel, Block, ConstantInt::get(IntTy, NumArgs - 4),
-  PtrToSizeArray};
+  ElemPtr};
   std::vector ArgTys = {
-  QueueTy,  IntTy,RangeTy,
-  GenericVoidPtrTy, GenericVoidPtrTy, IntTy,
-  PtrToSizeArray->getType()};
+  QueueTy,  IntTy, RangeTy,   GenericVoidPtrTy,
+  GenericVoidPtrTy, IntTy, ElemPtr->getType()};
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(
   Int32Ty, llvm::ArrayRef(ArgTys), false);
-  return RValue::get(
-  Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name),
- llvm::ArrayRef(Args)));
+  auto Call =
+  RValue::get(Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name),
+ llvm::ArrayRef(Args)));
+  if (TmpSize)
+EmitLifetimeEnd(TmpSize, TmpPtr);
+  return Call;
 }
 // Any calls now have event arguments passed.
 if (NumArgs >= 7) {
@@ -3430,15 +3439,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   ArgTys.push_back(Int32Ty);
   Name = "__enqueue_kernel_events_varargs";
 
-  auto *PtrToSizeArray = CreateArrayForSizeVar(7);
-  Args.push_back(PtrToSizeArray);
-  ArgTys.push_back(PtrToSizeArray->getType());
+  llvm::Value *ElemPtr, *TmpSize, *TmpPtr;
+  std::tie(ElemPtr, TmpSize, TmpPtr) = CreateArrayForSizeVar(7);
+  Args.push_back(ElemPtr);
+  ArgTys.push_back(ElemPtr->getType());
 
   llvm::FunctionType *FTy = llvm::FunctionType::get(
   Int32Ty, llvm::ArrayRef(ArgTys), false);
-  return RValue::get(
-  Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name),

r338321 - Fix use of uninitialized variable in r338299

2018-07-30 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Mon Jul 30 15:52:07 2018
New Revision: 338321

URL: http://llvm.org/viewvc/llvm-project?rev=338321&view=rev
Log:
Fix use of uninitialized variable in r338299

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=338321&r1=338320&r2=338321&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Jul 30 15:52:07 2018
@@ -989,9 +989,9 @@ llvm::DIType *CGDebugInfo::CreateType(co
 EltTys.push_back(DBuilder.createMemberType(
 Unit, "__descriptor", nullptr, LineNo, FieldSize, FieldAlign, 
FieldOffset,
 llvm::DINode::FlagZero, DescTy));
+FieldOffset += FieldSize;
   }
 
-  FieldOffset += FieldSize;
   Elements = DBuilder.getOrCreateArray(EltTys);
 
   // The __block_literal_generic structs are marked with a special


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


r338299 - [DebugInfo][OpenCL] Generate correct block literal debug info for OpenCL

2018-07-30 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Mon Jul 30 13:31:11 2018
New Revision: 338299

URL: http://llvm.org/viewvc/llvm-project?rev=338299&view=rev
Log:
[DebugInfo][OpenCL] Generate correct block literal debug info for OpenCL

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

Differential Revision: https://reviews.llvm.org/D49930

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

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=338299&r1=338298&r2=338299&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Jul 30 13:31:11 2018
@@ -971,20 +971,25 @@ llvm::DIType *CGDebugInfo::CreateType(co
   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 @@ void CGDebugInfo::EmitDeclareOfBlockLite
   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),
+

r326102 - [DebugInfo] Support DWARF v5 source code embedding extension

2018-02-26 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Mon Feb 26 09:32:31 2018
New Revision: 326102

URL: http://llvm.org/viewvc/llvm-project?rev=326102&view=rev
Log:
[DebugInfo] Support DWARF v5 source code embedding extension

In DWARF v5 the Line Number Program Header is extensible, allowing values with
new content types. This vendor extension to DWARF v5 allows source text to be
embedded directly in the line tables of the debug line section.

Add new flag (-g[no-]embed-source) to Driver and CC1 which indicates
that source should be passed through to LLVM during CodeGen.

Differential Revision: https://reviews.llvm.org/D42766

Added:
cfe/trunk/test/CodeGen/Inputs/debug-info-embed-source.c
cfe/trunk/test/CodeGen/debug-info-embed-source.c
Modified:
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/Driver/amdgpu-toolchain.c
cfe/trunk/test/Driver/debug-options.c

Modified: cfe/trunk/docs/ClangCommandLineReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangCommandLineReference.rst?rev=326102&r1=326101&r2=326102&view=diff
==
--- cfe/trunk/docs/ClangCommandLineReference.rst (original)
+++ cfe/trunk/docs/ClangCommandLineReference.rst Mon Feb 26 09:32:31 2018
@@ -2573,6 +2573,10 @@ Debug information flags
 
 .. option:: -gdwarf-aranges
 
+.. option:: -gembed-source
+
+.. option:: -gno-embed-source
+
 .. option:: -ggnu-pubnames
 
 .. option:: -grecord-gcc-switches, -gno-record-gcc-switches

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=326102&r1=326101&r2=326102&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Feb 26 09:32:31 2018
@@ -1703,6 +1703,11 @@ def gz : Flag<["-"], "gz">, Group;
 def gz_EQ : Joined<["-"], "gz=">, Group,
 HelpText<"DWARF debug sections compression type">;
+def gembed_source : Flag<["-"], "gembed-source">, Group, 
Flags<[CC1Option]>,
+HelpText<"Embed source text in DWARF debug sections">;
+def gno_embed_source : Flag<["-"], "gno-embed-source">, Group,
+Flags<[DriverOption]>,
+HelpText<"Restore the default behavior of not embedding source text in 
DWARF debug sections">;
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
 def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption]>,
   HelpText<"Display available options">;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=326102&r1=326101&r2=326102&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Mon Feb 26 09:32:31 2018
@@ -318,6 +318,9 @@ CODEGENOPT(GnuPubnames, 1, 0)
 
 CODEGENOPT(NoPLT, 1, 0)
 
+/// Whether to embed source in DWARF debug line section.
+CODEGENOPT(EmbedSource, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=326102&r1=326101&r2=326102&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Feb 26 09:32:31 2018
@@ -385,6 +385,19 @@ CGDebugInfo::computeChecksum(FileID FID,
   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 *CGDebugInfo::getOrCreateFi
 
   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.createFil

r326099 - [CodeGen][DebugInfo] Refactor duplicated code, NFC

2018-02-26 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Mon Feb 26 08:31:08 2018
New Revision: 326099

URL: http://llvm.org/viewvc/llvm-project?rev=326099&view=rev
Log:
[CodeGen][DebugInfo] Refactor duplicated code, NFC

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=326099&r1=326098&r2=326099&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Feb 26 08:31:08 2018
@@ -388,18 +388,14 @@ CGDebugInfo::computeChecksum(FileID FID,
 llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
   if (!Loc.isValid())
 // If Location is not valid then use main input file.
-return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
-   remapDIPath(TheCU->getDirectory()),
-   TheCU->getFile()->getChecksum());
+return getOrCreateMainFile();
 
   SourceManager &SM = CGM.getContext().getSourceManager();
   PresumedLoc PLoc = SM.getPresumedLoc(Loc);
 
   if (PLoc.isInvalid() || StringRef(PLoc.getFilename()).empty())
 // If the location is not valid then use main input file.
-return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
-   remapDIPath(TheCU->getDirectory()),
-   TheCU->getFile()->getChecksum());
+return getOrCreateMainFile();
 
   // Cache the results.
   const char *fname = PLoc.getFilename();


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


r324929 - [DebugInfo] Update Checksum handling in CGDebugInfo

2018-02-12 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Mon Feb 12 11:47:05 2018
New Revision: 324929

URL: http://llvm.org/viewvc/llvm-project?rev=324929&view=rev
Log:
[DebugInfo] Update Checksum handling in CGDebugInfo

Update to match new DIFile API.

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=324929&r1=324928&r2=324929&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Feb 12 11:47:05 2018
@@ -361,19 +361,19 @@ StringRef CGDebugInfo::getClassName(cons
   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 @@ llvm::DIFile *CGDebugInfo::getOrCreateFi
 // 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 @@ llvm::DIFile *CGDebugInfo::getOrCreateFi
 // 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,12 +412,15 @@ llvm::DIFile *CGDebugInfo::getOrCreateFi
   }
 
   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;
@@ -428,7 +429,6 @@ llvm::DIFile *CGDebugInfo::getOrCreateFi
 llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
   return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
  remapDIPath(TheCU->getDirectory()),
- TheCU->getFile()->getChecksumKind(),
  TheCU->getFile()->getChecksum());
 }
 
@@ -473,7 +473,8 @@ StringRef CGDebugInfo::getCurrentDirname
 
 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 @@ void CGDebugInfo::CreateCompileUnit() {
 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,

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=324929&r1=324928&r2=324929&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Mon Feb 12 11:47:05 2018
@@ -499,8 +499,8 @@ private:
   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