[PATCH] D72566: [clang-tidy] Clang tidy is now alias aware

2021-09-22 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

I think this should be as simple as having an opt-in "DisableAllAliaseeChecks" 
option in `.clang-tidy`, that force-disables all the checks that are actually 
aliases and not proper checks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72566

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


[PATCH] D110310: State the kind of VerifyDiagnosticConsumer regex syntax (NFC)

2021-09-22 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg created this revision.
sberg added a project: clang.
sberg requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110310

Files:
  clang/include/clang/Frontend/VerifyDiagnosticConsumer.h


Index: clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
===
--- clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
+++ clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
@@ -157,7 +157,8 @@
 /// In this example, the diagnostic may appear only once, if at all.
 ///
 /// Regex matching mode may be selected by appending '-re' to type and
-/// including regexes wrapped in double curly braces in the directive, such as:
+/// including regexes (using POSIX extended regular expression syntax) wrapped
+/// in double curly braces in the directive, such as:
 ///
 /// \code
 ///   expected-error-re {{format specifies type 'wchar_t **' (aka '{{.+}}')}}


Index: clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
===
--- clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
+++ clang/include/clang/Frontend/VerifyDiagnosticConsumer.h
@@ -157,7 +157,8 @@
 /// In this example, the diagnostic may appear only once, if at all.
 ///
 /// Regex matching mode may be selected by appending '-re' to type and
-/// including regexes wrapped in double curly braces in the directive, such as:
+/// including regexes (using POSIX extended regular expression syntax) wrapped
+/// in double curly braces in the directive, such as:
 ///
 /// \code
 ///   expected-error-re {{format specifies type 'wchar_t **' (aka '{{.+}}')}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72566: [clang-tidy] Clang tidy is now alias aware

2021-09-22 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.
Herald added a subscriber: jeroen.dobbelaere.

Hi!

I've been following this issue about aliases in clang-tidy through different 
bug reports and commit attempts. I see that the author abandoned this commit 
without an explanation. What's the reason? Where can I follow the continuation 
of this discussion, is there a email list or something?

I believe making sure that clang-tidy only runs once instance of the checks is 
important, it can dramatically reduce the runtime. This can have a significant 
impact in CI working with large codebases. It also doesn't make sense that 
alias checks aren't identical and don't detect the same things. As it has been 
mentioned above, users should not carry the burden of knowing and maintaining 
what is aliasing what at any point in time, that's an internal implementation 
detail of clang-tidy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72566

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


[PATCH] D108194: [clangd] IncludeCleaner: Mark used headers

2021-09-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/Headers.h:61
   SrcMgr::CharacteristicKind FileKind = SrcMgr::C_User;
+  FileID ID;
 };

Most includes are part of the preamble, so there are two relevant parse actions 
(preamble, and mainfile-using-preamble). Each has its own SourceManager and 
therefore namespace of FileIDs.

There's no rule that says a header gets the same FileID when a preamble is 
used. As written, RecordHeaders is assigning Inclusion::ID based on the 
preamble, and then we end up comparing it to FileIDs from 
compareUnusedIncludes().

From reading the ASTReader code, I *believe* that there's a simple offset 
between the two: e.g. that if a preamble uses FileIDs from 1-100, then these 
might be mapped to FileIDs 1501-1600 when that preamble is reused. We could go 
down the path of exploiting this. (Though we need to investigate the details 
and think a little about how it works with modules).

The somewhat less-coupled alternative we use today is to use the 
FileEntry::Name as documented in the private section of IncludeStructure. There 
are a few ways to build on top of this - basically we're either going to do 
most calculations in FileID space, or expose a "stable file index" from 
IncludeStructure and do most calculations in that space...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108194

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


[PATCH] D110304: [HIP] Fix linking of asanrt.bc

2021-09-22 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added subscribers: kerbowa, nhaehnle, jvesely.
yaxunl requested review of this revision.

HIP currently uses -mlink-builtin-bitcode to link all bitcode libraries, which
changes the linkage of functions to be internal once they are linked in. This
works for common bitcode libraries since these functions are not intended
to be exposed for external callers.

However, the functions in the sanitizer bitcode library is intended to be
called by instructions generated by the sanitizer pass. If their linkage is
changed to internal, their parameters may be altered by optimizations before
the sanitizer pass, which renders them unusable by the sanitizer pass.

To fix this issue, HIP toolchain links the sanitizer bitcode library with
-mlink-bitcode-file, which does not change the linkage.

An enum for bitcode link option and a struct BitCodeLibraryInfo is
introduced in ToolChain as a generic approach to pass the bitcode
linking option between ToolChain and Tool.


https://reviews.llvm.org/D110304

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/lib/Driver/ToolChains/HIP.h
  clang/test/CodeGenCUDA/Inputs/amdgpu-asanrtl.ll
  clang/test/CodeGenCUDA/amdgpu-asan.cu
  clang/test/Driver/hip-sanitize-options.hip

Index: clang/test/Driver/hip-sanitize-options.hip
===
--- clang/test/Driver/hip-sanitize-options.hip
+++ clang/test/Driver/hip-sanitize-options.hip
@@ -34,7 +34,7 @@
 // CHECK-NOT: {{"[^"]*lld(\.exe){0,1}".* ".*hip.bc"}}
 // CHECK: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* "-fsanitize=address"}}
 
-// NORDC: {{"[^"]*clang[^"]*".* "-emit-obj".* "-fcuda-is-device".* "-fsanitize=address".*}} "-o" "[[OUT:[^"]*.o]]"
+// NORDC: {{"[^"]*clang[^"]*".* "-emit-obj".* "-fcuda-is-device".* "-mlink-bitcode-file" ".*asanrtl.bc".* "-mlink-builtin-bitcode" ".*hip.bc".* "-fsanitize=address".*}} "-o" "[[OUT:[^"]*.o]]"
 // NORDC: {{"[^"]*lld(\.exe){0,1}".*}} "[[OUT]]" {{".*asanrtl.bc" ".*hip.bc"}}
 // NORDC: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* "-fsanitize=address"}}
 
Index: clang/test/CodeGenCUDA/amdgpu-asan.cu
===
--- clang/test/CodeGenCUDA/amdgpu-asan.cu
+++ clang/test/CodeGenCUDA/amdgpu-asan.cu
@@ -1,6 +1,20 @@
+// Create a sample address sanitizer bitcode library.
+
+// RUN: %clang_cc1 -x ir -fcuda-is-device -triple amdgcn-amd-amdhsa -emit-llvm-bc \
+// RUN:   -disable-llvm-passes -o %t.asanrtl.bc %S/Inputs/amdgpu-asanrtl.ll
+
+// Check sanitizer runtime library functions survive
+// optimizations without being removed or parameters altered.
+
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
+// RUN:   -fcuda-is-device -target-cpu gfx906 -fsanitize=address \
+// RUN:   -mlink-bitcode-file %t.asanrtl.bc -x hip \
+// RUN:   | FileCheck -check-prefix=ASAN %s
+
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -fsanitize=address \
-// RUN:   -x hip | FileCheck -check-prefix=ASAN %s
+// RUN:   -O3 -mlink-bitcode-file %t.asanrtl.bc -x hip \
+// RUN:   | FileCheck -check-prefix=ASAN %s
 
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=amdgcn-amd-amdhsa \
 // RUN:   -fcuda-is-device -target-cpu gfx906 -x hip \
@@ -8,8 +22,10 @@
 
 // REQUIRES: amdgpu-registered-target
 
-// ASAN-DAG: declare void @__amdgpu_device_library_preserve_asan_functions()
+// ASAN-DAG: define weak void @__amdgpu_device_library_preserve_asan_functions()
 // ASAN-DAG: @__amdgpu_device_library_preserve_asan_functions_ptr = weak addrspace(1) constant void ()* @__amdgpu_device_library_preserve_asan_functions
 // ASAN-DAG: @llvm.compiler.used = {{.*}}@__amdgpu_device_library_preserve_asan_functions_ptr
+// ASAN-DAG: define weak void @__asan_report_load1(i64 %{{.*}})
 
-// CHECK-NOT: @__amdgpu_device_library_preserve_asan_functions_ptr
+// CHECK-NOT: @__amdgpu_device_library_preserve_asan_functions
+// CHECK-NOT: @__asan_report_load1
Index: clang/test/CodeGenCUDA/Inputs/amdgpu-asanrtl.ll
===
--- /dev/null
+++ clang/test/CodeGenCUDA/Inputs/amdgpu-asanrtl.ll
@@ -0,0 +1,13 @@
+; Sample code for amdgpu address sanitizer runtime.
+
+; Note the runtime functions need to have weak linkage and default
+; visibility, otherwise they may be internalized and removed by GlobalOptPass.
+
+define weak void @__amdgpu_device_library_preserve_asan_functions() {
+  tail call void @__asan_report_load1(i64 0)
+  ret void
+}
+
+define weak void @__asan_report_load1(i64 %0) {
+  ret void
+}
Index: clang/lib/Driver/ToolChains/HIP.h
===
--- clang/lib/Driver/ToolChains/HIP.h
+++ clang/lib/Driver/ToolChains/HIP.h
@@ -83,7 +83,7 @@
llvm::opt::ArgStringLis

[PATCH] D110286: [WIP][Clang][OpenMP] Add new clang argument `-fopenmp-target-simd`

2021-09-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 374433.
tianshilei1992 added a comment.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

it can emit right mode


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110286

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2755,15 +2755,21 @@
 
 OpenMPIRBuilder::InsertPointTy
 OpenMPIRBuilder::createTargetInit(const LocationDescription &Loc, bool IsSPMD,
-  bool RequiresFullRuntime) {
+  bool IsSIMD, bool RequiresFullRuntime) {
   if (!updateToLocation(Loc))
 return Loc.IP;
 
   Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
   Value *Ident = getOrCreateIdent(SrcLocStr);
-  ConstantInt *IsSPMDVal = ConstantInt::getSigned(
-  IntegerType::getInt8Ty(Int8->getContext()),
-  IsSPMD ? OMP_TGT_EXEC_MODE_SPMD : OMP_TGT_EXEC_MODE_GENERIC);
+  int8_t Mode = 0;
+  if (IsSPMD)
+Mode |= OMP_TGT_EXEC_MODE_SPMD;
+  else
+Mode |= OMP_TGT_EXEC_MODE_GENERIC;
+  if (IsSIMD)
+Mode |= OMP_TGT_EXEC_MODE_SIMD;
+  ConstantInt *ModeCI =
+  ConstantInt::getSigned(IntegerType::getInt8Ty(Int8->getContext()), Mode);
   ConstantInt *UseGenericStateMachine =
   ConstantInt::getBool(Int32->getContext(), !IsSPMD);
   ConstantInt *RequiresFullRuntimeVal =
@@ -2773,7 +2779,7 @@
   omp::RuntimeFunction::OMPRTL___kmpc_target_init);
 
   CallInst *ThreadKind = Builder.CreateCall(
-  Fn, {Ident, IsSPMDVal, UseGenericStateMachine, RequiresFullRuntimeVal});
+  Fn, {Ident, ModeCI, UseGenericStateMachine, RequiresFullRuntimeVal});
 
   Value *ExecUserCode = Builder.CreateICmpEQ(
   ThreadKind, ConstantInt::get(ThreadKind->getType(), -1),
@@ -2807,23 +2813,29 @@
 }
 
 void OpenMPIRBuilder::createTargetDeinit(const LocationDescription &Loc,
- bool IsSPMD,
+ bool IsSPMD, bool IsSIMD,
  bool RequiresFullRuntime) {
   if (!updateToLocation(Loc))
 return;
 
   Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
   Value *Ident = getOrCreateIdent(SrcLocStr);
-  ConstantInt *IsSPMDVal = ConstantInt::getSigned(
-  IntegerType::getInt8Ty(Int8->getContext()),
-  IsSPMD ? OMP_TGT_EXEC_MODE_SPMD : OMP_TGT_EXEC_MODE_GENERIC);
+  int8_t Mode = 0;
+  if (IsSPMD)
+Mode |= OMP_TGT_EXEC_MODE_SPMD;
+  else
+Mode |= OMP_TGT_EXEC_MODE_GENERIC;
+  if (IsSIMD)
+Mode |= OMP_TGT_EXEC_MODE_SIMD;
+  ConstantInt *ModeCI =
+  ConstantInt::getSigned(IntegerType::getInt8Ty(Int8->getContext()), Mode);
   ConstantInt *RequiresFullRuntimeVal =
   ConstantInt::getBool(Int32->getContext(), RequiresFullRuntime);
 
   Function *Fn = getOrCreateRuntimeFunctionPtr(
   omp::RuntimeFunction::OMPRTL___kmpc_target_deinit);
 
-  Builder.CreateCall(Fn, {Ident, IsSPMDVal, RequiresFullRuntimeVal});
+  Builder.CreateCall(Fn, {Ident, ModeCI, RequiresFullRuntimeVal});
 }
 
 std::string OpenMPIRBuilder::getNameWithSeparators(ArrayRef Parts,
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1005,14 +1005,16 @@
   /// \param Loc The insert and source location description.
   /// \param IsSPMD Flag to indicate if the kernel is an SPMD kernel or not.
   /// \param RequiresFullRuntime Indicate if a full device runtime is necessary.
-  InsertPointTy createTargetInit(const LocationDescription &Loc, bool IsSPMD, bool RequiresFullRuntime);
+  InsertPointTy createTargetInit(const LocationDescription &Loc, bool IsSPMD,
+ bool IsSIMD, bool RequiresFullRuntime);
 
   /// Create a runtime call for kmpc_target_deinit
   ///
   /// \param Loc The insert and source location description.
   /// \param IsSPMD Flag to indicate if the kernel is an SPMD kernel or not.
   /// \param RequiresFullRuntime Indicate if a full device runtime is necessary.
-  void createTargetDeinit(const LocationDescription &Loc, bool IsSPMD, bool RequiresFullRuntime);
+  void createTargetDeinit(const LocationDescription &Loc, bool IsSPMD,
+  bool IsSIMD, bool RequiresFullRuntime);
 
   ///}

[PATCH] D110295: [WebAssembly] Add prototype relaxed SIMD fma/fms instructions

2021-09-22 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin accepted this revision.
aheejin added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td:14
 
 // Instructions requiring HasSIMD128 and the simd128 prefix byte
+multiclass ABSTRACT_SIMD_Ihttps://reviews.llvm.org/D110295/new/

https://reviews.llvm.org/D110295

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


[PATCH] D36850: [ThinLTO] Add norecurse function attribute propagation

2021-09-22 Thread Di Mo via Phabricator via cfe-commits
modimo added inline comments.



Comment at: clang/test/CodeGen/thinlto-funcattr-prop.ll:14
+
+; RUN: llvm-dis %t/b.bc -o - | FileCheck %s
+

tejohnson wrote:
> This is checking the summary generated by opt, not the result of the 
> llvm-lto2 run.
Fixed.



Comment at: llvm/include/llvm/IR/ModuleSummaryIndex.h:580
+// If there are calls to unknown targets (e.g. indirect)
+unsigned hasUnknownCall : 1;
+

tejohnson wrote:
> tejohnson wrote:
> > modimo wrote:
> > > tejohnson wrote:
> > > > Now that we have MayThrow, can we avoid a separate hasUnknownCall bool 
> > > > and just conservatively set MayThrow true in that case?
> > > hasUnknownCall is used for norecurse and other future flags as well to 
> > > stop propagation.
> > Ah that makes sense.
> nit, maybe change this to hasIndirectCall which I think is more specific?
My thinking is that the flag is a catch-all for blocking propagation and could 
conceivably be set for other reasons. It also matches the existing usage in 
FunctionAttrs.cpp for local propagation which also sets this for functions that 
are `OptNone`.



Comment at: llvm/include/llvm/LTO/LTO.h:26
 #include "llvm/Support/thread.h"
+#include "llvm/Transforms/IPO/FunctionAttrs.h"
 #include "llvm/Transforms/IPO/FunctionImport.h"

tejohnson wrote:
> Is this needed?
Yeah, `thinLTOPropagateFunctionAttrs` resides in FunctionAttrs.h and 
`runThinLTO` calls it to propagate.



Comment at: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp:379
   } else {
+HasUnknownCall = true;
 // Skip inline assembly calls.

tejohnson wrote:
> Should this be moved below the following checks for inline asm and direct 
> calls? (Not sure what the direct calls case is given that we handle direct 
> calls to "known functions" above though).
> 
> If it should stay where it is and treat the below cases as unknown, probably 
> should add tests for them.
Any call that isn't emitted to the summary CallGraphEdges is a hole in 
propagation knowledge.

Direct calls case is from https://reviews.llvm.org/D40056 which is handling:
```
; Test calls that aren't handled either as direct or indirect.
call void select (i1 icmp eq (i32* @global, i32* null), void ()* @f, void 
()* @g)()
```
Neat that select can be consolidated into a call, though I wonder if it should 
be allowed given it could be canonicalized to be another IR instruction above 
it and maybe eliminate this edge case. 

Tangent aside, since in all these cases the call isn't part of the static 
callgraph `HasUnknownCall` needs to be set for correctness. Tests added in 
funcattrs-prop-unknown.ll (replacing funcattrs-prop-indirect.ll since we're 
handling more than just indirect here).



Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:484
+if (!CalleeSummary->fflags().NoUnwind ||
+CallerSummary->fflags().MayThrow)
+  InferredFlags.NoUnwind = false;

tejohnson wrote:
> You've already set InferredFlags.NoUnwind to false above this loop in the 
> case where MayThrow was set on the CallerSummary.
Good catch, this case should be querying CalleeSummary MayThrow.



Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:499
+  ++NumThinLinkNoRecurse;
+  CachedAttributes[V]->setNoRecurse();
+}

