[clang] [Clang] Automatically enable `-fconvergent-functions` on GPU targets (PR #111076)

2024-10-03 Thread Matt Arsenault via cfe-commits


@@ -4106,9 +4106,10 @@ bool CompilerInvocation::ParseLangArgs(LangOptions 
&Opts, ArgList &Args,
   Opts.Blocks = Args.hasArg(OPT_fblocks) || (Opts.OpenCL
 && Opts.OpenCLVersion == 200);
 
-  Opts.ConvergentFunctions = Args.hasArg(OPT_fconvergent_functions) ||
- Opts.OpenCL || (Opts.CUDA && Opts.CUDAIsDevice) ||
- Opts.SYCLIsDevice || Opts.HLSL;
+  Opts.ConvergentFunctions = Args.hasFlag(
+  OPT_fconvergent_functions, OPT_fno_convergent_functions,
+  Opts.OpenMPIsTargetDevice || T.isAMDGPU() || T.isNVPTX() || Opts.OpenCL 
||
+  Opts.CUDAIsDevice || Opts.SYCLIsDevice || Opts.HLSL);

arsenm wrote:

Sort all the language checks together, before the target list. We probably 
should have a hasConvergentOperations() predicate somewhere 

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


[clang] [Clang] Automatically enable `-fconvergent-functions` on GPU targets (PR #111076)

2024-10-03 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> -fno-convergent-functions to opt-out if you want to test broken behavior. 

You may legitimately know there are no convergent functions in the TU. We also 
have the noconvergent source attribute now for this 

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-10-03 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-10-03 Thread via cfe-commits


@@ -98,6 +98,13 @@ Improvements to clang-tidy
 New checks
 ^^
 
+- New :doc:`bugprone-incorrect-enable-shared-from-this
+  ` check.
+
+  Check if class/structs publicly inherits from 
``std::enable_shared_from_this``,

EugeneZelenko wrote:

```suggestion
  Detects if class/structs publicly inherits from 
``std::enable_shared_from_this``,
```
This is continuation of previous statement, so `check checks` does not sound 
well.

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-10-03 Thread via cfe-commits

MichelleCDjunaidi wrote:

@EugeneZelenko @5chmidti Any updates on the feedback? Is this ready to merge?

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


[clang] [clang-format] Make some binary operations imply requires clause (PR #110942)

2024-10-03 Thread Owen Pan via cfe-commits


@@ -3528,6 +3528,17 @@ bool UnwrappedLineParser::parseRequires() {
 return false;
   }
   break;
+case tok::equalequal:
+case tok::greaterequal:
+case tok::lessequal:
+case tok::r_paren:
+case tok::pipepipe:
+  if (OpenAngles == 0) {
+FormatTok = Tokens->setPosition(StoredPosition);
+parseRequiresClause(RequiresToken);
+return true;
+  }
+  break;

owenca wrote:

If we are doing a limited fix now, maybe just move the `case tok::amp:` up as 
suggested above? It would cover patterns similar to that in #110485 no matter 
what operator is used in the parenthesized expression after `& requires`.

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


[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-10-03 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-bootstrap-ubsan` running on `sanitizer-buildbot4` while 
building `clang` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/25/builds/3046


Here is the relevant piece of the build log for the reference

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 86069 tests, 88 workers --
Testing:  0.
FAIL: Clang :: CodeGen/attr-target-version-riscv-invalid.c (6616 of 86069)
 TEST 'Clang :: 
CodeGen/attr-target-version-riscv-invalid.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: not 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/lib/clang/20/include
 -nostdsysteminc -triple riscv64 -target-feature +i -emit-llvm -o - 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c
 2>&1 | 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/FileCheck
 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c
 --check-prefix=CHECK-UNSUPPORT-OS
+ not 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/lib/clang/20/include
 -nostdsysteminc -triple riscv64 -target-feature +i -emit-llvm -o - 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c
+ 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/FileCheck
 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c
 --check-prefix=CHECK-UNSUPPORT-OS
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c:3:24:
 error: CHECK-UNSUPPORT-OS: expected string not found in input
// CHECK-UNSUPPORT-OS: error: function multiversioning is currently only 
supported on Linux
   ^
:1:1: note: scanning from here
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c:8:48:
 error: function multiversioning doesn't support feature '|'
^
:1:128: note: possible intended match here
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c:8:48:
 error: function multiversioning doesn't support feature '|'

   ^

Input file: 
Check file: 
/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c

-dump-input=help explains the following input dum

[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-10-03 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-bootstrap-asan` running on `sanitizer-buildbot2` while 
building `clang` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/52/builds/2670


Here is the relevant piece of the build log for the reference

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 86068 of 86069 tests, 88 workers --
Testing:  0.
FAIL: Clang :: CodeGen/attr-target-version-riscv.c (6772 of 86068)
 TEST 'Clang :: CodeGen/attr-target-version-riscv.c' FAILED 

Exit Code: 2

Command Output (stderr):
--
RUN: at line 2: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/20/include
 -nostdsysteminc -triple riscv64-linux-gnu -target-feature +i -emit-llvm -o - 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/CodeGen/attr-target-version-riscv.c
 | 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/CodeGen/attr-target-version-riscv.c
+ /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/20/include
 -nostdsysteminc -triple riscv64-linux-gnu -target-feature +i -emit-llvm -o - 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/CodeGen/attr-target-version-riscv.c
+ 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/CodeGen/attr-target-version-riscv.c
=
==856967==ERROR: AddressSanitizer: heap-use-after-free on address 
0x6c706d6290a2 at pc 0x60a5a52d007d bp 0x7ffe112f6770 sp 0x7ffe112f6768
READ of size 1 at 0x6c706d6290a2 thread T0
#0 0x60a5a52d007c in ascii_strncasecmp 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Support/StringRef.cpp:30:33
#1 0x60a5a52d007c in llvm::StringRef::compare_insensitive(llvm::StringRef) 
const 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Support/StringRef.cpp:38:17
#2 0x60a5a5418dcd in equals_insensitive 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/StringRef.h:176:38
#3 0x60a5a5418dcd in 
llvm::RISCVISAInfo::getRISCVFeaturesBitsInfo(llvm::StringRef) 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/lib/TargetParser/RISCVISAInfo.cpp:1063:15
#4 0x60a5a654391e in 
clang::targets::RISCVTargetInfo::validateCpuSupports(llvm::StringRef) const 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/lib/Basic/Targets/RISCV.cpp:483:16
#5 0x60a5ab7d1e6f in CheckMultiVersionValue(clang::Sema&, 
clang::FunctionDecl con

[clang] [Clang][Driver] Support relative paths for CLANG_CONFIG_FILE_SYSTEM_DIR (PR #110962)

2024-10-03 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.


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


[clang] [Clang][Driver] Support relative paths for CLANG_CONFIG_FILE_SYSTEM_DIR (PR #110962)

2024-10-03 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Note: you are using github's private email address feature, but llvm-project 
prefers to show the real email address. Actually, there is a bot detecting the 
issue and making a message, though it has some issues and does not trigger on 
this PR.

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


[clang] [llvm] [PGO]Add `-fdiagnostics-show-profile-count` option to show real loop count from instr-profile (PR #75021)

2024-10-03 Thread Elvis Wang via cfe-commits

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


[clang] 1e5e153 - Revert "[RISCV][FMV] Support target_version" (#111096)

2024-10-03 Thread via cfe-commits

Author: Piyou Chen
Date: 2024-10-04T12:02:39+08:00
New Revision: 1e5e153485b817422c311f9326e80781a83ea7bc

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

LOG: Revert "[RISCV][FMV] Support target_version" (#111096)

Reverts llvm/llvm-project#99040 due to 
https://lab.llvm.org/buildbot/#/builders/190/builds/7052

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 
clang/test/CodeGen/attr-target-version-riscv-invalid.c
clang/test/CodeGen/attr-target-version-riscv.c
clang/test/CodeGenCXX/attr-target-version-riscv.cpp
clang/test/SemaCXX/attr-target-version-riscv.cpp



diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 034fbbe0bc7829..a81429ad6a2380 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14325,17 +14325,9 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
 }
   } else if (const auto *TV = FD->getAttr()) {
-std::vector Features;
-if (Target->getTriple().isRISCV()) {
-  ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(TV->getName());
-  Features.insert(Features.begin(), ParsedAttr.Features.begin(),
-  ParsedAttr.Features.end());
-} else {
-  assert(Target->getTriple().isAArch64());
-  llvm::SmallVector Feats;
-  TV->getFeatures(Feats);
-  Features = getFMVBackendFeaturesFor(Feats);
-}
+llvm::SmallVector Feats;
+TV->getFeatures(Feats);
+std::vector Features = getFMVBackendFeaturesFor(Feats);
 Features.insert(Features.begin(),
 Target->getTargetOpts().FeaturesAsWritten.begin(),
 Target->getTargetOpts().FeaturesAsWritten.end());

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 5ba098144a74e7..25c1c496a4f27f 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4287,13 +4287,8 @@ void CodeGenModule::emitMultiVersionFunctions() {
   } else if (const auto *TVA = CurFD->getAttr()) {
 if (TVA->isDefaultVersion() && IsDefined)
   ShouldEmitResolver = true;
+TVA->getFeatures(Feats);
 llvm::Function *Func = createFunction(CurFD);
-if (getTarget().getTriple().isRISCV()) {
-  Feats.push_back(TVA->getName());
-} else {
-  assert(getTarget().getTriple().isAArch64());
-  TVA->getFeatures(Feats);
-}
 Options.emplace_back(Func, /*Architecture*/ "", Feats);
   } else if (const auto *TC = CurFD->getAttr()) {
 if (IsDefined)

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 21f25a2ea09eb0..2bf610746bc317 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10329,8 +10329,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   // Handle attributes.
   ProcessDeclAttributes(S, NewFD, D);
   const auto *NewTVA = NewFD->getAttr();
-  if (Context.getTargetInfo().getTriple().isAArch64() && NewTVA &&
-  !NewTVA->isDefaultVersion() &&
+  if (NewTVA && !NewTVA->isDefaultVersion() &&
   !Context.getTargetInfo().hasFeature("fmv")) {
 // Don't add to scope fmv functions declarations if fmv disabled
 AddToScope = false;
@@ -11039,15 +11038,7 @@ static bool CheckMultiVersionValue(Sema &S, const 
FunctionDecl *FD) {
 
   if (TVA) {
 llvm::SmallVector Feats;
-if (S.getASTContext().getTargetInfo().getTriple().isRISCV()) {
-  ParsedTargetAttr ParseInfo =
-  S.getASTContext().getTargetInfo().parseTargetAttr(TVA->getName());
-  for (auto &Feat : ParseInfo.Features)
-Feats.push_back(StringRef{Feat}.substr(1));
-} else {
-  assert(S.getASTContext().getTargetInfo().getTriple().isAArch64());
-  TVA->getFeatures(Feats);
-}
+TVA->getFeatures(Feats);
 for (const auto &Feat : Feats) {
   if (!TargetInfo.validateCpuSupports(Feat)) {
 S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
@@ -11333,8 +11324,7 @@ static bool 
PreviousDeclsHaveMultiVersionAttribute(const FunctionDecl *FD) {
 }
 
 static void patchDefaultTargetVersion(FunctionDecl *From, FunctionDecl *To) {
-  if (!From->getASTContext().getTargetInfo().getTriple().isAArch64() &&
-  !From->getASTContext().getTargetInfo().getTriple().isRISCV())
+  if (!From->getASTContext().getTargetInfo().getTriple().isAArch64())
 return;
 
   MultiVersionKind MVKindFrom = From->getMultiVersionKind();
@@ -15521,8 +15511,7 @@ Decl *Sema::ActOnStartO

[clang] Revert "[RISCV][FMV] Support target_version" (PR #111096)

2024-10-03 Thread Piyou Chen via cfe-commits

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-10-03 Thread via cfe-commits


@@ -0,0 +1,34 @@
+.. title:: clang-tidy - bugprone-incorrect-enable-shared-from-this
+
+bugprone-incorrect-enable-shared-from-this
+==
+
+Checks if a class or struct publicly inherits from 
+``std::enable_shared_from_this``, because unintended behavior will 
+otherwise occur when calling ``shared_from_this``.
+
+Consider the following code:
+
+.. code-block:: c++
+
+#include 
+
+// private inheritance
+class BadExample : std::enable_shared_from_this {
+
+// ``shared_from_this``` unintended behaviour
+// libstd implementation returns uninitialized ``weak_ptr``
+public:
+BadExample* foo() { return shared_from_this().get(); }
+void bar() { return; }
+};
+
+void using_not_public() {
+auto bad_example = std::make_shared();
+auto* b_ex = bad_example->foo();
+b_ex->bar();
+}
+
+Using ``libstd`` implementation, ``shared_from_this`` will throw 

EugeneZelenko wrote:

```suggestion
Using `libstd` implementation, ``shared_from_this`` will throw 
```

`libstdc++`?

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


[clang] [clang-format] Handle template closer followed by braces (PR #110971)

2024-10-03 Thread Owen Pan via cfe-commits


@@ -3538,6 +3538,11 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) {
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
   EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser);
+
+  Tokens = annotate("return std::conditional_t{};");
+  ASSERT_EQ(Tokens.size(), 21u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[16], tok::greater, TT_TemplateCloser);

owenca wrote:

The root cause was the misannotation of the `>`, so we add an annotation test 
instead of verifying the spacing directly.

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-10-03 Thread via cfe-commits


@@ -0,0 +1,34 @@
+.. title:: clang-tidy - bugprone-incorrect-enable-shared-from-this
+
+bugprone-incorrect-enable-shared-from-this
+==
+
+Checks if a class or struct publicly inherits from 
+``std::enable_shared_from_this``, because unintended behavior will 
+otherwise occur when calling ``shared_from_this``.
+
+Consider the following code:
+
+.. code-block:: c++
+
+#include 
+
+// private inheritance
+class BadExample : std::enable_shared_from_this {
+
+// ``shared_from_this``` unintended behaviour
+// libstd implementation returns uninitialized ``weak_ptr``
+public:
+BadExample* foo() { return shared_from_this().get(); }
+void bar() { return; }
+};
+
+void using_not_public() {
+auto bad_example = std::make_shared();
+auto* b_ex = bad_example->foo();
+b_ex->bar();
+}
+
+Using ``libstd`` implementation, ``shared_from_this`` will throw 

MichelleCDjunaidi wrote:

Yeah, libstdc++. Will change.

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-10-03 Thread via cfe-commits


@@ -98,6 +98,13 @@ Improvements to clang-tidy
 New checks
 ^^
 
+- New :doc:`bugprone-incorrect-enable-shared-from-this
+  ` check.
+
+  Check if class/structs publicly inherits from 
``std::enable_shared_from_this``,

MichelleCDjunaidi wrote:

Noted, will do.

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


[clang] Revert "[RISCV][FMV] Support target_version" (PR #111096)

2024-10-03 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-arm-ubuntu` running 
on `linaro-lldb-arm-ubuntu` while building `clang` at step 6 "test".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/18/builds/4906


Here is the relevant piece of the build log for the reference

```
Step 6 (test) failure: build (failure)
...
UNSUPPORTED: lldb-api :: 
lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py (789 of 
2809)
PASS: lldb-api :: lang/cpp/global_variables/TestCPPGlobalVariables.py (790 of 
2809)
UNSUPPORTED: lldb-api :: lang/cpp/gmodules/templates/TestGModules.py (791 of 
2809)
PASS: lldb-api :: 
lang/cpp/incompatible-class-templates/TestCppIncompatibleClassTemplates.py (792 
of 2809)
PASS: lldb-api :: lang/cpp/incomplete-stl-types/TestStlIncompleteTypes.py (793 
of 2809)
PASS: lldb-api :: 
lang/cpp/incomplete-types/members/TestCppIncompleteTypeMembers.py (794 of 2809)
PASS: lldb-api :: lang/cpp/keywords_enabled/TestCppKeywordsEnabled.py (795 of 
2809)
PASS: lldb-api :: lang/cpp/incomplete-types/TestCppIncompleteTypes.py (796 of 
2809)
PASS: lldb-api :: lang/cpp/inlines/TestInlines.py (797 of 2809)
PASS: lldb-api :: lang/cpp/lambdas/TestLambdas.py (798 of 2809)
FAIL: lldb-api :: 
lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py (799 of 2809)
 TEST 'lldb-api :: 
lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py' FAILED 

Script:
--
/usr/bin/python3.10 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py 
-u CXXFLAGS -u CFLAGS --env ARCHIVER=/usr/local/bin/llvm-ar --env 
OBJCOPY=/usr/bin/llvm-objcopy --env 
LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env 
LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env 
LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch 
armv8l --build-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb 
--compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang 
--dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil 
--llvm-tools-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin 
--lldb-obj-root /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb 
--lldb-libs-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/lang/c/shared_lib_stripped_symbols
 -p TestSharedLibStrippedSymbols.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision 
1e5e153485b817422c311f9326e80781a83ea7bc)
  clang revision 1e5e153485b817422c311f9326e80781a83ea7bc
  llvm revision 1e5e153485b817422c311f9326e80781a83ea7bc
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 
'debugserver', 'objc']

--
Command Output (stderr):
--
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_expr_dsym (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase) (test 
case does not fall in any category of interest for this run) 
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_expr_dwarf (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
FAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_expr_dwo (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_frame_variable_dsym 
(TestSharedLibStrippedSymbols.SharedLibStrippedTestCase) (test case does not 
fall in any category of interest for this run) 
XFAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_frame_variable_dwarf 
(TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
XFAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_frame_variable_dwo (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
==
FAIL: test_expr_dwo (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
   Test that types work when defined in a shared library and forwa/d-declared 
in the main executable
--
Traceback (most recent call last):
  File 
"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py",
 line 1769, in test_method
return attrvalue(self)
  File 
"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/lang/c/shared_lib_stripped_sy

[clang] [Clang][Driver] Support relative paths for CLANG_CONFIG_FILE_SYSTEM_DIR (PR #110962)

2024-10-03 Thread Carlo Cabrera via cfe-commits

carlocab wrote:

I authored my commit using a working email address. See the 
[header](https://github.com/llvm/llvm-project/commit/e31545f666eb4ca32030956a38dbc4078a64068c.patch)
 of the patch:
```
>From e31545f666eb4ca32030956a38dbc4078a64068c Mon Sep 17 00:00:00 2001
From: Carlo Cabrera 
Date: Thu, 3 Oct 2024 14:15:07 +0800
Subject: [PATCH] [Clang][Driver] Support relative paths for
 CLANG_CONFIG_FILE_SYSTEM_DIR
```
Is that insufficient?

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


[clang] [llvm] [IR] Allow fast math flags on calls with homogeneous FP struct types (PR #110506)

2024-10-03 Thread Mikael Holmén via cfe-commits

mikaelholmen wrote:

Hi,

I bisected a crash to this patch. I can't share the C reproducer but it's 
instcombine that crashes and a reduced reproducer for that is
```opt -passes=instcombine bbi-99792.ll -o /dev/null```

[bbi-99792.ll.gz](https://github.com/user-attachments/files/17253640/bbi-99792.ll.gz)


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


[clang] [libc] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)

2024-10-03 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

IIRC, you discussed once to have GPU-agnostic intrinsics in LLVM-IR. The 
backends then have to handle the details.

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


[clang] [clang-format] Handle template closer followed by braces (PR #110971)

2024-10-03 Thread Carlos Galvez via cfe-commits


@@ -3538,6 +3538,11 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) {
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
   EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser);
+
+  Tokens = annotate("return std::conditional_t{};");
+  ASSERT_EQ(Tokens.size(), 21u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[16], tok::greater, TT_TemplateCloser);

carlosgalvezp wrote:

Ok, thanks for the clarification!

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


[clang] [Clang][Driver] Support relative paths for CLANG_CONFIG_FILE_SYSTEM_DIR (PR #110962)

2024-10-03 Thread Carlo Cabrera via cfe-commits

carlocab wrote:

That's annoying. Thanks GitHub. I've updating my settings now.

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


[clang] [Clang][Driver] Support relative paths for CLANG_CONFIG_FILE_SYSTEM_DIR (PR #110962)

2024-10-03 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> This commit will be authored by 30379873+carlo...@users.noreply.github.com

"Squash and merge" uses the PR author's github's setting. The commit email is 
completely ignored (unless there is another contributor, which would lead to a 
Co-authored-by:)

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


[clang] [clang] Implement constexpr __builtin_bit_cast for complex types (PR #109981)

2024-10-03 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][docs] Add documentation for APValue constructors (PR #109994)

2024-10-03 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/109994

>From 5a0832c88169e12e43deb498ead994e04966bb59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 25 Sep 2024 16:42:55 +0200
Subject: [PATCH] [clang][docs] Add documentation for APValue constructors

---
 clang/include/clang/AST/APValue.h | 68 +--
 1 file changed, 56 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/AST/APValue.h 
b/clang/include/clang/AST/APValue.h
index c4206b73b11562..7869ee386689d7 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -314,51 +314,95 @@ class APValue {
   DataType Data;
 
 public:
+  /// Creates an empty APValue of type None.
   APValue() : Kind(None) {}
+  /// Creates an integer APValue holding the given value.
   explicit APValue(APSInt I) : Kind(None) {
 MakeInt(); setInt(std::move(I));
   }
+  /// Creates a float APValue holding the given value.
   explicit APValue(APFloat F) : Kind(None) {
 MakeFloat(); setFloat(std::move(F));
   }
+  /// Creates a fixed-point APValue holding the given value.
   explicit APValue(APFixedPoint FX) : Kind(None) {
 MakeFixedPoint(std::move(FX));
   }
+  /// Creates a vector APValue with \p N elements. The elements
+  /// are read from \p E.
   explicit APValue(const APValue *E, unsigned N) : Kind(None) {
 MakeVector(); setVector(E, N);
   }
+  /// Creates an integer complex APValue with the given real and imaginary
+  /// values.
   APValue(APSInt R, APSInt I) : Kind(None) {
 MakeComplexInt(); setComplexInt(std::move(R), std::move(I));
   }
+  /// Creates a float complex APValue with the given real and imaginary values.
   APValue(APFloat R, APFloat I) : Kind(None) {
 MakeComplexFloat(); setComplexFloat(std::move(R), std::move(I));
   }
   APValue(const APValue &RHS);
   APValue(APValue &&RHS);
-  APValue(LValueBase B, const CharUnits &O, NoLValuePath N,
+  /// Creates an lvalue APValue without an lvalue path.
+  /// \param Base The base of the lvalue.
+  /// \param Offset The offset of the lvalue.
+  /// \param IsNullPtr Whether this lvalue is a null pointer.
+  APValue(LValueBase Base, const CharUnits &Offset, NoLValuePath,
   bool IsNullPtr = false)
   : Kind(None) {
-MakeLValue(); setLValue(B, O, N, IsNullPtr);
-  }
-  APValue(LValueBase B, const CharUnits &O, ArrayRef Path,
-  bool OnePastTheEnd, bool IsNullPtr = false)
+MakeLValue();
+setLValue(Base, Offset, NoLValuePath{}, IsNullPtr);
+  }
+  /// Creates an lvalue APValue with an lvalue path.
+  /// \param Base The base of the lvalue.
+  /// \param Offset The offset of the lvalue.
+  /// \param Path The lvalue path.
+  /// \param OnePastTheEnd Whether this lvalue is one-past-the-end of the
+  /// subobject it points to.
+  /// \param IsNullPtr Whether this lvalue is a null pointer.
+  APValue(LValueBase Base, const CharUnits &Offset,
+  ArrayRef Path, bool OnePastTheEnd,
+  bool IsNullPtr = false)
   : Kind(None) {
-MakeLValue(); setLValue(B, O, Path, OnePastTheEnd, IsNullPtr);
-  }
+MakeLValue();
+setLValue(Base, Offset, Path, OnePastTheEnd, IsNullPtr);
+  }
+  /// Creates a new array APValue.
+  /// \param UninitArray Marker. Pass an empty UninitArray.
+  /// \param InitElts Number of elements you're going to initialize in the
+  /// array.
+  /// \param Size Full size of the array.
   APValue(UninitArray, unsigned InitElts, unsigned Size) : Kind(None) {
 MakeArray(InitElts, Size);
   }
-  APValue(UninitStruct, unsigned B, unsigned M) : Kind(None) {
-MakeStruct(B, M);
-  }
-  explicit APValue(const FieldDecl *D, const APValue &V = APValue())
+  /// Creates a new struct APValue.
+  /// \param UninitStruct Marker. Pass an empty UninitStruct.
+  /// \param NumBases Number of bases.
+  /// \param NumMembers Number of members.
+  APValue(UninitStruct, unsigned NumBases, unsigned NumMembers) : Kind(None) {
+MakeStruct(NumBases, NumMembers);
+  }
+  /// Creates a new union APValue.
+  /// \param ActiveDecl The FieldDecl of the active union member.
+  /// \param ActiveValue The value of the active union member.
+  explicit APValue(const FieldDecl *ActiveDecl,
+   const APValue &ActiveValue = APValue())
   : Kind(None) {
-MakeUnion(); setUnion(D, V);
+MakeUnion();
+setUnion(ActiveDecl, ActiveValue);
   }
+  /// Creates a new member pointer APValue.
+  /// \param Member Declaration of the member
+  /// \param IsDerivedMember Whether member is a derived one.
+  /// \param Path The path of the member.
   APValue(const ValueDecl *Member, bool IsDerivedMember,
   ArrayRef Path) : Kind(None) {
 MakeMemberPointer(Member, IsDerivedMember, Path);
   }
+  /// Creates a new address label diff APValue.
+  /// \param LHSExpr The left-hand side of the difference.
+  /// \param RHSExpr The right-hand side of the difference.
   APValue(const AddrLabelExpr* LHSExpr, const Ad

[clang] 1682c99 - [Clang][Driver] Support relative paths for CLANG_CONFIG_FILE_SYSTEM_DIR (#110962)

2024-10-03 Thread via cfe-commits

Author: Carlo Cabrera
Date: 2024-10-03T23:10:03-07:00
New Revision: 1682c99a8877364f1d847395cef501e813804caa

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

LOG: [Clang][Driver] Support relative paths for CLANG_CONFIG_FILE_SYSTEM_DIR 
(#110962)

Shipping a system configuration file for Clang is useful, but it limits
the relocatability of the toolchain because it bakes in a reference to
an absolute path on the file system.

Let's fix that by allowing for `CLANG_CONFIG_FILE_SYSTEM_DIR` to be set
to a relative path, and then interpreting that relative to the location
of the driver if applicable.

This would be useful for the LLVM package we ship at Homebrew. We
currently have to bake in a `DEFAULT_SYSROOT` in order to ship a
toolchain that works out of the box on macOS. If
`CLANG_CONFIG_FILE_SYSTEM_DIR` supported relative paths, we could
replace that with a configuration file which would be easier to update
when the compiled-in `DEFAULT_SYSROOT` becomes stale (e.g. on macOS
version upgrades).

We could, of course, set `CLANG_CONFIG_FILE_SYSTEM_DIR` to an absolute
path to begin with. However, we do have users who install Homebrew into
a prefix that is different from the one used on our buildbots, so doing
this would result in a broken toolchain for those users.

Added: 


Modified: 
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 10d72be2c3d658..e9bf60d5e2ee46 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -229,7 +229,14 @@ Driver::Driver(StringRef ClangExecutable, StringRef 
TargetTriple,
   }
 
 #if defined(CLANG_CONFIG_FILE_SYSTEM_DIR)
-  SystemConfigDir = CLANG_CONFIG_FILE_SYSTEM_DIR;
+  if (llvm::sys::path::is_absolute(CLANG_CONFIG_FILE_SYSTEM_DIR)) {
+SystemConfigDir = CLANG_CONFIG_FILE_SYSTEM_DIR;
+  } else {
+SmallString<128> configFileDir(Dir);
+llvm::sys::path::append(configFileDir, CLANG_CONFIG_FILE_SYSTEM_DIR);
+llvm::sys::path::remove_dots(configFileDir, true);
+SystemConfigDir = static_cast(configFileDir);
+  }
 #endif
 #if defined(CLANG_CONFIG_FILE_USER_DIR)
   {



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


[clang] [Clang][Driver] Support relative paths for CLANG_CONFIG_FILE_SYSTEM_DIR (PR #110962)

2024-10-03 Thread Fangrui Song via cfe-commits

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


[clang] [Clang][Driver] Support relative paths for CLANG_CONFIG_FILE_SYSTEM_DIR (PR #110962)

2024-10-03 Thread via cfe-commits

github-actions[bot] wrote:



@carlocab Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang-tools-extra] [clang-tidy] Create bugprone-bitwise-pointer-cast check (PR #108083)

2024-10-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/108083

>From 1b1d54e0ce0d0bc4250ff045840b0a0a7bac59a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Tue, 10 Sep 2024 13:46:51 +
Subject: [PATCH 1/2] [clang-tidy] Create bugprone-bitwise-pointer-cast check

To detect unsafe usages of casting a pointer to another via copying
the bytes from one into the other, either via std::bit_cast or via
memcpy.use of bit_cast. This is currently not caught by any other
means.

Fixes #106987
---
 .../bugprone/BitwisePointerCastCheck.cpp  | 44 +
 .../bugprone/BitwisePointerCastCheck.h| 34 +++
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  8 ++-
 .../checks/bugprone/bitwise-pointer-cast.rst  | 52 
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../bugprone/bitwise-pointer-cast.cpp | 61 +++
 8 files changed, 203 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/bitwise-pointer-cast.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/bitwise-pointer-cast.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.cpp
new file mode 100644
index 00..3a361a22ed9b73
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.cpp
@@ -0,0 +1,44 @@
+//===--- BitwisePointerCastCheck.cpp - clang-tidy 
-===//
+//
+// 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 "BitwisePointerCastCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void BitwisePointerCastCheck::registerMatchers(MatchFinder *Finder) {
+  auto IsPointerType = refersToType(qualType(isAnyPointer()));
+  Finder->addMatcher(callExpr(hasDeclaration(functionDecl(allOf(
+  hasName("::std::bit_cast"),
+  hasTemplateArgument(0, IsPointerType),
+  hasTemplateArgument(1, IsPointerType)
+ .bind("bit_cast"),
+ this);
+
+  auto IsDoublePointerType =
+  hasType(qualType(pointsTo(qualType(isAnyPointer();
+  Finder->addMatcher(callExpr(hasArgument(0, IsDoublePointerType),
+  hasArgument(1, IsDoublePointerType),
+  
hasDeclaration(functionDecl(hasName("::memcpy"
+ .bind("memcpy"),
+ this);
+}
+
+void BitwisePointerCastCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto *Call = Result.Nodes.getNodeAs("bit_cast"))
+diag(Call->getBeginLoc(),
+ "do not use 'std::bit_cast' to cast between pointers")
+<< Call->getSourceRange();
+  else if (const auto *Call = Result.Nodes.getNodeAs("memcpy"))
+diag(Call->getBeginLoc(), "do not use 'memcpy' to cast between pointers")
+<< Call->getSourceRange();
+}
+
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.h
new file mode 100644
index 00..1515519b3c9fda
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.h
@@ -0,0 +1,34 @@
+//===--- BitwisePointerCastCheck.h - clang-tidy -*- 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BITWISEPOINTERCASTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BITWISEPOINTERCASTCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// Warns about code that tries to cast between pointers by means of
+/// ``std::bit_cast`` or ``memcpy``.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/bitwise-pointer-cast.html
+class BitwisePointerCastCheck : public ClangTidyCheck {
+public:
+  BitwisePointerCastCheck(StringRef Nam

[clang-tools-extra] [clang-tidy] Create bugprone-bitwise-pointer-cast check (PR #108083)

2024-10-03 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/108083

>From 1b1d54e0ce0d0bc4250ff045840b0a0a7bac59a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Tue, 10 Sep 2024 13:46:51 +
Subject: [PATCH 1/2] [clang-tidy] Create bugprone-bitwise-pointer-cast check

To detect unsafe usages of casting a pointer to another via copying
the bytes from one into the other, either via std::bit_cast or via
memcpy.use of bit_cast. This is currently not caught by any other
means.

Fixes #106987
---
 .../bugprone/BitwisePointerCastCheck.cpp  | 44 +
 .../bugprone/BitwisePointerCastCheck.h| 34 +++
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  8 ++-
 .../checks/bugprone/bitwise-pointer-cast.rst  | 52 
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../bugprone/bitwise-pointer-cast.cpp | 61 +++
 8 files changed, 203 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/bitwise-pointer-cast.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/bitwise-pointer-cast.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.cpp
new file mode 100644
index 00..3a361a22ed9b73
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.cpp
@@ -0,0 +1,44 @@
+//===--- BitwisePointerCastCheck.cpp - clang-tidy 
-===//
+//
+// 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 "BitwisePointerCastCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void BitwisePointerCastCheck::registerMatchers(MatchFinder *Finder) {
+  auto IsPointerType = refersToType(qualType(isAnyPointer()));
+  Finder->addMatcher(callExpr(hasDeclaration(functionDecl(allOf(
+  hasName("::std::bit_cast"),
+  hasTemplateArgument(0, IsPointerType),
+  hasTemplateArgument(1, IsPointerType)
+ .bind("bit_cast"),
+ this);
+
+  auto IsDoublePointerType =
+  hasType(qualType(pointsTo(qualType(isAnyPointer();
+  Finder->addMatcher(callExpr(hasArgument(0, IsDoublePointerType),
+  hasArgument(1, IsDoublePointerType),
+  
hasDeclaration(functionDecl(hasName("::memcpy"
+ .bind("memcpy"),
+ this);
+}
+
+void BitwisePointerCastCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto *Call = Result.Nodes.getNodeAs("bit_cast"))
+diag(Call->getBeginLoc(),
+ "do not use 'std::bit_cast' to cast between pointers")
+<< Call->getSourceRange();
+  else if (const auto *Call = Result.Nodes.getNodeAs("memcpy"))
+diag(Call->getBeginLoc(), "do not use 'memcpy' to cast between pointers")
+<< Call->getSourceRange();
+}
+
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.h
new file mode 100644
index 00..1515519b3c9fda
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.h
@@ -0,0 +1,34 @@
+//===--- BitwisePointerCastCheck.h - clang-tidy -*- 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BITWISEPOINTERCASTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BITWISEPOINTERCASTCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// Warns about code that tries to cast between pointers by means of
+/// ``std::bit_cast`` or ``memcpy``.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/bitwise-pointer-cast.html
+class BitwisePointerCastCheck : public ClangTidyCheck {
+public:
+  BitwisePointerCastCheck(StringRef Nam

[clang] [HLSL] get inout/out ABI for array parameters working (PR #111047)

2024-10-03 Thread Sarah Spall via cfe-commits

https://github.com/spall created 
https://github.com/llvm/llvm-project/pull/111047

Get inout/out parameters working for HLSL Arrays.
Utilizes the fix from #109323, and corrects the assignment behavior slightly to 
allow for Non-LValues on the RHS. 
Closes #106917 

>From c73ce3707e59242b8ccbb6757a290938c2d39e5e Mon Sep 17 00:00:00 2001
From: Sarah Spall 
Date: Tue, 17 Sep 2024 20:25:46 +
Subject: [PATCH 1/4] theoretically fix issue

---
 clang/lib/Sema/SemaType.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index c44fc9c4194ca4..8c80ece635fbff 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5675,6 +5675,9 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
   assert(!T.isNull() && "T must not be null at the end of this function");
   if (!AreDeclaratorChunksValid)
 return Context.getTrivialTypeSourceInfo(T);
+
+  if (state.didParseHLSLParamMod() && !T->isConstantArrayType())
+T = S.HLSL().getInoutParameterType(T);
   return GetTypeSourceInfoForDeclarator(state, T, TInfo);
 }
 
@@ -8562,7 +8565,6 @@ static void 
HandleHLSLParamModifierAttr(TypeProcessingState &State,
 return;
   if (Attr.getSemanticSpelling() == HLSLParamModifierAttr::Keyword_inout ||
   Attr.getSemanticSpelling() == HLSLParamModifierAttr::Keyword_out) {
-CurType = S.HLSL().getInoutParameterType(CurType);
 State.setParsedHLSLParamMod(true);
   }
 }

>From 0f64ad26f2218a037694b01649a4ebd5e2bf766c Mon Sep 17 00:00:00 2001
From: Sarah Spall 
Date: Wed, 2 Oct 2024 21:34:02 +
Subject: [PATCH 2/4] get inout working

---
 clang/include/clang/AST/ASTContext.h |  4 +++
 clang/lib/AST/ASTContext.cpp | 10 +++
 clang/lib/CodeGen/CGCall.cpp |  3 +-
 clang/lib/CodeGen/CGExpr.cpp |  7 +++--
 clang/lib/Sema/SemaExprCXX.cpp   | 13 +++--
 clang/lib/Sema/SemaOverload.cpp  | 43 
 6 files changed, 55 insertions(+), 25 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a4d36f2eacd5d1..bdd4d86c30d389 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1471,6 +1471,10 @@ class ASTContext : public RefCountedBase {
   /// type to the decayed type.
   QualType getDecayedType(QualType Orig, QualType Decayed) const;
 
+  /// Return the uniqued reference to a constant array type from the
+  /// original array parameter type.
+  QualType getConstantArrayFromArrayParameterType(QualType Ty) const;
+
   /// Return the uniqued reference to a specified array parameter type from the
   /// original array type.
   QualType getArrayParameterType(QualType Ty) const;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 735def67f7840f..b49783176f79d8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3830,6 +3830,16 @@ QualType ASTContext::getDecayedType(QualType T) const {
   return getDecayedType(T, Decayed);
 }
 
+QualType ASTContext::getConstantArrayFromArrayParameterType(QualType Ty) const 
{
+  if (Ty->isConstantArrayType() && !Ty->isArrayParameterType())
+return Ty;
+  assert(Ty->isArrayParameterType() && "Ty must be an array parameter type.");
+  const auto *ATy = cast(Ty);
+  return getConstantArrayType(ATy->getElementType(), ATy->getSize(),
+ ATy->getSizeExpr(), ATy->getSizeModifier(),
+ ATy->getIndexTypeQualifiers().getAsOpaqueValue());
+}
+
 QualType ASTContext::getArrayParameterType(QualType Ty) const {
   if (Ty->isArrayParameterType())
 return Ty;
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 4ae981e4013e9c..fe578cacc64de1 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4690,7 +4690,8 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, 
const Expr *E,
 return emitWritebackArg(*this, args, CRE);
   }
 
-  assert(type->isReferenceType() == E->isGLValue() &&
+  assert(type->isArrayParameterType() ||
+(type->isReferenceType() == E->isGLValue()) &&
  "reference binding to unmaterialized r-value!");
 
   // Add writeback for HLSLOutParamExpr.
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 4c7cbf2aec..9f7ce71b30b498 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5811,9 +5811,12 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const 
BinaryOperator *E) {
 // This function implements trivial copy assignment for HLSL's
 // assignable constant arrays.
 LValue CodeGenFunction::EmitHLSLArrayAssignLValue(const BinaryOperator *E) {
-  LValue TrivialAssignmentRHS = EmitLValue(E->getRHS());
+  // Don't emit an LValue for the RHS because it might not be an LValue
   LValue LHS = EmitLValue(E->getLHS());
-  EmitAggregateAssign(LHS, TrivialAssignmentRHS, E->getLHS(

[clang] [HLSL] get inout/out ABI for array parameters working (PR #111047)

2024-10-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Sarah Spall (spall)


Changes

Get inout/out parameters working for HLSL Arrays.
Utilizes the fix from #109323, and corrects the assignment behavior 
slightly to allow for Non-LValues on the RHS. 
Closes #106917 

---

Patch is 21.41 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/111047.diff


13 Files Affected:

- (modified) clang/include/clang/AST/ASTContext.h (+4) 
- (modified) clang/lib/AST/ASTContext.cpp (+10) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+2-1) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+5-2) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+10-3) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+24-19) 
- (modified) clang/lib/Sema/SemaType.cpp (+3-1) 
- (added) clang/test/AST/HLSL/ArrayOutArgExpr.hlsl (+63) 
- (modified) clang/test/CodeGenHLSL/ArrayAssignable.hlsl (+9-11) 
- (modified) clang/test/CodeGenHLSL/ArrayTemporary.hlsl (+4-6) 
- (added) clang/test/CodeGenHLSL/BasicFeatures/ArrayOutputArguments.hlsl (+48) 
- (modified) clang/test/SemaHLSL/ArrayTemporary.hlsl (-3) 
- (added) clang/test/SemaHLSL/Language/ArrayOutputArgs-errors.hlsl (+51) 


``diff
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a4d36f2eacd5d1..bdd4d86c30d389 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1471,6 +1471,10 @@ class ASTContext : public RefCountedBase {
   /// type to the decayed type.
   QualType getDecayedType(QualType Orig, QualType Decayed) const;
 
+  /// Return the uniqued reference to a constant array type from the
+  /// original array parameter type.
+  QualType getConstantArrayFromArrayParameterType(QualType Ty) const;
+
   /// Return the uniqued reference to a specified array parameter type from the
   /// original array type.
   QualType getArrayParameterType(QualType Ty) const;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 735def67f7840f..b49783176f79d8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3830,6 +3830,16 @@ QualType ASTContext::getDecayedType(QualType T) const {
   return getDecayedType(T, Decayed);
 }
 
+QualType ASTContext::getConstantArrayFromArrayParameterType(QualType Ty) const 
{
+  if (Ty->isConstantArrayType() && !Ty->isArrayParameterType())
+return Ty;
+  assert(Ty->isArrayParameterType() && "Ty must be an array parameter type.");
+  const auto *ATy = cast(Ty);
+  return getConstantArrayType(ATy->getElementType(), ATy->getSize(),
+ ATy->getSizeExpr(), ATy->getSizeModifier(),
+ ATy->getIndexTypeQualifiers().getAsOpaqueValue());
+}
+
 QualType ASTContext::getArrayParameterType(QualType Ty) const {
   if (Ty->isArrayParameterType())
 return Ty;
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 4ae981e4013e9c..fe578cacc64de1 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4690,7 +4690,8 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, 
const Expr *E,
 return emitWritebackArg(*this, args, CRE);
   }
 
-  assert(type->isReferenceType() == E->isGLValue() &&
+  assert(type->isArrayParameterType() ||
+(type->isReferenceType() == E->isGLValue()) &&
  "reference binding to unmaterialized r-value!");
 
   // Add writeback for HLSLOutParamExpr.
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 4c7cbf2aec..9f7ce71b30b498 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5811,9 +5811,12 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const 
BinaryOperator *E) {
 // This function implements trivial copy assignment for HLSL's
 // assignable constant arrays.
 LValue CodeGenFunction::EmitHLSLArrayAssignLValue(const BinaryOperator *E) {
-  LValue TrivialAssignmentRHS = EmitLValue(E->getRHS());
+  // Don't emit an LValue for the RHS because it might not be an LValue
   LValue LHS = EmitLValue(E->getLHS());
-  EmitAggregateAssign(LHS, TrivialAssignmentRHS, E->getLHS()->getType());
+  // In C assignment operator RHS is often an RValue.
+  // EmitAggregateAssign expects an LValue for the RHS so call the below
+  // function instead.
+  EmitInitializationToLValue(E->getRHS(), LHS);
   return LHS;
 }
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index b30414a8a8277a..89df42a837d024 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4424,10 +4424,17 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
 break;
 
   case ICK_HLSL_Array_RValue:
-FromType = Context.getArrayParameterType(FromType);
-From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
- /*BasePath=*/nullptr, CCK)
+if (ToType->isArrayParameterType()) {
+  FromType = Context.getArrayParameterType(FromT

[clang] [HLSL] get inout/out ABI for array parameters working (PR #111047)

2024-10-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Sarah Spall (spall)


Changes

Get inout/out parameters working for HLSL Arrays.
Utilizes the fix from #109323, and corrects the assignment behavior 
slightly to allow for Non-LValues on the RHS. 
Closes #106917 

---

Patch is 21.41 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/111047.diff


13 Files Affected:

- (modified) clang/include/clang/AST/ASTContext.h (+4) 
- (modified) clang/lib/AST/ASTContext.cpp (+10) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+2-1) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+5-2) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+10-3) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+24-19) 
- (modified) clang/lib/Sema/SemaType.cpp (+3-1) 
- (added) clang/test/AST/HLSL/ArrayOutArgExpr.hlsl (+63) 
- (modified) clang/test/CodeGenHLSL/ArrayAssignable.hlsl (+9-11) 
- (modified) clang/test/CodeGenHLSL/ArrayTemporary.hlsl (+4-6) 
- (added) clang/test/CodeGenHLSL/BasicFeatures/ArrayOutputArguments.hlsl (+48) 
- (modified) clang/test/SemaHLSL/ArrayTemporary.hlsl (-3) 
- (added) clang/test/SemaHLSL/Language/ArrayOutputArgs-errors.hlsl (+51) 


``diff
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a4d36f2eacd5d1..bdd4d86c30d389 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1471,6 +1471,10 @@ class ASTContext : public RefCountedBase {
   /// type to the decayed type.
   QualType getDecayedType(QualType Orig, QualType Decayed) const;
 
+  /// Return the uniqued reference to a constant array type from the
+  /// original array parameter type.
+  QualType getConstantArrayFromArrayParameterType(QualType Ty) const;
+
   /// Return the uniqued reference to a specified array parameter type from the
   /// original array type.
   QualType getArrayParameterType(QualType Ty) const;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 735def67f7840f..b49783176f79d8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3830,6 +3830,16 @@ QualType ASTContext::getDecayedType(QualType T) const {
   return getDecayedType(T, Decayed);
 }
 
+QualType ASTContext::getConstantArrayFromArrayParameterType(QualType Ty) const 
{
+  if (Ty->isConstantArrayType() && !Ty->isArrayParameterType())
+return Ty;
+  assert(Ty->isArrayParameterType() && "Ty must be an array parameter type.");
+  const auto *ATy = cast(Ty);
+  return getConstantArrayType(ATy->getElementType(), ATy->getSize(),
+ ATy->getSizeExpr(), ATy->getSizeModifier(),
+ ATy->getIndexTypeQualifiers().getAsOpaqueValue());
+}
+
 QualType ASTContext::getArrayParameterType(QualType Ty) const {
   if (Ty->isArrayParameterType())
 return Ty;
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 4ae981e4013e9c..fe578cacc64de1 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4690,7 +4690,8 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, 
const Expr *E,
 return emitWritebackArg(*this, args, CRE);
   }
 
-  assert(type->isReferenceType() == E->isGLValue() &&
+  assert(type->isArrayParameterType() ||
+(type->isReferenceType() == E->isGLValue()) &&
  "reference binding to unmaterialized r-value!");
 
   // Add writeback for HLSLOutParamExpr.
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 4c7cbf2aec..9f7ce71b30b498 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5811,9 +5811,12 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const 
BinaryOperator *E) {
 // This function implements trivial copy assignment for HLSL's
 // assignable constant arrays.
 LValue CodeGenFunction::EmitHLSLArrayAssignLValue(const BinaryOperator *E) {
-  LValue TrivialAssignmentRHS = EmitLValue(E->getRHS());
+  // Don't emit an LValue for the RHS because it might not be an LValue
   LValue LHS = EmitLValue(E->getLHS());
-  EmitAggregateAssign(LHS, TrivialAssignmentRHS, E->getLHS()->getType());
+  // In C assignment operator RHS is often an RValue.
+  // EmitAggregateAssign expects an LValue for the RHS so call the below
+  // function instead.
+  EmitInitializationToLValue(E->getRHS(), LHS);
   return LHS;
 }
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index b30414a8a8277a..89df42a837d024 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4424,10 +4424,17 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
 break;
 
   case ICK_HLSL_Array_RValue:
-FromType = Context.getArrayParameterType(FromType);
-From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
- /*BasePath=*/nullptr, CCK)
+if (ToType->isArrayParameterType()) {
+  FromType = Context.getArrayParameterType(FromType);
+  

[clang] [llvm] Update llvm::Registry to work for LLVM shared library builds on windows (PR #109024)

2024-10-03 Thread Thomas Fransham via cfe-commits

https://github.com/fsfod updated 
https://github.com/llvm/llvm-project/pull/109024

>From fcb6837e5c6ff48bf261bae9d3cedda55da89a7e Mon Sep 17 00:00:00 2001
From: Thomas Fransham 
Date: Wed, 28 Aug 2024 16:08:52 +0100
Subject: [PATCH 1/7] Update llvm::Registry to work for LLVM shared library
 builds on windows

Windows doesn't implicitly import and merge exported symbols across shared 
libraries
like Linux does so we need to explicitly export/import each instantiation of 
llvm::Registry.
Updated LLVM_INSTANTIATE_REGISTRY macro to export Registry::add_node and
Registry::begin() and add extern template declarations for the all 
instantiations of llvm::Registry.
---
 clang/include/clang/Basic/ParsedAttrInfo.h|  5 +++
 .../clang/Frontend/FrontendPluginRegistry.h   |  5 +++
 llvm/include/llvm/CodeGen/GCMetadataPrinter.h |  2 +
 llvm/include/llvm/IR/GCStrategy.h |  2 +
 llvm/include/llvm/Support/Compiler.h  |  5 +++
 llvm/include/llvm/Support/Registry.h  | 43 ++-
 6 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/Basic/ParsedAttrInfo.h 
b/clang/include/clang/Basic/ParsedAttrInfo.h
index 537d8f3391d589..2b82dd3b43d133 100644
--- a/clang/include/clang/Basic/ParsedAttrInfo.h
+++ b/clang/include/clang/Basic/ParsedAttrInfo.h
@@ -17,6 +17,7 @@
 
 #include "clang/Basic/AttrSubjectMatchRules.h"
 #include "clang/Basic/AttributeCommonInfo.h"
+#include "clang/Support/Compiler.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/Registry.h"
 #include 
@@ -165,4 +166,8 @@ const std::list> 
&getAttributePluginInstances();
 
 } // namespace clang
 
+namespace llvm {
+extern template class CLANG_TEMPLATE_ABI llvm::Registry;
+} // namespace llvm
+
 #endif // LLVM_CLANG_BASIC_PARSEDATTRINFO_H
diff --git a/clang/include/clang/Frontend/FrontendPluginRegistry.h 
b/clang/include/clang/Frontend/FrontendPluginRegistry.h
index 810578534acb45..5eea9c2fd89a32 100644
--- a/clang/include/clang/Frontend/FrontendPluginRegistry.h
+++ b/clang/include/clang/Frontend/FrontendPluginRegistry.h
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_FRONTEND_FRONTENDPLUGINREGISTRY_H
 
 #include "clang/Frontend/FrontendAction.h"
+#include "clang/Support/Compiler.h"
 #include "llvm/Support/Registry.h"
 
 namespace clang {
@@ -23,4 +24,8 @@ using FrontendPluginRegistry = 
llvm::Registry;
 
 } // namespace clang
 
+namespace llvm {
+extern template class CLANG_TEMPLATE_ABI Registry;
+} // namespace llvm
+
 #endif // LLVM_CLANG_FRONTEND_FRONTENDPLUGINREGISTRY_H
diff --git a/llvm/include/llvm/CodeGen/GCMetadataPrinter.h 
b/llvm/include/llvm/CodeGen/GCMetadataPrinter.h
index f9527c9f8752e9..9d421be8313f01 100644
--- a/llvm/include/llvm/CodeGen/GCMetadataPrinter.h
+++ b/llvm/include/llvm/CodeGen/GCMetadataPrinter.h
@@ -34,6 +34,8 @@ class StackMaps;
 /// defaults from Registry.
 using GCMetadataPrinterRegistry = Registry;
 
+extern template class LLVM_TEMPLATE_ABI Registry;
+
 /// GCMetadataPrinter - Emits GC metadata as assembly code.  Instances are
 /// created, managed, and owned by the AsmPrinter.
 class GCMetadataPrinter {
diff --git a/llvm/include/llvm/IR/GCStrategy.h 
b/llvm/include/llvm/IR/GCStrategy.h
index 3186465f001812..cbfbe23aaa0683 100644
--- a/llvm/include/llvm/IR/GCStrategy.h
+++ b/llvm/include/llvm/IR/GCStrategy.h
@@ -141,6 +141,8 @@ class GCStrategy {
 /// GCMetadataPrinterRegistery as well.
 using GCRegistry = Registry;
 
+extern template class LLVM_TEMPLATE_ABI Registry;
+
 /// Lookup the GCStrategy object associated with the given gc name.
 std::unique_ptr getGCStrategy(const StringRef Name);
 
diff --git a/llvm/include/llvm/Support/Compiler.h 
b/llvm/include/llvm/Support/Compiler.h
index 1d2d751d4dc11a..e893734b81fb7d 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -179,6 +179,7 @@
 #define LLVM_ABI
 #define LLVM_TEMPLATE_ABI
 #define LLVM_EXPORT_TEMPLATE
+#define LLVM_ABI_EXPORT
 #elif defined(_WIN32) && !defined(__MINGW32__)
 #if defined(LLVM_EXPORTS)
 #define LLVM_ABI __declspec(dllexport)
@@ -189,19 +190,23 @@
 #define LLVM_TEMPLATE_ABI __declspec(dllimport)
 #define LLVM_EXPORT_TEMPLATE
 #endif
+#define LLVM_ABI_EXPORT __declspec(dllexport)
 #elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX)
 #define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define LLVM_EXPORT_TEMPLATE
+#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #elif defined(__MACH__) || defined(__WASM__)
 #define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define LLVM_TEMPLATE_ABI
 #define LLVM_EXPORT_TEMPLATE
+#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #endif
 #else
 #define LLVM_ABI
 #define LLVM_TEMPLATE_ABI
 #define LLVM_EXPORT_TEMPLATE
+#define LLVM_ABI_EXPORT
 #endif
 #define LLVM_C_ABI LLVM_ABI
 #endif
diff --git a/llvm/include/llvm/Support/Registry.h 
b/llvm/include/llvm/Support/Registry.h
index 5bb6a254a47f4c..2dcbe0f2a28208 100644
--- a/llvm/i

[clang] [HLSL] get inout/out ABI for array parameters working (PR #111047)

2024-10-03 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 32ffc9fdc2cd422c88c926b862adb3de726e3888 
ba56fbdc3c17b973dd4dd5757cf860447ba076d3 --extensions cpp,h -- 
clang/include/clang/AST/ASTContext.h clang/lib/AST/ASTContext.cpp 
clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CGExpr.cpp 
clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaOverload.cpp 
clang/lib/Sema/SemaType.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index b49783176f..315850f941 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3836,8 +3836,8 @@ QualType 
ASTContext::getConstantArrayFromArrayParameterType(QualType Ty) const {
   assert(Ty->isArrayParameterType() && "Ty must be an array parameter type.");
   const auto *ATy = cast(Ty);
   return getConstantArrayType(ATy->getElementType(), ATy->getSize(),
- ATy->getSizeExpr(), ATy->getSizeModifier(),
- ATy->getIndexTypeQualifiers().getAsOpaqueValue());
+  ATy->getSizeExpr(), ATy->getSizeModifier(),
+  
ATy->getIndexTypeQualifiers().getAsOpaqueValue());
 }
 
 QualType ASTContext::getArrayParameterType(QualType Ty) const {
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index fe578cacc6..9bfd7436b8 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4691,8 +4691,8 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, 
const Expr *E,
   }
 
   assert(type->isArrayParameterType() ||
-(type->isReferenceType() == E->isGLValue()) &&
- "reference binding to unmaterialized r-value!");
+ (type->isReferenceType() == E->isGLValue()) &&
+ "reference binding to unmaterialized r-value!");
 
   // Add writeback for HLSLOutParamExpr.
   if (const HLSLOutArgExpr *OE = dyn_cast(E)) {
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 89df42a837..ba1931dc4f 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4428,12 +4428,12 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   FromType = Context.getArrayParameterType(FromType);
   From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
/*BasePath=*/nullptr, CCK)
-   .get();
+ .get();
 } else { // FromType must be ArrayParameterType
   FromType = Context.getConstantArrayFromArrayParameterType(FromType);
   From = ImpCastExprToType(From, FromType, CK_HLSLArrayRValue, VK_PRValue,
-  /*BasePath=*/nullptr, CCK)
-   .get();
+   /*BasePath=*/nullptr, CCK)
+ .get();
 }
 break;
 
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6dd6bdbd33..8826c0bc75 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2215,7 +2215,7 @@ static bool IsStandardConversion(Sema &S, Expr* From, 
QualType ToType,
 
   bool argIsLValue = From->isGLValue();
   if (S.getLangOpts().HLSL && FromType->isConstantArrayType() &&
- ToType->isConstantArrayType()) {
+  ToType->isConstantArrayType()) {
 // HLSL constant array parameters do not decay, so if the argument is a
 // constant array and the parameter is an ArrayParameterType we have 
special
 // handling here.
@@ -2236,7 +2236,7 @@ static bool IsStandardConversion(Sema &S, Expr* From, 
QualType ToType,
 SCS.setAllToTypes(ToType);
 return true;
   } else if (argIsLValue && !FromType->canDecayToPointerType() &&
-  S.Context.getCanonicalType(FromType) != S.Context.OverloadTy) {
+ S.Context.getCanonicalType(FromType) != S.Context.OverloadTy) {
 // Lvalue-to-rvalue conversion (C++11 4.1):
 //   A glvalue (3.10) of a non-function, non-array type T can
 //   be converted to a prvalue.

``




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


[clang] [Clang] Add "extend lifetime" flags and release note (PR #110000)

2024-10-03 Thread Stephen Tozer via cfe-commits


@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 %s -emit-llvm -O2 -fextend-lifetimes -o - | FileCheck 
--check-prefixes=CHECK-ALL,CHECK-O2 %s
+// RUN: %clang_cc1 %s -emit-llvm -O0 -fextend-lifetimes -o - | FileCheck 
--check-prefixes=CHECK-ALL,CHECK-O0 %s
+
+// Checks that we emit the function attribute has_fake_uses when
+// -fextend-lifetimes is on and optimizations are enabled, and that it does not
+// when optimizations are disabled.
+
+// CHECK-ALL:define {{.*}}void @foo
+// CHECK-O2: attributes #0 = {{{.*}}has_fake_uses

SLTozer wrote:

This isn't the only effect from the front end; this flag will actually generate 
llvm.fake.use intrinsics, but only for source variables, which this test does 
not have. But as you've noted, this test should probably include variables to 
demonstrate that we also don't emit fake uses for those at O0!

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


[clang] [HLSL] get inout/out ABI for array parameters working (PR #111047)

2024-10-03 Thread Sarah Spall via cfe-commits

https://github.com/spall updated 
https://github.com/llvm/llvm-project/pull/111047

>From c73ce3707e59242b8ccbb6757a290938c2d39e5e Mon Sep 17 00:00:00 2001
From: Sarah Spall 
Date: Tue, 17 Sep 2024 20:25:46 +
Subject: [PATCH 1/5] theoretically fix issue

---
 clang/lib/Sema/SemaType.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index c44fc9c4194ca4..8c80ece635fbff 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5675,6 +5675,9 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
   assert(!T.isNull() && "T must not be null at the end of this function");
   if (!AreDeclaratorChunksValid)
 return Context.getTrivialTypeSourceInfo(T);
+
+  if (state.didParseHLSLParamMod() && !T->isConstantArrayType())
+T = S.HLSL().getInoutParameterType(T);
   return GetTypeSourceInfoForDeclarator(state, T, TInfo);
 }
 
@@ -8562,7 +8565,6 @@ static void 
HandleHLSLParamModifierAttr(TypeProcessingState &State,
 return;
   if (Attr.getSemanticSpelling() == HLSLParamModifierAttr::Keyword_inout ||
   Attr.getSemanticSpelling() == HLSLParamModifierAttr::Keyword_out) {
-CurType = S.HLSL().getInoutParameterType(CurType);
 State.setParsedHLSLParamMod(true);
   }
 }

>From 0f64ad26f2218a037694b01649a4ebd5e2bf766c Mon Sep 17 00:00:00 2001
From: Sarah Spall 
Date: Wed, 2 Oct 2024 21:34:02 +
Subject: [PATCH 2/5] get inout working

---
 clang/include/clang/AST/ASTContext.h |  4 +++
 clang/lib/AST/ASTContext.cpp | 10 +++
 clang/lib/CodeGen/CGCall.cpp |  3 +-
 clang/lib/CodeGen/CGExpr.cpp |  7 +++--
 clang/lib/Sema/SemaExprCXX.cpp   | 13 +++--
 clang/lib/Sema/SemaOverload.cpp  | 43 
 6 files changed, 55 insertions(+), 25 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a4d36f2eacd5d1..bdd4d86c30d389 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1471,6 +1471,10 @@ class ASTContext : public RefCountedBase {
   /// type to the decayed type.
   QualType getDecayedType(QualType Orig, QualType Decayed) const;
 
+  /// Return the uniqued reference to a constant array type from the
+  /// original array parameter type.
+  QualType getConstantArrayFromArrayParameterType(QualType Ty) const;
+
   /// Return the uniqued reference to a specified array parameter type from the
   /// original array type.
   QualType getArrayParameterType(QualType Ty) const;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 735def67f7840f..b49783176f79d8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3830,6 +3830,16 @@ QualType ASTContext::getDecayedType(QualType T) const {
   return getDecayedType(T, Decayed);
 }
 
+QualType ASTContext::getConstantArrayFromArrayParameterType(QualType Ty) const 
{
+  if (Ty->isConstantArrayType() && !Ty->isArrayParameterType())
+return Ty;
+  assert(Ty->isArrayParameterType() && "Ty must be an array parameter type.");
+  const auto *ATy = cast(Ty);
+  return getConstantArrayType(ATy->getElementType(), ATy->getSize(),
+ ATy->getSizeExpr(), ATy->getSizeModifier(),
+ ATy->getIndexTypeQualifiers().getAsOpaqueValue());
+}
+
 QualType ASTContext::getArrayParameterType(QualType Ty) const {
   if (Ty->isArrayParameterType())
 return Ty;
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 4ae981e4013e9c..fe578cacc64de1 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4690,7 +4690,8 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, 
const Expr *E,
 return emitWritebackArg(*this, args, CRE);
   }
 
-  assert(type->isReferenceType() == E->isGLValue() &&
+  assert(type->isArrayParameterType() ||
+(type->isReferenceType() == E->isGLValue()) &&
  "reference binding to unmaterialized r-value!");
 
   // Add writeback for HLSLOutParamExpr.
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 4c7cbf2aec..9f7ce71b30b498 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5811,9 +5811,12 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const 
BinaryOperator *E) {
 // This function implements trivial copy assignment for HLSL's
 // assignable constant arrays.
 LValue CodeGenFunction::EmitHLSLArrayAssignLValue(const BinaryOperator *E) {
-  LValue TrivialAssignmentRHS = EmitLValue(E->getRHS());
+  // Don't emit an LValue for the RHS because it might not be an LValue
   LValue LHS = EmitLValue(E->getLHS());
-  EmitAggregateAssign(LHS, TrivialAssignmentRHS, E->getLHS()->getType());
+  // In C assignment operator RHS is often an RValue.
+  // EmitAggregateAssign expects an LValue for the RHS so call the below
+  // function instead.
+  EmitInitiali

[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)

2024-10-03 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/110179

>From 4a3348e56950583fb28211879f5ab157c34cbc66 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 26 Sep 2024 16:47:14 -0500
Subject: [PATCH 1/2] [Clang] Implement resource directory headers for common
 GPU intrinsics

Summary:
All GPU based languages provide some way to access things like the
thread ID or other resources. However, this is spread between many
different languages and it varies between targets. The goal here is to
provide a resource directory header that just provides these in an
easier to understand way, primarily so this can be used for C/C++ code.
The interface aims to be common, to faciliate easier porting, but target
specific stuff could be put in the individual headers.
---
 clang/lib/Headers/CMakeLists.txt |  14 +++
 clang/lib/Headers/amdgpuintrin.h | 187 +++
 clang/lib/Headers/gpuintrin.h|  18 +++
 clang/lib/Headers/nvptxintrin.h  | 184 ++
 4 files changed, 403 insertions(+)
 create mode 100644 clang/lib/Headers/amdgpuintrin.h
 create mode 100644 clang/lib/Headers/gpuintrin.h
 create mode 100644 clang/lib/Headers/nvptxintrin.h

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index ff392e7122a448..a0e7ae67b7219a 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -268,6 +268,12 @@ set(x86_files
   cpuid.h
   )
 
+set(gpu_files
+  gpuintrin.h
+  nvptxintrin.h
+  amdgpuintrin.h
+  )
+
 set(windows_only_files
   intrin0.h
   intrin.h
@@ -296,6 +302,7 @@ set(files
   ${systemz_files}
   ${ve_files}
   ${x86_files}
+  ${gpu_files}
   ${webassembly_files}
   ${windows_only_files}
   ${utility_files}
@@ -518,6 +525,7 @@ add_header_target("systemz-resource-headers" 
"${systemz_files};${zos_wrapper_fil
 add_header_target("ve-resource-headers" "${ve_files}")
 add_header_target("webassembly-resource-headers" "${webassembly_files}")
 add_header_target("x86-resource-headers" "${x86_files}")
+add_header_target("gpu-resource-headers" "${gpu_files}")
 
 # Other header groupings
 add_header_target("hlsl-resource-headers" ${hlsl_files})
@@ -704,6 +712,12 @@ install(
   EXCLUDE_FROM_ALL
   COMPONENT x86-resource-headers)
 
+install(
+  FILES ${gpu_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT gpu-resource-headers)
+
 if(NOT CLANG_ENABLE_HLSL)
   set(EXCLUDE_HLSL EXCLUDE_FROM_ALL)
 endif()
diff --git a/clang/lib/Headers/amdgpuintrin.h b/clang/lib/Headers/amdgpuintrin.h
new file mode 100644
index 00..95936f86bd15b8
--- /dev/null
+++ b/clang/lib/Headers/amdgpuintrin.h
@@ -0,0 +1,187 @@
+//===-- amdgpuintrin.h - AMDPGU intrinsic functions 
---===//
+//
+// 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
+//
+//===--===//
+
+#ifndef __AMDGPUINTRIN_H
+#define __AMDGPUINTRIN_H
+
+#ifndef __AMDGPU__
+#error "This file is intended for AMDGPU targets or offloading to AMDGPU
+#endif
+
+#include 
+#include 
+
+#if defined(__HIP__) || defined(__CUDA__)
+#define _DEFAULT_ATTRS __attribute__((device)) __attribute__((always_inline))
+#else
+#define _DEFAULT_ATTRS __attribute__((always_inline))
+#endif
+
+#pragma omp begin declare target device_type(nohost)
+#pragma omp begin declare variant match(device = {arch(amdgcn)})
+
+// Type aliases to the address spaces used by the AMDGPU backend.
+#define _private __attribute__((opencl_private))
+#define _constant __attribute__((opencl_constant))
+#define _local __attribute__((opencl_local))
+#define _global __attribute__((opencl_global))
+
+// Attribute to declare a function as a kernel.
+#define _kernel __attribute__((amdgpu_kernel, visibility("protected")))
+
+// Returns the number of workgroups in the 'x' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_x() {
+  return __builtin_amdgcn_grid_size_x() / __builtin_amdgcn_workgroup_size_x();
+}
+
+// Returns the number of workgroups in the 'y' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_y() {
+  return __builtin_amdgcn_grid_size_y() / __builtin_amdgcn_workgroup_size_y();
+}
+
+// Returns the number of workgroups in the 'z' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_z() {
+  return __builtin_amdgcn_grid_size_z() / __builtin_amdgcn_workgroup_size_z();
+}
+
+// Returns the total number of workgruops in the grid.
+_DEFAULT_ATTRS static inline uint64_t _get_num_blocks() {
+  return _get_num_blocks_x() * _get_num_blocks_y() * _get_num_blocks_z();
+}
+
+// Returns the 'x' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t _get_block_id_x() {
+  return __builtin_amdgcn_workgroup_id_x();
+}
+
+// Returns the 'y'

[clang] [Clang] [Sema] Don't crash on unexpanded pack in invalid block literal (PR #110762)

2024-10-03 Thread via cfe-commits

cor3ntin wrote:

> Side note: lambdas don’t suffer from this problem because they push a new 
> LambdaScopeInfo, so if the lambda is discarded, the ‘enclosing lambda’ (which 
> is just that very same lambda) is discarded along with it. I’m not sure 
> making blocks work the same way would work (i.e. allowing unexpanded 
> parameter packs if there is an enclosing lambda or block, but I’m assuming 
> there is a reason why we don’t support that...), because currently, e.g. this 
> doesn’t work at all:

I am not sure i understand that.

Imo the issue is that `DiagnoseUnexpandedParameterPacks` (where we set 
`LambdaScopeInfo::ContainsUnexpandedParameterPack` does not account for blocks 
- and probably should.

Ideally
 - DiagnoseUnexpandedParameterPacks would handle arbitrary capturing-scope 
thingies (statement expressions, lambdas, blocks, eventually do expressions, 
and other terrifying such constructs)
 - Once the innermost such construct is fully constructed, the 
`ContainsUnexpandedParameterPack` flag could bubble upward to the enclosing 
capturing scope



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


[clang] [Clang] fix overload resolution for object parameters with top-level cv-qualifiers in member functions (PR #110435)

2024-10-03 Thread via cfe-commits


@@ -1073,3 +1073,10 @@ int main() {
   return foo[]; // expected-error {{no viable overloaded operator[] for type 
'Foo'}}
 }
 }
+
+namespace GH100394 {
+struct C {
+  void f(this const C);
+  void f() const ;  // ok
+};

cor3ntin wrote:

Here is a fun test 
```
struct C {
  void f(this const C);
  void f(this volatile C) ;  
};

(deprecated but should be handled nevertheless)

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


[clang] [llvm] [HLSL] Implement `WaveReadLaneAt` intrinsic for spirv backend (PR #111010)

2024-10-03 Thread Finn Plummer via cfe-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/111010

>From 70089645ec5cf62b491a56df96ec46f4328fbc11 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Thu, 3 Oct 2024 11:43:51 -0700
Subject: [PATCH 1/2] [HLSL] Implement `WaveReadLaneAt` intrinsic

- create a clang built-in in Builtins.td
- add semantic checking in SemaHLSL.cpp
- link the WaveReadLaneAt api in hlsl_intrinsics.h
- add lowering to spirv backend op GroupNonUniformShuffle
  with Scope = 2 (Group) in SPIRVInstructionSelector.cpp

- add tests for HLSL intrinsic lowering to spirv intrinsic in
  WaveReadLaneAt.hlsl
- add tests for sema checks in WaveReadLaneAt-errors.hlsl
- add spir-v backend tests in WaveReadLaneAt.ll
---
 clang/include/clang/Basic/Builtins.td |  6 +++
 clang/lib/CodeGen/CGBuiltin.cpp   | 16 
 clang/lib/CodeGen/CGHLSLRuntime.h |  1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  7 
 clang/lib/Sema/SemaHLSL.cpp   | 20 ++
 .../CodeGenHLSL/builtins/WaveReadLaneAt.hlsl  | 40 +++
 .../BuiltIns/WaveReadLaneAt-errors.hlsl   | 21 ++
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  1 +
 .../Target/SPIRV/SPIRVInstructionSelector.cpp | 15 +++
 .../SPIRV/hlsl-intrinsics/WaveReadLaneAt.ll   | 28 +
 10 files changed, 155 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/WaveReadLaneAt.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/WaveReadLaneAt-errors.hlsl
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveReadLaneAt.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 8090119e512fbb..eec9acd4d27d7d 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4703,6 +4703,12 @@ def HLSLWaveIsFirstLane : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "bool()";
 }
 
+def HLSLWaveReadLaneAt : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_wave_read_lane_at"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 def HLSLClamp : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_elementwise_clamp"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index da3eca73bfb575..dff56af9282e9d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18835,6 +18835,22 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveIsFirstLaneIntrinsic();
 return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID));
   }
+  case Builtin::BI__builtin_hlsl_wave_read_lane_at: {
+// Due to the use of variadic arguments we must explicitly retreive them 
and
+// create our function type.
+Value *OpExpr = EmitScalarExpr(E->getArg(0));
+Value *OpIndex = EmitScalarExpr(E->getArg(1));
+llvm::FunctionType *FT = llvm::FunctionType::get(
+OpExpr->getType(), ArrayRef{OpExpr->getType(), OpIndex->getType()},
+false);
+
+// Get overloaded name
+std::string name =
+Intrinsic::getName(CGM.getHLSLRuntime().getWaveReadLaneAtIntrinsic(),
+   ArrayRef{OpExpr->getType()}, &CGM.getModule());
+return EmitRuntimeCall(CGM.CreateRuntimeFunction(FT, name, {}, false, 
true),
+   ArrayRef{OpExpr, OpIndex}, 
"hlsl.wave.read.lane.at");
+  }
   case Builtin::BI__builtin_hlsl_elementwise_sign: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 llvm::Type *Xty = Op0->getType();
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index a8aabca7348ffb..a639ce2d784f4a 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -87,6 +87,7 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(UDot, udot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_read_lane_at)
 
   
//===--===//
   // End of reserved area for HLSL intrinsic getters.
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 810a16d75f0228..a7bdc353ae71bf 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -2015,6 +2015,13 @@ _HLSL_AVAILABILITY(shadermodel, 6.0)
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_is_first_lane)
 __attribute__((convergent)) bool WaveIsFirstLane();
 
+// \brief Returns the value of the expression for the given lane index within
+// the specified wave.
+template 
+_HLSL_AVAILABILITY(shadermodel, 6.0)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_read_lane_at)
+__attribute__((convergent)) T WaveReadLaneAt(T, int32_t);
+
 
//===---

[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)

2024-10-03 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/110179

>From 4a3348e56950583fb28211879f5ab157c34cbc66 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 26 Sep 2024 16:47:14 -0500
Subject: [PATCH 1/3] [Clang] Implement resource directory headers for common
 GPU intrinsics

Summary:
All GPU based languages provide some way to access things like the
thread ID or other resources. However, this is spread between many
different languages and it varies between targets. The goal here is to
provide a resource directory header that just provides these in an
easier to understand way, primarily so this can be used for C/C++ code.
The interface aims to be common, to faciliate easier porting, but target
specific stuff could be put in the individual headers.
---
 clang/lib/Headers/CMakeLists.txt |  14 +++
 clang/lib/Headers/amdgpuintrin.h | 187 +++
 clang/lib/Headers/gpuintrin.h|  18 +++
 clang/lib/Headers/nvptxintrin.h  | 184 ++
 4 files changed, 403 insertions(+)
 create mode 100644 clang/lib/Headers/amdgpuintrin.h
 create mode 100644 clang/lib/Headers/gpuintrin.h
 create mode 100644 clang/lib/Headers/nvptxintrin.h

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index ff392e7122a448..a0e7ae67b7219a 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -268,6 +268,12 @@ set(x86_files
   cpuid.h
   )
 
+set(gpu_files
+  gpuintrin.h
+  nvptxintrin.h
+  amdgpuintrin.h
+  )
+
 set(windows_only_files
   intrin0.h
   intrin.h
@@ -296,6 +302,7 @@ set(files
   ${systemz_files}
   ${ve_files}
   ${x86_files}
+  ${gpu_files}
   ${webassembly_files}
   ${windows_only_files}
   ${utility_files}
@@ -518,6 +525,7 @@ add_header_target("systemz-resource-headers" 
"${systemz_files};${zos_wrapper_fil
 add_header_target("ve-resource-headers" "${ve_files}")
 add_header_target("webassembly-resource-headers" "${webassembly_files}")
 add_header_target("x86-resource-headers" "${x86_files}")
+add_header_target("gpu-resource-headers" "${gpu_files}")
 
 # Other header groupings
 add_header_target("hlsl-resource-headers" ${hlsl_files})
@@ -704,6 +712,12 @@ install(
   EXCLUDE_FROM_ALL
   COMPONENT x86-resource-headers)
 
+install(
+  FILES ${gpu_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT gpu-resource-headers)
+
 if(NOT CLANG_ENABLE_HLSL)
   set(EXCLUDE_HLSL EXCLUDE_FROM_ALL)
 endif()
diff --git a/clang/lib/Headers/amdgpuintrin.h b/clang/lib/Headers/amdgpuintrin.h
new file mode 100644
index 00..95936f86bd15b8
--- /dev/null
+++ b/clang/lib/Headers/amdgpuintrin.h
@@ -0,0 +1,187 @@
+//===-- amdgpuintrin.h - AMDPGU intrinsic functions 
---===//
+//
+// 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
+//
+//===--===//
+
+#ifndef __AMDGPUINTRIN_H
+#define __AMDGPUINTRIN_H
+
+#ifndef __AMDGPU__
+#error "This file is intended for AMDGPU targets or offloading to AMDGPU
+#endif
+
+#include 
+#include 
+
+#if defined(__HIP__) || defined(__CUDA__)
+#define _DEFAULT_ATTRS __attribute__((device)) __attribute__((always_inline))
+#else
+#define _DEFAULT_ATTRS __attribute__((always_inline))
+#endif
+
+#pragma omp begin declare target device_type(nohost)
+#pragma omp begin declare variant match(device = {arch(amdgcn)})
+
+// Type aliases to the address spaces used by the AMDGPU backend.
+#define _private __attribute__((opencl_private))
+#define _constant __attribute__((opencl_constant))
+#define _local __attribute__((opencl_local))
+#define _global __attribute__((opencl_global))
+
+// Attribute to declare a function as a kernel.
+#define _kernel __attribute__((amdgpu_kernel, visibility("protected")))
+
+// Returns the number of workgroups in the 'x' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_x() {
+  return __builtin_amdgcn_grid_size_x() / __builtin_amdgcn_workgroup_size_x();
+}
+
+// Returns the number of workgroups in the 'y' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_y() {
+  return __builtin_amdgcn_grid_size_y() / __builtin_amdgcn_workgroup_size_y();
+}
+
+// Returns the number of workgroups in the 'z' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_z() {
+  return __builtin_amdgcn_grid_size_z() / __builtin_amdgcn_workgroup_size_z();
+}
+
+// Returns the total number of workgruops in the grid.
+_DEFAULT_ATTRS static inline uint64_t _get_num_blocks() {
+  return _get_num_blocks_x() * _get_num_blocks_y() * _get_num_blocks_z();
+}
+
+// Returns the 'x' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t _get_block_id_x() {
+  return __builtin_amdgcn_workgroup_id_x();
+}
+
+// Returns the 'y'

[clang] [llvm] [HLSL] Implement `WaveReadLaneAt` intrinsic for spirv backend (PR #111010)

2024-10-03 Thread Finn Plummer via cfe-commits

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


[clang] [Clang][Driver][AArch64] Add support for aarch64-amazon-linux triple (PR #109263)

2024-10-03 Thread Fangrui Song via cfe-commits

MaskRay wrote:

I don't think we've reached consensus. The comment there serves a purpose and 
specifically discourages people from doing this mismatching triple things.

If the GCC installation on Amazon Linux uses `aarch64-amazon-linux`, and the 
default target triple of the Clang is `aarch64-unknown-linux-gnu`, it's by 
design that the GCC installation doesn't got picked.
(The code here is more loose in that `--target=aarch64-unknown-linux-musl` 
would pick up `aarch64-amazon-linux`.)

If for some reason you have a Clang with the default target triple 
`aarch64-unknown-linux-gnu`,
you could change `clang` to a wrapper that does `real/clang 
--target=aarch64-amazon-linux`.

While I appreciate @stewartsmith 's long context, I don't think it provides 
real justification.


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


[clang] eaff3a7 - [clang-format] Fix a bug that misannotates binary operators */&/&& (#110945)

2024-10-03 Thread via cfe-commits

Author: Owen Pan
Date: 2024-10-03T18:57:50-07:00
New Revision: eaff3a743406ff1636e6328e1ba1bc66318d53cb

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

LOG: [clang-format] Fix a bug that misannotates binary operators */&/&& 
(#110945)

Fixes #110879.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 5398e2dadd485a..e2068e557732af 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -366,7 +366,7 @@ class AnnotatingParser {
 } else if (OpeningParen.Previous &&
(OpeningParen.Previous->isOneOf(
 tok::kw_static_assert, tok::kw_noexcept, tok::kw_explicit,
-tok::kw_while, tok::l_paren, tok::comma,
+tok::kw_while, tok::l_paren, tok::comma, TT_CastRParen,
 TT_BinaryOperator) ||
 OpeningParen.Previous->isIf())) {
   // static_assert, if and while usually contain expressions.

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index de1346b5ddd5a7..a89adfa3f4fdd9 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -367,6 +367,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
 "}");
   ASSERT_EQ(Tokens.size(), 20u) << Tokens;
   EXPECT_TOKEN(Tokens[14], tok::star, TT_PointerOrReference);
+
+  Tokens = annotate("Thingy kConfig = {\n"
+"1,\n"
+"(uint16_t)(kScale * height_pixels),\n"
+"};");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_CastRParen);
+  EXPECT_TOKEN(Tokens[11], tok::star, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {



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


[clang] [clang-format] Fix a bug that misannotates binary operators */&/&& (PR #110945)

2024-10-03 Thread Owen Pan via cfe-commits

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


[clang] [Clang][Driver][AArch64] Add support for aarch64-amazon-linux triple (PR #109263)

2024-10-03 Thread Fangrui Song via cfe-commits

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

.

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits


@@ -461,6 +487,33 @@ class OpLowerer {
 });
   }
 
+  [[nodiscard]] bool lowerSplitDouble(Function &F) {
+IRBuilder<> &IRB = OpBuilder.getIRB();
+return replaceFunction(F, [&](CallInst *CI) -> Error {
+  IRB.SetInsertPoint(CI);
+
+  Value *Arg0 = CI->getArgOperand(0);
+
+  if (Arg0->getType()->isVectorTy()) {
+return make_error(
+"splitdouble doesn't support lowering vector types.",

farzonl wrote:

DXILOpLowering already has an error when  it encounters a vector. Putting this 
in here like this just makes  it so we have to change splitdouble 
implementation code to get everything working when the scalarization PR lands. 
What I recomend is to create a correct  Vector test case and XFAIL it. 

Then when scalarization of Struct vectors  lands that test will go from XFAIL 
to pass and we will know we can remove XFAIL or better yet integrate those 
tests with  splitdouble.ll

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,14 @@
+; RUN: opt -S -scalarizer -mtriple=spirv-vulkan-library %s 2>&1 | llc 
-verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown -o - | FileCheck %s
+
+; SPIRV lowering for splitdouble should relly on the scalarizer.

farzonl wrote:

This comment doesn't sound right. We don't currently use the scalarizer when 
targeting SPIRV. I don't understand why we would start for the split double 
case.

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits


@@ -264,6 +265,31 @@ class OpLowerer {
 return lowerToBindAndAnnotateHandle(F);
   }
 
+  Error replaceSplitDoubleCallUsages(CallInst *Intrin, CallInst *Op) {
+IRBuilder<> &IRB = OpBuilder.getIRB();
+
+for (Use &U : make_early_inc_range(Intrin->uses())) {
+  if (auto *EVI = dyn_cast(U.getUser())) {
+
+assert(EVI->getNumIndices() == 1 &&
+   "splitdouble result should be indexed individually.");
+if (EVI->getNumIndices() != 1)
+  return make_error(
+  "splitdouble result should be indexed individually.",
+  inconvertibleErrorCode());
+
+unsigned int IndexVal = EVI->getIndices()[0];
+
+auto *OpEVI = IRB.CreateExtractValue(Op, IndexVal);

farzonl wrote:

Just going to repeat this comment the `CreateExtractValue` should happen in  
CGBuiltins.

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


[clang] [TableGen] Avoid repeated hash lookups (NFC) (PR #111089)

2024-10-03 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/111089

None

>From 14a0790867efd134b4ae0ceafeddb58e504929ec Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Thu, 3 Oct 2024 08:46:35 -0700
Subject: [PATCH] [TableGen] Avoid repeated hash lookups (NFC)

---
 clang/utils/TableGen/MveEmitter.cpp | 28 
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/clang/utils/TableGen/MveEmitter.cpp 
b/clang/utils/TableGen/MveEmitter.cpp
index 57e6353e60a141..915e914d6b9287 100644
--- a/clang/utils/TableGen/MveEmitter.cpp
+++ b/clang/utils/TableGen/MveEmitter.cpp
@@ -994,9 +994,10 @@ class EmitterBase {
   const VectorType *getVectorType(const ScalarType *ST, unsigned Lanes) {
 std::tuple key(ST->kind(),
ST->sizeInBits(), 
Lanes);
-if (VectorTypes.find(key) == VectorTypes.end())
-  VectorTypes[key] = std::make_unique(ST, Lanes);
-return VectorTypes[key].get();
+auto [It, Inserted] = VectorTypes.try_emplace(key);
+if (Inserted)
+  It->second = std::make_unique(ST, Lanes);
+return It->second.get();
   }
   const VectorType *getVectorType(const ScalarType *ST) {
 return getVectorType(ST, 128 / ST->sizeInBits());
@@ -1004,22 +1005,25 @@ class EmitterBase {
   const MultiVectorType *getMultiVectorType(unsigned Registers,
 const VectorType *VT) {
 std::pair key(VT->cNameBase(), Registers);
-if (MultiVectorTypes.find(key) == MultiVectorTypes.end())
-  MultiVectorTypes[key] = std::make_unique(Registers, VT);
-return MultiVectorTypes[key].get();
+auto [It, Inserted] = MultiVectorTypes.try_emplace(key);
+if (Inserted)
+  It->second = std::make_unique(Registers, VT);
+return It->second.get();
   }
   const PredicateType *getPredicateType(unsigned Lanes) {
 unsigned key = Lanes;
-if (PredicateTypes.find(key) == PredicateTypes.end())
-  PredicateTypes[key] = std::make_unique(Lanes);
-return PredicateTypes[key].get();
+auto [It, Inserted] = PredicateTypes.try_emplace(key);
+if (Inserted)
+  It->second = std::make_unique(Lanes);
+return It->second.get();
   }
   const PointerType *getPointerType(const Type *T, bool Const) {
 PointerType PT(T, Const);
 std::string key = PT.cName();
-if (PointerTypes.find(key) == PointerTypes.end())
-  PointerTypes[key] = std::make_unique(PT);
-return PointerTypes[key].get();
+auto [It, Inserted] = PointerTypes.try_emplace(key);
+if (Inserted)
+  It->second = std::make_unique(PT);
+return It->second.get();
   }
 
   // Methods to construct a type from various pieces of Tablegen. These are

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


[clang] [libclang] Avoid repeated hash lookups (NFC) (PR #111087)

2024-10-03 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/111087

None

>From df0ae6125e18bae6e90863300e12d094654b7b1f Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Thu, 3 Oct 2024 08:45:56 -0700
Subject: [PATCH] [libclang] Avoid repeated hash lookups (NFC)

---
 clang/tools/libclang/CXIndexDataConsumer.cpp | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/clang/tools/libclang/CXIndexDataConsumer.cpp 
b/clang/tools/libclang/CXIndexDataConsumer.cpp
index 8d364ed8876a12..ced94e13baf12e 100644
--- a/clang/tools/libclang/CXIndexDataConsumer.cpp
+++ b/clang/tools/libclang/CXIndexDataConsumer.cpp
@@ -952,18 +952,12 @@ void CXIndexDataConsumer::addContainerInMap(const 
DeclContext *DC,
   if (!DC)
 return;
 
-  ContainerMapTy::iterator I = ContainerMap.find(DC);
-  if (I == ContainerMap.end()) {
-if (container)
-  ContainerMap[DC] = container;
-return;
-  }
   // Allow changing the container of a previously seen DeclContext so we
   // can handle invalid user code, like a function re-definition.
   if (container)
-I->second = container;
+ContainerMap[DC] = container;
   else
-ContainerMap.erase(I);
+ContainerMap.erase(DC);
 }
 
 CXIdxClientEntity CXIndexDataConsumer::getClientEntity(const Decl *D) const {

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


[clang] [libclang] Avoid repeated hash lookups (NFC) (PR #111087)

2024-10-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/111087.diff


1 Files Affected:

- (modified) clang/tools/libclang/CXIndexDataConsumer.cpp (+2-8) 


``diff
diff --git a/clang/tools/libclang/CXIndexDataConsumer.cpp 
b/clang/tools/libclang/CXIndexDataConsumer.cpp
index 8d364ed8876a12..ced94e13baf12e 100644
--- a/clang/tools/libclang/CXIndexDataConsumer.cpp
+++ b/clang/tools/libclang/CXIndexDataConsumer.cpp
@@ -952,18 +952,12 @@ void CXIndexDataConsumer::addContainerInMap(const 
DeclContext *DC,
   if (!DC)
 return;
 
-  ContainerMapTy::iterator I = ContainerMap.find(DC);
-  if (I == ContainerMap.end()) {
-if (container)
-  ContainerMap[DC] = container;
-return;
-  }
   // Allow changing the container of a previously seen DeclContext so we
   // can handle invalid user code, like a function re-definition.
   if (container)
-I->second = container;
+ContainerMap[DC] = container;
   else
-ContainerMap.erase(I);
+ContainerMap.erase(DC);
 }
 
 CXIdxClientEntity CXIndexDataConsumer::getClientEntity(const Decl *D) const {

``




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


[clang] [DependencyScanning] Avoid repeated hash lookups (NFC) (PR #111088)

2024-10-03 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/111088

None

>From 5e09bfd855a7ebee4dd07dc64bcdc157e89f6aa4 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Thu, 3 Oct 2024 08:47:01 -0700
Subject: [PATCH] [DependencyScanning] Avoid repeated hash lookups (NFC)

---
 clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 677f426590ab9e..77f9d07175c2c1 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -549,7 +549,7 @@ void ModuleDepCollectorPP::EndOfMainFile() {
 auto It = MDC.ModularDeps.find(M);
 // Only report direct dependencies that were successfully handled.
 if (It != MDC.ModularDeps.end())
-  MDC.Consumer.handleDirectModuleDependency(MDC.ModularDeps[M]->ID);
+  MDC.Consumer.handleDirectModuleDependency(It->second->ID);
   }
 
   for (auto &&I : MDC.FileDeps)

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,14 @@
+; RUN: opt -S -scalarizer -mtriple=spirv-vulkan-library %s 2>&1 | llc 
-verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown -o - | FileCheck %s

farzonl wrote:

I don't think this file should exist. I don't understand why we are using `opt` 
the `-scalarizer` pass and why we aren't running the output into the SPIRV 
validator via `spirv-val`

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits

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


[clang] [TableGen] Avoid repeated hash lookups (NFC) (PR #111089)

2024-10-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/111089.diff


1 Files Affected:

- (modified) clang/utils/TableGen/MveEmitter.cpp (+16-12) 


``diff
diff --git a/clang/utils/TableGen/MveEmitter.cpp 
b/clang/utils/TableGen/MveEmitter.cpp
index 57e6353e60a141..915e914d6b9287 100644
--- a/clang/utils/TableGen/MveEmitter.cpp
+++ b/clang/utils/TableGen/MveEmitter.cpp
@@ -994,9 +994,10 @@ class EmitterBase {
   const VectorType *getVectorType(const ScalarType *ST, unsigned Lanes) {
 std::tuple key(ST->kind(),
ST->sizeInBits(), 
Lanes);
-if (VectorTypes.find(key) == VectorTypes.end())
-  VectorTypes[key] = std::make_unique(ST, Lanes);
-return VectorTypes[key].get();
+auto [It, Inserted] = VectorTypes.try_emplace(key);
+if (Inserted)
+  It->second = std::make_unique(ST, Lanes);
+return It->second.get();
   }
   const VectorType *getVectorType(const ScalarType *ST) {
 return getVectorType(ST, 128 / ST->sizeInBits());
@@ -1004,22 +1005,25 @@ class EmitterBase {
   const MultiVectorType *getMultiVectorType(unsigned Registers,
 const VectorType *VT) {
 std::pair key(VT->cNameBase(), Registers);
-if (MultiVectorTypes.find(key) == MultiVectorTypes.end())
-  MultiVectorTypes[key] = std::make_unique(Registers, VT);
-return MultiVectorTypes[key].get();
+auto [It, Inserted] = MultiVectorTypes.try_emplace(key);
+if (Inserted)
+  It->second = std::make_unique(Registers, VT);
+return It->second.get();
   }
   const PredicateType *getPredicateType(unsigned Lanes) {
 unsigned key = Lanes;
-if (PredicateTypes.find(key) == PredicateTypes.end())
-  PredicateTypes[key] = std::make_unique(Lanes);
-return PredicateTypes[key].get();
+auto [It, Inserted] = PredicateTypes.try_emplace(key);
+if (Inserted)
+  It->second = std::make_unique(Lanes);
+return It->second.get();
   }
   const PointerType *getPointerType(const Type *T, bool Const) {
 PointerType PT(T, Const);
 std::string key = PT.cName();
-if (PointerTypes.find(key) == PointerTypes.end())
-  PointerTypes[key] = std::make_unique(PT);
-return PointerTypes[key].get();
+auto [It, Inserted] = PointerTypes.try_emplace(key);
+if (Inserted)
+  It->second = std::make_unique(PT);
+return It->second.get();
   }
 
   // Methods to construct a type from various pieces of Tablegen. These are

``




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


[clang] [Sema] Avoid repeated hash lookups (NFC) (PR #111090)

2024-10-03 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/111090

None

>From cd8fc9cd8e9ef757d129b3bbdddaeaf163d08d51 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Thu, 3 Oct 2024 08:47:32 -0700
Subject: [PATCH] [Sema] Avoid repeated hash lookups (NFC)

---
 clang/lib/Sema/SemaLambda.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index c2b35856111f3b..aeb20299b714a3 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -423,11 +423,11 @@ bool Sema::DiagnoseInvalidExplicitObjectParameterInLambda(
   // is an empty cast path for the method stored in the context (signalling 
that
   // we've already diagnosed it) and then just not building the call, but that
   // doesn't really seem any simpler than diagnosing it at the call site...
-  if (auto It = Context.LambdaCastPaths.find(Method);
-  It != Context.LambdaCastPaths.end())
+  auto [It, Inserted] = Context.LambdaCastPaths.try_emplace(Method);
+  if (!Inserted)
 return It->second.empty();
 
-  CXXCastPath &Path = Context.LambdaCastPaths[Method];
+  CXXCastPath &Path = It->second;
   CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
  /*DetectVirtual=*/false);
   if (!IsDerivedFrom(RD->getLocation(), ExplicitObjectParameterType, 
LambdaType,

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


[clang] [Sema] Avoid repeated hash lookups (NFC) (PR #111090)

2024-10-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/111090.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaLambda.cpp (+3-3) 


``diff
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index c2b35856111f3b..aeb20299b714a3 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -423,11 +423,11 @@ bool Sema::DiagnoseInvalidExplicitObjectParameterInLambda(
   // is an empty cast path for the method stored in the context (signalling 
that
   // we've already diagnosed it) and then just not building the call, but that
   // doesn't really seem any simpler than diagnosing it at the call site...
-  if (auto It = Context.LambdaCastPaths.find(Method);
-  It != Context.LambdaCastPaths.end())
+  auto [It, Inserted] = Context.LambdaCastPaths.try_emplace(Method);
+  if (!Inserted)
 return It->second.empty();
 
-  CXXCastPath &Path = Context.LambdaCastPaths[Method];
+  CXXCastPath &Path = It->second;
   CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
  /*DetectVirtual=*/false);
   if (!IsDerivedFrom(RD->getLocation(), ExplicitObjectParameterType, 
LambdaType,

``




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


[clang] [DependencyScanning] Avoid repeated hash lookups (NFC) (PR #111088)

2024-10-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/111088.diff


1 Files Affected:

- (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (+1-1) 


``diff
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 677f426590ab9e..77f9d07175c2c1 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -549,7 +549,7 @@ void ModuleDepCollectorPP::EndOfMainFile() {
 auto It = MDC.ModularDeps.find(M);
 // Only report direct dependencies that were successfully handled.
 if (It != MDC.ModularDeps.end())
-  MDC.Consumer.handleDirectModuleDependency(MDC.ModularDeps[M]->ID);
+  MDC.Consumer.handleDirectModuleDependency(It->second->ID);
   }
 
   for (auto &&I : MDC.FileDeps)

``




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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,16 @@
+; RUN: not opt -S -scalarizer -dxil-op-lower 
-mtriple=dxil-pc-shadermodel6.3-library %s 2>&1 | FileCheck %s
+
+; DXIL operation splitdouble doesn't support vector types.
+; CHECK: in function test_vector_double_split
+; CHECK-SAME: splitdouble doesn't support lowering vector types.
+
+define noundef <3 x i32> @test_vector_double_split(<3 x double> noundef %D) 
local_unnamed_addr {
+entry:
+  %hlsl.splitdouble = tail call { <3 x i32>, <3 x i32> } 
@llvm.dx.splitdouble.v3i32(<3 x double> %D)

farzonl wrote:

remove tail:
```suggestion
  %hlsl.splitdouble = call { <3 x i32>, <3 x i32> } 
@llvm.dx.splitdouble.v3i32(<3 x double> %D)
```

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,16 @@
+; RUN: not opt -S -scalarizer -dxil-op-lower 
-mtriple=dxil-pc-shadermodel6.3-library %s 2>&1 | FileCheck %s
+
+; DXIL operation splitdouble doesn't support vector types.

farzonl wrote:

This is the test I would like to see become an XFAIL

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


[clang] 7ab488e - [RISCV][FMV] Support target_version (#99040)

2024-10-03 Thread via cfe-commits

Author: Piyou Chen
Date: 2024-10-04T11:02:45+08:00
New Revision: 7ab488e92c39c813a50cb4fd6587e7afc161c7d5

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

LOG: [RISCV][FMV] Support target_version (#99040)

This patch enable `target_version` attribute for RISC-V target.

The proposal of `target_version` syntax can be found at the
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/48 (which has
landed), as modified by the proposed
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/85 (which adds the
priority syntax).

`target_version` attribute will trigger the function multi-versioning
feature and act like `target_clones` attribute. See
https://github.com/llvm/llvm-project/pull/85786 for the implementation
of `target_clones`.

Added: 
clang/test/CodeGen/attr-target-version-riscv-invalid.c
clang/test/CodeGen/attr-target-version-riscv.c
clang/test/CodeGenCXX/attr-target-version-riscv.cpp
clang/test/SemaCXX/attr-target-version-riscv.cpp

Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a81429ad6a2380..034fbbe0bc7829 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14325,9 +14325,17 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
 }
   } else if (const auto *TV = FD->getAttr()) {
-llvm::SmallVector Feats;
-TV->getFeatures(Feats);
-std::vector Features = getFMVBackendFeaturesFor(Feats);
+std::vector Features;
+if (Target->getTriple().isRISCV()) {
+  ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(TV->getName());
+  Features.insert(Features.begin(), ParsedAttr.Features.begin(),
+  ParsedAttr.Features.end());
+} else {
+  assert(Target->getTriple().isAArch64());
+  llvm::SmallVector Feats;
+  TV->getFeatures(Feats);
+  Features = getFMVBackendFeaturesFor(Feats);
+}
 Features.insert(Features.begin(),
 Target->getTargetOpts().FeaturesAsWritten.begin(),
 Target->getTargetOpts().FeaturesAsWritten.end());

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 25c1c496a4f27f..5ba098144a74e7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4287,8 +4287,13 @@ void CodeGenModule::emitMultiVersionFunctions() {
   } else if (const auto *TVA = CurFD->getAttr()) {
 if (TVA->isDefaultVersion() && IsDefined)
   ShouldEmitResolver = true;
-TVA->getFeatures(Feats);
 llvm::Function *Func = createFunction(CurFD);
+if (getTarget().getTriple().isRISCV()) {
+  Feats.push_back(TVA->getName());
+} else {
+  assert(getTarget().getTriple().isAArch64());
+  TVA->getFeatures(Feats);
+}
 Options.emplace_back(Func, /*Architecture*/ "", Feats);
   } else if (const auto *TC = CurFD->getAttr()) {
 if (IsDefined)

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 2bf610746bc317..21f25a2ea09eb0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10329,7 +10329,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   // Handle attributes.
   ProcessDeclAttributes(S, NewFD, D);
   const auto *NewTVA = NewFD->getAttr();
-  if (NewTVA && !NewTVA->isDefaultVersion() &&
+  if (Context.getTargetInfo().getTriple().isAArch64() && NewTVA &&
+  !NewTVA->isDefaultVersion() &&
   !Context.getTargetInfo().hasFeature("fmv")) {
 // Don't add to scope fmv functions declarations if fmv disabled
 AddToScope = false;
@@ -11038,7 +11039,15 @@ static bool CheckMultiVersionValue(Sema &S, const 
FunctionDecl *FD) {
 
   if (TVA) {
 llvm::SmallVector Feats;
-TVA->getFeatures(Feats);
+if (S.getASTContext().getTargetInfo().getTriple().isRISCV()) {
+  ParsedTargetAttr ParseInfo =
+  S.getASTContext().getTargetInfo().parseTargetAttr(TVA->getName());
+  for (auto &Feat : ParseInfo.Features)
+Feats.push_back(StringRef{Feat}.substr(1));
+} else {
+  assert(S.getASTContext().getTargetInfo().getTriple().isAArch64());
+  TVA->getFeatures(Feats);
+}
 for (const auto &Feat : Feats) {
   if (!TargetInfo.validateCpuSupports(Feat)) {
 S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
@@ -11324,7 +11333,8 @@ static bool 
PreviousDeclsHaveMultiVersionAttribute(const FunctionDecl 

[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,16 @@
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown %s -o - | 
FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - 
-filetype=obj | spirv-val %}
+
+; Make sure lowering is correctly generating spirv code.
+
+define spir_func noundef i32 @test_scalar(double noundef %D) 
local_unnamed_addr {
+entry:
+  ; CHECK: %[[#]] = OpBitcast %[[#]] %[[#]]

farzonl wrote:

when you do `[[#]]` you aren't checking any of the values. 

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


[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-10-03 Thread Piyou Chen via cfe-commits

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


[clang] [Clang][Sema] Fix templated array size calculation. (PR #96464)

2024-10-03 Thread via cfe-commits

https://github.com/awson updated https://github.com/llvm/llvm-project/pull/96464

>From 096b999120cc28844d780acbc16f8308b3a54160 Mon Sep 17 00:00:00 2001
From: awson 
Date: Mon, 24 Jun 2024 10:34:51 +0300
Subject: [PATCH 1/3] [Clang][Sema] don't handle ArraySize/AllocType early.

---
 clang/lib/Sema/SemaExprCXX.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index f3af8dee6b090c..2f79540faea009 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2174,7 +2174,8 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool 
UseGlobal,
 
   // Per C++0x [expr.new]p5, the type being constructed may be a
   // typedef of an array type.
-  if (!ArraySize) {
+  // Dependent case will be handled separately.
+  if (!ArraySize && !AllocType->isDependentType()) {
 if (const ConstantArrayType *Array
   = Context.getAsConstantArrayType(AllocType)) {
   ArraySize = IntegerLiteral::Create(Context, Array->getSize(),

>From 50dbd2c8dce3a70f19ea6f2f22f6f1f9bda84a1e Mon Sep 17 00:00:00 2001
From: awson 
Date: Mon, 24 Jun 2024 11:07:58 +0300
Subject: [PATCH 2/3] [clang][Sema] Tests for GH41441

I've borrowed size-calculation test from PR89036 and added another test, which 
PR89036 fails on.
---
 clang/test/SemaCXX/GH41441.cpp | 46 ++
 1 file changed, 46 insertions(+)
 create mode 100644 clang/test/SemaCXX/GH41441.cpp

diff --git a/clang/test/SemaCXX/GH41441.cpp b/clang/test/SemaCXX/GH41441.cpp
new file mode 100644
index 00..7a6260fef91b56
--- /dev/null
+++ b/clang/test/SemaCXX/GH41441.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang --target=x86_64-pc-linux -S -fno-discard-value-names -emit-llvm 
-o - %s | FileCheck %s
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+namespace std {
+  using size_t = decltype(sizeof(int));
+};
+void* operator new[](std::size_t, void*) noexcept;
+
+// CHECK: call void @llvm.memset.p0.i64(ptr align 1 %x, i8 0, i64 8, i1 false)
+// CHECK: call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 32, i1 
false)
+template 
+void f()
+{
+typedef TYPE TArray[8];
+
+TArray x;
+new(&x) TArray();
+}
+
+template 
+void f1() {
+  int (*x)[1] = new int[1][1];
+}
+template void f1();
+void f2() {
+  int (*x)[1] = new int[1][1];
+}
+
+int main()
+{
+f();
+f();
+}
+
+// expected-no-diagnostics
+template  struct unique_ptr {unique_ptr(T* p){}};
+
+template 
+unique_ptr make_unique(unsigned long long n) {
+  return unique_ptr(new T[n]());
+}
+
+auto boro(int n){
+   typedef double HistoryBuffer[4];
+   return make_unique(n);
+}

>From 81ea2f2233b769e75dc43b37933f78fe8c8f2e7d Mon Sep 17 00:00:00 2001
From: awson 
Date: Tue, 17 Sep 2024 10:22:36 +0300
Subject: [PATCH 3/3] [Clang][Sema] Update release notes on GH41441.

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 69b2aea52aa9d3..6708167bf8b362 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -391,6 +391,7 @@ Bug Fixes to C++ Support
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. #GH63819, #GH107560
 - Fix a crash when a static assert declaration has an invalid close location. 
(#GH108687)
+- Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 
 Bug Fixes to AST Handling
 ^

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits


@@ -489,6 +542,9 @@ class OpLowerer {
   case Intrinsic::dx_typedBufferStore:
 HasErrors |= lowerTypedBufferStore(F);
 break;
+  case Intrinsic::dx_splitdouble:

farzonl wrote:

I'd like to see all the changes to `DXILOpLowering.cpp` removed. I don't see 
why this can't all be done in cgbuiltins.

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits


@@ -82,5 +82,5 @@ let TargetPrefix = "spv" in {
 [llvm_anyint_ty, LLVMScalarOrSameVectorWidth<0, LLVMVectorElementType<0>>],
 [IntrNoMem, Commutative] >;
   def int_spv_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], 
[IntrConvergent]>;
-  def int_spv_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, 
llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;
+  def int_spv_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, 
llvm_i32_ty>], [llvm_any_ty]>;

farzonl wrote:

This looks like a bad merge.  Please add `[IntrNoMem]` back.

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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits

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


[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-10-03 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-clang-aarch64-darwin` 
running on `doug-worker-5` while building `clang` at step 6 
"test-build-unified-tree-check-all".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/190/builds/7052


Here is the relevant piece of the build log for the reference

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'Clang :: 
CodeGen/attr-target-version-riscv-invalid.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: not 
/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 
-internal-isystem 
/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include 
-nostdsysteminc -triple riscv64 -target-feature +i -emit-llvm -o - 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c
 2>&1 | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c
 --check-prefix=CHECK-UNSUPPORT-OS
+ not /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 
-internal-isystem 
/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include 
-nostdsysteminc -triple riscv64 -target-feature +i -emit-llvm -o - 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c
 --check-prefix=CHECK-UNSUPPORT-OS
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c:3:24:
 error: CHECK-UNSUPPORT-OS: expected string not found in 
input
// CHECK-UNSUPPORT-OS: error: function multiversioning is currently only 
supported on Linux
   ^
:1:1: note: scanning from here
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c:8:48:
 error: function multiversioning doesn't support feature '9'
^
:1:120: note: possible intended match here
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c:8:48:
 error: function multiversioning doesn't support feature '9'
   
^

Input file: 
Check file: 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c

-dump-input=help explains the following input dump.

Input was:
<<
   1: 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/CodeGen/attr-target-version-riscv-invalid.c:8:48:
 error: function multiversioning doesn't support feature '9' 
check:3'0 
X~~
 error: no match found
check:3'1  
  ? 
   possible intended match
   2:  8 | 
__attribute__((target_version("arch=+c"))) int foo(void) { 
check:3'0 

   3:  | ^ 
check:3'0 ~
   4: 1 error generated. 
check:3'0 ~~~
>>

--




```



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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-03 Thread Farzon Lotfi via cfe-commits


@@ -85,4 +85,9 @@ def int_dx_rsqrt  : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], 
[LLVMMatchType<0>]
 def int_dx_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], 
[IntrConvergent]>;
 def int_dx_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, 
llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;
 def int_dx_step : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty, 
LLVMMatchType<0>], [IntrNoMem]>;
+
+def int_dx_splitdouble : DefaultAttrsIntrinsic<
+[llvm_anyint_ty, LLVMMatchType<0>], 
+[LLVMScalarOrSameVectorWidth<0, llvm_double_ty>], 
+[IntrNoMem, IntrWillReturn]>;

farzonl wrote:

`DefaultAttrsIntrinsic` already has a `IntrWillReturn` attribute. 
```suggestion
def int_dx_splitdouble : DefaultAttrsIntrinsic<
[llvm_anyint_ty, LLVMMatchType<0>], 
[LLVMScalarOrSameVectorWidth<0, llvm_double_ty>], 
[IntrNoMem]>;
```

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


[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-10-03 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-hexagon-elf` running 
on `hexagon-build-02` while building `clang` at step 5 "ninja check 1".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/40/builds/2132


Here is the relevant piece of the build log for the reference

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'Clang :: 
CodeGen/attr-target-version-riscv-invalid.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: not 
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/stage1/bin/clang 
-cc1 -internal-isystem 
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/stage1/lib/clang/20/include
 -nostdsysteminc -triple riscv64 -target-feature +i -emit-llvm -o - 
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/llvm/clang/test/CodeGen/attr-target-version-riscv-invalid.c
 2>&1 | 
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/stage1/bin/FileCheck
 
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/llvm/clang/test/CodeGen/attr-target-version-riscv-invalid.c
 --check-prefix=CHECK-UNSUPPORT-OS
+ 
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/stage1/bin/FileCheck
 
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/llvm/clang/test/CodeGen/attr-target-version-riscv-invalid.c
 --check-prefix=CHECK-UNSUPPORT-OS
+ not 
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/stage1/bin/clang 
-cc1 -internal-isystem 
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/stage1/lib/clang/20/include
 -nostdsysteminc -triple riscv64 -target-feature +i -emit-llvm -o - 
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/llvm/clang/test/CodeGen/attr-target-version-riscv-invalid.c
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/llvm/clang/test/CodeGen/attr-target-version-riscv-invalid.c:3:24:
 error: CHECK-UNSUPPORT-OS: expected string not found in input
// CHECK-UNSUPPORT-OS: error: function multiversioning is currently only 
supported on Linux
   ^
:1:1: note: scanning from here
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/llvm/clang/test/CodeGen/attr-target-version-riscv-invalid.c:8:48:
 error: function multiversioning doesn't support feature ''
^
:1:128: note: possible intended match here
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/llvm/clang/test/CodeGen/attr-target-version-riscv-invalid.c:8:48:
 error: function multiversioning doesn't support feature ''

   ^

Input file: 
Check file: 
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/llvm/clang/test/CodeGen/attr-target-version-riscv-invalid.c

-dump-input=help explains the following input dump.

Input was:
<<
   1: 
/local/mnt/workspace/bots/hexagon-build-02/clang-hexagon-elf/llvm/clang/test/CodeGen/attr-target-version-riscv-invalid.c:8:48:
 error: function multiversioning doesn't support feature '' 
check:3'0 
X~
 error: no match found
check:3'1   
 ?  
 possible intended match
   2:  8 | __attribute__((target_version("arch=+c"))) int foo(void) { 
check:3'0 
   3:  | ^ 
check:3'0 ~
   4: 1 error generated. 
check:3'0 ~~~
>>

--




```



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


[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-10-03 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-fast` running on `sanitizer-buildbot3` while building 
`clang` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/169/builds/3933


Here is the relevant piece of the build log for the reference

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 86068 of 86069 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
FAIL: Clang :: SemaCXX/attr-target-version-riscv.cpp (86054 of 86068)
 TEST 'Clang :: SemaCXX/attr-target-version-riscv.cpp' 
FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang -cc1 
-internal-isystem 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/lib/clang/20/include
 -nostdsysteminc -triple riscv64-linux-gnu  -fsyntax-only -verify -fexceptions 
-fcxx-exceptions 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/SemaCXX/attr-target-version-riscv.cpp
 -std=c++14
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/lib/clang/20/include
 -nostdsysteminc -triple riscv64-linux-gnu -fsyntax-only -verify -fexceptions 
-fcxx-exceptions 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/SemaCXX/attr-target-version-riscv.cpp
 -std=c++14
=
==3823339==ERROR: AddressSanitizer: heap-use-after-free on address 
0x503089b2 at pc 0x5f3ce727c192 bp 0x7ffcbd9fd0d0 sp 0x7ffcbd9fd0c8
READ of size 1 at 0x503089b2 thread T0
#0 0x5f3ce727c191 in ascii_strncasecmp(char const*, char const*, unsigned 
long) 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Support/StringRef.cpp:30:33
#1 0x5f3ce727c073 in llvm::StringRef::compare_insensitive(llvm::StringRef) 
const 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Support/StringRef.cpp:38:17
#2 0x5f3ce73dca5d in equals_insensitive 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/StringRef.h:176:38
#3 0x5f3ce73dca5d in 
llvm::RISCVISAInfo::getRISCVFeaturesBitsInfo(llvm::StringRef) 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/TargetParser/RISCVISAInfo.cpp:1063:15
#4 0x5f3ce87b0dce in 
clang::targets::RISCVTargetInfo::validateCpuSupports(llvm::StringRef) const 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Basic/Targets/RISCV.cpp:483:16
#5 0x5f3cee187ddb in CheckMultiVersionValue(clang::Sema&, 
clang::FunctionDecl const*) 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaDecl.cpp:11052:23
#6 0x5f3cee1132a2 in CheckMultiVersionFirstFunction 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaDecl.cpp:11312:22
#7 0x5f3cee1132a2 in CheckMultiVersionFunction 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaDecl.cpp:11773:12
#8 0x5f3cee1132a2 in clang::Sema::CheckFunctionD

[clang] Revert "[RISCV][FMV] Support target_version" (PR #111096)

2024-10-03 Thread Piyou Chen via cfe-commits

https://github.com/BeMg created https://github.com/llvm/llvm-project/pull/111096

Reverts llvm/llvm-project#99040 to fix 
https://lab.llvm.org/buildbot/#/builders/190/builds/7052

>From 32174720649068de7c4ef97a484d777dba72e65c Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Fri, 4 Oct 2024 11:55:45 +0800
Subject: [PATCH] Revert "[RISCV][FMV] Support target_version (#99040)"

This reverts commit 7ab488e92c39c813a50cb4fd6587e7afc161c7d5.
---
 clang/lib/AST/ASTContext.cpp  |  14 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |   7 +-
 clang/lib/Sema/SemaDecl.cpp   |  19 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  48 --
 .../attr-target-version-riscv-invalid.c   |  13 -
 .../test/CodeGen/attr-target-version-riscv.c  | 443 --
 .../CodeGenCXX/attr-target-version-riscv.cpp  | 432 -
 .../SemaCXX/attr-target-version-riscv.cpp | 113 -
 8 files changed, 8 insertions(+), 1081 deletions(-)
 delete mode 100644 clang/test/CodeGen/attr-target-version-riscv-invalid.c
 delete mode 100644 clang/test/CodeGen/attr-target-version-riscv.c
 delete mode 100644 clang/test/CodeGenCXX/attr-target-version-riscv.cpp
 delete mode 100644 clang/test/SemaCXX/attr-target-version-riscv.cpp

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 034fbbe0bc7829..a81429ad6a2380 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14325,17 +14325,9 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
 }
   } else if (const auto *TV = FD->getAttr()) {
-std::vector Features;
-if (Target->getTriple().isRISCV()) {
-  ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(TV->getName());
-  Features.insert(Features.begin(), ParsedAttr.Features.begin(),
-  ParsedAttr.Features.end());
-} else {
-  assert(Target->getTriple().isAArch64());
-  llvm::SmallVector Feats;
-  TV->getFeatures(Feats);
-  Features = getFMVBackendFeaturesFor(Feats);
-}
+llvm::SmallVector Feats;
+TV->getFeatures(Feats);
+std::vector Features = getFMVBackendFeaturesFor(Feats);
 Features.insert(Features.begin(),
 Target->getTargetOpts().FeaturesAsWritten.begin(),
 Target->getTargetOpts().FeaturesAsWritten.end());
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 5ba098144a74e7..25c1c496a4f27f 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4287,13 +4287,8 @@ void CodeGenModule::emitMultiVersionFunctions() {
   } else if (const auto *TVA = CurFD->getAttr()) {
 if (TVA->isDefaultVersion() && IsDefined)
   ShouldEmitResolver = true;
+TVA->getFeatures(Feats);
 llvm::Function *Func = createFunction(CurFD);
-if (getTarget().getTriple().isRISCV()) {
-  Feats.push_back(TVA->getName());
-} else {
-  assert(getTarget().getTriple().isAArch64());
-  TVA->getFeatures(Feats);
-}
 Options.emplace_back(Func, /*Architecture*/ "", Feats);
   } else if (const auto *TC = CurFD->getAttr()) {
 if (IsDefined)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 21f25a2ea09eb0..2bf610746bc317 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10329,8 +10329,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   // Handle attributes.
   ProcessDeclAttributes(S, NewFD, D);
   const auto *NewTVA = NewFD->getAttr();
-  if (Context.getTargetInfo().getTriple().isAArch64() && NewTVA &&
-  !NewTVA->isDefaultVersion() &&
+  if (NewTVA && !NewTVA->isDefaultVersion() &&
   !Context.getTargetInfo().hasFeature("fmv")) {
 // Don't add to scope fmv functions declarations if fmv disabled
 AddToScope = false;
@@ -11039,15 +11038,7 @@ static bool CheckMultiVersionValue(Sema &S, const 
FunctionDecl *FD) {
 
   if (TVA) {
 llvm::SmallVector Feats;
-if (S.getASTContext().getTargetInfo().getTriple().isRISCV()) {
-  ParsedTargetAttr ParseInfo =
-  S.getASTContext().getTargetInfo().parseTargetAttr(TVA->getName());
-  for (auto &Feat : ParseInfo.Features)
-Feats.push_back(StringRef{Feat}.substr(1));
-} else {
-  assert(S.getASTContext().getTargetInfo().getTriple().isAArch64());
-  TVA->getFeatures(Feats);
-}
+TVA->getFeatures(Feats);
 for (const auto &Feat : Feats) {
   if (!TargetInfo.validateCpuSupports(Feat)) {
 S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
@@ -11333,8 +11324,7 @@ static bool 
PreviousDeclsHaveMultiVersionAttribute(const FunctionDecl *FD) {
 }
 
 static void patchDefaultTargetVersion(FunctionDecl *From, FunctionDecl *To) {
-  if (!From-

[clang] Revert "[RISCV][FMV] Support target_version" (PR #111096)

2024-10-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Piyou Chen (BeMg)


Changes

Reverts llvm/llvm-project#99040 to fix 
https://lab.llvm.org/buildbot/#/builders/190/builds/7052

---

Patch is 57.55 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/111096.diff


8 Files Affected:

- (modified) clang/lib/AST/ASTContext.cpp (+3-11) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-6) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+4-15) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (-48) 
- (removed) clang/test/CodeGen/attr-target-version-riscv-invalid.c (-13) 
- (removed) clang/test/CodeGen/attr-target-version-riscv.c (-443) 
- (removed) clang/test/CodeGenCXX/attr-target-version-riscv.cpp (-432) 
- (removed) clang/test/SemaCXX/attr-target-version-riscv.cpp (-113) 


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 034fbbe0bc7829..a81429ad6a2380 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14325,17 +14325,9 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
 }
   } else if (const auto *TV = FD->getAttr()) {
-std::vector Features;
-if (Target->getTriple().isRISCV()) {
-  ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(TV->getName());
-  Features.insert(Features.begin(), ParsedAttr.Features.begin(),
-  ParsedAttr.Features.end());
-} else {
-  assert(Target->getTriple().isAArch64());
-  llvm::SmallVector Feats;
-  TV->getFeatures(Feats);
-  Features = getFMVBackendFeaturesFor(Feats);
-}
+llvm::SmallVector Feats;
+TV->getFeatures(Feats);
+std::vector Features = getFMVBackendFeaturesFor(Feats);
 Features.insert(Features.begin(),
 Target->getTargetOpts().FeaturesAsWritten.begin(),
 Target->getTargetOpts().FeaturesAsWritten.end());
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 5ba098144a74e7..25c1c496a4f27f 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4287,13 +4287,8 @@ void CodeGenModule::emitMultiVersionFunctions() {
   } else if (const auto *TVA = CurFD->getAttr()) {
 if (TVA->isDefaultVersion() && IsDefined)
   ShouldEmitResolver = true;
+TVA->getFeatures(Feats);
 llvm::Function *Func = createFunction(CurFD);
-if (getTarget().getTriple().isRISCV()) {
-  Feats.push_back(TVA->getName());
-} else {
-  assert(getTarget().getTriple().isAArch64());
-  TVA->getFeatures(Feats);
-}
 Options.emplace_back(Func, /*Architecture*/ "", Feats);
   } else if (const auto *TC = CurFD->getAttr()) {
 if (IsDefined)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 21f25a2ea09eb0..2bf610746bc317 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10329,8 +10329,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   // Handle attributes.
   ProcessDeclAttributes(S, NewFD, D);
   const auto *NewTVA = NewFD->getAttr();
-  if (Context.getTargetInfo().getTriple().isAArch64() && NewTVA &&
-  !NewTVA->isDefaultVersion() &&
+  if (NewTVA && !NewTVA->isDefaultVersion() &&
   !Context.getTargetInfo().hasFeature("fmv")) {
 // Don't add to scope fmv functions declarations if fmv disabled
 AddToScope = false;
@@ -11039,15 +11038,7 @@ static bool CheckMultiVersionValue(Sema &S, const 
FunctionDecl *FD) {
 
   if (TVA) {
 llvm::SmallVector Feats;
-if (S.getASTContext().getTargetInfo().getTriple().isRISCV()) {
-  ParsedTargetAttr ParseInfo =
-  S.getASTContext().getTargetInfo().parseTargetAttr(TVA->getName());
-  for (auto &Feat : ParseInfo.Features)
-Feats.push_back(StringRef{Feat}.substr(1));
-} else {
-  assert(S.getASTContext().getTargetInfo().getTriple().isAArch64());
-  TVA->getFeatures(Feats);
-}
+TVA->getFeatures(Feats);
 for (const auto &Feat : Feats) {
   if (!TargetInfo.validateCpuSupports(Feat)) {
 S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
@@ -11333,8 +11324,7 @@ static bool 
PreviousDeclsHaveMultiVersionAttribute(const FunctionDecl *FD) {
 }
 
 static void patchDefaultTargetVersion(FunctionDecl *From, FunctionDecl *To) {
-  if (!From->getASTContext().getTargetInfo().getTriple().isAArch64() &&
-  !From->getASTContext().getTargetInfo().getTriple().isRISCV())
+  if (!From->getASTContext().getTargetInfo().getTriple().isAArch64())
 return;
 
   MultiVersionKind MVKindFrom = From->getMultiVersionKind();
@@ -15521,8 +15511,7 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, 
Decl *D,
 FD->setInvalidDecl();
   }
   if (const auto *Attr = FD

[clang] Revert "[RISCV][FMV] Support target_version" (PR #111096)

2024-10-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Piyou Chen (BeMg)


Changes

Reverts llvm/llvm-project#99040 to fix 
https://lab.llvm.org/buildbot/#/builders/190/builds/7052

---

Patch is 57.55 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/111096.diff


8 Files Affected:

- (modified) clang/lib/AST/ASTContext.cpp (+3-11) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-6) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+4-15) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (-48) 
- (removed) clang/test/CodeGen/attr-target-version-riscv-invalid.c (-13) 
- (removed) clang/test/CodeGen/attr-target-version-riscv.c (-443) 
- (removed) clang/test/CodeGenCXX/attr-target-version-riscv.cpp (-432) 
- (removed) clang/test/SemaCXX/attr-target-version-riscv.cpp (-113) 


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 034fbbe0bc7829..a81429ad6a2380 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14325,17 +14325,9 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
 }
   } else if (const auto *TV = FD->getAttr()) {
-std::vector Features;
-if (Target->getTriple().isRISCV()) {
-  ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(TV->getName());
-  Features.insert(Features.begin(), ParsedAttr.Features.begin(),
-  ParsedAttr.Features.end());
-} else {
-  assert(Target->getTriple().isAArch64());
-  llvm::SmallVector Feats;
-  TV->getFeatures(Feats);
-  Features = getFMVBackendFeaturesFor(Feats);
-}
+llvm::SmallVector Feats;
+TV->getFeatures(Feats);
+std::vector Features = getFMVBackendFeaturesFor(Feats);
 Features.insert(Features.begin(),
 Target->getTargetOpts().FeaturesAsWritten.begin(),
 Target->getTargetOpts().FeaturesAsWritten.end());
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 5ba098144a74e7..25c1c496a4f27f 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4287,13 +4287,8 @@ void CodeGenModule::emitMultiVersionFunctions() {
   } else if (const auto *TVA = CurFD->getAttr()) {
 if (TVA->isDefaultVersion() && IsDefined)
   ShouldEmitResolver = true;
+TVA->getFeatures(Feats);
 llvm::Function *Func = createFunction(CurFD);
-if (getTarget().getTriple().isRISCV()) {
-  Feats.push_back(TVA->getName());
-} else {
-  assert(getTarget().getTriple().isAArch64());
-  TVA->getFeatures(Feats);
-}
 Options.emplace_back(Func, /*Architecture*/ "", Feats);
   } else if (const auto *TC = CurFD->getAttr()) {
 if (IsDefined)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 21f25a2ea09eb0..2bf610746bc317 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10329,8 +10329,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   // Handle attributes.
   ProcessDeclAttributes(S, NewFD, D);
   const auto *NewTVA = NewFD->getAttr();
-  if (Context.getTargetInfo().getTriple().isAArch64() && NewTVA &&
-  !NewTVA->isDefaultVersion() &&
+  if (NewTVA && !NewTVA->isDefaultVersion() &&
   !Context.getTargetInfo().hasFeature("fmv")) {
 // Don't add to scope fmv functions declarations if fmv disabled
 AddToScope = false;
@@ -11039,15 +11038,7 @@ static bool CheckMultiVersionValue(Sema &S, const 
FunctionDecl *FD) {
 
   if (TVA) {
 llvm::SmallVector Feats;
-if (S.getASTContext().getTargetInfo().getTriple().isRISCV()) {
-  ParsedTargetAttr ParseInfo =
-  S.getASTContext().getTargetInfo().parseTargetAttr(TVA->getName());
-  for (auto &Feat : ParseInfo.Features)
-Feats.push_back(StringRef{Feat}.substr(1));
-} else {
-  assert(S.getASTContext().getTargetInfo().getTriple().isAArch64());
-  TVA->getFeatures(Feats);
-}
+TVA->getFeatures(Feats);
 for (const auto &Feat : Feats) {
   if (!TargetInfo.validateCpuSupports(Feat)) {
 S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
@@ -11333,8 +11324,7 @@ static bool 
PreviousDeclsHaveMultiVersionAttribute(const FunctionDecl *FD) {
 }
 
 static void patchDefaultTargetVersion(FunctionDecl *From, FunctionDecl *To) {
-  if (!From->getASTContext().getTargetInfo().getTriple().isAArch64() &&
-  !From->getASTContext().getTargetInfo().getTriple().isRISCV())
+  if (!From->getASTContext().getTargetInfo().getTriple().isAArch64())
 return;
 
   MultiVersionKind MVKindFrom = From->getMultiVersionKind();
@@ -15521,8 +15511,7 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, 
Decl *D,
 FD->setInvalidDecl();
   }
   if (const auto *A

[clang] [llvm] Update llvm::Registry to work for LLVM shared library builds on windows (PR #109024)

2024-10-03 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 46a76c33343c34c0eb5fa7ec849d0de42cfed412 
f8e37cf5e9dfe85ca5a9081fc294329c3265aea1 --extensions h -- 
clang/include/clang/Basic/ParsedAttrInfo.h 
clang/include/clang/Frontend/FrontendPluginRegistry.h 
clang/include/clang/Lex/Preprocessor.h 
clang/include/clang/Tooling/CompilationDatabasePluginRegistry.h 
clang/include/clang/Tooling/ToolExecutorPluginRegistry.h 
llvm/include/llvm/CodeGen/GCMetadataPrinter.h llvm/include/llvm/IR/GCStrategy.h 
llvm/include/llvm/Support/Compiler.h llvm/include/llvm/Support/Registry.h
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/Support/Registry.h 
b/llvm/include/llvm/Support/Registry.h
index c80da1c5d3..2a3519b1b4 100644
--- a/llvm/include/llvm/Support/Registry.h
+++ b/llvm/include/llvm/Support/Registry.h
@@ -107,7 +107,7 @@ namespace llvm {
 
 // begin is not defined here in order to avoid usage of an undefined static
 // data member, instead it's instantiated by LLVM_INSTANTIATE_REGISTRY.
-static iterator begin() { return iterator(Head); } 
+static iterator begin() { return iterator(Head); }
 static iterator end()   { return iterator(nullptr); }
 
 static iterator_range entries() {
@@ -137,20 +137,20 @@ namespace llvm {
 };
   };
 
-  template typename Registry::node *Registry::Head = nullptr;
-  template typename Registry::node *Registry::Tail = nullptr;
+  template  typename Registry::node *Registry::Head = 
nullptr;
+  template  typename Registry::node *Registry::Tail = 
nullptr;
 } // end namespace llvm
 
 #ifdef _WIN32
 /// Instantiate a registry class.
-#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
-  namespace llvm { \
-template class LLVM_ABI_EXPORT Registry;\
+#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS)  
\
+  namespace llvm { 
\
+  template class LLVM_ABI_EXPORT Registry;   
\
   }
 #else
-#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
-  namespace llvm { \
-template class Registry;\
+#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS)  
\
+  namespace llvm { 
\
+  template class Registry; 
\
   }
 #endif
 

``




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


[clang] Add visibility features for z/OS (eg. _Export, pragma export) (PR #111035)

2024-10-03 Thread Sean Perry via cfe-commits

https://github.com/perry-ca updated 
https://github.com/llvm/llvm-project/pull/111035

>From e8d355c9cd165e0a255bbbfb5b0126cf7b1461a6 Mon Sep 17 00:00:00 2001
From: Sean Perry 
Date: Wed, 2 Oct 2024 12:56:43 -0500
Subject: [PATCH 1/5] initial work for pragma export & _Export keyword

---
 clang/include/clang/AST/ASTConsumer.h |   3 +
 clang/include/clang/Basic/Attr.td |   6 +
 clang/include/clang/Basic/AttrDocs.td |  21 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   7 +
 clang/include/clang/Basic/TokenKinds.def  |   5 +
 clang/include/clang/Parse/Parser.h|  13 ++
 clang/include/clang/Sema/DeclSpec.h   |  31 ++-
 clang/include/clang/Sema/Sema.h   |  30 +++
 clang/lib/CodeGen/BackendConsumer.h   |   1 +
 clang/lib/CodeGen/CodeGenAction.cpp   |   4 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  15 ++
 clang/lib/CodeGen/CodeGenModule.h |   2 +
 clang/lib/CodeGen/ModuleBuilder.cpp   |   6 +-
 clang/lib/Driver/ToolChains/ZOS.cpp   |  12 +-
 clang/lib/Parse/ParseDecl.cpp |  18 ++
 clang/lib/Parse/ParseDeclCXX.cpp  |   6 +
 clang/lib/Parse/ParsePragma.cpp   | 208 ++
 clang/lib/Parse/Parser.cpp|   3 +
 clang/lib/Sema/DeclSpec.cpp   |   6 +
 clang/lib/Sema/Sema.cpp   |  21 ++
 clang/lib/Sema/SemaAttr.cpp   | 162 ++
 clang/lib/Sema/SemaDecl.cpp   |  13 ++
 clang/test/CodeGen/attr-export-failing.cpp|   4 +
 clang/test/CodeGen/attr-export.cpp|  51 +
 clang/test/CodeGen/pragma-export.c|  39 
 clang/test/CodeGen/pragma-export.cpp  |  82 +++
 clang/test/CodeGen/zos-pragmas.c  |  11 +
 clang/test/CodeGen/zos-pragmas.cpp|  11 +
 28 files changed, 784 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-export-failing.cpp
 create mode 100644 clang/test/CodeGen/attr-export.cpp
 create mode 100644 clang/test/CodeGen/pragma-export.c
 create mode 100644 clang/test/CodeGen/pragma-export.cpp
 create mode 100644 clang/test/CodeGen/zos-pragmas.c
 create mode 100644 clang/test/CodeGen/zos-pragmas.cpp

diff --git a/clang/include/clang/AST/ASTConsumer.h 
b/clang/include/clang/AST/ASTConsumer.h
index 447f2592d23595..b15d53e700c679 100644
--- a/clang/include/clang/AST/ASTConsumer.h
+++ b/clang/include/clang/AST/ASTConsumer.h
@@ -108,6 +108,9 @@ class ASTConsumer {
   /// completed.
   virtual void CompleteExternalDeclaration(DeclaratorDecl *D) {}
 
+  /// CompletePragmaExport - complete #pragma export statements.
+  virtual void CompletePragmaExport(Decl *D) {}
+
   /// Callback invoked when an MSInheritanceAttr has been attached to a
   /// CXXRecordDecl.
   virtual void AssignInheritanceModel(CXXRecordDecl *RD) {}
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fbcbf0ed416416..884c4147cf1285 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4520,6 +4520,12 @@ def ReleaseHandle : InheritableParamAttr {
   let Documentation = [ReleaseHandleDocs];
 }
 
+def zOSExport : InheritableAttr {
+  let Spellings = [CustomKeyword<"_Export">];
+  let Subjects = SubjectList<[Function, Var, CXXRecord]>;
+  let Documentation = [zOSExportDocs];
+}
+
 def UnsafeBufferUsage : InheritableAttr {
   let Spellings = [Clang<"unsafe_buffer_usage">];
   let Subjects = SubjectList<[Function, Field]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 53d88482698f00..bf56fa6ad7162f 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6863,6 +6863,27 @@ attribute requires a string literal argument to identify 
the handle being releas
   }];
 }
 
+def zOSExportDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Use the _Export keyword with a function name or external variable to declare
+that it is to be exported (made available to other modules). You must define
+the object name in the same translation unit in which you use the _Export
+keyword. For example:
+
+.. code-block:: c
+
+  int _Export anthony(float);
+
+This statement exports the function anthony, if you define the function in the
+translation unit. The _Export keyword must immediately precede the object name.
+If you apply the _Export keyword to a class, the compiler automatically exports
+all static data members and member functions of the class. However, if you want
+it to apply to individual class members, then you must apply it to each member
+that can be referenced.
+  }];
+}
+
 def UnsafeBufferUsageDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 64e6d0407b0ce3..09842ed02efd4b 100644
--- a/c

[clang] [llvm] [HLSL] Implement `WaveReadLaneAt` intrinsic for spirv backend (PR #111010)

2024-10-03 Thread Finn Plummer via cfe-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/111010

>From 358ea8278b4e10a094d342aa9b3b1571120a1478 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Thu, 3 Oct 2024 11:43:51 -0700
Subject: [PATCH 1/2] [HLSL] Implement `WaveReadLaneAt` intrinsic

- create a clang built-in in Builtins.td
- add semantic checking in SemaHLSL.cpp
- link the WaveReadLaneAt api in hlsl_intrinsics.h
- add lowering to spirv backend op GroupNonUniformShuffle
  with Scope = 2 (Group) in SPIRVInstructionSelector.cpp

- add tests for HLSL intrinsic lowering to spirv intrinsic in
  WaveReadLaneAt.hlsl
- add tests for sema checks in WaveReadLaneAt-errors.hlsl
- add spir-v backend tests in WaveReadLaneAt.ll
---
 clang/include/clang/Basic/Builtins.td |  6 +++
 clang/lib/CodeGen/CGBuiltin.cpp   | 17 
 clang/lib/CodeGen/CGHLSLRuntime.h |  1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  7 
 clang/lib/Sema/SemaHLSL.cpp   | 20 ++
 .../CodeGenHLSL/builtins/WaveReadLaneAt.hlsl  | 40 +++
 .../BuiltIns/WaveReadLaneAt-errors.hlsl   | 21 ++
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  1 +
 .../Target/SPIRV/SPIRVInstructionSelector.cpp | 15 +++
 .../SPIRV/hlsl-intrinsics/WaveReadLaneAt.ll   | 28 +
 10 files changed, 156 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/WaveReadLaneAt.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/WaveReadLaneAt-errors.hlsl
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveReadLaneAt.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 8090119e512fbb..eec9acd4d27d7d 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4703,6 +4703,12 @@ def HLSLWaveIsFirstLane : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "bool()";
 }
 
+def HLSLWaveReadLaneAt : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_wave_read_lane_at"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 def HLSLClamp : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_elementwise_clamp"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index da3eca73bfb575..2cd851475b6dd9 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18835,6 +18835,23 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 Intrinsic::ID ID = CGM.getHLSLRuntime().getWaveIsFirstLaneIntrinsic();
 return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID));
   }
+  case Builtin::BI__builtin_hlsl_wave_read_lane_at: {
+// Due to the use of variadic arguments we must explicitly retreive them 
and
+// create our function type.
+Value *OpExpr = EmitScalarExpr(E->getArg(0));
+Value *OpIndex = EmitScalarExpr(E->getArg(1));
+llvm::FunctionType *FT = llvm::FunctionType::get(
+OpExpr->getType(), ArrayRef{OpExpr->getType(), OpIndex->getType()},
+false);
+
+// Get overloaded name
+std::string name =
+Intrinsic::getName(CGM.getHLSLRuntime().getWaveReadLaneAtIntrinsic(),
+   ArrayRef{OpExpr->getType()}, &CGM.getModule());
+return EmitRuntimeCall(
+CGM.CreateRuntimeFunction(FT, name, {}, false, true),
+ArrayRef{OpExpr, OpIndex}, "hlsl.wave.read.lane.at");
+  }
   case Builtin::BI__builtin_hlsl_elementwise_sign: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 llvm::Type *Xty = Op0->getType();
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index a8aabca7348ffb..a639ce2d784f4a 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -87,6 +87,7 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(UDot, udot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_read_lane_at)
 
   
//===--===//
   // End of reserved area for HLSL intrinsic getters.
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 810a16d75f0228..a7bdc353ae71bf 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -2015,6 +2015,13 @@ _HLSL_AVAILABILITY(shadermodel, 6.0)
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_is_first_lane)
 __attribute__((convergent)) bool WaveIsFirstLane();
 
+// \brief Returns the value of the expression for the given lane index within
+// the specified wave.
+template 
+_HLSL_AVAILABILITY(shadermodel, 6.0)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_read_lane_at)
+__attribute__((convergent)) T WaveReadLaneAt(T, int32_t);
+
 
//===--

[clang] [llvm] Update llvm::Registry to work for LLVM shared library builds on windows (PR #109024)

2024-10-03 Thread Thomas Fransham via cfe-commits

https://github.com/fsfod updated 
https://github.com/llvm/llvm-project/pull/109024

>From fcb6837e5c6ff48bf261bae9d3cedda55da89a7e Mon Sep 17 00:00:00 2001
From: Thomas Fransham 
Date: Wed, 28 Aug 2024 16:08:52 +0100
Subject: [PATCH 1/6] Update llvm::Registry to work for LLVM shared library
 builds on windows

Windows doesn't implicitly import and merge exported symbols across shared 
libraries
like Linux does so we need to explicitly export/import each instantiation of 
llvm::Registry.
Updated LLVM_INSTANTIATE_REGISTRY macro to export Registry::add_node and
Registry::begin() and add extern template declarations for the all 
instantiations of llvm::Registry.
---
 clang/include/clang/Basic/ParsedAttrInfo.h|  5 +++
 .../clang/Frontend/FrontendPluginRegistry.h   |  5 +++
 llvm/include/llvm/CodeGen/GCMetadataPrinter.h |  2 +
 llvm/include/llvm/IR/GCStrategy.h |  2 +
 llvm/include/llvm/Support/Compiler.h  |  5 +++
 llvm/include/llvm/Support/Registry.h  | 43 ++-
 6 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/Basic/ParsedAttrInfo.h 
b/clang/include/clang/Basic/ParsedAttrInfo.h
index 537d8f3391d589..2b82dd3b43d133 100644
--- a/clang/include/clang/Basic/ParsedAttrInfo.h
+++ b/clang/include/clang/Basic/ParsedAttrInfo.h
@@ -17,6 +17,7 @@
 
 #include "clang/Basic/AttrSubjectMatchRules.h"
 #include "clang/Basic/AttributeCommonInfo.h"
+#include "clang/Support/Compiler.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/Registry.h"
 #include 
@@ -165,4 +166,8 @@ const std::list> 
&getAttributePluginInstances();
 
 } // namespace clang
 
+namespace llvm {
+extern template class CLANG_TEMPLATE_ABI llvm::Registry;
+} // namespace llvm
+
 #endif // LLVM_CLANG_BASIC_PARSEDATTRINFO_H
diff --git a/clang/include/clang/Frontend/FrontendPluginRegistry.h 
b/clang/include/clang/Frontend/FrontendPluginRegistry.h
index 810578534acb45..5eea9c2fd89a32 100644
--- a/clang/include/clang/Frontend/FrontendPluginRegistry.h
+++ b/clang/include/clang/Frontend/FrontendPluginRegistry.h
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_FRONTEND_FRONTENDPLUGINREGISTRY_H
 
 #include "clang/Frontend/FrontendAction.h"
+#include "clang/Support/Compiler.h"
 #include "llvm/Support/Registry.h"
 
 namespace clang {
@@ -23,4 +24,8 @@ using FrontendPluginRegistry = 
llvm::Registry;
 
 } // namespace clang
 
+namespace llvm {
+extern template class CLANG_TEMPLATE_ABI Registry;
+} // namespace llvm
+
 #endif // LLVM_CLANG_FRONTEND_FRONTENDPLUGINREGISTRY_H
diff --git a/llvm/include/llvm/CodeGen/GCMetadataPrinter.h 
b/llvm/include/llvm/CodeGen/GCMetadataPrinter.h
index f9527c9f8752e9..9d421be8313f01 100644
--- a/llvm/include/llvm/CodeGen/GCMetadataPrinter.h
+++ b/llvm/include/llvm/CodeGen/GCMetadataPrinter.h
@@ -34,6 +34,8 @@ class StackMaps;
 /// defaults from Registry.
 using GCMetadataPrinterRegistry = Registry;
 
+extern template class LLVM_TEMPLATE_ABI Registry;
+
 /// GCMetadataPrinter - Emits GC metadata as assembly code.  Instances are
 /// created, managed, and owned by the AsmPrinter.
 class GCMetadataPrinter {
diff --git a/llvm/include/llvm/IR/GCStrategy.h 
b/llvm/include/llvm/IR/GCStrategy.h
index 3186465f001812..cbfbe23aaa0683 100644
--- a/llvm/include/llvm/IR/GCStrategy.h
+++ b/llvm/include/llvm/IR/GCStrategy.h
@@ -141,6 +141,8 @@ class GCStrategy {
 /// GCMetadataPrinterRegistery as well.
 using GCRegistry = Registry;
 
+extern template class LLVM_TEMPLATE_ABI Registry;
+
 /// Lookup the GCStrategy object associated with the given gc name.
 std::unique_ptr getGCStrategy(const StringRef Name);
 
diff --git a/llvm/include/llvm/Support/Compiler.h 
b/llvm/include/llvm/Support/Compiler.h
index 1d2d751d4dc11a..e893734b81fb7d 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -179,6 +179,7 @@
 #define LLVM_ABI
 #define LLVM_TEMPLATE_ABI
 #define LLVM_EXPORT_TEMPLATE
+#define LLVM_ABI_EXPORT
 #elif defined(_WIN32) && !defined(__MINGW32__)
 #if defined(LLVM_EXPORTS)
 #define LLVM_ABI __declspec(dllexport)
@@ -189,19 +190,23 @@
 #define LLVM_TEMPLATE_ABI __declspec(dllimport)
 #define LLVM_EXPORT_TEMPLATE
 #endif
+#define LLVM_ABI_EXPORT __declspec(dllexport)
 #elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX)
 #define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define LLVM_EXPORT_TEMPLATE
+#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #elif defined(__MACH__) || defined(__WASM__)
 #define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define LLVM_TEMPLATE_ABI
 #define LLVM_EXPORT_TEMPLATE
+#define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #endif
 #else
 #define LLVM_ABI
 #define LLVM_TEMPLATE_ABI
 #define LLVM_EXPORT_TEMPLATE
+#define LLVM_ABI_EXPORT
 #endif
 #define LLVM_C_ABI LLVM_ABI
 #endif
diff --git a/llvm/include/llvm/Support/Registry.h 
b/llvm/include/llvm/Support/Registry.h
index 5bb6a254a47f4c..2dcbe0f2a28208 100644
--- a/llvm/i

[clang] [llvm] [HLSL] Implement `WaveReadLaneAt` intrinsic for spirv backend (PR #111010)

2024-10-03 Thread Finn Plummer via cfe-commits

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


[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)

2024-10-03 Thread Joseph Huber via cfe-commits

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


[clang] [clang] Allow class with anonymous union member to be const-default-constructible even if a union member has a default member initializer (#95854) (PR #96301)

2024-10-03 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

LGTM, Thanks!
Give a couple of days to @shafik before merging

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


[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)

2024-10-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Joseph Huber (jhuber6)


Changes

Summary:
All GPU based languages provide some way to access things like the
thread ID or other resources. However, this is spread between many
different languages and it varies between targets. The goal here is to
provide a resource directory header that just provides these in an
easier to understand way, primarily so this can be used for C/C++ code.
The interface aims to be common, to faciliate easier porting, but target
specific stuff could be put in the individual headers.


---

Patch is 58.27 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/110179.diff


6 Files Affected:

- (modified) clang/lib/Headers/CMakeLists.txt (+14) 
- (added) clang/lib/Headers/amdgpuintrin.h (+153) 
- (added) clang/lib/Headers/gpuintrin.h (+76) 
- (added) clang/lib/Headers/nvptxintrin.h (+153) 
- (added) clang/test/Headers/gpuintrin.c (+508) 
- (added) clang/test/Headers/gpuintrin_lang.c (+61) 


``diff
diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index ff392e7122a448..a0e7ae67b7219a 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -268,6 +268,12 @@ set(x86_files
   cpuid.h
   )
 
+set(gpu_files
+  gpuintrin.h
+  nvptxintrin.h
+  amdgpuintrin.h
+  )
+
 set(windows_only_files
   intrin0.h
   intrin.h
@@ -296,6 +302,7 @@ set(files
   ${systemz_files}
   ${ve_files}
   ${x86_files}
+  ${gpu_files}
   ${webassembly_files}
   ${windows_only_files}
   ${utility_files}
@@ -518,6 +525,7 @@ add_header_target("systemz-resource-headers" 
"${systemz_files};${zos_wrapper_fil
 add_header_target("ve-resource-headers" "${ve_files}")
 add_header_target("webassembly-resource-headers" "${webassembly_files}")
 add_header_target("x86-resource-headers" "${x86_files}")
+add_header_target("gpu-resource-headers" "${gpu_files}")
 
 # Other header groupings
 add_header_target("hlsl-resource-headers" ${hlsl_files})
@@ -704,6 +712,12 @@ install(
   EXCLUDE_FROM_ALL
   COMPONENT x86-resource-headers)
 
+install(
+  FILES ${gpu_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT gpu-resource-headers)
+
 if(NOT CLANG_ENABLE_HLSL)
   set(EXCLUDE_HLSL EXCLUDE_FROM_ALL)
 endif()
diff --git a/clang/lib/Headers/amdgpuintrin.h b/clang/lib/Headers/amdgpuintrin.h
new file mode 100644
index 00..1fd7261cf4ca75
--- /dev/null
+++ b/clang/lib/Headers/amdgpuintrin.h
@@ -0,0 +1,153 @@
+//===-- amdgpuintrin.h - AMDPGU intrinsic functions 
---===//
+//
+// 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
+//
+//===--===//
+
+#ifndef __AMDGPUINTRIN_H
+#define __AMDGPUINTRIN_H
+
+#ifndef __AMDGPU__
+#error "This file is intended for AMDGPU targets or offloading to AMDGPU"
+#endif
+
+#include 
+#include 
+
+#if defined(__HIP__) || defined(__CUDA__)
+#define _DEFAULT_ATTRS __attribute__((device))
+#elif !defined(_DEFAULT_ATTRS)
+#define _DEFAULT_ATTRS
+#endif
+
+#pragma omp begin declare target device_type(nohost)
+#pragma omp begin declare variant match(device = {arch(amdgcn)})
+
+// Type aliases to the address spaces used by the AMDGPU backend.
+#define _Private __attribute__((opencl_private))
+#define _Constant __attribute__((opencl_constant))
+#define _Local __attribute__((opencl_local))
+#define _Global __attribute__((opencl_global))
+
+// Attribute to declare a function as a kernel.
+#define _Kernel __attribute__((amdgpu_kernel, visibility("protected")))
+
+// Returns the number of workgroups in the 'x' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t __gpu_num_blocks_x() {
+  return __builtin_amdgcn_grid_size_x() / __builtin_amdgcn_workgroup_size_x();
+}
+
+// Returns the number of workgroups in the 'y' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t __gpu_num_blocks_y() {
+  return __builtin_amdgcn_grid_size_y() / __builtin_amdgcn_workgroup_size_y();
+}
+
+// Returns the number of workgroups in the 'z' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t __gpu_num_blocks_z() {
+  return __builtin_amdgcn_grid_size_z() / __builtin_amdgcn_workgroup_size_z();
+}
+
+// Returns the 'x' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t __gpu_block_id_x() {
+  return __builtin_amdgcn_workgroup_id_x();
+}
+
+// Returns the 'y' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t __gpu_block_id_y() {
+  return __builtin_amdgcn_workgroup_id_y();
+}
+
+// Returns the 'z' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t __gpu_block_id_z() {
+  return __builtin_amdgcn_workgroup_id_z();
+}
+
+// Returns the number of workitems in the 'x' dimension.
+_DEFAULT_ATTRS sta

[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)

2024-10-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Joseph Huber (jhuber6)


Changes

Summary:
All GPU based languages provide some way to access things like the
thread ID or other resources. However, this is spread between many
different languages and it varies between targets. The goal here is to
provide a resource directory header that just provides these in an
easier to understand way, primarily so this can be used for C/C++ code.
The interface aims to be common, to faciliate easier porting, but target
specific stuff could be put in the individual headers.


---

Patch is 58.27 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/110179.diff


6 Files Affected:

- (modified) clang/lib/Headers/CMakeLists.txt (+14) 
- (added) clang/lib/Headers/amdgpuintrin.h (+153) 
- (added) clang/lib/Headers/gpuintrin.h (+76) 
- (added) clang/lib/Headers/nvptxintrin.h (+153) 
- (added) clang/test/Headers/gpuintrin.c (+508) 
- (added) clang/test/Headers/gpuintrin_lang.c (+61) 


``diff
diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index ff392e7122a448..a0e7ae67b7219a 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -268,6 +268,12 @@ set(x86_files
   cpuid.h
   )
 
+set(gpu_files
+  gpuintrin.h
+  nvptxintrin.h
+  amdgpuintrin.h
+  )
+
 set(windows_only_files
   intrin0.h
   intrin.h
@@ -296,6 +302,7 @@ set(files
   ${systemz_files}
   ${ve_files}
   ${x86_files}
+  ${gpu_files}
   ${webassembly_files}
   ${windows_only_files}
   ${utility_files}
@@ -518,6 +525,7 @@ add_header_target("systemz-resource-headers" 
"${systemz_files};${zos_wrapper_fil
 add_header_target("ve-resource-headers" "${ve_files}")
 add_header_target("webassembly-resource-headers" "${webassembly_files}")
 add_header_target("x86-resource-headers" "${x86_files}")
+add_header_target("gpu-resource-headers" "${gpu_files}")
 
 # Other header groupings
 add_header_target("hlsl-resource-headers" ${hlsl_files})
@@ -704,6 +712,12 @@ install(
   EXCLUDE_FROM_ALL
   COMPONENT x86-resource-headers)
 
+install(
+  FILES ${gpu_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT gpu-resource-headers)
+
 if(NOT CLANG_ENABLE_HLSL)
   set(EXCLUDE_HLSL EXCLUDE_FROM_ALL)
 endif()
diff --git a/clang/lib/Headers/amdgpuintrin.h b/clang/lib/Headers/amdgpuintrin.h
new file mode 100644
index 00..1fd7261cf4ca75
--- /dev/null
+++ b/clang/lib/Headers/amdgpuintrin.h
@@ -0,0 +1,153 @@
+//===-- amdgpuintrin.h - AMDPGU intrinsic functions 
---===//
+//
+// 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
+//
+//===--===//
+
+#ifndef __AMDGPUINTRIN_H
+#define __AMDGPUINTRIN_H
+
+#ifndef __AMDGPU__
+#error "This file is intended for AMDGPU targets or offloading to AMDGPU"
+#endif
+
+#include 
+#include 
+
+#if defined(__HIP__) || defined(__CUDA__)
+#define _DEFAULT_ATTRS __attribute__((device))
+#elif !defined(_DEFAULT_ATTRS)
+#define _DEFAULT_ATTRS
+#endif
+
+#pragma omp begin declare target device_type(nohost)
+#pragma omp begin declare variant match(device = {arch(amdgcn)})
+
+// Type aliases to the address spaces used by the AMDGPU backend.
+#define _Private __attribute__((opencl_private))
+#define _Constant __attribute__((opencl_constant))
+#define _Local __attribute__((opencl_local))
+#define _Global __attribute__((opencl_global))
+
+// Attribute to declare a function as a kernel.
+#define _Kernel __attribute__((amdgpu_kernel, visibility("protected")))
+
+// Returns the number of workgroups in the 'x' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t __gpu_num_blocks_x() {
+  return __builtin_amdgcn_grid_size_x() / __builtin_amdgcn_workgroup_size_x();
+}
+
+// Returns the number of workgroups in the 'y' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t __gpu_num_blocks_y() {
+  return __builtin_amdgcn_grid_size_y() / __builtin_amdgcn_workgroup_size_y();
+}
+
+// Returns the number of workgroups in the 'z' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t __gpu_num_blocks_z() {
+  return __builtin_amdgcn_grid_size_z() / __builtin_amdgcn_workgroup_size_z();
+}
+
+// Returns the 'x' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t __gpu_block_id_x() {
+  return __builtin_amdgcn_workgroup_id_x();
+}
+
+// Returns the 'y' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t __gpu_block_id_y() {
+  return __builtin_amdgcn_workgroup_id_y();
+}
+
+// Returns the 'z' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t __gpu_block_id_z() {
+  return __builtin_amdgcn_workgroup_id_z();
+}
+
+// Returns the number of workitems in the 'x' dimension.
+_DEFAULT_

[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)

2024-10-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Joseph Huber (jhuber6)


Changes

Summary:
All GPU based languages provide some way to access things like the
thread ID or other resources. However, this is spread between many
different languages and it varies between targets. The goal here is to
provide a resource directory header that just provides these in an
easier to understand way, primarily so this can be used for C/C++ code.
The interface aims to be common, to faciliate easier porting, but target
specific stuff could be put in the individual headers.


---

Patch is 58.27 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/110179.diff


6 Files Affected:

- (modified) clang/lib/Headers/CMakeLists.txt (+14) 
- (added) clang/lib/Headers/amdgpuintrin.h (+153) 
- (added) clang/lib/Headers/gpuintrin.h (+76) 
- (added) clang/lib/Headers/nvptxintrin.h (+153) 
- (added) clang/test/Headers/gpuintrin.c (+508) 
- (added) clang/test/Headers/gpuintrin_lang.c (+61) 


``diff
diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index ff392e7122a448..a0e7ae67b7219a 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -268,6 +268,12 @@ set(x86_files
   cpuid.h
   )
 
+set(gpu_files
+  gpuintrin.h
+  nvptxintrin.h
+  amdgpuintrin.h
+  )
+
 set(windows_only_files
   intrin0.h
   intrin.h
@@ -296,6 +302,7 @@ set(files
   ${systemz_files}
   ${ve_files}
   ${x86_files}
+  ${gpu_files}
   ${webassembly_files}
   ${windows_only_files}
   ${utility_files}
@@ -518,6 +525,7 @@ add_header_target("systemz-resource-headers" 
"${systemz_files};${zos_wrapper_fil
 add_header_target("ve-resource-headers" "${ve_files}")
 add_header_target("webassembly-resource-headers" "${webassembly_files}")
 add_header_target("x86-resource-headers" "${x86_files}")
+add_header_target("gpu-resource-headers" "${gpu_files}")
 
 # Other header groupings
 add_header_target("hlsl-resource-headers" ${hlsl_files})
@@ -704,6 +712,12 @@ install(
   EXCLUDE_FROM_ALL
   COMPONENT x86-resource-headers)
 
+install(
+  FILES ${gpu_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT gpu-resource-headers)
+
 if(NOT CLANG_ENABLE_HLSL)
   set(EXCLUDE_HLSL EXCLUDE_FROM_ALL)
 endif()
diff --git a/clang/lib/Headers/amdgpuintrin.h b/clang/lib/Headers/amdgpuintrin.h
new file mode 100644
index 00..1fd7261cf4ca75
--- /dev/null
+++ b/clang/lib/Headers/amdgpuintrin.h
@@ -0,0 +1,153 @@
+//===-- amdgpuintrin.h - AMDPGU intrinsic functions 
---===//
+//
+// 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
+//
+//===--===//
+
+#ifndef __AMDGPUINTRIN_H
+#define __AMDGPUINTRIN_H
+
+#ifndef __AMDGPU__
+#error "This file is intended for AMDGPU targets or offloading to AMDGPU"
+#endif
+
+#include 
+#include 
+
+#if defined(__HIP__) || defined(__CUDA__)
+#define _DEFAULT_ATTRS __attribute__((device))
+#elif !defined(_DEFAULT_ATTRS)
+#define _DEFAULT_ATTRS
+#endif
+
+#pragma omp begin declare target device_type(nohost)
+#pragma omp begin declare variant match(device = {arch(amdgcn)})
+
+// Type aliases to the address spaces used by the AMDGPU backend.
+#define _Private __attribute__((opencl_private))
+#define _Constant __attribute__((opencl_constant))
+#define _Local __attribute__((opencl_local))
+#define _Global __attribute__((opencl_global))
+
+// Attribute to declare a function as a kernel.
+#define _Kernel __attribute__((amdgpu_kernel, visibility("protected")))
+
+// Returns the number of workgroups in the 'x' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t __gpu_num_blocks_x() {
+  return __builtin_amdgcn_grid_size_x() / __builtin_amdgcn_workgroup_size_x();
+}
+
+// Returns the number of workgroups in the 'y' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t __gpu_num_blocks_y() {
+  return __builtin_amdgcn_grid_size_y() / __builtin_amdgcn_workgroup_size_y();
+}
+
+// Returns the number of workgroups in the 'z' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t __gpu_num_blocks_z() {
+  return __builtin_amdgcn_grid_size_z() / __builtin_amdgcn_workgroup_size_z();
+}
+
+// Returns the 'x' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t __gpu_block_id_x() {
+  return __builtin_amdgcn_workgroup_id_x();
+}
+
+// Returns the 'y' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t __gpu_block_id_y() {
+  return __builtin_amdgcn_workgroup_id_y();
+}
+
+// Returns the 'z' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t __gpu_block_id_z() {
+  return __builtin_amdgcn_workgroup_id_z();
+}
+
+// Returns the number of workitems in the 'x' dimension.
+_DEFAULT_ATT

[clang] 8ee7d91 - [clang][MicrosoftCXXABI] Avoid Type::getPointerTo() (NFC) (#110915)

2024-10-03 Thread via cfe-commits

Author: Youngsuk Kim
Date: 2024-10-03T17:06:41-04:00
New Revision: 8ee7d911efb2d3353adcc825e112f55021920846

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

LOG: [clang][MicrosoftCXXABI] Avoid Type::getPointerTo() (NFC) (#110915)

`llvm::Type::getPointerTo()` is to be deprecated & removed soon.

Added: 


Modified: 
clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 79dcdc04b0996f..0b0b45ffead92f 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -518,7 +518,7 @@ class MicrosoftCXXABI : public CGCXXABI {
 CGM.IntTy,
 CGM.IntTy,
 CGM.IntTy,
-
getImageRelativeType(getClassHierarchyDescriptorType()->getPointerTo()),
+getImageRelativeType(CGM.UnqualPtrTy),
 };
 BaseClassDescriptorType = llvm::StructType::create(
 CGM.getLLVMContext(), FieldTypes, "rtti.BaseClassDescriptor");
@@ -531,13 +531,8 @@ class MicrosoftCXXABI : public CGCXXABI {
 // Forward-declare RTTIClassHierarchyDescriptor to break a cycle.
 ClassHierarchyDescriptorType = llvm::StructType::create(
 CGM.getLLVMContext(), "rtti.ClassHierarchyDescriptor");
-llvm::Type *FieldTypes[] = {
-CGM.IntTy,
-CGM.IntTy,
-CGM.IntTy,
-getImageRelativeType(
-getBaseClassDescriptorType()->getPointerTo()->getPointerTo()),
-};
+llvm::Type *FieldTypes[] = {CGM.IntTy, CGM.IntTy, CGM.IntTy,
+getImageRelativeType(CGM.UnqualPtrTy)};
 ClassHierarchyDescriptorType->setBody(FieldTypes);
 return ClassHierarchyDescriptorType;
   }
@@ -552,7 +547,7 @@ class MicrosoftCXXABI : public CGCXXABI {
 CGM.IntTy,
 CGM.IntTy,
 getImageRelativeType(CGM.Int8PtrTy),
-
getImageRelativeType(getClassHierarchyDescriptorType()->getPointerTo()),
+getImageRelativeType(CGM.UnqualPtrTy),
 getImageRelativeType(CompleteObjectLocatorType),
 };
 llvm::ArrayRef FieldTypesRef(FieldTypes);
@@ -749,8 +744,7 @@ class MicrosoftCXXABI : public CGCXXABI {
 
 llvm::SmallString<23> CTATypeName("eh.CatchableTypeArray.");
 CTATypeName += llvm::utostr(NumEntries);
-llvm::Type *CTType =
-getImageRelativeType(getCatchableTypeType()->getPointerTo());
+llvm::Type *CTType = getImageRelativeType(CGM.UnqualPtrTy);
 llvm::Type *FieldTypes[] = {
 CGM.IntTy,   // NumEntries
 llvm::ArrayType::get(CTType, NumEntries) // CatchableTypes
@@ -777,7 +771,7 @@ class MicrosoftCXXABI : public CGCXXABI {
   llvm::FunctionCallee getThrowFn() {
 // _CxxThrowException is passed an exception object and a ThrowInfo object
 // which describes the exception.
-llvm::Type *Args[] = {CGM.Int8PtrTy, getThrowInfoType()->getPointerTo()};
+llvm::Type *Args[] = {CGM.Int8PtrTy, CGM.UnqualPtrTy};
 llvm::FunctionType *FTy =
 llvm::FunctionType::get(CGM.VoidTy, Args, /*isVarArg=*/false);
 llvm::FunctionCallee Throw =
@@ -909,9 +903,8 @@ void 
MicrosoftCXXABI::emitVirtualObjectDelete(CodeGenFunction &CGF,
 }
 
 void MicrosoftCXXABI::emitRethrow(CodeGenFunction &CGF, bool isNoReturn) {
-  llvm::Value *Args[] = {
-  llvm::ConstantPointerNull::get(CGM.Int8PtrTy),
-  llvm::ConstantPointerNull::get(getThrowInfoType()->getPointerTo())};
+  llvm::Value *Args[] = {llvm::ConstantPointerNull::get(CGM.Int8PtrTy),
+ llvm::ConstantPointerNull::get(CGM.UnqualPtrTy)};
   llvm::FunctionCallee Fn = getThrowFn();
   if (isNoReturn)
 CGF.EmitNoreturnRuntimeCallOrInvoke(Fn, Args);
@@ -1958,13 +1951,13 @@ CGCallee 
MicrosoftCXXABI::getVirtualFunctionPointer(CodeGenFunction &CGF,
 SourceLocation Loc) {
   CGBuilderTy &Builder = CGF.Builder;
 
-  Ty = Ty->getPointerTo();
+  Ty = CGF.UnqualPtrTy;
   Address VPtr =
   adjustThisArgumentForVirtualFunctionCall(CGF, GD, This, true);
 
   auto *MethodDecl = cast(GD.getDecl());
-  llvm::Value *VTable = CGF.GetVTablePtr(VPtr, Ty->getPointerTo(),
- MethodDecl->getParent());
+  llvm::Value *VTable =
+  CGF.GetVTablePtr(VPtr, CGF.UnqualPtrTy, MethodDecl->getParent());
 
   MicrosoftVTableContext &VFTContext = CGM.getMicrosoftVTableContext();
   MethodVFTableLocation ML = VFTContext.getMethodVFTableLocation(GD);
@@ -2125,9 +2118,9 @@ MicrosoftCXXABI::EmitVirtualMemPtrThunk(const 
CXXMethodDecl *MD,
 
   // Load the vfptr and then callee from the vftable.  The callee should have
   // adjusted 'this' so that the vfptr is at offset zero.
-  llvm::Type *ThunkPtrTy = ThunkTy->getPointerTo();
-  llvm::Value *VTable =

[clang] [clang] Redeclare function templates instances per primary template (PR #110387)

2024-10-03 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

LGTM once @zyn0217 outstanding comments are resolved.

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


[clang] [clang][MicrosoftCXXABI] Avoid Type::getPointerTo() (NFC) (PR #110915)

2024-10-03 Thread Youngsuk Kim via cfe-commits

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


[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)

2024-10-03 Thread Joseph Huber via cfe-commits


@@ -0,0 +1,187 @@
+//===-- amdgpuintrin.h - AMDPGU intrinsic functions 
---===//
+//
+// 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
+//
+//===--===//
+
+#ifndef __AMDGPUINTRIN_H
+#define __AMDGPUINTRIN_H
+
+#ifndef __AMDGPU__
+#error "This file is intended for AMDGPU targets or offloading to AMDGPU
+#endif
+
+#include 
+#include 
+
+#if defined(__HIP__) || defined(__CUDA__)
+#define _DEFAULT_ATTRS __attribute__((device)) __attribute__((always_inline))
+#else
+#define _DEFAULT_ATTRS __attribute__((always_inline))
+#endif
+
+#pragma omp begin declare target device_type(nohost)
+#pragma omp begin declare variant match(device = {arch(amdgcn)})
+
+// Type aliases to the address spaces used by the AMDGPU backend.
+#define _private __attribute__((opencl_private))
+#define _constant __attribute__((opencl_constant))
+#define _local __attribute__((opencl_local))
+#define _global __attribute__((opencl_global))
+
+// Attribute to declare a function as a kernel.
+#define _kernel __attribute__((amdgpu_kernel, visibility("protected")))
+
+// Returns the number of workgroups in the 'x' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_x() {
+  return __builtin_amdgcn_grid_size_x() / __builtin_amdgcn_workgroup_size_x();
+}
+
+// Returns the number of workgroups in the 'y' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_y() {
+  return __builtin_amdgcn_grid_size_y() / __builtin_amdgcn_workgroup_size_y();
+}
+
+// Returns the number of workgroups in the 'z' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_z() {
+  return __builtin_amdgcn_grid_size_z() / __builtin_amdgcn_workgroup_size_z();
+}
+
+// Returns the total number of workgruops in the grid.
+_DEFAULT_ATTRS static inline uint64_t _get_num_blocks() {
+  return _get_num_blocks_x() * _get_num_blocks_y() * _get_num_blocks_z();
+}
+
+// Returns the 'x' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t _get_block_id_x() {
+  return __builtin_amdgcn_workgroup_id_x();
+}
+
+// Returns the 'y' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t _get_block_id_y() {
+  return __builtin_amdgcn_workgroup_id_y();
+}
+
+// Returns the 'z' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t _get_block_id_z() {
+  return __builtin_amdgcn_workgroup_id_z();
+}
+
+// Returns the absolute id of the AMD workgroup.
+_DEFAULT_ATTRS static inline uint64_t _get_block_id() {
+  return _get_block_id_x() + _get_num_blocks_x() * _get_block_id_y() +
+ _get_num_blocks_x() * _get_num_blocks_y() * _get_block_id_z();
+}
+
+// Returns the number of workitems in the 'x' dimension.
+_DEFAULT_ATTRS static inline uint32_t _get_num_threads_x() {
+  return __builtin_amdgcn_workgroup_size_x();
+}
+
+// Returns the number of workitems in the 'y' dimension.
+_DEFAULT_ATTRS static inline uint32_t _get_num_threads_y() {
+  return __builtin_amdgcn_workgroup_size_y();
+}
+
+// Returns the number of workitems in the 'z' dimension.
+_DEFAULT_ATTRS static inline uint32_t _get_num_threads_z() {
+  return __builtin_amdgcn_workgroup_size_z();
+}
+
+// Returns the total number of workitems in the workgroup.
+_DEFAULT_ATTRS static inline uint64_t _get_num_threads() {
+  return _get_num_threads_x() * _get_num_threads_y() * _get_num_threads_z();
+}
+
+// Returns the 'x' dimension id of the workitem in the current AMD workgroup.
+_DEFAULT_ATTRS static inline uint32_t _get_thread_id_x() {
+  return __builtin_amdgcn_workitem_id_x();
+}
+
+// Returns the 'y' dimension id of the workitem in the current AMD workgroup.
+_DEFAULT_ATTRS static inline uint32_t _get_thread_id_y() {
+  return __builtin_amdgcn_workitem_id_y();
+}
+
+// Returns the 'z' dimension id of the workitem in the current AMD workgroup.
+_DEFAULT_ATTRS static inline uint32_t _get_thread_id_z() {
+  return __builtin_amdgcn_workitem_id_z();
+}
+
+// Returns the absolute id of the thread in the current AMD workgroup.
+_DEFAULT_ATTRS static inline uint64_t _get_thread_id() {
+  return _get_thread_id_x() + _get_num_threads_x() * _get_thread_id_y() +
+ _get_num_threads_x() * _get_num_threads_y() * _get_thread_id_z();
+}
+
+// Returns the size of an AMD wavefront, either 32 or 64 depending on hardware
+// and compilation options.
+_DEFAULT_ATTRS static inline uint32_t _get_lane_size() {
+  return __builtin_amdgcn_wavefrontsize();
+}
+
+// Returns the id of the thread inside of an AMD wavefront executing together.
+_DEFAULT_ATTRS [[clang::convergent]] static inline uint32_t _get_lane_id() {
+  return __builtin_amdgcn_mbcnt_hi(~0u, __builtin_amdgcn_mbcnt_lo(~0u, 0u));
+}
+
+// Returns the bit-mask of active threads in

[clang] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)

2024-10-03 Thread Joseph Huber via cfe-commits


@@ -0,0 +1,184 @@
+//===-- nvptxintrin.h - NVPTX intrinsic functions 
-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef __NVPTXINTRIN_H
+#define __NVPTXINTRIN_H
+
+#ifndef __NVPTX__
+#error "This file is intended for NVPTX targets or offloading to NVPTX
+#endif
+
+#include 
+#include 
+
+#if defined(__HIP__) || defined(__CUDA__)
+#define _DEFAULT_ATTRS __attribute__((device)) __attribute__((always_inline))
+#else
+#define _DEFAULT_ATTRS __attribute__((always_inline))
+#endif
+
+#pragma omp begin declare target device_type(nohost)
+#pragma omp begin declare variant match(device = {arch(nvptx64)})
+
+// Type aliases to the address spaces used by the NVPTX backend.
+#define _private __attribute__((opencl_private))
+#define _constant __attribute__((opencl_constant))
+#define _local __attribute__((opencl_local))
+#define _global __attribute__((opencl_global))
+
+// Attribute to declare a function as a kernel.
+#define _kernel __attribute__((nvptx_kernel))
+
+// Returns the number of CUDA blocks in the 'x' dimension.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_x() {
+  return __nvvm_read_ptx_sreg_nctaid_x();
+}
+
+// Returns the number of CUDA blocks in the 'y' dimension.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_y() {
+  return __nvvm_read_ptx_sreg_nctaid_y();
+}
+
+// Returns the number of CUDA blocks in the 'z' dimension.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_z() {
+  return __nvvm_read_ptx_sreg_nctaid_z();
+}
+
+// Returns the total number of CUDA blocks.
+_DEFAULT_ATTRS static inline uint64_t _get_num_blocks() {
+  return _get_num_blocks_x() * _get_num_blocks_y() * _get_num_blocks_z();
+}
+
+// Returns the 'x' dimension of the current CUDA block's id.
+_DEFAULT_ATTRS static inline uint32_t _get_block_id_x() {
+  return __nvvm_read_ptx_sreg_ctaid_x();
+}
+
+// Returns the 'y' dimension of the current CUDA block's id.
+_DEFAULT_ATTRS static inline uint32_t _get_block_id_y() {
+  return __nvvm_read_ptx_sreg_ctaid_y();
+}
+
+// Returns the 'z' dimension of the current CUDA block's id.
+_DEFAULT_ATTRS static inline uint32_t _get_block_id_z() {
+  return __nvvm_read_ptx_sreg_ctaid_z();
+}
+
+// Returns the absolute id of the CUDA block.
+_DEFAULT_ATTRS static inline uint64_t _get_block_id() {
+  return _get_block_id_x() + _get_num_blocks_x() * _get_block_id_y() +
+ _get_num_blocks_x() * _get_num_blocks_y() * _get_block_id_z();
+}
+
+// Returns the number of CUDA threads in the 'x' dimension.
+_DEFAULT_ATTRS static inline uint32_t _get_num_threads_x() {
+  return __nvvm_read_ptx_sreg_ntid_x();
+}
+
+// Returns the number of CUDA threads in the 'y' dimension.
+_DEFAULT_ATTRS static inline uint32_t _get_num_threads_y() {
+  return __nvvm_read_ptx_sreg_ntid_y();
+}
+
+// Returns the number of CUDA threads in the 'z' dimension.
+_DEFAULT_ATTRS static inline uint32_t _get_num_threads_z() {
+  return __nvvm_read_ptx_sreg_ntid_z();
+}
+
+// Returns the total number of threads in the block.
+_DEFAULT_ATTRS static inline uint64_t _get_num_threads() {
+  return _get_num_threads_x() * _get_num_threads_y() * _get_num_threads_z();
+}
+
+// Returns the 'x' dimension id of the thread in the current CUDA block.
+_DEFAULT_ATTRS static inline uint32_t _get_thread_id_x() {
+  return __nvvm_read_ptx_sreg_tid_x();
+}
+
+// Returns the 'y' dimension id of the thread in the current CUDA block.
+_DEFAULT_ATTRS static inline uint32_t _get_thread_id_y() {
+  return __nvvm_read_ptx_sreg_tid_y();
+}
+
+// Returns the 'z' dimension id of the thread in the current CUDA block.
+_DEFAULT_ATTRS static inline uint32_t _get_thread_id_z() {
+  return __nvvm_read_ptx_sreg_tid_z();
+}
+
+// Returns the absolute id of the thread in the current CUDA block.
+_DEFAULT_ATTRS static inline uint64_t _get_thread_id() {
+  return _get_thread_id_x() + _get_num_threads_x() * _get_thread_id_y() +
+ _get_num_threads_x() * _get_num_threads_y() * _get_thread_id_z();
+}
+
+// Returns the size of a CUDA warp, always 32 on NVIDIA hardware.
+_DEFAULT_ATTRS static inline uint32_t _get_lane_size() { return 32; }
+
+// Returns the id of the thread inside of a CUDA warp executing together.
+_DEFAULT_ATTRS [[clang::convergent]] static inline uint32_t _get_lane_id() {
+  return __nvvm_read_ptx_sreg_laneid();
+}
+
+// Returns the bit-mask of active threads in the current warp.
+_DEFAULT_ATTRS [[clang::convergent]] static inline uint64_t _get_lane_mask() {
+  return __nvvm_activemask();
+}
+
+// Copies the value from the first active thread in the warp to the rest.
+_DEFAULT_ATTRS [[clang::convergent]] static inline uint32_t
+_broadcast_value(uint64_t lane_mask, uint32_t x) {
+  uint32_t mask = static_cast(lane_mask);
+  u

[clang] [Clang] Extend lifetime of temporaries in mem-default-init for P2718R0 (PR #86960)

2024-10-03 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

LGTM
But you need a release note to say that the implementation of P2718R0 is 
complete

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


[clang] [flang] [llvm] [openmp] [flang][driver] rename flang-new to flang (PR #110023)

2024-10-03 Thread Brad Richardson via cfe-commits

https://github.com/everythingfunctional updated 
https://github.com/llvm/llvm-project/pull/110023

>From 649a73478c78389560042030a9717a05e8e338a8 Mon Sep 17 00:00:00 2001
From: Brad Richardson 
Date: Wed, 25 Sep 2024 13:25:22 -0500
Subject: [PATCH 1/4] [flang][driver] rename flang-new to flang

---
 .github/workflows/release-binaries.yml|  2 +-
 clang/include/clang/Driver/Options.td |  4 +-
 clang/lib/Driver/Driver.cpp   |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  6 +-
 clang/test/Driver/flang/flang.f90 |  2 +-
 clang/test/Driver/flang/flang_ucase.F90   |  2 +-
 .../Driver/flang/multiple-inputs-mixed.f90|  2 +-
 clang/test/Driver/flang/multiple-inputs.f90   |  4 +-
 flang/docs/FlangDriver.md | 76 +--
 flang/docs/ImplementingASemanticCheck.md  |  4 +-
 flang/docs/Overview.md| 26 +++
 .../FlangOmpReport/FlangOmpReport.cpp |  2 +-
 .../flang/Optimizer/Analysis/AliasAnalysis.h  |  2 +-
 flang/include/flang/Tools/CrossToolHelpers.h  |  2 +-
 flang/lib/Frontend/CompilerInvocation.cpp |  6 +-
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 .../ExecuteCompilerInvocation.cpp |  3 +-
 flang/runtime/CMakeLists.txt  |  6 +-
 flang/test/CMakeLists.txt |  2 +-
 flang/test/Driver/aarch64-outline-atomics.f90 |  2 +-
 .../Driver/color-diagnostics-forwarding.f90   |  4 +-
 flang/test/Driver/compiler-options.f90|  4 +-
 flang/test/Driver/convert.f90 |  2 +-
 .../test/Driver/disable-ext-name-interop.f90  |  2 +-
 flang/test/Driver/driver-version.f90  |  4 +-
 flang/test/Driver/escaped-backslash.f90   |  4 +-
 flang/test/Driver/fdefault.f90| 28 +++
 flang/test/Driver/flarge-sizes.f90| 20 ++---
 .../test/Driver/frame-pointer-forwarding.f90  |  2 +-
 flang/test/Driver/frontend-forwarding.f90 |  4 +-
 flang/test/Driver/hlfir-no-hlfir-error.f90|  4 +-
 flang/test/Driver/intrinsic-module-path.f90   |  2 +-
 flang/test/Driver/large-data-threshold.f90|  6 +-
 flang/test/Driver/lto-flags.f90   |  2 +-
 flang/test/Driver/macro-def-undef.F90 |  4 +-
 flang/test/Driver/missing-input.f90   | 14 ++--
 flang/test/Driver/multiple-input-files.f90|  2 +-
 flang/test/Driver/omp-driver-offload.f90  | 66 
 .../predefined-macros-compiler-version.F90|  4 +-
 flang/test/Driver/std2018-wrong.f90   |  2 +-
 flang/test/Driver/std2018.f90 |  2 +-
 .../Driver/supported-suffices/f03-suffix.f03  |  2 +-
 .../Driver/supported-suffices/f08-suffix.f08  |  2 +-
 flang/test/Driver/use-module-error.f90|  4 +-
 flang/test/Driver/use-module.f90  |  4 +-
 flang/test/Driver/version-loops.f90   | 18 ++---
 flang/test/Driver/wextra-ok.f90   |  2 +-
 flang/test/HLFIR/hlfir-flags.f90  |  2 +-
 .../Intrinsics/command_argument_count.f90 |  4 +-
 flang/test/Lower/Intrinsics/exit.f90  |  2 +-
 .../test/Lower/Intrinsics/ieee_is_normal.f90  |  2 +-
 flang/test/Lower/Intrinsics/isnan.f90 |  2 +-
 flang/test/Lower/Intrinsics/modulo.f90|  2 +-
 .../OpenMP/Todo/omp-declarative-allocate.f90  |  2 +-
 .../OpenMP/Todo/omp-declare-reduction.f90 |  2 +-
 .../Lower/OpenMP/Todo/omp-declare-simd.f90|  2 +-
 .../parallel-lastprivate-clause-scalar.f90|  2 +-
 .../parallel-wsloop-reduction-byref.f90   |  2 +-
 .../OpenMP/parallel-wsloop-reduction.f90  |  2 +-
 flang/test/lit.cfg.py |  4 +-
 flang/tools/f18/CMakeLists.txt| 10 +--
 flang/tools/flang-driver/CMakeLists.txt   | 12 +--
 flang/tools/flang-driver/driver.cpp   |  6 +-
 llvm/runtimes/CMakeLists.txt  | 10 +--
 offload/CMakeLists.txt|  4 +-
 openmp/CMakeLists.txt |  4 +-
 66 files changed, 220 insertions(+), 227 deletions(-)

diff --git a/.github/workflows/release-binaries.yml 
b/.github/workflows/release-binaries.yml
index 925912df6843e4..6073ebac9e6c2c 100644
--- a/.github/workflows/release-binaries.yml
+++ b/.github/workflows/release-binaries.yml
@@ -328,7 +328,7 @@ jobs:
   run: |
 # Build some of the mlir tools that take a long time to link
 if [ "${{ needs.prepare.outputs.build-flang }}" = "true" ]; then
-  ninja -C ${{ steps.setup-stage.outputs.build-prefix 
}}/build/tools/clang/stage2-bins/ -j2 flang-new bbc
+  ninja -C ${{ steps.setup-stage.outputs.build-prefix 
}}/build/tools/clang/stage2-bins/ -j2 flang bbc
 fi
 ninja -C ${{ steps.setup-stage.outputs.build-prefix 
}}/build/tools/clang/stage2-bins/ \
 mlir-bytecode-parser-fuzzer \
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 932cf13edab53d..4a45a825da8fa1 100644
--- a/clang/include/clang/Drive

[clang] [llvm] [HLSL] Implement `WaveReadLaneAt` intrinsic for spirv backend (PR #111010)

2024-10-03 Thread Finn Plummer via cfe-commits

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


[clang] [libc] [Clang] Implement resource directory headers for common GPU intrinsics (PR #110179)

2024-10-03 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/110179

>From 4a3348e56950583fb28211879f5ab157c34cbc66 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 26 Sep 2024 16:47:14 -0500
Subject: [PATCH 1/4] [Clang] Implement resource directory headers for common
 GPU intrinsics

Summary:
All GPU based languages provide some way to access things like the
thread ID or other resources. However, this is spread between many
different languages and it varies between targets. The goal here is to
provide a resource directory header that just provides these in an
easier to understand way, primarily so this can be used for C/C++ code.
The interface aims to be common, to faciliate easier porting, but target
specific stuff could be put in the individual headers.
---
 clang/lib/Headers/CMakeLists.txt |  14 +++
 clang/lib/Headers/amdgpuintrin.h | 187 +++
 clang/lib/Headers/gpuintrin.h|  18 +++
 clang/lib/Headers/nvptxintrin.h  | 184 ++
 4 files changed, 403 insertions(+)
 create mode 100644 clang/lib/Headers/amdgpuintrin.h
 create mode 100644 clang/lib/Headers/gpuintrin.h
 create mode 100644 clang/lib/Headers/nvptxintrin.h

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index ff392e7122a448..a0e7ae67b7219a 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -268,6 +268,12 @@ set(x86_files
   cpuid.h
   )
 
+set(gpu_files
+  gpuintrin.h
+  nvptxintrin.h
+  amdgpuintrin.h
+  )
+
 set(windows_only_files
   intrin0.h
   intrin.h
@@ -296,6 +302,7 @@ set(files
   ${systemz_files}
   ${ve_files}
   ${x86_files}
+  ${gpu_files}
   ${webassembly_files}
   ${windows_only_files}
   ${utility_files}
@@ -518,6 +525,7 @@ add_header_target("systemz-resource-headers" 
"${systemz_files};${zos_wrapper_fil
 add_header_target("ve-resource-headers" "${ve_files}")
 add_header_target("webassembly-resource-headers" "${webassembly_files}")
 add_header_target("x86-resource-headers" "${x86_files}")
+add_header_target("gpu-resource-headers" "${gpu_files}")
 
 # Other header groupings
 add_header_target("hlsl-resource-headers" ${hlsl_files})
@@ -704,6 +712,12 @@ install(
   EXCLUDE_FROM_ALL
   COMPONENT x86-resource-headers)
 
+install(
+  FILES ${gpu_files}
+  DESTINATION ${header_install_dir}
+  EXCLUDE_FROM_ALL
+  COMPONENT gpu-resource-headers)
+
 if(NOT CLANG_ENABLE_HLSL)
   set(EXCLUDE_HLSL EXCLUDE_FROM_ALL)
 endif()
diff --git a/clang/lib/Headers/amdgpuintrin.h b/clang/lib/Headers/amdgpuintrin.h
new file mode 100644
index 00..95936f86bd15b8
--- /dev/null
+++ b/clang/lib/Headers/amdgpuintrin.h
@@ -0,0 +1,187 @@
+//===-- amdgpuintrin.h - AMDPGU intrinsic functions 
---===//
+//
+// 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
+//
+//===--===//
+
+#ifndef __AMDGPUINTRIN_H
+#define __AMDGPUINTRIN_H
+
+#ifndef __AMDGPU__
+#error "This file is intended for AMDGPU targets or offloading to AMDGPU
+#endif
+
+#include 
+#include 
+
+#if defined(__HIP__) || defined(__CUDA__)
+#define _DEFAULT_ATTRS __attribute__((device)) __attribute__((always_inline))
+#else
+#define _DEFAULT_ATTRS __attribute__((always_inline))
+#endif
+
+#pragma omp begin declare target device_type(nohost)
+#pragma omp begin declare variant match(device = {arch(amdgcn)})
+
+// Type aliases to the address spaces used by the AMDGPU backend.
+#define _private __attribute__((opencl_private))
+#define _constant __attribute__((opencl_constant))
+#define _local __attribute__((opencl_local))
+#define _global __attribute__((opencl_global))
+
+// Attribute to declare a function as a kernel.
+#define _kernel __attribute__((amdgpu_kernel, visibility("protected")))
+
+// Returns the number of workgroups in the 'x' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_x() {
+  return __builtin_amdgcn_grid_size_x() / __builtin_amdgcn_workgroup_size_x();
+}
+
+// Returns the number of workgroups in the 'y' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_y() {
+  return __builtin_amdgcn_grid_size_y() / __builtin_amdgcn_workgroup_size_y();
+}
+
+// Returns the number of workgroups in the 'z' dimension of the grid.
+_DEFAULT_ATTRS static inline uint32_t _get_num_blocks_z() {
+  return __builtin_amdgcn_grid_size_z() / __builtin_amdgcn_workgroup_size_z();
+}
+
+// Returns the total number of workgruops in the grid.
+_DEFAULT_ATTRS static inline uint64_t _get_num_blocks() {
+  return _get_num_blocks_x() * _get_num_blocks_y() * _get_num_blocks_z();
+}
+
+// Returns the 'x' dimension of the current AMD workgroup's id.
+_DEFAULT_ATTRS static inline uint32_t _get_block_id_x() {
+  return __builtin_amdgcn_workgroup_id_x();
+}
+
+// Returns the 'y'

  1   2   3   4   5   >