[clang] [clang]Transform uninstantiated ExceptionSpec in TemplateInstantiator (PR #68878)

2023-10-12 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/68878

>From b93096929aa98e17dfdb0240a9285d315fc95bfc Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 12 Oct 2023 19:31:08 +0800
Subject: [PATCH 1/2] [clang]Transform uninstantiated ExceptionSpec in
 TemplateInstantiator

Fixes #68543, #42496
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  9 -
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 19 +--
 .../dependent-noexcept-uninstantiated.cpp | 11 +++
 4 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/dependent-noexcept-uninstantiated.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..d3612db7957391d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -377,6 +377,8 @@ Bug Fixes in This Version
   cannot be used with ``Release`` mode builds. (`#68237 
`_).
 - Fix crash in evaluating ``constexpr`` value for invalid template function.
   Fixes (`#68542 `_)
+- Clang will correctly evaluate ``noexcept`` expression with template in 
template
+  method of template record.
 
 - Fixed an issue when a shift count larger than ``__INT64_MAX__``, in a right
   shift operation, could result in missing warnings about
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 62fbd903a04044b..2883e650b1ebd94 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3367,7 +3367,14 @@ Sema::TemplateDeductionResult 
Sema::SubstituteExplicitTemplateArguments(
 SmallVector ExceptionStorage;
 if (getLangOpts().CPlusPlus17 &&
 SubstExceptionSpec(Function->getLocation(), EPI.ExceptionSpec,
-   ExceptionStorage, MLTAL))
+   ExceptionStorage,
+   getTemplateInstantiationArgs(
+   FunctionTemplate, /*Final=*/true,
+   /*Innermost=*/SugaredExplicitArgumentList,
+   /*RelativeToPrimary=*/false,
+   /*Pattern=*/nullptr,
+   /*ForConstraintInstantiation=*/false,
+   /*SkipForSpecialization=*/true)))
   return TDK_SubstitutionFailure;
 
 *FunctionType = BuildFunctionType(ResultType, ParamTypes,
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 23de64080a070ca..f28768931cfabf4 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1325,6 +1325,11 @@ namespace {
 /// declaration.
 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation 
Loc);
 
+bool TransformExceptionSpec(SourceLocation Loc,
+FunctionProtoType::ExceptionSpecInfo ,
+SmallVectorImpl ,
+bool );
+
 /// Rebuild the exception declaration and register the declaration
 /// as an instantiated local.
 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
@@ -1607,6 +1612,18 @@ Decl 
*TemplateInstantiator::TransformDefinition(SourceLocation Loc, Decl *D) {
   return Inst;
 }
 
+bool TemplateInstantiator::TransformExceptionSpec(
+SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo ,
+SmallVectorImpl , bool ) {
+  if (ESI.Type == EST_Uninstantiated) {
+ESI.NoexceptExpr = cast(ESI.SourceTemplate->getType())
+   ->getNoexceptExpr();
+ESI.Type = EST_DependentNoexcept;
+Changed = true;
+  }
+  return inherited::TransformExceptionSpec(Loc, ESI, Exceptions, Changed);
+}
+
 NamedDecl *
 TemplateInstantiator::TransformFirstQualifierInScope(NamedDecl *D,
  SourceLocation Loc) {
@@ -2672,8 +2689,6 @@ bool Sema::SubstExceptionSpec(SourceLocation Loc,
   FunctionProtoType::ExceptionSpecInfo ,
   SmallVectorImpl ,
   const MultiLevelTemplateArgumentList ) {
-  assert(ESI.Type != EST_Uninstantiated);
-
   bool Changed = false;
   TemplateInstantiator Instantiator(*this, Args, Loc, DeclarationName());
   return Instantiator.TransformExceptionSpec(Loc, ESI, ExceptionStorage,
diff --git a/clang/test/SemaCXX/dependent-noexcept-uninstantiated.cpp 
b/clang/test/SemaCXX/dependent-noexcept-uninstantiated.cpp
new file mode 100644
index 000..ddb269890227539
--- /dev/null
+++ b/clang/test/SemaCXX/dependent-noexcept-uninstantiated.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 %s
+// expected-no-diagnostics
+
+using A = int;
+using B = char;
+
+template  struct 

[clang] [clang][modules] Use file name as requested (PR #68957)

2023-10-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Jan Svoboda (jansvoboda11)


Changes

This prevents redefinition errors due to having multiple paths for the same 
module map. (rdar://24116019)

Originally implemented and tested downstream by @bcardosolopes, I just 
made use of `FileEntryRef::getNameAsRequested()`.

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


4 Files Affected:

- (modified) clang/lib/Lex/HeaderSearch.cpp (+1-1) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+2-2) 
- (added) clang/test/Modules/Inputs/all-product-headers.yaml (+33) 
- (added) clang/test/Modules/modulemap-collision.m (+15) 


``diff
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 4c8b64a374b47d5..cf1c0cc5284f316 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1623,7 +1623,7 @@ bool HeaderSearch::findUsableModuleForHeader(
 ModuleMap::KnownHeader *SuggestedModule, bool IsSystemHeaderDir) {
   if (needModuleLookup(RequestingModule, SuggestedModule)) {
 // If there is a module that corresponds to this header, suggest it.
-hasModuleMap(File.getName(), Root, IsSystemHeaderDir);
+hasModuleMap(File.getNameAsRequested(), Root, IsSystemHeaderDir);
 return suggestModule(*this, File, RequestingModule, SuggestedModule);
   }
   return true;
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 27700c711d52fdd..0d216927d76260d 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1384,10 +1384,10 @@ void ASTWriter::WriteControlBlock(Preprocessor , 
ASTContext ,
   SmallVector ModMaps(AdditionalModMaps->begin(),
AdditionalModMaps->end());
   llvm::sort(ModMaps, [](FileEntryRef A, FileEntryRef B) {
-return A.getName() < B.getName();
+return A.getNameAsRequested() < B.getNameAsRequested();
   });
   for (FileEntryRef F : ModMaps)
-AddPath(F.getName(), Record);
+AddPath(F.getNameAsRequested(), Record);
 } else {
   Record.push_back(0);
 }
diff --git a/clang/test/Modules/Inputs/all-product-headers.yaml 
b/clang/test/Modules/Inputs/all-product-headers.yaml
new file mode 100644
index 000..53d683f2ad2ecc0
--- /dev/null
+++ b/clang/test/Modules/Inputs/all-product-headers.yaml
@@ -0,0 +1,33 @@
+{
+  'version': 0,
+  'case-sensitive': 'false',
+  'roots': [
+{
+  'type': 'directory',
+  'name': "DUMMY_DIR/build/A.framework/PrivateHeaders"
+  'contents': [
+{
+  'type': 'file',
+  'name': "A.h",
+  'external-contents': "DUMMY_DIR/sources/A.h"
+}
+  ]
+},
+{
+  'type': 'directory',
+  'name': "DUMMY_DIR/build/A.framework/Modules"
+  'contents': [
+{
+  'type': 'file',
+  'name': "module.modulemap",
+  'external-contents': "DUMMY_DIR/build/module.modulemap"
+},
+{
+  'type': 'file',
+  'name': "module.private.modulemap",
+  'external-contents': "DUMMY_DIR/build/module.private.modulemap"
+}
+  ]
+}
+  ]
+}
diff --git a/clang/test/Modules/modulemap-collision.m 
b/clang/test/Modules/modulemap-collision.m
new file mode 100644
index 000..5ada45da3dae191
--- /dev/null
+++ b/clang/test/Modules/modulemap-collision.m
@@ -0,0 +1,15 @@
+// REQUIRES: shell
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/sources %t/build
+// RUN: echo "// A.h" > %t/sources/A.h
+// RUN: echo "framework module A {}" > %t/sources/module.modulemap
+// RUN: echo "framework module A.Private { umbrella header \"A.h\" }" > 
%t/sources/module.private.modulemap
+// RUN: cp %t/sources/module.modulemap %t/build/module.modulemap
+// RUN: cp %t/sources/module.private.modulemap 
%t/build/module.private.modulemap
+
+// RUN: sed -e "s:DUMMY_DIR:%t:g" %S/Inputs/all-product-headers.yaml > 
%t/build/all-product-headers.yaml
+// RUN: %clang_cc1 -fsyntax-only -ivfsoverlay 
%t/build/all-product-headers.yaml -F%t/build -fmodules -fimplicit-module-maps 
-Wno-private-module -fmodules-cache-path=%t/cache -x objective-c %s -verify
+
+// expected-no-diagnostics
+#import 

``




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


[clang] [clang][modules] Use file name as requested (PR #68957)

2023-10-12 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 created 
https://github.com/llvm/llvm-project/pull/68957

This prevents redefinition errors due to having multiple paths for the same 
module map. (rdar://24116019)

Originally implemented and tested downstream by @bcardosolopes, I just made use 
of `FileEntryRef::getNameAsRequested()`.

>From 4f60df88e1623733a64896ef332fd9a31e5b0e47 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Thu, 12 Oct 2023 21:46:47 -0700
Subject: [PATCH] [clang][modules] Use file name as requested

This prevents redefinition errors due to having multiple paths for the same 
module map. (rdar://24116019)

Originally implemented and tested downstream by @bcardosolopes, I just made use 
of `FileEntryRef::getNameAsRequested()`.
---
 clang/lib/Lex/HeaderSearch.cpp|  2 +-
 clang/lib/Serialization/ASTWriter.cpp |  4 +--
 .../Modules/Inputs/all-product-headers.yaml   | 33 +++
 clang/test/Modules/modulemap-collision.m  | 15 +
 4 files changed, 51 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Modules/Inputs/all-product-headers.yaml
 create mode 100644 clang/test/Modules/modulemap-collision.m

diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 4c8b64a374b47d5..cf1c0cc5284f316 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1623,7 +1623,7 @@ bool HeaderSearch::findUsableModuleForHeader(
 ModuleMap::KnownHeader *SuggestedModule, bool IsSystemHeaderDir) {
   if (needModuleLookup(RequestingModule, SuggestedModule)) {
 // If there is a module that corresponds to this header, suggest it.
-hasModuleMap(File.getName(), Root, IsSystemHeaderDir);
+hasModuleMap(File.getNameAsRequested(), Root, IsSystemHeaderDir);
 return suggestModule(*this, File, RequestingModule, SuggestedModule);
   }
   return true;
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 27700c711d52fdd..0d216927d76260d 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1384,10 +1384,10 @@ void ASTWriter::WriteControlBlock(Preprocessor , 
ASTContext ,
   SmallVector ModMaps(AdditionalModMaps->begin(),
AdditionalModMaps->end());
   llvm::sort(ModMaps, [](FileEntryRef A, FileEntryRef B) {
-return A.getName() < B.getName();
+return A.getNameAsRequested() < B.getNameAsRequested();
   });
   for (FileEntryRef F : ModMaps)
-AddPath(F.getName(), Record);
+AddPath(F.getNameAsRequested(), Record);
 } else {
   Record.push_back(0);
 }
diff --git a/clang/test/Modules/Inputs/all-product-headers.yaml 
b/clang/test/Modules/Inputs/all-product-headers.yaml
new file mode 100644
index 000..53d683f2ad2ecc0
--- /dev/null
+++ b/clang/test/Modules/Inputs/all-product-headers.yaml
@@ -0,0 +1,33 @@
+{
+  'version': 0,
+  'case-sensitive': 'false',
+  'roots': [
+{
+  'type': 'directory',
+  'name': "DUMMY_DIR/build/A.framework/PrivateHeaders"
+  'contents': [
+{
+  'type': 'file',
+  'name': "A.h",
+  'external-contents': "DUMMY_DIR/sources/A.h"
+}
+  ]
+},
+{
+  'type': 'directory',
+  'name': "DUMMY_DIR/build/A.framework/Modules"
+  'contents': [
+{
+  'type': 'file',
+  'name': "module.modulemap",
+  'external-contents': "DUMMY_DIR/build/module.modulemap"
+},
+{
+  'type': 'file',
+  'name': "module.private.modulemap",
+  'external-contents': "DUMMY_DIR/build/module.private.modulemap"
+}
+  ]
+}
+  ]
+}
diff --git a/clang/test/Modules/modulemap-collision.m 
b/clang/test/Modules/modulemap-collision.m
new file mode 100644
index 000..5ada45da3dae191
--- /dev/null
+++ b/clang/test/Modules/modulemap-collision.m
@@ -0,0 +1,15 @@
+// REQUIRES: shell
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/sources %t/build
+// RUN: echo "// A.h" > %t/sources/A.h
+// RUN: echo "framework module A {}" > %t/sources/module.modulemap
+// RUN: echo "framework module A.Private { umbrella header \"A.h\" }" > 
%t/sources/module.private.modulemap
+// RUN: cp %t/sources/module.modulemap %t/build/module.modulemap
+// RUN: cp %t/sources/module.private.modulemap 
%t/build/module.private.modulemap
+
+// RUN: sed -e "s:DUMMY_DIR:%t:g" %S/Inputs/all-product-headers.yaml > 
%t/build/all-product-headers.yaml
+// RUN: %clang_cc1 -fsyntax-only -ivfsoverlay 
%t/build/all-product-headers.yaml -F%t/build -fmodules -fimplicit-module-maps 
-Wno-private-module -fmodules-cache-path=%t/cache -x objective-c %s -verify
+
+// expected-no-diagnostics
+#import 

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


[clang] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2023-10-12 Thread Yeting Kuo via cfe-commits

yetingk wrote:

> The patch basically changes the ShadowCallStack back-end to emit an 
> sspush/sspopchk instead of the usual SCS push/pop, which seems like a 
> reasonable approach to me. However, it would be helpful to mention the 
> dependency on `-fsanitize=shadow-call-stack` in the commit message, and you 
> should also update [the 
> documentation](https://clang.llvm.org/docs/ShadowCallStack.html).

Thank you for the reminder. I have updated the document by 
[e32fc6c](https://github.com/llvm/llvm-project/pull/68075/commits/e32fc6cfb624d2ee90dc5b1da2c2e505f9920ac0).

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


[clang] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2023-10-12 Thread Yeting Kuo via cfe-commits

https://github.com/yetingk updated 
https://github.com/llvm/llvm-project/pull/68075

>From 91bb1d9884276a37f93515a648aa6ece353fdc70 Mon Sep 17 00:00:00 2001
From: Yeting Kuo 
Date: Tue, 12 Sep 2023 12:28:00 +0800
Subject: [PATCH 1/4] [RISCV] Add MC layer support for Zicfiss.

The patch adds the instructions in Zicfiss extension. Zicfiss extension is
to support shadow stack for control flow integrity.

Differential Revision: https://reviews.llvm.org/D152793
---
 .../test/Preprocessor/riscv-target-features.c |   9 ++
 llvm/docs/RISCVUsage.rst  |   3 +
 llvm/lib/Support/RISCVISAInfo.cpp |   2 +
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |  29 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|   7 ++
 llvm/lib/Target/RISCV/RISCVInstrInfo.td   |   9 +-
 .../lib/Target/RISCV/RISCVInstrInfoZicfiss.td |  86 +++
 llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp   |   3 +
 llvm/lib/Target/RISCV/RISCVRegisterInfo.td|   9 ++
 llvm/test/MC/RISCV/attribute-arch.s   |   3 +
 llvm/test/MC/RISCV/rv32zicfiss-invalid.s  |  20 
 llvm/test/MC/RISCV/rv32zicfiss-valid.s| 103 ++
 llvm/test/MC/RISCV/rv64zicfiss-invalid.s  |  20 
 llvm/test/MC/RISCV/rv64zicfiss-valid.s| 103 ++
 14 files changed, 402 insertions(+), 4 deletions(-)
 create mode 100644 llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
 create mode 100644 llvm/test/MC/RISCV/rv32zicfiss-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv32zicfiss-valid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zicfiss-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zicfiss-valid.s

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 02b67dc7944ba88..163eba81543ee5b 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -113,6 +113,7 @@
 // CHECK-NOT: __riscv_zfa {{.*$}}
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
+// CHECK-NOT: __riscv_zicfiss {{.*$}}
 // CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_ztso {{.*$}}
 // CHECK-NOT: __riscv_zvbb {{.*$}}
@@ -1220,3 +1221,11 @@
 // RUN: -march=rv64i_zve32x_zvkt1p0 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZVKT-EXT %s
 // CHECK-ZVKT-EXT: __riscv_zvkt 100{{$}}
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32izicfiss0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64izicfiss0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
+// CHECK-ZICFISS-EXT: __riscv_zicfiss 3000{{$}}
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 8d12d58738c609a..31c55def0a7694a 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -205,6 +205,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zicfilp``
   LLVM implements the `0.2 draft specification 
`__.
 
+``experimental-zicfiss``
+  LLVM implements the `0.3.1 draft specification 
`__.
+
 ``experimental-zicond``
   LLVM implements the `1.0-rc1 draft specification 
`__.
 
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index a02c9842e85839a..c414b62c5f31092 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -170,6 +170,8 @@ static const RISCVSupportedExtension 
SupportedExperimentalExtensions[] = {
 {"zfbfmin", RISCVExtensionVersion{0, 8}},
 
 {"zicfilp", RISCVExtensionVersion{0, 2}},
+{"zicfiss", RISCVExtensionVersion{0, 3}},
+
 {"zicond", RISCVExtensionVersion{1, 0}},
 
 {"ztso", RISCVExtensionVersion{0, 1}},
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index d561d90d3088c1a..14b3122f0fecbdb 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -74,6 +74,17 @@ static DecodeStatus DecodeGPRRegisterClass(MCInst , 
uint32_t RegNo,
   return MCDisassembler::Success;
 }
 
+static DecodeStatus DecodeGPRRARegisterClass(MCInst , uint32_t RegNo,
+ uint64_t Address,
+ const MCDisassembler *Decoder) {
+  MCRegister Reg = RISCV::X0 + RegNo;
+  if (Reg != RISCV::X1 && Reg != RISCV::X5)
+return MCDisassembler::Fail;
+
+  Inst.addOperand(MCOperand::createReg(Reg));
+  return MCDisassembler::Success;
+}
+
 static DecodeStatus DecodeFPR16RegisterClass(MCInst , uint32_t RegNo,
   

[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Shengchen Kan via cfe-commits

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

LGTM

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


[clang-tools-extra] [InstCombine] Refactor matchFunnelShift to allow more pattern (NFC) (PR #68474)

2023-10-12 Thread via cfe-commits


@@ -2732,100 +2732,114 @@ static Instruction *matchFunnelShift(Instruction , 
InstCombinerImpl ) {
   // rotate matching code under visitSelect and visitTrunc?
   unsigned Width = Or.getType()->getScalarSizeInBits();
 
-  // First, find an or'd pair of opposite shifts:
-  // or (lshr ShVal0, ShAmt0), (shl ShVal1, ShAmt1)
-  BinaryOperator *Or0, *Or1;
-  if (!match(Or.getOperand(0), m_BinOp(Or0)) ||
-  !match(Or.getOperand(1), m_BinOp(Or1)))
-return nullptr;
-
-  Value *ShVal0, *ShVal1, *ShAmt0, *ShAmt1;
-  if (!match(Or0, m_OneUse(m_LogicalShift(m_Value(ShVal0), m_Value(ShAmt0 
||
-  !match(Or1, m_OneUse(m_LogicalShift(m_Value(ShVal1), m_Value(ShAmt1 
||
-  Or0->getOpcode() == Or1->getOpcode())
+  Instruction *Or0, *Or1;
+  if (!match(Or.getOperand(0), m_Instruction(Or0)) ||
+  !match(Or.getOperand(1), m_Instruction(Or1)))
 return nullptr;
 
-  // Canonicalize to or(shl(ShVal0, ShAmt0), lshr(ShVal1, ShAmt1)).
-  if (Or0->getOpcode() == BinaryOperator::LShr) {
-std::swap(Or0, Or1);
-std::swap(ShVal0, ShVal1);
-std::swap(ShAmt0, ShAmt1);
-  }
-  assert(Or0->getOpcode() == BinaryOperator::Shl &&
- Or1->getOpcode() == BinaryOperator::LShr &&
- "Illegal or(shift,shift) pair");
-
-  // Match the shift amount operands for a funnel shift pattern. This always
-  // matches a subtraction on the R operand.
-  auto matchShiftAmount = [&](Value *L, Value *R, unsigned Width) -> Value * {
-// Check for constant shift amounts that sum to the bitwidth.
-const APInt *LI, *RI;
-if (match(L, m_APIntAllowUndef(LI)) && match(R, m_APIntAllowUndef(RI)))
-  if (LI->ult(Width) && RI->ult(Width) && (*LI + *RI) == Width)
-return ConstantInt::get(L->getType(), *LI);
-
-Constant *LC, *RC;
-if (match(L, m_Constant(LC)) && match(R, m_Constant(RC)) &&
-match(L, m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, APInt(Width, Width))) 
&&
-match(R, m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, APInt(Width, Width))) 
&&
-match(ConstantExpr::getAdd(LC, RC), m_SpecificIntAllowUndef(Width)))
-  return ConstantExpr::mergeUndefsWith(LC, RC);
-
-// (shl ShVal, X) | (lshr ShVal, (Width - x)) iff X < Width.
-// We limit this to X < Width in case the backend re-expands the intrinsic,
-// and has to reintroduce a shift modulo operation (InstCombine might 
remove
-// it after this fold). This still doesn't guarantee that the final codegen
-// will match this original pattern.
-if (match(R, m_OneUse(m_Sub(m_SpecificInt(Width), m_Specific(L) {
-  KnownBits KnownL = IC.computeKnownBits(L, /*Depth*/ 0, );
-  return KnownL.getMaxValue().ult(Width) ? L : nullptr;
-}
+  bool IsFshl = true; // Sub on LSHR.
+  SmallVector FShiftArgs;
 
-// For non-constant cases, the following patterns currently only work for
-// rotation patterns.
-// TODO: Add general funnel-shift compatible patterns.
-if (ShVal0 != ShVal1)
+  // First, find an or'd pair of opposite shifts:
+  // or (lshr ShVal0, ShAmt0), (shl ShVal1, ShAmt1)
+  if (isa(Or0) && isa(Or1)) {

goldsteinn wrote:

What is the rationale for this check? Isn't it covered by the matching of 
logical shifts?

But either way, if it is indeed useful, can you invert it and early return to 
keep nested scopes down.

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


[clang] [InstCombine] Refactor matchFunnelShift to allow more pattern (NFC) (PR #68474)

2023-10-12 Thread via cfe-commits


@@ -2732,100 +2732,114 @@ static Instruction *matchFunnelShift(Instruction , 
InstCombinerImpl ) {
   // rotate matching code under visitSelect and visitTrunc?
   unsigned Width = Or.getType()->getScalarSizeInBits();
 
-  // First, find an or'd pair of opposite shifts:
-  // or (lshr ShVal0, ShAmt0), (shl ShVal1, ShAmt1)
-  BinaryOperator *Or0, *Or1;
-  if (!match(Or.getOperand(0), m_BinOp(Or0)) ||
-  !match(Or.getOperand(1), m_BinOp(Or1)))
-return nullptr;
-
-  Value *ShVal0, *ShVal1, *ShAmt0, *ShAmt1;
-  if (!match(Or0, m_OneUse(m_LogicalShift(m_Value(ShVal0), m_Value(ShAmt0 
||
-  !match(Or1, m_OneUse(m_LogicalShift(m_Value(ShVal1), m_Value(ShAmt1 
||
-  Or0->getOpcode() == Or1->getOpcode())
+  Instruction *Or0, *Or1;
+  if (!match(Or.getOperand(0), m_Instruction(Or0)) ||
+  !match(Or.getOperand(1), m_Instruction(Or1)))
 return nullptr;
 
-  // Canonicalize to or(shl(ShVal0, ShAmt0), lshr(ShVal1, ShAmt1)).
-  if (Or0->getOpcode() == BinaryOperator::LShr) {
-std::swap(Or0, Or1);
-std::swap(ShVal0, ShVal1);
-std::swap(ShAmt0, ShAmt1);
-  }
-  assert(Or0->getOpcode() == BinaryOperator::Shl &&
- Or1->getOpcode() == BinaryOperator::LShr &&
- "Illegal or(shift,shift) pair");
-
-  // Match the shift amount operands for a funnel shift pattern. This always
-  // matches a subtraction on the R operand.
-  auto matchShiftAmount = [&](Value *L, Value *R, unsigned Width) -> Value * {
-// Check for constant shift amounts that sum to the bitwidth.
-const APInt *LI, *RI;
-if (match(L, m_APIntAllowUndef(LI)) && match(R, m_APIntAllowUndef(RI)))
-  if (LI->ult(Width) && RI->ult(Width) && (*LI + *RI) == Width)
-return ConstantInt::get(L->getType(), *LI);
-
-Constant *LC, *RC;
-if (match(L, m_Constant(LC)) && match(R, m_Constant(RC)) &&
-match(L, m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, APInt(Width, Width))) 
&&
-match(R, m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, APInt(Width, Width))) 
&&
-match(ConstantExpr::getAdd(LC, RC), m_SpecificIntAllowUndef(Width)))
-  return ConstantExpr::mergeUndefsWith(LC, RC);
-
-// (shl ShVal, X) | (lshr ShVal, (Width - x)) iff X < Width.
-// We limit this to X < Width in case the backend re-expands the intrinsic,
-// and has to reintroduce a shift modulo operation (InstCombine might 
remove
-// it after this fold). This still doesn't guarantee that the final codegen
-// will match this original pattern.
-if (match(R, m_OneUse(m_Sub(m_SpecificInt(Width), m_Specific(L) {
-  KnownBits KnownL = IC.computeKnownBits(L, /*Depth*/ 0, );
-  return KnownL.getMaxValue().ult(Width) ? L : nullptr;
-}
+  bool IsFshl = true; // Sub on LSHR.
+  SmallVector FShiftArgs;
 
-// For non-constant cases, the following patterns currently only work for
-// rotation patterns.
-// TODO: Add general funnel-shift compatible patterns.
-if (ShVal0 != ShVal1)
+  // First, find an or'd pair of opposite shifts:
+  // or (lshr ShVal0, ShAmt0), (shl ShVal1, ShAmt1)
+  if (isa(Or0) && isa(Or1)) {

goldsteinn wrote:

What is the rationale for this check? Isn't it covered by the matching of 
logical shifts?

But either way, if it is indeed useful, can you invert it and early return to 
keep nested scopes down.

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


[clang] [Clang][LoongArch] Add ABI implementation of passing vectors (PR #68954)

2023-10-12 Thread via cfe-commits

https://github.com/yjijd created https://github.com/llvm/llvm-project/pull/68954

None

>From 74d9ea74aea28db6f5a3a4c6dfccb132d87d1fa8 Mon Sep 17 00:00:00 2001
From: licongtian 
Date: Tue, 10 Oct 2023 15:51:58 +0800
Subject: [PATCH] [Clang][LoongArch] Add ABI implementation of passing vectors

---
 clang/lib/CodeGen/Targets/LoongArch.cpp | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/clang/lib/CodeGen/Targets/LoongArch.cpp 
b/clang/lib/CodeGen/Targets/LoongArch.cpp
index 7483bf6d6d1e8e2..26c68c3583b2a19 100644
--- a/clang/lib/CodeGen/Targets/LoongArch.cpp
+++ b/clang/lib/CodeGen/Targets/LoongArch.cpp
@@ -321,6 +321,13 @@ ABIArgInfo LoongArchABIInfo::classifyArgumentType(QualType 
Ty, bool IsFixed,
 return ABIArgInfo::getDirect();
   }
 
+  // Pass 128-bit/256-bit vector values via vector registers directly.
+  if (Ty->isVectorType() && (((getContext().getTypeSize(Ty) == 128) &&
+  (getTarget().hasFeature("lsx"))) ||
+ ((getContext().getTypeSize(Ty) == 256) &&
+  getTarget().hasFeature("lasx"
+return ABIArgInfo::getDirect();
+
   // Complex types for the *f or *d ABI must be passed directly rather than
   // using CoerceAndExpand.
   if (IsFixed && Ty->isComplexType() && FRLen && FARsLeft >= 2) {

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


[clang] [Clang][LoongArch] Support compiler options -mlsx/-mlasx for clang (PR #68952)

2023-10-12 Thread via cfe-commits

https://github.com/yjijd created https://github.com/llvm/llvm-project/pull/68952

This patch adds compiler options -mlsx/-mlasx which enables the instruction 
sets of LSX and LASX, and sets related predefined macros acording to the 
options.

>From ba3d3560675bcfd84bd11bfed9e26ad86b60faaf Mon Sep 17 00:00:00 2001
From: licongtian 
Date: Wed, 20 Sep 2023 11:21:56 +0800
Subject: [PATCH] [Clang][LoongArch] Support compiler options -mlsx/-mlasx for
 clang

This patch adds compiler options -mlsx/-mlasx which enables the
instruction sets of LSX and LASX, and sets related predefined macros
acording to the options.
---
 .../clang/Basic/DiagnosticDriverKinds.td  |  6 +++
 clang/include/clang/Driver/Options.td | 10 +
 clang/lib/Basic/Targets/LoongArch.cpp | 12 +-
 clang/lib/Basic/Targets/LoongArch.h   |  4 ++
 .../lib/Driver/ToolChains/Arch/LoongArch.cpp  | 32 +++
 clang/test/Driver/loongarch-mlasx-error.c | 15 +++
 clang/test/Driver/loongarch-mlasx.c   | 37 +
 clang/test/Driver/loongarch-mlsx-error.c  | 12 ++
 clang/test/Driver/loongarch-mlsx.c| 41 +++
 clang/test/Preprocessor/init-loongarch.c  | 35 
 10 files changed, 203 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Driver/loongarch-mlasx-error.c
 create mode 100644 clang/test/Driver/loongarch-mlasx.c
 create mode 100644 clang/test/Driver/loongarch-mlsx-error.c
 create mode 100644 clang/test/Driver/loongarch-mlsx.c

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 9c00fa50bb95580..76a26df14d75832 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -756,6 +756,12 @@ def warn_drv_loongarch_conflicting_implied_val : Warning<
   InGroup;
 def err_drv_loongarch_invalid_mfpu_EQ : Error<
   "invalid argument '%0' to -mfpu=; must be one of: 64, 32, none, 0 (alias for 
none)">;
+def err_drv_loongarch_wrong_fpu_width_for_lsx : Error<
+  "wrong fpu width; LSX depends on 64-bit FPU.">;
+def err_drv_loongarch_wrong_fpu_width_for_lasx : Error<
+  "wrong fpu width; LASX depends on 64-bit FPU.">;
+def err_drv_loongarch_invalid_simd_option_combination : Error<
+  "invalid option combination; LASX depends on LSX.">;
 
 def err_drv_expand_response_file : Error<
   "failed to expand response file: %0">;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3f2058a5d4650ca..f747aa31f9d4e1e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -201,6 +201,8 @@ def m_riscv_Features_Group : OptionGroup<"">,
  Group, DocName<"RISC-V">;
 def m_ve_Features_Group : OptionGroup<"">,
   Group, DocName<"VE">;
+def m_loongarch_Features_Group : OptionGroup<"">,
+ Group, DocName<"LoongArch">;
 
 def m_libc_Group : OptionGroup<"">, Group,
Flags<[HelpHidden]>;
@@ -4910,6 +4912,14 @@ def mstack_protector_guard_reg_EQ : Joined<["-"], 
"mstack-protector-guard-reg=">
 def mfentry : Flag<["-"], "mfentry">, HelpText<"Insert calls to fentry at 
function entry (x86/SystemZ only)">,
   Visibility<[ClangOption, CC1Option]>, Group,
   MarshallingInfoFlag>;
+def mlsx : Flag<["-"], "mlsx">, Group,
+  HelpText<"Enable Loongson SIMD Extension (LSX).">;
+def mno_lsx : Flag<["-"], "mno-lsx">, Group,
+  HelpText<"Disable Loongson SIMD Extension (LSX).">;
+def mlasx : Flag<["-"], "mlasx">, Group,
+  HelpText<"Enable Loongson Advanced SIMD Extension (LASX).">;
+def mno_lasx : Flag<["-"], "mno-lasx">, Group,
+  HelpText<"Disable Loongson Advanced SIMD Extension (LASX).">;
 def mnop_mcount : Flag<["-"], "mnop-mcount">, HelpText<"Generate 
mcount/__fentry__ calls as nops. To activate they need to be patched in.">,
   Visibility<[ClangOption, CC1Option]>, Group,
   MarshallingInfoFlag>;
diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index 4448a2ae10a1725..88537989a05129f 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -208,6 +208,11 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions ,
 TuneCPU = ArchName;
   Builder.defineMacro("__loongarch_tune", Twine('"') + TuneCPU + Twine('"'));
 
+  if (HasFeatureLSX)
+Builder.defineMacro("__loongarch_sx", Twine(1));
+  if (HasFeatureLASX)
+Builder.defineMacro("__loongarch_asx", Twine(1));
+
   StringRef ABI = getABI();
   if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
 Builder.defineMacro("__loongarch_lp64");
@@ -257,6 +262,8 @@ bool LoongArchTargetInfo::hasFeature(StringRef Feature) 
const {
   .Case("loongarch64", Is64Bit)
   .Case("32bit", !Is64Bit)
   .Case("64bit", Is64Bit)
+  .Case("lsx", HasFeatureLSX)
+  .Case("lasx", HasFeatureLASX)
   

[clang] [clang][ASTImporter] Fix crash when template class static member imported to other translation unit. (PR #68774)

2023-10-12 Thread Ding Fei via cfe-commits

danix800 wrote:

Caused by missing `MemberSpecializationInfo` when importing so moving testcase 
into `ASTImporterTest` as unittest would be better.

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


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-12 Thread Yueh-Ting Chen via cfe-commits


@@ -0,0 +1,57 @@
+# RUN: llvm-mc -triple=riscv64 -show-encoding 
--mattr=+v,+xsfvqmaccqoq,+xsfvqmaccdod %s \
+# RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv64 -show-encoding %s 2>&1 \
+# RUN:| FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv64 -filetype=obj 
--mattr=+v,+xsfvqmaccqoq,+xsfvqmaccdod %s \
+# RUN:| llvm-objdump -d --mattr=+v,+xsfvqmaccqoq,+xsfvqmaccdod - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv64 -filetype=obj 
--mattr=+v,+xsfvqmaccqoq,+xsfvqmaccdod %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+sf.vqmaccu.2x8x2 v8, v4, v20

eopXD wrote:

>From intuition I would say the motivation to mask a matrix multiplication may 
>not be strong? To split matrixes, tiling are done. So a masked version is 
>probably not needed. (This is my own personal guess though. Not a math library 
>expert here to back this up with experience.

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


[clang] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-12 Thread Louis Dionne via cfe-commits


@@ -642,18 +642,8 @@ get_sanitizer_flags(SANITIZER_FLAGS 
"${LLVM_USE_SANITIZER}")
 
 # Link system libraries ===
 function(cxx_link_system_libraries target)
-
-# In order to remove just libc++ from the link step
-# we need to use -nostdlib++ whenever it is supported.
-# Unfortunately this cannot be used universally because for example g++ 
supports
-# only -nodefaultlibs in which case all libraries will be removed and
-# all libraries but c++ have to be added in manually.
-  if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++")
-  else()
-target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs")
-target_add_compile_flags_if_supported(${target} PRIVATE "/Zl")
-target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib")

ldionne wrote:

@mstorsjo FYI, I checked a recent Clang-CL (DLL) job like 
https://buildkite.com/llvm-project/libcxx-ci/builds/30715#018b257a-9457-4020-a4d0-3d22d4704e25
 and it seems like `/nodefaultlib` and `/Zl` are never detected as supported on 
Windows. Hence, we were never actually enabling those flags.

I'm not certain how the Windows build works without that but it seems like it 
does.

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


[libunwind] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-12 Thread Louis Dionne via cfe-commits


@@ -642,18 +642,8 @@ get_sanitizer_flags(SANITIZER_FLAGS 
"${LLVM_USE_SANITIZER}")
 
 # Link system libraries ===
 function(cxx_link_system_libraries target)
-
-# In order to remove just libc++ from the link step
-# we need to use -nostdlib++ whenever it is supported.
-# Unfortunately this cannot be used universally because for example g++ 
supports
-# only -nodefaultlibs in which case all libraries will be removed and
-# all libraries but c++ have to be added in manually.
-  if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++")
-  else()
-target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs")
-target_add_compile_flags_if_supported(${target} PRIVATE "/Zl")
-target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib")

ldionne wrote:

@mstorsjo FYI, I checked a recent Clang-CL (DLL) job like 
https://buildkite.com/llvm-project/libcxx-ci/builds/30715#018b257a-9457-4020-a4d0-3d22d4704e25
 and it seems like `/nodefaultlib` and `/Zl` are never detected as supported on 
Windows. Hence, we were never actually enabling those flags.

I'm not certain how the Windows build works without that but it seems like it 
does.

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


[clang] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-12 Thread Louis Dionne via cfe-commits

https://github.com/ldionne updated 
https://github.com/llvm/llvm-project/pull/68832

>From 9ca88d1a30ec1bcaa9c3c943c32649c36ad136d0 Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Wed, 11 Oct 2023 12:21:39 -0700
Subject: [PATCH 1/3] [libc++] Use -nostdlib++ on GCC unconditionally

We support GCC 13, which supports the flag. This allows simplifying
the CMake logic around the use of -nostdlib++. Note that there are
other places where we don't assume -nostdlib++ yet in the build, but
this patch is intentionally trying to be small because this part of
our CMake is pretty tricky.
---
 libcxx/CMakeLists.txt| 33 -
 libcxx/cmake/config-ix.cmake | 15 ---
 2 files changed, 4 insertions(+), 44 deletions(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 16540caf68eaf04..55ad0f49cbdb6fd 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -642,18 +642,11 @@ get_sanitizer_flags(SANITIZER_FLAGS 
"${LLVM_USE_SANITIZER}")
 
 # Link system libraries ===
 function(cxx_link_system_libraries target)
-
-# In order to remove just libc++ from the link step
-# we need to use -nostdlib++ whenever it is supported.
-# Unfortunately this cannot be used universally because for example g++ 
supports
-# only -nodefaultlibs in which case all libraries will be removed and
-# all libraries but c++ have to be added in manually.
-  if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++")
+  if (MSVC)
+target_add_compile_flags(${target} PRIVATE "/Zl")
+target_link_libraries(${target} PRIVATE "/nodefaultlib")
   else()
-target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs")
-target_add_compile_flags_if_supported(${target} PRIVATE "/Zl")
-target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib")
+target_link_libraries(${target} PRIVATE "-nostdlib++")
   endif()
 
   if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER)
@@ -663,24 +656,6 @@ function(cxx_link_system_libraries target)
 target_add_link_flags_if_supported(${target} PRIVATE "--unwindlib=none")
   endif()
 
-  if (NOT APPLE) # On Apple platforms, we always use -nostdlib++ so we don't 
need to re-add other libraries
-if (LIBCXX_HAS_PTHREAD_LIB)
-  target_link_libraries(${target} PRIVATE pthread)
-endif()
-
-if (LIBCXX_HAS_C_LIB)
-  target_link_libraries(${target} PRIVATE c)
-endif()
-
-if (LIBCXX_HAS_M_LIB)
-  target_link_libraries(${target} PRIVATE m)
-endif()
-
-if (LIBCXX_HAS_RT_LIB)
-  target_link_libraries(${target} PRIVATE rt)
-endif()
-  endif()
-
   if (LIBCXX_USE_COMPILER_RT)
 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
 if (LIBCXX_BUILTINS_LIBRARY)
diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake
index 9962d848d85e846..9fed861a4e193c5 100644
--- a/libcxx/cmake/config-ix.cmake
+++ b/libcxx/cmake/config-ix.cmake
@@ -14,14 +14,6 @@ include(CheckCSourceCompiles)
 # link with --uwnindlib=none. Check if that option works.
 llvm_check_compiler_linker_flag(C "--unwindlib=none" 
CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
 
-if(WIN32 AND NOT MINGW)
-  # NOTE(compnerd) this is technically a lie, there is msvcrt, but for now, 
lets
-  # let the default linking take care of that.
-  set(LIBCXX_HAS_C_LIB NO)
-else()
-  check_library_exists(c fopen "" LIBCXX_HAS_C_LIB)
-endif()
-
 if (NOT LIBCXX_USE_COMPILER_RT)
   if(WIN32 AND NOT MINGW)
 set(LIBCXX_HAS_GCC_S_LIB NO)
@@ -54,9 +46,6 @@ else()
 endif()
 
 if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
-  if (LIBCXX_HAS_C_LIB)
-list(APPEND CMAKE_REQUIRED_LIBRARIES c)
-  endif ()
   if (LIBCXX_USE_COMPILER_RT)
 include(HandleCompilerRT)
 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY
@@ -108,22 +97,18 @@ if(WIN32 AND NOT MINGW)
   # TODO(compnerd) do we want to support an emulation layer that allows for the
   # use of pthread-win32 or similar libraries to emulate pthreads on Windows?
   set(LIBCXX_HAS_PTHREAD_LIB NO)
-  set(LIBCXX_HAS_M_LIB NO)
   set(LIBCXX_HAS_RT_LIB NO)
   set(LIBCXX_HAS_ATOMIC_LIB NO)
 elseif(APPLE)
   set(LIBCXX_HAS_PTHREAD_LIB NO)
-  set(LIBCXX_HAS_M_LIB NO)
   set(LIBCXX_HAS_RT_LIB NO)
   set(LIBCXX_HAS_ATOMIC_LIB NO)
 elseif(FUCHSIA)
-  set(LIBCXX_HAS_M_LIB NO)
   set(LIBCXX_HAS_PTHREAD_LIB NO)
   set(LIBCXX_HAS_RT_LIB NO)
   check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)
 else()
   check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB)
-  check_library_exists(m ccos "" LIBCXX_HAS_M_LIB)
   check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB)
   check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)
 endif()

>From db65842e8ef437152a59cb72c9b690dd85bc10df Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Thu, 12 Oct 2023 16:20:32 -0700
Subject: [PATCH 

[libunwind] [libc++] Use -nostdlib++ on GCC unconditionally (PR #68832)

2023-10-12 Thread Louis Dionne via cfe-commits

https://github.com/ldionne updated 
https://github.com/llvm/llvm-project/pull/68832

>From 9ca88d1a30ec1bcaa9c3c943c32649c36ad136d0 Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Wed, 11 Oct 2023 12:21:39 -0700
Subject: [PATCH 1/3] [libc++] Use -nostdlib++ on GCC unconditionally

We support GCC 13, which supports the flag. This allows simplifying
the CMake logic around the use of -nostdlib++. Note that there are
other places where we don't assume -nostdlib++ yet in the build, but
this patch is intentionally trying to be small because this part of
our CMake is pretty tricky.
---
 libcxx/CMakeLists.txt| 33 -
 libcxx/cmake/config-ix.cmake | 15 ---
 2 files changed, 4 insertions(+), 44 deletions(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 16540caf68eaf04..55ad0f49cbdb6fd 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -642,18 +642,11 @@ get_sanitizer_flags(SANITIZER_FLAGS 
"${LLVM_USE_SANITIZER}")
 
 # Link system libraries ===
 function(cxx_link_system_libraries target)
-
-# In order to remove just libc++ from the link step
-# we need to use -nostdlib++ whenever it is supported.
-# Unfortunately this cannot be used universally because for example g++ 
supports
-# only -nodefaultlibs in which case all libraries will be removed and
-# all libraries but c++ have to be added in manually.
-  if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
-target_add_link_flags_if_supported(${target} PRIVATE "-nostdlib++")
+  if (MSVC)
+target_add_compile_flags(${target} PRIVATE "/Zl")
+target_link_libraries(${target} PRIVATE "/nodefaultlib")
   else()
-target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs")
-target_add_compile_flags_if_supported(${target} PRIVATE "/Zl")
-target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib")
+target_link_libraries(${target} PRIVATE "-nostdlib++")
   endif()
 
   if (CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER)
@@ -663,24 +656,6 @@ function(cxx_link_system_libraries target)
 target_add_link_flags_if_supported(${target} PRIVATE "--unwindlib=none")
   endif()
 
-  if (NOT APPLE) # On Apple platforms, we always use -nostdlib++ so we don't 
need to re-add other libraries
-if (LIBCXX_HAS_PTHREAD_LIB)
-  target_link_libraries(${target} PRIVATE pthread)
-endif()
-
-if (LIBCXX_HAS_C_LIB)
-  target_link_libraries(${target} PRIVATE c)
-endif()
-
-if (LIBCXX_HAS_M_LIB)
-  target_link_libraries(${target} PRIVATE m)
-endif()
-
-if (LIBCXX_HAS_RT_LIB)
-  target_link_libraries(${target} PRIVATE rt)
-endif()
-  endif()
-
   if (LIBCXX_USE_COMPILER_RT)
 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY)
 if (LIBCXX_BUILTINS_LIBRARY)
diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake
index 9962d848d85e846..9fed861a4e193c5 100644
--- a/libcxx/cmake/config-ix.cmake
+++ b/libcxx/cmake/config-ix.cmake
@@ -14,14 +14,6 @@ include(CheckCSourceCompiles)
 # link with --uwnindlib=none. Check if that option works.
 llvm_check_compiler_linker_flag(C "--unwindlib=none" 
CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG)
 
-if(WIN32 AND NOT MINGW)
-  # NOTE(compnerd) this is technically a lie, there is msvcrt, but for now, 
lets
-  # let the default linking take care of that.
-  set(LIBCXX_HAS_C_LIB NO)
-else()
-  check_library_exists(c fopen "" LIBCXX_HAS_C_LIB)
-endif()
-
 if (NOT LIBCXX_USE_COMPILER_RT)
   if(WIN32 AND NOT MINGW)
 set(LIBCXX_HAS_GCC_S_LIB NO)
@@ -54,9 +46,6 @@ else()
 endif()
 
 if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
-  if (LIBCXX_HAS_C_LIB)
-list(APPEND CMAKE_REQUIRED_LIBRARIES c)
-  endif ()
   if (LIBCXX_USE_COMPILER_RT)
 include(HandleCompilerRT)
 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY
@@ -108,22 +97,18 @@ if(WIN32 AND NOT MINGW)
   # TODO(compnerd) do we want to support an emulation layer that allows for the
   # use of pthread-win32 or similar libraries to emulate pthreads on Windows?
   set(LIBCXX_HAS_PTHREAD_LIB NO)
-  set(LIBCXX_HAS_M_LIB NO)
   set(LIBCXX_HAS_RT_LIB NO)
   set(LIBCXX_HAS_ATOMIC_LIB NO)
 elseif(APPLE)
   set(LIBCXX_HAS_PTHREAD_LIB NO)
-  set(LIBCXX_HAS_M_LIB NO)
   set(LIBCXX_HAS_RT_LIB NO)
   set(LIBCXX_HAS_ATOMIC_LIB NO)
 elseif(FUCHSIA)
-  set(LIBCXX_HAS_M_LIB NO)
   set(LIBCXX_HAS_PTHREAD_LIB NO)
   set(LIBCXX_HAS_RT_LIB NO)
   check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)
 else()
   check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB)
-  check_library_exists(m ccos "" LIBCXX_HAS_M_LIB)
   check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB)
   check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)
 endif()

>From db65842e8ef437152a59cb72c9b690dd85bc10df Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Thu, 12 Oct 2023 16:20:32 -0700
Subject: [PATCH 

[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Freddy Ye via cfe-commits


@@ -20,6 +20,11 @@
 #include 
 #endif
 
+#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+defined(__UINTR__)

FreddyLeaf wrote:

3e32e495d8fa56ad3770769a5d4559ea0a41af96

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


[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Freddy Ye via cfe-commits


@@ -922,8 +922,6 @@ endif()
 
 include(HandleLLVMOptions)
 
-##
-

FreddyLeaf wrote:

3e32e495d8fa56ad3770769a5d4559ea0a41af96

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


[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Freddy Ye via cfe-commits


@@ -241,6 +241,7 @@ X86_FEATURE   (SM3, "sm3")
 X86_FEATURE   (SM4, "sm4")
 X86_FEATURE   (AVXVNNIINT16,"avxvnniint16")
 X86_FEATURE   (EVEX512, "evex512")
+X86_FEATURE   (USERMSR,"usermsr")

FreddyLeaf wrote:

3e32e495d8fa56ad3770769a5d4559ea0a41af96

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


[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Freddy Ye via cfe-commits


@@ -0,0 +1,26 @@
+# RUN: llvm-mc --disassemble %s -triple=x86_64 | FileCheck %s 
--check-prefixes=ATT
+# RUN: llvm-mc --disassemble %s -triple=x86_64 --output-asm-variant=1 | 
FileCheck %s --check-prefixes=INTEL
+
+# ATT:   urdmsr $123, %r9
+# INTEL: urdmsr r9, 123
+0xc4,0xc7,0x7b,0xf8,0xc1,0x7b,0x00,0x00,0x00
+
+# ATT:   urdmsr %r9, %r9
+# INTEL: urdmsr r9, r9
+0xf2,0x45,0x0f,0x38,0xf8,0xc9
+
+# ATT:   urdmsr %r9, %r9
+# INTEL: urdmsr r9, r9
+0xf2,0x4d,0x0f,0x38,0xf8,0xc9

FreddyLeaf wrote:

3e32e495d8fa56ad3770769a5d4559ea0a41af96

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


[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Freddy Ye via cfe-commits


@@ -325,6 +325,8 @@ def FeatureTSXLDTRK : SubtargetFeature<"tsxldtrk", 
"HasTSXLDTRK", "true",
"Support TSXLDTRK instructions">;
 def FeatureUINTR : SubtargetFeature<"uintr", "HasUINTR", "true",
 "Has UINTR Instructions">;
+def FeatureUSERMSR : SubtargetFeature<"usermsr", "HasUSERMSR", "true",
+"Support USERMSR instructions">;

FreddyLeaf wrote:

3e32e495d8fa56ad3770769a5d4559ea0a41af96

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


[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/68944

>From 2377ab2b9865d8f152996fd38f6b543767f8c2ae Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Wed, 11 Oct 2023 14:09:02 +0800
Subject: [PATCH 1/2] Add USER_MSR instructions.

For more details about this instruction, please refer to the latest ISE 
document: 
https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html
---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/include/clang/Basic/BuiltinsX86_64.def  |  3 +
 clang/include/clang/Driver/Options.td |  2 +
 clang/lib/Basic/Targets/X86.cpp   |  6 ++
 clang/lib/Basic/Targets/X86.h |  1 +
 clang/lib/Headers/CMakeLists.txt  |  1 +
 clang/lib/Headers/usermsrintrin.h | 30 +
 clang/lib/Headers/x86gprintrin.h  |  5 ++
 .../CodeGen/X86/usermsr-builtins-error-32.c   | 14 
 clang/test/CodeGen/X86/usermsr-builtins.c | 29 +
 clang/test/Driver/x86-target-features.c   |  5 ++
 clang/test/Preprocessor/x86_target_features.c |  6 ++
 llvm/CMakeLists.txt   |  2 -
 llvm/docs/ReleaseNotes.rst|  1 +
 llvm/include/llvm/IR/IntrinsicsX86.td | 10 ++-
 .../Support/X86DisassemblerDecoderCommon.h|  5 +-
 .../llvm/TargetParser/X86TargetParser.def |  1 +
 .../X86/Disassembler/X86Disassembler.cpp  |  9 +++
 .../X86/Disassembler/X86DisassemblerDecoder.h |  3 +-
 .../lib/Target/X86/MCTargetDesc/X86BaseInfo.h |  3 +-
 .../X86/MCTargetDesc/X86MCCodeEmitter.cpp |  4 ++
 llvm/lib/Target/X86/X86.td|  2 +
 llvm/lib/Target/X86/X86InstrFormats.td|  4 ++
 llvm/lib/Target/X86/X86InstrInfo.td   |  1 +
 llvm/lib/Target/X86/X86InstrSystem.td | 16 +
 llvm/lib/TargetParser/Host.cpp|  1 +
 llvm/lib/TargetParser/X86TargetParser.cpp |  1 +
 llvm/test/CodeGen/X86/usermsr-intrinsics.ll   | 64 +++
 llvm/test/MC/Disassembler/X86/usermsr-64.txt  | 26 
 llvm/test/MC/X86/usermsr-64-att.s | 18 ++
 llvm/test/MC/X86/usermsr-64-intel.s   | 18 ++
 llvm/utils/TableGen/X86DisassemblerTables.cpp |  1 +
 llvm/utils/TableGen/X86DisassemblerTables.h   |  3 +-
 llvm/utils/TableGen/X86RecognizableInstr.cpp  |  1 +
 llvm/utils/TableGen/X86RecognizableInstr.h|  2 +-
 35 files changed, 293 insertions(+), 8 deletions(-)
 create mode 100644 clang/lib/Headers/usermsrintrin.h
 create mode 100644 clang/test/CodeGen/X86/usermsr-builtins-error-32.c
 create mode 100644 clang/test/CodeGen/X86/usermsr-builtins.c
 create mode 100644 llvm/test/CodeGen/X86/usermsr-intrinsics.ll
 create mode 100644 llvm/test/MC/Disassembler/X86/usermsr-64.txt
 create mode 100644 llvm/test/MC/X86/usermsr-64-att.s
 create mode 100644 llvm/test/MC/X86/usermsr-64-intel.s

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 31969201a1cac8c..5300f8458760809 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -538,6 +538,9 @@ X86 Support
 
 - Added option ``-m[no-]evex512`` to disable ZMM and 64-bit mask instructions
   for AVX512 features.
+- Support ISA of ``USER_MSR``.
+  * Support intrinsic of ``_urdmsr``.
+  * Support intrinsic of ``_uwrmsr``.
 
 Arm and AArch64 Support
 ^^^
diff --git a/clang/include/clang/Basic/BuiltinsX86_64.def 
b/clang/include/clang/Basic/BuiltinsX86_64.def
index e5c1fe8b319217e..5e00916d4b25ae3 100644
--- a/clang/include/clang/Basic/BuiltinsX86_64.def
+++ b/clang/include/clang/Basic/BuiltinsX86_64.def
@@ -104,6 +104,9 @@ TARGET_BUILTIN(__builtin_ia32_clui, "v", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_stui, "v", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_testui, "Uc", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_senduipi, "vUWi", "n", "uintr")
+// USERMSR
+TARGET_BUILTIN(__builtin_ia32_urdmsr, "ULLiULLi", "n", "usermsr")
+TARGET_BUILTIN(__builtin_ia32_uwrmsr, "vULLiULLi", "n", "usermsr")
 
 // AMX internal builtin
 TARGET_BUILTIN(__builtin_ia32_tile_loadconfig_internal, "vvC*", "n", 
"amx-tile")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3f2058a5d4650ca..f0ee6eba67374d8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5904,6 +5904,8 @@ def mtsxldtrk : Flag<["-"], "mtsxldtrk">, 
Group;
 def mno_tsxldtrk : Flag<["-"], "mno-tsxldtrk">, Group;
 def muintr : Flag<["-"], "muintr">, Group;
 def mno_uintr : Flag<["-"], "mno-uintr">, Group;
+def musermsr : Flag<["-"], "musermsr">, Group;
+def mno_usermsr : Flag<["-"], "mno-usermsr">, Group;
 def mvaes : Flag<["-"], "mvaes">, Group;
 def mno_vaes : Flag<["-"], "mno-vaes">, Group;
 def mvpclmulqdq : Flag<["-"], "mvpclmulqdq">, Group;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 022d5753135e160..bea5c52a7b8d7c9 100644
--- 

[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Freddy Ye via cfe-commits


@@ -0,0 +1,26 @@
+# RUN: llvm-mc --disassemble %s -triple=x86_64 | FileCheck %s 
--check-prefixes=ATT
+# RUN: llvm-mc --disassemble %s -triple=x86_64 --output-asm-variant=1 | 
FileCheck %s --check-prefixes=INTEL
+
+# ATT:   urdmsr $123, %r9
+# INTEL: urdmsr r9, 123
+0xc4,0xc7,0x7b,0xf8,0xc1,0x7b,0x00,0x00,0x00
+
+# ATT:   urdmsr %r9, %r9
+# INTEL: urdmsr r9, r9
+0xf2,0x45,0x0f,0x38,0xf8,0xc9
+
+# ATT:   urdmsr %r9, %r9
+# INTEL: urdmsr r9, r9
+0xf2,0x4d,0x0f,0x38,0xf8,0xc9

FreddyLeaf wrote:

All legacy Instructions with R64 supported could be judged as "software WIG". 
So this is a WIG instruction, too. Same as below:
```
$ echo "0xf3,0x41,0x0f,0xc7,0xf0" | llvm-mc --disassemble
.text
senduipi%r8
$ echo "0xf3,0x49,0x0f,0xc7,0xf0" | llvm-mc --disassemble
.text
senduipi%r8
```
Will add a comment.

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


[clang] [IRPGO][ValueProfile] Instrument virtual table address that could be used to do virtual table address comparision for indirect-call-promotion. (PR #66825)

2023-10-12 Thread Hongtao Yu via cfe-commits

htyu wrote:


> The performance win depends a lot on value distribution. For large copies, 
> using SIMD with nontemporal hint is the way to go.

Right, and the dominating single-range distribution is also important for our 
approach, similar to how speculative indirect call promotion works.

Recently we have also found out that rep mov started outperforming nontemporal 
SIMD for very large copies, e.g above 1KB.

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


[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Phoebe Wang via cfe-commits


@@ -325,6 +325,8 @@ def FeatureTSXLDTRK : SubtargetFeature<"tsxldtrk", 
"HasTSXLDTRK", "true",
"Support TSXLDTRK instructions">;
 def FeatureUINTR : SubtargetFeature<"uintr", "HasUINTR", "true",
 "Has UINTR Instructions">;
+def FeatureUSERMSR : SubtargetFeature<"usermsr", "HasUSERMSR", "true",
+"Support USERMSR instructions">;

phoebewang wrote:

indent

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


[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Phoebe Wang via cfe-commits


@@ -0,0 +1,26 @@
+# RUN: llvm-mc --disassemble %s -triple=x86_64 | FileCheck %s 
--check-prefixes=ATT
+# RUN: llvm-mc --disassemble %s -triple=x86_64 --output-asm-variant=1 | 
FileCheck %s --check-prefixes=INTEL
+
+# ATT:   urdmsr $123, %r9
+# INTEL: urdmsr r9, 123
+0xc4,0xc7,0x7b,0xf8,0xc1,0x7b,0x00,0x00,0x00
+
+# ATT:   urdmsr %r9, %r9
+# INTEL: urdmsr r9, r9
+0xf2,0x45,0x0f,0x38,0xf8,0xc9
+
+# ATT:   urdmsr %r9, %r9
+# INTEL: urdmsr r9, r9
+0xf2,0x4d,0x0f,0x38,0xf8,0xc9

phoebewang wrote:

Why different encodings decode to the same instruction? Should avoid to use the 
same register?

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


[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Phoebe Wang via cfe-commits


@@ -241,6 +241,7 @@ X86_FEATURE   (SM3, "sm3")
 X86_FEATURE   (SM4, "sm4")
 X86_FEATURE   (AVXVNNIINT16,"avxvnniint16")
 X86_FEATURE   (EVEX512, "evex512")
+X86_FEATURE   (USERMSR,"usermsr")

phoebewang wrote:

Make it aligned above

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


[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Phoebe Wang via cfe-commits


@@ -922,8 +922,6 @@ endif()
 
 include(HandleLLVMOptions)
 
-##
-

phoebewang wrote:

Unrelated change

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


[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Phoebe Wang via cfe-commits


@@ -20,6 +20,11 @@
 #include 
 #endif
 
+#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) ||  
\
+defined(__UINTR__)

phoebewang wrote:

__USERMSR__

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


[clang] [mlir] Add ContractionOpInterface utility functions for vector matrix multiplication (PR #68945)

2023-10-12 Thread via cfe-commits

https://github.com/NatashaKnk created 
https://github.com/llvm/llvm-project/pull/68945

None

>From e431cc466e5609e19757481604dad47558219166 Mon Sep 17 00:00:00 2001
From: Natasha Kononenko 
Date: Fri, 13 Oct 2023 00:48:17 +
Subject: [PATCH 1/2] Add ContractionOpInterface utility functions for vector
 matrix multiplication

---
 .../Dialect/Linalg/IR/LinalgInterfaces.td |  33 +
 .../mlir/Dialect/Utils/StructuredOpsUtils.h   |  18 +++
 mlir/lib/Dialect/Utils/StructuredOpsUtils.cpp |  73 ++
 .../Dialect/Utils/StructuredOpsUtilsTest.cpp  | 130 ++
 4 files changed, 254 insertions(+)

diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td 
b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
index 9ca029b489ad144..e8e9b273cbcf234 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
@@ -86,6 +86,39 @@ def LinalgContractionOpInterface : 
OpInterface<"ContractionOpInterface"> {
 /*methodBody=*/[{
 return mlir::isRowMajorBatchMatmul($_op.getIndexingMaps());
 }]>,
+InterfaceMethod<
+/*desc=*/[{
+  Returns whether the given op has indexing maps that correspond to a
+  vector-matrix multiplication.
+}],
+/*retTy=*/"bool",
+/*methodName=*/"isVecMat",
+/*args=*/(ins),
+/*methodBody=*/[{
+return mlir::isVecMat($_op.getIndexingMaps());
+}]>,
+InterfaceMethod<
+/*desc=*/[{
+  Returns whether the given op has indexing maps that correspond to a
+  matrix-vector multiplication.
+}],
+/*retTy=*/"bool",
+/*methodName=*/"isMatVec",
+/*args=*/(ins),
+/*methodBody=*/[{
+return mlir::isMatVec($_op.getIndexingMaps());
+}]>,
+InterfaceMethod<
+/*desc=*/[{
+  Returns whether the given op has indexing maps that correspond to a
+  batched matrix-vector multiplication.
+}],
+/*retTy=*/"bool",
+/*methodName=*/"isBatchMatVec",
+/*args=*/(ins),
+/*methodBody=*/[{
+return mlir::isBatchMatVec($_op.getIndexingMaps());
+}]>,
   ];
 }
 
diff --git a/mlir/include/mlir/Dialect/Utils/StructuredOpsUtils.h 
b/mlir/include/mlir/Dialect/Utils/StructuredOpsUtils.h
index dab24bd93032692..7bdf260e83ce0be 100644
--- a/mlir/include/mlir/Dialect/Utils/StructuredOpsUtils.h
+++ b/mlir/include/mlir/Dialect/Utils/StructuredOpsUtils.h
@@ -49,6 +49,24 @@ bool isColumnMajorMatmul(ArrayAttr indexingMaps);
 /// the reduction.
 bool isRowMajorBatchMatmul(ArrayAttr indexingMaps);
 
+/// Tests whether the given maps describe a vector matrix multiplication. The
+/// test is permutation-invariant. Note that this only checks the affine maps
+/// from an operation, so does not perform any checks on the math being
+/// performed within the reduction.
+bool isVecMat(ArrayAttr indexingMaps);
+
+/// Tests whether the given maps describe a matrix vector multiplication. The
+/// test is permutation-invariant. Note that this only checks the affine maps
+/// from an operation, so does not perform any checks on the math being
+/// performed within the reduction.
+bool isMatVec(ArrayAttr indexingMaps);
+
+/// Tests whether the given maps describe a batch matrix vector multiplication.
+/// The test is permutation-invariant. Note that this only checks the affine
+/// maps from an operation, so does not perform any checks on the math being
+/// performed within the reduction.
+bool isBatchMatVec(ArrayAttr indexingMaps);
+
 /// Return positions in `iteratorTypes` that match `iteratorTypeName`.
 inline void findPositionsOfType(ArrayRef iteratorTypes,
 utils::IteratorType iteratorTypeName,
diff --git a/mlir/lib/Dialect/Utils/StructuredOpsUtils.cpp 
b/mlir/lib/Dialect/Utils/StructuredOpsUtils.cpp
index a2977901f4751d4..e56be5a062ec6b7 100644
--- a/mlir/lib/Dialect/Utils/StructuredOpsUtils.cpp
+++ b/mlir/lib/Dialect/Utils/StructuredOpsUtils.cpp
@@ -96,6 +96,79 @@ bool mlir::isRowMajorBatchMatmul(ArrayAttr indexingMaps) {
   return indexingMaps == maps;
 }
 
+bool mlir::isVecMat(ArrayAttr indexingMaps) {
+  if (indexingMaps.size() != 3)
+return false;
+  auto map0 = cast(indexingMaps[0]).getValue();
+  auto map1 = cast(indexingMaps[1]).getValue();
+  auto map2 = cast(indexingMaps[2]).getValue();
+
+  if (map0.getNumResults() != 1 || map1.getNumResults() != 2 ||
+  map2.getNumResults() != 1 || map0.getNumInputs() != 2 ||
+  map1.getNumInputs() != 2 || map2.getNumInputs() != 2) {
+return false;
+  }
+
+  // Extract dimensions for K * KxN -> N
+  AffineExpr k = map0.getResult(0);
+  AffineExpr n = map2.getResult(0);
+  auto *context = indexingMaps.getContext();
+  auto mapA = AffineMapAttr::get(AffineMap::get(2, 0, {k}, context));
+  auto mapB = AffineMapAttr::get(AffineMap::get(2, 0, {k, n}, context));
+  auto mapC = AffineMapAttr::get(AffineMap::get(2, 0, {n}, context));
+  auto maps = ArrayAttr::get(context, {mapA, mapB, mapC});
+  return indexingMaps == 

[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 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 a712244f3b76cd2ef60b4f3ce5efaf6d4d49c6fe 
2377ab2b9865d8f152996fd38f6b543767f8c2ae -- clang/lib/Headers/usermsrintrin.h 
clang/test/CodeGen/X86/usermsr-builtins-error-32.c 
clang/test/CodeGen/X86/usermsr-builtins.c clang/lib/Basic/Targets/X86.cpp 
clang/lib/Basic/Targets/X86.h clang/lib/Headers/x86gprintrin.h 
clang/test/Driver/x86-target-features.c 
clang/test/Preprocessor/x86_target_features.c 
llvm/include/llvm/Support/X86DisassemblerDecoderCommon.h 
llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp 
llvm/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h 
llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h 
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp 
llvm/lib/TargetParser/Host.cpp llvm/lib/TargetParser/X86TargetParser.cpp 
llvm/utils/TableGen/X86DisassemblerTables.cpp 
llvm/utils/TableGen/X86DisassemblerTables.h 
llvm/utils/TableGen/X86RecognizableInstr.cpp 
llvm/utils/TableGen/X86RecognizableInstr.h
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/Support/X86DisassemblerDecoderCommon.h 
b/llvm/include/llvm/Support/X86DisassemblerDecoderCommon.h
index 6e08fc6a0..82419fb80 100644
--- a/llvm/include/llvm/Support/X86DisassemblerDecoderCommon.h
+++ b/llvm/include/llvm/Support/X86DisassemblerDecoderCommon.h
@@ -33,7 +33,7 @@ namespace X86Disassembler {
 #define THREEDNOW_MAP_SYM x86Disassembler3DNowOpcodes
 #define MAP5_SYM  x86DisassemblerMap5Opcodes
 #define MAP6_SYM  x86DisassemblerMap6Opcodes
-#define MAP7_SYM  x86DisassemblerMap7Opcodes
+#define MAP7_SYM x86DisassemblerMap7Opcodes
 
 #define INSTRUCTIONS_STR  "x86DisassemblerInstrSpecifiers"
 #define CONTEXTS_STR  "x86DisassemblerContexts"
@@ -47,7 +47,7 @@ namespace X86Disassembler {
 #define THREEDNOW_MAP_STR "x86Disassembler3DNowOpcodes"
 #define MAP5_STR  "x86DisassemblerMap5Opcodes"
 #define MAP6_STR  "x86DisassemblerMap6Opcodes"
-#define MAP7_STR  "x86DisassemblerMap7Opcodes"
+#define MAP7_STR "x86DisassemblerMap7Opcodes"
 
 // Attributes of an instruction that must be known before the opcode can be
 // processed correctly.  Most of these indicate the presence of particular
@@ -289,17 +289,17 @@ enum InstructionContext {
 // Opcode types, which determine which decode table to use, both in the Intel
 // manual and also for the decoder.
 enum OpcodeType {
-  ONEBYTE   = 0,
-  TWOBYTE   = 1,
-  THREEBYTE_38  = 2,
-  THREEBYTE_3A  = 3,
-  XOP8_MAP  = 4,
-  XOP9_MAP  = 5,
-  XOPA_MAP  = 6,
+  ONEBYTE = 0,
+  TWOBYTE = 1,
+  THREEBYTE_38 = 2,
+  THREEBYTE_3A = 3,
+  XOP8_MAP = 4,
+  XOP9_MAP = 5,
+  XOPA_MAP = 6,
   THREEDNOW_MAP = 7,
-  MAP5  = 8,
-  MAP6  = 9,
-  MAP7  = 10
+  MAP5 = 8,
+  MAP6 = 9,
+  MAP7 = 10
 };
 
 // The following structs are used for the hierarchical decode table.  After
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h 
b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
index 1e5a3606f..07eaad70c 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
@@ -584,32 +584,32 @@ namespace X86II {
 // PseudoFrm - This represents an instruction that is a pseudo instruction
 // or one that has not been implemented yet.  It is illegal to code 
generate
 // it, but tolerated for intermediate implementation stages.
-Pseudo = 0,
+Pseudo = 0,
 
 /// Raw - This form is for instructions that don't have any operands, so
 /// they are just a fixed opcode value, like 'leave'.
-RawFrm = 1,
+RawFrm = 1,
 
 /// AddRegFrm - This form is used for instructions like 'push r32' that 
have
 /// their one register operand added to their opcode.
-AddRegFrm  = 2,
+AddRegFrm = 2,
 
 /// RawFrmMemOffs - This form is for instructions that store an absolute
 /// memory offset as an immediate with a possible segment override.
-RawFrmMemOffs  = 3,
+RawFrmMemOffs = 3,
 
 /// RawFrmSrc - This form is for instructions that use the source index
 /// register SI/ESI/RSI with a possible segment override.
-RawFrmSrc  = 4,
+RawFrmSrc = 4,
 
 /// RawFrmDst - This form is for instructions that use the destination 
index
 /// register DI/EDI/RDI.
-RawFrmDst  = 5,
+RawFrmDst = 5,
 
 /// RawFrmDstSrc - This form is for instructions that use the source index
 /// register SI/ESI/RSI with a possible segment override, and also the
 /// destination index register DI/EDI/RDI.
-RawFrmDstSrc   = 6,
+RawFrmDstSrc = 6,
 
 /// RawFrmImm8 - This is used for the ENTER instruction, which has two
 /// immediates, the first of which is a 16-bit immediate (specified by
@@ -630,7 +630,8 @@ namespace X86II {
  

[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Freddy Ye (FreddyLeaf)


Changes

For more details about this instruction, please refer to the latest ISE 
document: 
https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html


---

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


35 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Basic/BuiltinsX86_64.def (+3) 
- (modified) clang/include/clang/Driver/Options.td (+2) 
- (modified) clang/lib/Basic/Targets/X86.cpp (+6) 
- (modified) clang/lib/Basic/Targets/X86.h (+1) 
- (modified) clang/lib/Headers/CMakeLists.txt (+1) 
- (added) clang/lib/Headers/usermsrintrin.h (+30) 
- (modified) clang/lib/Headers/x86gprintrin.h (+5) 
- (added) clang/test/CodeGen/X86/usermsr-builtins-error-32.c (+14) 
- (added) clang/test/CodeGen/X86/usermsr-builtins.c (+29) 
- (modified) clang/test/Driver/x86-target-features.c (+5) 
- (modified) clang/test/Preprocessor/x86_target_features.c (+6) 
- (modified) llvm/CMakeLists.txt (-2) 
- (modified) llvm/docs/ReleaseNotes.rst (+1) 
- (modified) llvm/include/llvm/IR/IntrinsicsX86.td (+9-1) 
- (modified) llvm/include/llvm/Support/X86DisassemblerDecoderCommon.h (+4-1) 
- (modified) llvm/include/llvm/TargetParser/X86TargetParser.def (+1) 
- (modified) llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp (+9) 
- (modified) llvm/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h (+2-1) 
- (modified) llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h (+2-1) 
- (modified) llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp (+4) 
- (modified) llvm/lib/Target/X86/X86.td (+2) 
- (modified) llvm/lib/Target/X86/X86InstrFormats.td (+4) 
- (modified) llvm/lib/Target/X86/X86InstrInfo.td (+1) 
- (modified) llvm/lib/Target/X86/X86InstrSystem.td (+16) 
- (modified) llvm/lib/TargetParser/Host.cpp (+1) 
- (modified) llvm/lib/TargetParser/X86TargetParser.cpp (+1) 
- (added) llvm/test/CodeGen/X86/usermsr-intrinsics.ll (+64) 
- (added) llvm/test/MC/Disassembler/X86/usermsr-64.txt (+26) 
- (added) llvm/test/MC/X86/usermsr-64-att.s (+18) 
- (added) llvm/test/MC/X86/usermsr-64-intel.s (+18) 
- (modified) llvm/utils/TableGen/X86DisassemblerTables.cpp (+1) 
- (modified) llvm/utils/TableGen/X86DisassemblerTables.h (+2-1) 
- (modified) llvm/utils/TableGen/X86RecognizableInstr.cpp (+1) 
- (modified) llvm/utils/TableGen/X86RecognizableInstr.h (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 31969201a1cac8c..5300f8458760809 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -538,6 +538,9 @@ X86 Support
 
 - Added option ``-m[no-]evex512`` to disable ZMM and 64-bit mask instructions
   for AVX512 features.
+- Support ISA of ``USER_MSR``.
+  * Support intrinsic of ``_urdmsr``.
+  * Support intrinsic of ``_uwrmsr``.
 
 Arm and AArch64 Support
 ^^^
diff --git a/clang/include/clang/Basic/BuiltinsX86_64.def 
b/clang/include/clang/Basic/BuiltinsX86_64.def
index e5c1fe8b319217e..5e00916d4b25ae3 100644
--- a/clang/include/clang/Basic/BuiltinsX86_64.def
+++ b/clang/include/clang/Basic/BuiltinsX86_64.def
@@ -104,6 +104,9 @@ TARGET_BUILTIN(__builtin_ia32_clui, "v", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_stui, "v", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_testui, "Uc", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_senduipi, "vUWi", "n", "uintr")
+// USERMSR
+TARGET_BUILTIN(__builtin_ia32_urdmsr, "ULLiULLi", "n", "usermsr")
+TARGET_BUILTIN(__builtin_ia32_uwrmsr, "vULLiULLi", "n", "usermsr")
 
 // AMX internal builtin
 TARGET_BUILTIN(__builtin_ia32_tile_loadconfig_internal, "vvC*", "n", 
"amx-tile")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3f2058a5d4650ca..f0ee6eba67374d8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5904,6 +5904,8 @@ def mtsxldtrk : Flag<["-"], "mtsxldtrk">, 
Group;
 def mno_tsxldtrk : Flag<["-"], "mno-tsxldtrk">, Group;
 def muintr : Flag<["-"], "muintr">, Group;
 def mno_uintr : Flag<["-"], "mno-uintr">, Group;
+def musermsr : Flag<["-"], "musermsr">, Group;
+def mno_usermsr : Flag<["-"], "mno-usermsr">, Group;
 def mvaes : Flag<["-"], "mvaes">, Group;
 def mno_vaes : Flag<["-"], "mno-vaes">, Group;
 def mvpclmulqdq : Flag<["-"], "mvpclmulqdq">, Group;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 022d5753135e160..bea5c52a7b8d7c9 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -376,6 +376,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasTSXLDTRK = true;
 } else if (Feature == "+uintr") {
   HasUINTR = true;
+} else if (Feature == "+usermsr") {
+  HasUSERMSR = true;
 } else if (Feature == "+crc32") {
   HasCRC32 = true;
 } else if 

[clang] [X86] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Freddy Ye via cfe-commits

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


[clang] Add USER_MSR instructions. (PR #68944)

2023-10-12 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf created 
https://github.com/llvm/llvm-project/pull/68944

For more details about this instruction, please refer to the latest ISE 
document: 
https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html


>From 2377ab2b9865d8f152996fd38f6b543767f8c2ae Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Wed, 11 Oct 2023 14:09:02 +0800
Subject: [PATCH] Add USER_MSR instructions.

For more details about this instruction, please refer to the latest ISE 
document: 
https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html
---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/include/clang/Basic/BuiltinsX86_64.def  |  3 +
 clang/include/clang/Driver/Options.td |  2 +
 clang/lib/Basic/Targets/X86.cpp   |  6 ++
 clang/lib/Basic/Targets/X86.h |  1 +
 clang/lib/Headers/CMakeLists.txt  |  1 +
 clang/lib/Headers/usermsrintrin.h | 30 +
 clang/lib/Headers/x86gprintrin.h  |  5 ++
 .../CodeGen/X86/usermsr-builtins-error-32.c   | 14 
 clang/test/CodeGen/X86/usermsr-builtins.c | 29 +
 clang/test/Driver/x86-target-features.c   |  5 ++
 clang/test/Preprocessor/x86_target_features.c |  6 ++
 llvm/CMakeLists.txt   |  2 -
 llvm/docs/ReleaseNotes.rst|  1 +
 llvm/include/llvm/IR/IntrinsicsX86.td | 10 ++-
 .../Support/X86DisassemblerDecoderCommon.h|  5 +-
 .../llvm/TargetParser/X86TargetParser.def |  1 +
 .../X86/Disassembler/X86Disassembler.cpp  |  9 +++
 .../X86/Disassembler/X86DisassemblerDecoder.h |  3 +-
 .../lib/Target/X86/MCTargetDesc/X86BaseInfo.h |  3 +-
 .../X86/MCTargetDesc/X86MCCodeEmitter.cpp |  4 ++
 llvm/lib/Target/X86/X86.td|  2 +
 llvm/lib/Target/X86/X86InstrFormats.td|  4 ++
 llvm/lib/Target/X86/X86InstrInfo.td   |  1 +
 llvm/lib/Target/X86/X86InstrSystem.td | 16 +
 llvm/lib/TargetParser/Host.cpp|  1 +
 llvm/lib/TargetParser/X86TargetParser.cpp |  1 +
 llvm/test/CodeGen/X86/usermsr-intrinsics.ll   | 64 +++
 llvm/test/MC/Disassembler/X86/usermsr-64.txt  | 26 
 llvm/test/MC/X86/usermsr-64-att.s | 18 ++
 llvm/test/MC/X86/usermsr-64-intel.s   | 18 ++
 llvm/utils/TableGen/X86DisassemblerTables.cpp |  1 +
 llvm/utils/TableGen/X86DisassemblerTables.h   |  3 +-
 llvm/utils/TableGen/X86RecognizableInstr.cpp  |  1 +
 llvm/utils/TableGen/X86RecognizableInstr.h|  2 +-
 35 files changed, 293 insertions(+), 8 deletions(-)
 create mode 100644 clang/lib/Headers/usermsrintrin.h
 create mode 100644 clang/test/CodeGen/X86/usermsr-builtins-error-32.c
 create mode 100644 clang/test/CodeGen/X86/usermsr-builtins.c
 create mode 100644 llvm/test/CodeGen/X86/usermsr-intrinsics.ll
 create mode 100644 llvm/test/MC/Disassembler/X86/usermsr-64.txt
 create mode 100644 llvm/test/MC/X86/usermsr-64-att.s
 create mode 100644 llvm/test/MC/X86/usermsr-64-intel.s

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 31969201a1cac8c..5300f8458760809 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -538,6 +538,9 @@ X86 Support
 
 - Added option ``-m[no-]evex512`` to disable ZMM and 64-bit mask instructions
   for AVX512 features.
+- Support ISA of ``USER_MSR``.
+  * Support intrinsic of ``_urdmsr``.
+  * Support intrinsic of ``_uwrmsr``.
 
 Arm and AArch64 Support
 ^^^
diff --git a/clang/include/clang/Basic/BuiltinsX86_64.def 
b/clang/include/clang/Basic/BuiltinsX86_64.def
index e5c1fe8b319217e..5e00916d4b25ae3 100644
--- a/clang/include/clang/Basic/BuiltinsX86_64.def
+++ b/clang/include/clang/Basic/BuiltinsX86_64.def
@@ -104,6 +104,9 @@ TARGET_BUILTIN(__builtin_ia32_clui, "v", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_stui, "v", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_testui, "Uc", "n", "uintr")
 TARGET_BUILTIN(__builtin_ia32_senduipi, "vUWi", "n", "uintr")
+// USERMSR
+TARGET_BUILTIN(__builtin_ia32_urdmsr, "ULLiULLi", "n", "usermsr")
+TARGET_BUILTIN(__builtin_ia32_uwrmsr, "vULLiULLi", "n", "usermsr")
 
 // AMX internal builtin
 TARGET_BUILTIN(__builtin_ia32_tile_loadconfig_internal, "vvC*", "n", 
"amx-tile")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3f2058a5d4650ca..f0ee6eba67374d8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5904,6 +5904,8 @@ def mtsxldtrk : Flag<["-"], "mtsxldtrk">, 
Group;
 def mno_tsxldtrk : Flag<["-"], "mno-tsxldtrk">, Group;
 def muintr : Flag<["-"], "muintr">, Group;
 def mno_uintr : Flag<["-"], "mno-uintr">, Group;
+def musermsr : Flag<["-"], "musermsr">, Group;
+def mno_usermsr : Flag<["-"], "mno-usermsr">, Group;
 def mvaes : Flag<["-"], "mvaes">, Group;
 def mno_vaes : 

[clang] Let clang-cl support CUDA/HIP (PR #68921)

2023-10-12 Thread Artem Belevich via cfe-commits

Artem-B wrote:

@rnk -- would that be acceptable for clang-cl on windows?

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


[clang] [clang][Interp] Only evaluate the source array initialization of an `ArrayInitLoopExpr` once (PR #68039)

2023-10-12 Thread via cfe-commits


@@ -827,6 +829,9 @@ bool ByteCodeExprGen::VisitArrayInitLoopExpr(
 
 template 
 bool ByteCodeExprGen::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
+  if (OpaqueExprs.contains(E))
+return this->emitGetLocal(*classify(E), OpaqueExprs[E], E);

isuckatcs wrote:

Good question, I found this in the test files:

```
`-OpaqueValueExpr {{.*}} 'result_t':'awaitable_frame::result_t' lvalue
   `-MaterializeTemporaryExpr {{.*}} 'result_t':'awaitable_frame::result_t' 
lvalue
  `-...
```
```
struct awaitable_frame {
  ...
  struct result_t {
~result_t();
bool await_ready() const noexcept;
void await_suspend(std::coroutine_handle) noexcept;
void await_resume() const noexcept;
  };
  ...
};
```
Based on this it seems like it can be a composite type, so I'll make sure this 
case is handled too.

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


[clang] [CUDA][HIP] Fix host/device context in concept (PR #67721)

2023-10-12 Thread Richard Smith via cfe-commits


@@ -176,3 +176,34 @@ Predefined Macros
* - ``HIP_API_PER_THREAD_DEFAULT_STREAM``
  - Alias to ``__HIP_API_PER_THREAD_DEFAULT_STREAM__``. Deprecated.
 
+C++20 Concepts with HIP and CUDA
+
+
+In Clang, when working with HIP or CUDA, it's important to note that all 
constraints in C++20 concepts are assumed to be for the host side only. This 
behavior is consistent across both programming models, and developers should be 
aware of this assumption when writing code that utilizes C++20 concepts.
+
+Example:
+.. code-block:: c++
+
+   template 
+   concept MyConcept = requires(T& obj) {
+ my_function(obj);  // Assumed to be a host-side requirement

zygoloid wrote:

If I understand correctly, normally a template is usable from either host or 
device (depending on whether it ends up calling any host-only or device-only 
function). This choice for concepts seems like it's going to be problematic for 
that model. Something as simple as:

```c++
template T f(T x) { return x; }
```

... should really be callable on the host or device side if `T` is copyable on 
the host or device side, and using the host side in all cases will mean that 
things like the C++ `` or `` header may stop doing the 
right thing in some cases if/when they get extended to use concepts. And it 
seems like with this patch there's not anything that the authors of those 
headers can really do about it.

Perhaps it would be better for the host/device choice in a concept satisfaction 
check to depend on the context in which the concept is required to be satisfied 
(which I would imagine is what happened by chance before this patch), and for 
us to include the CUDA context as part of the constraint satisfaction cache 
key? That kind of direction seems like it'd give closer results to what we'd 
get from the split compilation model. I don't know if that actually works in 
general, though. For example, given:

```c++
__host__ X host_global;
__device__ X device_global;
```

... where `X` is a constrained template, what seems like it should happen here 
is that we take the `__host__` / `__device__` into account when 
concept-checking `X`'s template arguments, but I'd worry that we don't have the 
host/device information to hand when checking the concept satisfaction query 
for `X`.

More broadly, I think there'll be cases where a CUDA developer will want, from 
host code, to check whether a constraint would be satisfied on the device, and 
some mechanism for doing that seems useful. I think that *can* be done with the 
model I suggest above, by putting a kernel call inside a `requires` expression, 
but it seems awkward, so perhaps some syntax for explicitly evaluating a 
*concept-id* in a particular host/device would be useful.

But it definitely seems worthwhile to figure out what rule NVCC is using here.

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


[clang] [libc++] Add a CI job for the LLDB data formatters (PR #65174)

2023-10-12 Thread Michael Buch via cfe-commits

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


[clang-tools-extra] [libc++] Add a CI job for the LLDB data formatters (PR #65174)

2023-10-12 Thread Michael Buch via cfe-commits

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


[clang] [libc++] Add a CI job for the LLDB data formatters (PR #65174)

2023-10-12 Thread Michael Buch via cfe-commits


@@ -574,6 +574,20 @@ benchmarks)
 generate-cmake
 check-cxx-benchmarks
 ;;
+check-lldb-data-formatters)
+clean
+${CMAKE}\
+-S "${MONOREPO_ROOT}/llvm"  \
+-B "${BUILD_DIR}"   \
+-GNinja -DCMAKE_MAKE_PROGRAM="${NINJA}" \
+-DCMAKE_BUILD_TYPE=RelWithDebInfo   \
+-DLLVM_ENABLE_ASSERTIONS=ON \
+-DLLDB_ENABLE_PYTHON=ON \
+-DLLVM_ENABLE_PROJECTS='llvm;clang;lldb'\
+-DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi'
+
+${NINJA} -C "${BUILD_DIR}" 
check-lldb-api-functionalities-data-formatter-data-formatter-stl-libcxx

Michael137 wrote:

I think using a "standalone" build of LLDB would make sense here? Correct me if 
I'm wrong @adrian-prantl @JDevlieghere 
Here is how we configure it for the [standalone 
bot](https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake-standalone/): 
https://github.com/llvm/llvm-project/pull/65174#discussion_r1357566522

So if we have a clang build already, we can just point the LLDB build to those 
artifacts as follows:
```
 '-DLLVM_DIR={}'.format(llvm_dir),
 '-DClang_DIR={}'.format(clang_dir),
```

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


[clang] [clang][Interp] Only evaluate the source array initialization of an `ArrayInitLoopExpr` once (PR #68039)

2023-10-12 Thread via cfe-commits


@@ -478,6 +480,43 @@ template  class SourceLocScope final {
   bool Enabled = false;
 };
 
+template  class StoredOpaqueValueScope final {
+public:
+  StoredOpaqueValueScope(ByteCodeExprGen *Ctx) : Ctx(Ctx) {}
+
+  bool VisitAndStoreOpaqueValue(const OpaqueValueExpr *Ove) {
+assert(Ove && "OpaqueValueExpr is a nullptr!");
+assert(!Ctx->OpaqueExprs.contains(Ove) &&
+   "OpaqueValueExpr already stored!");
+
+std::optional CommonTy = Ctx->classify(Ove);
+std::optional LocalIndex = Ctx->allocateLocalPrimitive(
+Ove, *CommonTy, Ove->getType().isConstQualified());
+if (!LocalIndex)
+  return false;
+
+if (!Ctx->visit(Ove))
+  return false;
+
+if (!Ctx->emitSetLocal(*CommonTy, *LocalIndex, Ove))
+  return false;
+
+Ctx->OpaqueExprs.insert({Ove, *LocalIndex});
+StoredValues.emplace_back(Ove);
+
+return true;

isuckatcs wrote:

I wanted to follow the same pattern that other scopes in the same header file 
have, when the functions are defined inside the header, but I'll move this 
definition into the source file as requested.

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


[clang] [clang][Interp] Only evaluate the source array initialization of an `ArrayInitLoopExpr` once (PR #68039)

2023-10-12 Thread via cfe-commits


@@ -478,6 +480,43 @@ template  class SourceLocScope final {
   bool Enabled = false;
 };
 
+template  class StoredOpaqueValueScope final {
+public:
+  StoredOpaqueValueScope(ByteCodeExprGen *Ctx) : Ctx(Ctx) {}
+
+  bool VisitAndStoreOpaqueValue(const OpaqueValueExpr *Ove) {
+assert(Ove && "OpaqueValueExpr is a nullptr!");
+assert(!Ctx->OpaqueExprs.contains(Ove) &&
+   "OpaqueValueExpr already stored!");
+
+std::optional CommonTy = Ctx->classify(Ove);
+std::optional LocalIndex = Ctx->allocateLocalPrimitive(
+Ove, *CommonTy, Ove->getType().isConstQualified());
+if (!LocalIndex)
+  return false;
+
+if (!Ctx->visit(Ove))
+  return false;
+
+if (!Ctx->emitSetLocal(*CommonTy, *LocalIndex, Ove))
+  return false;
+
+Ctx->OpaqueExprs.insert({Ove, *LocalIndex});
+StoredValues.emplace_back(Ove);
+
+return true;
+  }
+
+  ~StoredOpaqueValueScope() {
+for (const auto *SV : StoredValues)
+  Ctx->OpaqueExprs.erase(SV);
+  }
+
+private:
+  ByteCodeExprGen *Ctx;
+  std::vector StoredValues;

isuckatcs wrote:

I kept in mind the scenario, when we might have nested 
`StoredOpaqueValueScope`s. Somehow we need to keep track of which 
`OpaqueValueExpr` should be removed from `Ctx->OpaqueExprs`, when we exit the 
scope.

Do you suggest keeping everything in `Ctx->OpaqueExprs` during the whole 
lifetime of the bytecode generator?

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


[clang] [libc++] Implement ranges::contains (PR #65148)

2023-10-12 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/65148

>From 02e9afd761228f401df4d9f8dfaaca44ffae0c6e Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Thu, 31 Aug 2023 20:08:32 +
Subject: [PATCH 01/12] [libc++] Implement ranges::contains

Differential Revision: https://reviews.llvm.org/D159232
---
 libcxx/include/CMakeLists.txt |   1 +
 libcxx/include/__algorithm/ranges_contains.h  |  60 ++
 libcxx/include/algorithm  |   9 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../alg.contains/ranges.contains.pass.cpp | 190 ++
 .../niebloid.compile.pass.cpp |   1 +
 6 files changed, 265 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 77a7269121ec142..024aa8959fb7200 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains.h 
b/libcxx/include/__algorithm/ranges_contains.h
new file mode 100644
index 000..647b7ea34be3421
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains.h
@@ -0,0 +1,60 @@
+//===--===//
+//
+// 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 _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
+
+#include <__algorithm/in_in_result.h>
+#include <__algorithm/ranges_find.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains {
+struct __fn {
+  template  _Sent, class _Type, 
class _Proj = identity>
+requires indirect_binary_predicate, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = 
{}) const {
+return ranges::find(std::move(__first), std::move(__last), __value, 
std::ref(__proj)) != __last;
+  }
+
+  template 
+requires indirect_binary_predicate, _Proj>, const _Type*>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool
+  operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const {
+return ranges::find(ranges::begin(__range), ranges::end(__range), __value, 
std::ref(__proj)) != ranges::end(__range);
+  }
+};
+} // namespace __contains
+inline namespace __cpo {
+inline constexpr auto contains = __contains::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER >= 23
+
+#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_H
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 76e0d22bf73ef85..003bf132b38b4d8 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -226,6 +226,14 @@ namespace ranges {
   template
 using copy_backward_result = in_out_result;
 // since C++20
 
+  template S, class T, class Proj = identity>
+requires indirect_binary_predicate, 
const T*>
+constexpr bool ranges::contains(I first, S last, const T& value, Proj proj 
= {});   // since C++23
+
+  template
+requires indirect_binary_predicate, Proj>, const T*>
+constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {});
 // since C++23
+
   template S, weakly_incrementable O>
 requires indirectly_copyable
 constexpr ranges::copy_result ranges::copy(I first, S last, O 
result);// since C++20
@@ -1827,6 +1835,7 @@ template 
 #include <__algorithm/ranges_any_of.h>
 #include <__algorithm/ranges_binary_search.h>
 #include <__algorithm/ranges_clamp.h>
+#include <__algorithm/ranges_contains.h>
 #include <__algorithm/ranges_copy.h>
 #include <__algorithm/ranges_copy_backward.h>
 #include <__algorithm/ranges_copy_if.h>
diff --git 

[clang] [libc++] Add a CI job for the LLDB data formatters (PR #65174)

2023-10-12 Thread Louis Dionne via cfe-commits

https://github.com/ldionne updated 
https://github.com/llvm/llvm-project/pull/65174

>From 9ff29c54e97dab71488ffe50ac871f007d357e4f Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Fri, 9 Sep 2022 19:12:18 -0400
Subject: [PATCH 1/2] [libc++] Add a CI job for the LLDB data formatters

This patch adds a CI job running the LLDB data formatters in the libc++
CI. This should avoid breaking the LLDB data formatters when e.g. the
layout of libc++ data structures is changed.

This was originally opened as https://reviews.llvm.org/D133621.
---
 libcxx/utils/ci/buildkite-pipeline.yml | 16 
 libcxx/utils/ci/run-buildbot   | 14 ++
 2 files changed, 30 insertions(+)

diff --git a/libcxx/utils/ci/buildkite-pipeline.yml 
b/libcxx/utils/ci/buildkite-pipeline.yml
index 723ae438619745f..929838cd91ae594 100644
--- a/libcxx/utils/ci/buildkite-pipeline.yml
+++ b/libcxx/utils/ci/buildkite-pipeline.yml
@@ -728,6 +728,22 @@ steps:
   limit: 2
 timeout_in_minutes: 120
 
+  - label: "LLDB Data Formatters"
+command: "libcxx/utils/ci/run-buildbot check-lldb-data-formatters"
+artifact_paths:
+  - "**/test-results.xml"
+env:
+CC: "clang-${LLVM_HEAD_VERSION}"
+CXX: "clang++-${LLVM_HEAD_VERSION}"
+agents:
+  queue: "libcxx-builders"
+  os: "linux"
+retry:
+  automatic:
+- exit_status: -1  # Agent was lost
+  limit: 2
+timeout_in_minutes: 120
+
   # Other non-testing CI jobs
   - label: "Benchmarks"
 command: "libcxx/utils/ci/run-buildbot benchmarks"
diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index fb4c5e1bfcf65be..f7edf436cf6c391 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -574,6 +574,20 @@ benchmarks)
 generate-cmake
 check-cxx-benchmarks
 ;;
+check-lldb-data-formatters)
+clean
+${CMAKE}\
+-S "${MONOREPO_ROOT}/llvm"  \
+-B "${BUILD_DIR}"   \
+-GNinja -DCMAKE_MAKE_PROGRAM="${NINJA}" \
+-DCMAKE_BUILD_TYPE=RelWithDebInfo   \
+-DLLVM_ENABLE_ASSERTIONS=ON \
+-DLLDB_ENABLE_PYTHON=ON \
+-DLLVM_ENABLE_PROJECTS='llvm;clang;lldb'\
+-DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi'
+
+${NINJA} -C "${BUILD_DIR}" 
check-lldb-api-functionalities-data-formatter-data-formatter-stl-libcxx
+;;
 documentation)
 clean
 generate-cmake -DLLVM_ENABLE_SPHINX=ON

>From 63879abeb3d62494b5602c66afcc647674acbe78 Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Thu, 12 Oct 2023 16:50:06 -0700
Subject: [PATCH 2/2] [libc++] Upload artifacts of the Bootstrapping build to
 BK

---
 libcxx/utils/ci/run-buildbot | 4 
 1 file changed, 4 insertions(+)

diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index dd387357f0cd86b..705f6969f44142d 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -367,6 +367,10 @@ bootstrapping-build)
   -DLLVM_ENABLE_ASSERTIONS=ON \
   -DLLVM_LIT_ARGS="-v --show-unsupported --xunit-xml-output 
test-results.xml --timeout=1500 --time-tests"
 
+${NINJA} -vC "${BUILD_DIR}" install-clang install-clang-resource-headers
+tar -cJvf install.tar.xz ${INSTALL_DIR}
+buildkite-agent artifact upload --debug install.tar.xz
+
 echo "+++ Running the libc++ and libc++abi tests"
 ${NINJA} -vC "${BUILD_DIR}" check-runtimes
 

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


[clang-tools-extra] [libc++] Implement ranges::contains (PR #65148)

2023-10-12 Thread via cfe-commits


@@ -0,0 +1,190 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// 
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+// template S, class T, class Proj = 
identity>
+// requires indirect_binary_predicate, const T*>
+// constexpr bool ranges::contains(I first, S last, const T& value, Proj 
proj = {});   // since C++23
+
+// template
+// requires indirect_binary_predicate, Proj>, const T*>
+// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); 
// since C++23
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "almost_satisfies_types.h"
+#include "boolean_testable.h"
+#include "test_iterators.h"
+
+struct NotEqualityComparable {};
+
+template 
+concept HasContainsIt = requires(Iter iter, Sent sent) { 
std::ranges::contains(iter, sent, *iter); };
+
+static_assert(HasContainsIt);
+static_assert(!HasContainsIt);
+static_assert(!HasContainsIt);
+static_assert(!HasContainsIt);
+static_assert(!HasContainsIt);
+static_assert(!HasContainsIt, 
SentinelForNotSemiregular>);
+static_assert(!HasContainsIt, 
InputRangeNotSentinelEqualityComparableWith>);
+
+static_assert(!HasContainsIt);
+static_assert(!HasContainsIt);
+
+template 
+concept HasContainsR = requires(Range range) { std::ranges::contains(range, 
ValT{}); };
+
+static_assert(HasContainsR, int>);
+static_assert(!HasContainsR);
+static_assert(!HasContainsR, 
NotEqualityComparable>);
+static_assert(!HasContainsR);
+static_assert(!HasContainsR);
+static_assert(!HasContainsR);
+static_assert(!HasContainsR);
+static_assert(!HasContainsR);
+
+static std::vector comparable_data;
+
+// clang-format off
+template 
+constexpr void test_iterators() {
+  using ValueT = std::iter_value_t;
+  {  // simple tests
+{
+  ValueT a[] = {1, 2, 3, 4, 5, 6};
+  std::same_as auto ret =
+std::ranges::contains(Iter(a), Sent(Iter(a + 6)), 3);
+  assert(ret);
+}
+{
+  ValueT a[] = {1, 2, 3, 4, 5, 6};
+  auto range = std::ranges::subrange(Iter(a), Sent(Iter(a + 6)));
+  std::same_as decltype(auto) ret =
+std::ranges::contains(range, 3);
+  assert(ret);
+}
+  }
+
+  { // check that an empty range works
+{
+  ValueT a[] = {};
+  auto ret = std::ranges::contains(Iter(a), Sent(Iter(a)), 1);
+  assert(!ret);
+}
+{
+  ValueT a[] = {};
+  auto range = std::ranges::subrange(Iter(a), Sent(Iter(a)));
+  auto ret = std::ranges::contains(range, 1);
+  assert(!ret);
+}
+  }
+
+  { // check that no match
+{
+  ValueT a[] = {13, 1, 21, 4, 5};
+  auto ret = std::ranges::contains(Iter(a), Sent(Iter(a + 5)), 10);
+  assert(!ret);
+}
+{
+  ValueT a[] = {13, 1, 21, 4, 5};
+  auto range = std::ranges::subrange(Iter(a), Sent(Iter(a + 5)));
+  auto ret = std::ranges::contains(range, 10);
+  assert(!ret);
+}
+  }
+
+  if (!std::is_constant_evaluated())
+comparable_data.clear();
+}
+template 
+class TriviallyComparable {

ZijunZhaoCCK wrote:

Sorry for the late reply! Okay! I will do that!

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


[clang] [TSAN] add support for riscv64 (PR #68735)

2023-10-12 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> > The review context is on 
> > [reviews.llvm.org/D145214](https://reviews.llvm.org/D145214) . Moving it 
> > here just causes more confusion.
> > @alexfanqi is the author of the patch and they can drive a reland.
> 
> Can you elaborate what is confusing? The patch was already reviewed and 
> accepted. I'm waiting on the author to reply back but I posted here for it to 
> be tested. @alexfanqi asked me to land the patch last time 
> ([reviews.llvm.org/D145214#4650928](https://reviews.llvm.org/D145214#4650928))

The patch is just a reland of https://reviews.llvm.org/D145214 . AIUI this pull 
request does not add anything on top of that, but the main author of commit 
46cb8d9a325233ac11ed5e90367c43774294d87e is now you with a Co-authored-by: tag 
attributing Alex Fan. That's what you got when you posted the pull request and 
merged the pull request via the web UI, instead of letting Alex Fan post the 
patch here.

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


[clang] [TSAN] add support for riscv64 (PR #68735)

2023-10-12 Thread via cfe-commits

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


[clang] 46cb8d9 - [TSAN] add support for riscv64 (#68735)

2023-10-12 Thread via cfe-commits

Author: AdityaK
Date: 2023-10-12T16:03:07-07:00
New Revision: 46cb8d9a325233ac11ed5e90367c43774294d87e

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

LOG: [TSAN] add support for riscv64 (#68735)

Implements for sv39 and sv48 VMA layout.

Userspace only has access to the bottom half of vma range. The top half
is used by kernel. There is no dedicated vsyscall or heap segment.
PIE program is allocated to start at TASK_SIZE/3*2. Maximum ASLR is
ARCH_MMAP_RND_BITS_MAX+PAGE_SHIFT=24+12=36 Loader, vdso and other
libraries are allocated below stack from the top.

Also change RestoreAddr to use 4 bits to accommodate MappingRiscv64_48

Reviewed by: MaskRay, dvyukov, asb, StephenFan, luismarques, jrtc27,
hiraditya, vitalybuka

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

D145214 was reverted because one file was missing in the latest commit.
Luckily the file was there in the previous commit, probably the author
missed uploading that file with latest commit.

Co-authored-by: Alex Fan 

Added: 
compiler-rt/lib/tsan/rtl/tsan_rtl_riscv64.S

Modified: 
clang/lib/Driver/ToolChains/Linux.cpp
compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
compiler-rt/lib/sanitizer_common/sanitizer_platform.h
compiler-rt/lib/tsan/rtl/CMakeLists.txt
compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
compiler-rt/lib/tsan/rtl/tsan_platform.h
compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
compiler-rt/lib/tsan/rtl/tsan_rtl.h
compiler-rt/test/tsan/map32bit.cpp
compiler-rt/test/tsan/mmap_large.cpp
compiler-rt/test/tsan/test.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 1ba222bf83b1032..735af54f114cef2 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -801,7 +801,7 @@ SanitizerMask Linux::getSupportedSanitizers() const {
   IsRISCV64 || IsSystemZ || IsHexagon || IsLoongArch64)
 Res |= SanitizerKind::Leak;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64 || IsSystemZ ||
-  IsLoongArch64)
+  IsLoongArch64 || IsRISCV64)
 Res |= SanitizerKind::Thread;
   if (IsX86_64 || IsSystemZ)
 Res |= SanitizerKind::KernelMemory;

diff  --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake 
b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index e8ab660c1d83c0c..416777171d2ca75 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -66,7 +66,7 @@ set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} 
${ARM64} ${PPC32} ${PPC
 ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
 ${RISCV32} ${RISCV64} ${LOONGARCH64})
 set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X}
-${LOONGARCH64})
+${LOONGARCH64} ${RISCV64})
 set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
 ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
 ${LOONGARCH64})

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h 
b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
index c1ca5c9ca44783b..5280416f8bd3029 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
@@ -303,7 +303,7 @@
 #define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 
40)
 #  endif
 #elif SANITIZER_RISCV64
-#  define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 38)
+#  define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
 #elif defined(__aarch64__)
 #  if SANITIZER_APPLE
 #if SANITIZER_OSX || SANITIZER_IOSSIM

diff  --git a/compiler-rt/lib/tsan/rtl/CMakeLists.txt 
b/compiler-rt/lib/tsan/rtl/CMakeLists.txt
index 7b18d379e919776..791c0596f65abf7 100644
--- a/compiler-rt/lib/tsan/rtl/CMakeLists.txt
+++ b/compiler-rt/lib/tsan/rtl/CMakeLists.txt
@@ -220,6 +220,10 @@ else()
   set(TSAN_ASM_SOURCES
 tsan_rtl_mips64.S
 )
+elseif(arch MATCHES "riscv64")
+  set(TSAN_ASM_SOURCES
+tsan_rtl_riscv64.S
+)
 elseif(arch MATCHES "s390x")
   set(TSAN_ASM_SOURCES
 tsan_rtl_s390x.S

diff  --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp 
b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
index 5add97ccd17a3ad..80f86ca98ed9cd9 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
@@ -81,6 +81,8 @@ struct ucontext_t {
 #define PTHREAD_ABI_BASE  "GLIBC_2.17"
 #elif SANITIZER_LOONGARCH64
 #define PTHREAD_ABI_BASE  "GLIBC_2.36"
+#elif SANITIZER_RISCV64
+#  define PTHREAD_ABI_BASE "GLIBC_2.27"
 #endif
 
 extern "C" int 

[clang] [Driver] Have -rdynamic be a no-op on Haiku (PR #67872)

2023-10-12 Thread Brad Smith via cfe-commits

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


[clang] 8da1e3d - [Driver] Have -rdynamic be a no-op on Haiku (#67872)

2023-10-12 Thread via cfe-commits

Author: Brad Smith
Date: 2023-10-12T18:05:49-04:00
New Revision: 8da1e3dd24a1cc6bc99bf3334009d2d19f21018f

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

LOG: [Driver] Have -rdynamic be a no-op on Haiku (#67872)

Do the same as the Haiku GCC patches.

https://github.com/haikuports/haikuports/commit/46afdec05771d126eb6cb6c3b3deb957604617c4

Added: 


Modified: 
clang/lib/Driver/ToolChains/Haiku.cpp
clang/test/Driver/haiku.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index 1985fed9cf32a30..c2653a4a2022edf 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -42,6 +42,9 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
   // Silence warning for "clang -pie foo.o -o foo"
   Args.ClaimAllArgs(options::OPT_pie);
 
+  // -rdynamic is a no-op with Haiku. Claim argument to avoid warning.
+  Args.ClaimAllArgs(options::OPT_rdynamic);
+
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
@@ -49,8 +52,6 @@ void haiku::Linker::ConstructJob(Compilation , const 
JobAction ,
   if (Static) {
 CmdArgs.push_back("-Bstatic");
   } else {
-if (Args.hasArg(options::OPT_rdynamic))
-  CmdArgs.push_back("-export-dynamic");
 if (Shared)
   CmdArgs.push_back("-shared");
 CmdArgs.push_back("--enable-new-dtags");

diff  --git a/clang/test/Driver/haiku.c b/clang/test/Driver/haiku.c
index 3888c6732923228..965d3cf97bc36bf 100644
--- a/clang/test/Driver/haiku.c
+++ b/clang/test/Driver/haiku.c
@@ -56,6 +56,11 @@
 // CHECK-LD-X86_64-SAME: {{^}} 
"[[SYSROOT]]/boot/system/develop/tools/lib/gcc/x86_64-unknown-haiku/13.2.0/crtendS.o"
 // CHECK-LD-X86_64-SAME: {{^}} "[[SYSROOT]]/boot/system/develop/lib/crtn.o"
 
+// Check -rdynamic is a no-op
+// RUN: %clang -### -rdynamic %s 2>&1 --target=x86_64-unknown-haiku \
+// RUN:| FileCheck --check-prefix=CHECK-RDYNAMIC %s
+// CHECK-RDYNAMIC-NOT: "-export-dynamic"
+
 // Check the right flags are present with -shared
 // RUN: %clang -### %s -shared 2>&1 --target=x86_64-unknown-haiku \
 // RUN: --gcc-toolchain="" \



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


[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-12 Thread Brad Smith via cfe-commits

brad0 wrote:

> Agreed: AFAICS the only open issue is whether the Solaris test should use the 
> `GNU` label as I have done, introduce an new common one (like `UNIX`; there's 
> nothing GNU-specific in that test), or really introduce a separate copy of 
> the check under a different label per target (my least preference because it 
> makes the test hard to read for no gain).

I think having additional tests makes sense if there is some variation on what 
is being checked but not when it's just copying and pasting the same thing with 
a different label.

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


[clang] [AMDGPU] Change the representation of double literals in operands (PR #68740)

2023-10-12 Thread Stanislav Mekhanoshin via cfe-commits

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


[clang] [clang][Interp] Fix crash during `InterpStack` printing (PR #68246)

2023-10-12 Thread via cfe-commits

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


[clang] 403e0e8 - [clang][Interp] Fix crash during `InterpStack` printing (#68246)

2023-10-12 Thread via cfe-commits

Author: isuckatcs
Date: 2023-10-12T23:26:44+02:00
New Revision: 403e0e8cd95f21d5f94f1e0663c2cfe48e54bf08

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

LOG: [clang][Interp] Fix crash during `InterpStack` printing (#68246)

`InterpStack` is using an `std::vector<>` to track the `ItemTypes`. As a
result, the new types are inserted
to the back of the `std::vector<>`, however `dump()` was reading the
types from the front (the bottom
of the stack) and printing the value on the top of the stack.

This lead to a crash if the type on the bottom had a different type from
the type on the top. E.g.:
```
Items: 2. Size: 40
0/8: 0
1/40: 0x5590cddc0460 {16, 16, 32}
```

The same method also miscalculated the offsets during printing the
stack, which was a source of
incorrect stack dumps and future crashes.

This patch changes the order of iteration of the types and fixes the
offset calculation.

As for testing the change, the issue is that it needs to be done as a
unittest, however from
`clang/unittests` we don't have access to `clang/lib`, where `Interp`
resides. Although the previous
implementation didn't have unittests either, so I'm not sure if we
actually care that much or not.

Added: 


Modified: 
clang/lib/AST/Interp/InterpStack.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpStack.cpp 
b/clang/lib/AST/Interp/InterpStack.cpp
index 18a34079c3b16ae..91fe40feb7671b6 100644
--- a/clang/lib/AST/Interp/InterpStack.cpp
+++ b/clang/lib/AST/Interp/InterpStack.cpp
@@ -86,20 +86,25 @@ void InterpStack::shrink(size_t Size) {
 
 void InterpStack::dump() const {
 #ifndef NDEBUG
-  llvm::errs() << "Items: " << ItemTypes.size() << ". Size: " << size() << 
"\n";
+  llvm::errs() << "Items: " << ItemTypes.size() << ". Size: " << size() << 
'\n';
   if (ItemTypes.empty())
 return;
 
   size_t Index = 0;
-  size_t Offset = align(primSize(ItemTypes[0]));
-  for (PrimType Ty : ItemTypes) {
-llvm::errs() << Index << "/" << Offset << ": ";
-TYPE_SWITCH(Ty, {
+  size_t Offset = 0;
+
+  // The type of the item on the top of the stack is inserted to the back
+  // of the vector, so the iteration has to happen backwards.
+  for (auto TyIt = ItemTypes.rbegin(); TyIt != ItemTypes.rend(); ++TyIt) {
+Offset += align(primSize(*TyIt));
+
+llvm::errs() << Index << '/' << Offset << ": ";
+TYPE_SWITCH(*TyIt, {
   const T  = peek(Offset);
   llvm::errs() << V;
 });
-llvm::errs() << "\n";
-Offset += align(primSize(Ty));
+llvm::errs() << '\n';
+
 ++Index;
   }
 #endif



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


[clang] [clang][Interp] Fix crash during `InterpStack` printing (PR #68246)

2023-10-12 Thread via cfe-commits

isuckatcs wrote:

>it could come in handy in the future

For me it was helpful to check what is on the stack at the moment, so it's 
definitely handy I think.

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


[clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)

2023-10-12 Thread Yusra Syeda via cfe-commits

https://github.com/ysyeda updated 
https://github.com/llvm/llvm-project/pull/68926

>From 5ea8bea2bdf345e2baee07e0a94ac40bd0f109c4 Mon Sep 17 00:00:00 2001
From: Yusra Syeda 
Date: Thu, 12 Oct 2023 16:56:27 -0400
Subject: [PATCH 1/2] This change adds support for the PPA2 section in zOS

---
 clang/include/clang/Basic/LangStandard.h  |   1 +
 clang/lib/Basic/LangStandards.cpp |  39 
 clang/lib/CodeGen/CodeGenModule.cpp   |  15 ++
 clang/lib/Driver/ToolChains/Clang.cpp |  13 +-
 clang/lib/Driver/ToolChains/Clang.h   |   3 +-
 clang/test/CodeGen/SystemZ/systemz-ppa2.c |  25 +++
 llvm/include/llvm/BinaryFormat/GOFF.h |   1 +
 llvm/include/llvm/MC/MCObjectFileInfo.h   |   4 +
 llvm/lib/MC/MCObjectFileInfo.cpp  |   5 +
 llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp | 197 +-
 llvm/lib/Target/SystemZ/SystemZAsmPrinter.h   |   7 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |  26 +++
 12 files changed, 331 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/SystemZ/systemz-ppa2.c
 create mode 100644 llvm/test/CodeGen/SystemZ/zos-ppa2.ll

diff --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index 6356f16acc811e0..d94567adf2bfb99 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -43,6 +43,7 @@ enum class Language : uint8_t {
   HLSL,
   ///@}
 };
+const char *LanguageToString(Language L);
 
 enum LangFeatures {
   LineComment = (1 << 0),
diff --git a/clang/lib/Basic/LangStandards.cpp 
b/clang/lib/Basic/LangStandards.cpp
index af9cf4f273920ee..e9b75d78e820a64 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -10,9 +10,48 @@
 #include "clang/Config/config.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/TargetParser/Triple.h"
 using namespace clang;
 
+const char *clang::LanguageToString(Language L) {
+  // I would like to make this function and the definition of Language
+  // in the .h file simply expand the contents of a .def file.
+  // However, in the .h the members of the enum have doxygen annotations
+  // and/or comments which would be lost.
+  switch (L) {
+  case Language::Unknown:
+return "Unknown";
+  case Language::Asm:
+return "Asm";
+  case Language::LLVM_IR:
+return "LLVM_IR";
+  case Language::C:
+return "C";
+  case Language::CXX:
+return "CXX";
+  case Language::ObjC:
+return "ObjC";
+  case Language::ObjCXX:
+return "ObjCXX";
+  case Language::OpenCL:
+return "OpenCL";
+  case Language::OpenCLCXX:
+return "OpenCLCXX";
+  case Language::CUDA:
+return "CUDA";
+  case Language::RenderScript:
+return "RenderScript";
+  case Language::HIP:
+return "HIP";
+  case Language::HLSL:
+return "HLSL";
+  }
+
+  std::string msg = llvm::formatv("Unknown value ({0}) passed to 
LanguageToString", (unsigned int) L);
+  llvm_unreachable(msg.c_str());
+}
+
 #define LANGSTANDARD(id, name, lang, desc, features)   
\
   static const LangStandard Lang_##id = {name, desc, features, Language::lang};
 #include "clang/Basic/LangStandards.def"
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 754377bed7f7eef..4fd5f8ad2d94c55 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -976,6 +976,21 @@ void CodeGenModule::Release() {
   Context.getTypeSizeInChars(Context.getWideCharType()).getQuantity();
   getModule().addModuleFlag(llvm::Module::Error, "wchar_size", WCharWidth);
 
+  if (getTriple().isOSzOS()) {
+int32_t ProductVersion, ProductRelease, ProductPatch;
+ProductVersion = LLVM_VERSION_MAJOR,
+ProductRelease = LLVM_VERSION_MINOR, ProductPatch = LLVM_VERSION_PATCH;
+getModule().addModuleFlag(llvm::Module::Warning, "Product Major Version", 
ProductVersion);
+getModule().addModuleFlag(llvm::Module::Warning, "Product Minor Version", 
ProductRelease);
+getModule().addModuleFlag(llvm::Module::Warning, "Product Patchlevel", 
ProductPatch);
+
+// Record the language because we need it for the PPA2.
+const char *lang_str = LanguageToString(
+LangStandard::getLangStandardForKind(LangOpts.LangStd).Language);
+getModule().addModuleFlag(llvm::Module::Error, "zos_cu_language",
+  llvm::MDString::get(VMContext, lang_str));
+  }
+
   llvm::Triple::ArchType Arch = Context.getTargetInfo().getTriple().getArch();
   if (   Arch == llvm::Triple::arm
   || Arch == llvm::Triple::armeb
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b91126ebed0186c..4f02fa2fc3c788a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1738,7 +1738,7 @@ void Clang::RenderTargetOptions(const llvm::Triple 

[clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)

2023-10-12 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 2ae3a712304870adf639a33547c1139a7b6304e5 
5ea8bea2bdf345e2baee07e0a94ac40bd0f109c4 -- 
clang/test/CodeGen/SystemZ/systemz-ppa2.c 
clang/include/clang/Basic/LangStandard.h clang/lib/Basic/LangStandards.cpp 
clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Driver/ToolChains/Clang.cpp 
clang/lib/Driver/ToolChains/Clang.h llvm/include/llvm/BinaryFormat/GOFF.h 
llvm/include/llvm/MC/MCObjectFileInfo.h llvm/lib/MC/MCObjectFileInfo.cpp 
llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp 
llvm/lib/Target/SystemZ/SystemZAsmPrinter.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Basic/LangStandards.cpp 
b/clang/lib/Basic/LangStandards.cpp
index e9b75d78e820..dea2126ba93b 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -48,7 +48,8 @@ const char *clang::LanguageToString(Language L) {
 return "HLSL";
   }
 
-  std::string msg = llvm::formatv("Unknown value ({0}) passed to 
LanguageToString", (unsigned int) L);
+  std::string msg = llvm::formatv(
+  "Unknown value ({0}) passed to LanguageToString", (unsigned int)L);
   llvm_unreachable(msg.c_str());
 }
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 4fd5f8ad2d94..65327df218e6 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -978,11 +978,14 @@ void CodeGenModule::Release() {
 
   if (getTriple().isOSzOS()) {
 int32_t ProductVersion, ProductRelease, ProductPatch;
-ProductVersion = LLVM_VERSION_MAJOR,
-ProductRelease = LLVM_VERSION_MINOR, ProductPatch = LLVM_VERSION_PATCH;
-getModule().addModuleFlag(llvm::Module::Warning, "Product Major Version", 
ProductVersion);
-getModule().addModuleFlag(llvm::Module::Warning, "Product Minor Version", 
ProductRelease);
-getModule().addModuleFlag(llvm::Module::Warning, "Product Patchlevel", 
ProductPatch);
+ProductVersion = LLVM_VERSION_MAJOR, ProductRelease = LLVM_VERSION_MINOR,
+ProductPatch = LLVM_VERSION_PATCH;
+getModule().addModuleFlag(llvm::Module::Warning, "Product Major Version",
+  ProductVersion);
+getModule().addModuleFlag(llvm::Module::Warning, "Product Minor Version",
+  ProductRelease);
+getModule().addModuleFlag(llvm::Module::Warning, "Product Patchlevel",
+  ProductPatch);
 
 // Record the language because we need it for the PPA2.
 const char *lang_str = LanguageToString(
diff --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp 
b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index d963009c6c15..9d1a8d103e34 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -30,7 +30,6 @@
 #include "llvm/Support/Chrono.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertEBCDIC.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FormatProviders.h"
 #include "llvm/Support/FormatVariadic.h"
 
@@ -1092,8 +1091,8 @@ void SystemZAsmPrinter::emitIDRLSection(Module ) {
 
   ConverterEBCDIC::convertToEBCDIC(TempStr, Data);
 
-  OutStreamer->emitInt8(0);   // Reserved.
-  OutStreamer->emitInt8(3);   // Format.
+  OutStreamer->emitInt8(0);   // Reserved.
+  OutStreamer->emitInt8(3);   // Format.
   OutStreamer->emitInt16(IDRLDataLength); // Length.
   OutStreamer->emitBytes(Data.str());
   OutStreamer->popSection();
@@ -1402,8 +1401,8 @@ void SystemZAsmPrinter::emitPPA2(Module ) {
 
   SmallString<7> Version; // 6 + null
   raw_svector_ostream ostr(Version);
-  ostr << formatv("{0,0-2:d}{1,0-2:d}{2,0-2:d}", ProductVersion,
-  ProductRelease, ProductPatch);
+  ostr << formatv("{0,0-2:d}{1,0-2:d}{2,0-2:d}", ProductVersion, 
ProductRelease,
+  ProductPatch);
 
   // Drop 0 during conversion.
   SmallString CompilationTimeStr;

``




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


[clang-tools-extra] [llvm-profdata] Do not create numerical strings for MD5 function names read from a Sample Profile. (PR #66164)

2023-10-12 Thread David Li via cfe-commits


@@ -902,12 +890,16 @@ std::error_code 
SampleProfileReaderExtBinaryBase::readFuncProfiles() {
   for (const auto  : FuncOffsetList) {
 const auto  = NameOffset.first;
 auto FName = FContext.getName();
+StringRef FNameString;
+if (!useMD5()) {
+  FNameString = FName.stringRef(Buffer);
+}
 // For function in the current module, keep its farthest ancestor
 // context. This can be used to load itself and its child and
 // sibling contexts.
-if ((useMD5() && FuncGuidsToUse.count(std::stoull(FName.data( ||
-(!useMD5() && (FuncsToUse.count(FName) ||
-   (Remapper && Remapper->exist(FName) {
+if ((useMD5() && FuncGuidsToUse.count(FName.getHashCode())) ||
+(!useMD5() && (FuncsToUse.count(FNameString) ||

david-xl wrote:

yes -- having a std::string buffer which is not used here is very confusing.

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


[clang-tools-extra] [llvm-profdata] Do not create numerical strings for MD5 function names read from a Sample Profile. (PR #66164)

2023-10-12 Thread David Li via cfe-commits


@@ -902,12 +890,16 @@ std::error_code 
SampleProfileReaderExtBinaryBase::readFuncProfiles() {
   for (const auto  : FuncOffsetList) {
 const auto  = NameOffset.first;
 auto FName = FContext.getName();
+StringRef FNameString;
+if (!useMD5()) {

david-xl wrote:

this one too.

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


[clang] [llvm-profdata] Do not create numerical strings for MD5 function names read from a Sample Profile. (PR #66164)

2023-10-12 Thread David Li via cfe-commits


@@ -902,12 +890,16 @@ std::error_code 
SampleProfileReaderExtBinaryBase::readFuncProfiles() {
   for (const auto  : FuncOffsetList) {
 const auto  = NameOffset.first;
 auto FName = FContext.getName();
+StringRef FNameString;
+if (!useMD5()) {
+  FNameString = FName.stringRef(Buffer);
+}
 // For function in the current module, keep its farthest ancestor
 // context. This can be used to load itself and its child and
 // sibling contexts.
-if ((useMD5() && FuncGuidsToUse.count(std::stoull(FName.data( ||
-(!useMD5() && (FuncsToUse.count(FName) ||
-   (Remapper && Remapper->exist(FName) {
+if ((useMD5() && FuncGuidsToUse.count(FName.getHashCode())) ||
+(!useMD5() && (FuncsToUse.count(FNameString) ||

david-xl wrote:

yes -- having a std::string buffer which is not used here is very confusing.

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


[clang] [llvm-profdata] Do not create numerical strings for MD5 function names read from a Sample Profile. (PR #66164)

2023-10-12 Thread David Li via cfe-commits


@@ -0,0 +1,222 @@
+//===--- ProfileFuncRef.h - Sample profile function name ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the StringRefOrHashCode class. It is to represent function
+// names in a sample profile, which can be in one of two forms - either a
+// regular string, or a 64-bit hash code.
+//
+//===--===//
+
+#ifndef LLVM_PROFILEDATA_PROFILEFUNCREF_H
+#define LLVM_PROFILEDATA_PROFILEFUNCREF_H
+
+#include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MD5.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace llvm {
+namespace sampleprof {
+
+/// This class represents a function name that is read from a sample profile. 
It
+/// comes with two forms: a string or a hash code. For efficient storage, a
+/// sample profile may store function names as 64-bit MD5 values, so when
+/// reading the profile, this class can represnet them without converting it to
+/// a string first.
+/// When representing a hash code, we utilize the Length field to store it, and
+/// Data is set to null. When representing a string, it is same as StringRef,
+/// and can be pointer-casted as one.
+/// We disallow implicit cast to StringRef because there are too many instances
+/// that it may cause break the code, such as using it in a StringMap.
+class ProfileFuncRef {
+
+  const char *Data = nullptr;
+
+  /// Use uint64_t instead of size_t so that it can also hold a MD5 value.
+  uint64_t LengthOrHashCode = 0;
+
+  /// Extension to memcmp to handle hash code representation. If both are hash
+  /// values, Lhs and Rhs are both null, function returns 0 (and needs an extra
+  /// comparison using getIntValue). If only one is hash code, it is considered
+  /// less than the StringRef one. Otherwise perform normal string comparison.
+  static int compareMemory(const char *Lhs, const char *Rhs, uint64_t Length) {
+if (Lhs == Rhs)
+  return 0;
+if (!Lhs)
+  return -1;
+if (!Rhs)
+  return 1;
+return ::memcmp(Lhs, Rhs, (size_t)Length);
+  }
+
+public:
+  ProfileFuncRef() = default;
+
+  /// Constructor from a StringRef. Check if Str is a number, which is 
generated
+  /// by converting a MD5 sample profile to a format that does not support MD5,
+  /// and if so, convert the numerical string to a hash code first. We assume
+  /// that no function name (from a profile) can be a pure number.
+  explicit ProfileFuncRef(StringRef Str)

david-xl wrote:

This question is unanswered/unaddressed.

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


[clang] [llvm-profdata] Do not create numerical strings for MD5 function names read from a Sample Profile. (PR #66164)

2023-10-12 Thread David Li via cfe-commits


@@ -902,12 +890,16 @@ std::error_code 
SampleProfileReaderExtBinaryBase::readFuncProfiles() {
   for (const auto  : FuncOffsetList) {
 const auto  = NameOffset.first;
 auto FName = FContext.getName();
+StringRef FNameString;

david-xl wrote:

please resolve this.

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


[clang] [llvm-profdata] Do not create numerical strings for MD5 function names read from a Sample Profile. (PR #66164)

2023-10-12 Thread David Li via cfe-commits


@@ -0,0 +1,222 @@
+//===--- ProfileFuncRef.h - Sample profile function name ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the StringRefOrHashCode class. It is to represent function
+// names in a sample profile, which can be in one of two forms - either a
+// regular string, or a 64-bit hash code.
+//
+//===--===//
+
+#ifndef LLVM_PROFILEDATA_PROFILEFUNCREF_H
+#define LLVM_PROFILEDATA_PROFILEFUNCREF_H
+
+#include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MD5.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace llvm {
+namespace sampleprof {
+
+/// This class represents a function name that is read from a sample profile. 
It
+/// comes with two forms: a string or a hash code. For efficient storage, a
+/// sample profile may store function names as 64-bit MD5 values, so when
+/// reading the profile, this class can represnet them without converting it to
+/// a string first.
+/// When representing a hash code, we utilize the Length field to store it, and
+/// Data is set to null. When representing a string, it is same as StringRef,
+/// and can be pointer-casted as one.
+/// We disallow implicit cast to StringRef because there are too many instances
+/// that it may cause break the code, such as using it in a StringMap.
+class ProfileFuncRef {

david-xl wrote:

FunctionId or FuncId sounds good to me @huangjd 

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


[clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)

2023-10-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Yusra Syeda (ysyeda)


Changes

This PR adds support for the PPA2 fields.

---

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


12 Files Affected:

- (modified) clang/include/clang/Basic/LangStandard.h (+1) 
- (modified) clang/lib/Basic/LangStandards.cpp (+39) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+15) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+11-2) 
- (modified) clang/lib/Driver/ToolChains/Clang.h (+2-1) 
- (added) clang/test/CodeGen/SystemZ/systemz-ppa2.c (+25) 
- (modified) llvm/include/llvm/BinaryFormat/GOFF.h (+1) 
- (modified) llvm/include/llvm/MC/MCObjectFileInfo.h (+4) 
- (modified) llvm/lib/MC/MCObjectFileInfo.cpp (+5) 
- (modified) llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp (+196-1) 
- (modified) llvm/lib/Target/SystemZ/SystemZAsmPrinter.h (+6-1) 
- (added) llvm/test/CodeGen/SystemZ/zos-ppa2.ll (+26) 


``diff
diff --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index 6356f16acc811e0..d94567adf2bfb99 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -43,6 +43,7 @@ enum class Language : uint8_t {
   HLSL,
   ///@}
 };
+const char *LanguageToString(Language L);
 
 enum LangFeatures {
   LineComment = (1 << 0),
diff --git a/clang/lib/Basic/LangStandards.cpp 
b/clang/lib/Basic/LangStandards.cpp
index af9cf4f273920ee..e9b75d78e820a64 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -10,9 +10,48 @@
 #include "clang/Config/config.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/TargetParser/Triple.h"
 using namespace clang;
 
+const char *clang::LanguageToString(Language L) {
+  // I would like to make this function and the definition of Language
+  // in the .h file simply expand the contents of a .def file.
+  // However, in the .h the members of the enum have doxygen annotations
+  // and/or comments which would be lost.
+  switch (L) {
+  case Language::Unknown:
+return "Unknown";
+  case Language::Asm:
+return "Asm";
+  case Language::LLVM_IR:
+return "LLVM_IR";
+  case Language::C:
+return "C";
+  case Language::CXX:
+return "CXX";
+  case Language::ObjC:
+return "ObjC";
+  case Language::ObjCXX:
+return "ObjCXX";
+  case Language::OpenCL:
+return "OpenCL";
+  case Language::OpenCLCXX:
+return "OpenCLCXX";
+  case Language::CUDA:
+return "CUDA";
+  case Language::RenderScript:
+return "RenderScript";
+  case Language::HIP:
+return "HIP";
+  case Language::HLSL:
+return "HLSL";
+  }
+
+  std::string msg = llvm::formatv("Unknown value ({0}) passed to 
LanguageToString", (unsigned int) L);
+  llvm_unreachable(msg.c_str());
+}
+
 #define LANGSTANDARD(id, name, lang, desc, features)   
\
   static const LangStandard Lang_##id = {name, desc, features, Language::lang};
 #include "clang/Basic/LangStandards.def"
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 754377bed7f7eef..4fd5f8ad2d94c55 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -976,6 +976,21 @@ void CodeGenModule::Release() {
   Context.getTypeSizeInChars(Context.getWideCharType()).getQuantity();
   getModule().addModuleFlag(llvm::Module::Error, "wchar_size", WCharWidth);
 
+  if (getTriple().isOSzOS()) {
+int32_t ProductVersion, ProductRelease, ProductPatch;
+ProductVersion = LLVM_VERSION_MAJOR,
+ProductRelease = LLVM_VERSION_MINOR, ProductPatch = LLVM_VERSION_PATCH;
+getModule().addModuleFlag(llvm::Module::Warning, "Product Major Version", 
ProductVersion);
+getModule().addModuleFlag(llvm::Module::Warning, "Product Minor Version", 
ProductRelease);
+getModule().addModuleFlag(llvm::Module::Warning, "Product Patchlevel", 
ProductPatch);
+
+// Record the language because we need it for the PPA2.
+const char *lang_str = LanguageToString(
+LangStandard::getLangStandardForKind(LangOpts.LangStd).Language);
+getModule().addModuleFlag(llvm::Module::Error, "zos_cu_language",
+  llvm::MDString::get(VMContext, lang_str));
+  }
+
   llvm::Triple::ArchType Arch = Context.getTargetInfo().getTriple().getArch();
   if (   Arch == llvm::Triple::arm
   || Arch == llvm::Triple::armeb
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b91126ebed0186c..4f02fa2fc3c788a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1738,7 +1738,7 @@ void Clang::RenderTargetOptions(const llvm::Triple 
,
 break;
 
   case llvm::Triple::systemz:
-AddSystemZTargetArgs(Args, CmdArgs);
+AddSystemZTargetArgs(EffectiveTriple, Args, CmdArgs);
  

[clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)

2023-10-12 Thread Yusra Syeda via cfe-commits

https://github.com/ysyeda created 
https://github.com/llvm/llvm-project/pull/68926

This PR adds support for the PPA2 fields.

>From 5ea8bea2bdf345e2baee07e0a94ac40bd0f109c4 Mon Sep 17 00:00:00 2001
From: Yusra Syeda 
Date: Thu, 12 Oct 2023 16:56:27 -0400
Subject: [PATCH] This change adds support for the PPA2 section in zOS

---
 clang/include/clang/Basic/LangStandard.h  |   1 +
 clang/lib/Basic/LangStandards.cpp |  39 
 clang/lib/CodeGen/CodeGenModule.cpp   |  15 ++
 clang/lib/Driver/ToolChains/Clang.cpp |  13 +-
 clang/lib/Driver/ToolChains/Clang.h   |   3 +-
 clang/test/CodeGen/SystemZ/systemz-ppa2.c |  25 +++
 llvm/include/llvm/BinaryFormat/GOFF.h |   1 +
 llvm/include/llvm/MC/MCObjectFileInfo.h   |   4 +
 llvm/lib/MC/MCObjectFileInfo.cpp  |   5 +
 llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp | 197 +-
 llvm/lib/Target/SystemZ/SystemZAsmPrinter.h   |   7 +-
 llvm/test/CodeGen/SystemZ/zos-ppa2.ll |  26 +++
 12 files changed, 331 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/SystemZ/systemz-ppa2.c
 create mode 100644 llvm/test/CodeGen/SystemZ/zos-ppa2.ll

diff --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index 6356f16acc811e0..d94567adf2bfb99 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -43,6 +43,7 @@ enum class Language : uint8_t {
   HLSL,
   ///@}
 };
+const char *LanguageToString(Language L);
 
 enum LangFeatures {
   LineComment = (1 << 0),
diff --git a/clang/lib/Basic/LangStandards.cpp 
b/clang/lib/Basic/LangStandards.cpp
index af9cf4f273920ee..e9b75d78e820a64 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -10,9 +10,48 @@
 #include "clang/Config/config.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/TargetParser/Triple.h"
 using namespace clang;
 
+const char *clang::LanguageToString(Language L) {
+  // I would like to make this function and the definition of Language
+  // in the .h file simply expand the contents of a .def file.
+  // However, in the .h the members of the enum have doxygen annotations
+  // and/or comments which would be lost.
+  switch (L) {
+  case Language::Unknown:
+return "Unknown";
+  case Language::Asm:
+return "Asm";
+  case Language::LLVM_IR:
+return "LLVM_IR";
+  case Language::C:
+return "C";
+  case Language::CXX:
+return "CXX";
+  case Language::ObjC:
+return "ObjC";
+  case Language::ObjCXX:
+return "ObjCXX";
+  case Language::OpenCL:
+return "OpenCL";
+  case Language::OpenCLCXX:
+return "OpenCLCXX";
+  case Language::CUDA:
+return "CUDA";
+  case Language::RenderScript:
+return "RenderScript";
+  case Language::HIP:
+return "HIP";
+  case Language::HLSL:
+return "HLSL";
+  }
+
+  std::string msg = llvm::formatv("Unknown value ({0}) passed to 
LanguageToString", (unsigned int) L);
+  llvm_unreachable(msg.c_str());
+}
+
 #define LANGSTANDARD(id, name, lang, desc, features)   
\
   static const LangStandard Lang_##id = {name, desc, features, Language::lang};
 #include "clang/Basic/LangStandards.def"
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 754377bed7f7eef..4fd5f8ad2d94c55 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -976,6 +976,21 @@ void CodeGenModule::Release() {
   Context.getTypeSizeInChars(Context.getWideCharType()).getQuantity();
   getModule().addModuleFlag(llvm::Module::Error, "wchar_size", WCharWidth);
 
+  if (getTriple().isOSzOS()) {
+int32_t ProductVersion, ProductRelease, ProductPatch;
+ProductVersion = LLVM_VERSION_MAJOR,
+ProductRelease = LLVM_VERSION_MINOR, ProductPatch = LLVM_VERSION_PATCH;
+getModule().addModuleFlag(llvm::Module::Warning, "Product Major Version", 
ProductVersion);
+getModule().addModuleFlag(llvm::Module::Warning, "Product Minor Version", 
ProductRelease);
+getModule().addModuleFlag(llvm::Module::Warning, "Product Patchlevel", 
ProductPatch);
+
+// Record the language because we need it for the PPA2.
+const char *lang_str = LanguageToString(
+LangStandard::getLangStandardForKind(LangOpts.LangStd).Language);
+getModule().addModuleFlag(llvm::Module::Error, "zos_cu_language",
+  llvm::MDString::get(VMContext, lang_str));
+  }
+
   llvm::Triple::ArchType Arch = Context.getTargetInfo().getTriple().getArch();
   if (   Arch == llvm::Triple::arm
   || Arch == llvm::Triple::armeb
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b91126ebed0186c..4f02fa2fc3c788a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1738,7 +1738,7 @@ void 

[clang] [clang][dataflow] Check for backedges directly (instead of loop statements). (PR #68923)

2023-10-12 Thread Yitzhak Mandelbaum via cfe-commits

ymand wrote:

> Nice fix! So, it looks like our definition of "loop head" was wrong.

Indeed. We didn't think of the way control-flow constructs *inside* the 
condition expression would be represented. Ironically (?), this is actually 
simpler and fixes another issue besides, which is nice. ;)

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


[clang] [clang][dataflow] Check for backedges directly (instead of loop statements). (PR #68923)

2023-10-12 Thread Yitzhak Mandelbaum via cfe-commits

https://github.com/ymand updated https://github.com/llvm/llvm-project/pull/68923

>From 83486a35e6d0e754dd99369fc546d04afedbe923 Mon Sep 17 00:00:00 2001
From: Yitzhak Mandelbaum 
Date: Thu, 12 Oct 2023 19:35:54 +
Subject: [PATCH 1/2] [clang][dataflow] Check for backedges directly (instead
 of loop statements).

Widen on backedge nodes, instead of nodes with a loop statement as terminator.
This fixes #67834 and a precision loss from assignment in a loop condition. The
commit contains tests for both of these issues.
---
 .../TypeErasedDataflowAnalysis.cpp| 29 ++-
 .../Analysis/FlowSensitive/TransferTest.cpp   | 14 +
 .../TypeErasedDataflowAnalysisTest.cpp| 28 ++
 3 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 6b167891c1a3ac8..5da3a5b1ccf8a2c 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -12,7 +12,6 @@
 
//===--===//
 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -33,8 +32,8 @@
 #include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallBitVector.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
 
@@ -53,19 +52,8 @@ static int blockIndexInPredecessor(const CFGBlock ,
   return BlockPos - Pred.succ_begin();
 }
 
-static bool isLoopHead(const CFGBlock ) {
-  if (const auto *T = B.getTerminatorStmt())
-switch (T->getStmtClass()) {
-  case Stmt::WhileStmtClass:
-  case Stmt::DoStmtClass:
-  case Stmt::ForStmtClass:
-  case Stmt::CXXForRangeStmtClass:
-return true;
-  default:
-return false;
-}
-
-  return false;
+static bool isBackedgeNode(const CFGBlock ) {
+ return B.getLoopTarget() != nullptr;
 }
 
 namespace {
@@ -502,14 +490,15 @@ runTypeErasedDataflowAnalysis(
 PostVisitCFG) {
   PrettyStackTraceAnalysis CrashInfo(CFCtx, "runTypeErasedDataflowAnalysis");
 
-  PostOrderCFGView POV(());
-  ForwardDataflowWorklist Worklist(CFCtx.getCFG(), );
+  const clang::CFG  = CFCtx.getCFG();
+  PostOrderCFGView POV();
+  ForwardDataflowWorklist Worklist(CFG, );
 
   std::vector> BlockStates(
-  CFCtx.getCFG().size());
+  CFG.size());
 
   // The entry basic block doesn't contain statements so it can be skipped.
-  const CFGBlock  = CFCtx.getCFG().getEntry();
+  const CFGBlock  = CFG.getEntry();
   BlockStates[Entry.getBlockID()] = {Analysis.typeErasedInitialElement(),
  InitEnv.fork()};
   Worklist.enqueueSuccessors();
@@ -553,7 +542,7 @@ runTypeErasedDataflowAnalysis(
 llvm::errs() << "Old Env:\n";
 OldBlockState->Env.dump();
   });
-  if (isLoopHead(*Block)) {
+  if (isBackedgeNode(*Block)) {
 LatticeJoinEffect Effect1 = Analysis.widenTypeErased(
 NewBlockState.Lattice, OldBlockState->Lattice);
 LatticeJoinEffect Effect2 =
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 632632a1b30e78b..7c697fa5f87d941 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4099,6 +4099,20 @@ TEST(TransferTest, 
LoopDereferencingChangingRecordPointerConverges) {
   ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
 }
 
+TEST(TransferTest, LoopWithDisjunctiveConditionConverges) {
+  std::string Code = R"cc(
+bool foo();
+
+void target() {
+  bool c = false;
+  while (foo() || foo()) {
+c = true;
+  }
+}
+  )cc";
+  ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
+}
+
 TEST(TransferTest, DoesNotCrashOnUnionThisExpr) {
   std::string Code = R"(
 union Union {
diff --git 
a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
index 2425bb8711bdbaf..6800d736afd9b08 100644
--- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -913,6 +913,34 @@ TEST_F(FlowConditionTest, WhileStmt) {
   });
 }
 
+TEST_F(FlowConditionTest, WhileStmtWithAssignmentInCondition) {
+  std::string Code = R"(
+void target(bool Foo) {
+  // This test checks whether the analysis preserves the connection between
+  // the value of `Foo` and the assignment expression, despite widening.
+  // The equality operator generates a fresh boolean variable on each
+  

[clang] [AMDGPU] Change the representation of double literals in operands (PR #68740)

2023-10-12 Thread Stanislav Mekhanoshin via cfe-commits

https://github.com/rampitec updated 
https://github.com/llvm/llvm-project/pull/68740

>From cc9e065a9218eb36750a2c2a4a4d08fae3f329fa Mon Sep 17 00:00:00 2001
From: Stanislav Mekhanoshin 
Date: Wed, 4 Oct 2023 13:36:25 -0700
Subject: [PATCH 1/6] [AMDGPU] Change the representation of double literals in
 operands

A 64-bit literal can be used as a 32-bit zero or sign extended
operand. In case of double zeroes are added to the low 32 bits.
Currently asm parser stores only high 32 bits of a double into
an operand. To support codegen as requested by the
https://github.com/llvm/llvm-project/issues/67781 we need to
change the representation to store a full 64-bit value so that
codegen can simply add immediates to an instruction.

There is some code to support compatibility with existing tests
and asm kernels. We allow to use short hex strings to represent
only a high 32 bit of a double value as a valid literal.
---
 .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp  | 21 --
 .../Disassembler/AMDGPUDisassembler.cpp   | 28 ++-
 .../AMDGPU/Disassembler/AMDGPUDisassembler.h  |  9 --
 .../AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp | 12 +---
 .../AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h   |  2 +-
 .../MCTargetDesc/AMDGPUMCCodeEmitter.cpp  |  3 ++
 llvm/lib/Target/AMDGPU/SIRegisterInfo.td  |  4 ++-
 .../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp|  7 +
 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h |  3 ++
 9 files changed, 70 insertions(+), 19 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp 
b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 35656bcaea1af7f..0553d3f20b21c56 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -2140,9 +2140,10 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst , 
int64_t Val, bool ApplyMo
   const_cast(AsmParser)->Warning(Inst.getLoc(),
   "Can't encode literal as exact 64-bit floating-point operand. "
   "Low 32-bits will be set to zero");
+  Val &= 0xu;
 }
 
-Inst.addOperand(MCOperand::createImm(Literal.lshr(32).getZExtValue()));
+Inst.addOperand(MCOperand::createImm(Val));
 setImmKindLiteral();
 return;
   }
@@ -2241,7 +2242,10 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst , 
int64_t Val, bool ApplyMo
   return;
 }
 
-Inst.addOperand(MCOperand::createImm(Lo_32(Val)));
+if (isInt<32>(Val) || isUInt<32>(Val))
+  Val = AMDGPU::isSISrcFPOperand(InstDesc, OpNum) ? Val << 32 : Lo_32(Val);
+
+Inst.addOperand(MCOperand::createImm(Val));
 setImmKindLiteral();
 return;
 
@@ -4297,7 +4301,18 @@ bool AMDGPUAsmParser::validateVOPLiteral(const MCInst 
,
   continue;
 
 if (MO.isImm() && !isInlineConstant(Inst, OpIdx)) {
-  uint32_t Value = static_cast(MO.getImm());
+  uint64_t Value = static_cast(MO.getImm());
+  bool IsFP = AMDGPU::isSISrcFPOperand(Desc, OpIdx);
+  bool IsValid32Op = AMDGPU::isValid32BitLiteral(Value, IsFP);
+
+  if (!IsValid32Op && !isInt<32>(Value) && !isUInt<32>(Value)) {
+Error(getLitLoc(Operands), "invalid operand for instruction");
+return false;
+  }
+
+  if (IsFP && IsValid32Op)
+Value = Hi_32(Value);
+
   if (NumLiterals == 0 || LiteralValue != Value) {
 LiteralValue = Value;
 ++NumLiterals;
diff --git a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp 
b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
index 439762bc6caf786..8c49c9a9c87772e 100644
--- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
+++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
@@ -378,6 +378,15 @@ static DecodeStatus decodeOperand_AVLdSt_Any(MCInst , 
unsigned Imm,
   return addOperand(Inst, DAsm->decodeSrcOp(Opw, Imm | 256));
 }
 
+static DecodeStatus
+decodeOperand_VSrc_f64(MCInst , unsigned Imm, uint64_t Addr,
+   const MCDisassembler *Decoder) {
+  assert(Imm < (1 << 9) && "9-bit encoding");
+  auto DAsm = static_cast(Decoder);
+  return addOperand(Inst, DAsm->decodeSrcOp(AMDGPUDisassembler::OPW64, Imm,
+false, 64, true));
+}
+
 static DecodeStatus
 DecodeAVLdSt_32RegisterClass(MCInst , unsigned Imm, uint64_t Addr,
  const MCDisassembler *Decoder) {
@@ -1218,7 +1227,7 @@ 
AMDGPUDisassembler::decodeMandatoryLiteralConstant(unsigned Val) const {
   return MCOperand::createImm(Literal);
 }
 
-MCOperand AMDGPUDisassembler::decodeLiteralConstant() const {
+MCOperand AMDGPUDisassembler::decodeLiteralConstant(bool ExtendFP64) const {
   // For now all literal constants are supposed to be unsigned integer
   // ToDo: deal with signed/unsigned 64-bit integer constants
   // ToDo: deal with float/double constants
@@ -1228,9 +1237,11 @@ MCOperand AMDGPUDisassembler::decodeLiteralConstant() 
const {
   

[clang] ef38833 - Revert "Reapply "InstCombine: Introduce SimplifyDemandedUseFPClass""

2023-10-12 Thread Leonard Chan via cfe-commits

Author: Leonard Chan
Date: 2023-10-12T20:23:39Z
New Revision: ef388334ee5a3584255b9ef5b3fefdb244fa3fd7

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

LOG: Revert "Reapply "InstCombine: Introduce SimplifyDemandedUseFPClass""

This reverts commit 5a36904c515b.

Reverted because this breaks some floating point operations. See the
comment on https://github.com/llvm/llvm-project/commit/5a36904c515b.

Added: 


Modified: 
clang/test/Headers/__clang_hip_math.hip
llvm/include/llvm/Analysis/ValueTracking.h
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/simplify-demanded-fpclass.ll

Removed: 




diff  --git a/clang/test/Headers/__clang_hip_math.hip 
b/clang/test/Headers/__clang_hip_math.hip
index 15eccc3b2baba08..fc18e14d8229635 100644
--- a/clang/test/Headers/__clang_hip_math.hip
+++ b/clang/test/Headers/__clang_hip_math.hip
@@ -231,8 +231,8 @@ extern "C" __device__ uint64_t test___make_mantissa(const 
char *p) {
 
 // CHECK-LABEL: @test_abs(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call noundef i32 @llvm.abs.i32(i32 
[[X:%.*]], i1 true)
-// CHECK-NEXT:ret i32 [[TMP0]]
+// CHECK-NEXT:[[ABS_I:%.*]] = tail call noundef i32 @llvm.abs.i32(i32 
[[X:%.*]], i1 true)
+// CHECK-NEXT:ret i32 [[ABS_I]]
 //
 extern "C" __device__ int test_abs(int x) {
   return abs(x);
@@ -240,8 +240,8 @@ extern "C" __device__ int test_abs(int x) {
 
 // CHECK-LABEL: @test_labs(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call noundef i64 @llvm.abs.i64(i64 
[[X:%.*]], i1 true)
-// CHECK-NEXT:ret i64 [[TMP0]]
+// CHECK-NEXT:[[ABS_I:%.*]] = tail call noundef i64 @llvm.abs.i64(i64 
[[X:%.*]], i1 true)
+// CHECK-NEXT:ret i64 [[ABS_I]]
 //
 extern "C" __device__ long test_labs(long x) {
   return labs(x);
@@ -249,8 +249,8 @@ extern "C" __device__ long test_labs(long x) {
 
 // CHECK-LABEL: @test_llabs(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call noundef i64 @llvm.abs.i64(i64 
[[X:%.*]], i1 true)
-// CHECK-NEXT:ret i64 [[TMP0]]
+// CHECK-NEXT:[[ABS_I:%.*]] = tail call noundef i64 @llvm.abs.i64(i64 
[[X:%.*]], i1 true)
+// CHECK-NEXT:ret i64 [[ABS_I]]
 //
 extern "C" __device__ long long test_llabs(long x) {
   return llabs(x);
@@ -2557,65 +2557,33 @@ extern "C" __device__ double test_nan(const char *tag) {
   return nan(tag);
 }
 
-// DEFAULT-LABEL: @test_nanf_emptystr(
-// DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:ret float 0x7FF8
-//
-// FINITEONLY-LABEL: @test_nanf_emptystr(
-// FINITEONLY-NEXT:  entry:
-// FINITEONLY-NEXT:ret float poison
-//
-// APPROX-LABEL: @test_nanf_emptystr(
-// APPROX-NEXT:  entry:
-// APPROX-NEXT:ret float 0x7FF8
+// CHECK-LABEL: @test_nanf_emptystr(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret float 0x7FF8
 //
 extern "C" __device__ float test_nanf_emptystr() {
   return nanf("");
 }
 
-// DEFAULT-LABEL: @test_nan_emptystr(
-// DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:ret double 0x7FF8
-//
-// FINITEONLY-LABEL: @test_nan_emptystr(
-// FINITEONLY-NEXT:  entry:
-// FINITEONLY-NEXT:ret double poison
-//
-// APPROX-LABEL: @test_nan_emptystr(
-// APPROX-NEXT:  entry:
-// APPROX-NEXT:ret double 0x7FF8
+// CHECK-LABEL: @test_nan_emptystr(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret double 0x7FF8
 //
 extern "C" __device__ double test_nan_emptystr() {
   return nan("");
 }
 
-// DEFAULT-LABEL: @test_nanf_fill(
-// DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:ret float 0x7FF8
-//
-// FINITEONLY-LABEL: @test_nanf_fill(
-// FINITEONLY-NEXT:  entry:
-// FINITEONLY-NEXT:ret float poison
-//
-// APPROX-LABEL: @test_nanf_fill(
-// APPROX-NEXT:  entry:
-// APPROX-NEXT:ret float 0x7FF8
+// CHECK-LABEL: @test_nanf_fill(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret float 0x7FF8
 //
 extern "C" __device__ float test_nanf_fill() {
   return nanf("0x456");
 }
 
-// DEFAULT-LABEL: @test_nan_fill(
-// DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:ret double 0x7FF8
-//
-// FINITEONLY-LABEL: @test_nan_fill(
-// FINITEONLY-NEXT:  entry:
-// FINITEONLY-NEXT:ret double poison
-//
-// APPROX-LABEL: @test_nan_fill(
-// APPROX-NEXT:  entry:
-// APPROX-NEXT:ret double 0x7FF8
+// CHECK-LABEL: @test_nan_fill(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret double 0x7FF8
 //
 extern "C" __device__ double test_nan_fill() {
   return nan("0x123");

diff  --git a/llvm/include/llvm/Analysis/ValueTracking.h 
b/llvm/include/llvm/Analysis/ValueTracking.h
index 

[clang] [Driver] Corrections for linker flags passed with relocatable linking on OpenBSD (PR #67254)

2023-10-12 Thread Brad Smith via cfe-commits

brad0 wrote:

@MaskRay ping.

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


[clang] [clang][dataflow] Check for backedges directly (instead of loop statements). (PR #68923)

2023-10-12 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.

Nice fix! So, it looks like our definition of "loop head" was wrong. 

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


[PATCH] D117593: [clang-tidy] Change google-explicit-constructor to ignore conversions and operators marked `explicit(false)`

2023-10-12 Thread Luka Govedič via Phabricator via cfe-commits
ProExpertProg added a comment.

Is there an update on this? I agree adding a flag to control this behavior 
would be good but the Google style guide clearly does not take the 
`explicit(false)` option into consideration. Currently the only alternatives 
are a disabling the check completely or adding a bunch of NOLINT statements 
everywhere, neither of which is great.

Perhaps an alternative would be to add a separate check, either called 
`explicit-constructor` or `google-explicit-constructor-permissive` with this 
functionality.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117593

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


[clang] [clang][dataflow] Check for backedges directly (instead of loop statements). (PR #68923)

2023-10-12 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 50ece4cba949787241b5fbfc94be6cfdc66e90ee 
da8cacb47b8f80f7ecb1e86f98683be6c54b4e57 -- 
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index c635edd12219..d96ad66dd674 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -53,7 +53,7 @@ static int blockIndexInPredecessor(const CFGBlock ,
 }
 
 static bool isBackedgeNode(const CFGBlock ) {
- return B.getLoopTarget() != nullptr;
+  return B.getLoopTarget() != nullptr;
 }
 
 namespace {
@@ -494,7 +494,6 @@ runTypeErasedDataflowAnalysis(
   PostOrderCFGView POV();
   ForwardDataflowWorklist Worklist(CFG, );
 
-
   std::vector> BlockStates(
   CFG.size());
 

``




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


[clang] Use the correct namespace for looking up matching operator!= (PR #68922)

2023-10-12 Thread Richard Smith via cfe-commits

zygoloid wrote:

Does this work for function-scope operator declarations?

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


[clang] Use the correct namespace for looking up matching operator!= (PR #68922)

2023-10-12 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/68922

>From 0c71b6bdd557ff4b9ad9a4ec4f0919e3460596b0 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 12 Oct 2023 21:35:52 +0200
Subject: [PATCH 1/2] Find opertor!= in the correct namespace

---
 clang/lib/Sema/SemaOverload.cpp   |  7 +-
 .../over.match.oper/p3-2a.cpp | 24 +++
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index ce78994e6553814..e1e0b4a888e49fa 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -960,12 +960,7 @@ static bool shouldAddReversedEqEq(Sema , SourceLocation 
OpLoc,
 return true;
   }
   // Otherwise the search scope is the namespace scope of which F is a member.
-  LookupResult NonMembers(S, NotEqOp, OpLoc,
-  Sema::LookupNameKind::LookupOperatorName);
-  S.LookupName(NonMembers,
-   S.getScopeForContext(EqFD->getEnclosingNamespaceContext()));
-  NonMembers.suppressAccessDiagnostics();
-  for (NamedDecl *Op : NonMembers) {
+  for (NamedDecl *Op : EqFD->getEnclosingNamespaceContext()->lookup(NotEqOp)) {
 auto *FD = Op->getAsFunction();
 if(auto* UD = dyn_cast(Op))
   FD = UD->getUnderlyingDecl()->getAsFunction();
diff --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
index 5c6804eb7726b5f..7142ed22ddb22ca 100644
--- a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
@@ -324,6 +324,30 @@ bool x = X() == X(); // expected-warning {{ambiguous}}
 }
 } // namespace P2468R2
 
+namespace ADL_GH68901{
+namespace A {
+struct S {};
+bool operator==(S, int); // expected-note {{no known conversion from 'int' to 
'S' for 1st argument}}
+bool operator!=(S, int);
+} // namespace A
+bool a = 0 == A::S(); // expected-error {{invalid operands to binary 
expression ('int' and 'A::S')}}
+
+namespace B {
+struct Derived {};
+struct Base : Derived {};
+
+bool operator==(Derived& a, Base& b);
+bool operator!=(Derived& a, Base& b);
+}  // namespace B
+
+void foo() {
+  // B::Base{} == B::Base{};
+  B::Base a,b;
+  bool v = a == b;
+}
+} //namespace ADL_GH68901
+
+
 #else // NO_ERRORS
 
 namespace problem_cases {

>From eb7ac047b269d71e4fc7afbbb8b8f65e857ff3a3 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 12 Oct 2023 21:48:20 +0200
Subject: [PATCH 2/2] Add release notes

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..c5b5f665ce9834c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -64,6 +64,10 @@ C/C++ Language Potentially Breaking Changes
 ``__has_c_attribute(warn_unused_result)``,  202003, 0
 ``__has_c_attribute(gnu::warn_unused_result)``, 202003, 1
 
+- Fixed a bug in finding matching `operator!=` while adding reveresed 
`operator==` as
+  outlined in "The Equality Operator You Are Looking For" (`P2468 
`_).
+  Fixes (`#68901: `_).
+
 C++ Specific Potentially Breaking Changes
 -
 - The name mangling rules for function templates has been changed to take into

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


[clang] [clang][dataflow] Check for backedges directly (instead of loop statements). (PR #68923)

2023-10-12 Thread Yitzhak Mandelbaum via cfe-commits

https://github.com/ymand updated https://github.com/llvm/llvm-project/pull/68923

>From 83486a35e6d0e754dd99369fc546d04afedbe923 Mon Sep 17 00:00:00 2001
From: Yitzhak Mandelbaum 
Date: Thu, 12 Oct 2023 19:35:54 +
Subject: [PATCH] [clang][dataflow] Check for backedges directly (instead of
 loop statements).

Widen on backedge nodes, instead of nodes with a loop statement as terminator.
This fixes #67834 and a precision loss from assignment in a loop condition. The
commit contains tests for both of these issues.
---
 .../TypeErasedDataflowAnalysis.cpp| 29 ++-
 .../Analysis/FlowSensitive/TransferTest.cpp   | 14 +
 .../TypeErasedDataflowAnalysisTest.cpp| 28 ++
 3 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 6b167891c1a3ac8..5da3a5b1ccf8a2c 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -12,7 +12,6 @@
 
//===--===//
 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -33,8 +32,8 @@
 #include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallBitVector.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
 
@@ -53,19 +52,8 @@ static int blockIndexInPredecessor(const CFGBlock ,
   return BlockPos - Pred.succ_begin();
 }
 
-static bool isLoopHead(const CFGBlock ) {
-  if (const auto *T = B.getTerminatorStmt())
-switch (T->getStmtClass()) {
-  case Stmt::WhileStmtClass:
-  case Stmt::DoStmtClass:
-  case Stmt::ForStmtClass:
-  case Stmt::CXXForRangeStmtClass:
-return true;
-  default:
-return false;
-}
-
-  return false;
+static bool isBackedgeNode(const CFGBlock ) {
+ return B.getLoopTarget() != nullptr;
 }
 
 namespace {
@@ -502,14 +490,15 @@ runTypeErasedDataflowAnalysis(
 PostVisitCFG) {
   PrettyStackTraceAnalysis CrashInfo(CFCtx, "runTypeErasedDataflowAnalysis");
 
-  PostOrderCFGView POV(());
-  ForwardDataflowWorklist Worklist(CFCtx.getCFG(), );
+  const clang::CFG  = CFCtx.getCFG();
+  PostOrderCFGView POV();
+  ForwardDataflowWorklist Worklist(CFG, );
 
   std::vector> BlockStates(
-  CFCtx.getCFG().size());
+  CFG.size());
 
   // The entry basic block doesn't contain statements so it can be skipped.
-  const CFGBlock  = CFCtx.getCFG().getEntry();
+  const CFGBlock  = CFG.getEntry();
   BlockStates[Entry.getBlockID()] = {Analysis.typeErasedInitialElement(),
  InitEnv.fork()};
   Worklist.enqueueSuccessors();
@@ -553,7 +542,7 @@ runTypeErasedDataflowAnalysis(
 llvm::errs() << "Old Env:\n";
 OldBlockState->Env.dump();
   });
-  if (isLoopHead(*Block)) {
+  if (isBackedgeNode(*Block)) {
 LatticeJoinEffect Effect1 = Analysis.widenTypeErased(
 NewBlockState.Lattice, OldBlockState->Lattice);
 LatticeJoinEffect Effect2 =
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 632632a1b30e78b..7c697fa5f87d941 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4099,6 +4099,20 @@ TEST(TransferTest, 
LoopDereferencingChangingRecordPointerConverges) {
   ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
 }
 
+TEST(TransferTest, LoopWithDisjunctiveConditionConverges) {
+  std::string Code = R"cc(
+bool foo();
+
+void target() {
+  bool c = false;
+  while (foo() || foo()) {
+c = true;
+  }
+}
+  )cc";
+  ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
+}
+
 TEST(TransferTest, DoesNotCrashOnUnionThisExpr) {
   std::string Code = R"(
 union Union {
diff --git 
a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
index 2425bb8711bdbaf..6800d736afd9b08 100644
--- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -913,6 +913,34 @@ TEST_F(FlowConditionTest, WhileStmt) {
   });
 }
 
+TEST_F(FlowConditionTest, WhileStmtWithAssignmentInCondition) {
+  std::string Code = R"(
+void target(bool Foo) {
+  // This test checks whether the analysis preserves the connection between
+  // the value of `Foo` and the assignment expression, despite widening.
+  // The equality operator generates a fresh boolean variable on each
+  

[clang] Use the correct namespace for looking up matching operator!= (PR #68922)

2023-10-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Utkarsh Saxena (usx95)


Changes

`S.getScopeForContext` determins the **active** scope associated with the given 
`declContext`. 
This fails to find the matching `operator!=` if candidate `operator==` was 
found via ADL since that scope is not active.

Instead, just directly lookup using the namespace decl of `operator==`

Fixes #68901

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaOverload.cpp (+1-6) 
- (modified) 
clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp (+24) 


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index ce78994e6553814..e1e0b4a888e49fa 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -960,12 +960,7 @@ static bool shouldAddReversedEqEq(Sema , SourceLocation 
OpLoc,
 return true;
   }
   // Otherwise the search scope is the namespace scope of which F is a member.
-  LookupResult NonMembers(S, NotEqOp, OpLoc,
-  Sema::LookupNameKind::LookupOperatorName);
-  S.LookupName(NonMembers,
-   S.getScopeForContext(EqFD->getEnclosingNamespaceContext()));
-  NonMembers.suppressAccessDiagnostics();
-  for (NamedDecl *Op : NonMembers) {
+  for (NamedDecl *Op : EqFD->getEnclosingNamespaceContext()->lookup(NotEqOp)) {
 auto *FD = Op->getAsFunction();
 if(auto* UD = dyn_cast(Op))
   FD = UD->getUnderlyingDecl()->getAsFunction();
diff --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
index 5c6804eb7726b5f..7142ed22ddb22ca 100644
--- a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
@@ -324,6 +324,30 @@ bool x = X() == X(); // expected-warning {{ambiguous}}
 }
 } // namespace P2468R2
 
+namespace ADL_GH68901{
+namespace A {
+struct S {};
+bool operator==(S, int); // expected-note {{no known conversion from 'int' to 
'S' for 1st argument}}
+bool operator!=(S, int);
+} // namespace A
+bool a = 0 == A::S(); // expected-error {{invalid operands to binary 
expression ('int' and 'A::S')}}
+
+namespace B {
+struct Derived {};
+struct Base : Derived {};
+
+bool operator==(Derived& a, Base& b);
+bool operator!=(Derived& a, Base& b);
+}  // namespace B
+
+void foo() {
+  // B::Base{} == B::Base{};
+  B::Base a,b;
+  bool v = a == b;
+}
+} //namespace ADL_GH68901
+
+
 #else // NO_ERRORS
 
 namespace problem_cases {

``




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


[clang] Use the correct namespace for looking up matching operator!= (PR #68922)

2023-10-12 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang][dataflow] Check for backedges directly (instead of loop statements). (PR #68923)

2023-10-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yitzhak Mandelbaum (ymand)


Changes

Widen on backedge nodes, instead of nodes with a loop statement as terminator.
This fixes #67834 and a precision loss from assignment in a loop 
condition. The
commit contains tests for both of these issues.


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


3 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
(+10-20) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+14) 
- (modified) 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp (+28) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 6b167891c1a3ac8..c635edd12219f0e 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -12,7 +12,6 @@
 
//===--===//
 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -33,8 +32,8 @@
 #include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallBitVector.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
 
@@ -53,19 +52,8 @@ static int blockIndexInPredecessor(const CFGBlock ,
   return BlockPos - Pred.succ_begin();
 }
 
-static bool isLoopHead(const CFGBlock ) {
-  if (const auto *T = B.getTerminatorStmt())
-switch (T->getStmtClass()) {
-  case Stmt::WhileStmtClass:
-  case Stmt::DoStmtClass:
-  case Stmt::ForStmtClass:
-  case Stmt::CXXForRangeStmtClass:
-return true;
-  default:
-return false;
-}
-
-  return false;
+static bool isBackedgeNode(const CFGBlock ) {
+ return B.getLoopTarget() != nullptr;
 }
 
 namespace {
@@ -502,14 +490,16 @@ runTypeErasedDataflowAnalysis(
 PostVisitCFG) {
   PrettyStackTraceAnalysis CrashInfo(CFCtx, "runTypeErasedDataflowAnalysis");
 
-  PostOrderCFGView POV(());
-  ForwardDataflowWorklist Worklist(CFCtx.getCFG(), );
+  const clang::CFG  = CFCtx.getCFG();
+  PostOrderCFGView POV();
+  ForwardDataflowWorklist Worklist(CFG, );
+
 
   std::vector> BlockStates(
-  CFCtx.getCFG().size());
+  CFG.size());
 
   // The entry basic block doesn't contain statements so it can be skipped.
-  const CFGBlock  = CFCtx.getCFG().getEntry();
+  const CFGBlock  = CFG.getEntry();
   BlockStates[Entry.getBlockID()] = {Analysis.typeErasedInitialElement(),
  InitEnv.fork()};
   Worklist.enqueueSuccessors();
@@ -553,7 +543,7 @@ runTypeErasedDataflowAnalysis(
 llvm::errs() << "Old Env:\n";
 OldBlockState->Env.dump();
   });
-  if (isLoopHead(*Block)) {
+  if (isBackedgeNode(*Block)) {
 LatticeJoinEffect Effect1 = Analysis.widenTypeErased(
 NewBlockState.Lattice, OldBlockState->Lattice);
 LatticeJoinEffect Effect2 =
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 632632a1b30e78b..7c697fa5f87d941 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4099,6 +4099,20 @@ TEST(TransferTest, 
LoopDereferencingChangingRecordPointerConverges) {
   ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
 }
 
+TEST(TransferTest, LoopWithDisjunctiveConditionConverges) {
+  std::string Code = R"cc(
+bool foo();
+
+void target() {
+  bool c = false;
+  while (foo() || foo()) {
+c = true;
+  }
+}
+  )cc";
+  ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
+}
+
 TEST(TransferTest, DoesNotCrashOnUnionThisExpr) {
   std::string Code = R"(
 union Union {
diff --git 
a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
index 2425bb8711bdbaf..6800d736afd9b08 100644
--- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -913,6 +913,34 @@ TEST_F(FlowConditionTest, WhileStmt) {
   });
 }
 
+TEST_F(FlowConditionTest, WhileStmtWithAssignmentInCondition) {
+  std::string Code = R"(
+void target(bool Foo) {
+  // This test checks whether the analysis preserves the connection between
+  // the value of `Foo` and the assignment expression, despite widening.
+  // The equality operator generates a fresh boolean variable on each
+  // interpretation, which forces use of widening.
+  while ((Foo = (3 == 4))) {
+(void)0;
+

[clang] [clang][dataflow] Check for backedges directly (instead of loop statements). (PR #68923)

2023-10-12 Thread Yitzhak Mandelbaum via cfe-commits

https://github.com/ymand created https://github.com/llvm/llvm-project/pull/68923

Widen on backedge nodes, instead of nodes with a loop statement as terminator.
This fixes #67834 and a precision loss from assignment in a loop condition. The
commit contains tests for both of these issues.


>From da8cacb47b8f80f7ecb1e86f98683be6c54b4e57 Mon Sep 17 00:00:00 2001
From: Yitzhak Mandelbaum 
Date: Thu, 12 Oct 2023 19:35:54 +
Subject: [PATCH] [clang][dataflow] Check for backedges directly (instead of
 loop statements).

Widen on backedge nodes, instead of nodes with a loop statement as terminator.
This fixes #67834 and a precision loss from assignment in a loop condition. The
commit contains tests for both of these issues.
---
 .../TypeErasedDataflowAnalysis.cpp| 30 +++
 .../Analysis/FlowSensitive/TransferTest.cpp   | 14 +
 .../TypeErasedDataflowAnalysisTest.cpp| 28 +
 3 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 6b167891c1a3ac8..c635edd12219f0e 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -12,7 +12,6 @@
 
//===--===//
 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -33,8 +32,8 @@
 #include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallBitVector.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Error.h"
 
@@ -53,19 +52,8 @@ static int blockIndexInPredecessor(const CFGBlock ,
   return BlockPos - Pred.succ_begin();
 }
 
-static bool isLoopHead(const CFGBlock ) {
-  if (const auto *T = B.getTerminatorStmt())
-switch (T->getStmtClass()) {
-  case Stmt::WhileStmtClass:
-  case Stmt::DoStmtClass:
-  case Stmt::ForStmtClass:
-  case Stmt::CXXForRangeStmtClass:
-return true;
-  default:
-return false;
-}
-
-  return false;
+static bool isBackedgeNode(const CFGBlock ) {
+ return B.getLoopTarget() != nullptr;
 }
 
 namespace {
@@ -502,14 +490,16 @@ runTypeErasedDataflowAnalysis(
 PostVisitCFG) {
   PrettyStackTraceAnalysis CrashInfo(CFCtx, "runTypeErasedDataflowAnalysis");
 
-  PostOrderCFGView POV(());
-  ForwardDataflowWorklist Worklist(CFCtx.getCFG(), );
+  const clang::CFG  = CFCtx.getCFG();
+  PostOrderCFGView POV();
+  ForwardDataflowWorklist Worklist(CFG, );
+
 
   std::vector> BlockStates(
-  CFCtx.getCFG().size());
+  CFG.size());
 
   // The entry basic block doesn't contain statements so it can be skipped.
-  const CFGBlock  = CFCtx.getCFG().getEntry();
+  const CFGBlock  = CFG.getEntry();
   BlockStates[Entry.getBlockID()] = {Analysis.typeErasedInitialElement(),
  InitEnv.fork()};
   Worklist.enqueueSuccessors();
@@ -553,7 +543,7 @@ runTypeErasedDataflowAnalysis(
 llvm::errs() << "Old Env:\n";
 OldBlockState->Env.dump();
   });
-  if (isLoopHead(*Block)) {
+  if (isBackedgeNode(*Block)) {
 LatticeJoinEffect Effect1 = Analysis.widenTypeErased(
 NewBlockState.Lattice, OldBlockState->Lattice);
 LatticeJoinEffect Effect2 =
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 632632a1b30e78b..7c697fa5f87d941 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -4099,6 +4099,20 @@ TEST(TransferTest, 
LoopDereferencingChangingRecordPointerConverges) {
   ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
 }
 
+TEST(TransferTest, LoopWithDisjunctiveConditionConverges) {
+  std::string Code = R"cc(
+bool foo();
+
+void target() {
+  bool c = false;
+  while (foo() || foo()) {
+c = true;
+  }
+}
+  )cc";
+  ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
+}
+
 TEST(TransferTest, DoesNotCrashOnUnionThisExpr) {
   std::string Code = R"(
 union Union {
diff --git 
a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
index 2425bb8711bdbaf..6800d736afd9b08 100644
--- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -913,6 +913,34 @@ TEST_F(FlowConditionTest, WhileStmt) {
   });
 }
 
+TEST_F(FlowConditionTest, WhileStmtWithAssignmentInCondition) {
+  std::string Code = R"(
+void target(bool Foo) {
+  // This test checks 

[clang] Use the correct namespace for looking up matching operator!= (PR #68922)

2023-10-12 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/68922

`S.getScopeForContext` determins the **active** scope associated with the given 
`declContext`. 
This fails to find the matching `operator!=` if candidate `operator==` was 
found via ADL since that scope is not active.

Instead, just directly lookup using the namespace decl of `operator==`

Fixes #68901

>From 0c71b6bdd557ff4b9ad9a4ec4f0919e3460596b0 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 12 Oct 2023 21:35:52 +0200
Subject: [PATCH] Find opertor!= in the correct namespace

---
 clang/lib/Sema/SemaOverload.cpp   |  7 +-
 .../over.match.oper/p3-2a.cpp | 24 +++
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index ce78994e6553814..e1e0b4a888e49fa 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -960,12 +960,7 @@ static bool shouldAddReversedEqEq(Sema , SourceLocation 
OpLoc,
 return true;
   }
   // Otherwise the search scope is the namespace scope of which F is a member.
-  LookupResult NonMembers(S, NotEqOp, OpLoc,
-  Sema::LookupNameKind::LookupOperatorName);
-  S.LookupName(NonMembers,
-   S.getScopeForContext(EqFD->getEnclosingNamespaceContext()));
-  NonMembers.suppressAccessDiagnostics();
-  for (NamedDecl *Op : NonMembers) {
+  for (NamedDecl *Op : EqFD->getEnclosingNamespaceContext()->lookup(NotEqOp)) {
 auto *FD = Op->getAsFunction();
 if(auto* UD = dyn_cast(Op))
   FD = UD->getUnderlyingDecl()->getAsFunction();
diff --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
index 5c6804eb7726b5f..7142ed22ddb22ca 100644
--- a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
@@ -324,6 +324,30 @@ bool x = X() == X(); // expected-warning {{ambiguous}}
 }
 } // namespace P2468R2
 
+namespace ADL_GH68901{
+namespace A {
+struct S {};
+bool operator==(S, int); // expected-note {{no known conversion from 'int' to 
'S' for 1st argument}}
+bool operator!=(S, int);
+} // namespace A
+bool a = 0 == A::S(); // expected-error {{invalid operands to binary 
expression ('int' and 'A::S')}}
+
+namespace B {
+struct Derived {};
+struct Base : Derived {};
+
+bool operator==(Derived& a, Base& b);
+bool operator!=(Derived& a, Base& b);
+}  // namespace B
+
+void foo() {
+  // B::Base{} == B::Base{};
+  B::Base a,b;
+  bool v = a == b;
+}
+} //namespace ADL_GH68901
+
+
 #else // NO_ERRORS
 
 namespace problem_cases {

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


[clang] [AMDGPU] Change the representation of double literals in operands (PR #68740)

2023-10-12 Thread Stanislav Mekhanoshin via cfe-commits

https://github.com/rampitec updated 
https://github.com/llvm/llvm-project/pull/68740

>From cc9e065a9218eb36750a2c2a4a4d08fae3f329fa Mon Sep 17 00:00:00 2001
From: Stanislav Mekhanoshin 
Date: Wed, 4 Oct 2023 13:36:25 -0700
Subject: [PATCH 1/6] [AMDGPU] Change the representation of double literals in
 operands

A 64-bit literal can be used as a 32-bit zero or sign extended
operand. In case of double zeroes are added to the low 32 bits.
Currently asm parser stores only high 32 bits of a double into
an operand. To support codegen as requested by the
https://github.com/llvm/llvm-project/issues/67781 we need to
change the representation to store a full 64-bit value so that
codegen can simply add immediates to an instruction.

There is some code to support compatibility with existing tests
and asm kernels. We allow to use short hex strings to represent
only a high 32 bit of a double value as a valid literal.
---
 .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp  | 21 --
 .../Disassembler/AMDGPUDisassembler.cpp   | 28 ++-
 .../AMDGPU/Disassembler/AMDGPUDisassembler.h  |  9 --
 .../AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp | 12 +---
 .../AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h   |  2 +-
 .../MCTargetDesc/AMDGPUMCCodeEmitter.cpp  |  3 ++
 llvm/lib/Target/AMDGPU/SIRegisterInfo.td  |  4 ++-
 .../Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp|  7 +
 llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h |  3 ++
 9 files changed, 70 insertions(+), 19 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp 
b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
index 35656bcaea1af7f..0553d3f20b21c56 100644
--- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -2140,9 +2140,10 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst , 
int64_t Val, bool ApplyMo
   const_cast(AsmParser)->Warning(Inst.getLoc(),
   "Can't encode literal as exact 64-bit floating-point operand. "
   "Low 32-bits will be set to zero");
+  Val &= 0xu;
 }
 
-Inst.addOperand(MCOperand::createImm(Literal.lshr(32).getZExtValue()));
+Inst.addOperand(MCOperand::createImm(Val));
 setImmKindLiteral();
 return;
   }
@@ -2241,7 +2242,10 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst , 
int64_t Val, bool ApplyMo
   return;
 }
 
-Inst.addOperand(MCOperand::createImm(Lo_32(Val)));
+if (isInt<32>(Val) || isUInt<32>(Val))
+  Val = AMDGPU::isSISrcFPOperand(InstDesc, OpNum) ? Val << 32 : Lo_32(Val);
+
+Inst.addOperand(MCOperand::createImm(Val));
 setImmKindLiteral();
 return;
 
@@ -4297,7 +4301,18 @@ bool AMDGPUAsmParser::validateVOPLiteral(const MCInst 
,
   continue;
 
 if (MO.isImm() && !isInlineConstant(Inst, OpIdx)) {
-  uint32_t Value = static_cast(MO.getImm());
+  uint64_t Value = static_cast(MO.getImm());
+  bool IsFP = AMDGPU::isSISrcFPOperand(Desc, OpIdx);
+  bool IsValid32Op = AMDGPU::isValid32BitLiteral(Value, IsFP);
+
+  if (!IsValid32Op && !isInt<32>(Value) && !isUInt<32>(Value)) {
+Error(getLitLoc(Operands), "invalid operand for instruction");
+return false;
+  }
+
+  if (IsFP && IsValid32Op)
+Value = Hi_32(Value);
+
   if (NumLiterals == 0 || LiteralValue != Value) {
 LiteralValue = Value;
 ++NumLiterals;
diff --git a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp 
b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
index 439762bc6caf786..8c49c9a9c87772e 100644
--- a/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
+++ b/llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
@@ -378,6 +378,15 @@ static DecodeStatus decodeOperand_AVLdSt_Any(MCInst , 
unsigned Imm,
   return addOperand(Inst, DAsm->decodeSrcOp(Opw, Imm | 256));
 }
 
+static DecodeStatus
+decodeOperand_VSrc_f64(MCInst , unsigned Imm, uint64_t Addr,
+   const MCDisassembler *Decoder) {
+  assert(Imm < (1 << 9) && "9-bit encoding");
+  auto DAsm = static_cast(Decoder);
+  return addOperand(Inst, DAsm->decodeSrcOp(AMDGPUDisassembler::OPW64, Imm,
+false, 64, true));
+}
+
 static DecodeStatus
 DecodeAVLdSt_32RegisterClass(MCInst , unsigned Imm, uint64_t Addr,
  const MCDisassembler *Decoder) {
@@ -1218,7 +1227,7 @@ 
AMDGPUDisassembler::decodeMandatoryLiteralConstant(unsigned Val) const {
   return MCOperand::createImm(Literal);
 }
 
-MCOperand AMDGPUDisassembler::decodeLiteralConstant() const {
+MCOperand AMDGPUDisassembler::decodeLiteralConstant(bool ExtendFP64) const {
   // For now all literal constants are supposed to be unsigned integer
   // ToDo: deal with signed/unsigned 64-bit integer constants
   // ToDo: deal with float/double constants
@@ -1228,9 +1237,11 @@ MCOperand AMDGPUDisassembler::decodeLiteralConstant() 
const {
   

[clang] [AMDGPU] Change the representation of double literals in operands (PR #68740)

2023-10-12 Thread Stanislav Mekhanoshin via cfe-commits

rampitec wrote:

> LGTM modulo one remaining comment about validateVOPLiteral.

Done.

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


[clang] [PowerPC] Fix use of FPSCR builtins in smmintrin.h (PR #67299)

2023-10-12 Thread Nemanja Ivanovic via cfe-commits


@@ -11595,6 +11595,50 @@ SDValue PPCTargetLowering::LowerFP_EXTEND(SDValue Op, 
SelectionDAG ) const {
   llvm_unreachable("ERROR:Should return for all cases within swtich.");
 }
 
+// Lower mffsl intrinsic with mffs in targets without ISA 3.0
+static SDValue lowerMFFSL(SDValue Op, SelectionDAG ,

nemanjai wrote:

I wonder if we actually need this. The reason `mffsl` exists is because it is a 
lightweight version of `mffs`. In order to make it lightweight, the instruction 
only extracts some bits from the FPSCR.
So in order to match the semantics, we end up doing the heavy weight 
instruction, materializing a 64-bit constant, moving to a GPR, masking out the 
bits and then moving it back to an FPR. So a user's attempt to use the 
lightweight version ends up costing them more than the heavy weight version on 
older CPU's.
Can we not just reject it on older CPU's and force the user to use the heavy 
weight instruction?

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


[clang] [IRPGO][ValueProfile] Instrument virtual table address that could be used to do virtual table address comparision for indirect-call-promotion. (PR #66825)

2023-10-12 Thread David Li via cfe-commits

david-xl wrote:

The performance win depends a lot on value distribution.  For large copies, 
using SIMD with nontemporal hint is the way to go.

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


[clang] [HLSL] Support vector swizzles on scalars (PR #67700)

2023-10-12 Thread via cfe-commits

cor3ntin wrote:

This is the documentation i found.
Can you confirm the intent is only to support `.x???` and `r???` ?
It alludes to more options.
Maybe we need a `isHLSLSwizzleStart` function to avoid comparing to `'x'` and 
`'r'` in multiple places.

https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx9-graphics-reference-asm-vs-registers-modifiers-source-swizzling
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx9-graphics-reference-asm-ps-registers-modifiers-source-register-swizzling
  

I don't suppose there is a specification / grammar for these things?

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


[clang] Let clang-cl support CUDA/HIP (PR #68921)

2023-10-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yaxun (Sam) Liu (yxsamliu)


Changes

clang-cl is a driver mode that accepts options of MSVC cl.exe as a drop-in 
replacement for cl.exe. Currently clang-cl accepts mixed clang style options 
and cl style options. To let clang-cl accept a clang-style option, just need to 
add visibility CLOption to that option.

Currently nvcc can pass cl style options to cl.exe, which allows nvcc to 
compile C++ and CUDA programs with mixed nvcc and cl style options. On the 
other hand, clang cannot use mixed clang and cl style options to compile 
CUDA/HIP programs.

This patch add visibility CLOption to options needed to compile CUDA/HIP 
programs. This allows clang-cl to compile CUDA/HIP programs with mixed clang 
and cl style options.

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


3 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+30-17) 
- (modified) clang/lib/Driver/Driver.cpp (+4-1) 
- (added) clang/test/Driver/cl-offload.cu (+27) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3f2058a5d4650ca..ceeb4c5e7c424cf 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -148,7 +148,8 @@ def pedantic_Group : OptionGroup<"">, 
Group,
  DocFlatten;
 
 def offload_Group : OptionGroup<"">, Group,
-   DocName<"Common Offloading options">;
+   DocName<"Common Offloading options">,
+   Visibility<[ClangOption, CLOption]>;
 
 def opencl_Group : OptionGroup<"">, Group,
DocName<"OpenCL options">;
@@ -157,13 +158,16 @@ def sycl_Group : OptionGroup<"">, 
Group,
  DocName<"SYCL options">;
 
 def cuda_Group : OptionGroup<"">, Group,
-   DocName<"CUDA options">;
+   DocName<"CUDA options">,
+   Visibility<[ClangOption, CLOption]>;
 
 def hip_Group : OptionGroup<"">, Group,
-   DocName<"HIP options">;
+   DocName<"HIP options">,
+   Visibility<[ClangOption, CLOption]>;
 
 def m_Group : OptionGroup<"">, Group,
-  DocName<"Target-dependent compilation options">;
+  DocName<"Target-dependent compilation options">,
+  Visibility<[ClangOption, CLOption]>;
 
 // Feature groups - these take command line options that correspond directly to
 // target specific features and can be translated directly from command line
@@ -5164,14 +5168,16 @@ def prebind__all__twolevel__modules : Flag<["-"], 
"prebind_all_twolevel_modules"
 def prebind : Flag<["-"], "prebind">;
 def preload : Flag<["-"], "preload">;
 def print_file_name_EQ : Joined<["-", "--"], "print-file-name=">,
-  HelpText<"Print the full library path of ">, MetaVarName<"">;
+  HelpText<"Print the full library path of ">, MetaVarName<"">,
+  Visibility<[ClangOption, CLOption]>;
 def print_ivar_layout : Flag<["-"], "print-ivar-layout">,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Enable Objective-C Ivar layout bitmap print trace">,
   MarshallingInfoFlag>;
 def print_libgcc_file_name : Flag<["-", "--"], "print-libgcc-file-name">,
   HelpText<"Print the library path for the currently used compiler runtime "
-   "library (\"libgcc.a\" or \"libclang_rt.builtins.*.a\")">;
+   "library (\"libgcc.a\" or \"libclang_rt.builtins.*.a\")">,
+  Visibility<[ClangOption, CLOption]>;
 def print_multi_directory : Flag<["-", "--"], "print-multi-directory">;
 def print_multi_lib : Flag<["-", "--"], "print-multi-lib">;
 def print_multi_flags : Flag<["-", "--"], "print-multi-flags-experimental">,
@@ -5180,27 +5186,34 @@ def print_multi_os_directory : Flag<["-", "--"], 
"print-multi-os-directory">,
   Flags<[Unsupported]>;
 def print_target_triple : Flag<["-", "--"], "print-target-triple">,
   HelpText<"Print the normalized target triple">,
-  Visibility<[ClangOption, FlangOption]>;
+  Visibility<[ClangOption, FlangOption, CLOption]>;
 def print_effective_triple : Flag<["-", "--"], "print-effective-triple">,
   HelpText<"Print the effective target triple">,
-  Visibility<[ClangOption, FlangOption]>;
+  Visibility<[ClangOption, FlangOption, CLOption]>;
 // GCC --disable-multiarch, GCC --enable-multiarch (upstream and Debian
 // specific) have different behaviors. We choose not to support the option.
 def : Flag<["-", "--"], "print-multiarch">, Flags<[Unsupported]>;
 def print_prog_name_EQ : Joined<["-", "--"], "print-prog-name=">,
-  HelpText<"Print the full program path of ">, MetaVarName<"">;
+  HelpText<"Print the full program path of ">, MetaVarName<"">,
+  Visibility<[ClangOption, CLOption]>;
 def print_resource_dir : Flag<["-", "--"], "print-resource-dir">,
-  HelpText<"Print the resource directory pathname">;
+  HelpText<"Print the resource directory pathname">,
+  Visibility<[ClangOption, CLOption]>;
 def print_search_dirs : Flag<["-", "--"], 

[clang] Let clang-cl support CUDA/HIP (PR #68921)

2023-10-12 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu created 
https://github.com/llvm/llvm-project/pull/68921

clang-cl is a driver mode that accepts options of MSVC cl.exe as a drop-in 
replacement for cl.exe. Currently clang-cl accepts mixed clang style options 
and cl style options. To let clang-cl accept a clang-style option, just need to 
add visibility CLOption to that option.

Currently nvcc can pass cl style options to cl.exe, which allows nvcc to 
compile C++ and CUDA programs with mixed nvcc and cl style options. On the 
other hand, clang cannot use mixed clang and cl style options to compile 
CUDA/HIP programs.

This patch add visibility CLOption to options needed to compile CUDA/HIP 
programs. This allows clang-cl to compile CUDA/HIP programs with mixed clang 
and cl style options.

>From d185724b60430229ae8ad1011d973201edbe09c8 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Thu, 12 Oct 2023 12:21:29 -0400
Subject: [PATCH] Let clang-cl support CUDA/HIP

clang-cl is a driver mode that accepts options of MSVC cl.exe as a drop-in
replacement for cl.exe. Currently clang-cl accepts mixed clang style options
and cl style options. To let clang-cl accept a clang-style option, just
need to add visibility CLOption to that option.

Currently nvcc can pass cl style options to cl.exe, which allows nvcc to
compile C++ and CUDA programs with mixed nvcc and cl style options. On
the other hand, clang cannot use mixed clang and cl style options to compile
CUDA/HIP programs.

This patch add visibility CLOption to options needed to compile CUDA/HIP
programs. This allows clang-cl to compile CUDA/HIP programs with mixed
clang and cl style options.
---
 clang/include/clang/Driver/Options.td | 47 +--
 clang/lib/Driver/Driver.cpp   |  5 ++-
 clang/test/Driver/cl-offload.cu   | 27 +++
 3 files changed, 61 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/Driver/cl-offload.cu

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3f2058a5d4650ca..ceeb4c5e7c424cf 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -148,7 +148,8 @@ def pedantic_Group : OptionGroup<"">, 
Group,
  DocFlatten;
 
 def offload_Group : OptionGroup<"">, Group,
-   DocName<"Common Offloading options">;
+   DocName<"Common Offloading options">,
+   Visibility<[ClangOption, CLOption]>;
 
 def opencl_Group : OptionGroup<"">, Group,
DocName<"OpenCL options">;
@@ -157,13 +158,16 @@ def sycl_Group : OptionGroup<"">, 
Group,
  DocName<"SYCL options">;
 
 def cuda_Group : OptionGroup<"">, Group,
-   DocName<"CUDA options">;
+   DocName<"CUDA options">,
+   Visibility<[ClangOption, CLOption]>;
 
 def hip_Group : OptionGroup<"">, Group,
-   DocName<"HIP options">;
+   DocName<"HIP options">,
+   Visibility<[ClangOption, CLOption]>;
 
 def m_Group : OptionGroup<"">, Group,
-  DocName<"Target-dependent compilation options">;
+  DocName<"Target-dependent compilation options">,
+  Visibility<[ClangOption, CLOption]>;
 
 // Feature groups - these take command line options that correspond directly to
 // target specific features and can be translated directly from command line
@@ -5164,14 +5168,16 @@ def prebind__all__twolevel__modules : Flag<["-"], 
"prebind_all_twolevel_modules"
 def prebind : Flag<["-"], "prebind">;
 def preload : Flag<["-"], "preload">;
 def print_file_name_EQ : Joined<["-", "--"], "print-file-name=">,
-  HelpText<"Print the full library path of ">, MetaVarName<"">;
+  HelpText<"Print the full library path of ">, MetaVarName<"">,
+  Visibility<[ClangOption, CLOption]>;
 def print_ivar_layout : Flag<["-"], "print-ivar-layout">,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Enable Objective-C Ivar layout bitmap print trace">,
   MarshallingInfoFlag>;
 def print_libgcc_file_name : Flag<["-", "--"], "print-libgcc-file-name">,
   HelpText<"Print the library path for the currently used compiler runtime "
-   "library (\"libgcc.a\" or \"libclang_rt.builtins.*.a\")">;
+   "library (\"libgcc.a\" or \"libclang_rt.builtins.*.a\")">,
+  Visibility<[ClangOption, CLOption]>;
 def print_multi_directory : Flag<["-", "--"], "print-multi-directory">;
 def print_multi_lib : Flag<["-", "--"], "print-multi-lib">;
 def print_multi_flags : Flag<["-", "--"], "print-multi-flags-experimental">,
@@ -5180,27 +5186,34 @@ def print_multi_os_directory : Flag<["-", "--"], 
"print-multi-os-directory">,
   Flags<[Unsupported]>;
 def print_target_triple : Flag<["-", "--"], "print-target-triple">,
   HelpText<"Print the normalized target triple">,
-  Visibility<[ClangOption, FlangOption]>;
+  Visibility<[ClangOption, FlangOption, CLOption]>;
 def print_effective_triple : Flag<["-", "--"], 

[clang] [RISCV] Implement shadow stack on shadow stack mode with Zicfiss. (PR #68075)

2023-10-12 Thread Sami Tolvanen via cfe-commits

samitolvanen wrote:

The patch basically changes the ShadowCallStack back-end to emit an 
sspush/sspopchk instead of the usual SCS push/pop, which seems like a 
reasonable approach to me. However, it would be helpful to mention the 
dependency on `-fsanitize=shadow-call-stack` in the commit message, and you 
should also update [the 
documentation](https://clang.llvm.org/docs/ShadowCallStack.html).

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


[clang] [PowerPC][X86] Make cpu id builtins target independent and lower for PPC (PR #68919)

2023-10-12 Thread Nemanja Ivanovic via cfe-commits

https://github.com/nemanjai updated 
https://github.com/llvm/llvm-project/pull/68919

>From 71f1352bf00d6a9eefa3f199859d47d093f272f8 Mon Sep 17 00:00:00 2001
From: Nemanja Ivanovic 
Date: Thu, 12 Oct 2023 14:08:42 -0400
Subject: [PATCH 1/2] [PowerPC][X86] Make cpu id builtins target independent
 and lower for PPC

Make __builtin_cpu_{init|supports|is} target independent and provide
an opt-in query for targets that want to support it. Each target is
still responsible for their specific lowering/code-gen.
Also provide code-gen for PowerPC.
---
 clang/include/clang/Basic/Builtins.def|   5 +
 clang/include/clang/Basic/BuiltinsX86.def |   7 -
 clang/include/clang/Basic/TargetInfo.h|   6 +
 clang/lib/Basic/Targets/PPC.cpp   |  14 ++
 clang/lib/Basic/Targets/PPC.h |   7 +
 clang/lib/Basic/Targets/X86.h |   4 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  42 +-
 clang/lib/Sema/SemaChecking.cpp   | 124 +++---
 clang/test/CodeGen/builtin-cpu-supports.c |  68 ++
 clang/test/Sema/builtin-cpu-supports.c|   8 +-
 llvm/include/llvm/IR/IntrinsicsPowerPC.td |   6 +
 .../llvm/TargetParser/PPCTargetParser.def |  80 +++
 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp |   4 +
 llvm/lib/Target/PowerPC/PPCInstrInfo.cpp  |  33 +
 llvm/lib/Target/PowerPC/PPCInstrInfo.td   |   3 +
 llvm/lib/Target/PowerPC/PPCTargetMachine.h|   3 +
 llvm/test/CodeGen/PowerPC/cpu-supports.ll | 111 
 17 files changed, 443 insertions(+), 82 deletions(-)
 create mode 100644 llvm/include/llvm/TargetParser/PPCTargetParser.def
 create mode 100644 llvm/test/CodeGen/PowerPC/cpu-supports.ll

diff --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 6ea8484606cfd5d..5e1f4088ff63f8a 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -118,6 +118,11 @@
 #  define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
 #endif
 
+// Builtins for checking CPU features based on the GCC builtins.
+BUILTIN(__builtin_cpu_supports, "bcC*", "nc")
+BUILTIN(__builtin_cpu_is, "bcC*", "nc")
+BUILTIN(__builtin_cpu_init, "v", "n")
+
 // Standard libc/libm functions:
 BUILTIN(__builtin_atan2 , "ddd"  , "Fne")
 BUILTIN(__builtin_atan2f, "fff"  , "Fne")
diff --git a/clang/include/clang/Basic/BuiltinsX86.def 
b/clang/include/clang/Basic/BuiltinsX86.def
index e4802f8ab1c1562..2acc5ce0f4a3653 100644
--- a/clang/include/clang/Basic/BuiltinsX86.def
+++ b/clang/include/clang/Basic/BuiltinsX86.def
@@ -26,13 +26,6 @@
 #  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) 
BUILTIN(ID, TYPE, ATTRS)
 #endif
 
-// Miscellaneous builtin for checking x86 cpu features.
-// TODO: Make this somewhat generic so that other backends
-// can use it?
-BUILTIN(__builtin_cpu_init, "v", "n")
-BUILTIN(__builtin_cpu_supports, "bcC*", "nc")
-BUILTIN(__builtin_cpu_is, "bcC*", "nc")
-
 // Undefined Values
 //
 TARGET_BUILTIN(__builtin_ia32_undef128, "V2d", "ncV:128:", "")
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9d56e97a3d4bb88..3d83b387aac0931 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1415,6 +1415,12 @@ class TargetInfo : public TransferrableTargetInfo,
 getTriple().isOSFreeBSD());
   }
 
+  // Identify whether this target supports __builtin_cpu_supports and
+  // __builtin_cpu_is.
+  virtual bool supportsCpuSupports() const { return false; }
+  virtual bool supportsCpuIs() const { return false; }
+  virtual bool supportsCpuInit() const { return false; }
+
   // Validate the contents of the __builtin_cpu_supports(const char*)
   // argument.
   virtual bool validateCpuSupports(StringRef Name) const { return false; }
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 0d87a3a4e8c20f3..d8759c86c9932ca 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -873,3 +873,17 @@ ArrayRef PPCTargetInfo::getTargetBuiltins() 
const {
   return llvm::ArrayRef(BuiltinInfo,
 clang::PPC::LastTSBuiltin - Builtin::FirstTSBuiltin);
 }
+
+bool PPCTargetInfo::validateCpuSupports(StringRef FeatureStr) const {
+#define PPC_FEATURE(NAME, DESC, ENUMNAME, ENUMVAL, HWCAPN) .Case(NAME, true)
+  return llvm::StringSwitch(FeatureStr)
+#include "llvm/TargetParser/PPCTargetParser.def"
+  .Default(false);
+}
+
+bool PPCTargetInfo::validateCpuIs(StringRef CPUName) const {
+#define PPC_CPU(NAME, NUM) .Case(NAME, true)
+  return llvm::StringSwitch(CPUName)
+#include "llvm/TargetParser/PPCTargetParser.def"
+  .Default(false);
+}
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index 4d62673ba7fb8c5..f700b625b790309 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -359,6 +359,13 

[clang] [HLSL] Support vector swizzles on scalars (PR #67700)

2023-10-12 Thread via cfe-commits


@@ -930,7 +930,11 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   // and FP constants (specifically, the 'pp-number' regex), and assumes that
   // the byte at "*end" is both valid and not part of the regex.  Because of
   // this, it doesn't have to check for 'overscan' in various places.
-  if (isPreprocessingNumberBody(*ThisTokEnd)) {
+  // Note: For HLSL, the end token is allowed to be '.' which would be in the
+  // 'pp-number' regex. This is required to support vector swizzles on numeric
+  // constants (i.e. 1.xx or 1.5f.rrr).
+  if (isPreprocessingNumberBody(*ThisTokEnd) &&
+  !(LangOpts.HLSL && *ThisTokEnd == '.')) {

cor3ntin wrote:

This looks fine to me - if a bit hackish.

What surprises me is that the `if` existed at all before the change.

`LexNumericConstant` would have consumed everything it could. There should 
*never* be a valid pp-number after.

We should be able to write something like
```cpp
assert(!isPreprocessingNumberBody(*ThisTokEnd) || (LangOpts.HLS && *ThisTokEnd 
== '.'))
```

and remove that `if`  / diagnostic (which is never tested)





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


[clang] [HLSL] Support vector swizzles on scalars (PR #67700)

2023-10-12 Thread via cfe-commits


@@ -1950,6 +1950,10 @@ bool Lexer::LexNumericConstant(Token , const char 
*CurPtr) {
   while (isPreprocessingNumberBody(C)) {
 CurPtr = ConsumeChar(CurPtr, Size, Result);
 PrevCh = C;
+if (LangOpts.HLSL && C == '.' && (*CurPtr == 'x' || *CurPtr == 'r')) {
+  CurPtr--;

cor3ntin wrote:

Indeed!

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


[clang] [PowerPC][X86] Make cpu id builtins target independent and lower for PPC (PR #68919)

2023-10-12 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 dd0f642e6ec5049ccabe3f462cc427ffe213829b 
71f1352bf00d6a9eefa3f199859d47d093f272f8 -- 
clang/include/clang/Basic/TargetInfo.h clang/lib/Basic/Targets/PPC.cpp 
clang/lib/Basic/Targets/PPC.h clang/lib/Basic/Targets/X86.h 
clang/lib/CodeGen/CGBuiltin.cpp clang/lib/Sema/SemaChecking.cpp 
clang/test/CodeGen/builtin-cpu-supports.c 
clang/test/Sema/builtin-cpu-supports.c 
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp 
llvm/lib/Target/PowerPC/PPCInstrInfo.cpp 
llvm/lib/Target/PowerPC/PPCTargetMachine.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 583b2be69..c5920216e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -16093,8 +16093,7 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 #define PPC_CPU(Name, NumericID) .Case(Name, NumericID)
 #include "llvm/TargetParser/PPCTargetParser.def"
 .Default(-1U);
-Value *Op0 =
-llvm::ConstantInt::get(Int32Ty, PPC_FAWORD_CPUID);
+Value *Op0 = llvm::ConstantInt::get(Int32Ty, PPC_FAWORD_CPUID);
 llvm::Function *F = CGM.getIntrinsic(Intrinsic::ppc_fixed_addr_ld);
 Value *TheCall = Builder.CreateCall(F, {Op0}, "cpu_is");
 return Builder.CreateICmpEQ(TheCall,
diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp 
b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
index 7d4cdd8be..79123cedd 100644
--- a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
+++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
@@ -3139,10 +3139,8 @@ bool PPCInstrInfo::expandPostRAPseudo(MachineInstr ) 
const {
 if ((FAType == PPC_FAWORD_HWCAP && Subtarget.isLittleEndian()) ||
 (FAType == PPC_FAWORD_HWCAP2 && !Subtarget.isLittleEndian()))
   Offset = Subtarget.isPPC64() ? -0x7064 : -0x703C;
-else if ((FAType == PPC_FAWORD_HWCAP2 &&
-  Subtarget.isLittleEndian()) ||
- (FAType == PPC_FAWORD_HWCAP &&
-  !Subtarget.isLittleEndian()))
+else if ((FAType == PPC_FAWORD_HWCAP2 && Subtarget.isLittleEndian()) ||
+ (FAType == PPC_FAWORD_HWCAP && !Subtarget.isLittleEndian()))
   Offset = Subtarget.isPPC64() ? -0x7068 : -0x7040;
 else if (FAType == PPC_FAWORD_CPUID)
   Offset = Subtarget.isPPC64() ? -0x705C : -0x7034;

``




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


[PATCH] D152914: [Draft] Make __builtin_cpu builtins target-independent

2023-10-12 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

In D152914#4653669 , @lei wrote:

> HI @nemanjai, Did you get a chance to post this as a github PR?

Long overdue, but I finally have it up at 
https://github.com/llvm/llvm-project/pull/68919


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152914

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


[clang] [PowerPC][X86] Make cpu id builtins target independent and lower for PPC (PR #68919)

2023-10-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nemanja Ivanovic (nemanjai)


Changes

Make __builtin_cpu_{init|supports|is} target independent and provide an opt-in 
query for targets that want to support it. Each target is still responsible for 
their specific lowering/code-gen. Also provide code-gen for PowerPC.

I originally proposed this in https://reviews.llvm.org/D152914 and this 
addresses the comments I received there.

---

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


17 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.def (+5) 
- (modified) clang/include/clang/Basic/BuiltinsX86.def (-7) 
- (modified) clang/include/clang/Basic/TargetInfo.h (+6) 
- (modified) clang/lib/Basic/Targets/PPC.cpp (+14) 
- (modified) clang/lib/Basic/Targets/PPC.h (+7) 
- (modified) clang/lib/Basic/Targets/X86.h (+4) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+39-3) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+77-47) 
- (modified) clang/test/CodeGen/builtin-cpu-supports.c (+46-22) 
- (modified) clang/test/Sema/builtin-cpu-supports.c (+5-3) 
- (modified) llvm/include/llvm/IR/IntrinsicsPowerPC.td (+6) 
- (added) llvm/include/llvm/TargetParser/PPCTargetParser.def (+80) 
- (modified) llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp (+4) 
- (modified) llvm/lib/Target/PowerPC/PPCInstrInfo.cpp (+33) 
- (modified) llvm/lib/Target/PowerPC/PPCInstrInfo.td (+3) 
- (modified) llvm/lib/Target/PowerPC/PPCTargetMachine.h (+3) 
- (added) llvm/test/CodeGen/PowerPC/cpu-supports.ll (+111) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 6ea8484606cfd5d..5e1f4088ff63f8a 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -118,6 +118,11 @@
 #  define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
 #endif
 
+// Builtins for checking CPU features based on the GCC builtins.
+BUILTIN(__builtin_cpu_supports, "bcC*", "nc")
+BUILTIN(__builtin_cpu_is, "bcC*", "nc")
+BUILTIN(__builtin_cpu_init, "v", "n")
+
 // Standard libc/libm functions:
 BUILTIN(__builtin_atan2 , "ddd"  , "Fne")
 BUILTIN(__builtin_atan2f, "fff"  , "Fne")
diff --git a/clang/include/clang/Basic/BuiltinsX86.def 
b/clang/include/clang/Basic/BuiltinsX86.def
index e4802f8ab1c1562..2acc5ce0f4a3653 100644
--- a/clang/include/clang/Basic/BuiltinsX86.def
+++ b/clang/include/clang/Basic/BuiltinsX86.def
@@ -26,13 +26,6 @@
 #  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) 
BUILTIN(ID, TYPE, ATTRS)
 #endif
 
-// Miscellaneous builtin for checking x86 cpu features.
-// TODO: Make this somewhat generic so that other backends
-// can use it?
-BUILTIN(__builtin_cpu_init, "v", "n")
-BUILTIN(__builtin_cpu_supports, "bcC*", "nc")
-BUILTIN(__builtin_cpu_is, "bcC*", "nc")
-
 // Undefined Values
 //
 TARGET_BUILTIN(__builtin_ia32_undef128, "V2d", "ncV:128:", "")
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9d56e97a3d4bb88..3d83b387aac0931 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1415,6 +1415,12 @@ class TargetInfo : public TransferrableTargetInfo,
 getTriple().isOSFreeBSD());
   }
 
+  // Identify whether this target supports __builtin_cpu_supports and
+  // __builtin_cpu_is.
+  virtual bool supportsCpuSupports() const { return false; }
+  virtual bool supportsCpuIs() const { return false; }
+  virtual bool supportsCpuInit() const { return false; }
+
   // Validate the contents of the __builtin_cpu_supports(const char*)
   // argument.
   virtual bool validateCpuSupports(StringRef Name) const { return false; }
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 0d87a3a4e8c20f3..d8759c86c9932ca 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -873,3 +873,17 @@ ArrayRef PPCTargetInfo::getTargetBuiltins() 
const {
   return llvm::ArrayRef(BuiltinInfo,
 clang::PPC::LastTSBuiltin - Builtin::FirstTSBuiltin);
 }
+
+bool PPCTargetInfo::validateCpuSupports(StringRef FeatureStr) const {
+#define PPC_FEATURE(NAME, DESC, ENUMNAME, ENUMVAL, HWCAPN) .Case(NAME, true)
+  return llvm::StringSwitch(FeatureStr)
+#include "llvm/TargetParser/PPCTargetParser.def"
+  .Default(false);
+}
+
+bool PPCTargetInfo::validateCpuIs(StringRef CPUName) const {
+#define PPC_CPU(NAME, NUM) .Case(NAME, true)
+  return llvm::StringSwitch(CPUName)
+#include "llvm/TargetParser/PPCTargetParser.def"
+  .Default(false);
+}
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index 4d62673ba7fb8c5..f700b625b790309 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -359,6 +359,13 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   bool isSPRegName(StringRef RegName) const override {
 return 

[clang] [PowerPC][X86] Make cpu id builtins target independent and lower for PPC (PR #68919)

2023-10-12 Thread Nemanja Ivanovic via cfe-commits

https://github.com/nemanjai created 
https://github.com/llvm/llvm-project/pull/68919

Make __builtin_cpu_{init|supports|is} target independent and provide an opt-in 
query for targets that want to support it. Each target is still responsible for 
their specific lowering/code-gen. Also provide code-gen for PowerPC.

I originally proposed this in https://reviews.llvm.org/D152914 and this 
addresses the comments I received there.

>From 71f1352bf00d6a9eefa3f199859d47d093f272f8 Mon Sep 17 00:00:00 2001
From: Nemanja Ivanovic 
Date: Thu, 12 Oct 2023 14:08:42 -0400
Subject: [PATCH] [PowerPC][X86] Make cpu id builtins target independent and
 lower for PPC

Make __builtin_cpu_{init|supports|is} target independent and provide
an opt-in query for targets that want to support it. Each target is
still responsible for their specific lowering/code-gen.
Also provide code-gen for PowerPC.
---
 clang/include/clang/Basic/Builtins.def|   5 +
 clang/include/clang/Basic/BuiltinsX86.def |   7 -
 clang/include/clang/Basic/TargetInfo.h|   6 +
 clang/lib/Basic/Targets/PPC.cpp   |  14 ++
 clang/lib/Basic/Targets/PPC.h |   7 +
 clang/lib/Basic/Targets/X86.h |   4 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  42 +-
 clang/lib/Sema/SemaChecking.cpp   | 124 +++---
 clang/test/CodeGen/builtin-cpu-supports.c |  68 ++
 clang/test/Sema/builtin-cpu-supports.c|   8 +-
 llvm/include/llvm/IR/IntrinsicsPowerPC.td |   6 +
 .../llvm/TargetParser/PPCTargetParser.def |  80 +++
 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp |   4 +
 llvm/lib/Target/PowerPC/PPCInstrInfo.cpp  |  33 +
 llvm/lib/Target/PowerPC/PPCInstrInfo.td   |   3 +
 llvm/lib/Target/PowerPC/PPCTargetMachine.h|   3 +
 llvm/test/CodeGen/PowerPC/cpu-supports.ll | 111 
 17 files changed, 443 insertions(+), 82 deletions(-)
 create mode 100644 llvm/include/llvm/TargetParser/PPCTargetParser.def
 create mode 100644 llvm/test/CodeGen/PowerPC/cpu-supports.ll

diff --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 6ea8484606cfd5d..5e1f4088ff63f8a 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -118,6 +118,11 @@
 #  define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
 #endif
 
+// Builtins for checking CPU features based on the GCC builtins.
+BUILTIN(__builtin_cpu_supports, "bcC*", "nc")
+BUILTIN(__builtin_cpu_is, "bcC*", "nc")
+BUILTIN(__builtin_cpu_init, "v", "n")
+
 // Standard libc/libm functions:
 BUILTIN(__builtin_atan2 , "ddd"  , "Fne")
 BUILTIN(__builtin_atan2f, "fff"  , "Fne")
diff --git a/clang/include/clang/Basic/BuiltinsX86.def 
b/clang/include/clang/Basic/BuiltinsX86.def
index e4802f8ab1c1562..2acc5ce0f4a3653 100644
--- a/clang/include/clang/Basic/BuiltinsX86.def
+++ b/clang/include/clang/Basic/BuiltinsX86.def
@@ -26,13 +26,6 @@
 #  define TARGET_HEADER_BUILTIN(ID, TYPE, ATTRS, HEADER, LANG, FEATURE) 
BUILTIN(ID, TYPE, ATTRS)
 #endif
 
-// Miscellaneous builtin for checking x86 cpu features.
-// TODO: Make this somewhat generic so that other backends
-// can use it?
-BUILTIN(__builtin_cpu_init, "v", "n")
-BUILTIN(__builtin_cpu_supports, "bcC*", "nc")
-BUILTIN(__builtin_cpu_is, "bcC*", "nc")
-
 // Undefined Values
 //
 TARGET_BUILTIN(__builtin_ia32_undef128, "V2d", "ncV:128:", "")
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 9d56e97a3d4bb88..3d83b387aac0931 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1415,6 +1415,12 @@ class TargetInfo : public TransferrableTargetInfo,
 getTriple().isOSFreeBSD());
   }
 
+  // Identify whether this target supports __builtin_cpu_supports and
+  // __builtin_cpu_is.
+  virtual bool supportsCpuSupports() const { return false; }
+  virtual bool supportsCpuIs() const { return false; }
+  virtual bool supportsCpuInit() const { return false; }
+
   // Validate the contents of the __builtin_cpu_supports(const char*)
   // argument.
   virtual bool validateCpuSupports(StringRef Name) const { return false; }
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 0d87a3a4e8c20f3..d8759c86c9932ca 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -873,3 +873,17 @@ ArrayRef PPCTargetInfo::getTargetBuiltins() 
const {
   return llvm::ArrayRef(BuiltinInfo,
 clang::PPC::LastTSBuiltin - Builtin::FirstTSBuiltin);
 }
+
+bool PPCTargetInfo::validateCpuSupports(StringRef FeatureStr) const {
+#define PPC_FEATURE(NAME, DESC, ENUMNAME, ENUMVAL, HWCAPN) .Case(NAME, true)
+  return llvm::StringSwitch(FeatureStr)
+#include "llvm/TargetParser/PPCTargetParser.def"
+  .Default(false);
+}
+
+bool PPCTargetInfo::validateCpuIs(StringRef CPUName) const {
+#define PPC_CPU(NAME, NUM) 

[clang] [HLSL] Support vector swizzles on scalars (PR #67700)

2023-10-12 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library  -x hlsl \
+// RUN:   -finclude-default-header -ast-dump %s | FileCheck %s
+
+
+// CHECK: ExtVectorElementExpr {{.*}} 'int 
__attribute__((ext_vector_type(2)))' xx
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int 
__attribute__((ext_vector_type(1)))' lvalue 
+// CHECK-NEXT: DeclRefExpr {{.*}} 'int' lvalue ParmVar {{.*}} 'V' 'int'
+
+int2 ToTwoInts(int V){
+  return V.xx;
+}
+
+// CHECK: ExtVectorElementExpr {{.*}} 'float 
__attribute__((ext_vector_type(4)))' 
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float 
__attribute__((ext_vector_type(1)))' lvalue 
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float' lvalue ParmVar {{.*}} 'V' 'float'
+
+
+float4 ToThreeFloats(float V){
+  return V.;
+}
+
+// CHECK: ExtVectorElementExpr {{.*}} 'int 
__attribute__((ext_vector_type(2)))' xx
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int 
__attribute__((ext_vector_type(1)))' 
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
+
+int2 FillOne(){
+  return 1.xx;
+}
+
+
+// CHECK: ExtVectorElementExpr {{.*}} 'unsigned int 
__attribute__((ext_vector_type(3)))' xxx
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int 
__attribute__((ext_vector_type(1)))' 
+// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned int' 1
+
+uint3 FillOneUnsigned(){
+  return 1u.xxx;
+}

AaronBallman wrote:

What happens with:
```
auto HooBoy() {
  return 4wb.;
}
```
or with a float that has a trailing period followed by this Very Special™ 
suffix?
```
float3 err() {
  return 1..rrr;
}
```

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


[clang] [HLSL] Support vector swizzles on scalars (PR #67700)

2023-10-12 Thread Aaron Ballman via cfe-commits

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


[clang] [HLSL] Support vector swizzles on scalars (PR #67700)

2023-10-12 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library  -x hlsl 
-finclude-default-header -verify %s
+
+
+int2 ToTwoInts(int V) {
+  return V.xy; // expected-error{{vector component access exceeds type 'int 
__attribute__((ext_vector_type(1)))' (vector of 1 'int' value)}}
+}
+
+float2 ToTwoFloats(float V) {
+  return V.rg; // expected-error{{vector component access exceeds type 'float 
__attribute__((ext_vector_type(1)))' (vector of 1 'float' value)}}
+}
+
+int4 SomeNonsense(int V) {
+  return V.poop; // expected-error{{illegal vector component name 'p'}}

AaronBallman wrote:

I'd like another test that validates we catch multiple levels of dots. e.g.,
```
float2 HowManyFloats(float V) {
  return V.rr.rr;
}
```
or dots not followed by anything useful:
```
float2 WhatIsHappening(float V) {
  return V.;
}
```

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


[clang] [Sema] Add check for bitfield assignments to larger integral types (PR #68276)

2023-10-12 Thread via cfe-commits

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


  1   2   3   >