tejohnson wrote:
> I think you can remove this and the below setNoUnwind() call on 
> CachedAttributes[V] since presumably this points to one of the function 
> summaries we update in the below loop.
Makes sense, removed. I like keeping the stats/debug tracking around though.



Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:537
+
+  for (Function &F : TheModule) {
+const auto &GV = DefinedGlobals.find(F.getGUID());

tejohnson wrote:
> Consider consolidating this function with thinLTOResolvePrevailingInModule, 
> to reduce the number of walks of the module and lookups into the 
> DefinedGlobals map.
Good idea, merged and renamed `thinLTOResolvePrevailingInModule` to 
`thinLTOFinalizeInModule`



Comment at: llvm/test/ThinLTO/X86/funcattrs-prop-indirect.ll:3
+; RUN: opt -thinlto-bc %s -thin-link-bitcode-file=%t1.thinlink.bc -o %t1.bc
+; RUN: llvm-lto2 run -disable-thinlto-funcattrs=0 %t1.bc -o %t.o -r 
%t1.bc,indirect,px -save-temps
+; RUN: llvm-dis -o - %t.o.1.3.import.bc | FileCheck %s

tejohnson wrote:
> Have a second version that tests with -thinlto-funcattrs-optimistic-indirect? 
> I don't see a test for that option anywhere. Or maybe just remove that option 
> - is it really needed?
Good point, option removed.



Comment at: llvm/test/ThinLTO/X86/funcattrs-prop.ll:8
+;; 1. If external, linkonce_odr or weak_odr. We capture the attributes of the 
prevailing symbol for propagation.
+;; 2. If linkonce or weak, individual calle

[PATCH] D36850: [ThinLTO] Add norecurse function attribute propagation

2021-09-22 Thread Di Mo via Phabricator via cfe-commits
modimo updated this revision to Diff 374431.
modimo marked 23 inline comments as done.
modimo added a comment.

Address feedback, rename funcattrs-prop-indirect.ll to funcattrs-prop-unknown.ll


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D36850

Files:
  clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  clang/test/CodeGen/thinlto-distributed-cfi.ll
  clang/test/CodeGen/thinlto-funcattr-prop.ll
  llvm/include/llvm/AsmParser/LLToken.h
  llvm/include/llvm/IR/GlobalValue.h
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/include/llvm/LTO/LTO.h
  llvm/include/llvm/Transforms/IPO/FunctionAttrs.h
  llvm/include/llvm/Transforms/IPO/FunctionImport.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/AsmParser/LLLexer.cpp
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/ModuleSummaryIndex.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Transforms/IPO/FunctionAttrs.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/test/Assembler/thinlto-summary.ll
  llvm/test/Bitcode/thinlto-function-summary-refgraph.ll
  llvm/test/Bitcode/thinlto-type-vcalls.ll
  llvm/test/ThinLTO/X86/deadstrip.ll
  llvm/test/ThinLTO/X86/dot-dumper.ll
  llvm/test/ThinLTO/X86/dot-dumper2.ll
  llvm/test/ThinLTO/X86/funcattrs-prop-exported-internal.ll
  llvm/test/ThinLTO/X86/funcattrs-prop-maythrow.ll
  llvm/test/ThinLTO/X86/funcattrs-prop-undefined.ll
  llvm/test/ThinLTO/X86/funcattrs-prop-unknown.ll
  llvm/test/ThinLTO/X86/funcattrs-prop-weak.ll
  llvm/test/ThinLTO/X86/funcattrs-prop.ll
  llvm/test/ThinLTO/X86/funcimport_alwaysinline.ll
  llvm/test/ThinLTO/X86/function_entry_count.ll
  llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll

Index: llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll
===
--- llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll
+++ llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll
@@ -3,15 +3,17 @@
 ; verification error.
 ; RUN: opt -module-summary %s -o %t1.bc
 ; RUN: opt -module-summary %p/Inputs/linkonce_resolution_comdat.ll -o %t2.bc
-; RUN: llvm-lto -thinlto-action=run %t1.bc %t2.bc -exported-symbol=f -exported-symbol=g -thinlto-save-temps=%t3.
+; RUN: llvm-lto -thinlto-action=run -disable-thinlto-funcattrs=0 %t1.bc %t2.bc -exported-symbol=f -exported-symbol=g -thinlto-save-temps=%t3.
 
 ; RUN: llvm-dis %t3.0.3.imported.bc -o - | FileCheck %s --check-prefix=IMPORT1
 ; RUN: llvm-dis %t3.1.3.imported.bc -o - | FileCheck %s --check-prefix=IMPORT2
 ; Copy from first module is prevailing and converted to weak_odr, copy
 ; from second module is preempted and converted to available_externally and
 ; removed from comdat.
-; IMPORT1: define weak_odr i32 @f(i8* %0) unnamed_addr comdat($c1) {
-; IMPORT2: define available_externally i32 @f(i8* %0) unnamed_addr {
+; IMPORT1: define weak_odr i32 @f(i8* %0) unnamed_addr [[ATTR:#[0-9]+]] comdat($c1) {
+; IMPORT2: define available_externally i32 @f(i8* %0) unnamed_addr [[ATTR:#[0-9]+]] {
+
+; CHECK-DAG: attributes [[ATTR]] = { norecurse nounwind }
 
 ; RUN: llvm-nm -o - < %t1.bc.thinlto.o | FileCheck %s --check-prefix=NM1
 ; NM1: W f
Index: llvm/test/ThinLTO/X86/function_entry_count.ll
===
--- llvm/test/ThinLTO/X86/function_entry_count.ll
+++ llvm/test/ThinLTO/X86/function_entry_count.ll
@@ -2,7 +2,7 @@
 ; RUN: opt -thinlto-bc %p/Inputs/function_entry_count.ll -write-relbf-to-summary -thin-link-bitcode-file=%t2.thinlink.bc -o %t2.bc
 
 ; First perform the thin link on the normal bitcode file.
-; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t.o -save-temps -thinlto-synthesize-entry-counts \
+; RUN: llvm-lto2 run %t1.bc %t2.bc -o %t.o -save-temps -disable-thinlto-funcattrs=0 -thinlto-synthesize-entry-counts \
 ; RUN: -r=%t1.bc,g, \
 ; RUN: -r=%t1.bc,f,px \
 ; RUN: -r=%t1.bc,h,px \
@@ -10,15 +10,16 @@
 ; RUN: -r=%t2.bc,g,px
 ; RUN: llvm-dis -o - %t.o.1.3.import.bc | FileCheck %s
 
-; RUN: llvm-lto -thinlto-action=run -thinlto-synthesize-entry-counts -exported-symbol=f \
+; RUN: llvm-lto -thinlto-action=run -disable-thinlto-funcattrs=0 -thinlto-synthesize-entry-counts -exported-symbol=f \
 ; RUN: -exported-symbol=g -exported-symbol=h -thinlto-save-temps=%t3. %t1.bc %t2.bc
 ; RUN: llvm-dis %t3.0.3.imported.bc -o - | FileCheck %s
 
-; CHECK: define void @h() !prof ![[PROF2:[0-9]+]]
-; CHECK: define void @f(i32{{.*}}) !prof ![[PROF1:[0-9]+]]
+; CHECK: define void @h() [[ATTR:#[0-9]+]] !prof ![[PROF2:[0-9]+]]
+; CHECK: define void @f(i32{{.*}}) [[ATTR:#[0-9]+]] !prof ![[PROF1:[0-9]+]]
 ; CHECK: define available_externally void @g() !prof ![[PROF2]]
 ; CHECK-DAG: ![[PROF1]] = !{!"synthetic_function_entry_count", i64 10}
 ; CHECK-DAG: ![[PROF2]] = !{!"synthetic_function_entry_coun

[PATCH] D109658: [X86][FP16] Change the order of the operands in complex FMA intrinsics to allow swap between the mul operands.

2021-09-22 Thread Pengfei Wang via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGebec077e07f5: [X86][FP16] Change the order of the operands 
in complex FMA intrinsics to allow… (authored by pengfei).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109658

Files:
  clang/lib/Headers/avx512fp16intrin.h
  clang/lib/Headers/avx512vlfp16intrin.h
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Target/X86/X86InstrAVX512.td
  llvm/lib/Target/X86/X86InstrFragmentsSIMD.td
  llvm/lib/Target/X86/X86InstrInfo.cpp
  llvm/lib/Target/X86/X86IntrinsicsInfo.h
  llvm/test/CodeGen/X86/avx512cfma-intrinsics.ll
  llvm/test/CodeGen/X86/avx512cfmul-intrinsics.ll
  llvm/test/CodeGen/X86/avx512cfmulsh-instrinsics.ll
  llvm/test/CodeGen/X86/avx512fp16-combine-vfmulc-fadd.ll
  llvm/test/CodeGen/X86/avx512fp16-combine-xor-vfmulc-fadd.ll
  llvm/test/CodeGen/X86/stack-folding-fp-avx512fp16.ll
  llvm/test/CodeGen/X86/stack-folding-fp-avx512fp16vl.ll

Index: llvm/test/CodeGen/X86/stack-folding-fp-avx512fp16vl.ll
===
--- llvm/test/CodeGen/X86/stack-folding-fp-avx512fp16vl.ll
+++ llvm/test/CodeGen/X86/stack-folding-fp-avx512fp16vl.ll
@@ -646,7 +646,7 @@
   ;CHECK-LABEL: stack_fold_fmaddc:
   ;CHECK:   vfmaddcph {{-?[0-9]*}}(%rsp), {{%xmm[0-9][0-9]*}}, {{%xmm[0-9][0-9]*}} {{.*#+}} 16-byte Folded Reload
   %1 = tail call <2 x i64> asm sideeffect "nop", "=x,~{xmm3},~{xmm4},~{xmm5},~{xmm6},~{xmm7},~{xmm8},~{xmm9},~{xmm10},~{xmm11},~{xmm12},~{xmm13},~{xmm14},~{xmm15},~{xmm16},~{xmm17},~{xmm18},~{xmm19},~{xmm20},~{xmm21},~{xmm22},~{xmm23},~{xmm24},~{xmm25},~{xmm26},~{xmm27},~{xmm28},~{xmm29},~{xmm30},~{xmm31},~{flags}"()
-  %2 = call <4 x float> @llvm.x86.avx512fp16.mask.vfmadd.cph.128(<4 x float> %a0, <4 x float> %a1, <4 x float> %a2, i8 -1)
+  %2 = call <4 x float> @llvm.x86.avx512fp16.mask.vfmadd.cph.128(<4 x float> %a1, <4 x float> %a2, <4 x float> %a0, i8 -1)
   ret <4 x float> %2
 }
 declare <4 x float> @llvm.x86.avx512fp16.mask.vfmadd.cph.128(<4 x float>, <4 x float>, <4 x float>, i8)
@@ -656,7 +656,7 @@
   ;CHECK:   vfmaddcph {{-?[0-9]*}}(%rsp), {{%xmm[0-9][0-9]*}}, {{%xmm[0-9][0-9]*}} {{{%k[0-7]}}} {{.*#+}} 16-byte Folded Reload
   %1 = tail call <2 x i64> asm sideeffect "nop", "=x,~{xmm2},~{xmm3},~{xmm4},~{xmm5},~{xmm6},~{xmm7},~{xmm8},~{xmm9},~{xmm10},~{xmm11},~{xmm12},~{xmm13},~{xmm14},~{xmm15},~{xmm16},~{xmm17},~{xmm18},~{xmm19},~{xmm20},~{xmm21},~{xmm22},~{xmm23},~{xmm24},~{xmm25},~{xmm26},~{xmm27},~{xmm28},~{xmm29},~{xmm30},~{xmm31},~{flags}"()
   %a0 = load <4 x float>, <4 x float>* %p
-  %2 = call <4 x float> @llvm.x86.avx512fp16.mask.vfmadd.cph.128(<4 x float> %a0, <4 x float> %a1, <4 x float> %a2, i8 %mask)
+  %2 = call <4 x float> @llvm.x86.avx512fp16.mask.vfmadd.cph.128(<4 x float> %a1, <4 x float> %a2, <4 x float> %a0, i8 %mask)
   ret <4 x float> %2
 }
 
@@ -665,7 +665,7 @@
   ;CHECK:   vfmaddcph {{-?[0-9]*}}(%rsp), {{%xmm[0-9][0-9]*}}, {{%xmm[0-9][0-9]*}} {{{%k[0-7]}}} {z} {{.*#+}} 16-byte Folded Reload
   %1 = tail call <2 x i64> asm sideeffect "nop", "=x,~{xmm2},~{xmm3},~{xmm4},~{xmm5},~{xmm6},~{xmm7},~{xmm8},~{xmm9},~{xmm10},~{xmm11},~{xmm12},~{xmm13},~{xmm14},~{xmm15},~{xmm16},~{xmm17},~{xmm18},~{xmm19},~{xmm20},~{xmm21},~{xmm22},~{xmm23},~{xmm24},~{xmm25},~{xmm26},~{xmm27},~{xmm28},~{xmm29},~{xmm30},~{xmm31},~{flags}"()
   %2 = load i8, i8* %mask
-  %3 = call <4 x float> @llvm.x86.avx512fp16.mask.vfmadd.cph.128(<4 x float> zeroinitializer, <4 x float> %a1, <4 x float> %a2, i8 %2)
+  %3 = call <4 x float> @llvm.x86.avx512fp16.mask.vfmadd.cph.128(<4 x float> %a1, <4 x float> %a2, <4 x float> zeroinitializer, i8 %2)
   ret <4 x float> %3
 }
 declare <4 x float> @llvm.x86.avx512fp16.maskz.vfmadd.cph.128(<4 x float>, <4 x float>, <4 x float>, i8)
@@ -674,7 +674,7 @@
   ;CHECK-LABEL: stack_fold_fcmaddc:
   ;CHECK:   vfcmaddcph {{-?[0-9]*}}(%rsp), {{%xmm[0-9][0-9]*}}, {{%xmm[0-9][0-9]*}} {{.*#+}} 16-byte Folded Reload
   %1 = tail call <2 x i64> asm sideeffect "nop", "=x,~{xmm3},~{xmm4},~{xmm5},~{xmm6},~{xmm7},~{xmm8},~{xmm9},~{xmm10},~{xmm11},~{xmm12},~{xmm13},~{xmm14},~{xmm15},~{xmm16},~{xmm17},~{xmm18},~{xmm19},~{xmm20},~{xmm21},~{xmm22},~{xmm23},~{xmm24},~{xmm25},~{xmm26},~{xmm27},~{xmm28},~{xmm29},~{xmm30},~{xmm31},~{flags}"()
-  %2 = call <4 x float> @llvm.x86.avx512fp16.mask.vfcmadd.cph.128(<4 x float> %a0, <4 x float> %a1, <4 x float> %a2, i8 -1)
+  %2 = call <4 x float> @llvm.x86.avx512fp16.mask.vfcmadd.cph.128(<4 x float> %a1, <4 x float> %a2, <4 x float> %a0, i8 -1)
   ret <4 x float> %2
 }
 declare <4 x float> @llvm.x86.avx512fp16.mask.vfcmadd.cph.128(<4 x float>, <4 x float>, <4 x float>, i8)
@@ -684,7 +684,7 @@
   ;CHECK:   vfcmaddcph {{-?[0-9]*}}(%rsp), {{%xmm[0-9][0-9]*}}, {{%xmm[0-9][0-9]*}} {{{%k[0-7]}}} {{.*#+}} 16-byte Folded Reload
   %1 = tail call <2 x i64> asm sid

[clang] ebec077 - [X86][FP16] Change the order of the operands in complex FMA intrinsics to allow swap between the mul operands.

2021-09-22 Thread via cfe-commits

Author: Wang, Pengfei
Date: 2021-09-23T11:02:48+08:00
New Revision: ebec077e07f5d35a870f075fb665c006978d49ea

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

LOG: [X86][FP16] Change the order of the operands in complex FMA intrinsics to 
allow swap between the mul operands.

Reviewed By: craig.topper

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

Added: 


Modified: 
clang/lib/Headers/avx512fp16intrin.h
clang/lib/Headers/avx512vlfp16intrin.h
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86InstrAVX512.td
llvm/lib/Target/X86/X86InstrFragmentsSIMD.td
llvm/lib/Target/X86/X86InstrInfo.cpp
llvm/lib/Target/X86/X86IntrinsicsInfo.h
llvm/test/CodeGen/X86/avx512cfma-intrinsics.ll
llvm/test/CodeGen/X86/avx512cfmul-intrinsics.ll
llvm/test/CodeGen/X86/avx512cfmulsh-instrinsics.ll
llvm/test/CodeGen/X86/avx512fp16-combine-vfmulc-fadd.ll
llvm/test/CodeGen/X86/avx512fp16-combine-xor-vfmulc-fadd.ll
llvm/test/CodeGen/X86/stack-folding-fp-avx512fp16.ll
llvm/test/CodeGen/X86/stack-folding-fp-avx512fp16vl.ll

Removed: 




diff  --git a/clang/lib/Headers/avx512fp16intrin.h 
b/clang/lib/Headers/avx512fp16intrin.h
index 80f22ab997243..a65247916be85 100644
--- a/clang/lib/Headers/avx512fp16intrin.h
+++ b/clang/lib/Headers/avx512fp16intrin.h
@@ -2934,8 +2934,8 @@ _mm_mask3_fnmsub_sh(__m128h __W, __m128h __X, __m128h 
__Y, __mmask8 __U) {
 static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_fcmadd_sch(__m128h __A,
__m128h __B,
__m128h __C) {
-  return (__m128h)__builtin_ia32_vfcmaddcsh_mask((__v4sf)__C, (__v4sf)__A,
- (__v4sf)__B, (__mmask8)-1,
+  return (__m128h)__builtin_ia32_vfcmaddcsh_mask((__v4sf)__A, (__v4sf)__B,
+ (__v4sf)__C, (__mmask8)-1,
  _MM_FROUND_CUR_DIRECTION);
 }
 
@@ -2943,15 +2943,15 @@ static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_mask_fcmadd_sch(__m128h __A, __mmask8 __U, __m128h __B, __m128h __C) {
   return (__m128h)__builtin_ia32_selectps_128(
   __U,
-  __builtin_ia32_vfcmaddcsh_mask((__v4sf)__C, (__v4sf)__A, (__v4sf)__B,
+  __builtin_ia32_vfcmaddcsh_mask((__v4sf)__A, (__v4sf)__B, (__v4sf)__C,
  (__mmask8)__U, _MM_FROUND_CUR_DIRECTION),
   (__v4sf)__A);
 }
 
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_maskz_fcmadd_sch(__mmask8 __U, __m128h __A, __m128h __B, __m128h __C) {
-  return (__m128h)__builtin_ia32_vfcmaddcsh_maskz((__v4sf)__C, (__v4sf)__A,
-  (__v4sf)__B, (__mmask8)__U,
+  return (__m128h)__builtin_ia32_vfcmaddcsh_maskz((__v4sf)__A, (__v4sf)__B,
+  (__v4sf)__C, (__mmask8)__U,
   _MM_FROUND_CUR_DIRECTION);
 }
 
@@ -2959,38 +2959,38 @@ static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_mask3_fcmadd_sch(__m128h __A, __m128h __B, __m128h __C, __mmask8 __U) {
   return (__m128h)_mm_move_ss((__m128)__C,
   (__m128)__builtin_ia32_vfcmaddcsh_mask(
-  (__v4sf)__C, (__v4sf)__A, (__v4sf)__B, __U,
+  (__v4sf)__A, (__v4sf)__B, (__v4sf)__C, __U,
   _MM_FROUND_CUR_DIRECTION));
 }
 
 #define _mm_fcmadd_round_sch(A, B, C, R)   
\
   ((__m128h)__builtin_ia32_vfcmaddcsh_mask(
\
-  (__v4sf)(__m128h)(C), (__v4sf)(__m128h)(A), (__v4sf)(__m128h)(B),
\
+  (__v4sf)(__m128h)(A), (__v4sf)(__m128h)(B), (__v4sf)(__m128h)(C),
\
   (__mmask8)-1, (int)(R)))
 
 #define _mm_mask_fcmadd_round_sch(A, U, B, C, R)   
\
   ((__m128h)__builtin_ia32_selectps_128(   
\
   (__mmask8)(U & 1),   
\
   __builtin_ia32_vfcmaddcsh_mask(  
\
-  (__v4sf)(__m128h)(C), (__v4sf)(__m128h)(A), (__v4sf)(__m128h)(B),
\
+  (__v4sf)(__m128h)(A), (__v4sf)(__m128h)(B), (__v4sf)(__m128h)(C),
\
   (__mmask8)(U), (int)(R)),
\
   (__v4sf)(__m128h)(A)))
 
 #define _mm_maskz_fcmadd_round_sch(U, A, B, C, R)  
\
   ((__m128h)__builtin_ia32_vfcmaddcsh_maskz(   
\
-  (__v4sf)(__m128h)(C), (__v4sf)(__m128h)(A), (__v4sf)(__m128h)(B),
\
+  (__v4sf)(__m128h)(A

[PATCH] D105092: [RISCV] (1/2) Add the tail policy argument to builtins/intrinsics.

2021-09-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

Nevermind.

LGTM




Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td:1315
  vti.RegClass:$merge, vti.RegClass:$rs2, vti.RegClass:$rs1,
- vti.Mask:$vm, GPR:$vl, vti.Log2SEW)>;
+ vti.Mask:$vm, GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>;
 

craig.topper wrote:
> This should be TAIL_UNDISTURBED. It has a $merge operand
Err nevermind. Maybe we only cared about the mask. Probably should add the 
policy to riscv_vselect_vl, but that's for another patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105092

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


[PATCH] D105092: [RISCV] (1/2) Add the tail policy argument to builtins/intrinsics.

2021-09-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper requested changes to this revision.
craig.topper added inline comments.
This revision now requires changes to proceed.



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td:1315
  vti.RegClass:$merge, vti.RegClass:$rs2, vti.RegClass:$rs1,
- vti.Mask:$vm, GPR:$vl, vti.Log2SEW)>;
+ vti.Mask:$vm, GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>;
 

This should be TAIL_UNDISTURBED. It has a $merge operand



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td:1327
  vti.RegClass:$merge, vti.RegClass:$rs2, uimm5:$imm,
- vti.Mask:$vm, GPR:$vl, vti.Log2SEW)>;
+ vti.Mask:$vm, GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>;
 

Same here



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td:1354
vti.RegClass:$merge, vti.RegClass:$rs2, ivti.RegClass:$rs1,
-   vti.Mask:$vm, GPR:$vl, vti.Log2SEW)>;
+   vti.Mask:$vm, GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>;
   }

And here



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td:1410
  vti.RegClass:$merge, vti.RegClass:$rs2, uimm5:$imm,
- vti.Mask:$vm, GPR:$vl, vti.Log2SEW)>;
+ vti.Mask:$vm, GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>;
 

And here



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td:1436
vti.RegClass:$merge, vti.RegClass:$rs2, ivti.RegClass:$rs1,
-   vti.Mask:$vm, GPR:$vl, vti.Log2SEW)>;
+   vti.Mask:$vm, GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>;
   }

And here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105092

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


[PATCH] D105092: [RISCV] (1/2) Add the tail policy argument to builtins/intrinsics.

2021-09-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105092

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


[PATCH] D110257: [CFE][Codegen] Do not break the contiguity of static allocas.

2021-09-22 Thread Mahesha S via Phabricator via cfe-commits
hsmhsm added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:102-106
+  auto *EBB = AllocaInsertPt->getParent();
+  auto Iter = AllocaInsertPt->getIterator();
+  if (Iter != EBB->end())
+++Iter;
+  Builder.SetInsertPoint(EBB, Iter);

arsenm wrote:
> hsmhsm wrote:
> > arsenm wrote:
> > > Where are the addrspacecasts inserted? Could you just adjust where those 
> > > are inserted instead?
> > The addressspace casts are inserted immediately after all static allocas 
> > (top static alloca cluster).
> > 
> > An example:
> > 
> > Before this patch:
> > 
> > ```
> > entry:
> >   %N.addr = alloca i64, align 8, addrspace(5)
> >   %N.addr.ascast = addrspacecast i64 addrspace(5)* %N.addr to i64*
> >   %vla.addr = alloca i64, align 8, addrspace(5)
> >   %vla.addr.ascast = addrspacecast i64 addrspace(5)* %vla.addr to i64*
> >   %a.addr = alloca i32*, align 8, addrspace(5)
> >   %a.addr.ascast = addrspacecast i32* addrspace(5)* %a.addr to i32**
> >   %vla.addr2 = alloca i64, align 8, addrspace(5)
> >   %vla.addr2.ascast = addrspacecast i64 addrspace(5)* %vla.addr2 to i64*
> >   %b.addr = alloca i32*, align 8, addrspace(5)
> >   %b.addr.ascast = addrspacecast i32* addrspace(5)* %b.addr to i32**
> >   %N.casted = alloca i64, align 8, addrspace(5)
> >   %N.casted.ascast = addrspacecast i64 addrspace(5)* %N.casted to i64*
> >   %.zero.addr = alloca i32, align 4, addrspace(5)
> >   %.zero.addr.ascast = addrspacecast i32 addrspace(5)* %.zero.addr to i32*
> >   %.threadid_temp. = alloca i32, align 4, addrspace(5)
> >   %.threadid_temp..ascast = addrspacecast i32 addrspace(5)* 
> > %.threadid_temp. to i32*  
> >   store i64 %N, i64* %N.addr.ascast, align 8
> > ```
> > 
> > With this patch:
> > 
> > ```
> > entry:
> >   %N.addr = alloca i64, align 8, addrspace(5)
> >   %vla.addr = alloca i64, align 8, addrspace(5)
> >   %a.addr = alloca i32*, align 8, addrspace(5)
> >   %vla.addr2 = alloca i64, align 8, addrspace(5)
> >   %b.addr = alloca i32*, align 8, addrspace(5)
> >   %N.casted = alloca i64, align 8, addrspace(5)
> >   %.zero.addr = alloca i32, align 4, addrspace(5)
> >   %.threadid_temp. = alloca i32, align 4, addrspace(5)
> >   %.threadid_temp..ascast = addrspacecast i32 addrspace(5)* 
> > %.threadid_temp. to i32*
> >   %.zero.addr.ascast = addrspacecast i32 addrspace(5)* %.zero.addr to i32*
> >   %N.casted.ascast = addrspacecast i64 addrspace(5)* %N.casted to i64*
> >   %b.addr.ascast = addrspacecast i32* addrspace(5)* %b.addr to i32**
> >   %vla.addr2.ascast = addrspacecast i64 addrspace(5)* %vla.addr2 to i64*
> >   %a.addr.ascast = addrspacecast i32* addrspace(5)* %a.addr to i32**
> >   %vla.addr.ascast = addrspacecast i64 addrspace(5)* %vla.addr to i64*
> >   %N.addr.ascast = addrspacecast i64 addrspace(5)* %N.addr to i64*
> >   store i64 %N, i64* %N.addr.ascast, align 8
> > ```
> I meant where in the clang code are these emitted, and how is that I set 
> point found?
I understand your question as - where exactly is code emitted? 

It is Clang Codegen part, the Clang Codegen maintains a builder (function 
specific?) which builds and emits code, and builder always maintains default 
current insertion position, and it can also be asked to insert at some other 
place by calling the api SetInsertPoint().

In this particular case, the addrespace casts are  emitted at (by calling the 
builder) 
https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/TargetInfo.cpp#445

All I am doing here is - direct the builder to insert addrespace casts just 
after all static allocas by appropriately setting the insert position via 
SetInsertPoint().


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110257

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


[PATCH] D109658: [X86][FP16] Change the order of the operands in complex FMA intrinsics to allow swap between the mul operands.

2021-09-22 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added a comment.

Thanks Craig!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109658

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


[PATCH] D110257: [CFE][Codegen] Do not break the contiguity of static allocas.

2021-09-22 Thread Mahesha S via Phabricator via cfe-commits
hsmhsm updated this revision to Diff 374419.
hsmhsm added a comment.

Update source comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110257

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/test/CodeGenCUDA/builtins-amdgcn.cu
  clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  clang/test/CodeGenCXX/amdgcn-func-arg.cpp
  clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
  clang/test/CodeGenCXX/vla.cpp
  clang/test/CodeGenSYCL/address-space-deduction.cpp
  clang/test/OpenMP/amdgcn_target_init_temp_alloca.cpp
  clang/test/OpenMP/distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/nvptx_allocate_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_teams_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/parallel_if_codegen.cpp
  clang/test/OpenMP/parallel_if_codegen_PR51349.cpp
  clang/test/OpenMP/parallel_master_taskloop_codegen.cpp
  clang/test/OpenMP/parallel_master_taskloop_simd_codegen.cpp
  clang/test/OpenMP/target_codegen_global_capture.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_parallel_if_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/task_codegen.c
  clang/test/OpenMP/teams_distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/vla_crash.c

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


[PATCH] D109658: [X86][FP16] Change the order of the operands in complex FMA intrinsics to allow swap between the mul operands.

2021-09-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109658

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


[PATCH] D110257: [CFE][Codegen] Do not break the contiguity of static allocas.

2021-09-22 Thread Mahesha S via Phabricator via cfe-commits
hsmhsm added a comment.

In D110257#3016113 , @rnk wrote:

> In D110257#3015641 , @hsmhsm wrote:
>
>> The logic at 
>> https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Utils/InlineFunction.cpp#L2093
>>  assumes that static allocas (within callee) are contiguous.
>
> No, it doesn't make that assumption. That code is an attempt to optimize the 
> linked list splicing, so that batches of contiguous allocas can be spliced 
> over together. I believe the code would still be correct if you removed this 
> inner loop and left behind the outer loop, which iterates over all allocas in 
> the entry block.

Thanks, understood it now. So, the actual logic (in the outer loop) is - scan 
the (contiguous ) batches of static allocas within the callees entry block, and 
move those batches to caller as one chunk at a time.

That said, it is still good idea (and actually an explicitly not mandated 
requirement) to maintain the contiguity of the static allocas at the top of the 
basic block as one cluster, and it should start from FE itself.  So, this patch 
is still relevant.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110257

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


[PATCH] D109658: [X86][FP16] Change the order of the operands in complex FMA intrinsics to allow swap between the mul operands.

2021-09-22 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added a comment.

By the way, we synced with GCC and we are using the same order in the builtins 
now. 
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=db3b96df03fdbe2fb770729501e2e9b65e66c2da;hp=ed643e9f171e99b0aa1453b3f29ed1103e9b5c80
We still have some different builtin names due to historical reasons, e.g. 
`__builtin_ia32_vfmulcsh_mask_round` (gcc), `__builtin_ia32_vfcmulcsh_mask` 
(llvm). I think it's OK for now.
Can we let this patch in? I will solve the multi evaluation problem in another 
patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109658

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


[PATCH] D110280: [modules] Fix IRGen assertion on accessing ObjC ivar inside a method.

2021-09-22 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Hmm.  It sounds like we misbehave if we're working with a non-canonical ivar.  
While it does seem preferable in general for lookups done after merging modules 
to return the canonical ivar, I'm not sure we can rely on the AST only having 
references to that ivar, since e.g. there might be references to non-canonical 
ivars in static/inline functions in the modules that declare them.  So while 
this seems like a good change  in the abstract — although maybe we should just 
be doing the lookup in the canonical definition in the first place? — it also 
might not be enough, and the record-layout code might just need to properly 
handle non-canonical ivars.




Comment at: clang/lib/AST/DeclObjC.cpp:81-84
   lookup_result R = lookup(Id);
   for (lookup_iterator Ivar = R.begin(), IvarEnd = R.end();
Ivar != IvarEnd; ++Ivar) {
+if (auto *ivar = dyn_cast((*Ivar)->getCanonicalDecl()))

vsapsai wrote:
> Don't really know what are the common patterns for name lookup and if this 
> approach is acceptable. For C we call `LookupResult::resolveKind` to deal 
> with multiple decls (and to avoid ambiguous lookup errors) but that's not 
> available for `lookup_result` (aka `DeclContextLookupResult`).
I think this is fine given the specific constraints on this lookup and on 
well-formed `@interface` declarations.



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:3354
+  if (auto *OID = dyn_cast(DC))
+return OID->getDefinition();
+

This is fine if this function is only ever called when there's actually a known 
member of the ID, which I  think is true.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110280

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


[PATCH] D109658: [X86][FP16] Change the order of the operands in complex FMA intrinsics to allow swap between the mul operands.

2021-09-22 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/lib/Headers/avx512fp16intrin.h:2972
 #define _mm_mask_fcmadd_round_sch(A, U, B, C, R)   
\
   ((__m128h)__builtin_ia32_selectps_128(   
\
   (__mmask8)(U & 1),   
\

craig.topper wrote:
> pengfei wrote:
> > craig.topper wrote:
> > > Why is this intrinsic written like this? We can't evaluate macro 
> > > arguments like A and U twice. It can cause surprising results.
> > Thanks Craig! You are right, we can't evaluate them twice. But we have to 
> > use them twice, because we want to provide user the same functionality as 
> > former FMA intrinsics. Maybe we need to define and use temp variables.
> Is it possible to just have single builtin call and create all the IR from 
> CGBuiltin?
Yeah, that's a good idea. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109658

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


[PATCH] D109658: [X86][FP16] Change the order of the operands in complex FMA intrinsics to allow swap between the mul operands.

2021-09-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Headers/avx512fp16intrin.h:2972
 #define _mm_mask_fcmadd_round_sch(A, U, B, C, R)   
\
   ((__m128h)__builtin_ia32_selectps_128(   
\
   (__mmask8)(U & 1),   
\

pengfei wrote:
> craig.topper wrote:
> > Why is this intrinsic written like this? We can't evaluate macro arguments 
> > like A and U twice. It can cause surprising results.
> Thanks Craig! You are right, we can't evaluate them twice. But we have to use 
> them twice, because we want to provide user the same functionality as former 
> FMA intrinsics. Maybe we need to define and use temp variables.
Is it possible to just have single builtin call and create all the IR from 
CGBuiltin?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109658

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


[PATCH] D109658: [X86][FP16] Change the order of the operands in complex FMA intrinsics to allow swap between the mul operands.

2021-09-22 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/lib/Headers/avx512fp16intrin.h:2972
 #define _mm_mask_fcmadd_round_sch(A, U, B, C, R)   
\
   ((__m128h)__builtin_ia32_selectps_128(   
\
   (__mmask8)(U & 1),   
\

craig.topper wrote:
> Why is this intrinsic written like this? We can't evaluate macro arguments 
> like A and U twice. It can cause surprising results.
Thanks Craig! You are right, we can't evaluate them twice. But we have to use 
them twice, because we want to provide user the same functionality as former 
FMA intrinsics. Maybe we need to define and use temp variables.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109658

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


[PATCH] D110089: [CUDA] Implement experimental support for texture lookups.

2021-09-22 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 374405.
tra added a comment.

Removed a test file committed by mistake.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110089

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_cuda_runtime_wrapper.h
  clang/lib/Headers/__clang_cuda_texture_intrinsics.h

Index: clang/lib/Headers/__clang_cuda_texture_intrinsics.h
===
--- /dev/null
+++ clang/lib/Headers/__clang_cuda_texture_intrinsics.h
@@ -0,0 +1,741 @@
+/*===--- __clang_cuda_texture_intrinsics.h - Device-side texture support ---===
+ *
+ * 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
+ *
+ *===---===
+ *
+ * This header provides in-header implmentations for NVCC's built-in
+ * __nv_tex_surf_handler() which is used by CUDA's texture-related headers.  The
+ * built-in is unusual as it's actually a set of function overloads that use the
+ * first string literal argument as one of the overload parameters. We can not
+ * implement is directly with C++. Instead, we convert the string literal into a
+ * numberic value and use that to parametrize the implementations.
+ */
+#ifndef __CLANG_CUDA_TEXTURE_INTRINSICS_H__
+#define __CLANG_CUDA_TEXTURE_INTRINSICS_H__
+#ifndef __CUDA__
+#error "This file is for CUDA compilation only."
+#endif
+
+#include 
+
+// __nv_tex_surf_handler() provided by this header as a macro.
+#define __nv_tex_surf_handler(__op, __ptr, ...)\
+  __cuda_tex::__tex_fetch<__cuda_tex::__Tag<__cuda_tex::__tex_op_hash(__op)>>( \
+  __ptr, __VA_ARGS__)
+
+#pragma push_macro("__Args")
+#pragma push_macro("__ID")
+#pragma push_macro("__ID")
+#pragma push_macro("__IDV")
+#pragma push_macro("__IMPL_2DGATHER")
+#pragma push_macro("__IMPL_ALIAS")
+#pragma push_macro("__IMPL_ALIASI")
+#pragma push_macro("__IMPL_F1")
+#pragma push_macro("__IMPL_F3")
+#pragma push_macro("__IMPL_F3N")
+#pragma push_macro("__IMPL_F3S")
+#pragma push_macro("__IMPL_S")
+#pragma push_macro("__IMPL_S3")
+#pragma push_macro("__IMPL_S3I")
+#pragma push_macro("__IMPL_S3N")
+#pragma push_macro("__IMPL_S3NI")
+#pragma push_macro("__IMPL_S3S")
+#pragma push_macro("__IMPL_S3SI")
+#pragma push_macro("__IMPL_SI")
+#pragma push_macro("__L")
+#pragma push_macro("__STRIP_PARENS")
+#pragma push_macro("__ASM_OUT")
+#pragma push_macro("__ASM_OUTP")
+
+// Put all functions into anonymous namespace so they have internal linkage.
+namespace {
+
+// Put the implmentation into its own namespace so we don't pollute the TU.
+namespace __cuda_tex {
+
+// First, we need a perfect hash function and a few constexpr helper functions
+// for converting a string literal into a numeric value which can be used to
+// parametrize a template. We can not use string literals for that as that would
+// require C++20.
+//
+// The hash function was generated with 'gperf' and then manually converted into
+// its constexpr equivalent.
+//
+// NOTE: the perfect hashing scheme comes with inherent self-test. If the hash
+// function has a collision for any of the texture operations, the compilation
+// will fail due to an attempt to redefine a tag with the same value. If the
+// header compiles, then the hash function is good enough for the job.
+
+constexpr size_t __tex_len(const char *s) {
+  return (s[0] == 0)? 0
+ : (s[1] == 0)  ? 1
+ : (s[2] == 0)  ? 2
+ : (s[3] == 0)  ? 3
+ : (s[4] == 0)  ? 4
+ : (s[5] == 0)  ? 5
+ : (s[6] == 0)  ? 6
+ : (s[7] == 0)  ? 7
+ : (s[8] == 0)  ? 8
+ : (s[9] == 0)  ? 9
+ : (s[10] == 0) ? 10
+ : (s[11] == 0) ? 11
+ : (s[12] == 0) ? 12
+ : (s[13] == 0) ? 13
+ : (s[14] == 0) ? 14
+ : (s[15] == 0) ? 15
+ : (s[16] == 0) ? 16
+ : (s[17] == 0) ? 17
+ : (s[18] == 0) ? 18
+ : (s[19] == 0) ? 19
+ : (s[20] == 0) ? 20
+ : (s[21] == 0) ? 21
+ : (s[22] == 0) ? 22
+ : (s[23] == 0) ? 23
+ : (s[24] == 0) ? 24
+ : (s[25] == 0) ? 25
+ : (s[26] == 0) ? 26
+ : (s[27] == 0) ? 27
+ : (s[28] == 0) ? 28
+ : (s[29] == 0) ? 29
+ : (s[30] == 0) ? 30
+ : (s[31] == 0) ? 31
+: 32;
+}
+
+constexpr unsigned char __tex_hash_map(unsigned char c) {
+  return (c == 49)? 10
+ : (c == 50)  ? 0
+ : (c == 51)  ? 100
+ : (c == 52)  ? 30
+ : (c == 67)  ? 10
+ : (c == 68)  ? 0
+ : (c == 69)  ? 25
+ : (c == 72)  ? 70
+ : (c == 77)  ? 0
+ : (c == 96)  ? 44
+ : (c == 99)  ? 10
+ : (c == 100) ? 5
+ : (c == 101) ? 60

[PATCH] D110089: [CUDA] Implement experimental support for texture lookups.

2021-09-22 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 374404.
tra added a comment.

Cleanups. Added more comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110089

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_cuda_runtime_wrapper.h
  clang/lib/Headers/__clang_cuda_texture_intrinsics.h
  clang/test/CodeGenCUDA/texture_intrinsics.cu

Index: clang/test/CodeGenCUDA/texture_intrinsics.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/texture_intrinsics.cu
@@ -0,0 +1,170 @@
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+//
+// RUN: %clang -target x86_64-linux -nocudainc -nocudalib --cuda-gpu-arch=sm_86 --cuda-device-only -S %s
+// RUN: %clang -target x86_64-linux -nocudainc -nocudalib --cuda-gpu-arch=sm_86 --cuda-host-only -S %s
+
+// Define bare minimum required for parsing the header file.
+#include "Inputs/cuda.h"
+
+struct float4 {
+  float x,y,z,w;
+};
+struct float2 {
+  float x,y;
+};
+struct int4 {
+  int x,y,z,w;
+};
+struct int2 {
+  int x,y;
+};
+using uint = unsigned int;
+struct uint4 {
+  uint x,y,z,w;
+};
+struct uint2 {
+  uint x,y;
+};
+using ushort = unsigned short;
+using cudaTextureObject_t = unsigned long long;
+
+enum cudaTextureReadMode {
+  cudaReadModeNormalizedFloat,
+  cudaReadModeElementType
+};
+enum {
+  cudaTextureType1D,
+  cudaTextureType2D,
+  cudaTextureType3D,
+  cudaTextureTypeCubemap,
+  cudaTextureType1DLayered,
+  cudaTextureType2DLayered,
+  cudaTextureTypeCubemapLayered
+};
+struct textureReference {
+};
+template 
+struct __attribute__((device_builtin_texture_type)) texture : public textureReference {
+};
+
+#include <__clang_cuda_texture_intrinsics.h>
+
+int CheckHashValues() { return 0;}
+template  int CheckHashValues(const char *first, Args... args) {
+  return __cuda_tex::__tex_hash(fisrt) + CheckHashValues(args...);
+}
+
+int CheckHashValuesTest() {
+  return
+}
+#if 0
+__isurf1DLayeredread
+__isurf1DLayeredwrite_v2
+__isurf1Dread
+__isurf1Dwrite_v2
+__isurf2DLayeredread
+__isurf2DLayeredwrite_v2
+__isurf2Dread
+__isurf2Dwrite_v2
+__isurf3Dread
+__isurf3Dwrite_v2
+__isurfCubemapLayeredread
+__isurfCubemapLayeredwrite_v2
+__isurfCubemapread
+__isurfCubemapwrite_v2
+__itex1D
+__itex1DGrad
+__itex1DLayered
+__itex1DLayeredGrad
+__itex1DLayeredLod
+__itex1DLod
+__itex1Dfetch
+__itex2D
+__itex2DGrad_sparse
+__itex2DGrad_v2
+__itex2DLayered
+__itex2DLayeredGrad_sparse
+__itex2DLayeredGrad_v2
+__itex2DLayeredLod
+__itex2DLayeredLod_sparse
+__itex2DLayered_sparse
+__itex2DLod
+__itex2DLod_sparse
+__itex2D_sparse
+__itex2Dgather
+__itex2Dgather_sparse
+__itex3D
+__itex3DGrad_sparse
+__itex3DGrad_v2
+__itex3DLod
+__itex3DLod_sparse
+__itex3D_sparse
+__itexCubemap
+__itexCubemapGrad_v2
+__itexCubemapLayered
+__itexCubemapLayeredGrad_v2
+__itexCubemapLayeredLod
+__itexCubemapLod
+__surf1DLayeredread_v2
+__surf1DLayeredwrite_v2
+__surf1Dread_v2
+__surf1Dwrite_v2
+__surf2DLayeredread_v2
+__surf2DLayeredwrite_v2
+__surf2Dread_v2
+__surf2Dwrite_v2
+__surf3Dread_v2
+__surf3Dwrite_v2
+__surfCubemapLayeredread_v2
+__surfCubemapLayeredwrite_v2
+__surfCubemapread_v2
+__surfCubemapwrite_v2
+__tex1DGrad_rmnf_v2
+__tex1DGrad_v2
+__tex1DLayeredGrad_rmnf_v2
+__tex1DLayeredGrad_v2
+__tex1DLayeredLod_rmnf_v2
+__tex1DLayeredLod_v2
+__tex1DLayered_rmnf_v2
+__tex1DLayered_v2
+__tex1DLod_rmnf_v2
+__tex1DLod_v2
+__tex1D_rmnf_v2
+__tex1D_v2
+__tex1Dfetch_rmnf_v2
+__tex1Dfetch_v2
+__tex2DGrad_rmnf_v2
+__tex2DGrad_v2
+__tex2DLayeredGrad_rmnf_v2
+__tex2DLayeredGrad_v2
+__tex2DLayeredLod_rmnf_v2
+__tex2DLayeredLod_v2
+__tex2DLayered_rmnf_v2
+__tex2DLayered_v2
+__tex2DLod_rmnf_v2
+__tex2DLod_v2
+__tex2D_rmnf_v2
+__tex2D_v2
+__tex2Dgather_rmnf_v2
+__tex2Dgather_v2
+__tex3DGrad_rmnf_v2
+__tex3DGrad_v2
+__tex3DLod_rmnf_v2
+__tex3DLod_v2
+__tex3D_rmnf_v2
+__tex3D_v2
+__texCubemapGrad_rmnf_v2
+__texCubemapGrad_v2
+__texCubemapLayeredGrad_rmnf_v2
+__texCubemapLayeredGrad_v2
+__texCubemapLayeredLod_rmnf_v2
+__texCubemapLayeredLod_v2
+__texCubemapLayered_rmnf_v2
+__texCubemapLayered_v2
+__texCubemapLod_rmnf_v2
+__texCubemapLod_v2
+__texCubemap_rmnf_v2
+__texCubemap_v2
+
+#endif
Index: clang/lib/Headers/__clang_cuda_texture_intrinsics.h
===
--- /dev/null
+++ clang/lib/Headers/__clang_cuda_texture_intrinsics.h
@@ -0,0 +1,741 @@
+/*===--- __clang_cuda_texture_intrinsics.h - Device-side texture support ---===
+ *
+ * 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
+ *
+ *===---===
+ *
+ * This header provides in-header implmentations for NVCC's built-in
+ * __nv_tex_surf_handler() which is used by CUDA's texture-related headers.  The
+ * built-in i

[PATCH] D109625: [compiler-rt] Ensure required deps for tests targets are actually built

2021-09-22 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added inline comments.



Comment at: compiler-rt/test/CMakeLists.txt:48
+  if (NOT TARGET ${dep})
+llvm_ExternalProject_BuildCmd(build_${dep} ${dep} ${BINARY_DIR})
+add_custom_target(${dep}

leonardchan wrote:
> phosek wrote:
> > This is going to run Ninja in the LLVM build once for each dependency 
> > listed above, correct? That seems quite expensive.
> > 
> > We already pass most of these to the child build via corresponding CMake 
> > variables, see 
> > https://github.com/llvm/llvm-project/blob/ed921282e551f2252ccfcbddd7a85ad8a006ed3f/llvm/cmake/modules/LLVMExternalProjectUtils.cmake#L160
> > 
> > For example, if just need some readelf implementation and not necessarily 
> > llvm-readelf, it may be better to use the value of `CMAKE_READELF` and 
> > propagate that down to tests through substitution (that is wherever the 
> > tests invoke `llvm-readelf`, we would replace it with `%readelf`).
> > 
> > We're still going to need this logic for tools where there's no 
> > corresponding CMake variable like `FileCheck` but it should be 
> > significantly fewer ones.
> So it looks like only FileCheck, count, and not are required but don't have 
> cmake variables. Would what I have now be ok where instead we just iterate 
> over a trimmed list of tools?
I lied, there's also clang-resource-headers and llvm-readelf.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109625

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


[PATCH] D109625: [compiler-rt] Ensure required deps for tests targets are actually built

2021-09-22 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 374396.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109625

Files:
  compiler-rt/test/CMakeLists.txt


Index: compiler-rt/test/CMakeLists.txt
===
--- compiler-rt/test/CMakeLists.txt
+++ compiler-rt/test/CMakeLists.txt
@@ -1,5 +1,6 @@
 # Needed for lit support in standalone builds.
 include(AddLLVM)
+include(LLVMExternalProjectUtils)
 
 option(COMPILER_RT_TEST_STANDALONE_BUILD_LIBS
   "When set to ON and testing in a standalone build, test the runtime \
@@ -28,14 +29,34 @@
 # When ANDROID, we build tests with the host compiler (i.e. CMAKE_C_COMPILER),
 # and run tests with tools from the host toolchain.
 if(NOT ANDROID)
-  if(NOT COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD)
-# Use LLVM utils and Clang from the same build tree.
-list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS
+  set(LIT_TEST_DEPS
   clang clang-resource-headers FileCheck count not llvm-config llvm-nm 
llvm-objdump
   llvm-readelf llvm-readobj llvm-size llvm-symbolizer compiler-rt-headers 
sancov)
-if (WIN32)
-  list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS KillTheDoctor)
-endif()
+  if (WIN32)
+list(APPEND LIT_TEST_DEPS KillTheDoctor)
+  endif()
+
+  if(NOT COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD)
+# Use LLVM utils and Clang from the same build tree.
+list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS ${LIT_TEST_DEPS})
+  elseif(COMPILER_RT_STANDALONE_BUILD)
+# If we are making a standalone build, we need to ensure some targets used
+# for testing are known and built as deps.
+list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS ${LIT_TEST_DEPS})
+
+# These are tools needed for testing in a standalone/runtimes build, but we
+# don't have a corresponding CMAKE_* flag for. These will need to be 
rebuilt.
+set(LIT_ONLY_TOOLS
+FileCheck count not clang-resource-headers llvm-readelf)
+foreach(dep ${LIT_ONLY_TOOLS})
+  if (NOT TARGET ${dep})
+llvm_ExternalProject_BuildCmd(build_${dep} ${dep} ${BINARY_DIR})
+add_custom_target(${dep}
+  COMMAND ${build_${dep}}
+  WORKING_DIRECTORY ${BINARY_DIR}
+  VERBATIM USES_TERMINAL)
+  endif()
+endforeach()
   endif()
   # Tests use C++ standard library headers.
   if (TARGET cxx-headers OR HAVE_LIBCXX)


Index: compiler-rt/test/CMakeLists.txt
===
--- compiler-rt/test/CMakeLists.txt
+++ compiler-rt/test/CMakeLists.txt
@@ -1,5 +1,6 @@
 # Needed for lit support in standalone builds.
 include(AddLLVM)
+include(LLVMExternalProjectUtils)
 
 option(COMPILER_RT_TEST_STANDALONE_BUILD_LIBS
   "When set to ON and testing in a standalone build, test the runtime \
@@ -28,14 +29,34 @@
 # When ANDROID, we build tests with the host compiler (i.e. CMAKE_C_COMPILER),
 # and run tests with tools from the host toolchain.
 if(NOT ANDROID)
-  if(NOT COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD)
-# Use LLVM utils and Clang from the same build tree.
-list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS
+  set(LIT_TEST_DEPS
   clang clang-resource-headers FileCheck count not llvm-config llvm-nm llvm-objdump
   llvm-readelf llvm-readobj llvm-size llvm-symbolizer compiler-rt-headers sancov)
-if (WIN32)
-  list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS KillTheDoctor)
-endif()
+  if (WIN32)
+list(APPEND LIT_TEST_DEPS KillTheDoctor)
+  endif()
+
+  if(NOT COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD)
+# Use LLVM utils and Clang from the same build tree.
+list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS ${LIT_TEST_DEPS})
+  elseif(COMPILER_RT_STANDALONE_BUILD)
+# If we are making a standalone build, we need to ensure some targets used
+# for testing are known and built as deps.
+list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS ${LIT_TEST_DEPS})
+
+# These are tools needed for testing in a standalone/runtimes build, but we
+# don't have a corresponding CMAKE_* flag for. These will need to be rebuilt.
+set(LIT_ONLY_TOOLS
+FileCheck count not clang-resource-headers llvm-readelf)
+foreach(dep ${LIT_ONLY_TOOLS})
+  if (NOT TARGET ${dep})
+llvm_ExternalProject_BuildCmd(build_${dep} ${dep} ${BINARY_DIR})
+add_custom_target(${dep}
+  COMMAND ${build_${dep}}
+  WORKING_DIRECTORY ${BINARY_DIR}
+  VERBATIM USES_TERMINAL)
+  endif()
+endforeach()
   endif()
   # Tests use C++ standard library headers.
   if (TARGET cxx-headers OR HAVE_LIBCXX)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110295: [WebAssembly] Add prototype relaxed SIMD fma/fms instructions

2021-09-22 Thread Ng Zhi An via Phabricator via cfe-commits
ngzhian accepted this revision.
ngzhian added a comment.
This revision is now accepted and ready to land.

The binary opcodes LGTM, not too sure about the tablegen stuff, tests look good 
too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110295

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


[PATCH] D110295: [WebAssembly] Add prototype relaxed SIMD fma/fms instructions

2021-09-22 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: aheejin, ngzhian.
Herald added subscribers: wingo, ecnelises, sunfish, hiraditya, 
jgravelle-google, sbc100, dschuff.
tlively requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Add experimental clang builtins, LLVM intrinsics, and backend definitions for
the new {f32x4,f64x2}.{fma,fms} instructions in the relaxed SIMD proposal:
https://github.com/WebAssembly/relaxed-simd/blob/main/proposals/relaxed-simd/Overview.md.
Do not allow these instructions to be selected without explicit user opt-in.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110295

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c
  llvm/include/llvm/IR/IntrinsicsWebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
  llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
  llvm/test/MC/WebAssembly/simd-encodings.s

Index: llvm/test/MC/WebAssembly/simd-encodings.s
===
--- llvm/test/MC/WebAssembly/simd-encodings.s
+++ llvm/test/MC/WebAssembly/simd-encodings.s
@@ -1,4 +1,4 @@
-# RUN: llvm-mc -no-type-check -show-encoding -triple=wasm32-unknown-unknown -mattr=+simd128 < %s | FileCheck %s
+# RUN: llvm-mc -no-type-check -show-encoding -triple=wasm32-unknown-unknown -mattr=+simd128,+relaxed-simd < %s | FileCheck %s
 
 main:
 .functype main () -> ()
@@ -779,4 +779,16 @@
 # CHECK: f64x2.convert_low_i32x4_u # encoding: [0xfd,0xff,0x01]
 f64x2.convert_low_i32x4_u
 
+# CHECK: f32x4.fma # encoding: [0xfd,0xaf,0x01]
+f32x4.fma
+
+# CHECK: f32x4.fms # encoding: [0xfd,0xb0,0x01]
+f32x4.fms
+
+# CHECK: f64x2.fma # encoding: [0xfd,0xcf,0x01]
+f64x2.fma
+
+# CHECK: f64x2.fms # encoding: [0xfd,0xd0,0x01]
+f64x2.fms
+
 end_function
Index: llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
===
--- llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
+++ llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll
@@ -1,5 +1,5 @@
-; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 | FileCheck %s --check-prefixes=CHECK,SLOW
-; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 -fast-isel | FileCheck %s
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128,+relaxed-simd | FileCheck %s --check-prefixes=CHECK,SLOW
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128,+relaxed-simd -fast-isel | FileCheck %s
 
 ; Test that SIMD128 intrinsics lower as expected. These intrinsics are
 ; only expected to lower successfully if the simd128 attribute is
@@ -600,6 +600,30 @@
   ret <4 x float> %v
 }
 
+; CHECK-LABEL: fma_v4f32:
+; CHECK-NEXT: .functype fma_v4f32 (v128, v128, v128) -> (v128){{$}}
+; CHECK-NEXT: f32x4.fma $push[[R:[0-9]+]]=, $0, $1, $2{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+declare <4 x float> @llvm.wasm.fma.v4f32(<4 x float>, <4 x float>, <4 x float>)
+define <4 x float> @fma_v4f32(<4 x float> %a, <4 x float> %b, <4 x float> %c) {
+  %v = call <4 x float> @llvm.wasm.fma.v4f32(
+<4 x float> %a, <4 x float> %b, <4 x float> %c
+  )
+  ret <4 x float> %v
+}
+
+; CHECK-LABEL: fms_v4f32:
+; CHECK-NEXT: .functype fms_v4f32 (v128, v128, v128) -> (v128){{$}}
+; CHECK-NEXT: f32x4.fms $push[[R:[0-9]+]]=, $0, $1, $2{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+declare <4 x float> @llvm.wasm.fms.v4f32(<4 x float>, <4 x float>, <4 x float>)
+define <4 x float> @fms_v4f32(<4 x float> %a, <4 x float> %b, <4 x float> %c) {
+  %v = call <4 x float> @llvm.wasm.fms.v4f32(
+<4 x float> %a, <4 x float> %b, <4 x float> %c
+  )
+  ret <4 x float> %v
+}
+
 ; ==
 ; 2 x f64
 ; ==
@@ -674,3 +698,27 @@
   %v = call <2 x double> @llvm.nearbyint.v2f64(<2 x double> %a)
   ret <2 x double> %v
 }
+
+; CHECK-LABEL: fma_v2f64:
+; CHECK-NEXT: .functype fma_v2f64 (v128, v128, v128) -> (v128){{$}}
+; CHECK-NEXT: f64x2.fma $push[[R:[0-9]+]]=, $0, $1, $2{{$}}
+; CHECK-NEXT: return $pop[[R]]{{$}}
+declare <2 x double> @llvm.wasm.fma.v2f64(<2 x double>, <2 x double>, <2 x double>)
+define <2 x double> @fma_v2f64(<2 x double> %a, <2 x double> %b, <2 x double> %c) {
+  %v = call <2 x double> @llvm.wasm.fma.v2f64(
+<2 x double> %a, <2 x double> %b, <2 x double> %c
+  )
+  ret 

[PATCH] D107647: [PowerPC] MMA - Add __builtin_vsx_build_pair and __builtin_mma_build_acc builtins

2021-09-22 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai accepted this revision.
nemanjai added a comment.

LGTM other than the code can be simplified as suggested.




Comment at: clang/lib/CodeGen/CGBuiltin.cpp:15888-15895
+SmallVector RevOps;
+unsigned NumVecs =
+(BuiltinID == PPC::BI__builtin_mma_build_acc) ? 4 : 2;
+for (unsigned i = NumVecs; i > 0; --i)
+  RevOps.push_back(Ops[i]);
+for (unsigned i = 1; i <= NumVecs; ++i)
+  Ops[i] = RevOps[i - 1];

This entire block seems to simply be `std::reverse(Ops.begin() + 1, Ops.end())`

Also, please add a note that the very first operand is the pointer to the 
pair/accumulator that is actually being built.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107647

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


[PATCH] D109625: [compiler-rt] Ensure required deps for tests targets are actually built

2021-09-22 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added inline comments.



Comment at: compiler-rt/test/CMakeLists.txt:48
+  if (NOT TARGET ${dep})
+llvm_ExternalProject_BuildCmd(build_${dep} ${dep} ${BINARY_DIR})
+add_custom_target(${dep}

phosek wrote:
> This is going to run Ninja in the LLVM build once for each dependency listed 
> above, correct? That seems quite expensive.
> 
> We already pass most of these to the child build via corresponding CMake 
> variables, see 
> https://github.com/llvm/llvm-project/blob/ed921282e551f2252ccfcbddd7a85ad8a006ed3f/llvm/cmake/modules/LLVMExternalProjectUtils.cmake#L160
> 
> For example, if just need some readelf implementation and not necessarily 
> llvm-readelf, it may be better to use the value of `CMAKE_READELF` and 
> propagate that down to tests through substitution (that is wherever the tests 
> invoke `llvm-readelf`, we would replace it with `%readelf`).
> 
> We're still going to need this logic for tools where there's no corresponding 
> CMake variable like `FileCheck` but it should be significantly fewer ones.
So it looks like only FileCheck, count, and not are required but don't have 
cmake variables. Would what I have now be ok where instead we just iterate over 
a trimmed list of tools?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109625

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


[PATCH] D109625: [compiler-rt] Ensure required deps for tests targets are actually built

2021-09-22 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 374393.
leonardchan retitled this revision from "[compiler-rt] Ensure LIT_TEST_DEP 
targets are actually built" to "[compiler-rt] Ensure required deps for tests 
targets are actually built".

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109625

Files:
  compiler-rt/test/CMakeLists.txt


Index: compiler-rt/test/CMakeLists.txt
===
--- compiler-rt/test/CMakeLists.txt
+++ compiler-rt/test/CMakeLists.txt
@@ -1,5 +1,6 @@
 # Needed for lit support in standalone builds.
 include(AddLLVM)
+include(LLVMExternalProjectUtils)
 
 option(COMPILER_RT_TEST_STANDALONE_BUILD_LIBS
   "When set to ON and testing in a standalone build, test the runtime \
@@ -28,14 +29,34 @@
 # When ANDROID, we build tests with the host compiler (i.e. CMAKE_C_COMPILER),
 # and run tests with tools from the host toolchain.
 if(NOT ANDROID)
-  if(NOT COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD)
-# Use LLVM utils and Clang from the same build tree.
-list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS
+  set(LIT_TEST_DEPS
   clang clang-resource-headers FileCheck count not llvm-config llvm-nm 
llvm-objdump
   llvm-readelf llvm-readobj llvm-size llvm-symbolizer compiler-rt-headers 
sancov)
-if (WIN32)
-  list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS KillTheDoctor)
-endif()
+  if (WIN32)
+list(APPEND LIT_TEST_DEPS KillTheDoctor)
+  endif()
+
+  if(NOT COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD)
+# Use LLVM utils and Clang from the same build tree.
+list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS ${LIT_TEST_DEPS})
+  elseif(COMPILER_RT_STANDALONE_BUILD)
+# If we are making a standalone build, we need to ensure some targets used
+# for testing are known and built as deps.
+list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS ${LIT_TEST_DEPS})
+
+# These are tools needed for testing in a standalone/runtimes build, but we
+# don't have a corresponding CMAKE_* flag for. These will need to be 
rebuilt.
+set(LIT_ONLY_TOOLS
+FileCheck count not)
+foreach(dep ${LIT_ONLY_TOOLS})
+  if (NOT TARGET ${dep})
+llvm_ExternalProject_BuildCmd(build_${dep} ${dep} ${BINARY_DIR})
+add_custom_target(${dep}
+  COMMAND ${build_${dep}}
+  WORKING_DIRECTORY ${BINARY_DIR}
+  VERBATIM USES_TERMINAL)
+  endif()
+endforeach()
   endif()
   # Tests use C++ standard library headers.
   if (TARGET cxx-headers OR HAVE_LIBCXX)


Index: compiler-rt/test/CMakeLists.txt
===
--- compiler-rt/test/CMakeLists.txt
+++ compiler-rt/test/CMakeLists.txt
@@ -1,5 +1,6 @@
 # Needed for lit support in standalone builds.
 include(AddLLVM)
+include(LLVMExternalProjectUtils)
 
 option(COMPILER_RT_TEST_STANDALONE_BUILD_LIBS
   "When set to ON and testing in a standalone build, test the runtime \
@@ -28,14 +29,34 @@
 # When ANDROID, we build tests with the host compiler (i.e. CMAKE_C_COMPILER),
 # and run tests with tools from the host toolchain.
 if(NOT ANDROID)
-  if(NOT COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD)
-# Use LLVM utils and Clang from the same build tree.
-list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS
+  set(LIT_TEST_DEPS
   clang clang-resource-headers FileCheck count not llvm-config llvm-nm llvm-objdump
   llvm-readelf llvm-readobj llvm-size llvm-symbolizer compiler-rt-headers sancov)
-if (WIN32)
-  list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS KillTheDoctor)
-endif()
+  if (WIN32)
+list(APPEND LIT_TEST_DEPS KillTheDoctor)
+  endif()
+
+  if(NOT COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD)
+# Use LLVM utils and Clang from the same build tree.
+list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS ${LIT_TEST_DEPS})
+  elseif(COMPILER_RT_STANDALONE_BUILD)
+# If we are making a standalone build, we need to ensure some targets used
+# for testing are known and built as deps.
+list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS ${LIT_TEST_DEPS})
+
+# These are tools needed for testing in a standalone/runtimes build, but we
+# don't have a corresponding CMAKE_* flag for. These will need to be rebuilt.
+set(LIT_ONLY_TOOLS
+FileCheck count not)
+foreach(dep ${LIT_ONLY_TOOLS})
+  if (NOT TARGET ${dep})
+llvm_ExternalProject_BuildCmd(build_${dep} ${dep} ${BINARY_DIR})
+add_custom_target(${dep}
+  COMMAND ${build_${dep}}
+  WORKING_DIRECTORY ${BINARY_DIR}
+  VERBATIM USES_TERMINAL)
+  endif()
+endforeach()
   endif()
   # Tests use C++ standard library headers.
   if (TARGET cxx-headers OR HAVE_LIBCXX)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110089: [CUDA] Implement experimental support for texture lookups.

2021-09-22 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Headers/__clang_cuda_texture_intrinsics.h:41
+
+namespace {
+

jlebar wrote:
> jlebar wrote:
> > what are you trying to accomplish with an anon ns inside a header?
> I know you wrote it in the commit message, but this file could really use 
> comments, otherwise I'm afraid you are going to be the only human being on 
> the planet who can edit this...
> 
> For starters, it seems that the purpose of this file is to define the 
> __nv_tex_surf_handler "function" -- is that right?
> what are you trying to accomplish with an anon ns inside a header?

I wanted to give all functions internal linkage, so they do not pollute visible 
symbols. Without that and with numeric tag IDs not being stable, we could end 
up having ODR issues in code compiled with `-fgpu-rdc` by different clang 
versions.

I've moved all defined functions into `namespace __cuda_tex`, so I don't have 
to use an extra prefix on all the types the header creates.

> For starters, it seems that the purpose of this file is to define the 
> __nv_tex_surf_handler "function" -- is that right?

Yes.  I've added a comment at the top of the doc.





Comment at: clang/lib/Headers/__clang_cuda_texture_intrinsics.h:91
+template  struct __FT {
+  using __bt = decltype(__T::x);
+  using __ft = typename __FT<__bt>::__ft;

jlebar wrote:
> this is c++11-only.  Which, you know what, fine by me.  But might be worth an 
> explicit #error at least?
I've added an include guard instead. This header is included from the cuda 
runtime wrapper for all compilations. We don't want to break folks who use 
c++98, but don't need textures. If they do try to use them, they will get a 
static assert.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110089

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


[PATCH] D110160: [clang][tooling] NFC: Refactor command-line diagnostic tests

2021-09-22 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110160

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


[PATCH] D110089: [CUDA] Implement experimental support for texture lookups.

2021-09-22 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 374391.
tra marked 2 inline comments as done.
tra added a comment.

Added better C++11 guards.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110089

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_cuda_runtime_wrapper.h
  clang/lib/Headers/__clang_cuda_texture_intrinsics.h

Index: clang/lib/Headers/__clang_cuda_texture_intrinsics.h
===
--- /dev/null
+++ clang/lib/Headers/__clang_cuda_texture_intrinsics.h
@@ -0,0 +1,700 @@
+/*===--- __clang_cuda_texture_intrinsics.h - Device-side texture support ---===
+ *
+ * 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
+ *
+ *===---===
+ *
+ * This header provides in-header implmentations for NVCC's built-in
+ * __nv_tex_surf_handler() which is used by CUDA's texture-related headers.  The
+ * built-in is unusual as it's actually a set of function overloads that use the
+ * first string literal argument as one of the overload parameters. We can not
+ * implement is directly with C++. Instead, we convert the string literal into a
+ * numberic value and use that to parametrize the implementations.
+ */
+#ifndef __CLANG_CUDA_TEXTURE_INTRINSICS_H__
+#define __CLANG_CUDA_TEXTURE_INTRINSICS_H__
+#ifndef __CUDA__
+#error "This file is for CUDA compilation only."
+#endif
+
+#include 
+
+// __nv_tex_surf_handler() provided by this header as a macro.
+#define __nv_tex_surf_handler(__op, __ptr, ...)\
+  __cuda_tex::__tex_fetch<__cuda_tex::__Tag<__cuda_tex::__tex_op_hash(__op)>>( \
+  __ptr, __VA_ARGS__)
+
+#pragma push_macro("__Args")
+#pragma push_macro("__ID")
+#pragma push_macro("__ID")
+#pragma push_macro("__IDV")
+#pragma push_macro("__IMPL_2DGATHER")
+#pragma push_macro("__IMPL_ALIAS")
+#pragma push_macro("__IMPL_ALIASI")
+#pragma push_macro("__IMPL_F1")
+#pragma push_macro("__IMPL_F3")
+#pragma push_macro("__IMPL_F3N")
+#pragma push_macro("__IMPL_F3S")
+#pragma push_macro("__IMPL_S")
+#pragma push_macro("__IMPL_S3")
+#pragma push_macro("__IMPL_S3I")
+#pragma push_macro("__IMPL_S3N")
+#pragma push_macro("__IMPL_S3NI")
+#pragma push_macro("__IMPL_S3S")
+#pragma push_macro("__IMPL_S3SI")
+#pragma push_macro("__IMPL_SI")
+#pragma push_macro("__L")
+#pragma push_macro("__STRIP_PARENS")
+#pragma push_macro("__ASM_OUT")
+#pragma push_macro("__ASM_OUTP")
+
+// Put all functions into anonymous namespace so they have internal linkage.
+namespace {
+
+// Put the implmentation into its own namespace so we don't pollute the TU.
+namespace __cuda_tex {
+
+// Perfect hash function and its helpers for converting a string literal into a
+// numeric value which can be used to parametrize a template. We can not use
+// string literals for that as that would require C++20.
+//
+// The hash function was generated with 'gperf' and manually converted into
+// constexpr equivalent.
+// TODO: add a test.
+
+constexpr size_t __tex_len(const char *s) {
+  return (s[0] == 0)? 0
+ : (s[1] == 0)  ? 1
+ : (s[2] == 0)  ? 2
+ : (s[3] == 0)  ? 3
+ : (s[4] == 0)  ? 4
+ : (s[5] == 0)  ? 5
+ : (s[6] == 0)  ? 6
+ : (s[7] == 0)  ? 7
+ : (s[8] == 0)  ? 8
+ : (s[9] == 0)  ? 9
+ : (s[10] == 0) ? 10
+ : (s[11] == 0) ? 11
+ : (s[12] == 0) ? 12
+ : (s[13] == 0) ? 13
+ : (s[14] == 0) ? 14
+ : (s[15] == 0) ? 15
+ : (s[16] == 0) ? 16
+ : (s[17] == 0) ? 17
+ : (s[18] == 0) ? 18
+ : (s[19] == 0) ? 19
+ : (s[20] == 0) ? 20
+ : (s[21] == 0) ? 21
+ : (s[22] == 0) ? 22
+ : (s[23] == 0) ? 23
+ : (s[24] == 0) ? 24
+ : (s[25] == 0) ? 25
+ : (s[26] == 0) ? 26
+ : (s[27] == 0) ? 27
+ : (s[28] == 0) ? 28
+ : (s[29] == 0) ? 29
+ : (s[30] == 0) ? 30
+ : (s[31] == 0) ? 31
+: 32;
+}
+
+constexpr unsigned char __tex_hash_map(unsigned char c) {
+  return (c == 49)? 10
+ : (c == 50)  ? 0
+ : (c == 51)  ? 100
+ : (c == 52)  ? 30
+ : (c == 67)  ? 10
+ : (c == 68)  ? 0
+ : (c == 69)  ? 25
+ : (c == 72)  ? 70
+ : (c == 77)  ? 0
+ : (c == 96)  ? 44
+ : (c == 99)  ? 10
+ : (c == 100) ? 5
+ : (c == 101) ? 60
+ : (c == 102) ? 40
+ : (c == 103) ? 70
+ : (c == 104) ? 25
+ : (c == 112) ? 0
+ : (c == 114) ? 45
+ : (c == 117) ? 5
+ : (c == 118) ? 85
+ : (c == 120) ? 20
+  : 225;
+}
+
+constexpr unsigned int __tex_op_hash(const char *str) {
+  ret

[PATCH] D110127: [Clang] Support typedef with btf_tag attributes

2021-09-22 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 374388.
yonghong-song added a comment.

- use -std=c2x attribute syntax `[[]]` in test to more precisely specify the 
location of the attribute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110127

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/attr-btf_tag.c


Index: clang/test/Sema/attr-btf_tag.c
===
--- clang/test/Sema/attr-btf_tag.c
+++ clang/test/Sema/attr-btf_tag.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -x c -triple x86_64-pc-linux-gnu -dwarf-version=4 
-fsyntax-only -verify %s
+// RUN: %clang_cc1 -x c -std=c2x -triple x86_64-pc-linux-gnu -dwarf-version=4 
-fsyntax-only -verify %s
 
 #define __tag1 __attribute__((btf_tag("tag1")))
 #define __tag2 __attribute__((btf_tag("tag2")))
@@ -25,15 +25,15 @@
 
 enum e1 {
   E1
-} __tag1; // expected-error {{'btf_tag' attribute only applies to variables, 
functions, structs, unions, classes, and non-static data members}}
+} __tag1; // expected-error {{'btf_tag' attribute only applies to variables, 
functions, structs, unions, classes, non-static data members, and typedefs}}
 
 enum e2 {
   E2
-} __tag_no_arg; // expected-error {{'btf_tag' attribute only applies to 
variables, functions, structs, unions, classes, and non-static data members}}
+} __tag_no_arg; // expected-error {{'btf_tag' attribute only applies to 
variables, functions, structs, unions, classes, non-static data members, and 
typedefs}}
 
 enum e3 {
   E3
-} __tag_2_arg; // expected-error {{'btf_tag' attribute only applies to 
variables, functions, structs, unions, classes, and non-static data members}}
+} __tag_2_arg; // expected-error {{'btf_tag' attribute only applies to 
variables, functions, structs, unions, classes, non-static data members, and 
typedefs}}
 
 int __tag1 __tag2 foo(struct t1 *arg, struct t2 *arg2);
 int __tag2 __tag3 foo(struct t1 *arg, struct t2 *arg2);
@@ -48,3 +48,13 @@
*/
   return (void __tag1 *)arg;
 }
+
+typedef unsigned * __u1 [[clang::btf_tag("tag1")]]; /* attribute applied to 
__u1 */
+__u1 convert2(long arg) {
+  return (__u1)arg;
+}
+
+typedef struct { int a; int b; } __u2 [[clang::btf_tag("tag1")]]; /* attribute 
applied to __u2 */
+__u2 * convert3(long arg) {
+  return (__u2 *)arg;
+}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -22,7 +22,7 @@
 // CHECK-NEXT: Assumption (SubjectMatchRule_function, 
SubjectMatchRule_objc_method)
 // CHECK-NEXT: Availability ((SubjectMatchRule_record, SubjectMatchRule_enum, 
SubjectMatchRule_enum_constant, SubjectMatchRule_field, 
SubjectMatchRule_function, SubjectMatchRule_namespace, 
SubjectMatchRule_objc_category, SubjectMatchRule_objc_implementation, 
SubjectMatchRule_objc_interface, SubjectMatchRule_objc_method, 
SubjectMatchRule_objc_property, SubjectMatchRule_objc_protocol, 
SubjectMatchRule_record, SubjectMatchRule_type_alias, 
SubjectMatchRule_variable))
 // CHECK-NEXT: BPFPreserveAccessIndex (SubjectMatchRule_record)
-// CHECK-NEXT: BTFTag (SubjectMatchRule_variable, SubjectMatchRule_function, 
SubjectMatchRule_record, SubjectMatchRule_field)
+// CHECK-NEXT: BTFTag (SubjectMatchRule_variable, SubjectMatchRule_function, 
SubjectMatchRule_record, SubjectMatchRule_field, SubjectMatchRule_type_alias)
 // CHECK-NEXT: BuiltinAlias (SubjectMatchRule_function)
 // CHECK-NEXT: CFAuditedTransfer (SubjectMatchRule_function)
 // CHECK-NEXT: CFConsumed (SubjectMatchRule_variable_is_parameter)
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -2016,9 +2016,10 @@
   let Content = [{
 Clang supports the ``__attribute__((btf_tag("ARGUMENT")))`` attribute for all
 targets. This attribute may be attached to a struct/union, struct/union field,
-function, function parameter or variable declaration. If -g is specified,
-the ``ARGUMENT`` info will be preserved in IR and be emitted to dwarf.
-For BPF targets, the ``ARGUMENT`` info will be emitted to .BTF ELF section too.
+function, function parameter, variable or typedef declaration. If -g is
+specified, the ``ARGUMENT`` info will be preserved in IR and be emitted to
+dwarf. For BPF targets, the ``ARGUMENT`` info will be emitted to .BTF ELF
+section too.
 
 The attribute can also be used as a type qualifier. Right now it is accepted
 and silently ignored in order to permit the linux kernel to build with the
Index: clang/include/clang/Basic/Attr.td
===

[PATCH] D110127: [Clang] Support typedef with btf_tag attributes

2021-09-22 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

In D110127#3016371 , @aaron.ballman 
wrote:

> In D110127#3013876 , @yonghong-song 
> wrote:
>
>> You can see that it doesn't matter where the attribute is placed, the 
>> attribute is always attached to the typedef.
>> I think the reason is for declarations, we only allow the btf_tag attribute 
>> to be placed for record, field, var, func, typedef,
>> and "unsigned *" does not qualify, so the attribute is applied to typedef.
>
> Agreed. If this attribute appertains to the type, then it goes through 
> SemaType.cpp and may require extra work to encode the information into the 
> type system. If it appertains to the declaration, then what's in 
> SemaDeclAttr.cpp is fine, but then I have questions about the use of the 
> attribute with cast notation from D110116  
> where this is being used definitely as a type attribute.

For typedef use case, it intends to be used as a decl attribute.

> One confounding factor here is that `__attribute__` will slide around to 
> whatever makes sense. You should try your examples with `[[]]` in C2x mode as 
> well -- the placement of the attribute syntax is strongly tied to what the 
> attribute applies to.

I tried `[[]]` syntax, it does seem better than otherwise,  e.g.,

  [$ ~/work/tests/llvm/btf_tag] cat t1.c
  #define __tag1 [[clang::btf_tag("tag1")]]
  typedef unsigned __tag1 * __u;
  __u u;
  [$~/work/tests/llvm/btf_tag] clang -c -std=c2x t1.c
  t1.c:2:18: error: 'btf_tag' attribute cannot be applied to types
  typedef unsigned __tag1 * __u;
   ^
  t1.c:1:18: note: expanded from macro '__tag1'
  #define __tag1 [[clang::btf_tag("tag1")]]
   ^
  1 error generated.
  [$ ~/work/tests/llvm/btf_tag]

and

  [$ ~/work/tests/llvm/btf_tag] cat t1.c
  #define __tag1 [[clang::btf_tag("tag1")]]
  typedef unsigned * __u __tag1;
  __u u;
  [$ ~/work/tests/llvm/btf_tag] clang -c -std=c2x t1.c
  [$ ~/work/tests/llvm/btf_tag]

If using old `__attribute__`  syntax, both above examples will compile 
successfully.

I will change my test to use -std=c2x.

>>> I'm asking because this raises other questions. For example:
>>>
>>>   void func(int i);
>>>   void func(int __attribute__((btf_tag("__user"))) i);
>>>
>>> Is the second a valid redeclaration of the first? Additionally:
>>
>> This should be okay as btf_tag is accumulative attribute.
>
> Okay, this is sounding more and more like a declaration attribute.
>
>>>   __attribute__((overloadable)) void func(int i) { puts("one"); }
>>>   __attribute__((overloadable)) void func(int 
>>> __attribute__((btf_tag("__user"))) i) { puts("two"); }
>>>
>>> Is this a valid overload set because of the type attribute? Along the same 
>>> lines, does adding this attribute to the type cause any ABI differences in 
>>> how the type is passed?
>>
>> btf_tag is for C only so overload function case won't happen.
>
> That's incorrect -- Clang supports attribute overloadable in C: 
> https://godbolt.org/z/eThKsn3zM

In this case, the overload is not valid and the attribute does not have an 
impact on overloading decision.

  [$ ~/work/tests/llvm/btf_tag] cat t.c
  #include 
  
  __attribute__((overloadable)) void func(int i) { puts("int"); }
  __attribute__((overloadable)) void func(int i 
__attribute__((btf_tag("tag2" { puts("float"); }
  
  int main(void) {
func(1);
  }
  [$ ~/work/tests/llvm/btf_tag] clang -c t.c
  t.c:4:36: error: redefinition of 'func'
  __attribute__((overloadable)) void func(int i 
__attribute__((btf_tag("tag2" { puts("float"); }
 ^
  t.c:3:36: note: previous definition is here
  __attribute__((overloadable)) void func(int i) { puts("int"); }
 ^
  1 error generated.
  [$ ~/work/tests/llvm/btf_tag]

So overloading is rejected. This is similar to below example with aligned 
attribute,

  [$ ~/work/tests/llvm/btf_tag] cat t.c
  #include 
  
  __attribute__((overloadable)) void func(int i) { puts("int"); }
  __attribute__((overloadable)) void func(int i __attribute__((aligned(8 { 
puts("float"); }
  
  int main(void) {
func(1);
  }
  [$ ~/work/tests/llvm/btf_tag] clang -c t.c
  t.c:4:36: error: redefinition of 'func'
  __attribute__((overloadable)) void func(int i __attribute__((aligned(8 { 
puts("float"); }
 ^
  t.c:3:36: note: previous definition is here
  __attribute__((overloadable)) void func(int i) { puts("int"); }
 ^
  1 error generated.
  [$ ~/work/tests/llvm/btf_tag]


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110127

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


[PATCH] D109703: [DebugInfo] Fix scope for local static variables

2021-09-22 Thread Ellis Hoag via Phabricator via cfe-commits
ellis added a comment.

In D109703#2998350 , @krisb wrote:

> But it seems imported declarations are broken not just for static locals, but 
> for all inlined entities, for example
>
>   namespace ns {
>   inline __attribute__((always_inline))
>   int foo() {
> int a = 42; 
> return a;
>   }
>   }
>   
>   int main() {
> using ns::foo;
> return foo();
>   }
>
> produces (with or w/o this patch) imported declaration for `foo()` that 
> refers to an empty subprogram:
>
>   x002a:   DW_TAG_namespace
>   DW_AT_name  ("ns")
>   
>   0x002f: DW_TAG_subprogram
> DW_AT_name  ("foo")
> DW_AT_inline  (DW_INL_inlined)
>   
>   0x003f:   DW_TAG_variable
>   DW_AT_name  ("a")
>   
>   0x004a:   NULL
>   
>   0x004b: DW_TAG_subprogram
>   
>   0x004c: NULL
>   
>   0x0054:   DW_TAG_subprogram
>   DW_AT_name  ("main")
>   
>   0x006d: DW_TAG_imported_declaration
> DW_AT_import  (0x004b)
>
> while it should point to `0x002f`.

I've looked into this and realized that clang correctly emits a 
`DW_TAG_inlined_subroutine` for foo so the variables here are actually ok. The 
`DW_TAG_imported_declaration` tag is incorrect though, and I have a fix in 
https://reviews.llvm.org/D110294.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109703

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


[PATCH] D110160: [clang][tooling] NFC: Refactor command-line diagnostic tests

2021-09-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 374383.
jansvoboda11 added a comment.

Use empty files and `-E`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110160

Files:
  clang/unittests/Tooling/ToolingTest.cpp

Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -15,6 +15,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/TextDiagnosticBuffer.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Tooling.h"
@@ -224,16 +225,6 @@
   EXPECT_TRUE(Invocation.run());
 }
 
-struct ErrorCountingDiagnosticConsumer : public DiagnosticConsumer {
-  ErrorCountingDiagnosticConsumer() : NumErrorsSeen(0) {}
-  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
-const Diagnostic &Info) override {
-if (DiagLevel == DiagnosticsEngine::Level::Error)
-  ++NumErrorsSeen;
-  }
-  unsigned NumErrorsSeen;
-};
-
 TEST(ToolInvocation, DiagnosticsEngineProperlyInitializedForCC1Construction) {
   llvm::IntrusiveRefCntPtr OverlayFileSystem(
   new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
@@ -245,24 +236,22 @@
 
   std::vector Args;
   Args.push_back("tool-executable");
-  Args.push_back("-target");
-  // Invalid argument that by default results in an error diagnostic:
-  Args.push_back("i386-apple-ios14.0-simulator");
-  // Argument that downgrades the error into a warning:
-  Args.push_back("-Wno-error=invalid-ios-deployment-target");
-  Args.push_back("-fsyntax-only");
+  // Unknown warning option will result in a warning.
+  Args.push_back("-fexpensive-optimizations");
+  // Argument that will suppress the warning above.
+  Args.push_back("-Wno-ignored-optimization-argument");
+  Args.push_back("-E");
   Args.push_back("test.cpp");
 
   clang::tooling::ToolInvocation Invocation(
   Args, std::make_unique(), Files.get());
-  InMemoryFileSystem->addFile(
-  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int a() {}\n"));
-  ErrorCountingDiagnosticConsumer Consumer;
+  InMemoryFileSystem->addFile("test.cpp", 0,
+  llvm::MemoryBuffer::getMemBuffer(""));
+  TextDiagnosticBuffer Consumer;
   Invocation.setDiagnosticConsumer(&Consumer);
   EXPECT_TRUE(Invocation.run());
-  // Check that `-Wno-error=invalid-ios-deployment-target` downgraded the error
-  // into a warning.
-  EXPECT_EQ(Consumer.NumErrorsSeen, 0u);
+  // Check that the warning was ignored due to the '-Wno-xxx' argument.
+  EXPECT_EQ(std::distance(Consumer.warn_begin(), Consumer.warn_end()), 0u);
 }
 
 TEST(ToolInvocation, CustomDiagnosticOptionsOverwriteParsedOnes) {
@@ -276,28 +265,28 @@
 
   std::vector Args;
   Args.push_back("tool-executable");
-  Args.push_back("-target");
-  // Invalid argument that by default results in an error diagnostic:
-  Args.push_back("i386-apple-ios14.0-simulator");
-  // Argument that downgrades the error into a warning:
-  Args.push_back("-Wno-error=invalid-ios-deployment-target");
-  Args.push_back("-fsyntax-only");
+  // Unknown warning option will result in a warning.
+  Args.push_back("-fexpensive-optimizations");
+  // Argument that will suppress the warning above.
+  Args.push_back("-Wno-ignored-optimization-argument");
+  Args.push_back("-E");
   Args.push_back("test.cpp");
 
   clang::tooling::ToolInvocation Invocation(
   Args, std::make_unique(), Files.get());
-  InMemoryFileSystem->addFile(
-  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int a() {}\n"));
-  ErrorCountingDiagnosticConsumer Consumer;
+  InMemoryFileSystem->addFile("test.cpp", 0,
+  llvm::MemoryBuffer::getMemBuffer(""));
+  TextDiagnosticBuffer Consumer;
   Invocation.setDiagnosticConsumer(&Consumer);
 
+  // Inject custom `DiagnosticOptions` for command-line parsing.
   auto DiagOpts = llvm::makeIntrusiveRefCnt();
   Invocation.setDiagnosticOptions(&*DiagOpts);
 
   EXPECT_TRUE(Invocation.run());
-  // Check that `-Wno-error=invalid-ios-deployment-target` didn't downgrade the
-  // error into a warning due to being overwritten by custom diagnostic options.
-  EXPECT_EQ(Consumer.NumErrorsSeen, 1u);
+  // Check that the warning was issued during command-line parsing due to the
+  // custom `DiagnosticOptions` without '-Wno-xxx'.
+  EXPECT_EQ(std::distance(Consumer.warn_begin(), Consumer.warn_end()), 1u);
 }
 
 struct DiagnosticConsumerExpectingSourceManager : public DiagnosticConsumer {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110160: [clang][tooling] NFC: Refactor command-line diagnostic tests

2021-09-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

I think we need a warning option to be able to suppress it (or conditionally 
promote to an error).




Comment at: clang/unittests/Tooling/ToolingTest.cpp:238-245
   Args.push_back("tool-executable");
-  Args.push_back("-target");
-  // Invalid argument that by default results in an error diagnostic:
-  Args.push_back("i386-apple-ios14.0-simulator");
-  // Argument that downgrades the error into a warning:
-  Args.push_back("-Wno-error=invalid-ios-deployment-target");
+  // Invalid argument (non-existent sysroot path) that will result in a 
warning.
+  Args.push_back("-isysroot");
+  Args.push_back("/dev/null/sysroot");
+  // Argument that will suppress the warning above.
+  Args.push_back("-Wno-missing-sysroot");
   Args.push_back("-fsyntax-only");

dexonsmith wrote:
> I'm worried this is going to behave differently when the unit test isn't run 
> on Darwin, since I think `-isysroot` is only valid for Darwin targets and 
> there's no `-arch` or `-target` option. Can you confirm whether this should 
> reproduce properly when run on other hosts as well?
Good point, I switched to a platform-agnostic flags.



Comment at: clang/unittests/Tooling/ToolingTest.cpp:280-281
   InMemoryFileSystem->addFile(
-  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int a() {}\n"));
-  ErrorCountingDiagnosticConsumer Consumer;
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void a() {}\n"));
+  TextDiagnosticBuffer Consumer;
   Invocation.setDiagnosticConsumer(&Consumer);

dexonsmith wrote:
> Can this just be empty and use `-E`? But if you switch to another error maybe 
> you don't need to modify this anyway?
Yes, that would be a nice simplification.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110160

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


[clang] 747b1a6 - [NFC] Remove trailing spaces from some files

2021-09-22 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2021-09-22T18:17:40-04:00
New Revision: 747b1a67a3dd706ffab9df9ee6f816b75ccaa5b6

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

LOG: [NFC] Remove trailing spaces from some files

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 1bc51bf41cdb..598c84759710 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -425,7 +425,7 @@ LANGOPT(RelativeCXXABIVTables, 1, 0,
 
 LANGOPT(ArmSveVectorBits, 32, 0, "SVE vector size in bits")
 
-ENUM_LANGOPT(ExtendIntArgs, ExtendArgsKind, 1, ExtendArgsKind::ExtendTo32, 
+ENUM_LANGOPT(ExtendIntArgs, ExtendArgsKind, 1, ExtendArgsKind::ExtendTo32,
  "Controls how scalar integer arguments are extended in calls "
  "to unprototyped and varargs functions")
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 64d837f975b2..b6d0ec76f79b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1805,7 +1805,7 @@ defm strict_float_cast_overflow : 
BoolFOption<"strict-float-cast-overflow",
 
 defm protect_parens : BoolFOption<"protect-parens",
   LangOpts<"ProtectParens">, DefaultFalse,
-  PosFlag,
   NegFlag>;
@@ -2548,7 +2548,7 @@ defm signed_char : BoolFOption<"signed-char",
   ShouldParseIf;
 defm split_stack : BoolFOption<"split-stack",
   CodeGenOpts<"EnableSegmentedStacks">, DefaultFalse,
-  NegFlag, 
+  NegFlag,
   PosFlag>;
 def fstack_protector_all : Flag<["-"], "fstack-protector-all">, Group,
   HelpText<"Enable stack protectors for all functions">;
@@ -4577,7 +4577,7 @@ def falternative_parameter_statement : Flag<["-"], 
"falternative-parameter-state
   HelpText<"Enable the old style PARAMETER statement">;
 def fintrinsic_modules_path : Separate<["-"], "fintrinsic-modules-path">,  
Group, MetaVarName<"">,
   HelpText<"Specify where to find the compiled intrinsic modules">,
-  DocBrief<[{This option specifies the location of pre-compiled intrinsic 
modules, 
+  DocBrief<[{This option specifies the location of pre-compiled intrinsic 
modules,
   if they are not in the default location expected by the compiler.}]>;
 
 defm backslash : OptInFC1FFlag<"backslash", "Specify that backslash in string 
introduces an escape character">;

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2368e6884188..dc52190cbb37 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3782,8 +3782,8 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, 
ArgList &Args,
   // '-mignore-xcoff-visibility' is implied. The generated command line will
   // contain both '-fvisibility default' and '-mignore-xcoff-visibility' and
   // subsequent calls to `CreateFromArgs`/`generateCC1CommandLine` will always
-  // produce the same arguments. 
- 
+  // produce the same arguments.
+
   if (T.isOSAIX() && (Args.hasArg(OPT_mignore_xcoff_visibility) ||
   !Args.hasArg(OPT_fvisibility)))
 Opts.IgnoreXCOFFVisibility = 1;



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


[PATCH] D110160: [clang][tooling] NFC: Refactor command-line diagnostic tests

2021-09-22 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 374382.
jansvoboda11 added a comment.

Use flags not specific to Darwin


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110160

Files:
  clang/unittests/Tooling/ToolingTest.cpp

Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -15,6 +15,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/TextDiagnosticBuffer.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Tooling.h"
@@ -224,16 +225,6 @@
   EXPECT_TRUE(Invocation.run());
 }
 
-struct ErrorCountingDiagnosticConsumer : public DiagnosticConsumer {
-  ErrorCountingDiagnosticConsumer() : NumErrorsSeen(0) {}
-  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
-const Diagnostic &Info) override {
-if (DiagLevel == DiagnosticsEngine::Level::Error)
-  ++NumErrorsSeen;
-  }
-  unsigned NumErrorsSeen;
-};
-
 TEST(ToolInvocation, DiagnosticsEngineProperlyInitializedForCC1Construction) {
   llvm::IntrusiveRefCntPtr OverlayFileSystem(
   new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
@@ -245,24 +236,22 @@
 
   std::vector Args;
   Args.push_back("tool-executable");
-  Args.push_back("-target");
-  // Invalid argument that by default results in an error diagnostic:
-  Args.push_back("i386-apple-ios14.0-simulator");
-  // Argument that downgrades the error into a warning:
-  Args.push_back("-Wno-error=invalid-ios-deployment-target");
+  // Unknown warning option will result in a warning.
+  Args.push_back("-fexpensive-optimizations");
+  // Argument that will suppress the warning above.
+  Args.push_back("-Wno-ignored-optimization-argument");
   Args.push_back("-fsyntax-only");
   Args.push_back("test.cpp");
 
   clang::tooling::ToolInvocation Invocation(
   Args, std::make_unique(), Files.get());
   InMemoryFileSystem->addFile(
-  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int a() {}\n"));
-  ErrorCountingDiagnosticConsumer Consumer;
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void a() {}\n"));
+  TextDiagnosticBuffer Consumer;
   Invocation.setDiagnosticConsumer(&Consumer);
   EXPECT_TRUE(Invocation.run());
-  // Check that `-Wno-error=invalid-ios-deployment-target` downgraded the error
-  // into a warning.
-  EXPECT_EQ(Consumer.NumErrorsSeen, 0u);
+  // Check that the warning was ignored due to the '-Wno-xxx' argument.
+  EXPECT_EQ(std::distance(Consumer.warn_begin(), Consumer.warn_end()), 0u);
 }
 
 TEST(ToolInvocation, CustomDiagnosticOptionsOverwriteParsedOnes) {
@@ -276,28 +265,28 @@
 
   std::vector Args;
   Args.push_back("tool-executable");
-  Args.push_back("-target");
-  // Invalid argument that by default results in an error diagnostic:
-  Args.push_back("i386-apple-ios14.0-simulator");
-  // Argument that downgrades the error into a warning:
-  Args.push_back("-Wno-error=invalid-ios-deployment-target");
+  // Unknown warning option will result in a warning.
+  Args.push_back("-fexpensive-optimizations");
+  // Argument that will suppress the warning above.
+  Args.push_back("-Wno-ignored-optimization-argument");
   Args.push_back("-fsyntax-only");
   Args.push_back("test.cpp");
 
   clang::tooling::ToolInvocation Invocation(
   Args, std::make_unique(), Files.get());
   InMemoryFileSystem->addFile(
-  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int a() {}\n"));
-  ErrorCountingDiagnosticConsumer Consumer;
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void a() {}\n"));
+  TextDiagnosticBuffer Consumer;
   Invocation.setDiagnosticConsumer(&Consumer);
 
+  // Inject custom `DiagnosticOptions` for command-line parsing.
   auto DiagOpts = llvm::makeIntrusiveRefCnt();
   Invocation.setDiagnosticOptions(&*DiagOpts);
 
   EXPECT_TRUE(Invocation.run());
-  // Check that `-Wno-error=invalid-ios-deployment-target` didn't downgrade the
-  // error into a warning due to being overwritten by custom diagnostic options.
-  EXPECT_EQ(Consumer.NumErrorsSeen, 1u);
+  // Check that the warning was issued during command-line parsing due to the
+  // custom `DiagnosticOptions` without '-Wno-xxx'.
+  EXPECT_EQ(std::distance(Consumer.warn_begin(), Consumer.warn_end()), 1u);
 }
 
 struct DiagnosticConsumerExpectingSourceManager : public DiagnosticConsumer {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108567: Implement #pragma clang final extension

2021-09-22 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 374377.
beanz added a comment.

Updates based on feedback from @aaron.ballman.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108567

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/Pragma.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/test/Lexer/Inputs/final-macro.h
  clang/test/Lexer/Inputs/unsafe-macro.h
  clang/test/Lexer/deprecate-macro.c
  clang/test/Lexer/final-macro.c
  clang/test/Lexer/pedantic-macro-interplay.c

Index: clang/test/Lexer/pedantic-macro-interplay.c
===
--- clang/test/Lexer/pedantic-macro-interplay.c
+++ clang/test/Lexer/pedantic-macro-interplay.c
@@ -11,4 +11,17 @@
 // not-expected-warning@+1{{macro 'UNSAFE_MACRO_2' has been marked as deprecated: Don't use this!}}
 #pragma clang restrict_expansion(UNSAFE_MACRO_2, "Don't use this!")
 
-// expected-no-diagnostics
+
+#define Foo 1
+#pragma clang final(Foo)
+// expected-note@+2{{macro marked 'deprecated' here}}
+// expected-note@+1{{macro marked 'deprecated' here}}
+#pragma clang deprecated(Foo)
+// expected-note@+1{{macro marked 'restrict_expansion' here}}
+#pragma clang restrict_expansion(Foo)
+
+// Test that unsafe_header and deprecated markings stick around after the undef
+#include "Inputs/final-macro.h"
+
+// expected-warning@+1{{macro 'Foo' has been marked as deprecated}}
+const int X = Foo;
Index: clang/test/Lexer/final-macro.c
===
--- /dev/null
+++ clang/test/Lexer/final-macro.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -Wfinal-macro %s -fsyntax-only -verify
+
+// Test warning production
+#define Foo 1
+// expected-note@+1 4{{macro marked 'final' here}}
+#pragma clang final(Foo)
+
+// expected-warning@+2{{macro 'Foo' has been marked as final and should not be redefined}}
+// expected-note@+1{{previous definition is here}}
+#define Foo 1
+
+// expected-warning@+2{{macro 'Foo' has been marked as final and should not be redefined}}
+// expected-warning@+1{{'Foo' macro redefined}}
+#define Foo 2
+
+// expected-warning@+1{{redefining builtin macro}}
+#define __TIME__ 1
+
+// expected-warning@+1{{undefining builtin macro}}
+#undef __TIMESTAMP__
+
+// expected-warning@+1{{macro 'Foo' has been marked as final and should not be undefined}}
+#undef Foo
+// expected-warning@+1{{macro 'Foo' has been marked as final and should not be redefined}}
+#define Foo 3
+
+// Test parse errors
+// expected-error@+1{{expected (}}
+#pragma clang final
+
+// expected-error@+1{{expected )}}
+#pragma clang final(Foo
+
+// expected-error@+1{{no macro named 'Baz'}}
+#pragma clang final(Baz)
+
+// expected-error@+1{{expected identifier}}
+#pragma clang final(4)
+
+// expected-error@+1{{expected (}}
+#pragma clang final Baz
+
+// no diagnostics triggered by these pragmas.
+#pragma clang deprecated(Foo)
+#pragma clang header_unsafe(Foo)
Index: clang/test/Lexer/deprecate-macro.c
===
--- clang/test/Lexer/deprecate-macro.c
+++ clang/test/Lexer/deprecate-macro.c
@@ -6,7 +6,7 @@
 // expected-error@+1{{expected identifier}}
 #pragma clang deprecated(4
 
-// expected-error@+1{{no macro named foo}}
+// expected-error@+1{{no macro named 'foo'}}
 #pragma clang deprecated(foo)
 
 #define bar 1
@@ -48,7 +48,7 @@
 #endif
 
 int main(int argc, char** argv) {
-// expected-error@+1{{no macro named main}}
+// expected-error@+1{{no macro named 'main'}}
 #pragma clang deprecated(main)
 
   // expected-warning@+1{{macro 'foo' has been marked as deprecated}}
Index: clang/test/Lexer/Inputs/unsafe-macro.h
===
--- clang/test/Lexer/Inputs/unsafe-macro.h
+++ clang/test/Lexer/Inputs/unsafe-macro.h
@@ -4,7 +4,7 @@
 // expected-error@+1{{expected identifier}}
 #pragma clang restrict_expansion(4
 
-// expected-error@+1{{no macro named foo}}
+// expected-error@+1{{no macro named 'foo'}}
 #pragma clang restrict_expansion(foo)
 
 
Index: clang/test/Lexer/Inputs/final-macro.h
===
--- /dev/null
+++ clang/test/Lexer/Inputs/final-macro.h
@@ -0,0 +1,4 @@
+// expected-warning@+2{{macro 'Foo' has been marked as deprecated}}
+// expected-warning@+1{{macro 'Foo' has been marked as unsafe for use in headers}}
+#if Foo
+#endif
Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -1413,26 +1413,46 @@
   return true;
 }
 
-void Preprocessor::emitMacroDeprecationWarning(const Token &Identifier) {
-  auto DepMsg = getMacroDeprecati

[PATCH] D108567: Implement #pragma clang final extension

2021-09-22 Thread Chris Bieneman via Phabricator via cfe-commits
beanz marked 3 inline comments as done and an inline comment as not done.
beanz added a comment.

Will push updates in a second.




Comment at: clang/test/Lexer/final-macro.c:14
+// expected-warning@+2{{macro 'Foo' has been marked as final and should not be 
redefined}}
+// expected-note@+1{{previous definition is here}}
+#define Foo 1

aaron.ballman wrote:
> This previous definition marker looks wrong to me -- it should be pointing to 
> line 4, right?
Since the macro is redefined here, when the later warning gets hit the note 
pops up here, which makes sense. This itself being a redefinition is amusing, 
but I think this is probably the way we want it to work. I don't have strong 
opinions though...



Comment at: clang/test/Lexer/final-macro.c:18
+// expected-warning@+2{{macro 'Foo' has been marked as final and should not be 
redefined}}
+// expected-warning@+1{{'Foo' macro redefined}}
+#define Foo 2

aaron.ballman wrote:
> Should we suppress this diagnostic when we know we're already issuing the 
> previous one? I get why they both are issued, but it does seem a bit unclean 
> to have two warnings that are  basically both "you are redefining this macro 
> and maybe you should reconsider that" diagnostics. (I don't feel strongly, 
> mostly wondering out loud.)
I can see this going both ways. I tend to err toward listing _all_ the warnings 
in case someone wants to try and suppress them for a specific use case. 
Otherwise they have to build multiple times in a cycle to suppress everything.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108567

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


[PATCH] D110111: [WebAssembly] Add relaxed-simd feature

2021-09-22 Thread Thomas Lively via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1552179ac019: [WebAssembly] Add relaxed-simd feature 
(authored by ngzhian, committed by tlively).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110111

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/Basic/Targets/WebAssembly.h
  clang/test/Preprocessor/wasm-target-features.c
  llvm/lib/Target/WebAssembly/WebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h

Index: llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
===
--- llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
+++ llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
@@ -36,6 +36,7 @@
   enum SIMDEnum {
 NoSIMD,
 SIMD128,
+RelaxedSIMD,
   } SIMDLevel = NoSIMD;
 
   bool HasAtomics = false;
@@ -89,6 +90,7 @@
   // Predicates used by WebAssemblyInstrInfo.td.
   bool hasAddr64() const { return TargetTriple.isArch64Bit(); }
   bool hasSIMD128() const { return SIMDLevel >= SIMD128; }
+  bool hasRelaxedSIMD() const { return SIMDLevel >= RelaxedSIMD; }
   bool hasAtomics() const { return HasAtomics; }
   bool hasNontrappingFPToInt() const { return HasNontrappingFPToInt; }
   bool hasSignExt() const { return HasSignExt; }
Index: llvm/lib/Target/WebAssembly/WebAssembly.td
===
--- llvm/lib/Target/WebAssembly/WebAssembly.td
+++ llvm/lib/Target/WebAssembly/WebAssembly.td
@@ -25,6 +25,9 @@
 def FeatureSIMD128 : SubtargetFeature<"simd128", "SIMDLevel", "SIMD128",
   "Enable 128-bit SIMD">;
 
+def FeatureRelaxedSIMD : SubtargetFeature<"relaxed-simd", "SIMDLevel", "RelaxedSIMD",
+  "Enable relaxed-simd instructions">;
+
 def FeatureAtomics : SubtargetFeature<"atomics", "HasAtomics", "true",
   "Enable Atomics">;
 
Index: clang/test/Preprocessor/wasm-target-features.c
===
--- clang/test/Preprocessor/wasm-target-features.c
+++ clang/test/Preprocessor/wasm-target-features.c
@@ -7,6 +7,15 @@
 //
 // SIMD128:#define __wasm_simd128__ 1{{$}}
 
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm32-unknown-unknown -mrelaxed-simd \
+// RUN:   | FileCheck %s -check-prefix=RELAXED-SIMD
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target wasm64-unknown-unknown -mrelaxed-simd \
+// RUN:   | FileCheck %s -check-prefix=RELAXED-SIMD
+//
+// RELAXED-SIMD:#define __wasm_relaxed_simd__ 1{{$}}
+
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target wasm32-unknown-unknown -mnontrapping-fptoint \
 // RUN:   | FileCheck %s -check-prefix=NONTRAPPING-FPTOINT
Index: clang/lib/Basic/Targets/WebAssembly.h
===
--- clang/lib/Basic/Targets/WebAssembly.h
+++ clang/lib/Basic/Targets/WebAssembly.h
@@ -27,6 +27,7 @@
   enum SIMDEnum {
 NoSIMD,
 SIMD128,
+RelaxedSIMD,
   } SIMDLevel = NoSIMD;
 
   bool HasNontrappingFPToInt = false;
Index: clang/lib/Basic/Targets/WebAssembly.cpp
===
--- clang/lib/Basic/Targets/WebAssembly.cpp
+++ clang/lib/Basic/Targets/WebAssembly.cpp
@@ -46,6 +46,7 @@
 bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
   return llvm::StringSwitch(Feature)
   .Case("simd128", SIMDLevel >= SIMD128)
+  .Case("relaxed-simd", SIMDLevel >= RelaxedSIMD)
   .Case("nontrapping-fptoint", HasNontrappingFPToInt)
   .Case("sign-ext", HasSignExt)
   .Case("exception-handling", HasExceptionHandling)
@@ -72,6 +73,8 @@
   defineCPUMacros(Builder, "wasm", /*Tuning=*/false);
   if (SIMDLevel >= SIMD128)
 Builder.defineMacro("__wasm_simd128__");
+  if (SIMDLevel >= RelaxedSIMD)
+Builder.defineMacro("__wasm_relaxed_simd__");
   if (HasNontrappingFPToInt)
 Builder.defineMacro("__wasm_nontrapping_fptoint__");
   if (HasSignExt)
@@ -96,6 +99,9 @@
  SIMDEnum Level, bool Enabled) {
   if (Enabled) {
 switch (Level) {
+case RelaxedSIMD:
+  Features["relaxed-simd"] = true;
+  LLVM_FALLTHROUGH;
 case SIMD128:
   Features["simd128"] = true;
   LLVM_FALLTHROUGH;
@@ -109,6 +115,9 @@
   case NoSIMD:
   case SIMD128:
 Features["simd128"] = false;
+LLVM_FALLTHROUGH;
+  case RelaxedSIMD:
+Features["relaxed-simd"] = false;
 break;
   }
 }
@@ -118,6 +127,8 @@
   bool Enabled) const {
   if (Name == "simd128")
 setSIMDLevel(Features, SIMD128, Enabled);
+  else if (Name == "relaxed-simd")
+setSIMDLevel(Features, RelaxedSIMD, Enabled);
   else
 Features[Name] = Enabled;

[clang] 1552179 - [WebAssembly] Add relaxed-simd feature

2021-09-22 Thread Thomas Lively via cfe-commits

Author: Zhi An Ng
Date: 2021-09-22T14:52:50-07:00
New Revision: 1552179ac0199d819396d8b8db807016a78c8951

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

LOG: [WebAssembly] Add relaxed-simd feature

This currently only defines a constant, but it the future will be used
to gate builtins for experimenting and prototyping relaxed-simd proposal
(https://github.com/WebAssembly/relaxed-simd/).

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/WebAssembly.cpp
clang/lib/Basic/Targets/WebAssembly.h
clang/test/Preprocessor/wasm-target-features.c
llvm/lib/Target/WebAssembly/WebAssembly.td
llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 13d740cdb0fb7..64d837f975b22 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3337,6 +3337,8 @@ def mharden_sls_EQ : Joined<["-"], "mharden-sls=">,
 
 def msimd128 : Flag<["-"], "msimd128">, Group;
 def mno_simd128 : Flag<["-"], "mno-simd128">, Group;
+def mrelaxed_simd : Flag<["-"], "mrelaxed-simd">, Group;
+def mno_relaxed_simd : Flag<["-"], "mno-relaxed-simd">, 
Group;
 def mnontrapping_fptoint : Flag<["-"], "mnontrapping-fptoint">, 
Group;
 def mno_nontrapping_fptoint : Flag<["-"], "mno-nontrapping-fptoint">, 
Group;
 def msign_ext : Flag<["-"], "msign-ext">, Group;

diff  --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index 7ef79849cb75d..61c35e65fccc1 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -46,6 +46,7 @@ bool WebAssemblyTargetInfo::setABI(const std::string &Name) {
 bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
   return llvm::StringSwitch(Feature)
   .Case("simd128", SIMDLevel >= SIMD128)
+  .Case("relaxed-simd", SIMDLevel >= RelaxedSIMD)
   .Case("nontrapping-fptoint", HasNontrappingFPToInt)
   .Case("sign-ext", HasSignExt)
   .Case("exception-handling", HasExceptionHandling)
@@ -72,6 +73,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const 
LangOptions &Opts,
   defineCPUMacros(Builder, "wasm", /*Tuning=*/false);
   if (SIMDLevel >= SIMD128)
 Builder.defineMacro("__wasm_simd128__");
+  if (SIMDLevel >= RelaxedSIMD)
+Builder.defineMacro("__wasm_relaxed_simd__");
   if (HasNontrappingFPToInt)
 Builder.defineMacro("__wasm_nontrapping_fptoint__");
   if (HasSignExt)
@@ -96,6 +99,9 @@ void 
WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap &Features,
  SIMDEnum Level, bool Enabled) {
   if (Enabled) {
 switch (Level) {
+case RelaxedSIMD:
+  Features["relaxed-simd"] = true;
+  LLVM_FALLTHROUGH;
 case SIMD128:
   Features["simd128"] = true;
   LLVM_FALLTHROUGH;
@@ -109,6 +115,9 @@ void 
WebAssemblyTargetInfo::setSIMDLevel(llvm::StringMap &Features,
   case NoSIMD:
   case SIMD128:
 Features["simd128"] = false;
+LLVM_FALLTHROUGH;
+  case RelaxedSIMD:
+Features["relaxed-simd"] = false;
 break;
   }
 }
@@ -118,6 +127,8 @@ void 
WebAssemblyTargetInfo::setFeatureEnabled(llvm::StringMap &Features,
   bool Enabled) const {
   if (Name == "simd128")
 setSIMDLevel(Features, SIMD128, Enabled);
+  else if (Name == "relaxed-simd")
+setSIMDLevel(Features, RelaxedSIMD, Enabled);
   else
 Features[Name] = Enabled;
 }
@@ -149,6 +160,14 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
   SIMDLevel = std::min(SIMDLevel, SIMDEnum(SIMD128 - 1));
   continue;
 }
+if (Feature == "+relaxed-simd") {
+  SIMDLevel = std::max(SIMDLevel, RelaxedSIMD);
+  continue;
+}
+if (Feature == "-relaxed-simd") {
+  SIMDLevel = std::min(SIMDLevel, SIMDEnum(RelaxedSIMD - 1));
+  continue;
+}
 if (Feature == "+nontrapping-fptoint") {
   HasNontrappingFPToInt = true;
   continue;

diff  --git a/clang/lib/Basic/Targets/WebAssembly.h 
b/clang/lib/Basic/Targets/WebAssembly.h
index 4a5ba25c75e7e..27b6576e4b7ad 100644
--- a/clang/lib/Basic/Targets/WebAssembly.h
+++ b/clang/lib/Basic/Targets/WebAssembly.h
@@ -27,6 +27,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public 
TargetInfo {
   enum SIMDEnum {
 NoSIMD,
 SIMD128,
+RelaxedSIMD,
   } SIMDLevel = NoSIMD;
 
   bool HasNontrappingFPToInt = false;

diff  --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index 29cc3071a235a..3c743142a3e38 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-feat

[PATCH] D103938: Diagnose -Wunused-value based on CFG reachability

2021-09-22 Thread Yuanfang Chen via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcbbf2e8c8ae7: Diagnose -Wunused-value based on CFG 
reachability (authored by ychen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103938

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/Analysis/dead-stores.c
  clang/test/CXX/basic/basic.link/p8.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/drs/dr20xx.cpp
  clang/test/CXX/drs/dr7xx.cpp
  clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
  clang/test/CodeCompletion/pragma-macro-token-caching.c
  clang/test/Frontend/fixed_point_crash.c
  clang/test/PCH/cxx-explicit-specifier.cpp
  clang/test/Parser/cxx-ambig-decl-expr.cpp
  clang/test/Parser/cxx0x-ambig.cpp
  clang/test/Parser/cxx1z-init-statement.cpp
  clang/test/Parser/objc-messaging-1.m
  clang/test/Parser/objc-try-catch-1.m
  clang/test/Parser/objcxx11-attributes.mm
  clang/test/Sema/const-eval.c
  clang/test/Sema/exprs.c
  clang/test/Sema/i-c-e.c
  clang/test/Sema/sizeless-1.c
  clang/test/Sema/switch-1.c
  clang/test/Sema/vla-2.c
  clang/test/Sema/warn-type-safety.c
  clang/test/Sema/warn-unused-value.c
  clang/test/SemaCXX/attr-annotate.cpp
  clang/test/SemaCXX/builtin-constant-p.cpp
  clang/test/SemaCXX/constant-expression-cxx2a.cpp
  clang/test/SemaCXX/constant-expression.cpp
  clang/test/SemaCXX/expression-traits.cpp
  clang/test/SemaCXX/matrix-type-operators.cpp
  clang/test/SemaCXX/overloaded-operator.cpp
  clang/test/SemaCXX/sizeless-1.cpp
  clang/test/SemaCXX/vector.cpp
  clang/test/SemaCXX/warn-comma-operator.cpp
  clang/test/SemaCXX/warn-unused-value.cpp
  clang/test/SemaTemplate/derived.cpp
  clang/test/SemaTemplate/lambda-capture-pack.cpp

Index: clang/test/SemaTemplate/lambda-capture-pack.cpp
===
--- clang/test/SemaTemplate/lambda-capture-pack.cpp
+++ clang/test/SemaTemplate/lambda-capture-pack.cpp
@@ -18,7 +18,7 @@
 namespace PR41576 {
   template  constexpr int f(Xs ...xs) {
 return [&](auto ...ys) { // expected-note {{instantiation}}
-  return ((xs + ys), ...); // expected-warning {{unused}}
+  return ((xs + ys), ...); // expected-warning {{left operand of comma operator has no effect}}
 }(1, 2);
   }
   static_assert(f(3, 4) == 6); // expected-note {{instantiation}}
Index: clang/test/SemaTemplate/derived.cpp
===
--- clang/test/SemaTemplate/derived.cpp
+++ clang/test/SemaTemplate/derived.cpp
@@ -49,6 +49,6 @@
 
   class A {
 TFP m_p;
-void Enable() { 0, A(); } // expected-warning {{unused}}
+void Enable() { 0, A(); } // expected-warning {{left operand of comma operator has no effect}}
   };
 }
Index: clang/test/SemaCXX/warn-unused-value.cpp
===
--- clang/test/SemaCXX/warn-unused-value.cpp
+++ clang/test/SemaCXX/warn-unused-value.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value %s
 // RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value -std=c++98 %s
 // RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value -std=c++17 %s
 
 // PR4806
 namespace test0 {
@@ -138,3 +139,26 @@
   (void)arr3;
   (void)arr4;
 }
+
+#if __cplusplus >= 201103L // C++11 or later
+namespace test5 {
+int v[(5, 6)]; // expected-warning {{left operand of comma operator has no effect}}
+void foo() {
+  new double[false ? (1, 2) : 3]
+// FIXME: We shouldn't diagnose the unreachable constant expression
+// here.
+[false ? (1, 2) : 3]; // expected-warning {{left operand of comma operator has no effect}}
+}
+} // namespace test5
+#endif
+
+#if __cplusplus >= 201703L // C++17 or later
+namespace test6 {
+auto b() {
+  if constexpr (false)
+return (1,0);
+  else
+return (1.0,0.0); // expected-warning {{left operand of comma operator has no effect}}
+}
+} // namespace test6
+#endif
Index: clang/test/SemaCXX/warn-comma-operator.cpp
===
--- clang/test/SemaCXX/warn-comma-operator.cpp
+++ clang/test/SemaCXX/warn-comma-operator.cpp
@@ -242,8 +242,8 @@
 
 template 
 class Foo {
-  typedef bool_seq<(xs::value, true)...> all_true;
-  typedef bool_seq<(xs::value, false)...> all_false;
+  typedef bool_seq<((void)xs::value, true)...> all_true;
+  typedef bool_seq<((void)xs::value, false)...> all_false;
   typedef bool_seq seq;
 };
 
Index: clang/test/SemaCXX/vector.cpp
===
--- clang/test/SemaCXX/vector.cpp
+++ clang/test/SemaCXX/vector.cpp

[clang] cbbf2e8 - Diagnose -Wunused-value based on CFG reachability

2021-09-22 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2021-09-22T14:38:06-07:00
New Revision: cbbf2e8c8ae7730ff0121f4868de4a7d188feb65

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

LOG: Diagnose -Wunused-value based on CFG reachability

While at it, add the diagnosis message "left operand of comma operator has no 
effect" (used by GCC) for comma operator.

This also makes Clang diagnose in the constant evaluation context which aligns 
with GCC/MSVC behavior. (https://godbolt.org/z/7zxb8Tx96)

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/Analysis/dead-stores.c
clang/test/CXX/basic/basic.link/p8.cpp
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr20xx.cpp
clang/test/CXX/drs/dr7xx.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
clang/test/CodeCompletion/pragma-macro-token-caching.c
clang/test/Frontend/fixed_point_crash.c
clang/test/PCH/cxx-explicit-specifier.cpp
clang/test/Parser/cxx-ambig-decl-expr.cpp
clang/test/Parser/cxx0x-ambig.cpp
clang/test/Parser/cxx1z-init-statement.cpp
clang/test/Parser/objc-messaging-1.m
clang/test/Parser/objc-try-catch-1.m
clang/test/Parser/objcxx11-attributes.mm
clang/test/Sema/const-eval.c
clang/test/Sema/exprs.c
clang/test/Sema/i-c-e.c
clang/test/Sema/sizeless-1.c
clang/test/Sema/switch-1.c
clang/test/Sema/vla-2.c
clang/test/Sema/warn-type-safety.c
clang/test/Sema/warn-unused-value.c
clang/test/SemaCXX/attr-annotate.cpp
clang/test/SemaCXX/builtin-constant-p.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp
clang/test/SemaCXX/constant-expression.cpp
clang/test/SemaCXX/expression-traits.cpp
clang/test/SemaCXX/matrix-type-operators.cpp
clang/test/SemaCXX/overloaded-operator.cpp
clang/test/SemaCXX/sizeless-1.cpp
clang/test/SemaCXX/vector.cpp
clang/test/SemaCXX/warn-comma-operator.cpp
clang/test/SemaCXX/warn-unused-value.cpp
clang/test/SemaTemplate/derived.cpp
clang/test/SemaTemplate/lambda-capture-pack.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0e803ee028ce9..cafee92e46e75 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8565,6 +8565,9 @@ def err_typecheck_choose_expr_requires_constant : Error<
   "'__builtin_choose_expr' requires a constant expression">;
 def warn_unused_expr : Warning<"expression result unused">,
   InGroup;
+def warn_unused_comma_left_operand : Warning<
+  "left operand of comma operator has no effect">,
+  InGroup;
 def warn_unused_voidptr : Warning<
   "expression result unused; should this cast be to 'void'?">,
   InGroup;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 93d5558b8267c..fc0b6919bd50b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4912,7 +4912,7 @@ class Sema final {
 
   /// DiagnoseUnusedExprResult - If the statement passed in is an expression
   /// whose result is unused, warn.
-  void DiagnoseUnusedExprResult(const Stmt *S);
+  void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID);
   void DiagnoseUnusedNestedTypedefs(const RecordDecl *D);
   void DiagnoseUnusedDecl(const NamedDecl *ND);
 
@@ -5118,6 +5118,16 @@ class Sema final {
   /// conversion.
   ExprResult tryConvertExprToType(Expr *E, QualType Ty);
 
+  /// Conditionally issue a diagnostic based on the statement's reachability
+  /// analysis evaluation context.
+  ///
+  /// \param Statement If Statement is non-null, delay reporting the
+  /// diagnostic until the function body is parsed, and then do a basic
+  /// reachability analysis to determine if the statement is reachable.
+  /// If it is unreachable, the diagnostic will not be emitted.
+  bool DiagIfReachable(SourceLocation Loc, ArrayRef Stmts,
+   const PartialDiagnostic &PD);
+
   /// Conditionally issue a diagnostic based on the current
   /// evaluation context.
   ///

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8eee366fbec67..8d483f317a421 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -28,6 +28,7 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "

[PATCH] D110128: [Driver] Correctly handle static C++ standard library

2021-09-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Please mention GNU ld 2.25 (2014) in the description.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110128

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


[PATCH] D110128: [Driver] Correctly handle static C++ standard library

2021-09-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110128

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


[PATCH] D110116: [Clang] Ignore BTFTag attr if used as a type attribute

2021-09-22 Thread Yonghong Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb875343873a5: [Clang] Ignore BTFTag attr if used as a type 
attribute (authored by yonghong-song).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110116

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Sema/attr-btf_tag.c


Index: clang/test/Sema/attr-btf_tag.c
===
--- clang/test/Sema/attr-btf_tag.c
+++ clang/test/Sema/attr-btf_tag.c
@@ -40,3 +40,11 @@
 int __tag1 foo(struct t1 *arg __tag1, struct t2 *arg2) {
   return arg->a + arg2->a;
 }
+
+void * convert(long arg) {
+  /* FIXME: the attribute __tag1 is accepted but didn't really do type 
conversion
+   * or enforce type checking. This is to permit linux kernel build with 
btf_tag
+   * attribute.
+   */
+  return (void __tag1 *)arg;
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8127,6 +8127,12 @@
 case ParsedAttr::IgnoredAttribute:
   break;
 
+case ParsedAttr::AT_BTFTag:
+  // FIXME: Linux kernel may also use this attribute for type casting 
check,
+  // which clang doesn's support for now. Let us ignore them so linux 
kernel
+  // build won't break.
+  attr.setUsedAsTypeAttr();
+  break;
 case ParsedAttr::AT_MayAlias:
   // FIXME: This attribute needs to actually be handled, but if we ignore
   // it it breaks large amounts of Linux software.
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1704,6 +1704,7 @@
   case attr::UPtr:
   case attr::AddressSpace:
   case attr::CmseNSCall:
+  case attr::BTFTag:
 llvm_unreachable("This attribute should have been handled already");
 
   case attr::NSReturnsRetained:
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -2019,6 +2019,10 @@
 function, function parameter or variable declaration. If -g is specified,
 the ``ARGUMENT`` info will be preserved in IR and be emitted to dwarf.
 For BPF targets, the ``ARGUMENT`` info will be emitted to .BTF ELF section too.
+
+The attribute can also be used as a type qualifier. Right now it is accepted
+and silently ignored in order to permit the linux kernel to build with the
+attribute.
   }];
 }
 
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1835,7 +1835,7 @@
   let LangOpts = [COnly];
 }
 
-def BTFTag : InheritableAttr {
+def BTFTag : DeclOrTypeAttr {
   let Spellings = [Clang<"btf_tag">];
   let Args = [StringArgument<"BTFTag">];
   let Subjects = SubjectList<[Var, Function, Record, Field], ErrorDiag>;


Index: clang/test/Sema/attr-btf_tag.c
===
--- clang/test/Sema/attr-btf_tag.c
+++ clang/test/Sema/attr-btf_tag.c
@@ -40,3 +40,11 @@
 int __tag1 foo(struct t1 *arg __tag1, struct t2 *arg2) {
   return arg->a + arg2->a;
 }
+
+void * convert(long arg) {
+  /* FIXME: the attribute __tag1 is accepted but didn't really do type conversion
+   * or enforce type checking. This is to permit linux kernel build with btf_tag
+   * attribute.
+   */
+  return (void __tag1 *)arg;
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8127,6 +8127,12 @@
 case ParsedAttr::IgnoredAttribute:
   break;
 
+case ParsedAttr::AT_BTFTag:
+  // FIXME: Linux kernel may also use this attribute for type casting check,
+  // which clang doesn's support for now. Let us ignore them so linux kernel
+  // build won't break.
+  attr.setUsedAsTypeAttr();
+  break;
 case ParsedAttr::AT_MayAlias:
   // FIXME: This attribute needs to actually be handled, but if we ignore
   // it it breaks large amounts of Linux software.
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1704,6 +1704,7 @@
   case attr::UPtr:
   case attr::AddressSpace:
   case attr::CmseNSCall:
+  case attr::BTFTag:
 llvm_unreachable("This attribute should have been handled already");
 
   case attr::NSReturnsRetained:
Index: clang/include/clang/Basic/AttrDocs.td

[clang] b875343 - [Clang] Ignore BTFTag attr if used as a type attribute

2021-09-22 Thread Yonghong Song via cfe-commits

Author: Yonghong Song
Date: 2021-09-22T13:48:29-07:00
New Revision: b875343873a584965daf507d73ff1fe71eab1953

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

LOG: [Clang] Ignore BTFTag attr if used as a type attribute

Currently, linux kernel has a __user attribute ([1]) defined as
   __attribute__((noderef, address_space(__user)))
which is used by sparse tool ([2]) to do some
type checking of pointers to user space memory.
During normal compilation, __user will be defined
to nothing so it won't have an impact on compilation.

The btf_tag attribute, which is motivated by
carrying linux kernel annotations into dwarf/BTF,
is introduced in [3]. We intended to define __user as
   __attribute__((btf_tag("user")))
so such information will be encoded in dwarf/BTF
and can be used later by bpf verification or other
tracing tools.

But linux kernel __user attribute is also used during
type conversion which btf_tag doesn't support ([4]) since
such type conversion is only used for compiler analysis
and not encoded in dwarf/btf. Theoretically, it is
possible for clang to understand these tags and
do a sparse-like type checking work. But I would like
to leave that to future work and for now suggest simply
ignore these btf_tag attributes if they are used
as type attributes.

  [1] 
https://github.com/torvalds/linux/blob/master/include/linux/compiler_types.h#L10
  [2] https://sparse.docs.kernel.org/en/latest/
  [3] https://reviews.llvm.org/D106614
  [4] https://github.com/torvalds/linux/blob/master/fs/binfmt_flat.c#L135

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

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/AST/TypePrinter.cpp
clang/lib/Sema/SemaType.cpp
clang/test/Sema/attr-btf_tag.c

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index a54039501a7f7..00e847bc5d2fb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1835,7 +1835,7 @@ def BPFPreserveAccessIndex : InheritableAttr,
   let LangOpts = [COnly];
 }
 
-def BTFTag : InheritableAttr {
+def BTFTag : DeclOrTypeAttr {
   let Spellings = [Clang<"btf_tag">];
   let Args = [StringArgument<"BTFTag">];
   let Subjects = SubjectList<[Var, Function, Record, Field], ErrorDiag>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b2b41c3bb4197..d3b0de06e7172 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2019,6 +2019,10 @@ targets. This attribute may be attached to a 
struct/union, struct/union field,
 function, function parameter or variable declaration. If -g is specified,
 the ``ARGUMENT`` info will be preserved in IR and be emitted to dwarf.
 For BPF targets, the ``ARGUMENT`` info will be emitted to .BTF ELF section too.
+
+The attribute can also be used as a type qualifier. Right now it is accepted
+and silently ignored in order to permit the linux kernel to build with the
+attribute.
   }];
 }
 

diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 3c7a6b8b9e953..2805916b1f7bb 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1704,6 +1704,7 @@ void TypePrinter::printAttributedAfter(const 
AttributedType *T,
   case attr::UPtr:
   case attr::AddressSpace:
   case attr::CmseNSCall:
+  case attr::BTFTag:
 llvm_unreachable("This attribute should have been handled already");
 
   case attr::NSReturnsRetained:

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index d2d54281c63e0..11a6d3faf2dd6 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8127,6 +8127,12 @@ static void processTypeAttrs(TypeProcessingState &state, 
QualType &type,
 case ParsedAttr::IgnoredAttribute:
   break;
 
+case ParsedAttr::AT_BTFTag:
+  // FIXME: Linux kernel may also use this attribute for type casting 
check,
+  // which clang doesn's support for now. Let us ignore them so linux 
kernel
+  // build won't break.
+  attr.setUsedAsTypeAttr();
+  break;
 case ParsedAttr::AT_MayAlias:
   // FIXME: This attribute needs to actually be handled, but if we ignore
   // it it breaks large amounts of Linux software.

diff  --git a/clang/test/Sema/attr-btf_tag.c b/clang/test/Sema/attr-btf_tag.c
index 88452fa875b1a..2ba2515868344 100644
--- a/clang/test/Sema/attr-btf_tag.c
+++ b/clang/test/Sema/attr-btf_tag.c
@@ -40,3 +40,11 @@ int __tag2 __tag3 foo(struct t1 *arg, struct t2 *arg2);
 int __tag1 foo(struct t1 *arg __tag1, struct t2 *arg2) {
   return arg->a + arg2->a;
 }
+
+void * convert(long arg) {
+  /* FIXME: the attribute __tag1 is accepted but d

[PATCH] D110089: [CUDA] Implement experimental support for texture lookups.

2021-09-22 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 374362.
tra added a comment.

Require c++11 for texture support.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110089

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_cuda_runtime_wrapper.h
  clang/lib/Headers/__clang_cuda_texture_intrinsics.h

Index: clang/lib/Headers/__clang_cuda_texture_intrinsics.h
===
--- /dev/null
+++ clang/lib/Headers/__clang_cuda_texture_intrinsics.h
@@ -0,0 +1,700 @@
+/*===--- __clang_cuda_texture_intrinsics.h - Device-side texture support ---===
+ *
+ * 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
+ *
+ *===---===
+ *
+ * This header provides in-header implmentations for NVCC's built-in
+ * __nv_tex_surf_handler() which is used by CUDA's texture-related headers.  The
+ * built-in is unusual as it's actually a set of function overloads that use the
+ * first string literal argument as one of the overload parameters. We can not
+ * implement is directly with C++. Instead, we convert the string literal into a
+ * numberic value and use that to parametrize the implementations.
+ */
+#ifndef __CLANG_CUDA_TEXTURE_INTRINSICS_H__
+#define __CLANG_CUDA_TEXTURE_INTRINSICS_H__
+#ifndef __CUDA__
+#error "This file is for CUDA compilation only."
+#endif
+
+#include 
+
+// __nv_tex_surf_handler() provided by this header as a macro.
+#define __nv_tex_surf_handler(__op, __ptr, ...)\
+  __cuda_tex::__tex_fetch<__cuda_tex::__Tag<__cuda_tex::__tex_op_hash(__op)>>( \
+  __ptr, __VA_ARGS__)
+
+#pragma push_macro("__Args")
+#pragma push_macro("__ID")
+#pragma push_macro("__ID")
+#pragma push_macro("__IDV")
+#pragma push_macro("__IMPL_2DGATHER")
+#pragma push_macro("__IMPL_ALIAS")
+#pragma push_macro("__IMPL_ALIASI")
+#pragma push_macro("__IMPL_F1")
+#pragma push_macro("__IMPL_F3")
+#pragma push_macro("__IMPL_F3N")
+#pragma push_macro("__IMPL_F3S")
+#pragma push_macro("__IMPL_S")
+#pragma push_macro("__IMPL_S3")
+#pragma push_macro("__IMPL_S3I")
+#pragma push_macro("__IMPL_S3N")
+#pragma push_macro("__IMPL_S3NI")
+#pragma push_macro("__IMPL_S3S")
+#pragma push_macro("__IMPL_S3SI")
+#pragma push_macro("__IMPL_SI")
+#pragma push_macro("__L")
+#pragma push_macro("__STRIP_PARENS")
+#pragma push_macro("__ASM_OUT")
+#pragma push_macro("__ASM_OUTP")
+
+// Put all functions into anonymous namespace so they have internal linkage.
+namespace {
+
+// Put the implmentation into its own namespace so we don't pollute the TU.
+namespace __cuda_tex {
+
+// Perfect hash function and its helpers for converting a string literal into a
+// numeric value which can be used to parametrize a template. We can not use
+// string literals for that as that would require C++20.
+//
+// The hash function was generated with 'gperf' and manually converted into
+// constexpr equivalent.
+// TODO: add a test.
+
+constexpr size_t __tex_len(const char *s) {
+  return (s[0] == 0)? 0
+ : (s[1] == 0)  ? 1
+ : (s[2] == 0)  ? 2
+ : (s[3] == 0)  ? 3
+ : (s[4] == 0)  ? 4
+ : (s[5] == 0)  ? 5
+ : (s[6] == 0)  ? 6
+ : (s[7] == 0)  ? 7
+ : (s[8] == 0)  ? 8
+ : (s[9] == 0)  ? 9
+ : (s[10] == 0) ? 10
+ : (s[11] == 0) ? 11
+ : (s[12] == 0) ? 12
+ : (s[13] == 0) ? 13
+ : (s[14] == 0) ? 14
+ : (s[15] == 0) ? 15
+ : (s[16] == 0) ? 16
+ : (s[17] == 0) ? 17
+ : (s[18] == 0) ? 18
+ : (s[19] == 0) ? 19
+ : (s[20] == 0) ? 20
+ : (s[21] == 0) ? 21
+ : (s[22] == 0) ? 22
+ : (s[23] == 0) ? 23
+ : (s[24] == 0) ? 24
+ : (s[25] == 0) ? 25
+ : (s[26] == 0) ? 26
+ : (s[27] == 0) ? 27
+ : (s[28] == 0) ? 28
+ : (s[29] == 0) ? 29
+ : (s[30] == 0) ? 30
+ : (s[31] == 0) ? 31
+: 32;
+}
+
+constexpr unsigned char __tex_hash_map(unsigned char c) {
+  return (c == 49)? 10
+ : (c == 50)  ? 0
+ : (c == 51)  ? 100
+ : (c == 52)  ? 30
+ : (c == 67)  ? 10
+ : (c == 68)  ? 0
+ : (c == 69)  ? 25
+ : (c == 72)  ? 70
+ : (c == 77)  ? 0
+ : (c == 96)  ? 44
+ : (c == 99)  ? 10
+ : (c == 100) ? 5
+ : (c == 101) ? 60
+ : (c == 102) ? 40
+ : (c == 103) ? 70
+ : (c == 104) ? 25
+ : (c == 112) ? 0
+ : (c == 114) ? 45
+ : (c == 117) ? 5
+ : (c == 118) ? 85
+ : (c == 120) ? 20
+  : 225;
+}
+
+constexpr unsigned int __tex_op_hash(const char *str) {
+  return __tex_len(str) + __tex_has

[PATCH] D110089: [CUDA] Implement experimental support for texture lookups.

2021-09-22 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 374360.
tra added a comment.

Switched to purely in-header implementation based on constexpr perfect hash.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110089

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_cuda_runtime_wrapper.h
  clang/lib/Headers/__clang_cuda_texture_intrinsics.h

Index: clang/lib/Headers/__clang_cuda_texture_intrinsics.h
===
--- /dev/null
+++ clang/lib/Headers/__clang_cuda_texture_intrinsics.h
@@ -0,0 +1,700 @@
+/*===--- __clang_cuda_texture_intrinsics.h - Device-side texture support ---===
+ *
+ * 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
+ *
+ *===---===
+ *
+ * This header provides in-header implmentations for NVCC's built-in
+ * __nv_tex_surf_handler() which is used by CUDA's texture-related headers.  The
+ * built-in is unusual as it's actually a set of function overloads that use the
+ * first string literal argument as one of the overload parameters. We can not
+ * implement is directly with C++. Instead, we convert the string literal into a
+ * numberic value and use that to parametrize the implementations.
+ */
+#ifndef __CLANG_CUDA_TEXTURE_INTRINSICS_H__
+#define __CLANG_CUDA_TEXTURE_INTRINSICS_H__
+#ifndef __CUDA__
+#error "This file is for CUDA compilation only."
+#endif
+
+#include 
+
+// __nv_tex_surf_handler() provided by this header as a macro.
+#define __nv_tex_surf_handler(__op, __ptr, ...)\
+  __cuda_tex::__tex_fetch<__cuda_tex::__Tag<__cuda_tex::__tex_op_hash(__op)>>( \
+  __ptr, __VA_ARGS__)
+
+#pragma push_macro("__Args")
+#pragma push_macro("__ID")
+#pragma push_macro("__ID")
+#pragma push_macro("__IDV")
+#pragma push_macro("__IMPL_2DGATHER")
+#pragma push_macro("__IMPL_ALIAS")
+#pragma push_macro("__IMPL_ALIASI")
+#pragma push_macro("__IMPL_F1")
+#pragma push_macro("__IMPL_F3")
+#pragma push_macro("__IMPL_F3N")
+#pragma push_macro("__IMPL_F3S")
+#pragma push_macro("__IMPL_S")
+#pragma push_macro("__IMPL_S3")
+#pragma push_macro("__IMPL_S3I")
+#pragma push_macro("__IMPL_S3N")
+#pragma push_macro("__IMPL_S3NI")
+#pragma push_macro("__IMPL_S3S")
+#pragma push_macro("__IMPL_S3SI")
+#pragma push_macro("__IMPL_SI")
+#pragma push_macro("__L")
+#pragma push_macro("__STRIP_PARENS")
+#pragma push_macro("__ASM_OUT")
+#pragma push_macro("__ASM_OUTP")
+
+// Put all functions into anonymous namespace so they have internal linkage.
+namespace {
+
+// Put the implmentation into its own namespace so we don't pollute the TU.
+namespace __cuda_tex {
+
+// Perfect hash function and its helpers for converting a string literal into a
+// numeric value which can be used to parametrize a template. We can not use
+// string literals for that as that would require C++20.
+//
+// The hash function was generated with 'gperf' and manually converted into
+// constexpr equivalent.
+// TODO: add a test.
+
+constexpr size_t __tex_len(const char *s) {
+  return (s[0] == 0)? 0
+ : (s[1] == 0)  ? 1
+ : (s[2] == 0)  ? 2
+ : (s[3] == 0)  ? 3
+ : (s[4] == 0)  ? 4
+ : (s[5] == 0)  ? 5
+ : (s[6] == 0)  ? 6
+ : (s[7] == 0)  ? 7
+ : (s[8] == 0)  ? 8
+ : (s[9] == 0)  ? 9
+ : (s[10] == 0) ? 10
+ : (s[11] == 0) ? 11
+ : (s[12] == 0) ? 12
+ : (s[13] == 0) ? 13
+ : (s[14] == 0) ? 14
+ : (s[15] == 0) ? 15
+ : (s[16] == 0) ? 16
+ : (s[17] == 0) ? 17
+ : (s[18] == 0) ? 18
+ : (s[19] == 0) ? 19
+ : (s[20] == 0) ? 20
+ : (s[21] == 0) ? 21
+ : (s[22] == 0) ? 22
+ : (s[23] == 0) ? 23
+ : (s[24] == 0) ? 24
+ : (s[25] == 0) ? 25
+ : (s[26] == 0) ? 26
+ : (s[27] == 0) ? 27
+ : (s[28] == 0) ? 28
+ : (s[29] == 0) ? 29
+ : (s[30] == 0) ? 30
+ : (s[31] == 0) ? 31
+: 32;
+}
+
+constexpr unsigned char __tex_hash_map(unsigned char c) {
+  return (c == 49)? 10
+ : (c == 50)  ? 0
+ : (c == 51)  ? 100
+ : (c == 52)  ? 30
+ : (c == 67)  ? 10
+ : (c == 68)  ? 0
+ : (c == 69)  ? 25
+ : (c == 72)  ? 70
+ : (c == 77)  ? 0
+ : (c == 96)  ? 44
+ : (c == 99)  ? 10
+ : (c == 100) ? 5
+ : (c == 101) ? 60
+ : (c == 102) ? 40
+ : (c == 103) ? 70
+ : (c == 104) ? 25
+ : (c == 112) ? 0
+ : (c == 114) ? 45
+ : (c == 117) ? 5
+ : (c == 118) ? 85
+ : (c == 120) ? 20
+  : 225;
+}
+
+constexpr unsigned int __tex_op_hash(const char *s

[PATCH] D110116: [Clang] Ignore BTFTag attr if used as a type attribute

2021-09-22 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 374358.
yonghong-song added a comment.

- to adjust some wording in AttrDocs.td based on Aaron's suggestion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110116

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Sema/attr-btf_tag.c


Index: clang/test/Sema/attr-btf_tag.c
===
--- clang/test/Sema/attr-btf_tag.c
+++ clang/test/Sema/attr-btf_tag.c
@@ -40,3 +40,11 @@
 int __tag1 foo(struct t1 *arg __tag1, struct t2 *arg2) {
   return arg->a + arg2->a;
 }
+
+void * convert(long arg) {
+  /* FIXME: the attribute __tag1 is accepted but didn't really do type 
conversion
+   * or enforce type checking. This is to permit linux kernel build with 
btf_tag
+   * attribute.
+   */
+  return (void __tag1 *)arg;
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8127,6 +8127,12 @@
 case ParsedAttr::IgnoredAttribute:
   break;
 
+case ParsedAttr::AT_BTFTag:
+  // FIXME: Linux kernel may also use this attribute for type casting 
check,
+  // which clang doesn's support for now. Let us ignore them so linux 
kernel
+  // build won't break.
+  attr.setUsedAsTypeAttr();
+  break;
 case ParsedAttr::AT_MayAlias:
   // FIXME: This attribute needs to actually be handled, but if we ignore
   // it it breaks large amounts of Linux software.
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1704,6 +1704,7 @@
   case attr::UPtr:
   case attr::AddressSpace:
   case attr::CmseNSCall:
+  case attr::BTFTag:
 llvm_unreachable("This attribute should have been handled already");
 
   case attr::NSReturnsRetained:
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -2019,6 +2019,10 @@
 function, function parameter or variable declaration. If -g is specified,
 the ``ARGUMENT`` info will be preserved in IR and be emitted to dwarf.
 For BPF targets, the ``ARGUMENT`` info will be emitted to .BTF ELF section too.
+
+The attribute can also be used as a type qualifier. Right now it is accepted
+and silently ignored in order to permit the linux kernel to build with the
+attribute.
   }];
 }
 
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1835,7 +1835,7 @@
   let LangOpts = [COnly];
 }
 
-def BTFTag : InheritableAttr {
+def BTFTag : DeclOrTypeAttr {
   let Spellings = [Clang<"btf_tag">];
   let Args = [StringArgument<"BTFTag">];
   let Subjects = SubjectList<[Var, Function, Record, Field], ErrorDiag>;


Index: clang/test/Sema/attr-btf_tag.c
===
--- clang/test/Sema/attr-btf_tag.c
+++ clang/test/Sema/attr-btf_tag.c
@@ -40,3 +40,11 @@
 int __tag1 foo(struct t1 *arg __tag1, struct t2 *arg2) {
   return arg->a + arg2->a;
 }
+
+void * convert(long arg) {
+  /* FIXME: the attribute __tag1 is accepted but didn't really do type conversion
+   * or enforce type checking. This is to permit linux kernel build with btf_tag
+   * attribute.
+   */
+  return (void __tag1 *)arg;
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8127,6 +8127,12 @@
 case ParsedAttr::IgnoredAttribute:
   break;
 
+case ParsedAttr::AT_BTFTag:
+  // FIXME: Linux kernel may also use this attribute for type casting check,
+  // which clang doesn's support for now. Let us ignore them so linux kernel
+  // build won't break.
+  attr.setUsedAsTypeAttr();
+  break;
 case ParsedAttr::AT_MayAlias:
   // FIXME: This attribute needs to actually be handled, but if we ignore
   // it it breaks large amounts of Linux software.
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1704,6 +1704,7 @@
   case attr::UPtr:
   case attr::AddressSpace:
   case attr::CmseNSCall:
+  case attr::BTFTag:
 llvm_unreachable("This attribute should have been handled already");
 
   case attr::NSReturnsRetained:
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basi

[PATCH] D109707: [HIP] [AlwaysInliner] Disable AlwaysInliner to eliminate undefined symbols

2021-09-22 Thread Anshil Gandhi via Phabricator via cfe-commits
gandhi21299 updated this revision to Diff 374354.
gandhi21299 added a comment.

- replaced a `cast` with a `dyn_cast` since the return value from 
`getCalleeFunction()` is not always a Function
- `RUN on line 2` was causing 2 more scalar registers to be used on tonga due 
to @func_alias not being inlined, hence I eliminated that test
- `RUN on line 3` generated a call instruction to an aliased function which is 
not supported on r600 (according to @arsenm ), hence I eliminated that test as 
well


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109707

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCUDA/amdgpu-alias-undef-symbols.cu
  llvm/lib/Target/AMDGPU/AMDGPUAlwaysInlinePass.cpp
  llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
  llvm/test/CodeGen/AMDGPU/inline-calls.ll


Index: llvm/test/CodeGen/AMDGPU/inline-calls.ll
===
--- llvm/test/CodeGen/AMDGPU/inline-calls.ll
+++ llvm/test/CodeGen/AMDGPU/inline-calls.ll
@@ -1,6 +1,4 @@
 ; RUN: llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck  
%s
-; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck  %s
-; RUN: llc -march=r600 -mcpu=redwood -verify-machineinstrs < %s | FileCheck %s
 
 ; ALL-NOT: {{^}}func:
 define internal i32 @func(i32 %a) {
@@ -18,8 +16,8 @@
   ret void
 }
 
-; CHECK-NOT: func_alias
-; ALL-NOT: func_alias
+; CHECK: func_alias
+; ALL: func_alias
 @func_alias = alias i32 (i32), i32 (i32)* @func
 
 ; ALL: {{^}}kernel3:
Index: llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
===
--- llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
@@ -62,7 +62,7 @@
 return nullptr;
   }
 
-  return cast(Op.getGlobal());
+  return dyn_cast(Op.getGlobal());
 }
 
 static bool hasAnyNonFlatUseOfReg(const MachineRegisterInfo &MRI,
Index: llvm/lib/Target/AMDGPU/AMDGPUAlwaysInlinePass.cpp
===
--- llvm/lib/Target/AMDGPU/AMDGPUAlwaysInlinePass.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUAlwaysInlinePass.cpp
@@ -93,6 +93,8 @@
 
   for (GlobalAlias &A : M.aliases()) {
 if (Function* F = dyn_cast(A.getAliasee())) {
+  if (A.getLinkage() != GlobalValue::InternalLinkage)
+continue;
   A.replaceAllUsesWith(F);
   AliasesToRemove.push_back(&A);
 }
Index: clang/test/CodeGenCUDA/amdgpu-alias-undef-symbols.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/amdgpu-alias-undef-symbols.cu
@@ -0,0 +1,15 @@
+// RUN: %clang --offload-arch=gfx906 --cuda-device-only -x hip -emit-llvm -S 
-o - %s \
+// RUN:   -fgpu-rdc -O3 -mllvm -amdgpu-early-inline-all=true -mllvm 
-amdgpu-function-calls=false | \
+// RUN:   FileCheck %s
+
+#include "Inputs/cuda.h"
+
+// CHECK: %struct.B = type { i8 }
+struct B {
+
+  // CHECK: @_ZN1BC1Ei = hidden unnamed_addr alias void (%struct.B*, i32), 
void (%struct.B*, i32)* @_ZN1BC2Ei
+  __device__ B(int x);
+};
+
+__device__ B::B(int x) {
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5084,9 +5084,9 @@
   }
 
   // Enable -mconstructor-aliases except on darwin, where we have to work 
around
-  // a linker bug (see ), and CUDA/AMDGPU device code,
-  // where aliases aren't supported.
-  if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX() && !RawTriple.isAMDGPU())
+  // a linker bug (see ), and CUDA device code, where
+  // aliases aren't supported.
+  if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX())
 CmdArgs.push_back("-mconstructor-aliases");
 
   // Darwin's kernel doesn't support guard variables; just die if we


Index: llvm/test/CodeGen/AMDGPU/inline-calls.ll
===
--- llvm/test/CodeGen/AMDGPU/inline-calls.ll
+++ llvm/test/CodeGen/AMDGPU/inline-calls.ll
@@ -1,6 +1,4 @@
 ; RUN: llc -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck  %s
-; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s | FileCheck  %s
-; RUN: llc -march=r600 -mcpu=redwood -verify-machineinstrs < %s | FileCheck %s
 
 ; ALL-NOT: {{^}}func:
 define internal i32 @func(i32 %a) {
@@ -18,8 +16,8 @@
   ret void
 }
 
-; CHECK-NOT: func_alias
-; ALL-NOT: func_alias
+; CHECK: func_alias
+; ALL: func_alias
 @func_alias = alias i32 (i32), i32 (i32)* @func
 
 ; ALL: {{^}}kernel3:
Index: llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
===
--- llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
@@ -62,7 +62,7 @@
 return nullptr;
 

[PATCH] D110111: [WebAssembly] Add relaxed-simd feature

2021-09-22 Thread Thomas Lively via Phabricator via cfe-commits
tlively accepted this revision.
tlively added a comment.
This revision is now accepted and ready to land.

Great, thanks! I will take care of landing this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110111

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


[PATCH] D110280: [modules] Fix IRGen assertion on accessing ObjC ivar inside a method.

2021-09-22 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added inline comments.



Comment at: clang/lib/AST/DeclObjC.cpp:81-84
   lookup_result R = lookup(Id);
   for (lookup_iterator Ivar = R.begin(), IvarEnd = R.end();
Ivar != IvarEnd; ++Ivar) {
+if (auto *ivar = dyn_cast((*Ivar)->getCanonicalDecl()))

Don't really know what are the common patterns for name lookup and if this 
approach is acceptable. For C we call `LookupResult::resolveKind` to deal with 
multiple decls (and to avoid ambiguous lookup errors) but that's not available 
for `lookup_result` (aka `DeclContextLookupResult`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110280

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


[PATCH] D110279: [OpenMP][Offloading] Change `bool IsSPMD` to `int8_t Mode` in `__kmpc_target_init` and `__kmpc_target_deinit`

2021-09-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D110279#3016332 , @jdoerfert wrote:

> This should not change anything, right? Please confirm running a non-trivial 
> example, like miniqmc or so, and then this is good to go.

miniQMC report 26/26 Passed. Will land the patch if Phabricator comes all green.

  âžś  OMP_NUM_THREADS=4 ctest .
  Test project /home/shiltian/Documents/apps/miniqmc/build
Start  1: unit_test_utilities
   1/26 Test  #1: unit_test_utilities    Passed
0.15 sec
Start  2: unit_test_particle
   2/26 Test  #2: unit_test_particle .   Passed
0.06 sec
Start  3: unit_test_omptarget_math
   3/26 Test  #3: unit_test_omptarget_math ...   Passed
0.20 sec
Start  4: unit_test_omptarget_reduction
   4/26 Test  #4: unit_test_omptarget_reduction ..   Passed
0.19 sec
Start  5: unit_test_omptarget_target_task
   5/26 Test  #5: unit_test_omptarget_target_task    Passed
0.33 sec
Start  6: unit_test_omptarget_complex
   6/26 Test  #6: unit_test_omptarget_complex    Passed
0.18 sec
Start  7: unit_test_omptarget_complex_reduction
   7/26 Test  #7: unit_test_omptarget_complex_reduction ..   Passed
0.20 sec
Start  8: unit_test_omptarget_math_with_complex_header
   8/26 Test  #8: unit_test_omptarget_math_with_complex_header ...   Passed
0.07 sec
Start  9: unit_test_omptarget_memory_interop
   9/26 Test  #9: unit_test_omptarget_memory_interop .   Passed
0.18 sec
Start 10: unit_test_omptarget_partial_update
  10/26 Test #10: unit_test_omptarget_partial_update .   Passed
0.18 sec
Start 11: unit_test_omptarget_partial_update_full
  11/26 Test #11: unit_test_omptarget_partial_update_full    Passed
0.35 sec
Start 12: unit_test_omptarget_map_always
  12/26 Test #12: unit_test_omptarget_map_always .   Passed
0.19 sec
Start 13: unit_test_omptarget_icpx_opencl_wrong_number
  13/26 Test #13: unit_test_omptarget_icpx_opencl_wrong_number ...   Passed
0.21 sec
Start 14: unit_test_omptarget_nowait_taskwait
  14/26 Test #14: unit_test_omptarget_nowait_taskwait    Passed
0.35 sec
Start 15: unit_test_omptarget_taskloop
  15/26 Test #15: unit_test_omptarget_taskloop ...   Passed
0.06 sec
Start 16: unit_test_omptarget_runtime_mem
  16/26 Test #16: unit_test_omptarget_runtime_mem    Passed
0.18 sec
Start 17: unit_test_omptarget_map_transfer
  17/26 Test #17: unit_test_omptarget_map_transfer ...   Passed
0.55 sec
Start 18: unit_test_omptarget_allocator
  18/26 Test #18: unit_test_omptarget_allocator ..   Passed
0.18 sec
Start 19: unit_test_wavefunction
  19/26 Test #19: unit_test_wavefunction .   Passed
0.07 sec
Start 20: unit_test_Drivers
  20/26 Test #20: unit_test_Drivers ..   Passed
0.06 sec
Start 21: unit_test_assignDevice
  21/26 Test #21: unit_test_assignDevice .   Passed
0.09 sec
Start 22: miniqmc-g111-r1-t16
  22/26 Test #22: miniqmc-g111-r1-t16    Passed
8.12 sec
Start 23: miniqmc_sync_move-g111-r1-t16
  23/26 Test #23: miniqmc_sync_move-g111-r1-t16 ..   Passed
4.95 sec
Start 24: check_spo-g111-r1-t16
  24/26 Test #24: check_spo-g111-r1-t16 ..   Passed
8.29 sec
Start 25: check_spo_batched-g111-r1-t16
  25/26 Test #25: check_spo_batched-g111-r1-t16 ..   Passed
5.22 sec
Start 26: check_wfc-g111-r1-t16
  26/26 Test #26: check_wfc-g111-r1-t16 ..   Passed
0.67 sec
  
  100% tests passed, 0 tests failed out of 26
  
  Label Time Summary:
  check  = 226.94 sec*proc (3 tests)
  miniqmc= 209.11 sec*proc (2 tests)
  unit   =   4.05 sec*proc (21 tests)
  
  Total Test time (real) =  31.33 sec


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110279

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


[PATCH] D110127: [Clang] Support typedef with btf_tag attributes

2021-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D110127#3013876 , @yonghong-song 
wrote:

> You can see that it doesn't matter where the attribute is placed, the 
> attribute is always attached to the typedef.
> I think the reason is for declarations, we only allow the btf_tag attribute 
> to be placed for record, field, var, func, typedef,
> and "unsigned *" does not qualify, so the attribute is applied to typedef.

Agreed. If this attribute appertains to the type, then it goes through 
SemaType.cpp and may require extra work to encode the information into the type 
system. If it appertains to the declaration, then what's in SemaDeclAttr.cpp is 
fine, but then I have questions about the use of the attribute with cast 
notation from D110116  where this is being 
used definitely as a type attribute.

One confounding factor here is that `__attribute__` will slide around to 
whatever makes sense. You should try your examples with `[[]]` in C2x mode as 
well -- the placement of the attribute syntax is strongly tied to what the 
attribute applies to.

>> I'm asking because this raises other questions. For example:
>>
>>   void func(int i);
>>   void func(int __attribute__((btf_tag("__user"))) i);
>>
>> Is the second a valid redeclaration of the first? Additionally:
>
> This should be okay as btf_tag is accumulative attribute.

Okay, this is sounding more and more like a declaration attribute.

>>   __attribute__((overloadable)) void func(int i) { puts("one"); }
>>   __attribute__((overloadable)) void func(int 
>> __attribute__((btf_tag("__user"))) i) { puts("two"); }
>>
>> Is this a valid overload set because of the type attribute? Along the same 
>> lines, does adding this attribute to the type cause any ABI differences in 
>> how the type is passed?
>
> btf_tag is for C only so overload function case won't happen.

That's incorrect -- Clang supports attribute overloadable in C: 
https://godbolt.org/z/eThKsn3zM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110127

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


[PATCH] D110287: [modules] While merging ObjCInterfaceDecl definitions, merge them as decl contexts too.

2021-09-22 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: rsmith, bruno, jansvoboda11.
Herald added a subscriber: ributzka.
vsapsai requested review of this revision.
Herald added a project: clang.

While working on https://reviews.llvm.org/D110280 I've tried to merge
decl contexts as it seems to be correct and matching our handling of
decl contexts from different modules. It's not required for the fix in
https://reviews.llvm.org/D110280 but it revealed a missing diagnostic,
so separating this change into a separate commit.

Renamed some variables to distinguish diagnostic like "declaration of
'x' does not match" for different cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110287

Files:
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/odr_hash.mm


Index: clang/test/Modules/odr_hash.mm
===
--- clang/test/Modules/odr_hash.mm
+++ clang/test/Modules/odr_hash.mm
@@ -241,12 +241,12 @@
 @end
 @interface Interface5  {
 @public
-  T x;
+  T y;
 }
 @end
 @interface Interface6  {
 @public
-  T1 x;
+  T1 z;
 }
 @end
 #elif defined(SECOND)
@@ -257,14 +257,21 @@
 @end
 @interface Interface5  {
 @public
-  T x;
+  T y;
 }
 @end
 @interface Interface6  {
 @public
-  T2 x;
+  T2 z;
 }
 @end
+#else
+// expected-error@first.h:* {{'Interface4::x' from module 'FirstModule' is not 
present in definition of 'Interface4' in module 'SecondModule'}}
+// expected-note@second.h:* {{declaration of 'x' does not match}}
+// expected-error@first.h:* {{'Interface5::y' from module 'FirstModule' is not 
present in definition of 'Interface5' in module 'SecondModule'}}
+// expected-note@second.h:* {{declaration of 'y' does not match}}
+// expected-error@first.h:* {{'Interface6::z' from module 'FirstModule' is not 
present in definition of 'Interface6' in module 'SecondModule'}}
+// expected-note@second.h:* {{declaration of 'z' does not match}}
 #endif
 
 namespace Types {
@@ -276,22 +283,22 @@
 };
 struct Invalid2 {
   Interface5 *I;
-  decltype(I->x) x;
+  decltype(I->y) y;
 };
 struct Invalid3 {
   Interface6 *I;
-  decltype(I->x) x;
+  decltype(I->z) z;
 };
 #else
 Invalid1 i1;
 // expected-error@first.h:* {{'Types::ObjCTypeParam::Invalid1::x' from module 
'FirstModule' is not present in definition of 'Types::ObjCTypeParam::Invalid1' 
in module 'SecondModule'}}
 // expected-note@second.h:* {{declaration of 'x' does not match}}
 Invalid2 i2;
-// expected-error@first.h:* {{'Types::ObjCTypeParam::Invalid2::x' from module 
'FirstModule' is not present in definition of 'Types::ObjCTypeParam::Invalid2' 
in module 'SecondModule'}}
-// expected-note@second.h:* {{declaration of 'x' does not match}}
+// expected-error@first.h:* {{'Types::ObjCTypeParam::Invalid2::y' from module 
'FirstModule' is not present in definition of 'Types::ObjCTypeParam::Invalid2' 
in module 'SecondModule'}}
+// expected-note@second.h:* {{declaration of 'y' does not match}}
 Invalid3 i3;
-// expected-error@first.h:* {{'Types::ObjCTypeParam::Invalid3::x' from module 
'FirstModule' is not present in definition of 'Types::ObjCTypeParam::Invalid3' 
in module 'SecondModule'}}
-// expected-note@second.h:* {{declaration of 'x' does not match}}
+// expected-error@first.h:* {{'Types::ObjCTypeParam::Invalid3::z' from module 
'FirstModule' is not present in definition of 'Types::ObjCTypeParam::Invalid3' 
in module 'SecondModule'}}
+// expected-note@second.h:* {{declaration of 'z' does not match}}
 #endif
 
 }  // namespace ObjCTypeParam
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1177,6 +1177,12 @@
 
 void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D,
  struct ObjCInterfaceDecl::DefinitionData &&NewDD) {
+  struct ObjCInterfaceDecl::DefinitionData &DD = D->data();
+  if (DD.Definition != NewDD.Definition) {
+Reader.MergedDeclContexts.insert(
+std::make_pair(NewDD.Definition, DD.Definition));
+  }
+
   // FIXME: odr checking?
 }
 


Index: clang/test/Modules/odr_hash.mm
===
--- clang/test/Modules/odr_hash.mm
+++ clang/test/Modules/odr_hash.mm
@@ -241,12 +241,12 @@
 @end
 @interface Interface5  {
 @public
-  T x;
+  T y;
 }
 @end
 @interface Interface6  {
 @public
-  T1 x;
+  T1 z;
 }
 @end
 #elif defined(SECOND)
@@ -257,14 +257,21 @@
 @end
 @interface Interface5  {
 @public
-  T x;
+  T y;
 }
 @end
 @interface Interface6  {
 @public
-  T2 x;
+  T2 z;
 }
 @end
+#else
+// expected-error@first.h:* {{'Interface4::x' from module 'FirstModule' is not present in definition of 'Interface4' in module 'SecondModule'}}
+// expected-note@second.h:* {{declaration of 'x' does not match}}
+// expected-error@first.h:* {{'Interface5::y' from module 'FirstModule' is not present in definition of 'Interface5' in module 'SecondModule'}}
+// ex

[PATCH] D110286: [WIP][Clang][OpenMP] Add new clang argument `-fopenmp-target-simd`

2021-09-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 created this revision.
Herald added subscribers: dexonsmith, dang, guansong, yaxunl.
tianshilei1992 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Currently an OpenMP thread is mapped to a hardware thread. In order to support
SIMD, we have to map an OpenMP thread to a warp (wavefront). This mapping has to
be determined when the kernel is launched, and the execution mode is encoded in
the `int8_t Mode` when calling `__kmpc_target_init`, which is introduced in
D110279 . However, we cannot determine if 
`simd` is used and then adjust `Mode`
accordingly in current Clang CodeGen because the function call to
`__kmpc_target_init` is emitted before the body of target region.

This patches adds a new clang argument `-fopenmp-target-simd` to emit code that
supports SIMD mapping. When this argument is set, no matter whether there is
`simd` directive in target region, the new mappig is always used. If it is not
set or `-fopenmp-no-target-simd` is set, the existing mapping will be used, and
`simd` directive will be ignored.

The reason we don't reuse `-fopenmp-simd` is the CodeGen of device code shares
some implementation with host code. `-fopenmp-simd` can change CodeGen, which we
don't expect to introduce any unknown effects.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110286

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3782,8 +3782,8 @@
   // '-mignore-xcoff-visibility' is implied. The generated command line will
   // contain both '-fvisibility default' and '-mignore-xcoff-visibility' and
   // subsequent calls to `CreateFromArgs`/`generateCC1CommandLine` will always
-  // produce the same arguments. 
- 
+  // produce the same arguments.
+
   if (T.isOSAIX() && (Args.hasArg(OPT_mignore_xcoff_visibility) ||
   !Args.hasArg(OPT_fvisibility)))
 Opts.IgnoreXCOFFVisibility = 1;
@@ -3863,6 +3863,10 @@
   Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_enable_irbuilder);
   bool IsTargetSpecified =
   Opts.OpenMPIsDevice || Args.hasArg(options::OPT_fopenmp_targets_EQ);
+  Opts.OpenMPTargetSimd =
+  IsTargetSpecified &&
+  Args.hasFlag(options::OPT_fopenmp_target_simd,
+   options::OPT_fno_openmp_target_simd, /*Default=*/false);
   Opts.OpenMPTargetNewRuntime =
   Opts.OpenMPIsDevice &&
   Args.hasArg(options::OPT_fopenmp_target_new_runtime);
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1805,7 +1805,7 @@
 
 defm protect_parens : BoolFOption<"protect-parens",
   LangOpts<"ProtectParens">, DefaultFalse,
-  PosFlag,
   NegFlag>;
@@ -2406,9 +2406,12 @@
   Group, Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
 def fopenmp_simd : Flag<["-"], "fopenmp-simd">, Group, Flags<[CC1Option, NoArgumentUnused]>,
   HelpText<"Emit OpenMP code only for SIMD-based constructs.">;
+def fopenmp_target_simd : Flag<["-"], "fopenmp-target-simd">, Group, Flags<[CC1Option, NoArgumentUnused]>,
+  HelpText<"Emit OpenMP target offloading code that supports SIMD execution.">;
 def fopenmp_enable_irbuilder : Flag<["-"], "fopenmp-enable-irbuilder">, Group, Flags<[CC1Option, NoArgumentUnused, HelpHidden]>,
   HelpText<"Use the experimental OpenMP-IR-Builder codegen path.">;
 def fno_openmp_simd : Flag<["-"], "fno-openmp-simd">, Group, Flags<[CC1Option, NoArgumentUnused]>;
+def fno_openmp_target_simd : Flag<["-"], "fno-openmp-target-simd">, Group, Flags<[CC1Option, NoArgumentUnused]>;
 def fopenmp_cuda_mode : Flag<["-"], "fopenmp-cuda-mode">, Group,
   Flags<[CC1Option, NoArgumentUnused, HelpHidden]>;
 def fno_openmp_cuda_mode : Flag<["-"], "fno-openmp-cuda-mode">, Group,
@@ -2548,7 +2551,7 @@
   ShouldParseIf;
 defm split_stack : BoolFOption<"split-stack",
   CodeGenOpts<"EnableSegmentedStacks">, DefaultFalse,
-  NegFlag, 
+  NegFlag,
   PosFlag>;
 def fstack_protector_all : Flag<["-"], "fstack-protector-all">, Group,
   HelpText<"Enable stack protectors for all functions">;
@@ -4575,7 +4578,7 @@
   HelpText<"Enable the old style PARAMETER statement">;
 def fintrinsic_modules_path : Separate<["-"], "fintrinsic-modules-path">,  Group, MetaVarName<"">,
   HelpText<"Specify where to find the compiled intrinsic modules">,
-  DocBrief<[{This option specifies the location of pre-compiled intrinsic modules, 
+  DocBrief<[{This option specifies the location of pre-compiled intrinsic modules,
   if they are not in the default locat

[PATCH] D110279: [OpenMP][Offloading] Change `bool IsSPMD` to `int8_t Mode` in `__kmpc_target_init` and `__kmpc_target_deinit`

2021-09-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

This should not change anything, right? Please confirm running a non-trivial 
example, like miniqmc or so, and then this is good to go.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110279

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


[PATCH] D110127: [Clang] Support typedef with btf_tag attributes

2021-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D110127#3013391 , @dblaikie wrote:

> Given this is about being preserved into debug info - I imagine it'll have 
> the same behavior as using a typedef in a function return type - whenever 
> that currently shows up in the DWARF, this attribute would. Where it doesn't, 
> this doesn't.
>
> So I wouldn't expect this feature to do any checking/require the typedef to 
> be used consistently - but fair questions to consider.

In that case, I'd assume this is a declaration attribute that appertains to the 
declaration of the typedef, and not to the underlying type. Basically, it 
sounds like this models more closely to the `nodebug` attribute than the 
`address_space` attribute: https://godbolt.org/z/zoo1xnG4n

(This matters because of the `[[clang::btf_tag(...)]]` spelling that's used in 
C2x.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110127

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


[PATCH] D110276: Clean up large copies of binaries copied into temp directories in tests

2021-09-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In D110276#3016295 , @thakis wrote:

> Oh, the win failure 
> (https://buildkite.com/llvm-project/premerge-checks/builds/57480#f7da3275-775a-4cf4-9624-d3539dd1f709)
>  might actually be real. Windows doesn't allow deleting files that are still 
> in use, and due to AV or similar, the file might still be in use for a bit 
> even after the program completes.

The failures I am seeing there are in a few other tests, not in the ones I 
modified. Can you confirm?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110276

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


[PATCH] D110276: Clean up large copies of binaries copied into temp directories in tests

2021-09-22 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Oh, the win failure 
(https://buildkite.com/llvm-project/premerge-checks/builds/57480#f7da3275-775a-4cf4-9624-d3539dd1f709)
 might actually be real. Windows doesn't allow deleting files that are still in 
use, and due to AV or similar, the file might still be in use for a bit even 
after the program completes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110276

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


[PATCH] D110116: [Clang] Ignore BTFTag attr if used as a type attribute

2021-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from a minor nit with documentation grammar.




Comment at: clang/include/clang/Basic/AttrDocs.td:2024
+The attribute can also be used as a type qualifier. Right now it is accepted
+and silently ignored in order to permit linux kernel build with the attribute.
   }];




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110116

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


[PATCH] D110276: Clean up large copies of binaries copied into temp directories in tests

2021-09-22 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

lg


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110276

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


[PATCH] D103938: Diagnose -Wunused-value based on CFG reachability

2021-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

The changes seem reasonable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103938

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


[PATCH] D110282: [PowerPC] SemaChecking for darn family of builtins

2021-09-22 Thread Albion Fung via Phabricator via cfe-commits
Conanap updated this revision to Diff 374329.
Conanap added a comment.

Added error testing


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

https://reviews.llvm.org/D110282

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-darn-32.c
  clang/test/CodeGen/builtins-ppc-xlcompat-darn.c
  clang/test/CodeGen/builtins-ppc-xlcompat-error.c
  clang/test/CodeGen/builtins-ppc.c

Index: clang/test/CodeGen/builtins-ppc.c
===
--- clang/test/CodeGen/builtins-ppc.c
+++ clang/test/CodeGen/builtins-ppc.c
@@ -36,16 +36,3 @@
   // CHECK: call double @llvm.ppc.setflm(double %1)
   res = __builtin_setflm(res);
 }
-
-void test_builtin_ppc_darn() {
-  volatile long res;
-  volatile int x;
-  // CHECK: call i64 @llvm.ppc.darn()
-  res = __builtin_darn();
-
-  // CHECK: call i64 @llvm.ppc.darnraw()
-  res = __builtin_darn_raw();
-
-  // CHECK: call i32 @llvm.ppc.darn32()
-  x = __builtin_darn_32();
-}
Index: clang/test/CodeGen/builtins-ppc-xlcompat-error.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-error.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-error.c
@@ -96,6 +96,14 @@
 unsigned long long testdivdeu(unsigned long long dividend, unsigned long long divisor) {
   return __divdeu(dividend, divisor); //expected-error {{this builtin is only available on 64-bit targets}}
 }
+
+int test_darn() {
+  return __darn(); //expected-error {{this builtin is only available on 64-bit targets}}
+}
+
+int test_darn_raw() {
+  return __darn_raw(); //expected-error {{this builtin is only available on 64-bit targets}}
+}
 #endif
 
 unsigned long test_mfspr(void) {
Index: clang/test/CodeGen/builtins-ppc-xlcompat-darn.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-darn.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-darn.c
@@ -5,12 +5,6 @@
 // RUN:   -emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
 // RUN: %clang_cc1 -triple powerpc64-unknown-aix \
 // RUN:-emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
-// RUN: %clang_cc1 -triple powerpc-unknown-unknown \
-// RUN:-emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
-// RUN: %clang_cc1 -triple powerpcle-unknown-unknown \
-// RUN:   -emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
-// RUN: %clang_cc1 -triple powerpc-unknown-aix \
-// RUN:-emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
 
 // The darn class of builtins are Power 9 and up and only darn_32 works in
 // 32 bit mode.
@@ -30,11 +24,3 @@
 long long testdarn_raw(void) {
   return __darn_raw();
 }
-
-// CHECK-LABEL: @testdarn_32(
-// CHECK: [[TMP0:%.*]] = call i32 @llvm.ppc.darn32()
-// CHECK-NEXT:ret i32 [[TMP0]]
-//
-int testdarn_32(void) {
-  return __darn_32();
-}
Index: clang/test/CodeGen/builtins-ppc-xlcompat-darn-32.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-darn-32.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple powerpc-unknown-unknown \
+// RUN:-emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpcle-unknown-unknown \
+// RUN:   -emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix \
+// RUN:-emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
+
+// CHECK-LABEL: @testdarn_32(
+// CHECK: [[TMP0:%.*]] = call i32 @llvm.ppc.darn32()
+// CHECK-NEXT:ret i32 [[TMP0]]
+//
+int testdarn_32(void) {
+  return __darn_32();
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3295,6 +3295,8 @@
   case PPC::BI__builtin_ppc_insert_exp:
   case PPC::BI__builtin_ppc_extract_sig:
   case PPC::BI__builtin_ppc_addex:
+  case PPC::BI__builtin_darn:
+  case PPC::BI__builtin_darn_raw:
 return true;
   }
   return false;
@@ -3473,6 +3475,11 @@
 return SemaFeatureCheck(*this, TheCall, "isa-v207-instructions",
 diag::err_ppc_builtin_only_on_arch, "8") ||
SemaBuiltinConstantArgRange(TheCall, 1, 1, 16);
+  case PPC::BI__builtin_darn:
+  case PPC::BI__builtin_darn_raw:
+  case PPC::BI__builtin_darn_32:
+return SemaFeatureCheck(*this, TheCall, "isa-v30-instructions",
+diag::err_ppc_builtin_only_on_arch, "9");
 #define CUSTOM_BUILTIN(Name, Intr, Types, Acc) \
   case PPC::BI__builtin_##Name: \
 return SemaBuiltinPPCMMACall(TheCall, Types);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110282: [PowerPC] SemaChecking for darn family of builtins

2021-09-22 Thread Albion Fung via Phabricator via cfe-commits
Conanap created this revision.
Conanap added reviewers: PowerPC, nemanjai, saghir, stefanp.
Conanap added projects: PowerPC, clang, LLVM.
Herald added a subscriber: kbarton.
Conanap requested review of this revision.

The `__darn` family of builtins are only available on Pwr9,
and only `__darn_32` is available on 32 bit, while the rest
are only available on 64 bit. The patch adds sema checking
for these builtins and separate the `__darn_32`'s 32 bit
test cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110282

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-darn-32.c
  clang/test/CodeGen/builtins-ppc-xlcompat-darn.c
  clang/test/CodeGen/builtins-ppc.c


Index: clang/test/CodeGen/builtins-ppc.c
===
--- clang/test/CodeGen/builtins-ppc.c
+++ clang/test/CodeGen/builtins-ppc.c
@@ -36,16 +36,3 @@
   // CHECK: call double @llvm.ppc.setflm(double %1)
   res = __builtin_setflm(res);
 }
-
-void test_builtin_ppc_darn() {
-  volatile long res;
-  volatile int x;
-  // CHECK: call i64 @llvm.ppc.darn()
-  res = __builtin_darn();
-
-  // CHECK: call i64 @llvm.ppc.darnraw()
-  res = __builtin_darn_raw();
-
-  // CHECK: call i32 @llvm.ppc.darn32()
-  x = __builtin_darn_32();
-}
Index: clang/test/CodeGen/builtins-ppc-xlcompat-darn.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-darn.c
+++ clang/test/CodeGen/builtins-ppc-xlcompat-darn.c
@@ -5,12 +5,6 @@
 // RUN:   -emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
 // RUN: %clang_cc1 -triple powerpc64-unknown-aix \
 // RUN:-emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
-// RUN: %clang_cc1 -triple powerpc-unknown-unknown \
-// RUN:-emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
-// RUN: %clang_cc1 -triple powerpcle-unknown-unknown \
-// RUN:   -emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
-// RUN: %clang_cc1 -triple powerpc-unknown-aix \
-// RUN:-emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
 
 // The darn class of builtins are Power 9 and up and only darn_32 works in
 // 32 bit mode.
@@ -30,11 +24,3 @@
 long long testdarn_raw(void) {
   return __darn_raw();
 }
-
-// CHECK-LABEL: @testdarn_32(
-// CHECK: [[TMP0:%.*]] = call i32 @llvm.ppc.darn32()
-// CHECK-NEXT:ret i32 [[TMP0]]
-//
-int testdarn_32(void) {
-  return __darn_32();
-}
Index: clang/test/CodeGen/builtins-ppc-xlcompat-darn-32.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-darn-32.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple powerpc-unknown-unknown \
+// RUN:-emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpcle-unknown-unknown \
+// RUN:   -emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix \
+// RUN:-emit-llvm %s -o -  -target-cpu pwr9 | FileCheck %s
+
+// CHECK-LABEL: @testdarn_32(
+// CHECK: [[TMP0:%.*]] = call i32 @llvm.ppc.darn32()
+// CHECK-NEXT:ret i32 [[TMP0]]
+//
+int testdarn_32(void) {
+  return __darn_32();
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3295,6 +3295,8 @@
   case PPC::BI__builtin_ppc_insert_exp:
   case PPC::BI__builtin_ppc_extract_sig:
   case PPC::BI__builtin_ppc_addex:
+  case PPC::BI__builtin_darn:
+  case PPC::BI__builtin_darn_raw:
 return true;
   }
   return false;
@@ -3473,6 +3475,11 @@
 return SemaFeatureCheck(*this, TheCall, "isa-v207-instructions",
 diag::err_ppc_builtin_only_on_arch, "8") ||
SemaBuiltinConstantArgRange(TheCall, 1, 1, 16);
+  case PPC::BI__builtin_darn:
+  case PPC::BI__builtin_darn_raw:
+  case PPC::BI__builtin_darn_32:
+return SemaFeatureCheck(*this, TheCall, "isa-v30-instructions",
+diag::err_ppc_builtin_only_on_arch, "9");
 #define CUSTOM_BUILTIN(Name, Intr, Types, Acc) \
   case PPC::BI__builtin_##Name: \
 return SemaBuiltinPPCMMACall(TheCall, Types);


Index: clang/test/CodeGen/builtins-ppc.c
===
--- clang/test/CodeGen/builtins-ppc.c
+++ clang/test/CodeGen/builtins-ppc.c
@@ -36,16 +36,3 @@
   // CHECK: call double @llvm.ppc.setflm(double %1)
   res = __builtin_setflm(res);
 }
-
-void test_builtin_ppc_darn() {
-  volatile long res;
-  volatile int x;
-  // CHECK: call i64 @llvm.ppc.darn()
-  res = __builtin_darn();
-
-  // CHECK: call i64 @llvm.ppc.darnraw()
-  res = __builtin_darn_raw();
-
-  // CHECK: call i32 @llvm.ppc.darn32()
-  x = __builtin_darn_32();
-}
Index: clang/test/CodeGen/builtins-ppc-xlcompat-darn.c
===
--- clang/test/CodeGen/builtins-ppc-xlcompat-darn.c
+++ clang/test/CodeGen/bu

[PATCH] D110089: [CUDA] Implement experimental support for texture lookups.

2021-09-22 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D110089#3016145 , @jlebar wrote:

>> Depending on which particular operation is used, the arguments vary, too.
>
> So something like
>
>   T __nv_tex_surf_handler(name, arg1) {
> switch (name) {
>   ...
>   default:
> panic();
> }
>   }
>   
>   T __nv_tex_surf_handler(name, arg1, arg2) {
> switch(...) { ... }
>   }
>
> and so on?

Yes, and there will be multiple such overloads for each `name`. So the switch 
will have to be replicated/adjusted in each overload.

> If it didn't buy us anything, I'd agree.  The thing I'm concerned about is 
> readability of this code.  Which, if we want to tie it back to users, affects 
> our ability to catch bugs in this implementation.
>
>> Having one trivial compiler builtin that simplifies things a lot is a better 
>> trade-off, IMO.
>
> Ah, maybe I wasn't clear then.  I'm not actually super-concerned with the 
> compiler builtin.  It'd be nice to get rid of it if there's a clean way to do 
> so, but if we don't, that's ok.  Basically, the builtin is just for changing 
> `strcmp(x, "foo")` into `builtin(x) == builtin("foo")`.  Fine.
>
> What I'm more concerned with is the spaghetti of macros here to do something 
> as simple as a series of overloaded functions.  It seems like a premature 
> optimization, and I don't feel confident I can check it for bugs.

The choice is between using macros to generate the boilerplate vs replicating 
things manually. If we could get templates to generaste inline asm operands, 
that would be great. Unfortunately it requires using literals, so the macros 
are the only way to construct the right instruction. 
If I do not do that with macros, I'll have to manually write each instruction 
variant and get it right every time.

I can preprocess the macros and commit the results. That would be about an 
order of magnitude more code than what we have now. That would be harder to 
change en masse without errors. E.g. try spotting the differences between any 
two neighboring functions there: 
https://gist.github.com/Artem-B/ec4290809650f5092d61d6dafa6b0131


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110089

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


[PATCH] D110281: Change __builtin_sycl_unique_stable_name to just use an Itanium mangling

2021-09-22 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

@rjmccall : We were able to get the SYCL committee to change the rules to make 
this feature 'implementable' now based on your feedback, so here it is.  This 
has been baking in our downstream for a while, so my hope is that this is 
sufficiently validated to be 'done' for a while.


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

https://reviews.llvm.org/D110281

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


[PATCH] D110281: Change __builtin_sycl_unique_stable_name to just use an Itanium mangling

2021-09-22 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: aaron.ballman, rjmccall.
Herald added subscribers: Naghasan, Anastasia, ebevhan, mgrang, yaxunl.
erichkeane requested review of this revision.

After significant problems in our downstream with the previous
implementation, the SYCL standard has opted to make using macros/etc to
change kernel-naming-lambdas in any way UB (even passively). As a
result, we are able to just emit the itanium mangling.

However, this DOES require a little work in the CXXABI, as the microsoft
and itanium mangler use different numbering schemes for lambdas.  This
patch adds a pair of mangling contexts that use the normal 'itanium'
mangling strategy to fill in the "DeviceManglingNumber" used previously
by CUDA.


https://reviews.llvm.org/D110281

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumCXXABI.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftCXXABI.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGenSYCL/unique_stable_name.cpp
  clang/test/CodeGenSYCL/unique_stable_name_windows_diff.cpp
  clang/test/SemaSYCL/unique_stable_name.cpp

Index: clang/test/SemaSYCL/unique_stable_name.cpp
===
--- clang/test/SemaSYCL/unique_stable_name.cpp
+++ clang/test/SemaSYCL/unique_stable_name.cpp
@@ -15,10 +15,6 @@
 template 
 void kernel1func(const Func &F1) {
   constexpr const char *F1_output = __builtin_sycl_unique_stable_name(Func); // #USN_F1
-  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
-  // expected-note@#kernel1func_call{{in instantiation of function template specialization}}
-  // expected-note@#USN_F1{{'__builtin_sycl_unique_stable_name' evaluated here}}
-  // expected-note@+1{{in instantiation of function template specialization}}
   kernel_single_task(F1); // #kernel1_call
 }
 
@@ -38,10 +34,6 @@
 template 
 void kernel2func(const Func &F2) {
   constexpr const char *F2_output = __builtin_sycl_unique_stable_name(Func); // #USN_F2
-  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
-  // expected-note@#kernel2func_call{{in instantiation of function template specialization}}
-  // expected-note@#USN_F2{{'__builtin_sycl_unique_stable_name' evaluated here}}
-  // expected-note@+1{{in instantiation of function template specialization}}
   kernel_single_task([]() {});
 }
 
@@ -93,40 +85,34 @@
   kernel_single_task(
   [=]() { l5(); }); // Used in the kernel, but not the kernel name itself
 
-  // kernel6 - expect error
+  // kernel6 - expect no error
   // Test that passing the lambda to the unique stable name builtin and then
-  // using the same lambda in the naming of a kernel causes a diagnostic on the
-  // kernel use due to the change in results to the stable name.
+  // using the same lambda in the naming of a kernel does not cause a diagnostic
+  // on the kernel use due to the change in results to the stable name.
   auto l6 = []() { return 1; };
   constexpr const char *l6_output =
   __builtin_sycl_unique_stable_name(decltype(l6)); // #USN_l6
-  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
-  // expected-note@#USN_l6{{'__builtin_sycl_unique_stable_name' evaluated here}}
-  // expected-note@+1{{in instantiation of function template specialization}}
   kernel_single_task(l6); // Used in the kernel name after builtin
 
-  // kernel7 - expect error
+  // kernel7 - expect no error
   // Same as kernel11 (below) except make the lambda part of naming the kernel.
   // Test that passing a lambda to the unique stable name builtin and then
-  // passing a second lambda to the kernel throws an error because the first
-  // lambda is included in the signature of the second lambda, hence it changes
-  // the mangling of the kernel.
+  // passing a second lambda to the kernel does not throw an error because the
+  // first lambda is included in the signature of the second lambda, but does
+  // not change the mangling of the kernel.
   auto l7 = []() { return 1; };
   auto l8 = [](decltype(l7) *derp = nullptr) { return 2; };
   constexpr const char *l7_output =
   __builtin_sycl_unique_stable_name(decltype(l7)); // #USN_l7
-  // expected-error@#kernelSingleTask{{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}}
-  // expected-note@#USN_l7{{'__builtin_sycl_unique_stable_name' evaluated here}}
-  // expected-note@+1{{in instantiation of function template specialization}}
   kernel_single_task(l8);
 
-  // kernel8 and kern

[PATCH] D110279: [WIP][OpenMP][Offloading] Change `bool IsSPMD` to `int8_t Mode` in `__kmpc_target_init` and `__kmpc_target_deinit`

2021-09-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 374323.
tianshilei1992 added a comment.

fix issues and add more tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110279

Files:
  clang/test/OpenMP/declare_target_codegen_globalization.cpp
  clang/test/OpenMP/nvptx_SPMD_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_force_full_runtime_SPMD_codegen.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_printf_codegen.c
  clang/test/OpenMP/nvptx_target_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/nvptx_teams_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/target_parallel_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_for_debug_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/test/Transforms/OpenMP/always_inline_device.ll
  llvm/test/Transforms/OpenMP/custom_state_machines.ll
  llvm/test/Transforms/OpenMP/custom_state_machines_remarks.ll
  llvm/test/Transforms/OpenMP/deduplication_target.ll
  llvm/test/Transforms/OpenMP/fold_generic_main_thread.ll
  llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold.ll
  llvm/test/Transforms/OpenMP/global_constructor.ll
  llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll
  llvm/test/Transforms/OpenMP/is_spmd_exec_mode_fold.ll
  llvm/test/Transforms/OpenMP/parallel_level_fold.ll
  llvm/test/Transforms/OpenMP/remove_globalization.ll
  llvm/test/Transforms/OpenMP/replace_globalization.ll
  llvm/test/Transforms/OpenMP/single_threaded_execution.ll
  llvm/test/Transforms/OpenMP/spmdization.ll
  llvm/test/Transforms/OpenMP/spmdization_assumes.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding.ll
  llvm/test/Transforms/OpenMP/spmdization_remarks.ll
  openmp/libomptarget/deviceRTLs/common/include/target.h
  openmp/libomptarget/deviceRTLs/common/omptarget.h
  openmp/libomptarget/deviceRTLs/common/src/omp_data.cu
  openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
  openmp/libomptarget/deviceRTLs/common/src/support.cu
  openmp/libomptarget/deviceRTLs/common/support.h
  openmp/libomptarget/deviceRTLs/interface.h

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


[PATCH] D110280: [modules] Fix IRGen assertion on accessing ObjC ivar inside a method.

2021-09-22 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: rsmith, bruno, jansvoboda11.
Herald added a subscriber: ributzka.
vsapsai requested review of this revision.
Herald added a project: clang.

When have ObjCInterfaceDecl with the same name in 2 different modules,
hitting the assertion

> Assertion failed: (Index < RL->getFieldCount() && "Ivar is not inside record 
> layout!"),
> function lookupFieldBitOffset, file 
> llvm-project/clang/lib/AST/RecordLayoutBuilder.cpp, line 3434.

on accessing an ivar inside a method. The assertion happens because
ivar belongs to one module while its containing interface belongs to
another module and then we fail to find the ivar inside the containing
interface. We already keep a single ObjCInterfaceDecl definition in
redecleration chain and in this case containing interface was correct.
The issue is with ObjCIvarDecl. IVar decl for IRGen is taken from
ObjCIvarRefExpr that is created in `Sema::BuildIvarRefExpr` using ivar
decl returned from `Sema::LookupIvarInObjCMethod`. And ivar lookup
returns a wrong decl because basically we take the first ObjCIvarDecl
found in `ASTReader::FindExternalVisibleDeclsByName` (called by
`DeclContext::lookup`). And in `ASTReader.Lookups` lookup table for a
wrong module comes first because `ASTReader::finishPendingActions`
processes `PendingUpdateRecords` in reverse order and the first
encountered ObjCIvarDecl will end up the last in `ASTReader.Lookups`.

Fix by merging ObjCIvarDecl from different modules correctly and by
using a canonical one in name lookup.

rdar://82854574


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110280

Files:
  clang/lib/AST/DeclObjC.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/test/Modules/merge-objc-interface.m

Index: clang/test/Modules/merge-objc-interface.m
===
--- /dev/null
+++ clang/test/Modules/merge-objc-interface.m
@@ -0,0 +1,96 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%t/Frameworks %t/test.m \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%t/Frameworks %t/test-functions.m \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+
+// Test a case when Objective-C interface ivars are present in two different modules.
+
+//--- Frameworks/Foundation.framework/Headers/Foundation.h
+@interface NSObject
+@end
+
+//--- Frameworks/Foundation.framework/Modules/module.modulemap
+framework module Foundation {
+  header "Foundation.h"
+  export *
+}
+
+//--- Frameworks/ObjCInterface.framework/Headers/ObjCInterface.h
+#import 
+@interface ObjCInterface : NSObject {
+@public
+  id _item;
+}
+@end
+
+@interface WithBitFields : NSObject {
+@public
+  int x: 3;
+  int y: 4;
+}
+@end
+
+//--- Frameworks/ObjCInterface.framework/Modules/module.modulemap
+framework module ObjCInterface {
+  header "ObjCInterface.h"
+  export *
+}
+
+//--- Frameworks/ObjCInterfaceCopy.framework/Headers/ObjCInterfaceCopy.h
+#import 
+@interface ObjCInterface : NSObject {
+@public
+  id _item;
+}
+@end
+
+@interface WithBitFields : NSObject {
+@public
+  int x: 3;
+  int y: 4;
+}
+@end
+
+//--- Frameworks/ObjCInterfaceCopy.framework/Modules/module.modulemap
+framework module ObjCInterfaceCopy {
+  header "ObjCInterfaceCopy.h"
+  export *
+}
+
+//--- test.m
+#import 
+#import 
+
+@implementation ObjCInterface
+- (void)test:(id)item {
+  _item = item;
+}
+@end
+
+@implementation WithBitFields
+- (void)reset {
+  x = 0;
+  y = 0;
+}
+@end
+
+//--- test-functions.m
+#import 
+
+void testAccessIVar(ObjCInterface *obj, id item) {
+  obj->_item = item;
+}
+void testAccessBitField(WithBitFields *obj) {
+  obj->x = 0;
+}
+
+#import 
+
+void testAccessIVarLater(ObjCInterface *obj, id item) {
+  obj->_item = item;
+}
+void testAccessBitFieldLater(WithBitFields *obj) {
+  obj->y = 0;
+}
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -3350,6 +3350,9 @@
 return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition()
   : nullptr;
 
+  if (auto *OID = dyn_cast(DC))
+return OID->getDefinition();
+
   // We can see the TU here only if we have no Sema object. In that case,
   // there's no TU scope to look in, so using the DC alone is sufficient.
   if (auto *TU = dyn_cast(DC))
Index: clang/lib/AST/DeclObjC.cpp
===
--- clang/lib/AST/DeclObjC.cpp
+++ clang/lib/AST/DeclObjC.cpp
@@ -81,7 +81,7 @@
   lookup_result R = lookup(Id);
   for (lookup_iterator Ivar = R.begin(), IvarEnd = R.end();
Ivar != IvarEnd; ++Ivar) {
-if (auto *ivar = dyn_cast(*Ivar))
+if (auto *ivar = dyn_cast((*Ivar)

[PATCH] D110279: [WIP][OpenMP][Offloading] Change `bool IsSPMD` to `int8_t Mode` in `__kmpc_target_init` and `__kmpc_target_deinit`

2021-09-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 374318.
tianshilei1992 added a comment.

fix issues


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110279

Files:
  clang/test/OpenMP/declare_target_codegen_globalization.cpp
  clang/test/OpenMP/nvptx_SPMD_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_force_full_runtime_SPMD_codegen.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_printf_codegen.c
  clang/test/OpenMP/nvptx_target_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/nvptx_teams_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/target_parallel_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_for_debug_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/test/Transforms/OpenMP/always_inline_device.ll
  llvm/test/Transforms/OpenMP/custom_state_machines.ll
  llvm/test/Transforms/OpenMP/custom_state_machines_remarks.ll
  llvm/test/Transforms/OpenMP/deduplication_target.ll
  llvm/test/Transforms/OpenMP/fold_generic_main_thread.ll
  llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold.ll
  llvm/test/Transforms/OpenMP/global_constructor.ll
  llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll
  llvm/test/Transforms/OpenMP/is_spmd_exec_mode_fold.ll
  llvm/test/Transforms/OpenMP/parallel_level_fold.ll
  llvm/test/Transforms/OpenMP/replace_globalization.ll
  llvm/test/Transforms/OpenMP/single_threaded_execution.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding.ll
  openmp/libomptarget/deviceRTLs/common/include/target.h
  openmp/libomptarget/deviceRTLs/common/omptarget.h
  openmp/libomptarget/deviceRTLs/common/src/omp_data.cu
  openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
  openmp/libomptarget/deviceRTLs/common/src/support.cu
  openmp/libomptarget/deviceRTLs/common/support.h
  openmp/libomptarget/deviceRTLs/interface.h

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


[PATCH] D110089: [CUDA] Implement experimental support for texture lookups.

2021-09-22 Thread Justin Lebar via Phabricator via cfe-commits
jlebar added a comment.

> Depending on which particular operation is used, the arguments vary, too.

So something like

  T __nv_tex_surf_handler(name, arg1) {
switch (name) {
  ...
  default:
panic();
}
  }
  
  T __nv_tex_surf_handler(name, arg1, arg2) {
switch(...) { ... }
  }

and so on?

> I'd need to push strcmp-based runtime dispatch down to the implementation of 
> the texture lookups with the same operand signature.

Agree.

> That's harder to generalize, as I'd have to implement string-based dispatch 
> for quite a few subsets of the operations -- basically for each variant of 
> cartesian product of {dimensionality, Lod, Level, Sparse}.



> Another downside is that the string comparison code will result in functions 
> being much larger than necessary. Probably not a big thing overall, but why 
> add overhead that would be paid for by all users and which does not buy us 
> anything?

If it didn't buy us anything, I'd agree.  The thing I'm concerned about is 
readability of this code.  Which, if we want to tie it back to users, affects 
our ability to catch bugs in this implementation.

> Having one trivial compiler builtin that simplifies things a lot is a better 
> trade-off, IMO.

Ah, maybe I wasn't clear then.  I'm not actually super-concerned with the 
compiler builtin.  It'd be nice to get rid of it if there's a clean way to do 
so, but if we don't, that's ok.  Basically, the builtin is just for changing 
`strcmp(x, "foo")` into `builtin(x) == builtin("foo")`.  Fine.

What I'm more concerned with is the spaghetti of macros here to do something as 
simple as a series of overloaded functions.  It seems like a premature 
optimization, and I don't feel confident I can check it for bugs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110089

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


[PATCH] D110279: [WIP][OpenMP][Offloading] Change `bool IsSPMD` to `int8_t Mode` in `__kmpc_target_init` and `__kmpc_target_deinit`

2021-09-22 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 created this revision.
Herald added subscribers: ormris, guansong, hiraditya, yaxunl.
tianshilei1992 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added subscribers: llvm-commits, openmp-commits, cfe-commits, sstefan1.
Herald added a reviewer: baziotis.
Herald added projects: clang, OpenMP, LLVM.

This is a follow-up of D110029 , which uses 
bitset to indicate execution mode.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110279

Files:
  clang/test/OpenMP/declare_target_codegen_globalization.cpp
  clang/test/OpenMP/nvptx_SPMD_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_force_full_runtime_SPMD_codegen.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_printf_codegen.c
  clang/test/OpenMP/nvptx_target_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/nvptx_teams_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/target_parallel_debug_codegen.cpp
  clang/test/OpenMP/target_parallel_for_debug_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/test/Transforms/OpenMP/always_inline_device.ll
  llvm/test/Transforms/OpenMP/custom_state_machines.ll
  llvm/test/Transforms/OpenMP/custom_state_machines_remarks.ll
  llvm/test/Transforms/OpenMP/deduplication_target.ll
  llvm/test/Transforms/OpenMP/fold_generic_main_thread.ll
  llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold.ll
  llvm/test/Transforms/OpenMP/global_constructor.ll
  llvm/test/Transforms/OpenMP/gpu_state_machine_function_ptr_replacement.ll
  llvm/test/Transforms/OpenMP/is_spmd_exec_mode_fold.ll
  llvm/test/Transforms/OpenMP/parallel_level_fold.ll
  llvm/test/Transforms/OpenMP/replace_globalization.ll
  llvm/test/Transforms/OpenMP/single_threaded_execution.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding.ll
  openmp/libomptarget/deviceRTLs/common/include/target.h
  openmp/libomptarget/deviceRTLs/common/omptarget.h
  openmp/libomptarget/deviceRTLs/common/src/omp_data.cu
  openmp/libomptarget/deviceRTLs/common/src/omptarget.cu
  openmp/libomptarget/deviceRTLs/common/src/support.cu
  openmp/libomptarget/deviceRTLs/common/support.h
  openmp/libomptarget/deviceRTLs/interface.h

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


[PATCH] D110278: Adding doWithCleanup abstraction

2021-09-22 Thread Chris Bieneman via Phabricator via cfe-commits
beanz created this revision.
beanz added reviewers: lhames, dblaikie.
Herald added subscribers: dexonsmith, mgorny.
beanz requested review of this revision.
Herald added projects: clang, LLVM.

This patch adds a new `doWithCleanup` abstraction to LLVM that works
with `llvm::Error`, `int`, `bool`, and 
return types that propagate status.

This abstraction is a more general way of having a conditional cleanup
that can be used with multiple return paths out of a function.

Test cases and a first use case in clang are part of the patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110278

Files:
  clang/include/clang/Frontend/FrontendAction.h
  clang/lib/Frontend/FrontendAction.cpp
  llvm/include/llvm/Support/Cleanup.h
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/Support/CleanupTests.cpp

Index: llvm/unittests/Support/CleanupTests.cpp
===
--- /dev/null
+++ llvm/unittests/Support/CleanupTests.cpp
@@ -0,0 +1,86 @@
+//===- unittests/CleanupTests.cpp - Cleanup.h tests ---===//
+//
+// 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
+//
+//===--===//
+
+#include "llvm/Support/Cleanup.h"
+#include "llvm/Support/Error.h"
+
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+TEST(Error, DoWithCleanupBool) {
+  bool CleanupRun = false;
+  bool Result =
+  doWithCleanup([] { return true; }, [&] { CleanupRun = true; });
+  EXPECT_TRUE(Result);
+  EXPECT_FALSE(CleanupRun);
+
+  Result =
+  doWithCleanup([] { return false; }, [&] { CleanupRun = true; });
+  EXPECT_FALSE(Result);
+  EXPECT_TRUE(CleanupRun);
+}
+
+TEST(Error, DoWithCleanupError) {
+  bool CleanupRun = false;
+  llvm::consumeError(doWithCleanup(
+  [&] { return Error::success(); }, [&] { CleanupRun = true; }));
+
+  EXPECT_FALSE(CleanupRun);
+
+  llvm::consumeError(doWithCleanup(
+  [&] { return errorCodeToError(inconvertibleErrorCode()); },
+  [&] { CleanupRun = true; }));
+  EXPECT_TRUE(CleanupRun);
+}
+
+TEST(Error, DoWithCleanupInt) {
+  bool CleanupRun = false;
+  int Result = doWithCleanup([] { return 0; }, [&] { CleanupRun = true; });
+  EXPECT_EQ(Result, 0);
+  EXPECT_FALSE(CleanupRun);
+
+  Result = doWithCleanup([] { return 1; }, [&] { CleanupRun = true; });
+  EXPECT_EQ(Result, 1);
+  EXPECT_TRUE(CleanupRun);
+}
+
+enum class PetType { Doggo, Kitteh, Birb, WhoozieWhatsit };
+
+TEST(Error, DoWithCleanupOverrideFailure) {
+  bool CleanupRun = false;
+  PetType Result = doWithCleanup(
+  [] { return PetType::Doggo; }, [&] { CleanupRun = true; },
+  [](PetType &E) { return E == PetType::WhoozieWhatsit; });
+  EXPECT_EQ(Result, PetType::Doggo);
+  EXPECT_FALSE(CleanupRun);
+
+  Result = doWithCleanup(
+  [] { return PetType::WhoozieWhatsit; }, [&] { CleanupRun = true; },
+  [](PetType &E) { return E == PetType::WhoozieWhatsit; });
+  EXPECT_EQ(Result, PetType::WhoozieWhatsit);
+  EXPECT_TRUE(CleanupRun);
+}
+
+enum class ResultTy {
+  Failure = 0,
+  Success,
+};
+
+TEST(Error, DoWithCleanupEnumNonZeroFailure) {
+  bool CleanupRun = false;
+  ResultTy Result = doWithCleanup([] { return ResultTy::Success; },
+[&] { CleanupRun = true; });
+  EXPECT_EQ(Result, ResultTy::Success);
+  EXPECT_FALSE(CleanupRun);
+
+  Result = doWithCleanup([] { return ResultTy::Failure; },
+   [&] { CleanupRun = true; });
+  EXPECT_EQ(Result, ResultTy::Failure);
+  EXPECT_TRUE(CleanupRun);
+}
Index: llvm/unittests/Support/CMakeLists.txt
===
--- llvm/unittests/Support/CMakeLists.txt
+++ llvm/unittests/Support/CMakeLists.txt
@@ -18,6 +18,7 @@
   Casting.cpp
   CheckedArithmeticTest.cpp
   Chrono.cpp
+  CleanupTests.cpp
   CommandLineTest.cpp
   CompressionTest.cpp
   ConvertUTFTest.cpp
Index: llvm/include/llvm/Support/Cleanup.h
===
--- /dev/null
+++ llvm/include/llvm/Support/Cleanup.h
@@ -0,0 +1,67 @@
+//===- llvm/Support/Cleanup.h - Cleanup on failure abstraction --*- C++ -*-===//
+//
+// 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
+//
+//===--===//
+//
+// This file defines helper abstractions for cleaning up resources on failure.
+//
+//===--===//
+
+#ifndef LLVM_SUPPORT_CLEANUP_H
+#define LLVM_SUPPORT_CLEANUP_H
+
+#include "llvm/Support/Error.h"
+
+#include 
+#include 
+
+namespace llvm {
+
+/// Helper templates for det

[PATCH] D110257: [CFE][Codegen] Do not break the contiguity of static allocas.

2021-09-22 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In D110257#3015641 , @hsmhsm wrote:

> The logic at 
> https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Utils/InlineFunction.cpp#L2093
>  assumes that static allocas (within callee) are contiguous.

No, it doesn't make that assumption. That code is an attempt to optimize the 
linked list splicing, so that batches of contiguous allocas can be spliced over 
together. I believe the code would still be correct if you removed this inner 
loop and left behind the outer loop, which iterates over all allocas in the 
entry block.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110257

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


[PATCH] D108370: [clang-tidy] Fix wrong FixIt about union in cppcoreguidelines-pro-type-member-init

2021-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:484
+ AnyMemberHasInitPerUnion, [&](const FieldDecl *F) {
 if (!FieldsToInit.count(F))
   return;

Given that we're touching this code, we might as well make clang-format happy 
with it (though I can't quite spot what it wants changed, so if it turns out to 
be a bad idea for some reason, I don't insist).



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp:526
+  union {
+int K;
+  };

aaron.ballman wrote:
> Can you add a `CHECK-FIXES-NOT` that we're not adding the fix for this case?
I think you missed this request? Same for the one immediately below.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp:534
+
+union U2 {
+  U2() {}

Sockke wrote:
> aaron.ballman wrote:
> > A related interesting test would be:
> > ```
> > union U3 {
> >   U3() {}
> > 
> >   struct {
> > int B;
> >   } b;
> >   int A;
> > };
> > ```
> > I would expect `A` or `b` to need initialization for the union, and `B` to 
> > need initialization for the struct.
> > A related interesting test would be:
> > ```
> > union U3 {
> >   U3() {}
> > 
> >   struct {
> > int B;
> >   } b;
> >   int A;
> > };
> > ```
> > I would expect `A` or `b` to need initialization for the union, and `B` to 
> > need initialization for the struct.
> 
> I apologize for the delay in responding. It seems to me that `struct {}b` has 
> no user-defined constructor, so all members are initialized to their 
> defaults, it is unnecessary to initialize `B` explicitly. 
Okay, fair point!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108370

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


[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-09-22 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/QualifierAlignmentFixer.cpp:449
+return false;
+  if (Tok->is(TT_TypenameMacro))
+return false;

I think this is still right, because it is a type (according to the 
configuration).



Comment at: clang/lib/Format/QualifierAlignmentFixer.h:16
+
+#ifndef LLVM_CLANG_LIB_FORMAT_LeftRightQualifierAlignmentFixer_H
+#define LLVM_CLANG_LIB_FORMAT_LeftRightQualifierAlignmentFixer_H

This clang-tidy isn't addressed.



Comment at: clang/unittests/Format/QualifierFixerTest.cpp:122
+
+}; // namespace
+

In addition to clang-tidies message: It is unnecessary.


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

https://reviews.llvm.org/D69764

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


[PATCH] D109437: [PowerPC] FP compare and test XL compat builtins.

2021-09-22 Thread Quinn Pham via Phabricator via cfe-commits
quinnp updated this revision to Diff 374312.
quinnp added a comment.

Moving the semachecking of `test_data_class` from the function to the switch 
case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109437

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-pwr9-error.c
  clang/test/CodeGen/builtins-ppc-xlcompat-test.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-test.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-test.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-test.ll
@@ -0,0 +1,99 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-unknown \
+; RUN:   -mcpu=pwr9 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-unknown \
+; RUN:   -mcpu=pwr9 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix \
+; RUN:   -mcpu=pwr9 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
+; RUN:   -mcpu=pwr9 < %s | FileCheck %s
+
+define i32 @test_builtin_ppc_compare_exp_eq(double %d) {
+; CHECK-LABEL: test_builtin_ppc_compare_exp_eq:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:xscmpexpdp 0, 1, 1
+; CHECK-NEXT:li 3, 0
+; CHECK-NEXT:li 4, 1
+; CHECK-NEXT:iseleq 3, 4, 3
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call i32 @llvm.ppc.compare.exp.eq(double %d, double %d)
+  ret i32 %0
+}
+
+declare i32 @llvm.ppc.compare.exp.eq(double, double)
+
+define i32 @test_builtin_ppc_compare_exp_lt(double %d) {
+; CHECK-LABEL: test_builtin_ppc_compare_exp_lt:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:xscmpexpdp 0, 1, 1
+; CHECK-NEXT:li 3, 0
+; CHECK-NEXT:li 4, 1
+; CHECK-NEXT:isellt 3, 4, 3
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call i32 @llvm.ppc.compare.exp.lt(double %d, double %d)
+  ret i32 %0
+}
+
+declare i32 @llvm.ppc.compare.exp.lt(double, double)
+
+define i32 @test_builtin_ppc_compare_exp_gt(double %d) {
+; CHECK-LABEL: test_builtin_ppc_compare_exp_gt:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:xscmpexpdp 0, 1, 1
+; CHECK-NEXT:li 3, 0
+; CHECK-NEXT:li 4, 1
+; CHECK-NEXT:iselgt 3, 4, 3
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call i32 @llvm.ppc.compare.exp.gt(double %d, double %d)
+  ret i32 %0
+}
+
+declare i32 @llvm.ppc.compare.exp.gt(double, double)
+
+define i32 @test_builtin_ppc_compare_exp_uo(double %d) {
+; CHECK-LABEL: test_builtin_ppc_compare_exp_uo:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:xscmpexpdp 0, 1, 1
+; CHECK-NEXT:li 3, 0
+; CHECK-NEXT:li 4, 1
+; CHECK-NEXT:isel 3, 4, 3, 3
+; CHECK-NEXT:blr
+entry:
+  %0 = tail call i32 @llvm.ppc.compare.exp.uo(double %d, double %d)
+  ret i32 %0
+}
+
+declare i32 @llvm.ppc.compare.exp.uo(double, double)
+
+define i32 @test_builtin_ppc_test_data_class_d(double %d) {
+; CHECK-LABEL: test_builtin_ppc_test_data_class_d:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:xststdcdp 0, 1, 0
+; CHECK-NEXT:li 3, 0
+; CHECK-NEXT:li 4, 1
+; CHECK-NEXT:iseleq 3, 4, 3
+; CHECK-NEXT:blr
+entry:
+  %test_data_class = tail call i32 @llvm.ppc.test.data.class.d(double %d, i32 0)
+  ret i32 %test_data_class
+}
+
+declare i32 @llvm.ppc.test.data.class.d(double, i32 immarg)
+
+define i32 @test_builtin_ppc_test_data_class_f(float %f) {
+; CHECK-LABEL: test_builtin_ppc_test_data_class_f:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:xststdcsp 0, 1, 127
+; CHECK-NEXT:li 3, 0
+; CHECK-NEXT:li 4, 1
+; CHECK-NEXT:iseleq 3, 4, 3
+; CHECK-NEXT:blr
+entry:
+  %test_data_class = tail call i32 @llvm.ppc.test.data.class.f(float %f, i32 127)
+  ret i32 %test_data_class
+}
+
+declare i32 @llvm.ppc.test.data.class.f(float, i32 immarg)
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -10373,6 +10373,56 @@
 }
 return DAG.getMergeValues(RetOps, dl);
   }
+  case Intrinsic::ppc_compare_exp_lt:
+  case Intrinsic::ppc_compare_exp_gt:
+  case Intrinsic::ppc_compare_exp_eq:
+  case Intrinsic::ppc_compare_exp_uo: {
+unsigned Pred;
+switch (IntrinsicID) {
+default:
+  llvm_unreachable("Unknown Intrinsic");
+case Intrinsic::ppc_compare_exp_lt:
+  Pred = PPC::PRED_LT;
+  break;
+case Intrinsic::ppc_compare_exp_gt:
+  Pred = PPC::PRED_GT;
+  break;
+case Intrinsic::ppc_compare_exp_eq

[PATCH] D110276: Clean up large copies of binaries copied into temp directories in tests

2021-09-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added reviewers: thakis, scott.linder.
tejohnson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In looking at the disk space used by a ninja check-all, I found that a
few of the largest files were copies of clang and lld made into temp
directories by a couple of tests. These tests were added in D53021 
 and
D74811 . Clean up these copies after usage.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110276

Files:
  clang/test/Driver/clang_f_opts.c
  lld/test/COFF/pdb-relative-source-lines.test


Index: lld/test/COFF/pdb-relative-source-lines.test
===
--- lld/test/COFF/pdb-relative-source-lines.test
+++ lld/test/COFF/pdb-relative-source-lines.test
@@ -41,6 +41,9 @@
 RUN: ./lld-link -debug -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb 
pdb_lines_1_relative.obj pdb_lines_2_relative.obj
 RUN: llvm-pdbutil pdb2yaml -modules -module-files -module-syms 
-subsections=lines,fc %t/out.pdb | FileCheck --check-prefix=ABSOLUTE %s
 
+Clean up copy of large binary copied into temp directory to avoid bloat.
+RUN: rm ./lld-link
+
 CHECK-LABEL:  - Module:  'c:\src\pdb_lines_1_relative.obj'
 CHECK-NEXT: ObjFile: 'c:\src\pdb_lines_1_relative.obj'
 CHECK:  SourceFiles:
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -565,6 +565,8 @@
 // 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{{.+}}"
+// Clean up copy of large binary copied into temp directory to avoid bloat.
+// RUN: rm "%t.r/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


Index: lld/test/COFF/pdb-relative-source-lines.test
===
--- lld/test/COFF/pdb-relative-source-lines.test
+++ lld/test/COFF/pdb-relative-source-lines.test
@@ -41,6 +41,9 @@
 RUN: ./lld-link -debug -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj
 RUN: llvm-pdbutil pdb2yaml -modules -module-files -module-syms -subsections=lines,fc %t/out.pdb | FileCheck --check-prefix=ABSOLUTE %s
 
+Clean up copy of large binary copied into temp directory to avoid bloat.
+RUN: rm ./lld-link
+
 CHECK-LABEL:  - Module:  'c:\src\pdb_lines_1_relative.obj'
 CHECK-NEXT: ObjFile: 'c:\src\pdb_lines_1_relative.obj'
 CHECK:  SourceFiles:
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -565,6 +565,8 @@
 // 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{{.+}}"
+// Clean up copy of large binary copied into temp directory to avoid bloat.
+// RUN: rm "%t.r/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


[PATCH] D110257: [CFE][Codegen] Do not break the contiguity of static allocas.

2021-09-22 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a subscriber: rnk.
jdoerfert added a comment.

In D110257#3015712 , @jdoerfert wrote:

> In D110257#3015641 , @hsmhsm wrote:
>
>> In D110257#3015553 , @arsenm wrote:
>>
>>> I do think it's cleaner/more canonical IR to cluster these at the top of 
>>> the block, but I don't understand this comment:
>>>
 otherwise, inliner's attempt to move static allocas from callee to caller 
 will fail,
>>>
>>> The inliner successfully moves allocas to the caller's entry block, even 
>>> with addrspacecasts interspersed.
>>
>> The logic at 
>> https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Utils/InlineFunction.cpp#L2093
>>  assumes that static allocas (within callee) are contiguous.
>
> True. Even worse. It will bail if a static alloca is used as an `inalloca` 
> argument.
> So, if you now interleave allocas that may be used in `inalloca` you also 
> break the "canonical form". 
> I assume this hits mostly windows but still.

@rnk This might be of interest to you. Any thoughts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110257

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


[PATCH] D110273: [PowerPC] Fix lharx and lbarx builtin signatures

2021-09-22 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

The description says it causes issues but there is no test case. Please add the 
test case that causes issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110273

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


[PATCH] D110257: [CFE][Codegen] Do not break the contiguity of static allocas.

2021-09-22 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:102-106
+  auto *EBB = AllocaInsertPt->getParent();
+  auto Iter = AllocaInsertPt->getIterator();
+  if (Iter != EBB->end())
+++Iter;
+  Builder.SetInsertPoint(EBB, Iter);

hsmhsm wrote:
> arsenm wrote:
> > Where are the addrspacecasts inserted? Could you just adjust where those 
> > are inserted instead?
> The addressspace casts are inserted immediately after all static allocas (top 
> static alloca cluster).
> 
> An example:
> 
> Before this patch:
> 
> ```
> entry:
>   %N.addr = alloca i64, align 8, addrspace(5)
>   %N.addr.ascast = addrspacecast i64 addrspace(5)* %N.addr to i64*
>   %vla.addr = alloca i64, align 8, addrspace(5)
>   %vla.addr.ascast = addrspacecast i64 addrspace(5)* %vla.addr to i64*
>   %a.addr = alloca i32*, align 8, addrspace(5)
>   %a.addr.ascast = addrspacecast i32* addrspace(5)* %a.addr to i32**
>   %vla.addr2 = alloca i64, align 8, addrspace(5)
>   %vla.addr2.ascast = addrspacecast i64 addrspace(5)* %vla.addr2 to i64*
>   %b.addr = alloca i32*, align 8, addrspace(5)
>   %b.addr.ascast = addrspacecast i32* addrspace(5)* %b.addr to i32**
>   %N.casted = alloca i64, align 8, addrspace(5)
>   %N.casted.ascast = addrspacecast i64 addrspace(5)* %N.casted to i64*
>   %.zero.addr = alloca i32, align 4, addrspace(5)
>   %.zero.addr.ascast = addrspacecast i32 addrspace(5)* %.zero.addr to i32*
>   %.threadid_temp. = alloca i32, align 4, addrspace(5)
>   %.threadid_temp..ascast = addrspacecast i32 addrspace(5)* %.threadid_temp. 
> to i32*  
>   store i64 %N, i64* %N.addr.ascast, align 8
> ```
> 
> With this patch:
> 
> ```
> entry:
>   %N.addr = alloca i64, align 8, addrspace(5)
>   %vla.addr = alloca i64, align 8, addrspace(5)
>   %a.addr = alloca i32*, align 8, addrspace(5)
>   %vla.addr2 = alloca i64, align 8, addrspace(5)
>   %b.addr = alloca i32*, align 8, addrspace(5)
>   %N.casted = alloca i64, align 8, addrspace(5)
>   %.zero.addr = alloca i32, align 4, addrspace(5)
>   %.threadid_temp. = alloca i32, align 4, addrspace(5)
>   %.threadid_temp..ascast = addrspacecast i32 addrspace(5)* %.threadid_temp. 
> to i32*
>   %.zero.addr.ascast = addrspacecast i32 addrspace(5)* %.zero.addr to i32*
>   %N.casted.ascast = addrspacecast i64 addrspace(5)* %N.casted to i64*
>   %b.addr.ascast = addrspacecast i32* addrspace(5)* %b.addr to i32**
>   %vla.addr2.ascast = addrspacecast i64 addrspace(5)* %vla.addr2 to i64*
>   %a.addr.ascast = addrspacecast i32* addrspace(5)* %a.addr to i32**
>   %vla.addr.ascast = addrspacecast i64 addrspace(5)* %vla.addr to i64*
>   %N.addr.ascast = addrspacecast i64 addrspace(5)* %N.addr to i64*
>   store i64 %N, i64* %N.addr.ascast, align 8
> ```
I meant where in the clang code are these emitted, and how is that I set point 
found?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110257

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


[clang] 38c09ea - DebugInfo: Add (initially no-op) -gsimple-template-names={simple,mangled}

2021-09-22 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2021-09-22T11:11:49-07:00
New Revision: 38c09ea2d279eabe3602e2002f8cdfcc5380

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

LOG: DebugInfo: Add (initially no-op) -gsimple-template-names={simple,mangled}

This is to build the foundation of a new debug info feature to use only
the base name of template as its debug info name (eg: "t1" instead of
the full "t1"). The intent being that a consumer can still retrieve
all that information from the DW_TAG_template_*_parameters.

So gno-simple-template-names is business as usual/previously ("t1")
   =simple is the simplified name ("t1")
   =mangled is a special mode to communicate the full information, but
   also indicate that the name should be able to be simplified. The data
   is encoded as "_STNt1|" which will be matched with an
   llvm-dwarfdump --verify feature to deconstruct this name, rebuild the
   original name, and then try to rebuild the simple name via the DWARF
   tags - then compare the latter and the former to ensure that all the
   data necessary to fully rebuild the name is present.

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/DebugInfoOptions.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Driver/debug-options.c

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 37900bf3ead1..5d1d4f9dc58e 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -320,6 +320,12 @@ CODEGENOPT(DebugFwdTemplateParams, 1, 0) ///< Whether to 
emit complete
  ///< template parameter descriptions 
in
  ///< forward declarations (versus just
  ///< including them in the name).
+ENUM_CODEGENOPT(DebugSimpleTemplateNames, 
codegenoptions::DebugTemplateNamesKind, 2, 
codegenoptions::DebugTemplateNamesKind::Full) ///< Whether to emit template 
parameters
+   ///< in the textual names of 
template
+  ///< specializations.
+  ///< Implies DebugFwdTemplateNames to
+  ///< allow decorated names to be
+  ///< reconstructed when needed.
 CODEGENOPT(EmitLLVMUseLists, 1, 0) ///< Control whether to serialize use-lists.
 
 CODEGENOPT(WholeProgramVTables, 1, 0) ///< Whether to apply whole-program

diff  --git a/clang/include/clang/Basic/DebugInfoOptions.h 
b/clang/include/clang/Basic/DebugInfoOptions.h
index c1259d7797db..a99a2b5903d7 100644
--- a/clang/include/clang/Basic/DebugInfoOptions.h
+++ b/clang/include/clang/Basic/DebugInfoOptions.h
@@ -54,6 +54,12 @@ enum DebugInfoKind {
   UnusedTypeInfo,
 };
 
+enum class DebugTemplateNamesKind {
+  Full,
+  Simple,
+  Mangled
+};
+
 } // end namespace codegenoptions
 } // end namespace clang
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f0932a0bd1de..13d740cdb0fb 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2967,6 +2967,15 @@ def gsplit_dwarf_EQ : Joined<["-"], "gsplit-dwarf=">, 
Group,
   HelpText<"Set DWARF fission mode to either 'split' or 'single'">,
   Values<"split,single">;
 def gno_split_dwarf : Flag<["-"], "gno-split-dwarf">, Group;
+def gsimple_template_names : Flag<["-"], "gsimple-template-names">, 
Group;
+def gsimple_template_names_EQ
+: Joined<["-"], "gsimple-template-names=">,
+  Group,
+  HelpText<"Use simple template names in DWARF, or include the full "
+   "template name with a modified prefix for validation">,
+  Values<"simple,mangled">, Flags<[CC1Option]>;
+def gno_simple_template_names : Flag<["-"], "gno-simple-template-names">,
+Group;
 def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group, 
Flags<[CC1Option]>;
 def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">, Group;
 def gpubnames : Flag<["-"], "gpubnames">, Group, 
Flags<[CC1Option]>;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index e6742c6575b9..6c7b8bbcaad7 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4128,6 +4128,29 @@ static void renderDebugOptions(const ToolChain &TC, 
const Driver &D,
options::OPT_gpubnames)
 ? "-gpubnames"
 : "-g

[PATCH] D110273: [PowerPC] Fix lharx and lbarx builtin signatures

2021-09-22 Thread Albion Fung via Phabricator via cfe-commits
Conanap created this revision.
Conanap added reviewers: PowerPC, nemanjai, stefanp, saghir.
Conanap added projects: clang, LLVM, PowerPC.
Herald added subscribers: steven.zhang, kbarton.
Conanap requested review of this revision.

The signatures for the PowerPC builtins `lharx` and
`lbarx` are incorrect, and causes issues when in a function
that requiers the return of the builtin to be promoted.
This patch fixes these signatures.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110273

Files:
  clang/include/clang/Basic/BuiltinsPPC.def


Index: clang/include/clang/Basic/BuiltinsPPC.def
===
--- clang/include/clang/Basic/BuiltinsPPC.def
+++ clang/include/clang/Basic/BuiltinsPPC.def
@@ -74,8 +74,8 @@
 BUILTIN(__builtin_ppc_fetch_and_swaplp, "ULiULiD*ULi", "")
 BUILTIN(__builtin_ppc_ldarx, "LiLiD*", "")
 BUILTIN(__builtin_ppc_lwarx, "iiD*", "")
-BUILTIN(__builtin_ppc_lharx, "isD*", "")
-BUILTIN(__builtin_ppc_lbarx, "UiUcD*", "")
+BUILTIN(__builtin_ppc_lharx, "ssD*", "")
+BUILTIN(__builtin_ppc_lbarx, "ccD*", "")
 BUILTIN(__builtin_ppc_stdcx, "iLiD*Li", "")
 BUILTIN(__builtin_ppc_stwcx, "iiD*i", "")
 BUILTIN(__builtin_ppc_sthcx, "isD*s", "")


Index: clang/include/clang/Basic/BuiltinsPPC.def
===
--- clang/include/clang/Basic/BuiltinsPPC.def
+++ clang/include/clang/Basic/BuiltinsPPC.def
@@ -74,8 +74,8 @@
 BUILTIN(__builtin_ppc_fetch_and_swaplp, "ULiULiD*ULi", "")
 BUILTIN(__builtin_ppc_ldarx, "LiLiD*", "")
 BUILTIN(__builtin_ppc_lwarx, "iiD*", "")
-BUILTIN(__builtin_ppc_lharx, "isD*", "")
-BUILTIN(__builtin_ppc_lbarx, "UiUcD*", "")
+BUILTIN(__builtin_ppc_lharx, "ssD*", "")
+BUILTIN(__builtin_ppc_lbarx, "ccD*", "")
 BUILTIN(__builtin_ppc_stdcx, "iLiD*Li", "")
 BUILTIN(__builtin_ppc_stwcx, "iiD*i", "")
 BUILTIN(__builtin_ppc_sthcx, "isD*s", "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-09-22 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 374298.
MyDeveloperDay added a comment.

Use better vector initialization


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

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/QualifierAlignmentFixer.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -0,0 +1,809 @@
+//===- unittest/Format/QualifierFixerTest.cpp - Formatting unit tests -===//
+//
+// 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
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "FormatTestUtils.h"
+#include "TestLexer.h"
+#include "gtest/gtest.h"
+
+#include "../../lib/Format/QualifierAlignmentFixer.h"
+
+#define DEBUG_TYPE "format-qualifier-fixer-test"
+
+using testing::ScopedTrace;
+
+namespace clang {
+namespace format {
+namespace {
+
+#define CHECK_PARSE(TEXT, FIELD, VALUE)\
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+class QualifierFixerTest : public ::testing::Test {
+protected:
+  enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck };
+
+  TokenList annotate(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+return TestLexer(Allocator, Buffers, Style).annotate(Code);
+  }
+  llvm::SpecificBumpPtrAllocator Allocator;
+  std::vector> Buffers;
+
+  std::string format(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ StatusCheck CheckComplete = SC_ExpectComplete) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+std::vector Ranges(1, tooling::Range(0, Code.size()));
+FormattingAttemptStatus Status;
+tooling::Replacements Replaces =
+reformat(Style, Code, Ranges, "", &Status);
+if (CheckComplete != SC_DoNotCheck) {
+  bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete;
+  EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete)
+  << Code << "\n\n";
+}
+ReplacementCount = Replaces.size();
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  FormatStyle getStyleWithColumns(FormatStyle Style, unsigned ColumnLimit) {
+Style.ColumnLimit = ColumnLimit;
+return Style;
+  }
+
+  FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) {
+return getStyleWithColumns(getLLVMStyle(), ColumnLimit);
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
+ llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Expected.str(), format(Expected, Style))
+<< "Expected code is not stable";
+EXPECT_EQ(Expected.str(), format(Code, Style));
+if (Style.Language == FormatStyle::LK_Cpp) {
+  // Objective-C++ is a superset of C++, so everything checked for C++
+  // needs to be checked for Objective-C++ as well.
+  FormatStyle ObjCStyle = Style;
+  ObjCStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
+}
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+_verifyFormat(File, Line, Code, test::messUp(Code), Style);
+  }
+
+  void _verifyIncompleteFormat(const char *File, int Line, llvm::StringRef Code,
+   const FormatStyle &Style = getLLVMStyle()) {
+ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Code.str(),
+  format(test::messUp(Code), St

[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-09-22 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 374294.
MyDeveloperDay marked 3 inline comments as done.
MyDeveloperDay added a comment.

Remove use of Typenamemacros (we'll solve this a different way later)


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

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/QualifierAlignmentFixer.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -0,0 +1,879 @@
+//===- unittest/Format/QualifierFixerTest.cpp - Formatting unit tests -===//
+//
+// 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
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "FormatTestUtils.h"
+#include "TestLexer.h"
+#include "gtest/gtest.h"
+
+#include "../../lib/Format/QualifierAlignmentFixer.h"
+
+#define DEBUG_TYPE "format-qualifier-fixer-test"
+
+using testing::ScopedTrace;
+
+namespace clang {
+namespace format {
+namespace {
+
+#define CHECK_PARSE(TEXT, FIELD, VALUE)\
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+class QualifierFixerTest : public ::testing::Test {
+protected:
+  enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck };
+
+  TokenList annotate(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+return TestLexer(Allocator, Buffers, Style).annotate(Code);
+  }
+  llvm::SpecificBumpPtrAllocator Allocator;
+  std::vector> Buffers;
+
+  std::string format(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ StatusCheck CheckComplete = SC_ExpectComplete) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+std::vector Ranges(1, tooling::Range(0, Code.size()));
+FormattingAttemptStatus Status;
+tooling::Replacements Replaces =
+reformat(Style, Code, Ranges, "", &Status);
+if (CheckComplete != SC_DoNotCheck) {
+  bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete;
+  EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete)
+  << Code << "\n\n";
+}
+ReplacementCount = Replaces.size();
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  FormatStyle getStyleWithColumns(FormatStyle Style, unsigned ColumnLimit) {
+Style.ColumnLimit = ColumnLimit;
+return Style;
+  }
+
+  FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) {
+return getStyleWithColumns(getLLVMStyle(), ColumnLimit);
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
+ llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Expected.str(), format(Expected, Style))
+<< "Expected code is not stable";
+EXPECT_EQ(Expected.str(), format(Code, Style));
+if (Style.Language == FormatStyle::LK_Cpp) {
+  // Objective-C++ is a superset of C++, so everything checked for C++
+  // needs to be checked for Objective-C++ as well.
+  FormatStyle ObjCStyle = Style;
+  ObjCStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
+}
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+_verifyFormat(File, Line, Code, test::messUp(Code), Style);
+  }
+
+  void _verifyIncompleteFormat(const char *File, int Line, llvm::StringRef Code,
+   const FormatStyle &Style = getLLVMStyle()) {
+ScopedTrace t(File, Line, ::testing::Message() <

[clang] 97b2f20 - Change error for storage-class to mean linkage, fix lang-linkage diag

2021-09-22 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2021-09-22T10:51:05-07:00
New Revision: 97b2f20a446e54f4354d8f950dfab62c37e6ddf4

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

LOG: Change error for storage-class to mean linkage, fix lang-linkage diag

Allow multiversioning declarations to match when the actual formal
linkage matches, not just when the storage class is identical.
Additionally, change the ambiguous 'linkage' mismatch to be more
specific and say 'language linkage'.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/attr-cpuspecific.cpp
clang/test/SemaCXX/attr-target-mv.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3cadd986b8ae..0e803ee028ce 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11208,8 +11208,8 @@ def err_multiversion_mismatched_attrs
 "%0 %select{is missing|has 
diff erent arguments}1">;
 def err_multiversion_
diff  : Error<
   "multiversioned function declaration has a 
diff erent %select{calling convention"
-  "|return type|constexpr specification|inline specification|storage class|"
-  "linkage}0">;
+  "|return type|constexpr specification|inline specification|linkage|"
+  "language linkage}0">;
 def err_multiversion_doesnt_support : Error<
   "attribute '%select{target|cpu_specific|cpu_dispatch}0' multiversioned 
functions do not "
   "yet support %select{function templates|virtual functions|"

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 13389ebdd72f..79080098026c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10322,8 +10322,8 @@ bool Sema::areMultiversionVariantFunctionsCompatible(
 ReturnType = 1,
 ConstexprSpec = 2,
 InlineSpec = 3,
-StorageClass = 4,
-Linkage = 5,
+Linkage = 4,
+LanguageLinkage = 5,
   };
 
   if (NoProtoDiagID.getDiagID() != 0 && OldFD &&
@@ -10397,11 +10397,11 @@ bool Sema::areMultiversionVariantFunctionsCompatible(
 if (OldFD->isInlineSpecified() != NewFD->isInlineSpecified())
   return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << InlineSpec;
 
-if (OldFD->getStorageClass() != NewFD->getStorageClass())
-  return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << StorageClass;
+if (OldFD->getFormalLinkage() != NewFD->getFormalLinkage())
+  return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << Linkage;
 
 if (!CLinkageMayDiffer && OldFD->isExternC() != NewFD->isExternC())
-  return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << Linkage;
+  return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << LanguageLinkage;
 
 if (CheckEquivalentExceptionSpec(
 OldFD->getType()->getAs(), OldFD->getLocation(),

diff  --git a/clang/test/SemaCXX/attr-cpuspecific.cpp 
b/clang/test/SemaCXX/attr-cpuspecific.cpp
index 861711b46383..fe4635816654 100644
--- a/clang/test/SemaCXX/attr-cpuspecific.cpp
+++ b/clang/test/SemaCXX/attr-cpuspecific.cpp
@@ -34,9 +34,19 @@ int __attribute__((cpu_specific(sandybridge))) foo2(void);
 constexpr int __attribute__((cpu_specific(ivybridge))) foo2(void);
 
 static int __attribute__((cpu_specific(sandybridge))) bar(void);
-//expected-error@+1 {{multiversioned function declaration has a 
diff erent storage class}}
+//expected-error@+1 {{multiversioned function declaration has a 
diff erent linkage}}
 int __attribute__((cpu_dispatch(ivybridge))) bar(void) {}
 
+// OK
+extern int __attribute__((cpu_specific(sandybridge))) bar2(void);
+int __attribute__((cpu_dispatch(ivybridge))) bar2(void) {}
+
+namespace {
+int __attribute__((cpu_specific(sandybridge))) bar3(void);
+static int __attribute__((cpu_dispatch(ivybridge))) bar3(void) {}
+}
+
+
 inline int __attribute__((cpu_specific(sandybridge))) baz(void);
 //expected-error@+1 {{multiversioned function declaration has a 
diff erent inline specification}}
 int __attribute__((cpu_specific(ivybridge))) baz(void) {return 1;}
@@ -74,7 +84,7 @@ struct S {
 extern "C" {
 int __attribute__((cpu_specific(atom))) 
diff _mangle(void) { return 0; }
 }
-//expected-error@+1 {{multiversioned function declaration has a 
diff erent linkage}}
+//expected-error@+1 {{multiversioned function declaration has a 
diff erent language linkage}}
 int __attribute__((cpu_specific(sandybridge))) 
diff _mangle(void) { return 0; }
 
 __attribute__((cpu_specific(atom))) void DiffDecl();

diff  --git a/clang/test/SemaCXX/attr-target-mv.cpp 
b/clang/test/SemaCXX/attr-target-mv.cpp
index 5ef1d398d2d8..5b2f0fc825f3 100644
--- a/clang/test/SemaCXX/attr-target-mv.cpp
+++ b/clang/test/SemaCXX/attr-target-mv.cpp
@@ -27,17 +27,26 @

[PATCH] D110255: Change error for storage-class to mean linkage, fix lang-linkage diag

2021-09-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


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

https://reviews.llvm.org/D110255

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


[PATCH] D109862: Don't diagnose unused but set when the Cleanup attribute is used.

2021-09-22 Thread Michael Benfield via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf9923674787: Don't diagnose unused but set when the 
Cleanup attribute is used. (authored by mbenfield).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109862

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/warn-unused-but-set-variables.c


Index: clang/test/Sema/warn-unused-but-set-variables.c
===
--- clang/test/Sema/warn-unused-but-set-variables.c
+++ clang/test/Sema/warn-unused-but-set-variables.c
@@ -49,3 +49,13 @@
   x = 0;
   (void) sizeof(x);
 }
+
+void for_cleanup(int *x) {
+  *x = 0;
+}
+
+void f3(void) {
+  // Don't warn if the __cleanup__ attribute is used.
+  __attribute__((__cleanup__(for_cleanup))) int x;
+  x = 5;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1921,8 +1921,10 @@
 }
 
 void Sema::DiagnoseUnusedButSetDecl(const VarDecl *VD) {
-  // If it's not referenced, it can't be set.
-  if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr())
+  // If it's not referenced, it can't be set. If it has the Cleanup attribute,
+  // it's not really unused.
+  if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr() ||
+  VD->hasAttr())
 return;
 
   const auto *Ty = VD->getType().getTypePtr()->getBaseElementTypeUnsafe();


Index: clang/test/Sema/warn-unused-but-set-variables.c
===
--- clang/test/Sema/warn-unused-but-set-variables.c
+++ clang/test/Sema/warn-unused-but-set-variables.c
@@ -49,3 +49,13 @@
   x = 0;
   (void) sizeof(x);
 }
+
+void for_cleanup(int *x) {
+  *x = 0;
+}
+
+void f3(void) {
+  // Don't warn if the __cleanup__ attribute is used.
+  __attribute__((__cleanup__(for_cleanup))) int x;
+  x = 5;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1921,8 +1921,10 @@
 }
 
 void Sema::DiagnoseUnusedButSetDecl(const VarDecl *VD) {
-  // If it's not referenced, it can't be set.
-  if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr())
+  // If it's not referenced, it can't be set. If it has the Cleanup attribute,
+  // it's not really unused.
+  if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr() ||
+  VD->hasAttr())
 return;
 
   const auto *Ty = VD->getType().getTypePtr()->getBaseElementTypeUnsafe();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] af99236 - Don't diagnose unused but set when the Cleanup attribute is used.

2021-09-22 Thread Michael Benfield via cfe-commits

Author: Michael Benfield
Date: 2021-09-22T17:48:09Z
New Revision: af99236747872af7e77092cbf6ddd18fa8623a2f

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

LOG: Don't diagnose unused but set when the Cleanup attribute is used.

This applies to -Wunused-but-set-variable and
-Wunused-but-set-parameter.

This addresses bug 51865.

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/warn-unused-but-set-variables.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index cc3417d4ccba..13389ebdd72f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1921,8 +1921,10 @@ void Sema::DiagnoseUnusedDecl(const NamedDecl *D) {
 }
 
 void Sema::DiagnoseUnusedButSetDecl(const VarDecl *VD) {
-  // If it's not referenced, it can't be set.
-  if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr())
+  // If it's not referenced, it can't be set. If it has the Cleanup attribute,
+  // it's not really unused.
+  if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr() ||
+  VD->hasAttr())
 return;
 
   const auto *Ty = VD->getType().getTypePtr()->getBaseElementTypeUnsafe();

diff  --git a/clang/test/Sema/warn-unused-but-set-variables.c 
b/clang/test/Sema/warn-unused-but-set-variables.c
index a8d05243321f..38042ba014c4 100644
--- a/clang/test/Sema/warn-unused-but-set-variables.c
+++ b/clang/test/Sema/warn-unused-but-set-variables.c
@@ -49,3 +49,13 @@ void f2 (void) {
   x = 0;
   (void) sizeof(x);
 }
+
+void for_cleanup(int *x) {
+  *x = 0;
+}
+
+void f3(void) {
+  // Don't warn if the __cleanup__ attribute is used.
+  __attribute__((__cleanup__(for_cleanup))) int x;
+  x = 5;
+}



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


[PATCH] D36850: [ThinLTO] Add norecurse function attribute propagation

2021-09-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added inline comments.



Comment at: llvm/include/llvm/IR/ModuleSummaryIndex.h:575
 unsigned AlwaysInline : 1;
+unsigned NoUnwind : 1;
+// Indicate if function contains instructions that mayThrow

tejohnson wrote:
> No Unwind needs a comment. And probably a note that it will be updated by 
> function attr propagation. Depends on how we want to handle inline asm calls 
> and other cases that currently set this true below (see my comment there).
Woops, the second sentence here "Depends on how we want to handle inline asm 
calls and other cases that currently set this true below (see my comment 
there)." I meant to add to the comment further below about the name of 
hasUnknownCall.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D36850

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


[PATCH] D36850: [ThinLTO] Add norecurse function attribute propagation

2021-09-22 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

Thanks for your patience, finally had a chance to go through everything much 
more carefully. Looks good, mostly a bunch of small or nitpicky final 
suggestions. The main comment/question of significance relates to where 
hasUnknownCall is being set currently.

Patch title and summary need an update.




Comment at: clang/test/CodeGen/thinlto-funcattr-prop.ll:14
+
+; RUN: llvm-dis %t/b.bc -o - | FileCheck %s
+

This is checking the summary generated by opt, not the result of the llvm-lto2 
run.



Comment at: llvm/include/llvm/IR/ModuleSummaryIndex.h:575
 unsigned AlwaysInline : 1;
+unsigned NoUnwind : 1;
+// Indicate if function contains instructions that mayThrow

No Unwind needs a comment. And probably a note that it will be updated by 
function attr propagation. Depends on how we want to handle inline asm calls 
and other cases that currently set this true below (see my comment there).



Comment at: llvm/include/llvm/IR/ModuleSummaryIndex.h:580
+// If there are calls to unknown targets (e.g. indirect)
+unsigned hasUnknownCall : 1;
+

tejohnson wrote:
> modimo wrote:
> > tejohnson wrote:
> > > Now that we have MayThrow, can we avoid a separate hasUnknownCall bool 
> > > and just conservatively set MayThrow true in that case?
> > hasUnknownCall is used for norecurse and other future flags as well to stop 
> > propagation.
> Ah that makes sense.
nit, maybe change this to hasIndirectCall which I think is more specific?



Comment at: llvm/include/llvm/LTO/LTO.h:26
 #include "llvm/Support/thread.h"
+#include "llvm/Transforms/IPO/FunctionAttrs.h"
 #include "llvm/Transforms/IPO/FunctionImport.h"

Is this needed?



Comment at: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp:379
   } else {
+HasUnknownCall = true;
 // Skip inline assembly calls.

Should this be moved below the following checks for inline asm and direct 
calls? (Not sure what the direct calls case is given that we handle direct 
calls to "known functions" above though).

If it should stay where it is and treat the below cases as unknown, probably 
should add tests for them.



Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:342
+// prevailing definitions and linkage types
+static FunctionSummary *calculateDefinitiveAttributes(
+ValueInfo VI, DenseMap &CachedAttributes,

Suggest renaming calculateDefinitiveAttributes and CachedAttributes to 
something like calculatePrevailingSummary and CachedPrevailingSummary which are 
more accurate now.



Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:484
+if (!CalleeSummary->fflags().NoUnwind ||
+CallerSummary->fflags().MayThrow)
+  InferredFlags.NoUnwind = false;

You've already set InferredFlags.NoUnwind to false above this loop in the case 
where MayThrow was set on the CallerSummary.



Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:499
+  ++NumThinLinkNoRecurse;
+  CachedAttributes[V]->setNoRecurse();
+}

I think you can remove this and the below setNoUnwind() call on 
CachedAttributes[V] since presumably this points to one of the function 
summaries we update in the below loop.



Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:531
+
+/// Insert function attributes in the Index back into the \p TheModule
+void llvm::thinLTOInsertFunctionAttrsForModule(

nit: suggest "Insert propagated function attributes from the Index ..."



Comment at: llvm/lib/Transforms/IPO/FunctionAttrs.cpp:537
+
+  for (Function &F : TheModule) {
+const auto &GV = DefinedGlobals.find(F.getGUID());

Consider consolidating this function with thinLTOResolvePrevailingInModule, to 
reduce the number of walks of the module and lookups into the DefinedGlobals 
map.



Comment at: llvm/test/ThinLTO/X86/funcattrs-prop-indirect.ll:3
+; RUN: opt -thinlto-bc %s -thin-link-bitcode-file=%t1.thinlink.bc -o %t1.bc
+; RUN: llvm-lto2 run -disable-thinlto-funcattrs=0 %t1.bc -o %t.o -r 
%t1.bc,indirect,px -save-temps
+; RUN: llvm-dis -o - %t.o.1.3.import.bc | FileCheck %s

Have a second version that tests with -thinlto-funcattrs-optimistic-indirect? I 
don't see a test for that option anywhere. Or maybe just remove that option - 
is it really needed?



Comment at: llvm/test/ThinLTO/X86/funcattrs-prop-indirect.ll:9
+
+; CHECK-NOT: ; Function Attrs: norecurse nounwind
+; CHECK: define i32 @indirect(i32 ()* nocapture %0) {

Perhaps this CHECK-NOT should just look for "Function Attrs:" as you do in some 
other tests below, in case some other attr is ever added to the IR that isn't 
related to this propagation, which could all

[PATCH] D109967: Simplify handling of builtin with inline redefinition

2021-09-22 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 374290.
serge-sans-paille added a comment.

Set default as suggested by @nickdesaulniers


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

https://reviews.llvm.org/D109967

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/memcpy-inline-builtin.c
  clang/test/CodeGen/memcpy-no-nobuiltin-if-not-emitted.c
  clang/test/CodeGen/memcpy-nobuiltin.c
  clang/test/CodeGen/pr9614.c

Index: clang/test/CodeGen/pr9614.c
===
--- clang/test/CodeGen/pr9614.c
+++ clang/test/CodeGen/pr9614.c
@@ -32,14 +32,14 @@
 
 // CHECK-LABEL: define{{.*}} void @f()
 // CHECK: call void @foo()
-// CHECK: call i32 @abs(i32 0)
+// CHECK: call i32 @abs(i32 %0)
 // CHECK: call i8* @strrchr(
 // CHECK: call void @llvm.prefetch.p0i8(
 // CHECK: call i8* @memchr(
 // CHECK: ret void
 
 // CHECK: declare void @foo()
-// CHECK: declare i32 @abs(i32
 // CHECK: declare i8* @strrchr(i8*, i32)
 // CHECK: declare i8* @memchr(
+// CHECK: declare i32 @abs(i32
 // CHECK: declare void @llvm.prefetch.p0i8(
Index: clang/test/CodeGen/memcpy-nobuiltin.c
===
--- clang/test/CodeGen/memcpy-nobuiltin.c
+++ clang/test/CodeGen/memcpy-nobuiltin.c
@@ -4,7 +4,8 @@
 //
 // CHECK-WITH-DECL-NOT: @llvm.memcpy
 // CHECK-NO-DECL: @llvm.memcpy
-// CHECK-SELF-REF-DECL: @llvm.memcpy
+// CHECK-SELF-REF-DECL-LABEL: define dso_local i8* @memcpy.inline
+// CHECK-SELF-REF-DECL:   @memcpy(
 //
 #include 
 void test(void *dest, void const *from, size_t n) {
Index: clang/test/CodeGen/memcpy-no-nobuiltin-if-not-emitted.c
===
--- clang/test/CodeGen/memcpy-no-nobuiltin-if-not-emitted.c
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - %s | FileCheck %s
-//
-// Verifies that clang doesn't mark an inline builtin definition as `nobuiltin`
-// if the builtin isn't emittable.
-
-typedef unsigned long size_t;
-
-// always_inline is used so clang will emit this body. Otherwise, we need >=
-// -O1.
-#define AVAILABLE_EXTERNALLY extern inline __attribute__((always_inline)) \
-__attribute__((gnu_inline))
-
-AVAILABLE_EXTERNALLY void *memcpy(void *a, const void *b, size_t c) {
-  return __builtin_memcpy(a, b, c);
-}
-
-// CHECK-LABEL: define{{.*}} void @foo
-void foo(void *a, const void *b, size_t c) {
-  // Clang will always _emit_ this as memcpy. LLVM turns it into @llvm.memcpy
-  // later on if optimizations are enabled.
-  // CHECK: call i8* @memcpy
-  memcpy(a, b, c);
-}
-
-// CHECK-NOT: nobuiltin
Index: clang/test/CodeGen/memcpy-inline-builtin.c
===
--- /dev/null
+++ clang/test/CodeGen/memcpy-inline-builtin.c
@@ -0,0 +1,44 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// RUN: %clang_cc1 -triple x86_64 -S -emit-llvm -o - %s | FileCheck %s
+//
+// Verifies that clang detects memcpy inline version and uses it instead of the builtin.
+
+typedef unsigned long size_t;
+
+// Clang requires these attributes for a function to be redefined.
+#define AVAILABLE_EXTERNALLY extern inline __attribute__((always_inline)) __attribute__((gnu_inline))
+
+// Clang recognizes an inline builtin and renames it to prevent conflict with builtins.
+AVAILABLE_EXTERNALLY void *memcpy(void *a, const void *b, size_t c) {
+  asm("# memcpy.inline marker");
+  return __builtin_memcpy(a, b, c);
+}
+
+// CHECK-LABEL: @foo(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR_I:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[B_ADDR_I:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[C_ADDR_I:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[C_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:store i8* [[A:%.*]], i8** [[A_ADDR]], align 8
+// CHECK-NEXT:store i8* [[B:%.*]], i8** [[B_ADDR]], align 8
+// CHECK-NEXT:store i64 [[C:%.*]], i64* [[C_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i8*, i8** [[A_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load i8*, i8** [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP2:%.*]] = load i64, i64* [[C_ADDR]], align 8
+// CHECK-NEXT:store i8* [[TMP0]], i8** [[A_ADDR_I]], align 8
+// CHECK-NEXT:store i8* [[TMP1]], i8** [[B_ADDR_I]], align 8
+// CHECK-NEXT:store i64 [[TMP2]], i64* [[C_ADDR_I]], align 8
+// CHECK-NEXT:call void asm sideeffect "# memcpy.inline marker", "~{dirflag},~{fpsr},~{flags}"() #[[ATTR2:[0-9]+]], !srcloc !2
+// CHECK-NEXT:[[TMP3:%.*]] = load i8*, i8** [[A_ADDR_I]], align 8
+// CHECK-NEXT:[[TMP4:%.*]] = load i8*, i8** [[B_ADDR_I]], align 8
+// CHECK-NEXT:[[TMP5:%.*]] = load i64, i64* [[C_ADDR_I]], align 8
+// CHECK-NEXT:call void @llvm.memcpy.p0i8.p0i8.

  1   2   >