[llvm-branch-commits] [clang] [Serialization] Introduce OnDiskHashTable for specializations (PR #83233)

2024-04-25 Thread Chuanqi Xu via llvm-branch-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/83233

>From 80c9ab1d56e1e69407af75444f276df446008fed Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 28 Feb 2024 11:41:53 +0800
Subject: [PATCH] [Serialization] Introduce OnDiskHashTable for specializations

Following up for https://github.com/llvm/llvm-project/pull/83108

This follows the suggestion literally from
https://github.com/llvm/llvm-project/pull/76774#issuecomment-1951172457

which introduces OnDiskHashTable for specializations based on
D41416.

Note that I didn't polish this patch to reduce the diff from D41416
to it easier to review. I'll make the polishing patch later. So that we
can focus what we're doing in this patch and focus on the style in the
next patch.
---
 clang/include/clang/AST/ExternalASTSource.h   |  11 +
 .../clang/Sema/MultiplexExternalSemaSource.h  |   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   6 +
 clang/include/clang/Serialization/ASTReader.h |  34 ++-
 clang/include/clang/Serialization/ASTWriter.h |  15 +
 clang/lib/AST/DeclTemplate.cpp|  17 ++
 clang/lib/AST/ExternalASTSource.cpp   |   5 +
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |  12 +
 clang/lib/Serialization/ASTReader.cpp | 145 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |  27 ++
 clang/lib/Serialization/ASTReaderInternals.h  | 124 +
 clang/lib/Serialization/ASTWriter.cpp | 174 +++-
 clang/lib/Serialization/ASTWriterDecl.cpp |  32 ++-
 clang/unittests/Serialization/CMakeLists.txt  |   1 +
 .../Serialization/LoadSpecLazilyTest.cpp  | 260 ++
 15 files changed, 856 insertions(+), 13 deletions(-)
 create mode 100644 clang/unittests/Serialization/LoadSpecLazilyTest.cpp

diff --git a/clang/include/clang/AST/ExternalASTSource.h 
b/clang/include/clang/AST/ExternalASTSource.h
index 385c32edbae0fd..24c4490d160f3f 100644
--- a/clang/include/clang/AST/ExternalASTSource.h
+++ b/clang/include/clang/AST/ExternalASTSource.h
@@ -150,6 +150,17 @@ class ExternalASTSource : public 
RefCountedBase {
   virtual bool
   FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
 
+  /// Load all the external specializations for the Decl \param D if \param
+  /// OnlyPartial is false. Otherwise, load all the external **partial**
+  /// specializations for the \param D.
+  virtual void LoadExternalSpecializations(const Decl *D, bool OnlyPartial);
+
+  /// Load all the specializations for the Decl \param D with the same template
+  /// args specified by \param TemplateArgs.
+  virtual void
+  LoadExternalSpecializations(const Decl *D,
+  ArrayRef TemplateArgs);
+
   /// Ensures that the table of all visible declarations inside this
   /// context is up to date.
   ///
diff --git a/clang/include/clang/Sema/MultiplexExternalSemaSource.h 
b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
index 238fb398b7d129..f81b70daa4b3d0 100644
--- a/clang/include/clang/Sema/MultiplexExternalSemaSource.h
+++ b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
@@ -97,6 +97,12 @@ class MultiplexExternalSemaSource : public 
ExternalSemaSource {
   bool FindExternalVisibleDeclsByName(const DeclContext *DC,
   DeclarationName Name) override;
 
+  void LoadExternalSpecializations(const Decl *D, bool OnlyPartial) override;
+
+  void
+  LoadExternalSpecializations(const Decl *D,
+  ArrayRef TemplateArgs) 
override;
+
   /// Ensures that the table of all visible declarations inside this
   /// context is up to date.
   void completeVisibleDeclsMap(const DeclContext *DC) override;
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 186c3b722ced16..b20a59ae8a2e9b 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -694,6 +694,9 @@ enum ASTRecordTypes {
   /// Record code for lexical and visible block for delayed namespace in
   /// reduced BMI.
   DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD = 68,
+
+  /// Record code for updated specialization
+  UPDATE_SPECIALIZATION = 69,
 };
 
 /// Record types used within a source manager block.
@@ -1451,6 +1454,9 @@ enum DeclCode {
   /// A HLSLBufferDecl record.
   DECL_HLSL_BUFFER,
 
+  // A decls specilization record.
+  DECL_SPECIALIZATIONS,
+
   /// An ImplicitConceptSpecializationDecl record.
   DECL_IMPLICIT_CONCEPT_SPECIALIZATION,
 
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 64f1ebc117b327..d1ec72f8475435 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -340,6 +340,9 @@ class ASTIdentifierLookupTrait;
 /// The on-disk hash table(s) used for DeclContext name lookup.
 struct DeclContextLookupTable;
 
+/// The on-disk hash table(s) used for specializa

[llvm-branch-commits] [clang] [Serialization] Introduce OnDiskHashTable for specializations (PR #83233)

2024-04-25 Thread Chuanqi Xu via llvm-branch-commits

ChuanqiXu9 wrote:

Rebased with main

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


[llvm-branch-commits] [clang] [Serialization] Code cleanups and polish 83233 (PR #83237)

2024-04-25 Thread Chuanqi Xu via llvm-branch-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/83237

>From f4edc5b1cde1735d1c9c9f6c43ef4f50066965b0 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 28 Feb 2024 11:41:53 +0800
Subject: [PATCH 1/2] [Serialization] Code cleanups and polish 83233

---
 clang/include/clang/AST/DeclTemplate.h| 40 ++---
 clang/include/clang/AST/ExternalASTSource.h   |  4 +-
 .../clang/Sema/MultiplexExternalSemaSource.h  |  2 +-
 .../include/clang/Serialization/ASTBitCodes.h |  2 +-
 clang/include/clang/Serialization/ASTReader.h |  2 +-
 clang/lib/AST/DeclTemplate.cpp| 88 +--
 clang/lib/AST/ExternalASTSource.cpp   |  6 +-
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |  7 +-
 clang/lib/Serialization/ASTCommon.h   |  1 -
 clang/lib/Serialization/ASTReader.cpp | 17 ++--
 clang/lib/Serialization/ASTReaderDecl.cpp | 76 +---
 clang/lib/Serialization/ASTReaderInternals.h  |  1 -
 clang/lib/Serialization/ASTWriter.cpp | 26 +-
 clang/lib/Serialization/ASTWriterDecl.cpp | 52 +--
 14 files changed, 87 insertions(+), 237 deletions(-)

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index fb32639b86351c..7b1966e0c19c83 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -256,8 +256,8 @@ class TemplateArgumentList final
   TemplateArgumentList(const TemplateArgumentList &) = delete;
   TemplateArgumentList &operator=(const TemplateArgumentList &) = delete;
 
-  /// Create hash for the given arguments.
-  static unsigned ComputeODRHash(ArrayRef Args);
+  /// Create stable hash for the given arguments across compiler invocations.
+  static unsigned ComputeStableHash(ArrayRef Args);
 
   /// Create a new template argument list that copies the given set of
   /// template arguments.
@@ -733,25 +733,6 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   }
 
   void anchor() override;
-  struct LazySpecializationInfo {
-GlobalDeclID DeclID = GlobalDeclID();
-unsigned ODRHash = ~0U;
-bool IsPartial = false;
-LazySpecializationInfo(GlobalDeclID ID, unsigned Hash = ~0U,
-   bool Partial = false)
-: DeclID(ID), ODRHash(Hash), IsPartial(Partial) {}
-LazySpecializationInfo() {}
-bool operator<(const LazySpecializationInfo &Other) const {
-  return DeclID < Other.DeclID;
-}
-bool operator==(const LazySpecializationInfo &Other) const {
-  assert((DeclID != Other.DeclID || ODRHash == Other.ODRHash) &&
- "Hashes differ!");
-  assert((DeclID != Other.DeclID || IsPartial == Other.IsPartial) &&
- "Both must be the same kinds!");
-  return DeclID == Other.DeclID;
-}
-  };
 
 protected:
   template  struct SpecEntryTraits {
@@ -795,16 +776,20 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 
   void loadLazySpecializationsImpl(bool OnlyPartial = false) const;
 
-  void loadLazySpecializationsImpl(llvm::ArrayRef Args,
+  bool loadLazySpecializationsImpl(llvm::ArrayRef Args,
TemplateParameterList *TPL = nullptr) const;
 
-  Decl *loadLazySpecializationImpl(LazySpecializationInfo &LazySpecInfo) const;
-
   template 
   typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector &Specs,
  void *&InsertPos, ProfileArguments &&...ProfileArgs);
 
+  template 
+  typename SpecEntryTraits::DeclType *
+  findSpecializationLocally(llvm::FoldingSetVector &Specs,
+void *&InsertPos,
+ProfileArguments &&...ProfileArgs);
+
   template 
   void addSpecializationImpl(llvm::FoldingSetVector &Specs,
  EntryType *Entry, void *InsertPos);
@@ -820,13 +805,6 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 llvm::PointerIntPair
   InstantiatedFromMember;
 
-/// If non-null, points to an array of specializations (including
-/// partial specializations) known only by their external declaration IDs.
-///
-/// The first value in the array is the number of specializations/partial
-/// specializations that follow.
-LazySpecializationInfo *LazySpecializations = nullptr;
-
 /// The set of "injected" template arguments used within this
 /// template.
 ///
diff --git a/clang/include/clang/AST/ExternalASTSource.h 
b/clang/include/clang/AST/ExternalASTSource.h
index 24c4490d160f3f..2f71d6030a12c9 100644
--- a/clang/include/clang/AST/ExternalASTSource.h
+++ b/clang/include/clang/AST/ExternalASTSource.h
@@ -157,7 +157,9 @@ class ExternalASTSource : public 
RefCountedBase {
 
   /// Load all the specializations for the Decl \param D with the same template
   /// args specified by \param TemplateArgs.
-  virtual void
+  ///
+  /// Return true if any new specializations get loaded. Return false 
otherwise.
+  virtual bool
   

[llvm-branch-commits] [clang] [Serialization] Code cleanups and polish 83233 (PR #83237)

2024-04-25 Thread Chuanqi Xu via llvm-branch-commits

ChuanqiXu9 wrote:

Rebased with main

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


[llvm-branch-commits] [OpenMP][MLIR] Add new arguments to map_info to help support record type maps (PR #82851)

2024-04-25 Thread Krzysztof Parzyszek via llvm-branch-commits

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


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


[llvm-branch-commits] [clang] [CIR] Add options to emit ClangIR and enable the ClangIR pipeline (PR #89030)

2024-04-25 Thread Erich Keane via llvm-branch-commits


@@ -2876,6 +2876,15 @@ def flax_vector_conversions : Flag<["-"], 
"flax-vector-conversions">, Group, Group,
   HelpText<"Force linking the clang builtins runtime library">;
+
+/// ClangIR-specific options - BEGIN
+def fclangir_enable : Flag<["-"], "fclangir-enable">, Visibility<[ClangOption, 
CC1Option]>,
+  Group, HelpText<"Use ClangIR pipeline to compile">,
+  MarshallingInfoFlag>;
+def emit_cir : Flag<["-"], "emit-cir">, Visibility<[ClangOption, CC1Option]>,

erichkeane wrote:

IMO, there is no good reason for `-emit-llvm` to be a driver option, other than 
for historical reasons.  That is, if we were putting it in today, we'd probably 
not expose it that way.  Because of that, I'd like to not repeat that mistake 
with `emit-cir`.

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


[llvm-branch-commits] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-25 Thread Pengcheng Wang via llvm-branch-commits

https://github.com/wangpc-pp created 
https://github.com/llvm/llvm-project/pull/90049

Masking them as `hasSideEffects=1` stops some optimizations.

For saturating instructions, they may write `vxsat`. This is like
floating-point instructions that may write `fflags`, but we don't
model floating-point instructions as `hasSideEffects=1`.

For fault-only-first instructions, I think we have made its side
effect `vl` an output operand and added explict def of `VL`.

These changes make optimizations like `performCombineVMergeAndVOps`
and MachineCSE possible for these instructions.

As a consequence, `copyprop.mir` can't test what we want to test in
https://reviews.llvm.org/D155140, so we replace `vssra.vi` with a
VCIX instruction (it has side effects).



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


[llvm-branch-commits] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Pengcheng Wang (wangpc-pp)


Changes

Masking them as `hasSideEffects=1` stops some optimizations.

For saturating instructions, they may write `vxsat`. This is like
floating-point instructions that may write `fflags`, but we don't
model floating-point instructions as `hasSideEffects=1`.

For fault-only-first instructions, I think we have made its side
effect `vl` an output operand and added explict def of `VL`.

These changes make optimizations like `performCombineVMergeAndVOps`
and MachineCSE possible for these instructions.

As a consequence, `copyprop.mir` can't test what we want to test in
https://reviews.llvm.org/D155140, so we replace `vssra.vi` with a
VCIX instruction (it has side effects).


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


7 Files Affected:

- (modified) llvm/include/llvm/IR/IntrinsicsRISCV.td (+6-7) 
- (modified) llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp (-1) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td (+5-5) 
- (modified) llvm/test/CodeGen/RISCV/regalloc-last-chance-recoloring-failure.ll 
(+27-42) 
- (modified) llvm/test/CodeGen/RISCV/rvv/commutable.ll (+9-12) 
- (modified) llvm/test/CodeGen/RISCV/rvv/copyprop.mir (+8-9) 
- (modified) llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-vops.ll (+12-20) 


``diff
diff --git a/llvm/include/llvm/IR/IntrinsicsRISCV.td 
b/llvm/include/llvm/IR/IntrinsicsRISCV.td
index 1d58860a0afc8a..4c4e7351212f8a 100644
--- a/llvm/include/llvm/IR/IntrinsicsRISCV.td
+++ b/llvm/include/llvm/IR/IntrinsicsRISCV.td
@@ -661,7 +661,7 @@ let TargetPrefix = "riscv" in {
 : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_any_ty,
  llvm_anyint_ty],
-[IntrNoMem, IntrHasSideEffects]>, RISCVVIntrinsic {
+[IntrNoMem]>, RISCVVIntrinsic {
 let ScalarOperand = 2;
 let VLOperand = 3;
   }
@@ -684,7 +684,7 @@ let TargetPrefix = "riscv" in {
 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_any_ty,
  LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, 
llvm_anyint_ty,
  LLVMMatchType<2>],
-[ImmArg>, IntrNoMem, IntrHasSideEffects]>, 
RISCVVIntrinsic {
+[ImmArg>, IntrNoMem]>, RISCVVIntrinsic {
 let ScalarOperand = 2;
 let VLOperand = 4;
   }
@@ -708,7 +708,7 @@ let TargetPrefix = "riscv" in {
 : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_any_ty,
  llvm_anyint_ty, LLVMMatchType<2>],
-[ImmArg>, IntrNoMem, IntrHasSideEffects]>,
+[ImmArg>, IntrNoMem]>,
 RISCVVIntrinsic {
 let VLOperand = 4;
   }
@@ -721,7 +721,7 @@ let TargetPrefix = "riscv" in {
 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_any_ty,
  LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, 
llvm_anyint_ty,
  LLVMMatchType<2>, LLVMMatchType<2>],
-[ImmArg>,ImmArg>, IntrNoMem, 
IntrHasSideEffects]>,
+[ImmArg>,ImmArg>, IntrNoMem]>,
 RISCVVIntrinsic {
 let VLOperand = 5;
   }
@@ -733,7 +733,7 @@ let TargetPrefix = "riscv" in {
 : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
 [LLVMMatchType<0>, llvm_anyvector_ty, llvm_any_ty,
  llvm_anyint_ty, LLVMMatchType<3>],
-[ImmArg>, IntrNoMem, IntrHasSideEffects]>,
+[ImmArg>, IntrNoMem]>,
 RISCVVIntrinsic {
 let VLOperand = 4;
   }
@@ -746,8 +746,7 @@ let TargetPrefix = "riscv" in {
 [LLVMMatchType<0>, llvm_anyvector_ty, llvm_any_ty,
  LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, 
llvm_anyint_ty,
  LLVMMatchType<3>, LLVMMatchType<3>],
-[ImmArg>, ImmArg>, IntrNoMem,
- IntrHasSideEffects]>, RISCVVIntrinsic {
+[ImmArg>, ImmArg>, IntrNoMem]>, 
RISCVVIntrinsic {
 let VLOperand = 5;
   }
   // Input: (vector_in, vector_in, scalar_in, vl, policy)
diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp 
b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
index b0568297a470a7..da1543bd7112a2 100644
--- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -3668,7 +3668,6 @@ bool 
RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
   }
 
   // Skip if True has side effect.
-  // TODO: Support vleff and vlsegff.
   if (TII->get(TrueOpc).hasUnmodeledSideEffects())
 return false;
 
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td 
b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
index ce8bad6618db92..ecb923d2821aae 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
+++ b/llvm/lib/Target/RISCV/RISCVInst

[llvm-branch-commits] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Pengcheng Wang (wangpc-pp)


Changes

Masking them as `hasSideEffects=1` stops some optimizations.

For saturating instructions, they may write `vxsat`. This is like
floating-point instructions that may write `fflags`, but we don't
model floating-point instructions as `hasSideEffects=1`.

For fault-only-first instructions, I think we have made its side
effect `vl` an output operand and added explict def of `VL`.

These changes make optimizations like `performCombineVMergeAndVOps`
and MachineCSE possible for these instructions.

As a consequence, `copyprop.mir` can't test what we want to test in
https://reviews.llvm.org/D155140, so we replace `vssra.vi` with a
VCIX instruction (it has side effects).


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


7 Files Affected:

- (modified) llvm/include/llvm/IR/IntrinsicsRISCV.td (+6-7) 
- (modified) llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp (-1) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td (+5-5) 
- (modified) llvm/test/CodeGen/RISCV/regalloc-last-chance-recoloring-failure.ll 
(+27-42) 
- (modified) llvm/test/CodeGen/RISCV/rvv/commutable.ll (+9-12) 
- (modified) llvm/test/CodeGen/RISCV/rvv/copyprop.mir (+8-9) 
- (modified) llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-vops.ll (+12-20) 


``diff
diff --git a/llvm/include/llvm/IR/IntrinsicsRISCV.td 
b/llvm/include/llvm/IR/IntrinsicsRISCV.td
index 1d58860a0afc8a..4c4e7351212f8a 100644
--- a/llvm/include/llvm/IR/IntrinsicsRISCV.td
+++ b/llvm/include/llvm/IR/IntrinsicsRISCV.td
@@ -661,7 +661,7 @@ let TargetPrefix = "riscv" in {
 : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_any_ty,
  llvm_anyint_ty],
-[IntrNoMem, IntrHasSideEffects]>, RISCVVIntrinsic {
+[IntrNoMem]>, RISCVVIntrinsic {
 let ScalarOperand = 2;
 let VLOperand = 3;
   }
@@ -684,7 +684,7 @@ let TargetPrefix = "riscv" in {
 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_any_ty,
  LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, 
llvm_anyint_ty,
  LLVMMatchType<2>],
-[ImmArg>, IntrNoMem, IntrHasSideEffects]>, 
RISCVVIntrinsic {
+[ImmArg>, IntrNoMem]>, RISCVVIntrinsic {
 let ScalarOperand = 2;
 let VLOperand = 4;
   }
@@ -708,7 +708,7 @@ let TargetPrefix = "riscv" in {
 : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_any_ty,
  llvm_anyint_ty, LLVMMatchType<2>],
-[ImmArg>, IntrNoMem, IntrHasSideEffects]>,
+[ImmArg>, IntrNoMem]>,
 RISCVVIntrinsic {
 let VLOperand = 4;
   }
@@ -721,7 +721,7 @@ let TargetPrefix = "riscv" in {
 [LLVMMatchType<0>, LLVMMatchType<0>, llvm_any_ty,
  LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, 
llvm_anyint_ty,
  LLVMMatchType<2>, LLVMMatchType<2>],
-[ImmArg>,ImmArg>, IntrNoMem, 
IntrHasSideEffects]>,
+[ImmArg>,ImmArg>, IntrNoMem]>,
 RISCVVIntrinsic {
 let VLOperand = 5;
   }
@@ -733,7 +733,7 @@ let TargetPrefix = "riscv" in {
 : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
 [LLVMMatchType<0>, llvm_anyvector_ty, llvm_any_ty,
  llvm_anyint_ty, LLVMMatchType<3>],
-[ImmArg>, IntrNoMem, IntrHasSideEffects]>,
+[ImmArg>, IntrNoMem]>,
 RISCVVIntrinsic {
 let VLOperand = 4;
   }
@@ -746,8 +746,7 @@ let TargetPrefix = "riscv" in {
 [LLVMMatchType<0>, llvm_anyvector_ty, llvm_any_ty,
  LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, 
llvm_anyint_ty,
  LLVMMatchType<3>, LLVMMatchType<3>],
-[ImmArg>, ImmArg>, IntrNoMem,
- IntrHasSideEffects]>, RISCVVIntrinsic {
+[ImmArg>, ImmArg>, IntrNoMem]>, 
RISCVVIntrinsic {
 let VLOperand = 5;
   }
   // Input: (vector_in, vector_in, scalar_in, vl, policy)
diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp 
b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
index b0568297a470a7..da1543bd7112a2 100644
--- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -3668,7 +3668,6 @@ bool 
RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
   }
 
   // Skip if True has side effect.
-  // TODO: Support vleff and vlsegff.
   if (TII->get(TrueOpc).hasUnmodeledSideEffects())
 return false;
 
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td 
b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
index ce8bad6618db92..ecb923d2821aae 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
+++ b/llvm/lib/Target/RISCV/RI

[llvm-branch-commits] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-25 Thread Luke Lau via llvm-branch-commits

https://github.com/lukel97 commented:

Removing it from vleNff sense to me. As long as we have the implicit-def $vl on 
the pseudo to prevent it being moved between vsetvlis I think it should be ok. 

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


[llvm-branch-commits] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-25 Thread Luke Lau via llvm-branch-commits

https://github.com/lukel97 edited 
https://github.com/llvm/llvm-project/pull/90049
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [RISCV] Make fixed-point instructions commutable (PR #90053)

2024-04-25 Thread Pengcheng Wang via llvm-branch-commits

https://github.com/wangpc-pp created 
https://github.com/llvm/llvm-project/pull/90053

This PR includes:
* vsadd.vv/vsaddu.vv
* vaadd.vv/vaaddu.vv
* vsmul.vv



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


[llvm-branch-commits] [RISCV] Make fixed-point instructions commutable (PR #90053)

2024-04-25 Thread Pengcheng Wang via llvm-branch-commits

https://github.com/wangpc-pp closed 
https://github.com/llvm/llvm-project/pull/90053
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [RISCV] Make fixed-point instructions commutable (PR #90053)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Pengcheng Wang (wangpc-pp)


Changes

This PR includes:
* vsadd.vv/vsaddu.vv
* vaadd.vv/vaaddu.vv
* vsmul.vv


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


3 Files Affected:

- (modified) llvm/lib/Target/RISCV/RISCVInstrInfo.cpp (+5) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td (+16-13) 
- (modified) llvm/test/CodeGen/RISCV/rvv/commutable.ll (+6-8) 


``diff
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp 
b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
index 5c1f154efa9911..f4ae8a25766405 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -2866,6 +2866,11 @@ bool RISCVInstrInfo::findCommutedOpIndices(const 
MachineInstr &MI,
   case CASE_RVV_OPCODE_WIDEN(VWMACC_VV):
   case CASE_RVV_OPCODE_WIDEN(VWMACCU_VV):
   case CASE_RVV_OPCODE_UNMASK(VADC_VVM):
+  case CASE_RVV_OPCODE(VSADD_VV):
+  case CASE_RVV_OPCODE(VSADDU_VV):
+  case CASE_RVV_OPCODE(VAADD_VV):
+  case CASE_RVV_OPCODE(VAADDU_VV):
+  case CASE_RVV_OPCODE(VSMUL_VV):
 // Operands 2 and 3 are commutable.
 return fixCommutedOpIndices(SrcOpIdx1, SrcOpIdx2, 2, 3);
   case CASE_VFMA_SPLATS(FMADD):
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td 
b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
index e9715b40adc079..fc60a9cc7cd30e 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
@@ -2146,8 +2146,9 @@ multiclass VPseudoBinaryRoundingMode {
-  let VLMul = MInfo.value, SEW=sew in {
+ int TargetConstraintType = 1,
+ bit Commutable = 0> {
+  let VLMul = MInfo.value, SEW=sew, isCommutable = Commutable in {
 defvar suffix = !if(sew, "_" # MInfo.MX # "_E" # sew, "_" # MInfo.MX);
 def suffix : VPseudoBinaryNoMaskRoundingMode;
 }
 
-multiclass VPseudoBinaryV_VV_RM {
-  defm _VV : VPseudoBinaryRoundingMode;
+multiclass VPseudoBinaryV_VV_RM {
+  defm _VV : VPseudoBinaryRoundingMode;
 }
 
 // Similar to VPseudoBinaryV_VV, but uses MxListF.
@@ -2715,10 +2717,11 @@ multiclass VPseudoVGTR_VV_VX_VI
   }
 }
 
-multiclass VPseudoVSALU_VV_VX_VI {
+multiclass VPseudoVSALU_VV_VX_VI {
   foreach m = MxList in {
 defvar mx = m.MX;
-defm "" : VPseudoBinaryV_VV,
+defm "" : VPseudoBinaryV_VV,
   SchedBinary<"WriteVSALUV", "ReadVSALUV", "ReadVSALUX", mx,
   forceMergeOpRead=true>;
 defm "" : VPseudoBinaryV_VX,
@@ -2788,7 +2791,7 @@ multiclass VPseudoVSALU_VV_VX {
 multiclass VPseudoVSMUL_VV_VX_RM {
   foreach m = MxList in {
 defvar mx = m.MX;
-defm "" : VPseudoBinaryV_VV_RM,
+defm "" : VPseudoBinaryV_VV_RM,
   SchedBinary<"WriteVSMulV", "ReadVSMulV", "ReadVSMulV", mx,
   forceMergeOpRead=true>;
 defm "" : VPseudoBinaryV_VX_RM,
@@ -2797,10 +2800,10 @@ multiclass VPseudoVSMUL_VV_VX_RM {
   }
 }
 
-multiclass VPseudoVAALU_VV_VX_RM {
+multiclass VPseudoVAALU_VV_VX_RM {
   foreach m = MxList in {
 defvar mx = m.MX;
-defm "" : VPseudoBinaryV_VV_RM,
+defm "" : VPseudoBinaryV_VV_RM,
   SchedBinary<"WriteVAALUV", "ReadVAALUV", "ReadVAALUV", mx,
   forceMergeOpRead=true>;
 defm "" : VPseudoBinaryV_VX_RM,
@@ -6448,8 +6451,8 @@ defm PseudoVMV_V : VPseudoUnaryVMV_V_X_I;
 // 12.1. Vector Single-Width Saturating Add and Subtract
 
//===--===//
 let Defs = [VXSAT], hasSideEffects = 1 in {
-  defm PseudoVSADDU : VPseudoVSALU_VV_VX_VI;
-  defm PseudoVSADD  : VPseudoVSALU_VV_VX_VI;
+  defm PseudoVSADDU : VPseudoVSALU_VV_VX_VI;
+  defm PseudoVSADD  : VPseudoVSALU_VV_VX_VI;
   defm PseudoVSSUBU : VPseudoVSALU_VV_VX;
   defm PseudoVSSUB  : VPseudoVSALU_VV_VX;
 }
@@ -6457,8 +6460,8 @@ let Defs = [VXSAT], hasSideEffects = 1 in {
 
//===--===//
 // 12.2. Vector Single-Width Averaging Add and Subtract
 
//===--===//
-defm PseudoVAADDU : VPseudoVAALU_VV_VX_RM;
-defm PseudoVAADD  : VPseudoVAALU_VV_VX_RM;
+defm PseudoVAADDU : VPseudoVAALU_VV_VX_RM;
+defm PseudoVAADD  : VPseudoVAALU_VV_VX_RM;
 defm PseudoVASUBU : VPseudoVAALU_VV_VX_RM;
 defm PseudoVASUB  : VPseudoVAALU_VV_VX_RM;
 
diff --git a/llvm/test/CodeGen/RISCV/rvv/commutable.ll 
b/llvm/test/CodeGen/RISCV/rvv/commutable.ll
index e383c1b477c45d..06a6327d3892b6 100644
--- a/llvm/test/CodeGen/RISCV/rvv/commutable.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/commutable.ll
@@ -724,10 +724,9 @@ define  @commutable_vaadd_vv( %0,  @llvm.riscv.vaadd.nxv1i64.nxv1i64( undef,  %0,  %1, iXLen 0, iXLen %2)
@@ -743,7 +742,7 @@ define  
@commutable_vaadd_vv_masked( %0,  @commutable_vaaddu_vv( %0,  @llvm.riscv.vaaddu.nxv1i64.nxv1i64( undef,  %0,  %1, iXLen 0, iXLen %2)
@@ -779,7 +777,7 @@ define 

[llvm-branch-commits] [libcxx] release/18.x: [libcxx] [modules] Add _LIBCPP_USING_IF_EXISTS on aligned_alloc (#89827) (PR #89894)

2024-04-25 Thread Louis Dionne via llvm-branch-commits

ldionne wrote:

> Can we ignore the libcxx test failure?

Yes. It turns out to be extremely difficult to keep the release branch CI 
working *and* the `main` branch CI working at the same time. I mean it mostly 
works, except for annoyances like this.

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


[llvm-branch-commits] [clang] c0b4837 - release/18.x: [clang-format] Revert breaking stream operators to previous default (#89016)

2024-04-25 Thread Owen Pan via llvm-branch-commits

Author: Owen Pan
Date: 2024-04-24T21:29:46-07:00
New Revision: c0b48372d82aa0adaef671788ee1a37a650ee4fd

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

LOG: release/18.x: [clang-format] Revert breaking stream operators to previous 
default (#89016)

Backport 29ecd6d50f14

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
polly/lib/Analysis/DependenceInfo.cpp
polly/lib/Analysis/ScopBuilder.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 4d482e6543d6f5..9c4a8381f99824 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5157,12 +5157,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
 return true;
   if (Left.IsUnterminatedLiteral)
 return true;
-  // FIXME: Breaking after newlines seems useful in general. Turn this into an
-  // option and recognize more cases like endl etc, and break independent of
-  // what comes after operator lessless.
-  if (Right.is(tok::lessless) && Right.Next &&
-  Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) &&
-  Left.TokenText.ends_with("\\n\"")) {
+  if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) &&
+  Right.Next->is(tok::string_literal)) {
 return true;
   }
   if (Right.is(TT_RequiresClause)) {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 6b4f9075d8f0ab..2ac0b0aab1bee9 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -27031,12 +27031,6 @@ TEST_F(FormatTest, 
PPDirectivesAndCommentsInBracedInit) {
getLLVMStyleWithColumns(30));
 }
 
-TEST_F(FormatTest, StreamOutputOperator) {
-  verifyFormat("std::cout << \"foo\" << \"bar\" << baz;");
-  verifyFormat("std::cout << \"foo\\n\"\n"
-   "  << \"bar\";");
-}
-
 TEST_F(FormatTest, BreakAdjacentStringLiterals) {
   constexpr StringRef Code{
   "return \"Code\" \"\\0\\52\\26\\55\\55\\0\" \"x013\" \"\\02\\xBA\";"};
@@ -27051,6 +27045,7 @@ TEST_F(FormatTest, BreakAdjacentStringLiterals) {
   Style.BreakAdjacentStringLiterals = false;
   verifyFormat(Code, Style);
 }
+
 } // namespace
 } // namespace test
 } // namespace format

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index f767b83a875471..cbe6b79a366882 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2624,15 +2624,6 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[21], BK_BracedInit);
 }
 
-TEST_F(TokenAnnotatorTest, StreamOperator) {
-  auto Tokens = annotate("\"foo\\n\" << aux << \"foo\\n\" << \"foo\";");
-  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
-  EXPECT_FALSE(Tokens[1]->MustBreakBefore);
-  EXPECT_FALSE(Tokens[3]->MustBreakBefore);
-  // Only break between string literals if the former ends with \n.
-  EXPECT_TRUE(Tokens[5]->MustBreakBefore);
-}
-
 } // namespace
 } // namespace format
 } // namespace clang

diff  --git a/polly/lib/Analysis/DependenceInfo.cpp 
b/polly/lib/Analysis/DependenceInfo.cpp
index 69257c603877ea..d58dc9917bc91f 100644
--- a/polly/lib/Analysis/DependenceInfo.cpp
+++ b/polly/lib/Analysis/DependenceInfo.cpp
@@ -950,8 +950,8 @@ class DependenceInfoPrinterLegacyPass final : public 
ScopPass {
   bool runOnScop(Scop &S) override {
 DependenceInfo &P = getAnalysis();
 
-OS << "Printing analysis '" << P.getPassName() << "' for " << "region: '"
-   << S.getRegion().getNameStr() << "' in function '"
+OS << "Printing analysis '" << P.getPassName() << "' for "
+   << "region: '" << S.getRegion().getNameStr() << "' in function '"
<< S.getFunction().getName() << "':\n";
 P.printScop(OS, S);
 

diff  --git a/polly/lib/Analysis/ScopBuilder.cpp 
b/polly/lib/Analysis/ScopBuilder.cpp
index c62cb2a85c835c..64314d6041b8e9 100644
--- a/polly/lib/Analysis/ScopBuilder.cpp
+++ b/polly/lib/Analysis/ScopBuilder.cpp
@@ -2689,9 +2689,10 @@ void ScopBuilder::addUserContext() {
 if (NameContext != NameUserContext) {
   std::string SpaceStr = stringFromIslObj(Space, "null");
   errs() << "Error: the name of dimension " << i
- << " provided in -polly-context " << "is '" << NameUserContext
- << "', but the name in the computed " << "context is '"
- << NameContext << "'. Due to this name mismatch, "
+ << " provided in -polly-context "
+ << "is '" << NameUserContext << "', but the name in the computed "
+ << "context is '" << NameContext
+

[llvm-branch-commits] [clang] [polly] release/18.x: [clang-format] Revert breaking stream operators to prev… (PR #89492)

2024-04-25 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/89492
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [libcxx] release/18.x: [libcxx] [modules] Add _LIBCPP_USING_IF_EXISTS on aligned_alloc (#89827) (PR #89894)

2024-04-25 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/89894

>From b9b73814ad8acd55e88d0415f4110d272797697d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Wed, 24 Apr 2024 11:45:27 +0300
Subject: [PATCH] =?UTF-8?q?[libcxx]=20[modules]=C2=A0Add=20=5FLIBCPP=5FUSI?=
 =?UTF-8?q?NG=5FIF=5FEXISTS=20on=20aligned=5Falloc=20(#89827)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is missing e.g. on Windows. With this change, it's possible to make
the libcxx std module work on mingw-w64 (although that requires a few
fixes to those headers).

In the regular cstdlib header, we have _LIBCPP_USING_IF_EXISTS flagged
on every single reexported function (since
a9c9183ca42629fa83cdda297d1d30c7bc1d7c91), but the modules seem to only
have _LIBCPP_USING_IF_EXISTS set on a few individual functions, so far.

(cherry picked from commit 91526d64a8adb14edc55adfd5270858791822837)
---
 libcxx/modules/std.compat/cstdlib.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/modules/std.compat/cstdlib.inc 
b/libcxx/modules/std.compat/cstdlib.inc
index a45a0a1caf8ba9..4783cbf5162390 100644
--- a/libcxx/modules/std.compat/cstdlib.inc
+++ b/libcxx/modules/std.compat/cstdlib.inc
@@ -25,7 +25,7 @@ export {
   using ::system;
 
   // [c.malloc], C library memory allocation
-  using ::aligned_alloc;
+  using ::aligned_alloc _LIBCPP_USING_IF_EXISTS;
   using ::calloc;
   using ::free;
   using ::malloc;

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


[llvm-branch-commits] [RISCV] Make fixed-point instructions commutable (PR #90053)

2024-04-25 Thread Pengcheng Wang via llvm-branch-commits

wangpc-pp wrote:

Sorry for bothering, I just ran spr on a non-spr branch.

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


[llvm-branch-commits] [libcxx] b9b7381 - [libcxx] [modules] Add _LIBCPP_USING_IF_EXISTS on aligned_alloc (#89827)

2024-04-25 Thread Tom Stellard via llvm-branch-commits

Author: Martin Storsjö
Date: 2024-04-25T06:53:04-07:00
New Revision: b9b73814ad8acd55e88d0415f4110d272797697d

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

LOG: [libcxx] [modules] Add _LIBCPP_USING_IF_EXISTS on aligned_alloc (#89827)

This is missing e.g. on Windows. With this change, it's possible to make
the libcxx std module work on mingw-w64 (although that requires a few
fixes to those headers).

In the regular cstdlib header, we have _LIBCPP_USING_IF_EXISTS flagged
on every single reexported function (since
a9c9183ca42629fa83cdda297d1d30c7bc1d7c91), but the modules seem to only
have _LIBCPP_USING_IF_EXISTS set on a few individual functions, so far.

(cherry picked from commit 91526d64a8adb14edc55adfd5270858791822837)

Added: 


Modified: 
libcxx/modules/std.compat/cstdlib.inc

Removed: 




diff  --git a/libcxx/modules/std.compat/cstdlib.inc 
b/libcxx/modules/std.compat/cstdlib.inc
index a45a0a1caf8ba9..4783cbf5162390 100644
--- a/libcxx/modules/std.compat/cstdlib.inc
+++ b/libcxx/modules/std.compat/cstdlib.inc
@@ -25,7 +25,7 @@ export {
   using ::system;
 
   // [c.malloc], C library memory allocation
-  using ::aligned_alloc;
+  using ::aligned_alloc _LIBCPP_USING_IF_EXISTS;
   using ::calloc;
   using ::free;
   using ::malloc;



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


[llvm-branch-commits] [libcxx] release/18.x: [libcxx] [modules] Add _LIBCPP_USING_IF_EXISTS on aligned_alloc (#89827) (PR #89894)

2024-04-25 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/89894
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-25 Thread Craig Topper via llvm-branch-commits

topperc wrote:

> For saturating instructions, they may write vxsat. This is like
floating-point instructions that may write fflags, but we don't
model floating-point instructions as hasSideEffects=1.

That's because floating point instructions use mayRaiseFPExceptions=1. And 
STRICT_* nodes set don't set the NoFPExcept bit in MIFlags. Though we don't 
have a story for how to make reading FFLAGS work with riscv.* intrinsics. 
That's an issue on all targets as there is no "constrained" or "strict" support 
for target specific intrinsics.

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


[llvm-branch-commits] [libcxx] [libc++][chrono] Fixes leap seconds. (PR #90070)

2024-04-25 Thread Mark de Wever via llvm-branch-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/90070

While implementing the UTC clock it turns out that the implementation of the 
leap seconds was not correct, it should store the individual value, not the sum.

It also looks like LWG3359 has not been fully implemented.

Implements parts of:
- LWG3359  leap second support should allow for negative leap seconds

>From d094cded6d023bbffdca0af983ef64e00289c797 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Mon, 15 Apr 2024 19:56:40 +0200
Subject: [PATCH] [libc++][chrono] Fixes leap seconds.

While implementing the UTC clock it turns out that the implementation of
the leap seconds was not correct, it should store the individual value,
not the sum.

It also looks like LWG3359 has not been fully implemented.

Implements parts of:
- LWG3359  leap second support should allow for negative leap seconds
---
 libcxx/docs/Status/Cxx20Issues.csv|  2 +-
 libcxx/src/tzdb.cpp   | 64 ---
 .../time.zone.db/leap_seconds.pass.cpp| 23 ---
 .../time.zone.db/leap_seconds.pass.cpp| 55 
 4 files changed, 83 insertions(+), 61 deletions(-)

diff --git a/libcxx/docs/Status/Cxx20Issues.csv 
b/libcxx/docs/Status/Cxx20Issues.csv
index db57b15256a62f..fed1c7e736248f 100644
--- a/libcxx/docs/Status/Cxx20Issues.csv
+++ b/libcxx/docs/Status/Cxx20Issues.csv
@@ -269,7 +269,7 @@
 "`3355 `__","The memory algorithms should support 
move-only input iterators introduced by 
P1207","Prague","|Complete|","15.0","|ranges|"
 "`3356 `__","``__cpp_lib_nothrow_convertible``\  
should be ``__cpp_lib_is_nothrow_convertible``\ ","Prague","|Complete|","12.0"
 "`3358 `__","|sect|\ [span.cons] is mistaken that 
``to_address``\  can throw","Prague","|Complete|","17.0"
-"`3359 `__","\  leap second support 
should allow for negative leap seconds","Prague","|Complete|","19.0","|chrono|"
+"`3359 `__","\  leap second support 
should allow for negative leap seconds","Prague","|In Progress|","","|chrono|"
 "`3360 `__","``three_way_comparable_with``\  is 
inconsistent with similar concepts","Prague","|Nothing To Do|","","|spaceship|"
 "`3362 `__","Strike ``stop_source``\ 's 
``operator!=``\ ","Prague","",""
 "`3363 `__","``drop_while_view``\  should opt-out 
of ``sized_range``\ ","Prague","|Nothing To Do|","","|ranges|"
diff --git a/libcxx/src/tzdb.cpp b/libcxx/src/tzdb.cpp
index 5951e59248e94f..8588646bbbc417 100644
--- a/libcxx/src/tzdb.cpp
+++ b/libcxx/src/tzdb.cpp
@@ -626,29 +626,49 @@ static void __parse_leap_seconds(vector& 
__leap_seconds, istream&&
   // seconds since 1 January 1970.
   constexpr auto __offset = sys_days{1970y / January / 1} - sys_days{1900y / 
January / 1};
 
-  while (true) {
-switch (__input.peek()) {
-case istream::traits_type::eof():
-  return;
-
-case ' ':
-case '\t':
-case '\n':
-  __input.get();
-  continue;
+  struct __entry {
+sys_seconds __timestamp;
+seconds __value;
+  };
+  vector<__entry> __entries;
+  [&] {
+while (true) {
+  switch (__input.peek()) {
+  case istream::traits_type::eof():
+return;
+
+  case ' ':
+  case '\t':
+  case '\n':
+__input.get();
+continue;
+
+  case '#':
+chrono::__skip_line(__input);
+continue;
+  }
 
-case '#':
+  sys_seconds __date = 
sys_seconds{seconds{chrono::__parse_integral(__input, false)}} - __offset;
+  chrono::__skip_mandatory_whitespace(__input);
+  seconds __value{chrono::__parse_integral(__input, false)};
   chrono::__skip_line(__input);
-  continue;
-}
 
-sys_seconds __date = sys_seconds{seconds{chrono::__parse_integral(__input, 
false)}} - __offset;
-chrono::__skip_mandatory_whitespace(__input);
-seconds __value{chrono::__parse_integral(__input, false)};
-chrono::__skip_line(__input);
-
-__leap_seconds.emplace_back(std::__private_constructor_tag{}, __date, 
__value);
-  }
+  __entries.emplace_back(__date, __value);
+}
+  }();
+  // The Standard requires the leap seconds to be sorted. The file
+  // leap-seconds.list usually provides them in sorted order, but that is not
+  // guaranteed so we ensure it here.
+  std::ranges::sort(__entries, {}, &__entry::__timestamp);
+
+  // The database should contain the number of seconds inserted by a leap
+  // second (1 or -1). So the difference between the two elements are stored.
+  // std::ranges::views::adjacent has not been implemented yet.
+  (void)ranges::adjacent_find(__entries, [&](const __entry& __first, const 
__entry& __second) {
+__leap_seconds.emplace_back(
+std::__private_constructor_tag{}, __second.__timestamp, 
__second.__value - __first.__value);
+return f

[llvm-branch-commits] [libcxx] [libc++][chrono] Fixes leap seconds. (PR #90070)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Mark de Wever (mordante)


Changes

While implementing the UTC clock it turns out that the implementation of the 
leap seconds was not correct, it should store the individual value, not the sum.

It also looks like LWG3359 has not been fully implemented.

Implements parts of:
- LWG3359  leap second support should allow for negative leap 
seconds

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


4 Files Affected:

- (modified) libcxx/docs/Status/Cxx20Issues.csv (+1-1) 
- (modified) libcxx/src/tzdb.cpp (+40-24) 
- (modified) 
libcxx/test/libcxx/time/time.zone/time.zone.db/leap_seconds.pass.cpp (+15-8) 
- (modified) libcxx/test/std/time/time.zone/time.zone.db/leap_seconds.pass.cpp 
(+27-28) 


``diff
diff --git a/libcxx/docs/Status/Cxx20Issues.csv 
b/libcxx/docs/Status/Cxx20Issues.csv
index db57b15256a62f..fed1c7e736248f 100644
--- a/libcxx/docs/Status/Cxx20Issues.csv
+++ b/libcxx/docs/Status/Cxx20Issues.csv
@@ -269,7 +269,7 @@
 "`3355 `__","The memory algorithms should support 
move-only input iterators introduced by 
P1207","Prague","|Complete|","15.0","|ranges|"
 "`3356 `__","``__cpp_lib_nothrow_convertible``\  
should be ``__cpp_lib_is_nothrow_convertible``\ ","Prague","|Complete|","12.0"
 "`3358 `__","|sect|\ [span.cons] is mistaken that 
``to_address``\  can throw","Prague","|Complete|","17.0"
-"`3359 `__","\  leap second support 
should allow for negative leap seconds","Prague","|Complete|","19.0","|chrono|"
+"`3359 `__","\  leap second support 
should allow for negative leap seconds","Prague","|In Progress|","","|chrono|"
 "`3360 `__","``three_way_comparable_with``\  is 
inconsistent with similar concepts","Prague","|Nothing To Do|","","|spaceship|"
 "`3362 `__","Strike ``stop_source``\ 's 
``operator!=``\ ","Prague","",""
 "`3363 `__","``drop_while_view``\  should opt-out 
of ``sized_range``\ ","Prague","|Nothing To Do|","","|ranges|"
diff --git a/libcxx/src/tzdb.cpp b/libcxx/src/tzdb.cpp
index 5951e59248e94f..8588646bbbc417 100644
--- a/libcxx/src/tzdb.cpp
+++ b/libcxx/src/tzdb.cpp
@@ -626,29 +626,49 @@ static void __parse_leap_seconds(vector& 
__leap_seconds, istream&&
   // seconds since 1 January 1970.
   constexpr auto __offset = sys_days{1970y / January / 1} - sys_days{1900y / 
January / 1};
 
-  while (true) {
-switch (__input.peek()) {
-case istream::traits_type::eof():
-  return;
-
-case ' ':
-case '\t':
-case '\n':
-  __input.get();
-  continue;
+  struct __entry {
+sys_seconds __timestamp;
+seconds __value;
+  };
+  vector<__entry> __entries;
+  [&] {
+while (true) {
+  switch (__input.peek()) {
+  case istream::traits_type::eof():
+return;
+
+  case ' ':
+  case '\t':
+  case '\n':
+__input.get();
+continue;
+
+  case '#':
+chrono::__skip_line(__input);
+continue;
+  }
 
-case '#':
+  sys_seconds __date = 
sys_seconds{seconds{chrono::__parse_integral(__input, false)}} - __offset;
+  chrono::__skip_mandatory_whitespace(__input);
+  seconds __value{chrono::__parse_integral(__input, false)};
   chrono::__skip_line(__input);
-  continue;
-}
 
-sys_seconds __date = sys_seconds{seconds{chrono::__parse_integral(__input, 
false)}} - __offset;
-chrono::__skip_mandatory_whitespace(__input);
-seconds __value{chrono::__parse_integral(__input, false)};
-chrono::__skip_line(__input);
-
-__leap_seconds.emplace_back(std::__private_constructor_tag{}, __date, 
__value);
-  }
+  __entries.emplace_back(__date, __value);
+}
+  }();
+  // The Standard requires the leap seconds to be sorted. The file
+  // leap-seconds.list usually provides them in sorted order, but that is not
+  // guaranteed so we ensure it here.
+  std::ranges::sort(__entries, {}, &__entry::__timestamp);
+
+  // The database should contain the number of seconds inserted by a leap
+  // second (1 or -1). So the difference between the two elements are stored.
+  // std::ranges::views::adjacent has not been implemented yet.
+  (void)ranges::adjacent_find(__entries, [&](const __entry& __first, const 
__entry& __second) {
+__leap_seconds.emplace_back(
+std::__private_constructor_tag{}, __second.__timestamp, 
__second.__value - __first.__value);
+return false;
+  });
 }
 
 void __init_tzdb(tzdb& __tzdb, __tz::__rules_storage_type& __rules) {
@@ -667,10 +687,6 @@ void __init_tzdb(tzdb& __tzdb, __tz::__rules_storage_type& 
__rules) {
   // The latter is much easier to parse, it seems Howard shares that
   // opinion.
   chrono::__parse_leap_seconds(__tzdb.leap_seconds, ifstream{__root / 
"leap-seconds.list"});
-  // The Standard requires the leap seconds t

[llvm-branch-commits] [clang] [polly] release/18.x: [clang-format] Correctly annotate braces in macros (#87… (PR #89491)

2024-04-25 Thread Owen Pan via llvm-branch-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/89491

>From 35fea1032741526f76d7fea49794061bf3a1d3ee Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 19 Apr 2024 23:20:47 -0700
Subject: [PATCH] release/18.x: [clang-format] Correctly annotate braces in
 macros (#87953)

Backport 58323de2e5ed
---
 clang/lib/Format/UnwrappedLineParser.cpp  | 20 +--
 clang/unittests/Format/FormatTest.cpp |  9 -
 clang/unittests/Format/TokenAnnotatorTest.cpp | 14 +
 .../lib/Analysis/ScopDetectionDiagnostic.cpp  |  2 +-
 4 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index b7d970f45271da..a6eb18bb2b3227 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -539,16 +539,6 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 if (Style.Language == FormatStyle::LK_Proto) {
   ProbablyBracedList = NextTok->isOneOf(tok::comma, tok::r_square);
 } else {
-  // Skip NextTok over preprocessor lines, otherwise we may not
-  // properly diagnose the block as a braced intializer
-  // if the comma separator appears after the pp directive.
-  while (NextTok->is(tok::hash)) {
-ScopedMacroState MacroState(*Line, Tokens, NextTok);
-do {
-  NextTok = Tokens->getNextToken();
-} while (NextTok->isNot(tok::eof));
-  }
-
   // Using OriginalColumn to distinguish between ObjC methods and
   // binary operators is a bit hacky.
   bool NextIsObjCMethod = NextTok->isOneOf(tok::plus, tok::minus) &&
@@ -607,6 +597,16 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 NextTok = Tokens->getNextToken();
 ProbablyBracedList = NextTok->isNot(tok::l_square);
   }
+
+  // Cpp macro definition body that is a nonempty braced list or block:
+  if (Style.isCpp() && Line->InMacroBody && PrevTok != FormatTok &&
+  !FormatTok->Previous && NextTok->is(tok::eof) &&
+  // A statement can end with only `;` (simple statement), a block
+  // closing brace (compound statement), or `:` (label statement).
+  // If PrevTok is a block opening brace, Tok ends an empty block.
+  !PrevTok->isOneOf(tok::semi, BK_Block, tok::colon)) {
+ProbablyBracedList = true;
+  }
 }
 if (ProbablyBracedList) {
   Tok->setBlockKind(BK_BracedInit);
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 2ac0b0aab1bee9..88877e53d014c6 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1865,6 +1865,13 @@ TEST_F(FormatTest, UnderstandsMacros) {
   verifyFormat("MACRO(co_return##something)");
 
   verifyFormat("#define A x:");
+
+  verifyFormat("#define Foo(Bar) {#Bar}", "#define Foo(Bar) \\\n"
+  "  { \\\n"
+  "#Bar \\\n"
+  "  }");
+  verifyFormat("#define Foo(Bar) {#Bar}", "#define Foo(Bar) \\\n"
+  "  { #Bar }");
 }
 
 TEST_F(FormatTest, ShortBlocksInMacrosDontMergeWithCodeAfterMacro) {
@@ -10865,7 +10872,7 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) {
   verifyFormat("some_templated_type");
 
   verifyFormat("#define FOO(typeName, realClass)   
\\\n"
-   "  { #typeName, foo(new foo(#typeName)) }",
+   "  {#typeName, foo(new foo(#typeName))}",
getLLVMStyleWithColumns(60));
 }
 
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index cbe6b79a366882..c530339826a1d3 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1885,14 +1885,20 @@ TEST_F(TokenAnnotatorTest, UnderstandHashInMacro) {
  "#Bar \\\n"
  "  }");
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
-  EXPECT_BRACE_KIND(Tokens[6], BK_Block);
-  EXPECT_BRACE_KIND(Tokens[9], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[6], BK_BracedInit);
+  EXPECT_BRACE_KIND(Tokens[9], BK_BracedInit);
 
   Tokens = annotate("#define Foo(Bar) \\\n"
 "  { #Bar }");
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
-  EXPECT_BRACE_KIND(Tokens[6], BK_Block);
-  EXPECT_BRACE_KIND(Tokens[9], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[6], BK_BracedInit);
+  EXPECT_BRACE_KIND(Tokens[9], BK_BracedInit);
+
+  Tokens = annotate("#define FOO(typeName, realClass) \\\n"
+"  {#typeName, foo(new foo(#typeName))}");
+  ASSERT_EQ(Tokens.size(), 29u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[8], BK_BracedInit);
+  EX

[llvm-branch-commits] [clang] release/18.x: [clang-format] Fix a regression in ContinuationIndenter (#88414) (PR #89412)

2024-04-25 Thread Owen Pan via llvm-branch-commits

owenca wrote:

@tstellar is this waiting for @HazardyKnusperkeks?

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


[llvm-branch-commits] [clang] release/18.x: [clang-format] Fix a regression in annotating TrailingReturnArrow (#86624) (PR #89415)

2024-04-25 Thread Owen Pan via llvm-branch-commits

owenca wrote:

@tstellar is this still waiting for @HazardyKnusperkeks?

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


[llvm-branch-commits] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-25 Thread Pengcheng Wang via llvm-branch-commits

wangpc-pp wrote:

> > For saturating instructions, they may write vxsat. This is like
> > floating-point instructions that may write fflags, but we don't
> > model floating-point instructions as hasSideEffects=1.
> 
> That's because floating point instructions use mayRaiseFPExceptions=1. And 
> STRICT_* nodes set don't set the NoFPExcept bit in MIFlags. Though we don't 
> have a story for how to make reading FFLAGS work with riscv.* intrinsics. 
> That's an issue on all targets as there is no "constrained" or "strict" 
> support for target specific intrinsics.

Thanks! I forgot about `mayRaiseFPExceptions.

I don't know if I understand correctly, if we have defined explicit `Def` list, 
does it mean that we have modelled it and there is no unmodelled side effect?

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


[llvm-branch-commits] [clang] [polly] release/18.x: [clang-format] Correctly annotate braces in macros (#87… (PR #89491)

2024-04-25 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/89491
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [polly] 35fea10 - release/18.x: [clang-format] Correctly annotate braces in macros (#87953)

2024-04-25 Thread Owen Pan via llvm-branch-commits

Author: Owen Pan
Date: 2024-04-25T08:31:16-07:00
New Revision: 35fea1032741526f76d7fea49794061bf3a1d3ee

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

LOG: release/18.x: [clang-format] Correctly annotate braces in macros (#87953)

Backport 58323de2e5ed

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
polly/lib/Analysis/ScopDetectionDiagnostic.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index b7d970f45271da..a6eb18bb2b3227 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -539,16 +539,6 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 if (Style.Language == FormatStyle::LK_Proto) {
   ProbablyBracedList = NextTok->isOneOf(tok::comma, tok::r_square);
 } else {
-  // Skip NextTok over preprocessor lines, otherwise we may not
-  // properly diagnose the block as a braced intializer
-  // if the comma separator appears after the pp directive.
-  while (NextTok->is(tok::hash)) {
-ScopedMacroState MacroState(*Line, Tokens, NextTok);
-do {
-  NextTok = Tokens->getNextToken();
-} while (NextTok->isNot(tok::eof));
-  }
-
   // Using OriginalColumn to distinguish between ObjC methods and
   // binary operators is a bit hacky.
   bool NextIsObjCMethod = NextTok->isOneOf(tok::plus, tok::minus) &&
@@ -607,6 +597,16 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 NextTok = Tokens->getNextToken();
 ProbablyBracedList = NextTok->isNot(tok::l_square);
   }
+
+  // Cpp macro definition body that is a nonempty braced list or block:
+  if (Style.isCpp() && Line->InMacroBody && PrevTok != FormatTok &&
+  !FormatTok->Previous && NextTok->is(tok::eof) &&
+  // A statement can end with only `;` (simple statement), a block
+  // closing brace (compound statement), or `:` (label statement).
+  // If PrevTok is a block opening brace, Tok ends an empty block.
+  !PrevTok->isOneOf(tok::semi, BK_Block, tok::colon)) {
+ProbablyBracedList = true;
+  }
 }
 if (ProbablyBracedList) {
   Tok->setBlockKind(BK_BracedInit);

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 2ac0b0aab1bee9..88877e53d014c6 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1865,6 +1865,13 @@ TEST_F(FormatTest, UnderstandsMacros) {
   verifyFormat("MACRO(co_return##something)");
 
   verifyFormat("#define A x:");
+
+  verifyFormat("#define Foo(Bar) {#Bar}", "#define Foo(Bar) \\\n"
+  "  { \\\n"
+  "#Bar \\\n"
+  "  }");
+  verifyFormat("#define Foo(Bar) {#Bar}", "#define Foo(Bar) \\\n"
+  "  { #Bar }");
 }
 
 TEST_F(FormatTest, ShortBlocksInMacrosDontMergeWithCodeAfterMacro) {
@@ -10865,7 +10872,7 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) {
   verifyFormat("some_templated_type");
 
   verifyFormat("#define FOO(typeName, realClass)   
\\\n"
-   "  { #typeName, foo(new foo(#typeName)) }",
+   "  {#typeName, foo(new foo(#typeName))}",
getLLVMStyleWithColumns(60));
 }
 

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index cbe6b79a366882..c530339826a1d3 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1885,14 +1885,20 @@ TEST_F(TokenAnnotatorTest, UnderstandHashInMacro) {
  "#Bar \\\n"
  "  }");
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
-  EXPECT_BRACE_KIND(Tokens[6], BK_Block);
-  EXPECT_BRACE_KIND(Tokens[9], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[6], BK_BracedInit);
+  EXPECT_BRACE_KIND(Tokens[9], BK_BracedInit);
 
   Tokens = annotate("#define Foo(Bar) \\\n"
 "  { #Bar }");
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
-  EXPECT_BRACE_KIND(Tokens[6], BK_Block);
-  EXPECT_BRACE_KIND(Tokens[9], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[6], BK_BracedInit);
+  EXPECT_BRACE_KIND(Tokens[9], BK_BracedInit);
+
+  Tokens = annotate("#define FOO(typeName, realClass) \\\n"
+"  {#typeName, foo(new foo(#typeName))}");
+  ASSERT_EQ(Tokens.

[llvm-branch-commits] [llvm] release/18.x: [DAGCombiner] Fix miscompile bug in combineShiftOfShiftedLogic (#89616) (PR #89766)

2024-04-25 Thread Tom Stellard via llvm-branch-commits
=?utf-8?q?Björn?= Pettersson 
Message-ID:
In-Reply-To: 


https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/89766

>From 1aa91720cc4fa1511c0851269babb40a05401193 Mon Sep 17 00:00:00 2001
From: Bjorn Pettersson 
Date: Mon, 22 Apr 2024 17:34:48 +0200
Subject: [PATCH 1/2] [DAGCombiner] Pre-commit test case for miscompile bug in
 combineShiftOfShiftedLogic

DAGCombiner is trying to fold shl over binops, and in the process
combining it with another shl. However it needs to be more careful
to ensure that the sum of the shift counts fits in the type used
for the shift amount.
For example, X86 is using i8 as shift amount type. So we need to
make sure that the sum of the shift amounts isn't greater than 255.

Fix will be applied in a later commit. This only pre-commits the
test case to show that we currently get the wrong result.

Bug was found when testing the C23 BitInt feature.

(cherry picked from commit 5fd9bbdea6cc248469d5465de44e747378ffafcb)
---
 llvm/test/CodeGen/X86/shift-combine.ll | 65 ++
 1 file changed, 65 insertions(+)

diff --git a/llvm/test/CodeGen/X86/shift-combine.ll 
b/llvm/test/CodeGen/X86/shift-combine.ll
index cf45641fba6321..f5bf3de9114dc5 100644
--- a/llvm/test/CodeGen/X86/shift-combine.ll
+++ b/llvm/test/CodeGen/X86/shift-combine.ll
@@ -787,3 +787,68 @@ define <4 x i32> 
@or_tree_with_mismatching_shifts_vec_i32(<4 x i32> %a, <4 x i32
   %r = or <4 x i32> %or.ab, %or.cd
   ret <4 x i32> %r
 }
+
+; FIXME: Reproducer for a DAGCombiner::combineShiftOfShiftedLogic
+; bug. DAGCombiner need to check that the sum of the shift amounts fits in i8,
+; which is the legal type used to described X86 shift amounts. Verify that we
+; do not try to create a shift with 130+160 as shift amount, and verify that
+; the stored value do not depend on %a1.
+define void @combineShiftOfShiftedLogic(i128 %a1, i32 %a2, ptr %p) {
+; X86-LABEL: combineShiftOfShiftedLogic:
+; X86:   # %bb.0:
+; X86-NEXT:pushl %ebx
+; X86-NEXT:.cfi_def_cfa_offset 8
+; X86-NEXT:pushl %edi
+; X86-NEXT:.cfi_def_cfa_offset 12
+; X86-NEXT:pushl %esi
+; X86-NEXT:.cfi_def_cfa_offset 16
+; X86-NEXT:.cfi_offset %esi, -16
+; X86-NEXT:.cfi_offset %edi, -12
+; X86-NEXT:.cfi_offset %ebx, -8
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:movl {{[0-9]+}}(%esp), %ecx
+; X86-NEXT:movl {{[0-9]+}}(%esp), %edx
+; X86-NEXT:movl {{[0-9]+}}(%esp), %ebx
+; X86-NEXT:movl {{[0-9]+}}(%esp), %edi
+; X86-NEXT:movl %edi, %esi
+; X86-NEXT:shldl $2, %ebx, %edi
+; X86-NEXT:shldl $2, %edx, %ebx
+; X86-NEXT:shrl $30, %esi
+; X86-NEXT:orl {{[0-9]+}}(%esp), %esi
+; X86-NEXT:shldl $2, %ecx, %edx
+; X86-NEXT:shll $2, %ecx
+; X86-NEXT:movl %edi, 16(%eax)
+; X86-NEXT:movl %ebx, 12(%eax)
+; X86-NEXT:movl %edx, 8(%eax)
+; X86-NEXT:movl %ecx, 4(%eax)
+; X86-NEXT:movl %esi, 20(%eax)
+; X86-NEXT:movl $0, (%eax)
+; X86-NEXT:popl %esi
+; X86-NEXT:.cfi_def_cfa_offset 12
+; X86-NEXT:popl %edi
+; X86-NEXT:.cfi_def_cfa_offset 8
+; X86-NEXT:popl %ebx
+; X86-NEXT:.cfi_def_cfa_offset 4
+; X86-NEXT:retl
+;
+; X64-LABEL: combineShiftOfShiftedLogic:
+; X64:   # %bb.0:
+; X64-NEXT:# kill: def $edx killed $edx def $rdx
+; X64-NEXT:shlq $32, %rdx
+; X64-NEXT:movq %rsi, %rax
+; X64-NEXT:shrq $30, %rax
+; X64-NEXT:orq %rdx, %rax
+; X64-NEXT:shldq $34, %rdi, %rsi
+; X64-NEXT:shlq $34, %rdi
+; X64-NEXT:movq %rsi, 8(%rcx)
+; X64-NEXT:movq %rdi, (%rcx)
+; X64-NEXT:movq %rax, 16(%rcx)
+; X64-NEXT:retq
+  %zext1 = zext i128 %a1 to i192
+  %zext2 = zext i32 %a2 to i192
+  %shl = shl i192 %zext1, 130
+  %or = or i192 %shl, %zext2
+  %res = shl i192 %or, 160
+  store i192 %res, ptr %p, align 8
+  ret void
+}

>From 78b99c73ee4b96fe9ce0e294d4632326afb2db42 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Pettersson?= 
Date: Tue, 23 Apr 2024 14:11:34 +0200
Subject: [PATCH 2/2] [DAGCombiner] Fix miscompile bug in
 combineShiftOfShiftedLogic (#89616)

Ensure that the sum of the shift amounts does not overflow the
shift amount type when combining shifts in combineShiftOfShiftedLogic.

Solves a miscompile bug found when testing the C23 BitInt feature.

Targets like X86 that only use an i8 for shift amounts after
legalization seems to be extra susceptible for bugs like this as it
isn't legal to shift more than 255 steps.

(cherry picked from commit f9b419b7a038dcd51a7943b160acc867714c595f)
---
 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp |  9 ++-
 llvm/test/CodeGen/X86/shift-combine.ll| 58 +--
 2 files changed, 22 insertions(+), 45 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp 
b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index e806e0f0731f23..5038f8a1fc1562 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -9636,8 +9636,15 @@ static SDValue combineSh

[llvm-branch-commits] [llvm] 78b99c7 - [DAGCombiner] Fix miscompile bug in combineShiftOfShiftedLogic (#89616)

2024-04-25 Thread Tom Stellard via llvm-branch-commits

Author: Björn Pettersson
Date: 2024-04-25T09:54:12-07:00
New Revision: 78b99c73ee4b96fe9ce0e294d4632326afb2db42

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

LOG: [DAGCombiner] Fix miscompile bug in combineShiftOfShiftedLogic (#89616)

Ensure that the sum of the shift amounts does not overflow the
shift amount type when combining shifts in combineShiftOfShiftedLogic.

Solves a miscompile bug found when testing the C23 BitInt feature.

Targets like X86 that only use an i8 for shift amounts after
legalization seems to be extra susceptible for bugs like this as it
isn't legal to shift more than 255 steps.

(cherry picked from commit f9b419b7a038dcd51a7943b160acc867714c595f)

Added: 


Modified: 
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/X86/shift-combine.ll

Removed: 




diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp 
b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index e806e0f0731f23..5038f8a1fc1562 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -9636,8 +9636,15 @@ static SDValue combineShiftOfShiftedLogic(SDNode *Shift, 
SelectionDAG &DAG) {
 if (ShiftAmtVal->getBitWidth() != C1Val.getBitWidth())
   return false;
 
+// The fold is not valid if the sum of the shift values doesn't fit in the
+// given shift amount type.
+bool Overflow = false;
+APInt NewShiftAmt = C1Val.uadd_ov(*ShiftAmtVal, Overflow);
+if (Overflow)
+  return false;
+
 // The fold is not valid if the sum of the shift values exceeds bitwidth.
-if ((*ShiftAmtVal + C1Val).uge(V.getScalarValueSizeInBits()))
+if (NewShiftAmt.uge(V.getScalarValueSizeInBits()))
   return false;
 
 return true;

diff  --git a/llvm/test/CodeGen/X86/shift-combine.ll 
b/llvm/test/CodeGen/X86/shift-combine.ll
index f5bf3de9114dc5..3316a332fafdff 100644
--- a/llvm/test/CodeGen/X86/shift-combine.ll
+++ b/llvm/test/CodeGen/X86/shift-combine.ll
@@ -788,61 +788,31 @@ define <4 x i32> 
@or_tree_with_mismatching_shifts_vec_i32(<4 x i32> %a, <4 x i32
   ret <4 x i32> %r
 }
 
-; FIXME: Reproducer for a DAGCombiner::combineShiftOfShiftedLogic
-; bug. DAGCombiner need to check that the sum of the shift amounts fits in i8,
-; which is the legal type used to described X86 shift amounts. Verify that we
-; do not try to create a shift with 130+160 as shift amount, and verify that
-; the stored value do not depend on %a1.
+; Reproducer for a DAGCombiner::combineShiftOfShiftedLogic bug. DAGCombiner
+; need to check that the sum of the shift amounts fits in i8, which is the
+; legal type used to described X86 shift amounts. Verify that we do not try to
+; create a shift with 130+160 as shift amount, and verify that the stored
+; value do not depend on %a1.
 define void @combineShiftOfShiftedLogic(i128 %a1, i32 %a2, ptr %p) {
 ; X86-LABEL: combineShiftOfShiftedLogic:
 ; X86:   # %bb.0:
-; X86-NEXT:pushl %ebx
-; X86-NEXT:.cfi_def_cfa_offset 8
-; X86-NEXT:pushl %edi
-; X86-NEXT:.cfi_def_cfa_offset 12
-; X86-NEXT:pushl %esi
-; X86-NEXT:.cfi_def_cfa_offset 16
-; X86-NEXT:.cfi_offset %esi, -16
-; X86-NEXT:.cfi_offset %edi, -12
-; X86-NEXT:.cfi_offset %ebx, -8
 ; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
 ; X86-NEXT:movl {{[0-9]+}}(%esp), %ecx
-; X86-NEXT:movl {{[0-9]+}}(%esp), %edx
-; X86-NEXT:movl {{[0-9]+}}(%esp), %ebx
-; X86-NEXT:movl {{[0-9]+}}(%esp), %edi
-; X86-NEXT:movl %edi, %esi
-; X86-NEXT:shldl $2, %ebx, %edi
-; X86-NEXT:shldl $2, %edx, %ebx
-; X86-NEXT:shrl $30, %esi
-; X86-NEXT:orl {{[0-9]+}}(%esp), %esi
-; X86-NEXT:shldl $2, %ecx, %edx
-; X86-NEXT:shll $2, %ecx
-; X86-NEXT:movl %edi, 16(%eax)
-; X86-NEXT:movl %ebx, 12(%eax)
-; X86-NEXT:movl %edx, 8(%eax)
-; X86-NEXT:movl %ecx, 4(%eax)
-; X86-NEXT:movl %esi, 20(%eax)
-; X86-NEXT:movl $0, (%eax)
-; X86-NEXT:popl %esi
-; X86-NEXT:.cfi_def_cfa_offset 12
-; X86-NEXT:popl %edi
-; X86-NEXT:.cfi_def_cfa_offset 8
-; X86-NEXT:popl %ebx
-; X86-NEXT:.cfi_def_cfa_offset 4
+; X86-NEXT:movl %eax, 20(%ecx)
+; X86-NEXT:movl $0, 16(%ecx)
+; X86-NEXT:movl $0, 12(%ecx)
+; X86-NEXT:movl $0, 8(%ecx)
+; X86-NEXT:movl $0, 4(%ecx)
+; X86-NEXT:movl $0, (%ecx)
 ; X86-NEXT:retl
 ;
 ; X64-LABEL: combineShiftOfShiftedLogic:
 ; X64:   # %bb.0:
 ; X64-NEXT:# kill: def $edx killed $edx def $rdx
 ; X64-NEXT:shlq $32, %rdx
-; X64-NEXT:movq %rsi, %rax
-; X64-NEXT:shrq $30, %rax
-; X64-NEXT:orq %rdx, %rax
-; X64-NEXT:shldq $34, %rdi, %rsi
-; X64-NEXT:shlq $34, %rdi
-; X64-NEXT:movq %rsi, 8(%rcx)
-; X64-NEXT:movq %rdi, (%rcx)
-; X64-NEXT:movq %rax, 16(%rcx)
+; X64-NEXT:movq 

[llvm-branch-commits] [llvm] 1aa9172 - [DAGCombiner] Pre-commit test case for miscompile bug in combineShiftOfShiftedLogic

2024-04-25 Thread Tom Stellard via llvm-branch-commits

Author: Bjorn Pettersson
Date: 2024-04-25T09:54:12-07:00
New Revision: 1aa91720cc4fa1511c0851269babb40a05401193

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

LOG: [DAGCombiner] Pre-commit test case for miscompile bug in 
combineShiftOfShiftedLogic

DAGCombiner is trying to fold shl over binops, and in the process
combining it with another shl. However it needs to be more careful
to ensure that the sum of the shift counts fits in the type used
for the shift amount.
For example, X86 is using i8 as shift amount type. So we need to
make sure that the sum of the shift amounts isn't greater than 255.

Fix will be applied in a later commit. This only pre-commits the
test case to show that we currently get the wrong result.

Bug was found when testing the C23 BitInt feature.

(cherry picked from commit 5fd9bbdea6cc248469d5465de44e747378ffafcb)

Added: 


Modified: 
llvm/test/CodeGen/X86/shift-combine.ll

Removed: 




diff  --git a/llvm/test/CodeGen/X86/shift-combine.ll 
b/llvm/test/CodeGen/X86/shift-combine.ll
index cf45641fba6321..f5bf3de9114dc5 100644
--- a/llvm/test/CodeGen/X86/shift-combine.ll
+++ b/llvm/test/CodeGen/X86/shift-combine.ll
@@ -787,3 +787,68 @@ define <4 x i32> 
@or_tree_with_mismatching_shifts_vec_i32(<4 x i32> %a, <4 x i32
   %r = or <4 x i32> %or.ab, %or.cd
   ret <4 x i32> %r
 }
+
+; FIXME: Reproducer for a DAGCombiner::combineShiftOfShiftedLogic
+; bug. DAGCombiner need to check that the sum of the shift amounts fits in i8,
+; which is the legal type used to described X86 shift amounts. Verify that we
+; do not try to create a shift with 130+160 as shift amount, and verify that
+; the stored value do not depend on %a1.
+define void @combineShiftOfShiftedLogic(i128 %a1, i32 %a2, ptr %p) {
+; X86-LABEL: combineShiftOfShiftedLogic:
+; X86:   # %bb.0:
+; X86-NEXT:pushl %ebx
+; X86-NEXT:.cfi_def_cfa_offset 8
+; X86-NEXT:pushl %edi
+; X86-NEXT:.cfi_def_cfa_offset 12
+; X86-NEXT:pushl %esi
+; X86-NEXT:.cfi_def_cfa_offset 16
+; X86-NEXT:.cfi_offset %esi, -16
+; X86-NEXT:.cfi_offset %edi, -12
+; X86-NEXT:.cfi_offset %ebx, -8
+; X86-NEXT:movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT:movl {{[0-9]+}}(%esp), %ecx
+; X86-NEXT:movl {{[0-9]+}}(%esp), %edx
+; X86-NEXT:movl {{[0-9]+}}(%esp), %ebx
+; X86-NEXT:movl {{[0-9]+}}(%esp), %edi
+; X86-NEXT:movl %edi, %esi
+; X86-NEXT:shldl $2, %ebx, %edi
+; X86-NEXT:shldl $2, %edx, %ebx
+; X86-NEXT:shrl $30, %esi
+; X86-NEXT:orl {{[0-9]+}}(%esp), %esi
+; X86-NEXT:shldl $2, %ecx, %edx
+; X86-NEXT:shll $2, %ecx
+; X86-NEXT:movl %edi, 16(%eax)
+; X86-NEXT:movl %ebx, 12(%eax)
+; X86-NEXT:movl %edx, 8(%eax)
+; X86-NEXT:movl %ecx, 4(%eax)
+; X86-NEXT:movl %esi, 20(%eax)
+; X86-NEXT:movl $0, (%eax)
+; X86-NEXT:popl %esi
+; X86-NEXT:.cfi_def_cfa_offset 12
+; X86-NEXT:popl %edi
+; X86-NEXT:.cfi_def_cfa_offset 8
+; X86-NEXT:popl %ebx
+; X86-NEXT:.cfi_def_cfa_offset 4
+; X86-NEXT:retl
+;
+; X64-LABEL: combineShiftOfShiftedLogic:
+; X64:   # %bb.0:
+; X64-NEXT:# kill: def $edx killed $edx def $rdx
+; X64-NEXT:shlq $32, %rdx
+; X64-NEXT:movq %rsi, %rax
+; X64-NEXT:shrq $30, %rax
+; X64-NEXT:orq %rdx, %rax
+; X64-NEXT:shldq $34, %rdi, %rsi
+; X64-NEXT:shlq $34, %rdi
+; X64-NEXT:movq %rsi, 8(%rcx)
+; X64-NEXT:movq %rdi, (%rcx)
+; X64-NEXT:movq %rax, 16(%rcx)
+; X64-NEXT:retq
+  %zext1 = zext i128 %a1 to i192
+  %zext2 = zext i32 %a2 to i192
+  %shl = shl i192 %zext1, 130
+  %or = or i192 %shl, %zext2
+  %res = shl i192 %or, 160
+  store i192 %res, ptr %p, align 8
+  ret void
+}



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


[llvm-branch-commits] [llvm] release/18.x: [DAGCombiner] Fix miscompile bug in combineShiftOfShiftedLogic (#89616) (PR #89766)

2024-04-25 Thread Tom Stellard via llvm-branch-commits
=?utf-8?q?Björn?= Pettersson 
Message-ID:
In-Reply-To: 


https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/89766
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [flang][OpenMP] Implement getIterationVariableSymbol helper function,… (PR #90087)

2024-04-25 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz created 
https://github.com/llvm/llvm-project/pull/90087

… NFC

>From 45d5017db069a8804fbdb75da223b68cbaab11f2 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 26 Mar 2024 10:14:13 -0500
Subject: [PATCH] [flang][OpenMP] Implement getIterationVariableSymbol helper
 function, NFC

---
 flang/lib/Lower/OpenMP/Utils.cpp | 24 +++-
 flang/lib/Lower/OpenMP/Utils.h   |  6 ++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 1400f1f4cc8dd2..c38e0c18cac88c 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -11,10 +11,11 @@
 
//===--===//
 
 #include "Utils.h"
-#include "Clauses.h"
 
+#include "Clauses.h"
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -87,6 +88,27 @@ mlir::Type getLoopVarType(Fortran::lower::AbstractConverter 
&converter,
   return converter.getFirOpBuilder().getIntegerType(loopVarTypeSize);
 }
 
+Fortran::semantics::Symbol *
+getIterationVariableSymbol(const Fortran::lower::pft::Evaluation &eval) {
+  return eval.visit(Fortran::common::visitors{
+  [&](const Fortran::parser::DoConstruct &doLoop) {
+if (const auto &maybeCtrl = doLoop.GetLoopControl()) {
+  using LoopControl = Fortran::parser::LoopControl;
+  if (auto *bounds = std::get_if(&maybeCtrl->u)) {
+static_assert(
+std::is_same_vname),
+   
Fortran::parser::Scalar>);
+return bounds->name.thing.symbol;
+  }
+}
+return static_cast(nullptr);
+  },
+  [](auto &&) {
+return static_cast(nullptr);
+  },
+  });
+}
+
 void gatherFuncAndVarSyms(
 const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
 llvm::SmallVectorImpl &symbolAndClause) {
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index 693a91f7cc6954..5e0ebba23bf358 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -34,6 +34,9 @@ struct OmpObjectList;
 } // namespace parser
 
 namespace lower {
+namespace pft {
+struct Evaluation;
+}
 
 class AbstractConverter;
 
@@ -54,6 +57,9 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location 
loc,
 mlir::Type getLoopVarType(Fortran::lower::AbstractConverter &converter,
   std::size_t loopVarTypeSize);
 
+Fortran::semantics::Symbol *
+getIterationVariableSymbol(const Fortran::lower::pft::Evaluation &eval);
+
 void gatherFuncAndVarSyms(
 const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
 llvm::SmallVectorImpl &symbolAndClause);

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


[llvm-branch-commits] [flang] [flang][OpenMP] Implement getIterationVariableSymbol helper function,… (PR #90087)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-fir-hlfir

Author: Krzysztof Parzyszek (kparzysz)


Changes

… NFC

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


2 Files Affected:

- (modified) flang/lib/Lower/OpenMP/Utils.cpp (+23-1) 
- (modified) flang/lib/Lower/OpenMP/Utils.h (+6) 


``diff
diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 1400f1f4cc8dd2..c38e0c18cac88c 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -11,10 +11,11 @@
 
//===--===//
 
 #include "Utils.h"
-#include "Clauses.h"
 
+#include "Clauses.h"
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -87,6 +88,27 @@ mlir::Type getLoopVarType(Fortran::lower::AbstractConverter 
&converter,
   return converter.getFirOpBuilder().getIntegerType(loopVarTypeSize);
 }
 
+Fortran::semantics::Symbol *
+getIterationVariableSymbol(const Fortran::lower::pft::Evaluation &eval) {
+  return eval.visit(Fortran::common::visitors{
+  [&](const Fortran::parser::DoConstruct &doLoop) {
+if (const auto &maybeCtrl = doLoop.GetLoopControl()) {
+  using LoopControl = Fortran::parser::LoopControl;
+  if (auto *bounds = std::get_if(&maybeCtrl->u)) {
+static_assert(
+std::is_same_vname),
+   
Fortran::parser::Scalar>);
+return bounds->name.thing.symbol;
+  }
+}
+return static_cast(nullptr);
+  },
+  [](auto &&) {
+return static_cast(nullptr);
+  },
+  });
+}
+
 void gatherFuncAndVarSyms(
 const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
 llvm::SmallVectorImpl &symbolAndClause) {
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index 693a91f7cc6954..5e0ebba23bf358 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -34,6 +34,9 @@ struct OmpObjectList;
 } // namespace parser
 
 namespace lower {
+namespace pft {
+struct Evaluation;
+}
 
 class AbstractConverter;
 
@@ -54,6 +57,9 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location 
loc,
 mlir::Type getLoopVarType(Fortran::lower::AbstractConverter &converter,
   std::size_t loopVarTypeSize);
 
+Fortran::semantics::Symbol *
+getIterationVariableSymbol(const Fortran::lower::pft::Evaluation &eval);
+
 void gatherFuncAndVarSyms(
 const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
 llvm::SmallVectorImpl &symbolAndClause);

``




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


[llvm-branch-commits] [flang] [flang][OpenMP] Pass symTable to all genXYZ functions, NFC (PR #90090)

2024-04-25 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz created 
https://github.com/llvm/llvm-project/pull/90090

This will unify the interface a bit more.

>From 8f1ce585ea3b32551563c2949630ad4118d511e6 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Wed, 24 Apr 2024 09:51:49 -0500
Subject: [PATCH] [flang][OpenMP] Pass symTable to all genXYZ functions, NFC

This will unify the interface a bit more.
---
 flang/lib/Lower/OpenMP/OpenMP.cpp | 171 ++
 1 file changed, 105 insertions(+), 66 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index f454f5a45a5150..47935e6cf8efcf 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -548,11 +548,12 @@ struct OpWithBodyGenInfo {
   mlir::Operation *)>;
 
   OpWithBodyGenInfo(Fortran::lower::AbstractConverter &converter,
+Fortran::lower::SymMap &symTable,
 Fortran::semantics::SemanticsContext &semaCtx,
 mlir::Location loc, Fortran::lower::pft::Evaluation &eval,
 llvm::omp::Directive dir)
-  : converter(converter), semaCtx(semaCtx), loc(loc), eval(eval), dir(dir) 
{
-  }
+  : converter(converter), symTable(symTable), semaCtx(semaCtx), loc(loc),
+eval(eval), dir(dir) {}
 
   OpWithBodyGenInfo &setGenNested(bool value) {
 genNested = value;
@@ -589,6 +590,8 @@ struct OpWithBodyGenInfo {
 
   /// [inout] converter to use for the clauses.
   Fortran::lower::AbstractConverter &converter;
+  /// [in] Symbol table
+  Fortran::lower::SymMap &symTable;
   /// [in] Semantics context
   Fortran::semantics::SemanticsContext &semaCtx;
   /// [in] location in source code.
@@ -764,6 +767,7 @@ static void createBodyOfOp(mlir::Operation &op, 
OpWithBodyGenInfo &info) {
 
 static void genBodyOfTargetDataOp(
 Fortran::lower::AbstractConverter &converter,
+Fortran::lower::SymMap &symTable,
 Fortran::semantics::SemanticsContext &semaCtx,
 Fortran::lower::pft::Evaluation &eval, bool genNested,
 mlir::omp::TargetDataOp &dataOp, llvm::ArrayRef useDeviceTypes,
@@ -830,6 +834,7 @@ static void genBodyOfTargetDataOp(
 // all the symbols present in mapSymbols as block arguments to this block.
 static void
 genBodyOfTargetOp(Fortran::lower::AbstractConverter &converter,
+  Fortran::lower::SymMap &symTable,
   Fortran::semantics::SemanticsContext &semaCtx,
   Fortran::lower::pft::Evaluation &eval, bool genNested,
   mlir::omp::TargetOp &targetOp,
@@ -1267,6 +1272,7 @@ static void genWsloopClauses(
 
 static mlir::omp::BarrierOp
 genBarrierOp(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::SymMap &symTable,
  Fortran::semantics::SemanticsContext &semaCtx,
  Fortran::lower::pft::Evaluation &eval, mlir::Location loc) {
   return converter.getFirOpBuilder().create(loc);
@@ -1274,6 +1280,7 @@ genBarrierOp(Fortran::lower::AbstractConverter &converter,
 
 static mlir::omp::CriticalOp
 genCriticalOp(Fortran::lower::AbstractConverter &converter,
+  Fortran::lower::SymMap &symTable,
   Fortran::semantics::SemanticsContext &semaCtx,
   Fortran::lower::pft::Evaluation &eval, bool genNested,
   mlir::Location loc, const List &clauses,
@@ -1298,7 +1305,7 @@ genCriticalOp(Fortran::lower::AbstractConverter 
&converter,
   }
 
   return genOpWithBody(
-  OpWithBodyGenInfo(converter, semaCtx, loc, eval,
+  OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval,
 llvm::omp::Directive::OMPD_critical)
   .setGenNested(genNested),
   nameAttr);
@@ -1306,6 +1313,7 @@ genCriticalOp(Fortran::lower::AbstractConverter 
&converter,
 
 static mlir::omp::DistributeOp
 genDistributeOp(Fortran::lower::AbstractConverter &converter,
+Fortran::lower::SymMap &symTable,
 Fortran::semantics::SemanticsContext &semaCtx,
 Fortran::lower::pft::Evaluation &eval, bool genNested,
 mlir::Location loc, const List &clauses) {
@@ -1315,6 +1323,7 @@ genDistributeOp(Fortran::lower::AbstractConverter 
&converter,
 
 static mlir::omp::FlushOp
 genFlushOp(Fortran::lower::AbstractConverter &converter,
+   Fortran::lower::SymMap &symTable,
Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
const ObjectList &objects, const List &clauses) {
@@ -1327,17 +1336,19 @@ genFlushOp(Fortran::lower::AbstractConverter &converter,
 
 static mlir::omp::MasterOp
 genMasterOp(Fortran::lower::AbstractConverter &converter,
+Fortran::lower::SymMap &symTable,
 Fortran::semantics::SemanticsContext &semaCtx,
 Fortran::lower::pft::Evaluation &eval, bool genNested,
 mlir::Location loc) {
   return genOpWithBody(
-  OpWithBodyGenInfo(converte

[llvm-branch-commits] [flang] [flang][OpenMP] Pass symTable to all genXYZ functions, NFC (PR #90090)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-fir-hlfir

Author: Krzysztof Parzyszek (kparzysz)


Changes

This will unify the interface a bit more.

---

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


1 Files Affected:

- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+105-66) 


``diff
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index f454f5a45a5150..47935e6cf8efcf 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -548,11 +548,12 @@ struct OpWithBodyGenInfo {
   mlir::Operation *)>;
 
   OpWithBodyGenInfo(Fortran::lower::AbstractConverter &converter,
+Fortran::lower::SymMap &symTable,
 Fortran::semantics::SemanticsContext &semaCtx,
 mlir::Location loc, Fortran::lower::pft::Evaluation &eval,
 llvm::omp::Directive dir)
-  : converter(converter), semaCtx(semaCtx), loc(loc), eval(eval), dir(dir) 
{
-  }
+  : converter(converter), symTable(symTable), semaCtx(semaCtx), loc(loc),
+eval(eval), dir(dir) {}
 
   OpWithBodyGenInfo &setGenNested(bool value) {
 genNested = value;
@@ -589,6 +590,8 @@ struct OpWithBodyGenInfo {
 
   /// [inout] converter to use for the clauses.
   Fortran::lower::AbstractConverter &converter;
+  /// [in] Symbol table
+  Fortran::lower::SymMap &symTable;
   /// [in] Semantics context
   Fortran::semantics::SemanticsContext &semaCtx;
   /// [in] location in source code.
@@ -764,6 +767,7 @@ static void createBodyOfOp(mlir::Operation &op, 
OpWithBodyGenInfo &info) {
 
 static void genBodyOfTargetDataOp(
 Fortran::lower::AbstractConverter &converter,
+Fortran::lower::SymMap &symTable,
 Fortran::semantics::SemanticsContext &semaCtx,
 Fortran::lower::pft::Evaluation &eval, bool genNested,
 mlir::omp::TargetDataOp &dataOp, llvm::ArrayRef useDeviceTypes,
@@ -830,6 +834,7 @@ static void genBodyOfTargetDataOp(
 // all the symbols present in mapSymbols as block arguments to this block.
 static void
 genBodyOfTargetOp(Fortran::lower::AbstractConverter &converter,
+  Fortran::lower::SymMap &symTable,
   Fortran::semantics::SemanticsContext &semaCtx,
   Fortran::lower::pft::Evaluation &eval, bool genNested,
   mlir::omp::TargetOp &targetOp,
@@ -1267,6 +1272,7 @@ static void genWsloopClauses(
 
 static mlir::omp::BarrierOp
 genBarrierOp(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::SymMap &symTable,
  Fortran::semantics::SemanticsContext &semaCtx,
  Fortran::lower::pft::Evaluation &eval, mlir::Location loc) {
   return converter.getFirOpBuilder().create(loc);
@@ -1274,6 +1280,7 @@ genBarrierOp(Fortran::lower::AbstractConverter &converter,
 
 static mlir::omp::CriticalOp
 genCriticalOp(Fortran::lower::AbstractConverter &converter,
+  Fortran::lower::SymMap &symTable,
   Fortran::semantics::SemanticsContext &semaCtx,
   Fortran::lower::pft::Evaluation &eval, bool genNested,
   mlir::Location loc, const List &clauses,
@@ -1298,7 +1305,7 @@ genCriticalOp(Fortran::lower::AbstractConverter 
&converter,
   }
 
   return genOpWithBody(
-  OpWithBodyGenInfo(converter, semaCtx, loc, eval,
+  OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval,
 llvm::omp::Directive::OMPD_critical)
   .setGenNested(genNested),
   nameAttr);
@@ -1306,6 +1313,7 @@ genCriticalOp(Fortran::lower::AbstractConverter 
&converter,
 
 static mlir::omp::DistributeOp
 genDistributeOp(Fortran::lower::AbstractConverter &converter,
+Fortran::lower::SymMap &symTable,
 Fortran::semantics::SemanticsContext &semaCtx,
 Fortran::lower::pft::Evaluation &eval, bool genNested,
 mlir::Location loc, const List &clauses) {
@@ -1315,6 +1323,7 @@ genDistributeOp(Fortran::lower::AbstractConverter 
&converter,
 
 static mlir::omp::FlushOp
 genFlushOp(Fortran::lower::AbstractConverter &converter,
+   Fortran::lower::SymMap &symTable,
Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
const ObjectList &objects, const List &clauses) {
@@ -1327,17 +1336,19 @@ genFlushOp(Fortran::lower::AbstractConverter &converter,
 
 static mlir::omp::MasterOp
 genMasterOp(Fortran::lower::AbstractConverter &converter,
+Fortran::lower::SymMap &symTable,
 Fortran::semantics::SemanticsContext &semaCtx,
 Fortran::lower::pft::Evaluation &eval, bool genNested,
 mlir::Location loc) {
   return genOpWithBody(
-  OpWithBodyGenInfo(converter, semaCtx, loc, eval,
+  OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval,
 llvm::omp::Directive::OMPD_mast

[llvm-branch-commits] [llvm] release/18.x: [AArch64] Remove invalid uabdl patterns. (#89272) (PR #89380)

2024-04-25 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/89380

>From a2bed53a4081ab20c89627f4626c5cbc8e3c9f57 Mon Sep 17 00:00:00 2001
From: David Green 
Date: Fri, 19 Apr 2024 09:30:13 +0100
Subject: [PATCH] [AArch64] Remove invalid uabdl patterns. (#89272)

These were added in https://reviews.llvm.org/D14208, which look like
they attempt to detect abs from xor+add+ashr. They do not appear to be
detecting the correct value for the src input though, which I think is
intended to be the sub(zext, zext) part of the pattern. We have pattens
from abs now, so the old invalid patterns can be removed.

Fixes #88784

(cherry picked from commit 851462fcaa7f6e3301865de84f98be7e872e64b6)
---
 llvm/lib/Target/AArch64/AArch64InstrInfo.td | 10 -
 llvm/test/CodeGen/AArch64/arm64-vabs.ll | 48 +
 2 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.td 
b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
index 03baa7497615e3..ac61dd8745d4e6 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.td
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
@@ -4885,19 +4885,9 @@ defm UABDL   : SIMDLongThreeVectorBHSabdl<1, 0b0111, 
"uabdl",
 def : Pat<(abs (v8i16 (sub (zext (v8i8 V64:$opA)),
(zext (v8i8 V64:$opB),
   (UABDLv8i8_v8i16 V64:$opA, V64:$opB)>;
-def : Pat<(xor (v8i16 (AArch64vashr v8i16:$src, (i32 15))),
-   (v8i16 (add (sub (zext (v8i8 V64:$opA)),
-(zext (v8i8 V64:$opB))),
-   (AArch64vashr v8i16:$src, (i32 15),
-  (UABDLv8i8_v8i16 V64:$opA, V64:$opB)>;
 def : Pat<(abs (v8i16 (sub (zext (extract_high_v16i8 (v16i8 V128:$opA))),
(zext (extract_high_v16i8 (v16i8 V128:$opB)),
   (UABDLv16i8_v8i16 V128:$opA, V128:$opB)>;
-def : Pat<(xor (v8i16 (AArch64vashr v8i16:$src, (i32 15))),
-   (v8i16 (add (sub (zext (extract_high_v16i8 (v16i8 V128:$opA))),
-(zext (extract_high_v16i8 (v16i8 V128:$opB,
-   (AArch64vashr v8i16:$src, (i32 15),
-  (UABDLv16i8_v8i16 V128:$opA, V128:$opB)>;
 def : Pat<(abs (v4i32 (sub (zext (v4i16 V64:$opA)),
(zext (v4i16 V64:$opB),
   (UABDLv4i16_v4i32 V64:$opA, V64:$opB)>;
diff --git a/llvm/test/CodeGen/AArch64/arm64-vabs.ll 
b/llvm/test/CodeGen/AArch64/arm64-vabs.ll
index fe4da2e7cf36b5..89c8d540b97e04 100644
--- a/llvm/test/CodeGen/AArch64/arm64-vabs.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-vabs.ll
@@ -1848,3 +1848,51 @@ define <2 x i128> @uabd_i64(<2 x i64> %a, <2 x i64> %b) {
   %absel = select <2 x i1> %abcmp, <2 x i128> %ababs, <2 x i128> %abdiff
   ret <2 x i128> %absel
 }
+
+define <8 x i16> @pr88784(<8 x i8> %l0, <8 x i8> %l1, <8 x i16> %l2) {
+; CHECK-SD-LABEL: pr88784:
+; CHECK-SD:   // %bb.0:
+; CHECK-SD-NEXT:usubl.8h v0, v0, v1
+; CHECK-SD-NEXT:cmlt.8h v1, v2, #0
+; CHECK-SD-NEXT:ssra.8h v0, v2, #15
+; CHECK-SD-NEXT:eor.16b v0, v1, v0
+; CHECK-SD-NEXT:ret
+;
+; CHECK-GI-LABEL: pr88784:
+; CHECK-GI:   // %bb.0:
+; CHECK-GI-NEXT:usubl.8h v0, v0, v1
+; CHECK-GI-NEXT:sshr.8h v1, v2, #15
+; CHECK-GI-NEXT:ssra.8h v0, v2, #15
+; CHECK-GI-NEXT:eor.16b v0, v1, v0
+; CHECK-GI-NEXT:ret
+  %l4 = zext <8 x i8> %l0 to <8 x i16>
+  %l5 = ashr <8 x i16> %l2, 
+  %l6 = zext <8 x i8> %l1 to <8 x i16>
+  %l7 = sub <8 x i16> %l4, %l6
+  %l8 = add <8 x i16> %l5, %l7
+  %l9 = xor <8 x i16> %l5, %l8
+  ret <8 x i16> %l9
+}
+
+define <8 x i16> @pr88784_fixed(<8 x i8> %l0, <8 x i8> %l1, <8 x i16> %l2) {
+; CHECK-SD-LABEL: pr88784_fixed:
+; CHECK-SD:   // %bb.0:
+; CHECK-SD-NEXT:uabdl.8h v0, v0, v1
+; CHECK-SD-NEXT:ret
+;
+; CHECK-GI-LABEL: pr88784_fixed:
+; CHECK-GI:   // %bb.0:
+; CHECK-GI-NEXT:usubl.8h v0, v0, v1
+; CHECK-GI-NEXT:sshr.8h v1, v0, #15
+; CHECK-GI-NEXT:ssra.8h v0, v0, #15
+; CHECK-GI-NEXT:eor.16b v0, v1, v0
+; CHECK-GI-NEXT:ret
+  %l4 = zext <8 x i8> %l0 to <8 x i16>
+  %l6 = zext <8 x i8> %l1 to <8 x i16>
+  %l7 = sub <8 x i16> %l4, %l6
+  %l5 = ashr <8 x i16> %l7, 
+  %l8 = add <8 x i16> %l5, %l7
+  %l9 = xor <8 x i16> %l5, %l8
+  ret <8 x i16> %l9
+}
+

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


[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Decompose compound construccts, do recursive lowering (PR #90098)

2024-04-25 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz created 
https://github.com/llvm/llvm-project/pull/90098

A compound construct with a list of clauses is broken up into individual 
leaf/composite constructs. Each such construct has the list of clauses that 
apply to it based on the OpenMP spec.

Each lowering function (i.e. a function that generates MLIR ops) is now 
responsible for generating its body as described below.

Functions that receive AST nodes extract the construct, and the clauses from 
the node. They then create a work queue consisting of individual constructs, 
and invoke a common dispatch function.

The dispatch function examines the current position in the queue, and invokes 
the appropriate lowering function. Each lowering function receives the queue as 
well, and once it needs to generate its body, it either invokes the dispatch 
function on the rest of the queue (if any), or processes nested evaluations if 
the work queue is at the end.

>From 6f7697e46ace92707bc4cf648fab25a72c0639a1 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Thu, 11 Apr 2024 10:35:02 -0500
Subject: [PATCH] [flang][OpenMP] Decompose compound construccts, do recursive
 lowering

A compound construct with a list of clauses is broken up into
individual leaf/composite constructs. Each such construct has
the list of clauses that apply to it based on the OpenMP spec.

Each lowering function (i.e. a function that generates MLIR ops)
is now responsible for generating its body as described below.

Functions that receive AST nodes extract the construct, and the
clauses from the node. They then create a work queue consisting
of individual constructs, and invoke a common dispatch function.

The dispatch function examines the current position in the queue,
and invokes the appropriate lowering function. Each lowering
function receives the queue as well, and once it needs to generate
its body, it either invokes the dispatch function on the rest of
the queue (if any), or processes nested evaluations if the work
queue is at the end.
---
 flang/lib/Lower/OpenMP/OpenMP.cpp | 784 +++---
 .../Frontend/OpenMP/ConstructDecompositionT.h | 985 ++
 2 files changed, 1376 insertions(+), 393 deletions(-)
 create mode 100644 llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h

diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 47935e6cf8efcf..4b8afd42f639d5 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -36,6 +36,7 @@
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/Transforms/RegionUtils.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Frontend/OpenMP/ConstructDecompositionT.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
 
 using namespace Fortran::lower::omp;
@@ -72,6 +73,89 @@ static void 
genNestedEvaluations(Fortran::lower::AbstractConverter &converter,
 converter.genEval(e);
 }
 
+//===--===//
+// Directive decomposition
+//===--===//
+
+namespace {
+using DirectiveWithClauses = tomp::DirectiveWithClauses;
+using ConstructQueue = List;
+} // namespace
+
+static void genOMPDispatch(Fortran::lower::AbstractConverter &converter,
+   Fortran::lower::SymMap &symTable,
+   Fortran::semantics::SemanticsContext &semaCtx,
+   Fortran::lower::pft::Evaluation &eval,
+   mlir::Location loc, const ConstructQueue &queue,
+   ConstructQueue::iterator item);
+
+namespace {
+struct ConstructDecomposition {
+  ConstructDecomposition(mlir::ModuleOp modOp,
+ semantics::SemanticsContext &semaCtx,
+ lower::pft::Evaluation &ev,
+ llvm::omp::Directive construct,
+ const List &clauses)
+  : semaCtx(semaCtx), mod(modOp), eval(ev) {
+tomp::ConstructDecompositionT decompose(getOpenMPVersion(modOp), *this,
+construct, 
llvm::ArrayRef(clauses));
+output = std::move(decompose.output);
+  }
+
+  // Given an object, return its base object if one exists.
+  std::optional getBaseObject(const Object &object) {
+return lower::omp::getBaseObject(object, semaCtx);
+  }
+
+  // Return the iteration variable of the associated loop if any.
+  std::optional getLoopIterVar() {
+if (semantics::Symbol *symbol = getIterationVariableSymbol(eval))
+  return Object{symbol, /*designator=*/{}};
+return std::nullopt;
+  }
+
+  semantics::SemanticsContext &semaCtx;
+  mlir::ModuleOp mod;
+  lower::pft::Evaluation &eval;
+  List output;
+};
+} // namespace
+
+LLVM_DUMP_METHOD static llvm::raw_ostream &
+operator<<(llvm::raw_ostream &os, const DirectiveWithClauses &dwc) {
+  os << llvm::omp::getOpenMPDirectiveName(dwc.id);
+  for (auto [i

[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Decompose compound construccts, do recursive lowering (PR #90098)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)


Changes

A compound construct with a list of clauses is broken up into individual 
leaf/composite constructs. Each such construct has the list of clauses that 
apply to it based on the OpenMP spec.

Each lowering function (i.e. a function that generates MLIR ops) is now 
responsible for generating its body as described below.

Functions that receive AST nodes extract the construct, and the clauses from 
the node. They then create a work queue consisting of individual constructs, 
and invoke a common dispatch function.

The dispatch function examines the current position in the queue, and invokes 
the appropriate lowering function. Each lowering function receives the queue as 
well, and once it needs to generate its body, it either invokes the dispatch 
function on the rest of the queue (if any), or processes nested evaluations if 
the work queue is at the end.

---

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


2 Files Affected:

- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+391-393) 
- (added) llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h (+985) 


``diff
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 47935e6cf8efcf..4b8afd42f639d5 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -36,6 +36,7 @@
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/Transforms/RegionUtils.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Frontend/OpenMP/ConstructDecompositionT.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
 
 using namespace Fortran::lower::omp;
@@ -72,6 +73,89 @@ static void 
genNestedEvaluations(Fortran::lower::AbstractConverter &converter,
 converter.genEval(e);
 }
 
+//===--===//
+// Directive decomposition
+//===--===//
+
+namespace {
+using DirectiveWithClauses = tomp::DirectiveWithClauses;
+using ConstructQueue = List;
+} // namespace
+
+static void genOMPDispatch(Fortran::lower::AbstractConverter &converter,
+   Fortran::lower::SymMap &symTable,
+   Fortran::semantics::SemanticsContext &semaCtx,
+   Fortran::lower::pft::Evaluation &eval,
+   mlir::Location loc, const ConstructQueue &queue,
+   ConstructQueue::iterator item);
+
+namespace {
+struct ConstructDecomposition {
+  ConstructDecomposition(mlir::ModuleOp modOp,
+ semantics::SemanticsContext &semaCtx,
+ lower::pft::Evaluation &ev,
+ llvm::omp::Directive construct,
+ const List &clauses)
+  : semaCtx(semaCtx), mod(modOp), eval(ev) {
+tomp::ConstructDecompositionT decompose(getOpenMPVersion(modOp), *this,
+construct, 
llvm::ArrayRef(clauses));
+output = std::move(decompose.output);
+  }
+
+  // Given an object, return its base object if one exists.
+  std::optional getBaseObject(const Object &object) {
+return lower::omp::getBaseObject(object, semaCtx);
+  }
+
+  // Return the iteration variable of the associated loop if any.
+  std::optional getLoopIterVar() {
+if (semantics::Symbol *symbol = getIterationVariableSymbol(eval))
+  return Object{symbol, /*designator=*/{}};
+return std::nullopt;
+  }
+
+  semantics::SemanticsContext &semaCtx;
+  mlir::ModuleOp mod;
+  lower::pft::Evaluation &eval;
+  List output;
+};
+} // namespace
+
+LLVM_DUMP_METHOD static llvm::raw_ostream &
+operator<<(llvm::raw_ostream &os, const DirectiveWithClauses &dwc) {
+  os << llvm::omp::getOpenMPDirectiveName(dwc.id);
+  for (auto [index, clause] : llvm::enumerate(dwc.clauses)) {
+os << (index == 0 ? '\t' : ' ');
+os << llvm::omp::getOpenMPClauseName(clause.id);
+  }
+  return os;
+}
+
+static void splitCompoundConstruct(
+mlir::ModuleOp modOp, Fortran::semantics::SemanticsContext &semaCtx,
+Fortran::lower::pft::Evaluation &eval, llvm::omp::Directive construct,
+const List &clauses, List &directives) {
+
+  ConstructDecomposition decompose(modOp, semaCtx, eval, construct, clauses);
+  assert(!decompose.output.empty());
+
+  llvm::SmallVector loweringUnits;
+  std::ignore =
+  llvm::omp::getLeafOrCompositeConstructs(construct, loweringUnits);
+
+  int leafIndex = 0;
+  for (llvm::omp::Directive dir_id : loweringUnits) {
+directives.push_back(DirectiveWithClauses{dir_id});
+DirectiveWithClauses &dwc = directives.back();
+llvm::ArrayRef leafsOrSelf =
+llvm::omp::getLeafConstructsOrSelf(dir_id);
+for (int i = 0, e = leafsOrSelf.size(); i != e; ++i) {
+  dwc.clauses.append(decompose.output[leafIndex].clauses);
+

[llvm-branch-commits] [flang] [flang][OpenMP] Implement getIterationVariableSymbol helper function,… (PR #90087)

2024-04-25 Thread Kiran Chandramohan via llvm-branch-commits

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

LG.

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


[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Decompose compound construccts, do recursive lowering (PR #90098)

2024-04-25 Thread Kiran Chandramohan via llvm-branch-commits

kiranchandramohan wrote:

Is it possible to add tests for this?

Can we move the decomposition logic into a separate file?

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


[llvm-branch-commits] [flang] [flang][OpenMP] Pass symTable to all genXYZ functions, NFC (PR #90090)

2024-04-25 Thread Kiran Chandramohan via llvm-branch-commits

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

LG.

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


[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Decompose compound construccts, do recursive lowering (PR #90098)

2024-04-25 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/90098

>From 6f7697e46ace92707bc4cf648fab25a72c0639a1 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Thu, 11 Apr 2024 10:35:02 -0500
Subject: [PATCH 1/2] [flang][OpenMP] Decompose compound construccts, do
 recursive lowering

A compound construct with a list of clauses is broken up into
individual leaf/composite constructs. Each such construct has
the list of clauses that apply to it based on the OpenMP spec.

Each lowering function (i.e. a function that generates MLIR ops)
is now responsible for generating its body as described below.

Functions that receive AST nodes extract the construct, and the
clauses from the node. They then create a work queue consisting
of individual constructs, and invoke a common dispatch function.

The dispatch function examines the current position in the queue,
and invokes the appropriate lowering function. Each lowering
function receives the queue as well, and once it needs to generate
its body, it either invokes the dispatch function on the rest of
the queue (if any), or processes nested evaluations if the work
queue is at the end.
---
 flang/lib/Lower/OpenMP/OpenMP.cpp | 784 +++---
 .../Frontend/OpenMP/ConstructDecompositionT.h | 985 ++
 2 files changed, 1376 insertions(+), 393 deletions(-)
 create mode 100644 llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h

diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 47935e6cf8efcf..4b8afd42f639d5 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -36,6 +36,7 @@
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/Transforms/RegionUtils.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Frontend/OpenMP/ConstructDecompositionT.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
 
 using namespace Fortran::lower::omp;
@@ -72,6 +73,89 @@ static void 
genNestedEvaluations(Fortran::lower::AbstractConverter &converter,
 converter.genEval(e);
 }
 
+//===--===//
+// Directive decomposition
+//===--===//
+
+namespace {
+using DirectiveWithClauses = tomp::DirectiveWithClauses;
+using ConstructQueue = List;
+} // namespace
+
+static void genOMPDispatch(Fortran::lower::AbstractConverter &converter,
+   Fortran::lower::SymMap &symTable,
+   Fortran::semantics::SemanticsContext &semaCtx,
+   Fortran::lower::pft::Evaluation &eval,
+   mlir::Location loc, const ConstructQueue &queue,
+   ConstructQueue::iterator item);
+
+namespace {
+struct ConstructDecomposition {
+  ConstructDecomposition(mlir::ModuleOp modOp,
+ semantics::SemanticsContext &semaCtx,
+ lower::pft::Evaluation &ev,
+ llvm::omp::Directive construct,
+ const List &clauses)
+  : semaCtx(semaCtx), mod(modOp), eval(ev) {
+tomp::ConstructDecompositionT decompose(getOpenMPVersion(modOp), *this,
+construct, 
llvm::ArrayRef(clauses));
+output = std::move(decompose.output);
+  }
+
+  // Given an object, return its base object if one exists.
+  std::optional getBaseObject(const Object &object) {
+return lower::omp::getBaseObject(object, semaCtx);
+  }
+
+  // Return the iteration variable of the associated loop if any.
+  std::optional getLoopIterVar() {
+if (semantics::Symbol *symbol = getIterationVariableSymbol(eval))
+  return Object{symbol, /*designator=*/{}};
+return std::nullopt;
+  }
+
+  semantics::SemanticsContext &semaCtx;
+  mlir::ModuleOp mod;
+  lower::pft::Evaluation &eval;
+  List output;
+};
+} // namespace
+
+LLVM_DUMP_METHOD static llvm::raw_ostream &
+operator<<(llvm::raw_ostream &os, const DirectiveWithClauses &dwc) {
+  os << llvm::omp::getOpenMPDirectiveName(dwc.id);
+  for (auto [index, clause] : llvm::enumerate(dwc.clauses)) {
+os << (index == 0 ? '\t' : ' ');
+os << llvm::omp::getOpenMPClauseName(clause.id);
+  }
+  return os;
+}
+
+static void splitCompoundConstruct(
+mlir::ModuleOp modOp, Fortran::semantics::SemanticsContext &semaCtx,
+Fortran::lower::pft::Evaluation &eval, llvm::omp::Directive construct,
+const List &clauses, List &directives) {
+
+  ConstructDecomposition decompose(modOp, semaCtx, eval, construct, clauses);
+  assert(!decompose.output.empty());
+
+  llvm::SmallVector loweringUnits;
+  std::ignore =
+  llvm::omp::getLeafOrCompositeConstructs(construct, loweringUnits);
+
+  int leafIndex = 0;
+  for (llvm::omp::Directive dir_id : loweringUnits) {
+directives.push_back(DirectiveWithClauses{dir_id});
+DirectiveWithClauses &dwc = directives.back();
+llvm::ArrayRef leafsOrS

[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Decompose compound construccts, do recursive lowering (PR #90098)

2024-04-25 Thread Krzysztof Parzyszek via llvm-branch-commits

kparzysz wrote:

> Is it possible to add tests for this?
> 
> Can we move the decomposition logic into a separate file?

The parts between lines 76 and 158?  Sure. 

I have a couple more PRs to open, and I'll work on that next.

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


[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Decompose compound construccts, do recursive lowering (PR #90098)

2024-04-25 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/90098
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Decompose compound constructs, do recursive lowering (PR #90098)

2024-04-25 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/90098
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [flang][OpenMP] Don't pass clauses to op-generating functions anymore (PR #90108)

2024-04-25 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz created 
https://github.com/llvm/llvm-project/pull/90108

The clauses should now be accessed from the construct queue.

>From 9e1990638495ad205c4898f697ac6dcf2a59f9cb Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Thu, 25 Apr 2024 11:08:14 -0500
Subject: [PATCH] [flang][OpenMP] Don't pass clauses to op-generating functions
 anymore

The clauses should now be accessed from the construct queue.
---
 flang/lib/Lower/OpenMP/OpenMP.cpp | 242 +-
 1 file changed, 107 insertions(+), 135 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 7e0105e749c39e..5a4e113ffca46a 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1229,8 +1229,7 @@ genCriticalOp(Fortran::lower::AbstractConverter 
&converter,
   Fortran::lower::SymMap &symTable,
   Fortran::semantics::SemanticsContext &semaCtx,
   Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
-  const List &clauses, const ConstructQueue &queue,
-  ConstructQueue::iterator item,
+  const ConstructQueue &queue, ConstructQueue::iterator item,
   const std::optional &name) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
   mlir::FlatSymbolRefAttr nameAttr;
@@ -1241,8 +1240,8 @@ genCriticalOp(Fortran::lower::AbstractConverter 
&converter,
 auto global = mod.lookupSymbol(nameStr);
 if (!global) {
   mlir::omp::CriticalClauseOps clauseOps;
-  genCriticalDeclareClauses(converter, semaCtx, clauses, loc, clauseOps,
-nameStr);
+  genCriticalDeclareClauses(converter, semaCtx, item->clauses, loc,
+clauseOps, nameStr);
 
   mlir::OpBuilder modBuilder(mod.getBodyRegion());
   global = modBuilder.create(loc, clauseOps);
@@ -1262,8 +1261,7 @@ genDistributeOp(Fortran::lower::AbstractConverter 
&converter,
 Fortran::lower::SymMap &symTable,
 Fortran::semantics::SemanticsContext &semaCtx,
 Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
-const List &clauses, const ConstructQueue &queue,
-ConstructQueue::iterator item) {
+const ConstructQueue &queue, ConstructQueue::iterator item) {
   TODO(loc, "Distribute construct");
   return nullptr;
 }
@@ -1273,10 +1271,11 @@ genFlushOp(Fortran::lower::AbstractConverter &converter,
Fortran::lower::SymMap &symTable,
Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
-   const ObjectList &objects, const List &clauses,
-   const ConstructQueue &queue, ConstructQueue::iterator item) {
+   const ObjectList &objects, const ConstructQueue &queue,
+   ConstructQueue::iterator item) {
   llvm::SmallVector operandRange;
-  genFlushClauses(converter, semaCtx, objects, clauses, loc, operandRange);
+  genFlushClauses(converter, semaCtx, objects, item->clauses, loc,
+  operandRange);
 
   return converter.getFirOpBuilder().create(
   converter.getCurrentLocation(), operandRange);
@@ -1287,8 +1286,7 @@ genMasterOp(Fortran::lower::AbstractConverter &converter,
 Fortran::lower::SymMap &symTable,
 Fortran::semantics::SemanticsContext &semaCtx,
 Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
-const List &clauses, const ConstructQueue &queue,
-ConstructQueue::iterator item) {
+const ConstructQueue &queue, ConstructQueue::iterator item) {
   return genOpWithBody(
   OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval,
 llvm::omp::Directive::OMPD_master),
@@ -1300,8 +1298,7 @@ genOrderedOp(Fortran::lower::AbstractConverter &converter,
  Fortran::lower::SymMap &symTable,
  Fortran::semantics::SemanticsContext &semaCtx,
  Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
- const List &clauses, const ConstructQueue &queue,
- ConstructQueue::iterator item) {
+ const ConstructQueue &queue, ConstructQueue::iterator item) {
   TODO(loc, "OMPD_ordered");
   return nullptr;
 }
@@ -1311,10 +1308,9 @@ genOrderedRegionOp(Fortran::lower::AbstractConverter 
&converter,
Fortran::lower::SymMap &symTable,
Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
-   const List &clauses, const ConstructQueue &queue,
-   ConstructQueue::iterator item) {
+   const ConstructQueue &queue, ConstructQueue::iterator item) 
{
   mlir::omp::OrderedRegionClauseOps clauseOps;
-  genOrderedRegionClauses(converter, semaCtx, clauses, loc, clauseOps);
+  gen

[llvm-branch-commits] [flang] [flang][OpenMP] Don't pass clauses to op-generating functions anymore (PR #90108)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-fir-hlfir

Author: Krzysztof Parzyszek (kparzysz)


Changes

The clauses should now be accessed from the construct queue.

---

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


1 Files Affected:

- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+107-135) 


``diff
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 7e0105e749c39e..5a4e113ffca46a 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1229,8 +1229,7 @@ genCriticalOp(Fortran::lower::AbstractConverter 
&converter,
   Fortran::lower::SymMap &symTable,
   Fortran::semantics::SemanticsContext &semaCtx,
   Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
-  const List &clauses, const ConstructQueue &queue,
-  ConstructQueue::iterator item,
+  const ConstructQueue &queue, ConstructQueue::iterator item,
   const std::optional &name) {
   fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
   mlir::FlatSymbolRefAttr nameAttr;
@@ -1241,8 +1240,8 @@ genCriticalOp(Fortran::lower::AbstractConverter 
&converter,
 auto global = mod.lookupSymbol(nameStr);
 if (!global) {
   mlir::omp::CriticalClauseOps clauseOps;
-  genCriticalDeclareClauses(converter, semaCtx, clauses, loc, clauseOps,
-nameStr);
+  genCriticalDeclareClauses(converter, semaCtx, item->clauses, loc,
+clauseOps, nameStr);
 
   mlir::OpBuilder modBuilder(mod.getBodyRegion());
   global = modBuilder.create(loc, clauseOps);
@@ -1262,8 +1261,7 @@ genDistributeOp(Fortran::lower::AbstractConverter 
&converter,
 Fortran::lower::SymMap &symTable,
 Fortran::semantics::SemanticsContext &semaCtx,
 Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
-const List &clauses, const ConstructQueue &queue,
-ConstructQueue::iterator item) {
+const ConstructQueue &queue, ConstructQueue::iterator item) {
   TODO(loc, "Distribute construct");
   return nullptr;
 }
@@ -1273,10 +1271,11 @@ genFlushOp(Fortran::lower::AbstractConverter &converter,
Fortran::lower::SymMap &symTable,
Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
-   const ObjectList &objects, const List &clauses,
-   const ConstructQueue &queue, ConstructQueue::iterator item) {
+   const ObjectList &objects, const ConstructQueue &queue,
+   ConstructQueue::iterator item) {
   llvm::SmallVector operandRange;
-  genFlushClauses(converter, semaCtx, objects, clauses, loc, operandRange);
+  genFlushClauses(converter, semaCtx, objects, item->clauses, loc,
+  operandRange);
 
   return converter.getFirOpBuilder().create(
   converter.getCurrentLocation(), operandRange);
@@ -1287,8 +1286,7 @@ genMasterOp(Fortran::lower::AbstractConverter &converter,
 Fortran::lower::SymMap &symTable,
 Fortran::semantics::SemanticsContext &semaCtx,
 Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
-const List &clauses, const ConstructQueue &queue,
-ConstructQueue::iterator item) {
+const ConstructQueue &queue, ConstructQueue::iterator item) {
   return genOpWithBody(
   OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval,
 llvm::omp::Directive::OMPD_master),
@@ -1300,8 +1298,7 @@ genOrderedOp(Fortran::lower::AbstractConverter &converter,
  Fortran::lower::SymMap &symTable,
  Fortran::semantics::SemanticsContext &semaCtx,
  Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
- const List &clauses, const ConstructQueue &queue,
- ConstructQueue::iterator item) {
+ const ConstructQueue &queue, ConstructQueue::iterator item) {
   TODO(loc, "OMPD_ordered");
   return nullptr;
 }
@@ -1311,10 +1308,9 @@ genOrderedRegionOp(Fortran::lower::AbstractConverter 
&converter,
Fortran::lower::SymMap &symTable,
Fortran::semantics::SemanticsContext &semaCtx,
Fortran::lower::pft::Evaluation &eval, mlir::Location loc,
-   const List &clauses, const ConstructQueue &queue,
-   ConstructQueue::iterator item) {
+   const ConstructQueue &queue, ConstructQueue::iterator item) 
{
   mlir::omp::OrderedRegionClauseOps clauseOps;
-  genOrderedRegionClauses(converter, semaCtx, clauses, loc, clauseOps);
+  genOrderedRegionClauses(converter, semaCtx, item->clauses, loc, clauseOps);
 
   return genOpWithBody(
   OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval,
@@ -1327,1

[llvm-branch-commits] [clang] release/18.x: [clang-format] Fix a regression in annotating TrailingReturnArrow (#86624) (PR #89415)

2024-04-25 Thread Björn Schäpers via llvm-branch-commits

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


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


[llvm-branch-commits] [clang] release/18.x: [clang-format] Fix a regression in ContinuationIndenter (#88414) (PR #89412)

2024-04-25 Thread Björn Schäpers via llvm-branch-commits

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


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


[llvm-branch-commits] [clang] release/18.x: [Clang] Handle structs with inner structs and no fields (#89126) (PR #89456)

2024-04-25 Thread Bill Wendling via llvm-branch-commits

bwendling wrote:

@tstellar The output is definitely different. It needs 
90ba33099cbb17e7c159e9ebc5a512037db99d6d, which looks to be only in `main`. I 
can generate a patch, since porting that change will probably be onerous. How 
do I do that for the 18.X branch?

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


[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Decompose compound constructs, do recursive lowering (PR #90098)

2024-04-25 Thread Krzysztof Parzyszek via llvm-branch-commits

kparzysz wrote:

Tests are still coming...

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


[llvm-branch-commits] [flang] [flang][OpenMP] Don't pass clauses to op-generating functions anymore (PR #90108)

2024-04-25 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/90108
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/18.x: [Clang] Handle structs with inner structs and no fields (#89126) (PR #89456)

2024-04-25 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

You can just make all the changes locally and then create a pull request for 
the release/18.x branch.

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


[llvm-branch-commits] [clang] [Clang] Handle structs with inner structs and no fields (#89126) (PR #90133)

2024-04-25 Thread Bill Wendling via llvm-branch-commits

https://github.com/bwendling created 
https://github.com/llvm/llvm-project/pull/90133

A struct that declares an inner struct, but no fields, won't have a field 
count. So getting the offset of the inner struct fails. This happens in both C 
and C++:

  struct foo {
struct bar {
  int Quantizermatrix[];
};
  };

Here 'struct foo' has no fields.

Closes: https://github.com/llvm/llvm-project/issues/88931

>From 504a17cc62a5c333f6228de0a70f04420da3efcc Mon Sep 17 00:00:00 2001
From: Bill Wendling <5993918+bwendl...@users.noreply.github.com>
Date: Fri, 19 Apr 2024 12:48:33 -0700
Subject: [PATCH] [Clang] Handle structs with inner structs and no fields
 (#89126)

A struct that declares an inner struct, but no fields, won't have a
field count. So getting the offset of the inner struct fails. This
happens in both C and C++:

  struct foo {
struct bar {
  int Quantizermatrix[];
};
  };

Here 'struct foo' has no fields.

Closes: https://github.com/llvm/llvm-project/issues/88931
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 25 +++-
 clang/test/CodeGen/attr-counted-by-pr88931.c  | 40 +++
 .../test/CodeGen/attr-counted-by-pr88931.cpp  | 21 ++
 3 files changed, 75 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-counted-by-pr88931.c
 create mode 100644 clang/test/CodeGen/attr-counted-by-pr88931.cpp

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a4f26a6f0eb19b..44ddd2428b10f5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -823,29 +823,32 @@ const FieldDecl 
*CodeGenFunction::FindFlexibleArrayMemberField(
 ASTContext &Ctx, const RecordDecl *RD, StringRef Name, uint64_t &Offset) {
   const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
   getLangOpts().getStrictFlexArraysLevel();
-  unsigned FieldNo = 0;
-  bool IsUnion = RD->isUnion();
+  uint32_t FieldNo = 0;
 
-  for (const Decl *D : RD->decls()) {
-if (const auto *Field = dyn_cast(D);
-Field && (Name.empty() || Field->getNameAsString() == Name) &&
+  if (RD->isImplicit())
+return nullptr;
+
+  for (const FieldDecl *FD : RD->fields()) {
+if ((Name.empty() || FD->getNameAsString() == Name) &&
 Decl::isFlexibleArrayMemberLike(
-Ctx, Field, Field->getType(), StrictFlexArraysLevel,
+Ctx, FD, FD->getType(), StrictFlexArraysLevel,
 /*IgnoreTemplateOrMacroSubstitution=*/true)) {
   const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
   Offset += Layout.getFieldOffset(FieldNo);
-  return Field;
+  return FD;
 }
 
-if (const auto *Record = dyn_cast(D))
-  if (const FieldDecl *Field =
-  FindFlexibleArrayMemberField(Ctx, Record, Name, Offset)) {
+QualType Ty = FD->getType();
+if (Ty->isRecordType()) {
+  if (const FieldDecl *Field = FindFlexibleArrayMemberField(
+  Ctx, Ty->getAsRecordDecl(), Name, Offset)) {
 const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
 Offset += Layout.getFieldOffset(FieldNo);
 return Field;
   }
+}
 
-if (!IsUnion && isa(D))
+if (!RD->isUnion())
   ++FieldNo;
   }
 
diff --git a/clang/test/CodeGen/attr-counted-by-pr88931.c 
b/clang/test/CodeGen/attr-counted-by-pr88931.c
new file mode 100644
index 00..520ebd09973284
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-pr88931.c
@@ -0,0 +1,40 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 
-Wno-missing-declarations -emit-llvm -o - %s | FileCheck %s
+
+struct foo {
+  int x,y,z;
+  struct bar {
+int count;
+int array[] __attribute__((counted_by(count)));
+  };
+};
+
+void init(void * __attribute__((pass_dynamic_object_size(0;
+
+// CHECK-LABEL: define dso_local void @test1(
+// CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ARRAY:%.*]] = getelementptr inbounds [[STRUCT_BAR:%.*]], 
ptr [[P]], i64 0, i32 1
+// CHECK-NEXT:tail call void @init(ptr noundef nonnull [[ARRAY]], i64 
noundef -1) #[[ATTR2:[0-9]+]]
+// CHECK-NEXT:ret void
+//
+void test1(struct bar *p) {
+  init(p->array);
+}
+
+struct mux {
+  int count;
+  int array[] __attribute__((counted_by(count)));
+};
+
+struct bux { struct mux x; };
+
+// CHECK-LABEL: define dso_local void @test2(
+// CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @init(ptr noundef [[P]], i64 noundef -1) 
#[[ATTR2]]
+// CHECK-NEXT:ret void
+//
+void test2(struct bux *p) {
+  init(p);
+}
diff --git a/clang/test/CodeGen/attr-counted-by-pr88931.cpp 
b/clang/test/CodeGen/attr-counted-by-pr88931.cpp
new file mode 100644
index 00..2a8cc1d07e50d9
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-b

[llvm-branch-commits] [clang] [Clang] Handle structs with inner structs and no fields (#89126) (PR #90133)

2024-04-25 Thread Bill Wendling via llvm-branch-commits

https://github.com/bwendling milestoned 
https://github.com/llvm/llvm-project/pull/90133
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Clang] Handle structs with inner structs and no fields (#89126) (PR #90133)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Bill Wendling (bwendling)


Changes

A struct that declares an inner struct, but no fields, won't have a field 
count. So getting the offset of the inner struct fails. This happens in both C 
and C++:

  struct foo {
struct bar {
  int Quantizermatrix[];
};
  };

Here 'struct foo' has no fields.

Closes: https://github.com/llvm/llvm-project/issues/88931

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+14-11) 
- (added) clang/test/CodeGen/attr-counted-by-pr88931.c (+40) 
- (added) clang/test/CodeGen/attr-counted-by-pr88931.cpp (+21) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a4f26a6f0eb19b..44ddd2428b10f5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -823,29 +823,32 @@ const FieldDecl 
*CodeGenFunction::FindFlexibleArrayMemberField(
 ASTContext &Ctx, const RecordDecl *RD, StringRef Name, uint64_t &Offset) {
   const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
   getLangOpts().getStrictFlexArraysLevel();
-  unsigned FieldNo = 0;
-  bool IsUnion = RD->isUnion();
+  uint32_t FieldNo = 0;
 
-  for (const Decl *D : RD->decls()) {
-if (const auto *Field = dyn_cast(D);
-Field && (Name.empty() || Field->getNameAsString() == Name) &&
+  if (RD->isImplicit())
+return nullptr;
+
+  for (const FieldDecl *FD : RD->fields()) {
+if ((Name.empty() || FD->getNameAsString() == Name) &&
 Decl::isFlexibleArrayMemberLike(
-Ctx, Field, Field->getType(), StrictFlexArraysLevel,
+Ctx, FD, FD->getType(), StrictFlexArraysLevel,
 /*IgnoreTemplateOrMacroSubstitution=*/true)) {
   const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
   Offset += Layout.getFieldOffset(FieldNo);
-  return Field;
+  return FD;
 }
 
-if (const auto *Record = dyn_cast(D))
-  if (const FieldDecl *Field =
-  FindFlexibleArrayMemberField(Ctx, Record, Name, Offset)) {
+QualType Ty = FD->getType();
+if (Ty->isRecordType()) {
+  if (const FieldDecl *Field = FindFlexibleArrayMemberField(
+  Ctx, Ty->getAsRecordDecl(), Name, Offset)) {
 const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
 Offset += Layout.getFieldOffset(FieldNo);
 return Field;
   }
+}
 
-if (!IsUnion && isa(D))
+if (!RD->isUnion())
   ++FieldNo;
   }
 
diff --git a/clang/test/CodeGen/attr-counted-by-pr88931.c 
b/clang/test/CodeGen/attr-counted-by-pr88931.c
new file mode 100644
index 00..520ebd09973284
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-pr88931.c
@@ -0,0 +1,40 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 
-Wno-missing-declarations -emit-llvm -o - %s | FileCheck %s
+
+struct foo {
+  int x,y,z;
+  struct bar {
+int count;
+int array[] __attribute__((counted_by(count)));
+  };
+};
+
+void init(void * __attribute__((pass_dynamic_object_size(0;
+
+// CHECK-LABEL: define dso_local void @test1(
+// CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ARRAY:%.*]] = getelementptr inbounds [[STRUCT_BAR:%.*]], 
ptr [[P]], i64 0, i32 1
+// CHECK-NEXT:tail call void @init(ptr noundef nonnull [[ARRAY]], i64 
noundef -1) #[[ATTR2:[0-9]+]]
+// CHECK-NEXT:ret void
+//
+void test1(struct bar *p) {
+  init(p->array);
+}
+
+struct mux {
+  int count;
+  int array[] __attribute__((counted_by(count)));
+};
+
+struct bux { struct mux x; };
+
+// CHECK-LABEL: define dso_local void @test2(
+// CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @init(ptr noundef [[P]], i64 noundef -1) 
#[[ATTR2]]
+// CHECK-NEXT:ret void
+//
+void test2(struct bux *p) {
+  init(p);
+}
diff --git a/clang/test/CodeGen/attr-counted-by-pr88931.cpp 
b/clang/test/CodeGen/attr-counted-by-pr88931.cpp
new file mode 100644
index 00..2a8cc1d07e50d9
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-pr88931.cpp
@@ -0,0 +1,21 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -Wall -emit-llvm -o - 
%s | FileCheck %s
+
+struct foo {
+  struct bar {
+int array[];
+bar();
+  };
+};
+
+void init(void * __attribute__((pass_dynamic_object_size(0;
+
+// CHECK-LABEL: define dso_local void @_ZN3foo3barC1Ev(
+// CHECK-SAME: ptr noundef nonnull align 4 dereferenceable(1) [[THIS:%.*]]) 
unnamed_addr #[[ATTR0:[0-9]+]] align 2 {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @_Z4initPvU25pass_dynamic_object_size0(ptr 
noundef nonnull [[THIS]], i64 nound

[llvm-branch-commits] [clang] [Clang] Handle structs with inner structs and no fields (#89126) (PR #90133)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Bill Wendling (bwendling)


Changes

A struct that declares an inner struct, but no fields, won't have a field 
count. So getting the offset of the inner struct fails. This happens in both C 
and C++:

  struct foo {
struct bar {
  int Quantizermatrix[];
};
  };

Here 'struct foo' has no fields.

Closes: https://github.com/llvm/llvm-project/issues/88931

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+14-11) 
- (added) clang/test/CodeGen/attr-counted-by-pr88931.c (+40) 
- (added) clang/test/CodeGen/attr-counted-by-pr88931.cpp (+21) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a4f26a6f0eb19b..44ddd2428b10f5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -823,29 +823,32 @@ const FieldDecl 
*CodeGenFunction::FindFlexibleArrayMemberField(
 ASTContext &Ctx, const RecordDecl *RD, StringRef Name, uint64_t &Offset) {
   const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
   getLangOpts().getStrictFlexArraysLevel();
-  unsigned FieldNo = 0;
-  bool IsUnion = RD->isUnion();
+  uint32_t FieldNo = 0;
 
-  for (const Decl *D : RD->decls()) {
-if (const auto *Field = dyn_cast(D);
-Field && (Name.empty() || Field->getNameAsString() == Name) &&
+  if (RD->isImplicit())
+return nullptr;
+
+  for (const FieldDecl *FD : RD->fields()) {
+if ((Name.empty() || FD->getNameAsString() == Name) &&
 Decl::isFlexibleArrayMemberLike(
-Ctx, Field, Field->getType(), StrictFlexArraysLevel,
+Ctx, FD, FD->getType(), StrictFlexArraysLevel,
 /*IgnoreTemplateOrMacroSubstitution=*/true)) {
   const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
   Offset += Layout.getFieldOffset(FieldNo);
-  return Field;
+  return FD;
 }
 
-if (const auto *Record = dyn_cast(D))
-  if (const FieldDecl *Field =
-  FindFlexibleArrayMemberField(Ctx, Record, Name, Offset)) {
+QualType Ty = FD->getType();
+if (Ty->isRecordType()) {
+  if (const FieldDecl *Field = FindFlexibleArrayMemberField(
+  Ctx, Ty->getAsRecordDecl(), Name, Offset)) {
 const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
 Offset += Layout.getFieldOffset(FieldNo);
 return Field;
   }
+}
 
-if (!IsUnion && isa(D))
+if (!RD->isUnion())
   ++FieldNo;
   }
 
diff --git a/clang/test/CodeGen/attr-counted-by-pr88931.c 
b/clang/test/CodeGen/attr-counted-by-pr88931.c
new file mode 100644
index 00..520ebd09973284
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-pr88931.c
@@ -0,0 +1,40 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 
-Wno-missing-declarations -emit-llvm -o - %s | FileCheck %s
+
+struct foo {
+  int x,y,z;
+  struct bar {
+int count;
+int array[] __attribute__((counted_by(count)));
+  };
+};
+
+void init(void * __attribute__((pass_dynamic_object_size(0;
+
+// CHECK-LABEL: define dso_local void @test1(
+// CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ARRAY:%.*]] = getelementptr inbounds [[STRUCT_BAR:%.*]], 
ptr [[P]], i64 0, i32 1
+// CHECK-NEXT:tail call void @init(ptr noundef nonnull [[ARRAY]], i64 
noundef -1) #[[ATTR2:[0-9]+]]
+// CHECK-NEXT:ret void
+//
+void test1(struct bar *p) {
+  init(p->array);
+}
+
+struct mux {
+  int count;
+  int array[] __attribute__((counted_by(count)));
+};
+
+struct bux { struct mux x; };
+
+// CHECK-LABEL: define dso_local void @test2(
+// CHECK-SAME: ptr noundef [[P:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @init(ptr noundef [[P]], i64 noundef -1) 
#[[ATTR2]]
+// CHECK-NEXT:ret void
+//
+void test2(struct bux *p) {
+  init(p);
+}
diff --git a/clang/test/CodeGen/attr-counted-by-pr88931.cpp 
b/clang/test/CodeGen/attr-counted-by-pr88931.cpp
new file mode 100644
index 00..2a8cc1d07e50d9
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-pr88931.cpp
@@ -0,0 +1,21 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -Wall -emit-llvm -o - 
%s | FileCheck %s
+
+struct foo {
+  struct bar {
+int array[];
+bar();
+  };
+};
+
+void init(void * __attribute__((pass_dynamic_object_size(0;
+
+// CHECK-LABEL: define dso_local void @_ZN3foo3barC1Ev(
+// CHECK-SAME: ptr noundef nonnull align 4 dereferenceable(1) [[THIS:%.*]]) 
unnamed_addr #[[ATTR0:[0-9]+]] align 2 {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @_Z4initPvU25pass_dynamic_object_size0(ptr 
noundef nonnull [[THIS]], i

[llvm-branch-commits] [clang] [Clang] Handle structs with inner structs and no fields (#89126) (PR #90133)

2024-04-25 Thread Bill Wendling via llvm-branch-commits

bwendling wrote:

Okay...I think this works now?

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


[llvm-branch-commits] [llvm][NFC] Document cl::opt variable and fix typo (PR #90145)

2024-04-25 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi created 
https://github.com/llvm/llvm-project/pull/90145

None


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


[llvm-branch-commits] [llvm][NFC] Document cl::opt variable and fix typo (PR #90145)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Paul Kirth (ilovepi)


Changes



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


1 Files Affected:

- (modified) llvm/lib/Transforms/Utils/MisExpect.cpp (+2-1) 


``diff
diff --git a/llvm/lib/Transforms/Utils/MisExpect.cpp 
b/llvm/lib/Transforms/Utils/MisExpect.cpp
index 6f5a25a26821b6..759289384ee06d 100644
--- a/llvm/lib/Transforms/Utils/MisExpect.cpp
+++ b/llvm/lib/Transforms/Utils/MisExpect.cpp
@@ -59,9 +59,10 @@ static cl::opt PGOWarnMisExpect(
 cl::desc("Use this option to turn on/off "
  "warnings about incorrect usage of llvm.expect intrinsics."));
 
+// Command line option for setting the diagnostic tolerance threshold
 static cl::opt MisExpectTolerance(
 "misexpect-tolerance", cl::init(0),
-cl::desc("Prevents emiting diagnostics when profile counts are "
+cl::desc("Prevents emitting diagnostics when profile counts are "
  "within N% of the threshold.."));
 
 } // namespace llvm

``




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


[llvm-branch-commits] [llvm][IR] Extend BranchWeightMetadata to track provenance of weights (PR #86609)

2024-04-25 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/86609


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


[llvm-branch-commits] [llvm][IR] Extend BranchWeightMetadata to track provenance of weights (PR #86609)

2024-04-25 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/86609


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


[llvm-branch-commits] [llvm][misexpect] Update MisExpect to use provenance tracking metadata (PR #86610)

2024-04-25 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/86610


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


[llvm-branch-commits] [llvm][misexpect] Update MisExpect to use provenance tracking metadata (PR #86610)

2024-04-25 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/86610


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


[llvm-branch-commits] [llvm][ProfDataUtils] provide getNumBranchWeights API (PR #90146)

2024-04-25 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi created 
https://github.com/llvm/llvm-project/pull/90146

As suggested in 
https://github.com/llvm/llvm-project/pull/86609/files#r1556689262
an API for getting the number of branch weights directly from the MD node would
be useful in a variety of checks, and keeps the logic within ProfDataUtils.



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


[llvm-branch-commits] [llvm][ProfDataUtils] provide getNumBranchWeights API (PR #90146)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Paul Kirth (ilovepi)


Changes

As suggested in 
https://github.com/llvm/llvm-project/pull/86609/files#r1556689262
an API for getting the number of branch weights directly from the MD node would
be useful in a variety of checks, and keeps the logic within ProfDataUtils.


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


4 Files Affected:

- (modified) llvm/include/llvm/IR/ProfDataUtils.h (+2) 
- (modified) llvm/lib/IR/Instructions.cpp (+1-5) 
- (modified) llvm/lib/IR/ProfDataUtils.cpp (+5-3) 
- (modified) llvm/lib/IR/Verifier.cpp (+5-5) 


``diff
diff --git a/llvm/include/llvm/IR/ProfDataUtils.h 
b/llvm/include/llvm/IR/ProfDataUtils.h
index 3c761bdc1bf3e9..7008d3240feded 100644
--- a/llvm/include/llvm/IR/ProfDataUtils.h
+++ b/llvm/include/llvm/IR/ProfDataUtils.h
@@ -66,6 +66,8 @@ bool hasBranchWeightProvenance(const MDNode *ProfileData);
 /// Return the offset to the first branch weight data
 unsigned getBranchWeightOffset(const MDNode *ProfileData);
 
+unsigned getNumBranchWeights(const MDNode &ProfileData);
+
 /// Extract branch weights from MD_prof metadata
 ///
 /// \param ProfileData A pointer to an MDNode.
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 650d32ac17fc2b..a14d6758cad1d8 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -5165,11 +5165,7 @@ void SwitchInstProfUpdateWrapper::init() {
   if (!ProfileData)
 return;
 
-  // FIXME: This check belongs in ProfDataUtils. Its almost equivalent to
-  // getValidBranchWeightMDNode(), but the need to use llvm_unreachable
-  // makes them slightly different.
-  if (ProfileData->getNumOperands() !=
-  SI.getNumSuccessors() + getBranchWeightOffset(ProfileData)) {
+  if (getNumBranchWeights(*ProfileData) != SI.getNumSuccessors()) {
 llvm_unreachable("number of prof branch_weights metadata operands does "
  "not correspond to number of succesors");
   }
diff --git a/llvm/lib/IR/ProfDataUtils.cpp b/llvm/lib/IR/ProfDataUtils.cpp
index cd219c22e3dfe6..9544ea85b93d96 100644
--- a/llvm/lib/IR/ProfDataUtils.cpp
+++ b/llvm/lib/IR/ProfDataUtils.cpp
@@ -123,6 +123,10 @@ unsigned getBranchWeightOffset(const MDNode *ProfileData) {
   return hasBranchWeightProvenance(ProfileData) ? 2 : 1;
 }
 
+unsigned getNumBranchWeights(const MDNode &ProfileData) {
+  return ProfileData.getNumOperands() - getBranchWeightOffset(&ProfileData);
+}
+
 MDNode *getBranchWeightMDNode(const Instruction &I) {
   auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
   if (!isBranchWeightMD(ProfileData))
@@ -132,9 +136,7 @@ MDNode *getBranchWeightMDNode(const Instruction &I) {
 
 MDNode *getValidBranchWeightMDNode(const Instruction &I) {
   auto *ProfileData = getBranchWeightMDNode(I);
-  auto Offset = getBranchWeightOffset(ProfileData);
-  if (ProfileData &&
-  ProfileData->getNumOperands() == Offset + I.getNumSuccessors())
+  if (ProfileData && getNumBranchWeights(*ProfileData) == I.getNumSuccessors())
 return ProfileData;
   return nullptr;
 }
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 4a142be71eec41..ecccb1790ff8ff 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -4787,10 +4787,9 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode 
*MD) {
 
   // Check consistency of !prof branch_weights metadata.
   if (ProfName.equals("branch_weights")) {
-unsigned int Offset = getBranchWeightOffset(I);
+unsigned NumBranchWeights = getNumBranchWeights(*MD);
 if (isa(&I)) {
-  Check(MD->getNumOperands() == (1 + Offset) ||
-MD->getNumOperands() == (2 + Offset),
+  Check(NumBranchWeights == 1 || NumBranchWeights == 2,
 "Wrong number of InvokeInst branch_weights operands", MD);
 } else {
   unsigned ExpectedNumOperands = 0;
@@ -4810,10 +4809,11 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode 
*MD) {
 CheckFailed("!prof branch_weights are not allowed for this 
instruction",
 MD);
 
-  Check(MD->getNumOperands() == Offset + ExpectedNumOperands,
+  Check(NumBranchWeights == ExpectedNumOperands,
 "Wrong number of operands", MD);
 }
-for (unsigned i = Offset; i < MD->getNumOperands(); ++i) {
+for (unsigned i = getBranchWeightOffset(MD); i < MD->getNumOperands();
+ ++i) {
   auto &MDO = MD->getOperand(i);
   Check(MDO, "second operand should not be null", MD);
   Check(mdconst::dyn_extract(MDO),

``




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


[llvm-branch-commits] [llvm][NFC] Document cl::opt variable and fix typo (PR #90145)

2024-04-25 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi edited 
https://github.com/llvm/llvm-project/pull/90145
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Clang] Handle structs with inner structs and no fields (#89126) (PR #90133)

2024-04-25 Thread Eli Friedman via llvm-branch-commits

efriedma-quic wrote:

Looks fine.

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


[llvm-branch-commits] [lld] [llvm] [llvm][lld][RISCV] Support x3_reg_usage (PR #84598)

2024-04-25 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/84598

>From 7c9298eea6d8239f9afedc3d6aabb1ec0f71e273 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 11 Mar 2024 15:35:59 -0700
Subject: [PATCH 1/3] Update callsite parameter

Created using spr 1.3.4
---
 lld/ELF/Arch/RISCV.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index b2e0ba17e4efe5..5eb2ce3d64513a 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1228,8 +1228,8 @@ mergeAttributesSection(const SmallVector §ions) {
   if (r.second) {
 firstX3RegUse = sec;
   } else {
-mergeX3RegUse(merged.intAttr, firstX3RegUse, sec,
-  r.first->getSecond(), *i);
+mergeX3RegUse(r.first, firstX3RegUse, sec, r.first->getSecond(),
+  *i);
   }
 }
 continue;

>From c39aca073491f06127eadd8c69cc15e23ea4bc2d Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 22 Mar 2024 12:44:27 -0700
Subject: [PATCH 2/3] Fix typos

Created using spr 1.3.4
---
 lld/ELF/Arch/RISCV.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 09db69286c5e9a..173afce454f382 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1139,8 +1139,8 @@ static void mergeX3RegUse(DenseMap::iterator it,
   const InputSectionBase *oldSection,
   const InputSectionBase *newSection,
   unsigned int oldTag, unsigned int newTag) {
-  // X3/GP register usage ar incompatible and cannot be merged, with the
-  // exception of the UNKNOWN or 0 value
+  // X3/GP register usage are incompatible and cannot be merged, with the
+  // exception of the UNKNOWN or 0 value.
   using RISCVAttrs::RISCVX3RegUse::X3RegUsage;
   if (newTag == X3RegUsage::UNKNOWN)
 return;

>From 86bb4a866953c886e586f61da0ec74c9e1129cfa Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 29 Mar 2024 16:15:38 -0700
Subject: [PATCH 3/3] Fix windows test failure

Created using spr 1.3.4
---
 llvm/test/CodeGen/RISCV/attributes.ll | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index eecab162eb31c8..9bd730003f0e72 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -519,7 +519,6 @@
 ; X3SCS: .attribute 16, 2
 ; X3TMP: .attribute 16, 3
 ; X3ERR: LLVM ERROR: Cannot set multiple ABIs for X3/GP
-; X3ERR: error: Aborted
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1

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


[llvm-branch-commits] [lld] [llvm] [llvm][lld][RISCV] Support x3_reg_usage (PR #84598)

2024-04-25 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/84598

>From 7c9298eea6d8239f9afedc3d6aabb1ec0f71e273 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 11 Mar 2024 15:35:59 -0700
Subject: [PATCH 1/3] Update callsite parameter

Created using spr 1.3.4
---
 lld/ELF/Arch/RISCV.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index b2e0ba17e4efe5..5eb2ce3d64513a 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1228,8 +1228,8 @@ mergeAttributesSection(const SmallVector §ions) {
   if (r.second) {
 firstX3RegUse = sec;
   } else {
-mergeX3RegUse(merged.intAttr, firstX3RegUse, sec,
-  r.first->getSecond(), *i);
+mergeX3RegUse(r.first, firstX3RegUse, sec, r.first->getSecond(),
+  *i);
   }
 }
 continue;

>From c39aca073491f06127eadd8c69cc15e23ea4bc2d Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 22 Mar 2024 12:44:27 -0700
Subject: [PATCH 2/3] Fix typos

Created using spr 1.3.4
---
 lld/ELF/Arch/RISCV.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 09db69286c5e9a..173afce454f382 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1139,8 +1139,8 @@ static void mergeX3RegUse(DenseMap::iterator it,
   const InputSectionBase *oldSection,
   const InputSectionBase *newSection,
   unsigned int oldTag, unsigned int newTag) {
-  // X3/GP register usage ar incompatible and cannot be merged, with the
-  // exception of the UNKNOWN or 0 value
+  // X3/GP register usage are incompatible and cannot be merged, with the
+  // exception of the UNKNOWN or 0 value.
   using RISCVAttrs::RISCVX3RegUse::X3RegUsage;
   if (newTag == X3RegUsage::UNKNOWN)
 return;

>From 86bb4a866953c886e586f61da0ec74c9e1129cfa Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 29 Mar 2024 16:15:38 -0700
Subject: [PATCH 3/3] Fix windows test failure

Created using spr 1.3.4
---
 llvm/test/CodeGen/RISCV/attributes.ll | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index eecab162eb31c8..9bd730003f0e72 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -519,7 +519,6 @@
 ; X3SCS: .attribute 16, 2
 ; X3TMP: .attribute 16, 3
 ; X3ERR: LLVM ERROR: Cannot set multiple ABIs for X3/GP
-; X3ERR: error: Aborted
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1

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


[llvm-branch-commits] [lld] [llvm] [llvm][lld][RISCV] Support x3_reg_usage (PR #84598)

2024-04-25 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/84598

>From 7c9298eea6d8239f9afedc3d6aabb1ec0f71e273 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 11 Mar 2024 15:35:59 -0700
Subject: [PATCH 1/3] Update callsite parameter

Created using spr 1.3.4
---
 lld/ELF/Arch/RISCV.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index b2e0ba17e4efe5..5eb2ce3d64513a 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1228,8 +1228,8 @@ mergeAttributesSection(const SmallVector §ions) {
   if (r.second) {
 firstX3RegUse = sec;
   } else {
-mergeX3RegUse(merged.intAttr, firstX3RegUse, sec,
-  r.first->getSecond(), *i);
+mergeX3RegUse(r.first, firstX3RegUse, sec, r.first->getSecond(),
+  *i);
   }
 }
 continue;

>From c39aca073491f06127eadd8c69cc15e23ea4bc2d Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 22 Mar 2024 12:44:27 -0700
Subject: [PATCH 2/3] Fix typos

Created using spr 1.3.4
---
 lld/ELF/Arch/RISCV.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 09db69286c5e9a..173afce454f382 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1139,8 +1139,8 @@ static void mergeX3RegUse(DenseMap::iterator it,
   const InputSectionBase *oldSection,
   const InputSectionBase *newSection,
   unsigned int oldTag, unsigned int newTag) {
-  // X3/GP register usage ar incompatible and cannot be merged, with the
-  // exception of the UNKNOWN or 0 value
+  // X3/GP register usage are incompatible and cannot be merged, with the
+  // exception of the UNKNOWN or 0 value.
   using RISCVAttrs::RISCVX3RegUse::X3RegUsage;
   if (newTag == X3RegUsage::UNKNOWN)
 return;

>From 86bb4a866953c886e586f61da0ec74c9e1129cfa Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 29 Mar 2024 16:15:38 -0700
Subject: [PATCH 3/3] Fix windows test failure

Created using spr 1.3.4
---
 llvm/test/CodeGen/RISCV/attributes.ll | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index eecab162eb31c8..9bd730003f0e72 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -519,7 +519,6 @@
 ; X3SCS: .attribute 16, 2
 ; X3TMP: .attribute 16, 3
 ; X3ERR: LLVM ERROR: Cannot set multiple ABIs for X3/GP
-; X3ERR: error: Aborted
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1

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


[llvm-branch-commits] [lld] [llvm] [llvm][lld][RISCV] Support x3_reg_usage (PR #84598)

2024-04-25 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/84598

>From 7c9298eea6d8239f9afedc3d6aabb1ec0f71e273 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 11 Mar 2024 15:35:59 -0700
Subject: [PATCH 1/3] Update callsite parameter

Created using spr 1.3.4
---
 lld/ELF/Arch/RISCV.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index b2e0ba17e4efe5..5eb2ce3d64513a 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1228,8 +1228,8 @@ mergeAttributesSection(const SmallVector §ions) {
   if (r.second) {
 firstX3RegUse = sec;
   } else {
-mergeX3RegUse(merged.intAttr, firstX3RegUse, sec,
-  r.first->getSecond(), *i);
+mergeX3RegUse(r.first, firstX3RegUse, sec, r.first->getSecond(),
+  *i);
   }
 }
 continue;

>From c39aca073491f06127eadd8c69cc15e23ea4bc2d Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 22 Mar 2024 12:44:27 -0700
Subject: [PATCH 2/3] Fix typos

Created using spr 1.3.4
---
 lld/ELF/Arch/RISCV.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 09db69286c5e9a..173afce454f382 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -1139,8 +1139,8 @@ static void mergeX3RegUse(DenseMap::iterator it,
   const InputSectionBase *oldSection,
   const InputSectionBase *newSection,
   unsigned int oldTag, unsigned int newTag) {
-  // X3/GP register usage ar incompatible and cannot be merged, with the
-  // exception of the UNKNOWN or 0 value
+  // X3/GP register usage are incompatible and cannot be merged, with the
+  // exception of the UNKNOWN or 0 value.
   using RISCVAttrs::RISCVX3RegUse::X3RegUsage;
   if (newTag == X3RegUsage::UNKNOWN)
 return;

>From 86bb4a866953c886e586f61da0ec74c9e1129cfa Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 29 Mar 2024 16:15:38 -0700
Subject: [PATCH 3/3] Fix windows test failure

Created using spr 1.3.4
---
 llvm/test/CodeGen/RISCV/attributes.ll | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index eecab162eb31c8..9bd730003f0e72 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -519,7 +519,6 @@
 ; X3SCS: .attribute 16, 2
 ; X3TMP: .attribute 16, 3
 ; X3ERR: LLVM ERROR: Cannot set multiple ABIs for X3/GP
-; X3ERR: error: Aborted
 
 define i32 @addi(i32 %a) {
   %1 = add i32 %a, 1

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


[llvm-branch-commits] [llvm][ProfDataUtils] provide getNumBranchWeights API (PR #90146)

2024-04-25 Thread Matthias Braun via llvm-branch-commits

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

LGTM

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


[llvm-branch-commits] [LoongArch][Codegen] Add support for TLSDESC (PR #90157)

2024-04-25 Thread via llvm-branch-commits

https://github.com/wangleiat created 
https://github.com/llvm/llvm-project/pull/90157

The implementation only enables when the `-enable-tlsdesc` option is
passed and the TLS model is `dynamic`.

LoongArch's GCC has the same option(-mtls-dialet=) as RISC-V.



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


[llvm-branch-commits] [LoongArch][Codegen] Add support for TLSDESC (PR #90157)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-backend-loongarch

@llvm/pr-subscribers-clang

Author: wanglei (wangleiat)


Changes

The implementation only enables when the `-enable-tlsdesc` option is
passed and the TLS model is `dynamic`.

LoongArch's GCC has the same option(-mtls-dialet=) as RISC-V.


---

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


10 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+1-1) 
- (added) clang/test/CodeGen/LoongArch/tls-dialect.c (+14) 
- (modified) llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp (+108) 
- (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp (+36-14) 
- (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.h (+2) 
- (modified) llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp (+6) 
- (modified) llvm/lib/Target/LoongArch/LoongArchInstrInfo.td (+7) 
- (modified) llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp (+18) 
- (modified) llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.h (+7-1) 
- (modified) llvm/test/CodeGen/LoongArch/tls-models.ll (+139) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index b65b96db16bd79..a5000221f61903 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -737,7 +737,7 @@ bool tools::isTLSDESCEnabled(const ToolChain &TC,
   StringRef V = A->getValue();
   bool SupportedArgument = false, EnableTLSDESC = false;
   bool Unsupported = !Triple.isOSBinFormatELF();
-  if (Triple.isRISCV()) {
+  if (Triple.isRISCV() || Triple.isLoongArch()) {
 SupportedArgument = V == "desc" || V == "trad";
 EnableTLSDESC = V == "desc";
   } else if (Triple.isX86()) {
diff --git a/clang/test/CodeGen/LoongArch/tls-dialect.c 
b/clang/test/CodeGen/LoongArch/tls-dialect.c
new file mode 100644
index 00..03401ef8af03d4
--- /dev/null
+++ b/clang/test/CodeGen/LoongArch/tls-dialect.c
@@ -0,0 +1,14 @@
+// REQUIRES: loongarch-registered-target
+/// cc1 -enable-tlsdesc (due to -mtls-dialect=desc) enables TLSDESC.
+// RUN: %clang_cc1 -triple loongarch64 -S -mrelocation-model pic -pic-level 1 
-enable-tlsdesc %s -o - | FileCheck %s --check-prefix=DESC
+// RUN: %clang_cc1 -triple loongarch64 -S -mrelocation-model pic -pic-level 1 
%s -o - | FileCheck %s --check-prefix=NODESC
+
+__thread int x;
+
+// DESC:   %desc_pc_hi20
+// DESC-NOT:   %gd_pc_hi20
+// NODESC: %gd_pc_hi20
+// NODESC-NOT: %desc_pc_hi20
+int use() {
+  return x;
+}
diff --git a/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp 
b/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
index ad39658f698e7b..c136f5b3e515d7 100644
--- a/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
@@ -80,6 +80,9 @@ class LoongArchPreRAExpandPseudo : public MachineFunctionPass 
{
   bool expandLoadAddressTLSGD(MachineBasicBlock &MBB,
   MachineBasicBlock::iterator MBBI,
   MachineBasicBlock::iterator &NextMBBI);
+  bool expandLoadAddressTLSDesc(MachineBasicBlock &MBB,
+MachineBasicBlock::iterator MBBI,
+MachineBasicBlock::iterator &NextMBBI);
 };
 
 char LoongArchPreRAExpandPseudo::ID = 0;
@@ -122,6 +125,8 @@ bool LoongArchPreRAExpandPseudo::expandMI(
 return expandLoadAddressTLSLD(MBB, MBBI, NextMBBI);
   case LoongArch::PseudoLA_TLS_GD:
 return expandLoadAddressTLSGD(MBB, MBBI, NextMBBI);
+  case LoongArch::PseudoLA_TLS_DESC_PC:
+return expandLoadAddressTLSDesc(MBB, MBBI, NextMBBI);
   }
   return false;
 }
@@ -267,6 +272,52 @@ bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSGD(
  SecondOpcode, LoongArchII::MO_GOT_PC_LO);
 }
 
+bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSDesc(
+MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
+MachineBasicBlock::iterator &NextMBBI) {
+  // Code Sequence:
+  // pcalau12i $a0, %desc_pc_hi20(sym)
+  // addi.w/d  $a0, $a0, %desc_pc_lo12(sym)
+  // ld.w/d$ra, $a0, %desc_ld(sym)
+  // jirl  $ra, $ra, %desc_ld(sym)
+  // add.d $dst, $a0, $tp
+  MachineFunction *MF = MBB.getParent();
+  MachineInstr &MI = *MBBI;
+  DebugLoc DL = MI.getDebugLoc();
+
+  const auto &STI = MF->getSubtarget();
+  unsigned ADD = STI.is64Bit() ? LoongArch::ADD_D : LoongArch::ADD_W;
+  unsigned ADDI = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
+  unsigned LD = STI.is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
+
+  Register DestReg = MI.getOperand(0).getReg();
+  Register ScratchReg =
+  MF->getRegInfo().createVirtualRegister(&LoongArch::GPRRegClass);
+  MachineOperand &Symbol = MI.getOperand(1);
+
+  BuildMI(MBB, MBBI, DL, TII->get(LoongArch::PCALAU12I), ScratchReg)
+  .addDisp(Symbol, 0, LoongArchII::MO_DES

[llvm-branch-commits] [LoongArch][Codegen] Add support for TLSDESC (PR #90157)

2024-04-25 Thread via llvm-branch-commits

https://github.com/wangleiat closed 
https://github.com/llvm/llvm-project/pull/90157
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-25 Thread via llvm-branch-commits

https://github.com/wangleiat created 
https://github.com/llvm/llvm-project/pull/90159

The implementation only enables when the `-enable-tlsdesc` option is
passed and the TLS model is `dynamic`.

LoongArch's GCC has the same option(-mtls-dialet=) as RISC-V.



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


[llvm-branch-commits] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: wanglei (wangleiat)


Changes

The implementation only enables when the `-enable-tlsdesc` option is
passed and the TLS model is `dynamic`.

LoongArch's GCC has the same option(-mtls-dialet=) as RISC-V.


---

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


10 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+1-1) 
- (added) clang/test/CodeGen/LoongArch/tls-dialect.c (+14) 
- (modified) llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp (+108) 
- (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp (+36-14) 
- (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.h (+2) 
- (modified) llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp (+6) 
- (modified) llvm/lib/Target/LoongArch/LoongArchInstrInfo.td (+7) 
- (modified) llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp (+18) 
- (modified) llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.h (+7-1) 
- (modified) llvm/test/CodeGen/LoongArch/tls-models.ll (+139) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index b65b96db16bd79..a5000221f61903 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -737,7 +737,7 @@ bool tools::isTLSDESCEnabled(const ToolChain &TC,
   StringRef V = A->getValue();
   bool SupportedArgument = false, EnableTLSDESC = false;
   bool Unsupported = !Triple.isOSBinFormatELF();
-  if (Triple.isRISCV()) {
+  if (Triple.isRISCV() || Triple.isLoongArch()) {
 SupportedArgument = V == "desc" || V == "trad";
 EnableTLSDESC = V == "desc";
   } else if (Triple.isX86()) {
diff --git a/clang/test/CodeGen/LoongArch/tls-dialect.c 
b/clang/test/CodeGen/LoongArch/tls-dialect.c
new file mode 100644
index 00..03401ef8af03d4
--- /dev/null
+++ b/clang/test/CodeGen/LoongArch/tls-dialect.c
@@ -0,0 +1,14 @@
+// REQUIRES: loongarch-registered-target
+/// cc1 -enable-tlsdesc (due to -mtls-dialect=desc) enables TLSDESC.
+// RUN: %clang_cc1 -triple loongarch64 -S -mrelocation-model pic -pic-level 1 
-enable-tlsdesc %s -o - | FileCheck %s --check-prefix=DESC
+// RUN: %clang_cc1 -triple loongarch64 -S -mrelocation-model pic -pic-level 1 
%s -o - | FileCheck %s --check-prefix=NODESC
+
+__thread int x;
+
+// DESC:   %desc_pc_hi20
+// DESC-NOT:   %gd_pc_hi20
+// NODESC: %gd_pc_hi20
+// NODESC-NOT: %desc_pc_hi20
+int use() {
+  return x;
+}
diff --git a/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp 
b/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
index ad39658f698e7b..c136f5b3e515d7 100644
--- a/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
@@ -80,6 +80,9 @@ class LoongArchPreRAExpandPseudo : public MachineFunctionPass 
{
   bool expandLoadAddressTLSGD(MachineBasicBlock &MBB,
   MachineBasicBlock::iterator MBBI,
   MachineBasicBlock::iterator &NextMBBI);
+  bool expandLoadAddressTLSDesc(MachineBasicBlock &MBB,
+MachineBasicBlock::iterator MBBI,
+MachineBasicBlock::iterator &NextMBBI);
 };
 
 char LoongArchPreRAExpandPseudo::ID = 0;
@@ -122,6 +125,8 @@ bool LoongArchPreRAExpandPseudo::expandMI(
 return expandLoadAddressTLSLD(MBB, MBBI, NextMBBI);
   case LoongArch::PseudoLA_TLS_GD:
 return expandLoadAddressTLSGD(MBB, MBBI, NextMBBI);
+  case LoongArch::PseudoLA_TLS_DESC_PC:
+return expandLoadAddressTLSDesc(MBB, MBBI, NextMBBI);
   }
   return false;
 }
@@ -267,6 +272,52 @@ bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSGD(
  SecondOpcode, LoongArchII::MO_GOT_PC_LO);
 }
 
+bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSDesc(
+MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
+MachineBasicBlock::iterator &NextMBBI) {
+  // Code Sequence:
+  // pcalau12i $a0, %desc_pc_hi20(sym)
+  // addi.w/d  $a0, $a0, %desc_pc_lo12(sym)
+  // ld.w/d$ra, $a0, %desc_ld(sym)
+  // jirl  $ra, $ra, %desc_ld(sym)
+  // add.d $dst, $a0, $tp
+  MachineFunction *MF = MBB.getParent();
+  MachineInstr &MI = *MBBI;
+  DebugLoc DL = MI.getDebugLoc();
+
+  const auto &STI = MF->getSubtarget();
+  unsigned ADD = STI.is64Bit() ? LoongArch::ADD_D : LoongArch::ADD_W;
+  unsigned ADDI = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
+  unsigned LD = STI.is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
+
+  Register DestReg = MI.getOperand(0).getReg();
+  Register ScratchReg =
+  MF->getRegInfo().createVirtualRegister(&LoongArch::GPRRegClass);
+  MachineOperand &Symbol = MI.getOperand(1);
+
+  BuildMI(MBB, MBBI, DL, TII->get(LoongArch::PCALAU12I), ScratchReg)
+  .addDisp(Symbol, 0, LoongArchII::MO_DESC_PC_HI);
+
+  BuildMI(MBB, MBBI, DL, TII->get(ADDI), LoongArch::R4)
+   

[llvm-branch-commits] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-25 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: wanglei (wangleiat)


Changes

The implementation only enables when the `-enable-tlsdesc` option is
passed and the TLS model is `dynamic`.

LoongArch's GCC has the same option(-mtls-dialet=) as RISC-V.


---

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


10 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+1-1) 
- (added) clang/test/CodeGen/LoongArch/tls-dialect.c (+14) 
- (modified) llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp (+108) 
- (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp (+36-14) 
- (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.h (+2) 
- (modified) llvm/lib/Target/LoongArch/LoongArchInstrInfo.cpp (+6) 
- (modified) llvm/lib/Target/LoongArch/LoongArchInstrInfo.td (+7) 
- (modified) llvm/lib/Target/LoongArch/LoongArchMCInstLower.cpp (+18) 
- (modified) llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchBaseInfo.h (+7-1) 
- (modified) llvm/test/CodeGen/LoongArch/tls-models.ll (+139) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index b65b96db16bd79..a5000221f61903 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -737,7 +737,7 @@ bool tools::isTLSDESCEnabled(const ToolChain &TC,
   StringRef V = A->getValue();
   bool SupportedArgument = false, EnableTLSDESC = false;
   bool Unsupported = !Triple.isOSBinFormatELF();
-  if (Triple.isRISCV()) {
+  if (Triple.isRISCV() || Triple.isLoongArch()) {
 SupportedArgument = V == "desc" || V == "trad";
 EnableTLSDESC = V == "desc";
   } else if (Triple.isX86()) {
diff --git a/clang/test/CodeGen/LoongArch/tls-dialect.c 
b/clang/test/CodeGen/LoongArch/tls-dialect.c
new file mode 100644
index 00..03401ef8af03d4
--- /dev/null
+++ b/clang/test/CodeGen/LoongArch/tls-dialect.c
@@ -0,0 +1,14 @@
+// REQUIRES: loongarch-registered-target
+/// cc1 -enable-tlsdesc (due to -mtls-dialect=desc) enables TLSDESC.
+// RUN: %clang_cc1 -triple loongarch64 -S -mrelocation-model pic -pic-level 1 
-enable-tlsdesc %s -o - | FileCheck %s --check-prefix=DESC
+// RUN: %clang_cc1 -triple loongarch64 -S -mrelocation-model pic -pic-level 1 
%s -o - | FileCheck %s --check-prefix=NODESC
+
+__thread int x;
+
+// DESC:   %desc_pc_hi20
+// DESC-NOT:   %gd_pc_hi20
+// NODESC: %gd_pc_hi20
+// NODESC-NOT: %desc_pc_hi20
+int use() {
+  return x;
+}
diff --git a/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp 
b/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
index ad39658f698e7b..c136f5b3e515d7 100644
--- a/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
@@ -80,6 +80,9 @@ class LoongArchPreRAExpandPseudo : public MachineFunctionPass 
{
   bool expandLoadAddressTLSGD(MachineBasicBlock &MBB,
   MachineBasicBlock::iterator MBBI,
   MachineBasicBlock::iterator &NextMBBI);
+  bool expandLoadAddressTLSDesc(MachineBasicBlock &MBB,
+MachineBasicBlock::iterator MBBI,
+MachineBasicBlock::iterator &NextMBBI);
 };
 
 char LoongArchPreRAExpandPseudo::ID = 0;
@@ -122,6 +125,8 @@ bool LoongArchPreRAExpandPseudo::expandMI(
 return expandLoadAddressTLSLD(MBB, MBBI, NextMBBI);
   case LoongArch::PseudoLA_TLS_GD:
 return expandLoadAddressTLSGD(MBB, MBBI, NextMBBI);
+  case LoongArch::PseudoLA_TLS_DESC_PC:
+return expandLoadAddressTLSDesc(MBB, MBBI, NextMBBI);
   }
   return false;
 }
@@ -267,6 +272,52 @@ bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSGD(
  SecondOpcode, LoongArchII::MO_GOT_PC_LO);
 }
 
+bool LoongArchPreRAExpandPseudo::expandLoadAddressTLSDesc(
+MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
+MachineBasicBlock::iterator &NextMBBI) {
+  // Code Sequence:
+  // pcalau12i $a0, %desc_pc_hi20(sym)
+  // addi.w/d  $a0, $a0, %desc_pc_lo12(sym)
+  // ld.w/d$ra, $a0, %desc_ld(sym)
+  // jirl  $ra, $ra, %desc_ld(sym)
+  // add.d $dst, $a0, $tp
+  MachineFunction *MF = MBB.getParent();
+  MachineInstr &MI = *MBBI;
+  DebugLoc DL = MI.getDebugLoc();
+
+  const auto &STI = MF->getSubtarget();
+  unsigned ADD = STI.is64Bit() ? LoongArch::ADD_D : LoongArch::ADD_W;
+  unsigned ADDI = STI.is64Bit() ? LoongArch::ADDI_D : LoongArch::ADDI_W;
+  unsigned LD = STI.is64Bit() ? LoongArch::LD_D : LoongArch::LD_W;
+
+  Register DestReg = MI.getOperand(0).getReg();
+  Register ScratchReg =
+  MF->getRegInfo().createVirtualRegister(&LoongArch::GPRRegClass);
+  MachineOperand &Symbol = MI.getOperand(1);
+
+  BuildMI(MBB, MBBI, DL, TII->get(LoongArch::PCALAU12I), ScratchReg)
+  .addDisp(Symbol, 0, LoongArchII::MO_DESC_PC_HI);
+
+  BuildMI(MBB, MBBI, DL, TII->get(ADDI), LoongArch::R

[llvm-branch-commits] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-25 Thread via llvm-branch-commits

wangleiat wrote:

@xen0n @xry111 

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


[llvm-branch-commits] [RISCV] Remove hasSideEffects=1 for saturating/fault-only-first instructions (PR #90049)

2024-04-25 Thread Pengcheng Wang via llvm-branch-commits

wangpc-pp wrote:

According to `Target.td`:
```c
// Does the instruction have side effects that are not captured by any
// operands of the instruction or other flags?
bit hasSideEffects = ?;
```
It seems we don't need to set `hasSideEffects` for vleNff since we have 
modelled `vl` as an output operand.
As for saturating instructions, I used to think that explicit `Def`/`Use` list 
is kind of side effects `captured by any operands of the instruction` (IIUC), 
so we don't need to set `hasSideEffects` either. And I have just investigated 
AArch64's implementation, they don't set this flag and don't add `Def` list 
(for example, [UQADD - Unsigned saturating 
Add](https://developer.arm.com/documentation/ddi0596/2021-12/SIMD-FP-Instructions/UQADD--Unsigned-saturating-Add-)):
https://github.com/llvm/llvm-project/blob/2de0bedfebb77a6c8a5b0d00902f796fa4022fd6/llvm/lib/Target/AArch64/AArch64InstrInfo.td#L5348
https://github.com/llvm/llvm-project/blob/2de0bedfebb77a6c8a5b0d00902f796fa4022fd6/llvm/lib/Target/AArch64/AArch64InstrFormats.td#L7317-L7336



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


[llvm-branch-commits] [LoongArch][Codegen] Add support for TLSDESC (PR #90159)

2024-04-25 Thread Xi Ruoyao via llvm-branch-commits

xry111 wrote:

> [wangleiat](https://github.com/wangleiat) wants to merge 1 commit into 
> [users/wangleiat/spr/main.loongarchcodegen-add-support-for-tlsdesc-1](https://github.com/llvm/llvm-project/tree/users/wangleiat/spr/main.loongarchcodegen-add-support-for-tlsdesc-1)
>  from 
> [users/wangleiat/spr/loongarchcodegen-add-support-for-tlsdesc-1](https://github.com/llvm/llvm-project/tree/users/wangleiat/spr/loongarchcodegen-add-support-for-tlsdesc-1)

Hmm, it looks like the target branch is wrong?

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