[llvm-branch-commits] [llvm] release/18.x: [AArch64][GISel] Don't pointlessly lower G_TRUNC (#81479) (PR #81581)

2024-02-13 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/81581
___
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: [AArch64][GISel] Don't pointlessly lower G_TRUNC (#81479) (PR #81581)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:

@aemerson What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/81581
___
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: [AArch64][GISel] Don't pointlessly lower G_TRUNC (#81479) (PR #81581)

2024-02-13 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/81581

Backport 070848c17c2944afa494d42d3ad42929f3379842

Requested by: @nikic

>From c9a5bed568b88196dd3d2444b827a42d29f72064 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Tue, 13 Feb 2024 09:29:56 +0100
Subject: [PATCH] [AArch64][GISel] Don't pointlessly lower G_TRUNC (#81479)

If we have something like G_TRUNC from v2s32 to v2s16, then lowering
this to a concat of two G_TRUNC s32 to s16 followed by G_TRUNC from
v2s16 to v2s8 does not bring us any closer to legality. In fact, the
first part of that is a G_BUILD_VECTOR whose legalization will produce a
new G_TRUNC from v2s32 to v2s16, and both G_TRUNCs will then get
combined to the original, causing a legalization cycle.

Make the lowering condition more precise, by requiring that the original
vector is >128 bits, which is I believe the only case where this
specific splitting approach is useful.

Note that this doesn't actually produce a legal result (the alwaysLegal
is a lie, as before), but it will cause a proper globalisel abort
instead of an infinite legalization loop.

Fixes https://github.com/llvm/llvm-project/issues/81244.

(cherry picked from commit 070848c17c2944afa494d42d3ad42929f3379842)
---
 .../AArch64/GISel/AArch64LegalizerInfo.cpp|  5 ++--
 .../AArch64/GlobalISel/legalize-xtn.mir   | 24 +++
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp 
b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index fd69a7d6c33d03..4b9d549e791142 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -622,9 +622,8 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const 
AArch64Subtarget &ST)
   .lowerIf([=](const LegalityQuery &Query) {
 LLT DstTy = Query.Types[0];
 LLT SrcTy = Query.Types[1];
-return DstTy.isVector() && (SrcTy.getSizeInBits() > 128 ||
-(DstTy.getScalarSizeInBits() * 2 <
- SrcTy.getScalarSizeInBits()));
+return DstTy.isVector() && SrcTy.getSizeInBits() > 128 &&
+   DstTy.getScalarSizeInBits() * 2 <= SrcTy.getScalarSizeInBits();
   })
 
   .alwaysLegal();
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir 
b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir
index 16b780a8397347..661265173ae82b 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir
@@ -529,3 +529,27 @@ body: |
 RET_ReallyLR implicit $q0
 
 ...
+
+---
+name:pr81244
+tracksRegLiveness: true
+body: |
+  bb.0:
+liveins: $d0
+; CHECK-LABEL: name: pr81244
+; CHECK: liveins: $d0
+; CHECK-NEXT: {{  $}}
+; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<2 x s32>) = COPY $d0
+; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(<2 x s8>) = G_TRUNC [[COPY]](<2 x s32>)
+; CHECK-NEXT: [[CONCAT_VECTORS:%[0-9]+]]:_(<4 x s8>) = G_CONCAT_VECTORS 
[[TRUNC]](<2 x s8>), [[TRUNC]](<2 x s8>)
+; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(<4 x s16>) = G_ANYEXT 
[[CONCAT_VECTORS]](<4 x s8>)
+; CHECK-NEXT: $d0 = COPY [[ANYEXT]](<4 x s16>)
+; CHECK-NEXT: RET_ReallyLR implicit $d0
+%0:_(<2 x s32>) = COPY $d0
+%1:_(<2 x s8>) = G_TRUNC %0(<2 x s32>)
+%2:_(<4 x s8>) = G_CONCAT_VECTORS %1(<2 x s8>), %1(<2 x s8>)
+%3:_(<4 x s16>) = G_ANYEXT %2(<4 x s8>)
+$d0 = COPY %3(<4 x s16>)
+RET_ReallyLR implicit $d0
+
+...

___
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: [AArch64][GISel] Don't pointlessly lower G_TRUNC (#81479) (PR #81581)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: None (llvmbot)


Changes

Backport 070848c17c2944afa494d42d3ad42929f3379842

Requested by: @nikic

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


2 Files Affected:

- (modified) llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp (+2-3) 
- (modified) llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir (+24) 


``diff
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp 
b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index fd69a7d6c33d03..4b9d549e791142 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -622,9 +622,8 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const 
AArch64Subtarget &ST)
   .lowerIf([=](const LegalityQuery &Query) {
 LLT DstTy = Query.Types[0];
 LLT SrcTy = Query.Types[1];
-return DstTy.isVector() && (SrcTy.getSizeInBits() > 128 ||
-(DstTy.getScalarSizeInBits() * 2 <
- SrcTy.getScalarSizeInBits()));
+return DstTy.isVector() && SrcTy.getSizeInBits() > 128 &&
+   DstTy.getScalarSizeInBits() * 2 <= SrcTy.getScalarSizeInBits();
   })
 
   .alwaysLegal();
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir 
b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir
index 16b780a8397347..661265173ae82b 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir
@@ -529,3 +529,27 @@ body: |
 RET_ReallyLR implicit $q0
 
 ...
+
+---
+name:pr81244
+tracksRegLiveness: true
+body: |
+  bb.0:
+liveins: $d0
+; CHECK-LABEL: name: pr81244
+; CHECK: liveins: $d0
+; CHECK-NEXT: {{  $}}
+; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<2 x s32>) = COPY $d0
+; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(<2 x s8>) = G_TRUNC [[COPY]](<2 x s32>)
+; CHECK-NEXT: [[CONCAT_VECTORS:%[0-9]+]]:_(<4 x s8>) = G_CONCAT_VECTORS 
[[TRUNC]](<2 x s8>), [[TRUNC]](<2 x s8>)
+; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(<4 x s16>) = G_ANYEXT 
[[CONCAT_VECTORS]](<4 x s8>)
+; CHECK-NEXT: $d0 = COPY [[ANYEXT]](<4 x s16>)
+; CHECK-NEXT: RET_ReallyLR implicit $d0
+%0:_(<2 x s32>) = COPY $d0
+%1:_(<2 x s8>) = G_TRUNC %0(<2 x s32>)
+%2:_(<4 x s8>) = G_CONCAT_VECTORS %1(<2 x s8>), %1(<2 x s8>)
+%3:_(<4 x s16>) = G_ANYEXT %2(<4 x s8>)
+$d0 = COPY %3(<4 x s16>)
+RET_ReallyLR implicit $d0
+
+...

``




https://github.com/llvm/llvm-project/pull/81581
___
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] Revert "[RISCV] Recurse on first operand of two operand shuffles (#79180)" (PR #80238)

2024-02-13 Thread Luke Lau via llvm-branch-commits

https://github.com/lukel97 milestoned 
https://github.com/llvm/llvm-project/pull/80238
___
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: [AArch64][GISel] Don't pointlessly lower G_TRUNC (#81479) (PR #81581)

2024-02-13 Thread Matt Arsenault via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/81581
___
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] [llvm] release/18.x: [AArch64][SME] Implement inline-asm clobbers for za/zt0 (#79276) (PR #81593)

2024-02-13 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/81593

Backport d9c20e437fe110fb79b5ca73a52762e5b930b361

Requested by: @MDevereau

>From 115724c36d4963364c1ea0014f5b7d654d80712e Mon Sep 17 00:00:00 2001
From: Matthew Devereau 
Date: Fri, 2 Feb 2024 08:12:05 +
Subject: [PATCH] [AArch64][SME] Implement inline-asm clobbers for za/zt0
 (#79276)

This enables specifing "za" or "zt0" to the clobber list for inline asm.
This complies with the acle SME addition to the asm extension here:
https://github.com/ARM-software/acle/pull/276

(cherry picked from commit d9c20e437fe110fb79b5ca73a52762e5b930b361)
---
 clang/lib/Basic/Targets/AArch64.cpp |  9 -
 clang/test/CodeGen/aarch64-inline-asm.c |  8 
 llvm/lib/Target/AArch64/AArch64ISelLowering.cpp |  8 
 llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp |  4 
 llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll | 16 
 5 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 336b7a5e3d727d..3036f461c1ded1 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1187,6 +1187,8 @@ TargetInfo::BuiltinVaListKind 
AArch64TargetInfo::getBuiltinVaListKind() const {
 }
 
 const char *const AArch64TargetInfo::GCCRegNames[] = {
+// clang-format off
+
 // 32-bit Integer registers
 "w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8", "w9", "w10", "w11",
 "w12", "w13", "w14", "w15", "w16", "w17", "w18", "w19", "w20", "w21", 
"w22",
@@ -1223,7 +1225,12 @@ const char *const AArch64TargetInfo::GCCRegNames[] = {
 
 // SVE predicate-as-counter registers
 "pn0",  "pn1",  "pn2",  "pn3",  "pn4",  "pn5",  "pn6",  "pn7",  "pn8",
-"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15"
+"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15",
+
+// SME registers
+"za", "zt0",
+
+// clang-format on
 };
 
 ArrayRef AArch64TargetInfo::getGCCRegNames() const {
diff --git a/clang/test/CodeGen/aarch64-inline-asm.c 
b/clang/test/CodeGen/aarch64-inline-asm.c
index 75e9a8c46b8769..8ddee560b11da4 100644
--- a/clang/test/CodeGen/aarch64-inline-asm.c
+++ b/clang/test/CodeGen/aarch64-inline-asm.c
@@ -95,3 +95,11 @@ void test_reduced_gpr_constraints(int var32, long var64) {
 // CHECK: [[ARG2:%.+]] = load i64, ptr
 // CHECK: call void asm sideeffect "add x0, x0, $0", "@3Ucj,~{x0}"(i64 
[[ARG2]])
 }
+
+void test_sme_constraints(){
+  asm("movt zt0[3, mul vl], z0" : : : "za");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
+
+  asm("movt zt0[3, mul vl], z0" : : : "zt0");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
+}
\ No newline at end of file
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index e97f5e32201488..bfce5bc92a9ad1 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -10718,6 +10718,14 @@ AArch64TargetLowering::getRegForInlineAsmConstraint(
   parseConstraintCode(Constraint) != AArch64CC::Invalid)
 return std::make_pair(unsigned(AArch64::NZCV), &AArch64::CCRRegClass);
 
+  if (Constraint == "{za}") {
+return std::make_pair(unsigned(AArch64::ZA), &AArch64::MPRRegClass);
+  }
+
+  if (Constraint == "{zt0}") {
+return std::make_pair(unsigned(AArch64::ZT0), &AArch64::ZTRRegClass);
+  }
+
   // Use the default implementation in TargetLowering to convert the register
   // constraint into a member of a register class.
   std::pair Res;
diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp 
b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
index f86e6947c9cdb0..48e1c1bc73022c 100644
--- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
@@ -507,6 +507,10 @@ bool AArch64RegisterInfo::isAsmClobberable(const 
MachineFunction &MF,
 MCRegisterInfo::regsOverlap(PhysReg, AArch64::X16))
 return true;
 
+  // ZA/ZT0 registers are reserved but may be permitted in the clobber list.
+  if (PhysReg == AArch64::ZA || PhysReg == AArch64::ZT0)
+return true;
+
   return !isReservedReg(MF, PhysReg);
 }
 
diff --git a/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll 
b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
new file mode 100644
index 00..a8cba7dc9a91e9
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-linux-gnu -stop-after=aarch64-isel < %s -o - 
| FileCheck %s
+
+define void @alpha( %x) local_unnamed_addr {
+entry:
+; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 
12 /* clobber */, implicit-def early-clobber $za
+  tail call void as

[llvm-branch-commits] [clang] [llvm] release/18.x: [AArch64][SME] Implement inline-asm clobbers for za/zt0 (#79276) (PR #81593)

2024-02-13 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/81593
___
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] [llvm] release/18.x: [AArch64][SME] Implement inline-asm clobbers for za/zt0 (#79276) (PR #81593)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:

@sdesmalen-arm What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/81593
___
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] [llvm] release/18.x: [AArch64][SME] Implement inline-asm clobbers for za/zt0 (#79276) (PR #81593)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport d9c20e437fe110fb79b5ca73a52762e5b930b361

Requested by: @MDevereau

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


5 Files Affected:

- (modified) clang/lib/Basic/Targets/AArch64.cpp (+8-1) 
- (modified) clang/test/CodeGen/aarch64-inline-asm.c (+8) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+8) 
- (modified) llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp (+4) 
- (added) llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll (+16) 


``diff
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 336b7a5e3d727d..3036f461c1ded1 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1187,6 +1187,8 @@ TargetInfo::BuiltinVaListKind 
AArch64TargetInfo::getBuiltinVaListKind() const {
 }
 
 const char *const AArch64TargetInfo::GCCRegNames[] = {
+// clang-format off
+
 // 32-bit Integer registers
 "w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8", "w9", "w10", "w11",
 "w12", "w13", "w14", "w15", "w16", "w17", "w18", "w19", "w20", "w21", 
"w22",
@@ -1223,7 +1225,12 @@ const char *const AArch64TargetInfo::GCCRegNames[] = {
 
 // SVE predicate-as-counter registers
 "pn0",  "pn1",  "pn2",  "pn3",  "pn4",  "pn5",  "pn6",  "pn7",  "pn8",
-"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15"
+"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15",
+
+// SME registers
+"za", "zt0",
+
+// clang-format on
 };
 
 ArrayRef AArch64TargetInfo::getGCCRegNames() const {
diff --git a/clang/test/CodeGen/aarch64-inline-asm.c 
b/clang/test/CodeGen/aarch64-inline-asm.c
index 75e9a8c46b8769..8ddee560b11da4 100644
--- a/clang/test/CodeGen/aarch64-inline-asm.c
+++ b/clang/test/CodeGen/aarch64-inline-asm.c
@@ -95,3 +95,11 @@ void test_reduced_gpr_constraints(int var32, long var64) {
 // CHECK: [[ARG2:%.+]] = load i64, ptr
 // CHECK: call void asm sideeffect "add x0, x0, $0", "@3Ucj,~{x0}"(i64 
[[ARG2]])
 }
+
+void test_sme_constraints(){
+  asm("movt zt0[3, mul vl], z0" : : : "za");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
+
+  asm("movt zt0[3, mul vl], z0" : : : "zt0");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
+}
\ No newline at end of file
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index e97f5e32201488..bfce5bc92a9ad1 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -10718,6 +10718,14 @@ AArch64TargetLowering::getRegForInlineAsmConstraint(
   parseConstraintCode(Constraint) != AArch64CC::Invalid)
 return std::make_pair(unsigned(AArch64::NZCV), &AArch64::CCRRegClass);
 
+  if (Constraint == "{za}") {
+return std::make_pair(unsigned(AArch64::ZA), &AArch64::MPRRegClass);
+  }
+
+  if (Constraint == "{zt0}") {
+return std::make_pair(unsigned(AArch64::ZT0), &AArch64::ZTRRegClass);
+  }
+
   // Use the default implementation in TargetLowering to convert the register
   // constraint into a member of a register class.
   std::pair Res;
diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp 
b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
index f86e6947c9cdb0..48e1c1bc73022c 100644
--- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
@@ -507,6 +507,10 @@ bool AArch64RegisterInfo::isAsmClobberable(const 
MachineFunction &MF,
 MCRegisterInfo::regsOverlap(PhysReg, AArch64::X16))
 return true;
 
+  // ZA/ZT0 registers are reserved but may be permitted in the clobber list.
+  if (PhysReg == AArch64::ZA || PhysReg == AArch64::ZT0)
+return true;
+
   return !isReservedReg(MF, PhysReg);
 }
 
diff --git a/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll 
b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
new file mode 100644
index 00..a8cba7dc9a91e9
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-linux-gnu -stop-after=aarch64-isel < %s -o - 
| FileCheck %s
+
+define void @alpha( %x) local_unnamed_addr {
+entry:
+; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 
12 /* clobber */, implicit-def early-clobber $za
+  tail call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
+  ret void
+}
+
+define void @beta( %x) local_unnamed_addr {
+entry:
+; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 
12 /* clobber */, implicit-def early-clobber $zt0
+  tail call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
+  ret void
+}

``




https://github.com/llvm/llvm-project/pull/81593
___
llvm-branch-commits mailing list
llvm-branch-commits

[llvm-branch-commits] [clang] [llvm] release/18.x: [AArch64][SME] Implement inline-asm clobbers for za/zt0 (#79276) (PR #81593)

2024-02-13 Thread Sander de Smalen via llvm-branch-commits

https://github.com/sdesmalen-arm approved this pull request.

Looks pretty low-risk to me and would be nice to get into the release if we can.

https://github.com/llvm/llvm-project/pull/81593
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread Kareem Ergawy via llvm-branch-commits

https://github.com/ergawy edited https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread Kareem Ergawy via llvm-branch-commits


@@ -1841,14 +1867,112 @@ createMapInfoOp(fir::FirOpBuilder &builder, 
mlir::Location loc,
   llvm::cast(retTy).getElementType());
 
   mlir::omp::MapInfoOp op = builder.create(
-  loc, retTy, baseAddr, varType, varPtrPtr, members, bounds,
+  loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds,
   builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
   builder.getAttr(mapCaptureType),
-  builder.getStringAttr(name));
+  builder.getStringAttr(name), builder.getBoolAttr(partialMap));
 
   return op;
 }
 
+int findComponenetMemberPlacement(
+const Fortran::semantics::Symbol *dTypeSym,
+const Fortran::semantics::Symbol *componentSym) {
+  int placement = -1;
+  if (const auto *derived{

ergawy wrote:

Any reason not to use: `if (const auto *derived = )` instead?

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread Kareem Ergawy via llvm-branch-commits


@@ -49,14 +49,16 @@ using DeclareTargetCapturePair =
 
//===--===//
 
 static Fortran::semantics::Symbol *
-getOmpObjectSymbol(const Fortran::parser::OmpObject &ompObject) {
+getOmpObjParentSymbol(const Fortran::parser::OmpObject &ompObject) {
   Fortran::semantics::Symbol *sym = nullptr;
   std::visit(
   Fortran::common::visitors{
   [&](const Fortran::parser::Designator &designator) {
-if (auto *arrayEle =
-Fortran::parser::Unwrap(
-designator)) {
+if (auto *structComp = Fortran::parser::Unwrap<
+Fortran::parser::StructureComponent>(designator)) {
+  sym = GetFirstName(structComp->base).symbol;
+} else if (auto *arrayEle = Fortran::parser::Unwrap<
+   Fortran::parser::ArrayElement>(designator)) {
   sym = GetFirstName(arrayEle->base).symbol;
 } else if (auto *structComp = Fortran::parser::Unwrap<
Fortran::parser::StructureComponent>(designator)) {

ergawy wrote:

This branch is dead now, right? I will never execute AFAICT.

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread Kareem Ergawy via llvm-branch-commits


@@ -1841,14 +1867,112 @@ createMapInfoOp(fir::FirOpBuilder &builder, 
mlir::Location loc,
   llvm::cast(retTy).getElementType());
 
   mlir::omp::MapInfoOp op = builder.create(
-  loc, retTy, baseAddr, varType, varPtrPtr, members, bounds,
+  loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds,
   builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
   builder.getAttr(mapCaptureType),
-  builder.getStringAttr(name));
+  builder.getStringAttr(name), builder.getBoolAttr(partialMap));
 
   return op;
 }
 
+int findComponenetMemberPlacement(
+const Fortran::semantics::Symbol *dTypeSym,
+const Fortran::semantics::Symbol *componentSym) {
+  int placement = -1;
+  if (const auto *derived{
+  dTypeSym->detailsIf()}) {
+for (auto t : derived->componentNames()) {

ergawy wrote:

I think this logic looks like a good candidate to be a method inside 
`DerivedTypeDetails`, WDYT?

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread Kareem Ergawy via llvm-branch-commits


@@ -1841,14 +1867,112 @@ createMapInfoOp(fir::FirOpBuilder &builder, 
mlir::Location loc,
   llvm::cast(retTy).getElementType());
 
   mlir::omp::MapInfoOp op = builder.create(
-  loc, retTy, baseAddr, varType, varPtrPtr, members, bounds,
+  loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds,
   builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
   builder.getAttr(mapCaptureType),
-  builder.getStringAttr(name));
+  builder.getStringAttr(name), builder.getBoolAttr(partialMap));
 
   return op;
 }
 
+int findComponenetMemberPlacement(
+const Fortran::semantics::Symbol *dTypeSym,
+const Fortran::semantics::Symbol *componentSym) {
+  int placement = -1;
+  if (const auto *derived{

ergawy wrote:

The [LLVM style 
guide](https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code)
 suggests to use early exits when possibe. Can we invert the condition and exit 
with `-1` in the `if` and then execute the main logic after we close the `if`?

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread Kareem Ergawy via llvm-branch-commits


@@ -1841,14 +1867,112 @@ createMapInfoOp(fir::FirOpBuilder &builder, 
mlir::Location loc,
   llvm::cast(retTy).getElementType());
 
   mlir::omp::MapInfoOp op = builder.create(
-  loc, retTy, baseAddr, varType, varPtrPtr, members, bounds,
+  loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds,
   builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
   builder.getAttr(mapCaptureType),
-  builder.getStringAttr(name));
+  builder.getStringAttr(name), builder.getBoolAttr(partialMap));
 
   return op;
 }
 
+int findComponenetMemberPlacement(
+const Fortran::semantics::Symbol *dTypeSym,
+const Fortran::semantics::Symbol *componentSym) {
+  int placement = -1;
+  if (const auto *derived{
+  dTypeSym->detailsIf()}) {
+for (auto t : derived->componentNames()) {
+  placement++;
+  if (t == componentSym->name())
+return placement;
+}
+  }
+  return placement;
+}
+
+static void
+checkAndApplyDeclTargetMapFlags(Fortran::lower::AbstractConverter &converter,
+llvm::omp::OpenMPOffloadMappingFlags &mapFlags,
+Fortran::semantics::Symbol *symbol) {
+  mlir::Operation *op =
+  converter.getModuleOp().lookupSymbol(converter.mangleName(*symbol));
+  if (op)
+if (auto declareTargetOp =
+llvm::dyn_cast(op)) {

ergawy wrote:

Can we use `auto declareTargetOp = 
SymbolTable::lookupNearestSymbolFrom(converter.getModuleOp(),
 converter.mangleName(*symbol));` instead?

It will collapse all the 3 lines and, I think, properly encapsulate what we are 
doing here.

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread Kareem Ergawy via llvm-branch-commits

https://github.com/ergawy commented:

Partially reviewed, will continue later.

Thanks Andrew, I am learning quite a bit from this PR.

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread Kareem Ergawy via llvm-branch-commits


@@ -72,6 +74,29 @@ getOmpObjectSymbol(const Fortran::parser::OmpObject 
&ompObject) {
   return sym;
 }
 
+static Fortran::semantics::Symbol *
+getOmpObjectSymbol(const Fortran::parser::OmpObject &ompObject) {

ergawy wrote:

Instead of having this and the above functions, can we have one function with a 
`bool getParentObjWhenApplicable` argument?

I am suggesting this because almost all the logic is repeated with the 
exception of the `StructureComponent` case, right?

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread Kareem Ergawy via llvm-branch-commits


@@ -1841,14 +1867,112 @@ createMapInfoOp(fir::FirOpBuilder &builder, 
mlir::Location loc,
   llvm::cast(retTy).getElementType());
 
   mlir::omp::MapInfoOp op = builder.create(
-  loc, retTy, baseAddr, varType, varPtrPtr, members, bounds,
+  loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds,
   builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
   builder.getAttr(mapCaptureType),
-  builder.getStringAttr(name));
+  builder.getStringAttr(name), builder.getBoolAttr(partialMap));
 
   return op;
 }
 
+int findComponenetMemberPlacement(
+const Fortran::semantics::Symbol *dTypeSym,
+const Fortran::semantics::Symbol *componentSym) {
+  int placement = -1;
+  if (const auto *derived{
+  dTypeSym->detailsIf()}) {
+for (auto t : derived->componentNames()) {
+  placement++;
+  if (t == componentSym->name())
+return placement;
+}
+  }
+  return placement;
+}
+
+static void
+checkAndApplyDeclTargetMapFlags(Fortran::lower::AbstractConverter &converter,
+llvm::omp::OpenMPOffloadMappingFlags &mapFlags,
+Fortran::semantics::Symbol *symbol) {
+  mlir::Operation *op =
+  converter.getModuleOp().lookupSymbol(converter.mangleName(*symbol));
+  if (op)
+if (auto declareTargetOp =
+llvm::dyn_cast(op)) {
+  // only Link clauses have OMP_MAP_PTR_AND_OBJ applied, To clause
+  // functions fairly different.
+  if (declareTargetOp.getDeclareTargetCaptureClause() ==
+  mlir::omp::DeclareTargetCaptureClause::link)
+mapFlags |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_PTR_AND_OBJ;
+}
+}
+
+static void insertChildMapInfoIntoParent(
+Fortran::lower::AbstractConverter &converter,
+llvm::SmallVector &memberParentSyms,
+llvm::SmallVector &memberMaps,

ergawy wrote:

Is there a reason to use the more general `mlir::Value` rather than 
`omp::MapInfoOp`? I think all elements of `memberMaps` are always instances of 
`MapInfoOp`, right?

It can be argued that we don't need full access to the op's data but my 
suggestion is to provide more "documentation" in the code by using as much 
specific types as possible.

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread via llvm-branch-commits


@@ -49,14 +49,16 @@ using DeclareTargetCapturePair =
 
//===--===//
 
 static Fortran::semantics::Symbol *
-getOmpObjectSymbol(const Fortran::parser::OmpObject &ompObject) {
+getOmpObjParentSymbol(const Fortran::parser::OmpObject &ompObject) {
   Fortran::semantics::Symbol *sym = nullptr;
   std::visit(
   Fortran::common::visitors{
   [&](const Fortran::parser::Designator &designator) {
-if (auto *arrayEle =
-Fortran::parser::Unwrap(
-designator)) {
+if (auto *structComp = Fortran::parser::Unwrap<
+Fortran::parser::StructureComponent>(designator)) {
+  sym = GetFirstName(structComp->base).symbol;
+} else if (auto *arrayEle = Fortran::parser::Unwrap<
+   Fortran::parser::ArrayElement>(designator)) {
   sym = GetFirstName(arrayEle->base).symbol;
 } else if (auto *structComp = Fortran::parser::Unwrap<
Fortran::parser::StructureComponent>(designator)) {

agozillon wrote:

nice catch! Thank you, it's a rebase artifact from putting it on top of a 
recent fix from @kparzysz 

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread via llvm-branch-commits


@@ -72,6 +74,29 @@ getOmpObjectSymbol(const Fortran::parser::OmpObject 
&ompObject) {
   return sym;
 }
 
+static Fortran::semantics::Symbol *
+getOmpObjectSymbol(const Fortran::parser::OmpObject &ompObject) {

agozillon wrote:

Sure, should be able to do! 

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread via llvm-branch-commits


@@ -1841,14 +1867,112 @@ createMapInfoOp(fir::FirOpBuilder &builder, 
mlir::Location loc,
   llvm::cast(retTy).getElementType());
 
   mlir::omp::MapInfoOp op = builder.create(
-  loc, retTy, baseAddr, varType, varPtrPtr, members, bounds,
+  loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds,
   builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
   builder.getAttr(mapCaptureType),
-  builder.getStringAttr(name));
+  builder.getStringAttr(name), builder.getBoolAttr(partialMap));
 
   return op;
 }
 
+int findComponenetMemberPlacement(
+const Fortran::semantics::Symbol *dTypeSym,
+const Fortran::semantics::Symbol *componentSym) {
+  int placement = -1;
+  if (const auto *derived{

agozillon wrote:

no real reason, it's just the style that's used in a lot of places in Flang, so 
I mimic it here. But happy to change it

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread via llvm-branch-commits


@@ -1841,14 +1867,112 @@ createMapInfoOp(fir::FirOpBuilder &builder, 
mlir::Location loc,
   llvm::cast(retTy).getElementType());
 
   mlir::omp::MapInfoOp op = builder.create(
-  loc, retTy, baseAddr, varType, varPtrPtr, members, bounds,
+  loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds,
   builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
   builder.getAttr(mapCaptureType),
-  builder.getStringAttr(name));
+  builder.getStringAttr(name), builder.getBoolAttr(partialMap));
 
   return op;
 }
 
+int findComponenetMemberPlacement(
+const Fortran::semantics::Symbol *dTypeSym,
+const Fortran::semantics::Symbol *componentSym) {
+  int placement = -1;
+  if (const auto *derived{
+  dTypeSym->detailsIf()}) {
+for (auto t : derived->componentNames()) {

agozillon wrote:

I'm happy to do that, does that seem reasonable @kiranchandramohan 

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread via llvm-branch-commits


@@ -1841,14 +1867,112 @@ createMapInfoOp(fir::FirOpBuilder &builder, 
mlir::Location loc,
   llvm::cast(retTy).getElementType());
 
   mlir::omp::MapInfoOp op = builder.create(
-  loc, retTy, baseAddr, varType, varPtrPtr, members, bounds,
+  loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds,
   builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
   builder.getAttr(mapCaptureType),
-  builder.getStringAttr(name));
+  builder.getStringAttr(name), builder.getBoolAttr(partialMap));
 
   return op;
 }
 
+int findComponenetMemberPlacement(
+const Fortran::semantics::Symbol *dTypeSym,
+const Fortran::semantics::Symbol *componentSym) {
+  int placement = -1;
+  if (const auto *derived{

agozillon wrote:

should be possible, will give it a try!

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread via llvm-branch-commits


@@ -1841,14 +1867,112 @@ createMapInfoOp(fir::FirOpBuilder &builder, 
mlir::Location loc,
   llvm::cast(retTy).getElementType());
 
   mlir::omp::MapInfoOp op = builder.create(
-  loc, retTy, baseAddr, varType, varPtrPtr, members, bounds,
+  loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds,
   builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
   builder.getAttr(mapCaptureType),
-  builder.getStringAttr(name));
+  builder.getStringAttr(name), builder.getBoolAttr(partialMap));
 
   return op;
 }
 
+int findComponenetMemberPlacement(
+const Fortran::semantics::Symbol *dTypeSym,
+const Fortran::semantics::Symbol *componentSym) {
+  int placement = -1;
+  if (const auto *derived{
+  dTypeSym->detailsIf()}) {
+for (auto t : derived->componentNames()) {
+  placement++;
+  if (t == componentSym->name())
+return placement;
+}
+  }
+  return placement;
+}
+
+static void
+checkAndApplyDeclTargetMapFlags(Fortran::lower::AbstractConverter &converter,
+llvm::omp::OpenMPOffloadMappingFlags &mapFlags,
+Fortran::semantics::Symbol *symbol) {
+  mlir::Operation *op =
+  converter.getModuleOp().lookupSymbol(converter.mangleName(*symbol));
+  if (op)
+if (auto declareTargetOp =
+llvm::dyn_cast(op)) {

agozillon wrote:

makes sense!

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread via llvm-branch-commits


@@ -1841,14 +1867,112 @@ createMapInfoOp(fir::FirOpBuilder &builder, 
mlir::Location loc,
   llvm::cast(retTy).getElementType());
 
   mlir::omp::MapInfoOp op = builder.create(
-  loc, retTy, baseAddr, varType, varPtrPtr, members, bounds,
+  loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds,
   builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
   builder.getAttr(mapCaptureType),
-  builder.getStringAttr(name));
+  builder.getStringAttr(name), builder.getBoolAttr(partialMap));
 
   return op;
 }
 
+int findComponenetMemberPlacement(
+const Fortran::semantics::Symbol *dTypeSym,
+const Fortran::semantics::Symbol *componentSym) {
+  int placement = -1;
+  if (const auto *derived{
+  dTypeSym->detailsIf()}) {
+for (auto t : derived->componentNames()) {
+  placement++;
+  if (t == componentSym->name())
+return placement;
+}
+  }
+  return placement;
+}
+
+static void
+checkAndApplyDeclTargetMapFlags(Fortran::lower::AbstractConverter &converter,
+llvm::omp::OpenMPOffloadMappingFlags &mapFlags,
+Fortran::semantics::Symbol *symbol) {
+  mlir::Operation *op =
+  converter.getModuleOp().lookupSymbol(converter.mangleName(*symbol));
+  if (op)
+if (auto declareTargetOp =
+llvm::dyn_cast(op)) {
+  // only Link clauses have OMP_MAP_PTR_AND_OBJ applied, To clause
+  // functions fairly different.
+  if (declareTargetOp.getDeclareTargetCaptureClause() ==
+  mlir::omp::DeclareTargetCaptureClause::link)
+mapFlags |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_PTR_AND_OBJ;
+}
+}
+
+static void insertChildMapInfoIntoParent(
+Fortran::lower::AbstractConverter &converter,
+llvm::SmallVector &memberParentSyms,
+llvm::SmallVector &memberMaps,

agozillon wrote:

No reason from what I recall, we just tend to pass things around as 
mlir::Value's (and I've gotten complacent with it I imagine) perhaps as it 
makes it easier to pass things around as we tend to use the more generalised 
mlir::Value most places as opposed to the operation itself.  However, I'll see 
what I can do!

https://github.com/llvm/llvm-project/pull/81511
___
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][OpenMP][MLIR] Extend derived (record) type map support in Flang OpenMP by adding some initial support for explicit member mapping (PR #81511)

2024-02-13 Thread via llvm-branch-commits

agozillon wrote:

> Partially reviewed, will continue later.
> 
> Thanks Andrew, I am learning quite a bit from this PR.

No worries, I'll await your review completion to update the PR! Please do take 
your time though, I'm aware it's a large PR. 

https://github.com/llvm/llvm-project/pull/81511
___
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] [llvm] release/18.x: [AArch64][SME] Implement inline-asm clobbers for za/zt0 (#79276) (PR #81616)

2024-02-13 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/81616

Backport d9c20e437fe110fb79b5ca73a52762e5b930b361

Requested by: @MDevereau

>From ba9eeb9e600d1ea8fe5455bfaa5f086f8ff89239 Mon Sep 17 00:00:00 2001
From: Matthew Devereau 
Date: Fri, 2 Feb 2024 08:12:05 +
Subject: [PATCH] [AArch64][SME] Implement inline-asm clobbers for za/zt0
 (#79276)

This enables specifing "za" or "zt0" to the clobber list for inline asm.
This complies with the acle SME addition to the asm extension here:
https://github.com/ARM-software/acle/pull/276

(cherry picked from commit d9c20e437fe110fb79b5ca73a52762e5b930b361)
---
 clang/lib/Basic/Targets/AArch64.cpp |  9 -
 clang/test/CodeGen/aarch64-inline-asm.c |  8 
 llvm/lib/Target/AArch64/AArch64ISelLowering.cpp |  8 
 llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp |  4 
 llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll | 16 
 5 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 336b7a5e3d727d..3036f461c1ded1 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1187,6 +1187,8 @@ TargetInfo::BuiltinVaListKind 
AArch64TargetInfo::getBuiltinVaListKind() const {
 }
 
 const char *const AArch64TargetInfo::GCCRegNames[] = {
+// clang-format off
+
 // 32-bit Integer registers
 "w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8", "w9", "w10", "w11",
 "w12", "w13", "w14", "w15", "w16", "w17", "w18", "w19", "w20", "w21", 
"w22",
@@ -1223,7 +1225,12 @@ const char *const AArch64TargetInfo::GCCRegNames[] = {
 
 // SVE predicate-as-counter registers
 "pn0",  "pn1",  "pn2",  "pn3",  "pn4",  "pn5",  "pn6",  "pn7",  "pn8",
-"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15"
+"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15",
+
+// SME registers
+"za", "zt0",
+
+// clang-format on
 };
 
 ArrayRef AArch64TargetInfo::getGCCRegNames() const {
diff --git a/clang/test/CodeGen/aarch64-inline-asm.c 
b/clang/test/CodeGen/aarch64-inline-asm.c
index 75e9a8c46b8769..8ddee560b11da4 100644
--- a/clang/test/CodeGen/aarch64-inline-asm.c
+++ b/clang/test/CodeGen/aarch64-inline-asm.c
@@ -95,3 +95,11 @@ void test_reduced_gpr_constraints(int var32, long var64) {
 // CHECK: [[ARG2:%.+]] = load i64, ptr
 // CHECK: call void asm sideeffect "add x0, x0, $0", "@3Ucj,~{x0}"(i64 
[[ARG2]])
 }
+
+void test_sme_constraints(){
+  asm("movt zt0[3, mul vl], z0" : : : "za");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
+
+  asm("movt zt0[3, mul vl], z0" : : : "zt0");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
+}
\ No newline at end of file
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index e97f5e32201488..bfce5bc92a9ad1 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -10718,6 +10718,14 @@ AArch64TargetLowering::getRegForInlineAsmConstraint(
   parseConstraintCode(Constraint) != AArch64CC::Invalid)
 return std::make_pair(unsigned(AArch64::NZCV), &AArch64::CCRRegClass);
 
+  if (Constraint == "{za}") {
+return std::make_pair(unsigned(AArch64::ZA), &AArch64::MPRRegClass);
+  }
+
+  if (Constraint == "{zt0}") {
+return std::make_pair(unsigned(AArch64::ZT0), &AArch64::ZTRRegClass);
+  }
+
   // Use the default implementation in TargetLowering to convert the register
   // constraint into a member of a register class.
   std::pair Res;
diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp 
b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
index f86e6947c9cdb0..48e1c1bc73022c 100644
--- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
@@ -507,6 +507,10 @@ bool AArch64RegisterInfo::isAsmClobberable(const 
MachineFunction &MF,
 MCRegisterInfo::regsOverlap(PhysReg, AArch64::X16))
 return true;
 
+  // ZA/ZT0 registers are reserved but may be permitted in the clobber list.
+  if (PhysReg == AArch64::ZA || PhysReg == AArch64::ZT0)
+return true;
+
   return !isReservedReg(MF, PhysReg);
 }
 
diff --git a/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll 
b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
new file mode 100644
index 00..a8cba7dc9a91e9
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-linux-gnu -stop-after=aarch64-isel < %s -o - 
| FileCheck %s
+
+define void @alpha( %x) local_unnamed_addr {
+entry:
+; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 
12 /* clobber */, implicit-def early-clobber $za
+  tail call void as

[llvm-branch-commits] [clang] [llvm] release/18.x: [AArch64][SME] Implement inline-asm clobbers for za/zt0 (#79276) (PR #81616)

2024-02-13 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/81616
___
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] [llvm] release/18.x: [AArch64][SME] Implement inline-asm clobbers for za/zt0 (#79276) (PR #81616)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:

@sdesmalen-arm What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/81616
___
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] [llvm] release/18.x: [AArch64][SME] Implement inline-asm clobbers for za/zt0 (#79276) (PR #81616)

2024-02-13 Thread via llvm-branch-commits

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/81616

>From 543b5df5dfc74e65c04c9b0c57dc559b17f90da0 Mon Sep 17 00:00:00 2001
From: Matthew Devereau 
Date: Fri, 2 Feb 2024 08:12:05 +
Subject: [PATCH] [AArch64][SME] Implement inline-asm clobbers for za/zt0
 (#79276)

This enables specifing "za" or "zt0" to the clobber list for inline asm.
This complies with the acle SME addition to the asm extension here:
https://github.com/ARM-software/acle/pull/276

(cherry picked from commit d9c20e437fe110fb79b5ca73a52762e5b930b361)
---
 clang/lib/Basic/Targets/AArch64.cpp |  9 -
 clang/test/CodeGen/aarch64-inline-asm.c |  8 
 llvm/lib/Target/AArch64/AArch64ISelLowering.cpp |  8 
 llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp |  4 
 llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll | 16 
 5 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 336b7a5e3d727d..3036f461c1ded1 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1187,6 +1187,8 @@ TargetInfo::BuiltinVaListKind 
AArch64TargetInfo::getBuiltinVaListKind() const {
 }
 
 const char *const AArch64TargetInfo::GCCRegNames[] = {
+// clang-format off
+
 // 32-bit Integer registers
 "w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8", "w9", "w10", "w11",
 "w12", "w13", "w14", "w15", "w16", "w17", "w18", "w19", "w20", "w21", 
"w22",
@@ -1223,7 +1225,12 @@ const char *const AArch64TargetInfo::GCCRegNames[] = {
 
 // SVE predicate-as-counter registers
 "pn0",  "pn1",  "pn2",  "pn3",  "pn4",  "pn5",  "pn6",  "pn7",  "pn8",
-"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15"
+"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15",
+
+// SME registers
+"za", "zt0",
+
+// clang-format on
 };
 
 ArrayRef AArch64TargetInfo::getGCCRegNames() const {
diff --git a/clang/test/CodeGen/aarch64-inline-asm.c 
b/clang/test/CodeGen/aarch64-inline-asm.c
index 75e9a8c46b8769..8ddee560b11da4 100644
--- a/clang/test/CodeGen/aarch64-inline-asm.c
+++ b/clang/test/CodeGen/aarch64-inline-asm.c
@@ -95,3 +95,11 @@ void test_reduced_gpr_constraints(int var32, long var64) {
 // CHECK: [[ARG2:%.+]] = load i64, ptr
 // CHECK: call void asm sideeffect "add x0, x0, $0", "@3Ucj,~{x0}"(i64 
[[ARG2]])
 }
+
+void test_sme_constraints(){
+  asm("movt zt0[3, mul vl], z0" : : : "za");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
+
+  asm("movt zt0[3, mul vl], z0" : : : "zt0");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
+}
\ No newline at end of file
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index e97f5e32201488..bfce5bc92a9ad1 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -10718,6 +10718,14 @@ AArch64TargetLowering::getRegForInlineAsmConstraint(
   parseConstraintCode(Constraint) != AArch64CC::Invalid)
 return std::make_pair(unsigned(AArch64::NZCV), &AArch64::CCRRegClass);
 
+  if (Constraint == "{za}") {
+return std::make_pair(unsigned(AArch64::ZA), &AArch64::MPRRegClass);
+  }
+
+  if (Constraint == "{zt0}") {
+return std::make_pair(unsigned(AArch64::ZT0), &AArch64::ZTRRegClass);
+  }
+
   // Use the default implementation in TargetLowering to convert the register
   // constraint into a member of a register class.
   std::pair Res;
diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp 
b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
index f86e6947c9cdb0..48e1c1bc73022c 100644
--- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
@@ -507,6 +507,10 @@ bool AArch64RegisterInfo::isAsmClobberable(const 
MachineFunction &MF,
 MCRegisterInfo::regsOverlap(PhysReg, AArch64::X16))
 return true;
 
+  // ZA/ZT0 registers are reserved but may be permitted in the clobber list.
+  if (PhysReg == AArch64::ZA || PhysReg == AArch64::ZT0)
+return true;
+
   return !isReservedReg(MF, PhysReg);
 }
 
diff --git a/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll 
b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
new file mode 100644
index 00..a8cba7dc9a91e9
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-linux-gnu -stop-after=aarch64-isel < %s -o - 
| FileCheck %s
+
+define void @alpha( %x) local_unnamed_addr {
+entry:
+; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 
12 /* clobber */, implicit-def early-clobber $za
+  tail call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
+  ret void
+}
+
+define vo

[llvm-branch-commits] [clang] [llvm] release/18.x: [AArch64][SME] Implement inline-asm clobbers for za/zt0 (#79276) (PR #81616)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport d9c20e437fe110fb79b5ca73a52762e5b930b361

Requested by: @MDevereau

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


5 Files Affected:

- (modified) clang/lib/Basic/Targets/AArch64.cpp (+8-1) 
- (modified) clang/test/CodeGen/aarch64-inline-asm.c (+8) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+8) 
- (modified) llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp (+4) 
- (added) llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll (+16) 


``diff
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 336b7a5e3d727d..3036f461c1ded1 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1187,6 +1187,8 @@ TargetInfo::BuiltinVaListKind 
AArch64TargetInfo::getBuiltinVaListKind() const {
 }
 
 const char *const AArch64TargetInfo::GCCRegNames[] = {
+// clang-format off
+
 // 32-bit Integer registers
 "w0", "w1", "w2", "w3", "w4", "w5", "w6", "w7", "w8", "w9", "w10", "w11",
 "w12", "w13", "w14", "w15", "w16", "w17", "w18", "w19", "w20", "w21", 
"w22",
@@ -1223,7 +1225,12 @@ const char *const AArch64TargetInfo::GCCRegNames[] = {
 
 // SVE predicate-as-counter registers
 "pn0",  "pn1",  "pn2",  "pn3",  "pn4",  "pn5",  "pn6",  "pn7",  "pn8",
-"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15"
+"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15",
+
+// SME registers
+"za", "zt0",
+
+// clang-format on
 };
 
 ArrayRef AArch64TargetInfo::getGCCRegNames() const {
diff --git a/clang/test/CodeGen/aarch64-inline-asm.c 
b/clang/test/CodeGen/aarch64-inline-asm.c
index 75e9a8c46b8769..8ddee560b11da4 100644
--- a/clang/test/CodeGen/aarch64-inline-asm.c
+++ b/clang/test/CodeGen/aarch64-inline-asm.c
@@ -95,3 +95,11 @@ void test_reduced_gpr_constraints(int var32, long var64) {
 // CHECK: [[ARG2:%.+]] = load i64, ptr
 // CHECK: call void asm sideeffect "add x0, x0, $0", "@3Ucj,~{x0}"(i64 
[[ARG2]])
 }
+
+void test_sme_constraints(){
+  asm("movt zt0[3, mul vl], z0" : : : "za");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
+
+  asm("movt zt0[3, mul vl], z0" : : : "zt0");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
+}
\ No newline at end of file
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index e97f5e32201488..bfce5bc92a9ad1 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -10718,6 +10718,14 @@ AArch64TargetLowering::getRegForInlineAsmConstraint(
   parseConstraintCode(Constraint) != AArch64CC::Invalid)
 return std::make_pair(unsigned(AArch64::NZCV), &AArch64::CCRRegClass);
 
+  if (Constraint == "{za}") {
+return std::make_pair(unsigned(AArch64::ZA), &AArch64::MPRRegClass);
+  }
+
+  if (Constraint == "{zt0}") {
+return std::make_pair(unsigned(AArch64::ZT0), &AArch64::ZTRRegClass);
+  }
+
   // Use the default implementation in TargetLowering to convert the register
   // constraint into a member of a register class.
   std::pair Res;
diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp 
b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
index f86e6947c9cdb0..48e1c1bc73022c 100644
--- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
@@ -507,6 +507,10 @@ bool AArch64RegisterInfo::isAsmClobberable(const 
MachineFunction &MF,
 MCRegisterInfo::regsOverlap(PhysReg, AArch64::X16))
 return true;
 
+  // ZA/ZT0 registers are reserved but may be permitted in the clobber list.
+  if (PhysReg == AArch64::ZA || PhysReg == AArch64::ZT0)
+return true;
+
   return !isReservedReg(MF, PhysReg);
 }
 
diff --git a/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll 
b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
new file mode 100644
index 00..a8cba7dc9a91e9
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-linux-gnu -stop-after=aarch64-isel < %s -o - 
| FileCheck %s
+
+define void @alpha( %x) local_unnamed_addr {
+entry:
+; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 
12 /* clobber */, implicit-def early-clobber $za
+  tail call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
+  ret void
+}
+
+define void @beta( %x) local_unnamed_addr {
+entry:
+; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 
12 /* clobber */, implicit-def early-clobber $zt0
+  tail call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
+  ret void
+}

``




https://github.com/llvm/llvm-project/pull/81616
___
llvm-branch-commits mailing list
llvm-branch-commits

[llvm-branch-commits] [ELF] Place .lbss/.lrodata/.ldata after .bss (PR #81224)

2024-02-13 Thread James Y Knight via llvm-branch-commits

jyknight wrote:

> I don't think this means that we unsupport -no-pie use cases

Yes, we'd still support -no-pie, but we'd fail to support -no-pie 
-mcmodel=medium.

> cost of layout purity

I see that you feel strongly about this (e.g. by calling it "purity"), but I 
don't understand why. It's not the cost of the "if" in the implementation 
you're worried about, I think, but some other aspect?

> INSERT AFTER .lrodata would give different behaviors (a 32-bit offset 
> relative to .text is positive in one while negative in the other)

I agree that the sign of the relative offset will change...but why is that 
concerning? The whole point of "INSERT AFTER" is to avoid specifying the entire 
layout. Does it matter that the offset relative to .text is sometimes negative 
and sometimes positive?

> which we should not treat hand-wavy.

Have scripts been broken by the _unconditional_ change from the offset being 
always-negative to the offset being always-positive? It seems unlikely to me 
that they would be, but am I missing something? If they don't, then that seems 
like having it be conditional is also fine.

https://github.com/llvm/llvm-project/pull/81224
___
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] Convert unique clauses in ClauseProcessor (PR #81622)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

Temporarily rename old clause list to `clauses2`, old clause iterator to 
`ClauseIterator2`.
Change `findUniqueClause` to iterate over `omp::Clause` objects, modify all 
handlers to operate on 'omp::clause::xyz` equivalents.

[Clause representation 2/6]

>From bdf305038dcb144bfdfbf6d32bedf3e8a481e463 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 6 Feb 2024 17:06:29 -0600
Subject: [PATCH] [flang][OpenMP] Convert unique clauses in ClauseProcessor

Temporarily rename old clause list to `clauses2`, old clause iterator
to `ClauseIterator2`.
Change `findUniqueClause` to iterate over `omp::Clause` objects,
modify all handlers to operate on 'omp::clause::xyz` equivalents.
---
 flang/lib/Lower/OpenMP.cpp | 242 +
 1 file changed, 114 insertions(+), 128 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 24bef1d999548b..d7a93db15a4bb8 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -1669,7 +1669,8 @@ class ClauseProcessor {
   ClauseProcessor(Fortran::lower::AbstractConverter &converter,
   Fortran::semantics::SemanticsContext &semaCtx,
   const Fortran::parser::OmpClauseList &clauses)
-  : converter(converter), semaCtx(semaCtx), clauses(clauses) {}
+  : converter(converter), semaCtx(semaCtx), clauses2(clauses),
+clauses(omp::makeList(clauses, semaCtx)) {}
 
   // 'Unique' clauses: They can appear at most once in the clause list.
   bool
@@ -1769,7 +1770,8 @@ class ClauseProcessor {
llvm::omp::Directive directive) const;
 
 private:
-  using ClauseIterator = std::list::const_iterator;
+  using ClauseIterator = omp::List::const_iterator;
+  using ClauseIterator2 = std::list::const_iterator;
 
   /// Utility to find a clause within a range in the clause list.
   template 
@@ -1782,14 +1784,26 @@ class ClauseProcessor {
 return end;
   }
 
+  /// Utility to find a clause within a range in the clause list.
+  template 
+  static ClauseIterator2 findClause2(ClauseIterator2 begin,
+ ClauseIterator2 end) {
+for (ClauseIterator2 it = begin; it != end; ++it) {
+  if (std::get_if(&it->u))
+return it;
+}
+
+return end;
+  }
+
   /// Return the first instance of the given clause found in the clause list or
   /// `nullptr` if not present. If more than one instance is expected, use
   /// `findRepeatableClause` instead.
   template 
   const T *
   findUniqueClause(const Fortran::parser::CharBlock **source = nullptr) const {
-ClauseIterator it = findClause(clauses.v.begin(), clauses.v.end());
-if (it != clauses.v.end()) {
+ClauseIterator it = findClause(clauses.begin(), clauses.end());
+if (it != clauses.end()) {
   if (source)
 *source = &it->source;
   return &std::get(it->u);
@@ -1804,9 +1818,9 @@ class ClauseProcessor {
   std::function
   callbackFn) const {
 bool found = false;
-ClauseIterator nextIt, endIt = clauses.v.end();
-for (ClauseIterator it = clauses.v.begin(); it != endIt; it = nextIt) {
-  nextIt = findClause(it, endIt);
+ClauseIterator2 nextIt, endIt = clauses2.v.end();
+for (ClauseIterator2 it = clauses2.v.begin(); it != endIt; it = nextIt) {
+  nextIt = findClause2(it, endIt);
 
   if (nextIt != endIt) {
 callbackFn(&std::get(nextIt->u), nextIt->source);
@@ -1829,7 +1843,8 @@ class ClauseProcessor {
 
   Fortran::lower::AbstractConverter &converter;
   Fortran::semantics::SemanticsContext &semaCtx;
-  const Fortran::parser::OmpClauseList &clauses;
+  const Fortran::parser::OmpClauseList &clauses2;
+  omp::List clauses;
 };
 
 
//===--===//
@@ -2294,64 +2309,55 @@ class ReductionProcessor {
 };
 
 static mlir::omp::ScheduleModifier
-translateScheduleModifier(const Fortran::parser::OmpScheduleModifierType &m) {
-  switch (m.v) {
-  case Fortran::parser::OmpScheduleModifierType::ModType::Monotonic:
+translateScheduleModifier(const omp::clause::Schedule::ModType &m) {
+  switch (m) {
+  case omp::clause::Schedule::ModType::Monotonic:
 return mlir::omp::ScheduleModifier::monotonic;
-  case Fortran::parser::OmpScheduleModifierType::ModType::Nonmonotonic:
+  case omp::clause::Schedule::ModType::Nonmonotonic:
 return mlir::omp::ScheduleModifier::nonmonotonic;
-  case Fortran::parser::OmpScheduleModifierType::ModType::Simd:
+  case omp::clause::Schedule::ModType::Simd:
 return mlir::omp::ScheduleModifier::simd;
   }
   return mlir::omp::ScheduleModifier::none;
 }
 
 static mlir::omp::ScheduleModifier
-getScheduleModifier(const Fortran::parser::OmpScheduleClause &x) {
-  const auto &modifier =
-  std::get>(x.t);
+getScheduleModifier(const omp::clause::Schedule &clause) {
+  using ScheduleModifier = omp::clause::Schedule::Sch

[llvm-branch-commits] [flang] [flang][OpenMP] Convert unique clauses in ClauseProcessor (PR #81622)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:




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

Author: Krzysztof Parzyszek (kparzysz)


Changes

Temporarily rename old clause list to `clauses2`, old clause iterator to 
`ClauseIterator2`.
Change `findUniqueClause` to iterate over `omp::Clause` objects, modify all 
handlers to operate on 'omp::clause::xyz` equivalents.

[Clause representation 2/6]

---

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


1 Files Affected:

- (modified) flang/lib/Lower/OpenMP.cpp (+114-128) 


``diff
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 24bef1d999548b..d7a93db15a4bb8 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -1669,7 +1669,8 @@ class ClauseProcessor {
   ClauseProcessor(Fortran::lower::AbstractConverter &converter,
   Fortran::semantics::SemanticsContext &semaCtx,
   const Fortran::parser::OmpClauseList &clauses)
-  : converter(converter), semaCtx(semaCtx), clauses(clauses) {}
+  : converter(converter), semaCtx(semaCtx), clauses2(clauses),
+clauses(omp::makeList(clauses, semaCtx)) {}
 
   // 'Unique' clauses: They can appear at most once in the clause list.
   bool
@@ -1769,7 +1770,8 @@ class ClauseProcessor {
llvm::omp::Directive directive) const;
 
 private:
-  using ClauseIterator = std::list::const_iterator;
+  using ClauseIterator = omp::List::const_iterator;
+  using ClauseIterator2 = std::list::const_iterator;
 
   /// Utility to find a clause within a range in the clause list.
   template 
@@ -1782,14 +1784,26 @@ class ClauseProcessor {
 return end;
   }
 
+  /// Utility to find a clause within a range in the clause list.
+  template 
+  static ClauseIterator2 findClause2(ClauseIterator2 begin,
+ ClauseIterator2 end) {
+for (ClauseIterator2 it = begin; it != end; ++it) {
+  if (std::get_if(&it->u))
+return it;
+}
+
+return end;
+  }
+
   /// Return the first instance of the given clause found in the clause list or
   /// `nullptr` if not present. If more than one instance is expected, use
   /// `findRepeatableClause` instead.
   template 
   const T *
   findUniqueClause(const Fortran::parser::CharBlock **source = nullptr) const {
-ClauseIterator it = findClause(clauses.v.begin(), clauses.v.end());
-if (it != clauses.v.end()) {
+ClauseIterator it = findClause(clauses.begin(), clauses.end());
+if (it != clauses.end()) {
   if (source)
 *source = &it->source;
   return &std::get(it->u);
@@ -1804,9 +1818,9 @@ class ClauseProcessor {
   std::function
   callbackFn) const {
 bool found = false;
-ClauseIterator nextIt, endIt = clauses.v.end();
-for (ClauseIterator it = clauses.v.begin(); it != endIt; it = nextIt) {
-  nextIt = findClause(it, endIt);
+ClauseIterator2 nextIt, endIt = clauses2.v.end();
+for (ClauseIterator2 it = clauses2.v.begin(); it != endIt; it = nextIt) {
+  nextIt = findClause2(it, endIt);
 
   if (nextIt != endIt) {
 callbackFn(&std::get(nextIt->u), nextIt->source);
@@ -1829,7 +1843,8 @@ class ClauseProcessor {
 
   Fortran::lower::AbstractConverter &converter;
   Fortran::semantics::SemanticsContext &semaCtx;
-  const Fortran::parser::OmpClauseList &clauses;
+  const Fortran::parser::OmpClauseList &clauses2;
+  omp::List clauses;
 };
 
 
//===--===//
@@ -2294,64 +2309,55 @@ class ReductionProcessor {
 };
 
 static mlir::omp::ScheduleModifier
-translateScheduleModifier(const Fortran::parser::OmpScheduleModifierType &m) {
-  switch (m.v) {
-  case Fortran::parser::OmpScheduleModifierType::ModType::Monotonic:
+translateScheduleModifier(const omp::clause::Schedule::ModType &m) {
+  switch (m) {
+  case omp::clause::Schedule::ModType::Monotonic:
 return mlir::omp::ScheduleModifier::monotonic;
-  case Fortran::parser::OmpScheduleModifierType::ModType::Nonmonotonic:
+  case omp::clause::Schedule::ModType::Nonmonotonic:
 return mlir::omp::ScheduleModifier::nonmonotonic;
-  case Fortran::parser::OmpScheduleModifierType::ModType::Simd:
+  case omp::clause::Schedule::ModType::Simd:
 return mlir::omp::ScheduleModifier::simd;
   }
   return mlir::omp::ScheduleModifier::none;
 }
 
 static mlir::omp::ScheduleModifier
-getScheduleModifier(const Fortran::parser::OmpScheduleClause &x) {
-  const auto &modifier =
-  std::get>(x.t);
+getScheduleModifier(const omp::clause::Schedule &clause) {
+  using ScheduleModifier = omp::clause::Schedule::ScheduleModifier;
+  const auto &modifier = std::get>(clause.t);
   // The input may have the modifier any order, so we look for one that isn't
   // SIMD. If modifier is not set at all, fall down to the bottom and return
   // "none".
   if (modifier) {
-const auto &modType1 =
-std::get(modifier->t);
-if (modType1.v

[llvm-branch-commits] [flang] [flang][OpenMP] Convert repeatable clauses (except Map) in ClauseProc… (PR #81623)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

…essor

Rename `findRepeatableClause` to `findRepeatableClause2`, and make the new 
`findRepeatableClause` operate on new `omp::Clause` objects.

Leave `Map` unchanged, because it will require more changes for it to work.

>From be33fa2419d24490a221f78fbba4f2b7097b6011 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 6 Feb 2024 17:06:29 -0600
Subject: [PATCH] [flang][OpenMP] Convert repeatable clauses (except Map) in
 ClauseProcessor

Rename `findRepeatableClause` to `findRepeatableClause2`, and make the
new `findRepeatableClause` operate on new `omp::Clause` objects.

Leave `Map` unchanged, because it will require more changes for it to
work.
---
 flang/include/flang/Evaluate/tools.h |  23 +
 flang/lib/Lower/OpenMP.cpp   | 632 +--
 2 files changed, 328 insertions(+), 327 deletions(-)

diff --git a/flang/include/flang/Evaluate/tools.h 
b/flang/include/flang/Evaluate/tools.h
index d257da1a709642..e974944e88 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -430,6 +430,29 @@ template  std::optional 
ExtractCoarrayRef(const A &x) {
   }
 }
 
+struct ExtractSubstringHelper {
+  template  static std::optional visit(T &&) {
+return std::nullopt;
+  }
+
+  static std::optional visit(const Substring &e) { return e; }
+
+  template 
+  static std::optional visit(const Designator &e) {
+return std::visit([](auto &&s) { return visit(s); }, e.u);
+  }
+
+  template 
+  static std::optional visit(const Expr &e) {
+return std::visit([](auto &&s) { return visit(s); }, e.u);
+  }
+};
+
+template 
+std::optional ExtractSubstring(const A &x) {
+  return ExtractSubstringHelper::visit(x);
+}
+
 // If an expression is simply a whole symbol data designator,
 // extract and return that symbol, else null.
 template  const Symbol *UnwrapWholeSymbolDataRef(const A &x) {
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index d7a93db15a4bb8..4b21ab934c9393 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -72,9 +72,9 @@ getOmpObjectSymbol(const Fortran::parser::OmpObject 
&ompObject) {
   return sym;
 }
 
-static void genObjectList(const Fortran::parser::OmpObjectList &objectList,
-  Fortran::lower::AbstractConverter &converter,
-  llvm::SmallVectorImpl &operands) {
+static void genObjectList2(const Fortran::parser::OmpObjectList &objectList,
+   Fortran::lower::AbstractConverter &converter,
+   llvm::SmallVectorImpl &operands) {
   auto addOperands = [&](Fortran::lower::SymbolRef sym) {
 const mlir::Value variable = converter.getSymbolAddress(sym);
 if (variable) {
@@ -93,27 +93,6 @@ static void genObjectList(const 
Fortran::parser::OmpObjectList &objectList,
   }
 }
 
-static void gatherFuncAndVarSyms(
-const Fortran::parser::OmpObjectList &objList,
-mlir::omp::DeclareTargetCaptureClause clause,
-llvm::SmallVectorImpl &symbolAndClause) {
-  for (const Fortran::parser::OmpObject &ompObject : objList.v) {
-Fortran::common::visit(
-Fortran::common::visitors{
-[&](const Fortran::parser::Designator &designator) {
-  if (const Fortran::parser::Name *name =
-  Fortran::semantics::getDesignatorNameIfDataRef(
-  designator)) {
-symbolAndClause.emplace_back(clause, *name->symbol);
-  }
-},
-[&](const Fortran::parser::Name &name) {
-  symbolAndClause.emplace_back(clause, *name.symbol);
-}},
-ompObject.u);
-  }
-}
-
 static Fortran::lower::pft::Evaluation *
 getCollapsedLoopEval(Fortran::lower::pft::Evaluation &eval, int collapseValue) 
{
   // Return the Evaluation of the innermost collapsed loop, or the current one
@@ -1257,6 +1236,32 @@ List makeList(const parser::OmpClauseList 
&clauses,
 }
 } // namespace omp
 
+static void genObjectList(const omp::ObjectList &objects,
+  Fortran::lower::AbstractConverter &converter,
+  llvm::SmallVectorImpl &operands) {
+  for (const omp::Object &object : objects) {
+const Fortran::semantics::Symbol *sym = object.sym;
+assert(sym && "Expected Symbol");
+if (mlir::Value variable = converter.getSymbolAddress(*sym)) {
+  operands.push_back(variable);
+} else {
+  if (const auto *details =
+  sym->detailsIf()) {
+operands.push_back(converter.getSymbolAddress(details->symbol()));
+converter.copySymbolBinding(details->symbol(), *sym);
+  }
+}
+  }
+}
+
+static void gatherFuncAndVarSyms(
+const omp::ObjectList &objects,
+mlir::omp::DeclareTargetCaptureClause clause,
+llvm::SmallVectorImpl &symbolAndClause) {
+  for (const omp::Object &object : objects)
+symbolAndClause.emplace_b

[llvm-branch-commits] [flang] [flang][OpenMP] Convert repeatable clauses (except Map) in ClauseProc… (PR #81623)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)


Changes

…essor

Rename `findRepeatableClause` to `findRepeatableClause2`, and make the new 
`findRepeatableClause` operate on new `omp::Clause` objects.

Leave `Map` unchanged, because it will require more changes for it to work.

---

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


2 Files Affected:

- (modified) flang/include/flang/Evaluate/tools.h (+23) 
- (modified) flang/lib/Lower/OpenMP.cpp (+305-327) 


``diff
diff --git a/flang/include/flang/Evaluate/tools.h 
b/flang/include/flang/Evaluate/tools.h
index d257da1a709642..e974944e88 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -430,6 +430,29 @@ template  std::optional 
ExtractCoarrayRef(const A &x) {
   }
 }
 
+struct ExtractSubstringHelper {
+  template  static std::optional visit(T &&) {
+return std::nullopt;
+  }
+
+  static std::optional visit(const Substring &e) { return e; }
+
+  template 
+  static std::optional visit(const Designator &e) {
+return std::visit([](auto &&s) { return visit(s); }, e.u);
+  }
+
+  template 
+  static std::optional visit(const Expr &e) {
+return std::visit([](auto &&s) { return visit(s); }, e.u);
+  }
+};
+
+template 
+std::optional ExtractSubstring(const A &x) {
+  return ExtractSubstringHelper::visit(x);
+}
+
 // If an expression is simply a whole symbol data designator,
 // extract and return that symbol, else null.
 template  const Symbol *UnwrapWholeSymbolDataRef(const A &x) {
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index d7a93db15a4bb8..4b21ab934c9393 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -72,9 +72,9 @@ getOmpObjectSymbol(const Fortran::parser::OmpObject 
&ompObject) {
   return sym;
 }
 
-static void genObjectList(const Fortran::parser::OmpObjectList &objectList,
-  Fortran::lower::AbstractConverter &converter,
-  llvm::SmallVectorImpl &operands) {
+static void genObjectList2(const Fortran::parser::OmpObjectList &objectList,
+   Fortran::lower::AbstractConverter &converter,
+   llvm::SmallVectorImpl &operands) {
   auto addOperands = [&](Fortran::lower::SymbolRef sym) {
 const mlir::Value variable = converter.getSymbolAddress(sym);
 if (variable) {
@@ -93,27 +93,6 @@ static void genObjectList(const 
Fortran::parser::OmpObjectList &objectList,
   }
 }
 
-static void gatherFuncAndVarSyms(
-const Fortran::parser::OmpObjectList &objList,
-mlir::omp::DeclareTargetCaptureClause clause,
-llvm::SmallVectorImpl &symbolAndClause) {
-  for (const Fortran::parser::OmpObject &ompObject : objList.v) {
-Fortran::common::visit(
-Fortran::common::visitors{
-[&](const Fortran::parser::Designator &designator) {
-  if (const Fortran::parser::Name *name =
-  Fortran::semantics::getDesignatorNameIfDataRef(
-  designator)) {
-symbolAndClause.emplace_back(clause, *name->symbol);
-  }
-},
-[&](const Fortran::parser::Name &name) {
-  symbolAndClause.emplace_back(clause, *name.symbol);
-}},
-ompObject.u);
-  }
-}
-
 static Fortran::lower::pft::Evaluation *
 getCollapsedLoopEval(Fortran::lower::pft::Evaluation &eval, int collapseValue) 
{
   // Return the Evaluation of the innermost collapsed loop, or the current one
@@ -1257,6 +1236,32 @@ List makeList(const parser::OmpClauseList 
&clauses,
 }
 } // namespace omp
 
+static void genObjectList(const omp::ObjectList &objects,
+  Fortran::lower::AbstractConverter &converter,
+  llvm::SmallVectorImpl &operands) {
+  for (const omp::Object &object : objects) {
+const Fortran::semantics::Symbol *sym = object.sym;
+assert(sym && "Expected Symbol");
+if (mlir::Value variable = converter.getSymbolAddress(*sym)) {
+  operands.push_back(variable);
+} else {
+  if (const auto *details =
+  sym->detailsIf()) {
+operands.push_back(converter.getSymbolAddress(details->symbol()));
+converter.copySymbolBinding(details->symbol(), *sym);
+  }
+}
+  }
+}
+
+static void gatherFuncAndVarSyms(
+const omp::ObjectList &objects,
+mlir::omp::DeclareTargetCaptureClause clause,
+llvm::SmallVectorImpl &symbolAndClause) {
+  for (const omp::Object &object : objects)
+symbolAndClause.emplace_back(clause, *object.sym);
+}
+
 
//===--===//
 // DataSharingProcessor
 
//===--===//
@@ -1718,9 +1723,8 @@ class ClauseProcessor {
  llvm::SmallVectorImpl &dependOperands) con

[llvm-branch-commits] [flang] [flang][Lower] Convert OMP Map and related functions to evaluate::Expr (PR #81626)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

The related functions are `gatherDataOperandAddrAndBounds` and `genBoundsOps`. 
The former is used in OpenACC as well, and it was updated to pass 
evaluate::Expr instead of parser objects.

The difference in the test case comes from unfolded conversions of index 
expressions, which are explicitly of type integer(kind=8).

Delete now unused `findRepeatableClause2` and `findClause2`.

Add `AsGenericExpr` that takes std::optional. It already returns optional Expr. 
Making it accept an optional Expr as input would reduce the number of necessary 
checks when handling frequent optional values in evaluator.

>From f4ed9e51d5f3d0d8c56a569b15299011653dd22f Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Thu, 8 Feb 2024 08:33:40 -0600
Subject: [PATCH] [flang][Lower] Convert OMP Map and related functions to
 evaluate::Expr

The related functions are `gatherDataOperandAddrAndBounds` and
`genBoundsOps`. The former is used in OpenACC as well, and it was
updated to pass evaluate::Expr instead of parser objects.

The difference in the test case comes from unfolded conversions
of index expressions, which are explicitly of type integer(kind=8).

Delete now unused `findRepeatableClause2` and `findClause2`.

Add `AsGenericExpr` that takes std::optional. It already returns optional
Expr. Making it accept an optional Expr as input would reduce the number
of necessary checks when handling frequent optional values in evaluator.
---
 flang/include/flang/Evaluate/tools.h |   8 +
 flang/lib/Lower/DirectivesCommon.h   | 389 ---
 flang/lib/Lower/OpenACC.cpp  |  54 ++--
 flang/lib/Lower/OpenMP.cpp   | 105 +++-
 4 files changed, 311 insertions(+), 245 deletions(-)

diff --git a/flang/include/flang/Evaluate/tools.h 
b/flang/include/flang/Evaluate/tools.h
index e974944e88..d5713cfe420a2e 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -148,6 +148,14 @@ inline Expr AsGenericExpr(Expr &&x) { 
return std::move(x); }
 std::optional> AsGenericExpr(DataRef &&);
 std::optional> AsGenericExpr(const Symbol &);
 
+// Propagate std::optional from input to output.
+template 
+std::optional> AsGenericExpr(std::optional &&x) {
+  if (!x)
+return std::nullopt;
+  return AsGenericExpr(std::move(*x));
+}
+
 template 
 common::IfNoLvalue::category>>, A> AsCategoryExpr(
 A &&x) {
diff --git a/flang/lib/Lower/DirectivesCommon.h 
b/flang/lib/Lower/DirectivesCommon.h
index 8d560db34e05bf..2fa90572bc63eb 100644
--- a/flang/lib/Lower/DirectivesCommon.h
+++ b/flang/lib/Lower/DirectivesCommon.h
@@ -808,6 +808,75 @@ genBaseBoundsOps(fir::FirOpBuilder &builder, 
mlir::Location loc,
   return bounds;
 }
 
+namespace detail {
+template  //
+static T &&AsRvalueRef(T &&t) {
+  return std::move(t);
+}
+template  //
+static T AsRvalueRef(T &t) {
+  return t;
+}
+template  //
+static T AsRvalueRef(const T &t) {
+  return t;
+}
+
+// Helper class for stripping enclosing parentheses and a conversion that
+// preserves type category. This is used for triplet elements, which are
+// always of type integer(kind=8). The lower/upper bounds are converted to
+// an "index" type, which is 64-bit, so the explicit conversion to kind=8
+// (if present) is not needed. When it's present, though, it causes generated
+// names to contain "int(..., kind=8)".
+struct PeelConvert {
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(
+  const Fortran::evaluate::Expr>
+  &expr) {
+return std::visit(
+[](auto &&s) { return visit_with_category(s); },
+expr.u);
+  }
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(
+  const Fortran::evaluate::Convert,
+   Category> &expr) {
+return AsGenericExpr(AsRvalueRef(expr.left()));
+  }
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(const T &) {
+return std::nullopt; //
+  }
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(const T &) {
+return std::nullopt; //
+  }
+
+  template 
+  static Fortran::semantics::MaybeExpr
+  visit(const Fortran::evaluate::Expr>
+&expr) {
+return std::visit([](auto &&s) { return visit_with_category(s); 
},
+  expr.u);
+  }
+  static Fortran::semantics::MaybeExpr
+  visit(const Fortran::evaluate::Expr &expr) {
+return std::visit([](auto &&s) { return visit(s); }, expr.u);
+  }
+  template  //
+  static Fortran::semantics::MaybeExpr visit(const T &) {
+return std::nullopt;
+  }
+};
+
+static Fortran::semantics::SomeExpr
+peelOuterConvert(Fortran::semantics::SomeExpr &expr) {
+  if (auto peeled = PeelConvert::visit(expr))
+return *peeled;
+  return expr;
+}
+} // namespace detail
+
 /// Generate bounds operations for an array section when subscripts are
 /// provided.
 template 
@@ -815,7 +884,7 @@ llvm::Small

[llvm-branch-commits] [flang] [flang][Lower] Convert OMP Map and related functions to evaluate::Expr (PR #81626)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-openacc

Author: Krzysztof Parzyszek (kparzysz)


Changes

The related functions are `gatherDataOperandAddrAndBounds` and `genBoundsOps`. 
The former is used in OpenACC as well, and it was updated to pass 
evaluate::Expr instead of parser objects.

The difference in the test case comes from unfolded conversions of index 
expressions, which are explicitly of type integer(kind=8).

Delete now unused `findRepeatableClause2` and `findClause2`.

Add `AsGenericExpr` that takes std::optional. It already returns optional Expr. 
Making it accept an optional Expr as input would reduce the number of necessary 
checks when handling frequent optional values in evaluator.

---

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


4 Files Affected:

- (modified) flang/include/flang/Evaluate/tools.h (+8) 
- (modified) flang/lib/Lower/DirectivesCommon.h (+235-154) 
- (modified) flang/lib/Lower/OpenACC.cpp (+35-19) 
- (modified) flang/lib/Lower/OpenMP.cpp (+33-72) 


``diff
diff --git a/flang/include/flang/Evaluate/tools.h 
b/flang/include/flang/Evaluate/tools.h
index e974944e88..d5713cfe420a2e 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -148,6 +148,14 @@ inline Expr AsGenericExpr(Expr &&x) { 
return std::move(x); }
 std::optional> AsGenericExpr(DataRef &&);
 std::optional> AsGenericExpr(const Symbol &);
 
+// Propagate std::optional from input to output.
+template 
+std::optional> AsGenericExpr(std::optional &&x) {
+  if (!x)
+return std::nullopt;
+  return AsGenericExpr(std::move(*x));
+}
+
 template 
 common::IfNoLvalue::category>>, A> AsCategoryExpr(
 A &&x) {
diff --git a/flang/lib/Lower/DirectivesCommon.h 
b/flang/lib/Lower/DirectivesCommon.h
index 8d560db34e05bf..2fa90572bc63eb 100644
--- a/flang/lib/Lower/DirectivesCommon.h
+++ b/flang/lib/Lower/DirectivesCommon.h
@@ -808,6 +808,75 @@ genBaseBoundsOps(fir::FirOpBuilder &builder, 
mlir::Location loc,
   return bounds;
 }
 
+namespace detail {
+template  //
+static T &&AsRvalueRef(T &&t) {
+  return std::move(t);
+}
+template  //
+static T AsRvalueRef(T &t) {
+  return t;
+}
+template  //
+static T AsRvalueRef(const T &t) {
+  return t;
+}
+
+// Helper class for stripping enclosing parentheses and a conversion that
+// preserves type category. This is used for triplet elements, which are
+// always of type integer(kind=8). The lower/upper bounds are converted to
+// an "index" type, which is 64-bit, so the explicit conversion to kind=8
+// (if present) is not needed. When it's present, though, it causes generated
+// names to contain "int(..., kind=8)".
+struct PeelConvert {
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(
+  const Fortran::evaluate::Expr>
+  &expr) {
+return std::visit(
+[](auto &&s) { return visit_with_category(s); },
+expr.u);
+  }
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(
+  const Fortran::evaluate::Convert,
+   Category> &expr) {
+return AsGenericExpr(AsRvalueRef(expr.left()));
+  }
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(const T &) {
+return std::nullopt; //
+  }
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(const T &) {
+return std::nullopt; //
+  }
+
+  template 
+  static Fortran::semantics::MaybeExpr
+  visit(const Fortran::evaluate::Expr>
+&expr) {
+return std::visit([](auto &&s) { return visit_with_category(s); 
},
+  expr.u);
+  }
+  static Fortran::semantics::MaybeExpr
+  visit(const Fortran::evaluate::Expr &expr) {
+return std::visit([](auto &&s) { return visit(s); }, expr.u);
+  }
+  template  //
+  static Fortran::semantics::MaybeExpr visit(const T &) {
+return std::nullopt;
+  }
+};
+
+static Fortran::semantics::SomeExpr
+peelOuterConvert(Fortran::semantics::SomeExpr &expr) {
+  if (auto peeled = PeelConvert::visit(expr))
+return *peeled;
+  return expr;
+}
+} // namespace detail
+
 /// Generate bounds operations for an array section when subscripts are
 /// provided.
 template 
@@ -815,7 +884,7 @@ llvm::SmallVector
 genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
  Fortran::lower::AbstractConverter &converter,
  Fortran::lower::StatementContext &stmtCtx,
- const std::list &subscripts,
+ const std::vector &subscripts,
  std::stringstream &asFortran, fir::ExtendedValue &dataExv,
  bool dataExvIsAssumedSize, AddrAndBoundsInfo &info,
  bool treatIndexAsSection = false) {
@@ -828,8 +897,7 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
   mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1);
   const int dataExvRank = static_cast(dataExv.rank());
   for (const

[llvm-branch-commits] [flang] [flang][OpenMP] Convert processTODO and remove unused objects (PR #81627)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

Remove `ClauseIterator2` and `clauses2` from ClauseProcessor.

[Clause representation 5/6]

>From 2e0088679635755536125a60de7508b6abcbf790 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Fri, 9 Feb 2024 15:03:54 -0600
Subject: [PATCH] [flang][OpenMP] Convert processTODO and remove unused objects

Remove `ClauseIterator2` and `clauses2` from ClauseProcessor.
---
 flang/lib/Lower/OpenMP.cpp | 75 ++
 1 file changed, 28 insertions(+), 47 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 7cf8fcc0a3d274..8dcd0708e6245c 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -1668,13 +1668,11 @@ void DataSharingProcessor::defaultPrivatize() {
 /// methods that relate to clauses that can impact the lowering of that
 /// construct.
 class ClauseProcessor {
-  using ClauseTy = Fortran::parser::OmpClause;
-
 public:
   ClauseProcessor(Fortran::lower::AbstractConverter &converter,
   Fortran::semantics::SemanticsContext &semaCtx,
   const Fortran::parser::OmpClauseList &clauses)
-  : converter(converter), semaCtx(semaCtx), clauses2(clauses),
+  : converter(converter), semaCtx(semaCtx),
 clauses(omp::makeList(clauses, semaCtx)) {}
 
   // 'Unique' clauses: They can appear at most once in the clause list.
@@ -1775,7 +1773,6 @@ class ClauseProcessor {
 
 private:
   using ClauseIterator = omp::List::const_iterator;
-  using ClauseIterator2 = std::list::const_iterator;
 
   /// Utility to find a clause within a range in the clause list.
   template 
@@ -1835,7 +1832,6 @@ class ClauseProcessor {
 
   Fortran::lower::AbstractConverter &converter;
   Fortran::semantics::SemanticsContext &semaCtx;
-  const Fortran::parser::OmpClauseList &clauses2;
   omp::List clauses;
 };
 
@@ -3131,19 +3127,17 @@ bool ClauseProcessor::processMotionClauses(
 template 
 void ClauseProcessor::processTODO(mlir::Location currentLocation,
   llvm::omp::Directive directive) const {
-  auto checkUnhandledClause = [&](const auto *x) {
+  auto checkUnhandledClause = [&](llvm::omp::Clause id, const auto *x) {
 if (!x)
   return;
 TODO(currentLocation,
- "Unhandled clause " +
- llvm::StringRef(Fortran::parser::ParseTreeDumper::GetNodeName(*x))
- .upper() +
+ "Unhandled clause " + llvm::omp::getOpenMPClauseName(id).upper() +
  " in " + llvm::omp::getOpenMPDirectiveName(directive).upper() +
  " construct");
   };
 
-  for (ClauseIterator2 it = clauses2.v.begin(); it != clauses2.v.end(); ++it)
-(checkUnhandledClause(std::get_if(&it->u)), ...);
+  for (ClauseIterator it = clauses.begin(); it != clauses.end(); ++it)
+(checkUnhandledClause(it->id, std::get_if(&it->u)), ...);
 }
 
 
//===--===//
@@ -3722,8 +3716,8 @@ genSingleOp(Fortran::lower::AbstractConverter &converter,
 
   ClauseProcessor cp(converter, semaCtx, beginClauseList);
   cp.processAllocate(allocatorOperands, allocateOperands);
-  cp.processTODO(
-  currentLocation, llvm::omp::Directive::OMPD_single);
+  cp.processTODO(currentLocation,
+   llvm::omp::Directive::OMPD_single);
 
   ClauseProcessor(converter, semaCtx, endClauseList).processNowait(nowaitAttr);
 
@@ -3756,10 +3750,9 @@ genTaskOp(Fortran::lower::AbstractConverter &converter,
   cp.processMergeable(mergeableAttr);
   cp.processPriority(stmtCtx, priorityClauseOperand);
   cp.processDepend(dependTypeOperands, dependOperands);
-  cp.processTODO(
-  currentLocation, llvm::omp::Directive::OMPD_task);
+  cp.processTODO(currentLocation,
+llvm::omp::Directive::OMPD_task);
 
   return genOpWithBody(
   OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
@@ -3784,7 +3777,7 @@ genTaskGroupOp(Fortran::lower::AbstractConverter 
&converter,
   llvm::SmallVector allocateOperands, allocatorOperands;
   ClauseProcessor cp(converter, semaCtx, clauseList);
   cp.processAllocate(allocatorOperands, allocateOperands);
-  cp.processTODO(
+  cp.processTODO(
   currentLocation, llvm::omp::Directive::OMPD_taskgroup);
   return genOpWithBody(
   OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
@@ -3868,8 +3861,7 @@ 
genEnterExitUpdateDataOp(Fortran::lower::AbstractConverter &converter,
 cp.processMap(currentLocation, directive, stmtCtx, mapOperands);
   }
 
-  cp.processTODO(currentLocation,
- directive);
+  cp.processTODO(currentLocation, directive);
 
   return firOpBuilder.create(currentLocation, ifClauseOperand,
deviceOperand, nullptr, mlir::ValueRange(),
@@ -4052,16 +4044,11 @@ genTargetOp(Fortran::lower::AbstractConverter 
&c

[llvm-branch-commits] [flang] [flang][OpenMP] Convert processTODO and remove unused objects (PR #81627)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:



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

@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)


Changes

Remove `ClauseIterator2` and `clauses2` from ClauseProcessor.

[Clause representation 5/6]

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


1 Files Affected:

- (modified) flang/lib/Lower/OpenMP.cpp (+28-47) 


``diff
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 7cf8fcc0a3d27..8dcd0708e6245 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -1668,13 +1668,11 @@ void DataSharingProcessor::defaultPrivatize() {
 /// methods that relate to clauses that can impact the lowering of that
 /// construct.
 class ClauseProcessor {
-  using ClauseTy = Fortran::parser::OmpClause;
-
 public:
   ClauseProcessor(Fortran::lower::AbstractConverter &converter,
   Fortran::semantics::SemanticsContext &semaCtx,
   const Fortran::parser::OmpClauseList &clauses)
-  : converter(converter), semaCtx(semaCtx), clauses2(clauses),
+  : converter(converter), semaCtx(semaCtx),
 clauses(omp::makeList(clauses, semaCtx)) {}
 
   // 'Unique' clauses: They can appear at most once in the clause list.
@@ -1775,7 +1773,6 @@ class ClauseProcessor {
 
 private:
   using ClauseIterator = omp::List::const_iterator;
-  using ClauseIterator2 = std::list::const_iterator;
 
   /// Utility to find a clause within a range in the clause list.
   template 
@@ -1835,7 +1832,6 @@ class ClauseProcessor {
 
   Fortran::lower::AbstractConverter &converter;
   Fortran::semantics::SemanticsContext &semaCtx;
-  const Fortran::parser::OmpClauseList &clauses2;
   omp::List clauses;
 };
 
@@ -3131,19 +3127,17 @@ bool ClauseProcessor::processMotionClauses(
 template 
 void ClauseProcessor::processTODO(mlir::Location currentLocation,
   llvm::omp::Directive directive) const {
-  auto checkUnhandledClause = [&](const auto *x) {
+  auto checkUnhandledClause = [&](llvm::omp::Clause id, const auto *x) {
 if (!x)
   return;
 TODO(currentLocation,
- "Unhandled clause " +
- llvm::StringRef(Fortran::parser::ParseTreeDumper::GetNodeName(*x))
- .upper() +
+ "Unhandled clause " + llvm::omp::getOpenMPClauseName(id).upper() +
  " in " + llvm::omp::getOpenMPDirectiveName(directive).upper() +
  " construct");
   };
 
-  for (ClauseIterator2 it = clauses2.v.begin(); it != clauses2.v.end(); ++it)
-(checkUnhandledClause(std::get_if(&it->u)), ...);
+  for (ClauseIterator it = clauses.begin(); it != clauses.end(); ++it)
+(checkUnhandledClause(it->id, std::get_if(&it->u)), ...);
 }
 
 
//===--===//
@@ -3722,8 +3716,8 @@ genSingleOp(Fortran::lower::AbstractConverter &converter,
 
   ClauseProcessor cp(converter, semaCtx, beginClauseList);
   cp.processAllocate(allocatorOperands, allocateOperands);
-  cp.processTODO(
-  currentLocation, llvm::omp::Directive::OMPD_single);
+  cp.processTODO(currentLocation,
+   llvm::omp::Directive::OMPD_single);
 
   ClauseProcessor(converter, semaCtx, endClauseList).processNowait(nowaitAttr);
 
@@ -3756,10 +3750,9 @@ genTaskOp(Fortran::lower::AbstractConverter &converter,
   cp.processMergeable(mergeableAttr);
   cp.processPriority(stmtCtx, priorityClauseOperand);
   cp.processDepend(dependTypeOperands, dependOperands);
-  cp.processTODO(
-  currentLocation, llvm::omp::Directive::OMPD_task);
+  cp.processTODO(currentLocation,
+llvm::omp::Directive::OMPD_task);
 
   return genOpWithBody(
   OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
@@ -3784,7 +3777,7 @@ genTaskGroupOp(Fortran::lower::AbstractConverter 
&converter,
   llvm::SmallVector allocateOperands, allocatorOperands;
   ClauseProcessor cp(converter, semaCtx, clauseList);
   cp.processAllocate(allocatorOperands, allocateOperands);
-  cp.processTODO(
+  cp.processTODO(
   currentLocation, llvm::omp::Directive::OMPD_taskgroup);
   return genOpWithBody(
   OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
@@ -3868,8 +3861,7 @@ 
genEnterExitUpdateDataOp(Fortran::lower::AbstractConverter &converter,
 cp.processMap(currentLocation, directive, stmtCtx, mapOperands);
   }
 
-  cp.processTODO(currentLocation,
- directive);
+  cp.processTODO(currentLocation, directive);
 
   return firOpBuilder.create(currentLocation, ifClauseOperand,
deviceOperand, nullptr, mlir::ValueRange(),
@@ -4052,16 +4044,11 @@ genTargetOp(Fortran::lower::AbstractConverter 
&converter,
   cp.processNowait(nowaitAttr);
   cp.processMap(currentLocation, directive, stmtCtx, mapOperands, &mapSymTypes,
 &mapSymLocs, &mapSymbols);
-  cp.processTODO(
+  cp.proc

[llvm-branch-commits] [flang] [flang][OpenMP] Convert DataSharingProcessor to omp::Clause (PR #81629)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

[Clause representation 6/6]

>From c5adb1dee4fdc31fe56390109db79d2551069a3e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Sat, 10 Feb 2024 08:50:48 -0600
Subject: [PATCH] [flang][OpenMP] Convert DataSharingProcessor to omp::Clause

---
 flang/lib/Lower/OpenMP.cpp | 303 ++---
 1 file changed, 149 insertions(+), 154 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 8dcd0708e6245c..88402828053e63 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -1277,14 +1277,15 @@ class DataSharingProcessor {
   llvm::SetVector symbolsInNestedRegions;
   llvm::SetVector symbolsInParentRegions;
   Fortran::lower::AbstractConverter &converter;
+  Fortran::semantics::SemanticsContext &semaCtx;
   fir::FirOpBuilder &firOpBuilder;
-  const Fortran::parser::OmpClauseList &opClauseList;
+  omp::List clauses;
   Fortran::lower::pft::Evaluation &eval;
 
   bool needBarrier();
   void collectSymbols(Fortran::semantics::Symbol::Flag flag);
   void collectOmpObjectListSymbol(
-  const Fortran::parser::OmpObjectList &ompObjectList,
+  const omp::ObjectList &objects,
   llvm::SetVector &symbolSet);
   void collectSymbolsForPrivatization();
   void insertBarrier();
@@ -1301,11 +1302,12 @@ class DataSharingProcessor {
 
 public:
   DataSharingProcessor(Fortran::lower::AbstractConverter &converter,
+   Fortran::semantics::SemanticsContext &semaCtx,
const Fortran::parser::OmpClauseList &opClauseList,
Fortran::lower::pft::Evaluation &eval)
-  : hasLastPrivateOp(false), converter(converter),
-firOpBuilder(converter.getFirOpBuilder()), opClauseList(opClauseList),
-eval(eval) {}
+  : hasLastPrivateOp(false), converter(converter), semaCtx(semaCtx),
+firOpBuilder(converter.getFirOpBuilder()),
+clauses(omp::makeList(opClauseList, semaCtx)), eval(eval) {}
   // Privatisation is split into two steps.
   // Step1 performs cloning of all privatisation clauses and copying for
   // firstprivates. Step1 is performed at the place where process/processStep1
@@ -1383,30 +1385,28 @@ void DataSharingProcessor::copyLastPrivateSymbol(
 }
 
 void DataSharingProcessor::collectOmpObjectListSymbol(
-const Fortran::parser::OmpObjectList &ompObjectList,
+const omp::ObjectList &objects,
 llvm::SetVector &symbolSet) {
-  for (const Fortran::parser::OmpObject &ompObject : ompObjectList.v) {
-Fortran::semantics::Symbol *sym = getOmpObjectSymbol(ompObject);
+  for (const omp::Object &object : objects) {
+Fortran::semantics::Symbol *sym = object.sym;
 symbolSet.insert(sym);
   }
 }
 
 void DataSharingProcessor::collectSymbolsForPrivatization() {
   bool hasCollapse = false;
-  for (const Fortran::parser::OmpClause &clause : opClauseList.v) {
+  for (const omp::Clause &clause : clauses) {
 if (const auto &privateClause =
-std::get_if(&clause.u)) {
+std::get_if(&clause.u)) {
   collectOmpObjectListSymbol(privateClause->v, privatizedSymbols);
 } else if (const auto &firstPrivateClause =
-   std::get_if(
-   &clause.u)) {
+   std::get_if(&clause.u)) {
   collectOmpObjectListSymbol(firstPrivateClause->v, privatizedSymbols);
 } else if (const auto &lastPrivateClause =
-   std::get_if(
-   &clause.u)) {
+   std::get_if(&clause.u)) {
   collectOmpObjectListSymbol(lastPrivateClause->v, privatizedSymbols);
   hasLastPrivateOp = true;
-} else if (std::get_if(&clause.u)) {
+} else if (std::get_if(&clause.u)) {
   hasCollapse = true;
 }
   }
@@ -1439,138 +1439,135 @@ void DataSharingProcessor::insertBarrier() {
 void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
   bool cmpCreated = false;
   mlir::OpBuilder::InsertPoint localInsPt = firOpBuilder.saveInsertionPoint();
-  for (const Fortran::parser::OmpClause &clause : opClauseList.v) {
-if (std::get_if(&clause.u)) {
-  // TODO: Add lastprivate support for simd construct
-  if (mlir::isa(op)) {
-if (&eval == &eval.parentConstruct->getLastNestedEvaluation()) {
-  // For `omp.sections`, lastprivatized variables occur in
-  // lexically final `omp.section` operation. The following FIR
-  // shall be generated for the same:
-  //
-  // omp.sections lastprivate(...) {
-  //  omp.section {...}
-  //  omp.section {...}
-  //  omp.section {
-  //  fir.allocate for `private`/`firstprivate`
-  //  
-  //  fir.if %true {
-  //  ^%lpv_update_blk
-  //  }
-  //  }
-  // }
-  //
-  // To keep code consistency while handling privatization
- 

[llvm-branch-commits] [flang] [flang][OpenMP] Convert DataSharingProcessor to omp::Clause (PR #81629)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)


Changes

[Clause representation 6/6]

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


1 Files Affected:

- (modified) flang/lib/Lower/OpenMP.cpp (+149-154) 


``diff
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 8dcd0708e6245..88402828053e6 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -1277,14 +1277,15 @@ class DataSharingProcessor {
   llvm::SetVector symbolsInNestedRegions;
   llvm::SetVector symbolsInParentRegions;
   Fortran::lower::AbstractConverter &converter;
+  Fortran::semantics::SemanticsContext &semaCtx;
   fir::FirOpBuilder &firOpBuilder;
-  const Fortran::parser::OmpClauseList &opClauseList;
+  omp::List clauses;
   Fortran::lower::pft::Evaluation &eval;
 
   bool needBarrier();
   void collectSymbols(Fortran::semantics::Symbol::Flag flag);
   void collectOmpObjectListSymbol(
-  const Fortran::parser::OmpObjectList &ompObjectList,
+  const omp::ObjectList &objects,
   llvm::SetVector &symbolSet);
   void collectSymbolsForPrivatization();
   void insertBarrier();
@@ -1301,11 +1302,12 @@ class DataSharingProcessor {
 
 public:
   DataSharingProcessor(Fortran::lower::AbstractConverter &converter,
+   Fortran::semantics::SemanticsContext &semaCtx,
const Fortran::parser::OmpClauseList &opClauseList,
Fortran::lower::pft::Evaluation &eval)
-  : hasLastPrivateOp(false), converter(converter),
-firOpBuilder(converter.getFirOpBuilder()), opClauseList(opClauseList),
-eval(eval) {}
+  : hasLastPrivateOp(false), converter(converter), semaCtx(semaCtx),
+firOpBuilder(converter.getFirOpBuilder()),
+clauses(omp::makeList(opClauseList, semaCtx)), eval(eval) {}
   // Privatisation is split into two steps.
   // Step1 performs cloning of all privatisation clauses and copying for
   // firstprivates. Step1 is performed at the place where process/processStep1
@@ -1383,30 +1385,28 @@ void DataSharingProcessor::copyLastPrivateSymbol(
 }
 
 void DataSharingProcessor::collectOmpObjectListSymbol(
-const Fortran::parser::OmpObjectList &ompObjectList,
+const omp::ObjectList &objects,
 llvm::SetVector &symbolSet) {
-  for (const Fortran::parser::OmpObject &ompObject : ompObjectList.v) {
-Fortran::semantics::Symbol *sym = getOmpObjectSymbol(ompObject);
+  for (const omp::Object &object : objects) {
+Fortran::semantics::Symbol *sym = object.sym;
 symbolSet.insert(sym);
   }
 }
 
 void DataSharingProcessor::collectSymbolsForPrivatization() {
   bool hasCollapse = false;
-  for (const Fortran::parser::OmpClause &clause : opClauseList.v) {
+  for (const omp::Clause &clause : clauses) {
 if (const auto &privateClause =
-std::get_if(&clause.u)) {
+std::get_if(&clause.u)) {
   collectOmpObjectListSymbol(privateClause->v, privatizedSymbols);
 } else if (const auto &firstPrivateClause =
-   std::get_if(
-   &clause.u)) {
+   std::get_if(&clause.u)) {
   collectOmpObjectListSymbol(firstPrivateClause->v, privatizedSymbols);
 } else if (const auto &lastPrivateClause =
-   std::get_if(
-   &clause.u)) {
+   std::get_if(&clause.u)) {
   collectOmpObjectListSymbol(lastPrivateClause->v, privatizedSymbols);
   hasLastPrivateOp = true;
-} else if (std::get_if(&clause.u)) {
+} else if (std::get_if(&clause.u)) {
   hasCollapse = true;
 }
   }
@@ -1439,138 +1439,135 @@ void DataSharingProcessor::insertBarrier() {
 void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
   bool cmpCreated = false;
   mlir::OpBuilder::InsertPoint localInsPt = firOpBuilder.saveInsertionPoint();
-  for (const Fortran::parser::OmpClause &clause : opClauseList.v) {
-if (std::get_if(&clause.u)) {
-  // TODO: Add lastprivate support for simd construct
-  if (mlir::isa(op)) {
-if (&eval == &eval.parentConstruct->getLastNestedEvaluation()) {
-  // For `omp.sections`, lastprivatized variables occur in
-  // lexically final `omp.section` operation. The following FIR
-  // shall be generated for the same:
-  //
-  // omp.sections lastprivate(...) {
-  //  omp.section {...}
-  //  omp.section {...}
-  //  omp.section {
-  //  fir.allocate for `private`/`firstprivate`
-  //  
-  //  fir.if %true {
-  //  ^%lpv_update_blk
-  //  }
-  //  }
-  // }
-  //
-  // To keep code consistency while handling privatization
-  // through this control flow, add a `fir.if` operation
-  // that always evaluates to true, in order to create
-  // a dedicated sub-region in `omp.sectio

[llvm-branch-commits] [flang] [flang][OpenMP] Convert repeatable clauses (except Map) in ClauseProc… (PR #81623)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/81623
___
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][Lower] Convert OMP Map and related functions to evaluate::Expr (PR #81626)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/81626
___
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] Convert processTODO and remove unused objects (PR #81627)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 1299d5190a3c273d2af4ab8c7f800af7df4e4ef6 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Fri, 9 Feb 2024 15:03:54 -0600
Subject: [PATCH] [flang][OpenMP] Convert processTODO and remove unused objects

Remove `ClauseIterator2` and `clauses2` from ClauseProcessor.
---
 flang/lib/Lower/OpenMP.cpp | 75 ++
 1 file changed, 28 insertions(+), 47 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 4309d69434839f..51ed0fe03dbe38 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -1669,13 +1669,11 @@ void DataSharingProcessor::defaultPrivatize() {
 /// methods that relate to clauses that can impact the lowering of that
 /// construct.
 class ClauseProcessor {
-  using ClauseTy = Fortran::parser::OmpClause;
-
 public:
   ClauseProcessor(Fortran::lower::AbstractConverter &converter,
   Fortran::semantics::SemanticsContext &semaCtx,
   const Fortran::parser::OmpClauseList &clauses)
-  : converter(converter), semaCtx(semaCtx), clauses2(clauses),
+  : converter(converter), semaCtx(semaCtx),
 clauses(omp::makeList(clauses, semaCtx)) {}
 
   // 'Unique' clauses: They can appear at most once in the clause list.
@@ -1776,7 +1774,6 @@ class ClauseProcessor {
 
 private:
   using ClauseIterator = omp::List::const_iterator;
-  using ClauseIterator2 = std::list::const_iterator;
 
   /// Utility to find a clause within a range in the clause list.
   template 
@@ -1836,7 +1833,6 @@ class ClauseProcessor {
 
   Fortran::lower::AbstractConverter &converter;
   Fortran::semantics::SemanticsContext &semaCtx;
-  const Fortran::parser::OmpClauseList &clauses2;
   omp::List clauses;
 };
 
@@ -3132,19 +3128,17 @@ bool ClauseProcessor::processMotionClauses(
 template 
 void ClauseProcessor::processTODO(mlir::Location currentLocation,
   llvm::omp::Directive directive) const {
-  auto checkUnhandledClause = [&](const auto *x) {
+  auto checkUnhandledClause = [&](llvm::omp::Clause id, const auto *x) {
 if (!x)
   return;
 TODO(currentLocation,
- "Unhandled clause " +
- llvm::StringRef(Fortran::parser::ParseTreeDumper::GetNodeName(*x))
- .upper() +
+ "Unhandled clause " + llvm::omp::getOpenMPClauseName(id).upper() +
  " in " + llvm::omp::getOpenMPDirectiveName(directive).upper() +
  " construct");
   };
 
-  for (ClauseIterator2 it = clauses2.v.begin(); it != clauses2.v.end(); ++it)
-(checkUnhandledClause(std::get_if(&it->u)), ...);
+  for (ClauseIterator it = clauses.begin(); it != clauses.end(); ++it)
+(checkUnhandledClause(it->id, std::get_if(&it->u)), ...);
 }
 
 
//===--===//
@@ -3723,8 +3717,8 @@ genSingleOp(Fortran::lower::AbstractConverter &converter,
 
   ClauseProcessor cp(converter, semaCtx, beginClauseList);
   cp.processAllocate(allocatorOperands, allocateOperands);
-  cp.processTODO(
-  currentLocation, llvm::omp::Directive::OMPD_single);
+  cp.processTODO(currentLocation,
+   llvm::omp::Directive::OMPD_single);
 
   ClauseProcessor(converter, semaCtx, endClauseList).processNowait(nowaitAttr);
 
@@ -3757,10 +3751,9 @@ genTaskOp(Fortran::lower::AbstractConverter &converter,
   cp.processMergeable(mergeableAttr);
   cp.processPriority(stmtCtx, priorityClauseOperand);
   cp.processDepend(dependTypeOperands, dependOperands);
-  cp.processTODO(
-  currentLocation, llvm::omp::Directive::OMPD_task);
+  cp.processTODO(currentLocation,
+llvm::omp::Directive::OMPD_task);
 
   return genOpWithBody(
   OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
@@ -3785,7 +3778,7 @@ genTaskGroupOp(Fortran::lower::AbstractConverter 
&converter,
   llvm::SmallVector allocateOperands, allocatorOperands;
   ClauseProcessor cp(converter, semaCtx, clauseList);
   cp.processAllocate(allocatorOperands, allocateOperands);
-  cp.processTODO(
+  cp.processTODO(
   currentLocation, llvm::omp::Directive::OMPD_taskgroup);
   return genOpWithBody(
   OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
@@ -3869,8 +3862,7 @@ 
genEnterExitUpdateDataOp(Fortran::lower::AbstractConverter &converter,
 cp.processMap(currentLocation, directive, stmtCtx, mapOperands);
   }
 
-  cp.processTODO(currentLocation,
- directive);
+  cp.processTODO(currentLocation, directive);
 
   return firOpBuilder.create(currentLocation, ifClauseOperand,
deviceOperand, nullptr, mlir::ValueRange(),
@@ -4053,16 +4045,11 @@ genTargetOp(Fortran::lower::AbstractConverter 
&converter,
   cp.processNowait(nowaitAttr);
   cp.processMap(currentLocation, directive, stmt

[llvm-branch-commits] [flang] [flang][OpenMP] Convert repeatable clauses (except Map) in ClauseProc… (PR #81623)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 841f10e44e5ec5cfc6b166421f878089a17c623c Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 6 Feb 2024 17:06:29 -0600
Subject: [PATCH] [flang][OpenMP] Convert repeatable clauses (except Map) in
 ClauseProcessor

Rename `findRepeatableClause` to `findRepeatableClause2`, and make the
new `findRepeatableClause` operate on new `omp::Clause` objects.

Leave `Map` unchanged, because it will require more changes for it to
work.
---
 flang/include/flang/Evaluate/tools.h |  23 +
 flang/lib/Lower/OpenMP.cpp   | 632 +--
 2 files changed, 328 insertions(+), 327 deletions(-)

diff --git a/flang/include/flang/Evaluate/tools.h 
b/flang/include/flang/Evaluate/tools.h
index d257da1a709642..e974944e88 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -430,6 +430,29 @@ template  std::optional 
ExtractCoarrayRef(const A &x) {
   }
 }
 
+struct ExtractSubstringHelper {
+  template  static std::optional visit(T &&) {
+return std::nullopt;
+  }
+
+  static std::optional visit(const Substring &e) { return e; }
+
+  template 
+  static std::optional visit(const Designator &e) {
+return std::visit([](auto &&s) { return visit(s); }, e.u);
+  }
+
+  template 
+  static std::optional visit(const Expr &e) {
+return std::visit([](auto &&s) { return visit(s); }, e.u);
+  }
+};
+
+template 
+std::optional ExtractSubstring(const A &x) {
+  return ExtractSubstringHelper::visit(x);
+}
+
 // If an expression is simply a whole symbol data designator,
 // extract and return that symbol, else null.
 template  const Symbol *UnwrapWholeSymbolDataRef(const A &x) {
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 4156887c8ff531..caae5c0cef9251 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -72,9 +72,9 @@ getOmpObjectSymbol(const Fortran::parser::OmpObject 
&ompObject) {
   return sym;
 }
 
-static void genObjectList(const Fortran::parser::OmpObjectList &objectList,
-  Fortran::lower::AbstractConverter &converter,
-  llvm::SmallVectorImpl &operands) {
+static void genObjectList2(const Fortran::parser::OmpObjectList &objectList,
+   Fortran::lower::AbstractConverter &converter,
+   llvm::SmallVectorImpl &operands) {
   auto addOperands = [&](Fortran::lower::SymbolRef sym) {
 const mlir::Value variable = converter.getSymbolAddress(sym);
 if (variable) {
@@ -93,27 +93,6 @@ static void genObjectList(const 
Fortran::parser::OmpObjectList &objectList,
   }
 }
 
-static void gatherFuncAndVarSyms(
-const Fortran::parser::OmpObjectList &objList,
-mlir::omp::DeclareTargetCaptureClause clause,
-llvm::SmallVectorImpl &symbolAndClause) {
-  for (const Fortran::parser::OmpObject &ompObject : objList.v) {
-Fortran::common::visit(
-Fortran::common::visitors{
-[&](const Fortran::parser::Designator &designator) {
-  if (const Fortran::parser::Name *name =
-  Fortran::semantics::getDesignatorNameIfDataRef(
-  designator)) {
-symbolAndClause.emplace_back(clause, *name->symbol);
-  }
-},
-[&](const Fortran::parser::Name &name) {
-  symbolAndClause.emplace_back(clause, *name.symbol);
-}},
-ompObject.u);
-  }
-}
-
 static Fortran::lower::pft::Evaluation *
 getCollapsedLoopEval(Fortran::lower::pft::Evaluation &eval, int collapseValue) 
{
   // Return the Evaluation of the innermost collapsed loop, or the current one
@@ -1258,6 +1237,32 @@ List makeList(const parser::OmpClauseList 
&clauses,
 }
 } // namespace omp
 
+static void genObjectList(const omp::ObjectList &objects,
+  Fortran::lower::AbstractConverter &converter,
+  llvm::SmallVectorImpl &operands) {
+  for (const omp::Object &object : objects) {
+const Fortran::semantics::Symbol *sym = object.sym;
+assert(sym && "Expected Symbol");
+if (mlir::Value variable = converter.getSymbolAddress(*sym)) {
+  operands.push_back(variable);
+} else {
+  if (const auto *details =
+  sym->detailsIf()) {
+operands.push_back(converter.getSymbolAddress(details->symbol()));
+converter.copySymbolBinding(details->symbol(), *sym);
+  }
+}
+  }
+}
+
+static void gatherFuncAndVarSyms(
+const omp::ObjectList &objects,
+mlir::omp::DeclareTargetCaptureClause clause,
+llvm::SmallVectorImpl &symbolAndClause) {
+  for (const omp::Object &object : objects)
+symbolAndClause.emplace_back(clause, *object.sym);
+}
+
 
//===--===//
 // DataSharingProcessor
 
//===--===//
@

[llvm-branch-commits] [flang] [flang][OpenMP] Convert processTODO and remove unused objects (PR #81627)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 1299d5190a3c273d2af4ab8c7f800af7df4e4ef6 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Fri, 9 Feb 2024 15:03:54 -0600
Subject: [PATCH] [flang][OpenMP] Convert processTODO and remove unused objects

Remove `ClauseIterator2` and `clauses2` from ClauseProcessor.
---
 flang/lib/Lower/OpenMP.cpp | 75 ++
 1 file changed, 28 insertions(+), 47 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 4309d69434839..51ed0fe03dbe3 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -1669,13 +1669,11 @@ void DataSharingProcessor::defaultPrivatize() {
 /// methods that relate to clauses that can impact the lowering of that
 /// construct.
 class ClauseProcessor {
-  using ClauseTy = Fortran::parser::OmpClause;
-
 public:
   ClauseProcessor(Fortran::lower::AbstractConverter &converter,
   Fortran::semantics::SemanticsContext &semaCtx,
   const Fortran::parser::OmpClauseList &clauses)
-  : converter(converter), semaCtx(semaCtx), clauses2(clauses),
+  : converter(converter), semaCtx(semaCtx),
 clauses(omp::makeList(clauses, semaCtx)) {}
 
   // 'Unique' clauses: They can appear at most once in the clause list.
@@ -1776,7 +1774,6 @@ class ClauseProcessor {
 
 private:
   using ClauseIterator = omp::List::const_iterator;
-  using ClauseIterator2 = std::list::const_iterator;
 
   /// Utility to find a clause within a range in the clause list.
   template 
@@ -1836,7 +1833,6 @@ class ClauseProcessor {
 
   Fortran::lower::AbstractConverter &converter;
   Fortran::semantics::SemanticsContext &semaCtx;
-  const Fortran::parser::OmpClauseList &clauses2;
   omp::List clauses;
 };
 
@@ -3132,19 +3128,17 @@ bool ClauseProcessor::processMotionClauses(
 template 
 void ClauseProcessor::processTODO(mlir::Location currentLocation,
   llvm::omp::Directive directive) const {
-  auto checkUnhandledClause = [&](const auto *x) {
+  auto checkUnhandledClause = [&](llvm::omp::Clause id, const auto *x) {
 if (!x)
   return;
 TODO(currentLocation,
- "Unhandled clause " +
- llvm::StringRef(Fortran::parser::ParseTreeDumper::GetNodeName(*x))
- .upper() +
+ "Unhandled clause " + llvm::omp::getOpenMPClauseName(id).upper() +
  " in " + llvm::omp::getOpenMPDirectiveName(directive).upper() +
  " construct");
   };
 
-  for (ClauseIterator2 it = clauses2.v.begin(); it != clauses2.v.end(); ++it)
-(checkUnhandledClause(std::get_if(&it->u)), ...);
+  for (ClauseIterator it = clauses.begin(); it != clauses.end(); ++it)
+(checkUnhandledClause(it->id, std::get_if(&it->u)), ...);
 }
 
 
//===--===//
@@ -3723,8 +3717,8 @@ genSingleOp(Fortran::lower::AbstractConverter &converter,
 
   ClauseProcessor cp(converter, semaCtx, beginClauseList);
   cp.processAllocate(allocatorOperands, allocateOperands);
-  cp.processTODO(
-  currentLocation, llvm::omp::Directive::OMPD_single);
+  cp.processTODO(currentLocation,
+   llvm::omp::Directive::OMPD_single);
 
   ClauseProcessor(converter, semaCtx, endClauseList).processNowait(nowaitAttr);
 
@@ -3757,10 +3751,9 @@ genTaskOp(Fortran::lower::AbstractConverter &converter,
   cp.processMergeable(mergeableAttr);
   cp.processPriority(stmtCtx, priorityClauseOperand);
   cp.processDepend(dependTypeOperands, dependOperands);
-  cp.processTODO(
-  currentLocation, llvm::omp::Directive::OMPD_task);
+  cp.processTODO(currentLocation,
+llvm::omp::Directive::OMPD_task);
 
   return genOpWithBody(
   OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
@@ -3785,7 +3778,7 @@ genTaskGroupOp(Fortran::lower::AbstractConverter 
&converter,
   llvm::SmallVector allocateOperands, allocatorOperands;
   ClauseProcessor cp(converter, semaCtx, clauseList);
   cp.processAllocate(allocatorOperands, allocateOperands);
-  cp.processTODO(
+  cp.processTODO(
   currentLocation, llvm::omp::Directive::OMPD_taskgroup);
   return genOpWithBody(
   OpWithBodyGenInfo(converter, semaCtx, currentLocation, eval)
@@ -3869,8 +3862,7 @@ 
genEnterExitUpdateDataOp(Fortran::lower::AbstractConverter &converter,
 cp.processMap(currentLocation, directive, stmtCtx, mapOperands);
   }
 
-  cp.processTODO(currentLocation,
- directive);
+  cp.processTODO(currentLocation, directive);
 
   return firOpBuilder.create(currentLocation, ifClauseOperand,
deviceOperand, nullptr, mlir::ValueRange(),
@@ -4053,16 +4045,11 @@ genTargetOp(Fortran::lower::AbstractConverter 
&converter,
   cp.processNowait(nowaitAttr);
   cp.processMap(currentLocation, directive, stmtCt

[llvm-branch-commits] [flang] [flang][Lower] Convert OMP Map and related functions to evaluate::Expr (PR #81626)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 87437159da37749ad395d84a3fc1b729bd9e2480 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Thu, 8 Feb 2024 08:33:40 -0600
Subject: [PATCH] [flang][Lower] Convert OMP Map and related functions to
 evaluate::Expr

The related functions are `gatherDataOperandAddrAndBounds` and
`genBoundsOps`. The former is used in OpenACC as well, and it was
updated to pass evaluate::Expr instead of parser objects.

The difference in the test case comes from unfolded conversions
of index expressions, which are explicitly of type integer(kind=8).

Delete now unused `findRepeatableClause2` and `findClause2`.

Add `AsGenericExpr` that takes std::optional. It already returns optional
Expr. Making it accept an optional Expr as input would reduce the number
of necessary checks when handling frequent optional values in evaluator.
---
 flang/include/flang/Evaluate/tools.h |   8 +
 flang/lib/Lower/DirectivesCommon.h   | 389 ---
 flang/lib/Lower/OpenACC.cpp  |  54 ++--
 flang/lib/Lower/OpenMP.cpp   | 105 +++-
 4 files changed, 311 insertions(+), 245 deletions(-)

diff --git a/flang/include/flang/Evaluate/tools.h 
b/flang/include/flang/Evaluate/tools.h
index e974944e88..d5713cfe420a2e 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -148,6 +148,14 @@ inline Expr AsGenericExpr(Expr &&x) { 
return std::move(x); }
 std::optional> AsGenericExpr(DataRef &&);
 std::optional> AsGenericExpr(const Symbol &);
 
+// Propagate std::optional from input to output.
+template 
+std::optional> AsGenericExpr(std::optional &&x) {
+  if (!x)
+return std::nullopt;
+  return AsGenericExpr(std::move(*x));
+}
+
 template 
 common::IfNoLvalue::category>>, A> AsCategoryExpr(
 A &&x) {
diff --git a/flang/lib/Lower/DirectivesCommon.h 
b/flang/lib/Lower/DirectivesCommon.h
index 8d560db34e05bf..2fa90572bc63eb 100644
--- a/flang/lib/Lower/DirectivesCommon.h
+++ b/flang/lib/Lower/DirectivesCommon.h
@@ -808,6 +808,75 @@ genBaseBoundsOps(fir::FirOpBuilder &builder, 
mlir::Location loc,
   return bounds;
 }
 
+namespace detail {
+template  //
+static T &&AsRvalueRef(T &&t) {
+  return std::move(t);
+}
+template  //
+static T AsRvalueRef(T &t) {
+  return t;
+}
+template  //
+static T AsRvalueRef(const T &t) {
+  return t;
+}
+
+// Helper class for stripping enclosing parentheses and a conversion that
+// preserves type category. This is used for triplet elements, which are
+// always of type integer(kind=8). The lower/upper bounds are converted to
+// an "index" type, which is 64-bit, so the explicit conversion to kind=8
+// (if present) is not needed. When it's present, though, it causes generated
+// names to contain "int(..., kind=8)".
+struct PeelConvert {
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(
+  const Fortran::evaluate::Expr>
+  &expr) {
+return std::visit(
+[](auto &&s) { return visit_with_category(s); },
+expr.u);
+  }
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(
+  const Fortran::evaluate::Convert,
+   Category> &expr) {
+return AsGenericExpr(AsRvalueRef(expr.left()));
+  }
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(const T &) {
+return std::nullopt; //
+  }
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(const T &) {
+return std::nullopt; //
+  }
+
+  template 
+  static Fortran::semantics::MaybeExpr
+  visit(const Fortran::evaluate::Expr>
+&expr) {
+return std::visit([](auto &&s) { return visit_with_category(s); 
},
+  expr.u);
+  }
+  static Fortran::semantics::MaybeExpr
+  visit(const Fortran::evaluate::Expr &expr) {
+return std::visit([](auto &&s) { return visit(s); }, expr.u);
+  }
+  template  //
+  static Fortran::semantics::MaybeExpr visit(const T &) {
+return std::nullopt;
+  }
+};
+
+static Fortran::semantics::SomeExpr
+peelOuterConvert(Fortran::semantics::SomeExpr &expr) {
+  if (auto peeled = PeelConvert::visit(expr))
+return *peeled;
+  return expr;
+}
+} // namespace detail
+
 /// Generate bounds operations for an array section when subscripts are
 /// provided.
 template 
@@ -815,7 +884,7 @@ llvm::SmallVector
 genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
  Fortran::lower::AbstractConverter &converter,
  Fortran::lower::StatementContext &stmtCtx,
- const std::list &subscripts,
+ const std::vector &subscripts,
  std::stringstream &asFortran, fir::ExtendedValue &dataExv,
  bool dataExvIsAssumedSize, AddrAndBoundsInfo &info,
  bool treatIndexAsSection = false) {
@@ -828,8 +897,7 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
   mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1)

[llvm-branch-commits] [flang] [flang][OpenMP] Convert DataSharingProcessor to omp::Clause (PR #81629)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 61d3ad32f0b5ab4903319add4ca5b68cd3e5ad3d Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Sat, 10 Feb 2024 08:50:48 -0600
Subject: [PATCH] [flang][OpenMP] Convert DataSharingProcessor to omp::Clause

---
 flang/lib/Lower/OpenMP.cpp | 303 ++---
 1 file changed, 149 insertions(+), 154 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 51ed0fe03dbe38..e45ab842b15556 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -1278,14 +1278,15 @@ class DataSharingProcessor {
   llvm::SetVector symbolsInNestedRegions;
   llvm::SetVector symbolsInParentRegions;
   Fortran::lower::AbstractConverter &converter;
+  Fortran::semantics::SemanticsContext &semaCtx;
   fir::FirOpBuilder &firOpBuilder;
-  const Fortran::parser::OmpClauseList &opClauseList;
+  omp::List clauses;
   Fortran::lower::pft::Evaluation &eval;
 
   bool needBarrier();
   void collectSymbols(Fortran::semantics::Symbol::Flag flag);
   void collectOmpObjectListSymbol(
-  const Fortran::parser::OmpObjectList &ompObjectList,
+  const omp::ObjectList &objects,
   llvm::SetVector &symbolSet);
   void collectSymbolsForPrivatization();
   void insertBarrier();
@@ -1302,11 +1303,12 @@ class DataSharingProcessor {
 
 public:
   DataSharingProcessor(Fortran::lower::AbstractConverter &converter,
+   Fortran::semantics::SemanticsContext &semaCtx,
const Fortran::parser::OmpClauseList &opClauseList,
Fortran::lower::pft::Evaluation &eval)
-  : hasLastPrivateOp(false), converter(converter),
-firOpBuilder(converter.getFirOpBuilder()), opClauseList(opClauseList),
-eval(eval) {}
+  : hasLastPrivateOp(false), converter(converter), semaCtx(semaCtx),
+firOpBuilder(converter.getFirOpBuilder()),
+clauses(omp::makeList(opClauseList, semaCtx)), eval(eval) {}
   // Privatisation is split into two steps.
   // Step1 performs cloning of all privatisation clauses and copying for
   // firstprivates. Step1 is performed at the place where process/processStep1
@@ -1384,30 +1386,28 @@ void DataSharingProcessor::copyLastPrivateSymbol(
 }
 
 void DataSharingProcessor::collectOmpObjectListSymbol(
-const Fortran::parser::OmpObjectList &ompObjectList,
+const omp::ObjectList &objects,
 llvm::SetVector &symbolSet) {
-  for (const Fortran::parser::OmpObject &ompObject : ompObjectList.v) {
-Fortran::semantics::Symbol *sym = getOmpObjectSymbol(ompObject);
+  for (const omp::Object &object : objects) {
+Fortran::semantics::Symbol *sym = object.sym;
 symbolSet.insert(sym);
   }
 }
 
 void DataSharingProcessor::collectSymbolsForPrivatization() {
   bool hasCollapse = false;
-  for (const Fortran::parser::OmpClause &clause : opClauseList.v) {
+  for (const omp::Clause &clause : clauses) {
 if (const auto &privateClause =
-std::get_if(&clause.u)) {
+std::get_if(&clause.u)) {
   collectOmpObjectListSymbol(privateClause->v, privatizedSymbols);
 } else if (const auto &firstPrivateClause =
-   std::get_if(
-   &clause.u)) {
+   std::get_if(&clause.u)) {
   collectOmpObjectListSymbol(firstPrivateClause->v, privatizedSymbols);
 } else if (const auto &lastPrivateClause =
-   std::get_if(
-   &clause.u)) {
+   std::get_if(&clause.u)) {
   collectOmpObjectListSymbol(lastPrivateClause->v, privatizedSymbols);
   hasLastPrivateOp = true;
-} else if (std::get_if(&clause.u)) {
+} else if (std::get_if(&clause.u)) {
   hasCollapse = true;
 }
   }
@@ -1440,138 +1440,135 @@ void DataSharingProcessor::insertBarrier() {
 void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
   bool cmpCreated = false;
   mlir::OpBuilder::InsertPoint localInsPt = firOpBuilder.saveInsertionPoint();
-  for (const Fortran::parser::OmpClause &clause : opClauseList.v) {
-if (std::get_if(&clause.u)) {
-  // TODO: Add lastprivate support for simd construct
-  if (mlir::isa(op)) {
-if (&eval == &eval.parentConstruct->getLastNestedEvaluation()) {
-  // For `omp.sections`, lastprivatized variables occur in
-  // lexically final `omp.section` operation. The following FIR
-  // shall be generated for the same:
-  //
-  // omp.sections lastprivate(...) {
-  //  omp.section {...}
-  //  omp.section {...}
-  //  omp.section {
-  //  fir.allocate for `private`/`firstprivate`
-  //  
-  //  fir.if %true {
-  //  ^%lpv_update_blk
-  //  }
-  //  }
-  // }
-  //
-  // To keep code consistency while handling privatization
-  // through this control flow

[llvm-branch-commits] [flang] [flang][OpenMP] Convert unique clauses in ClauseProcessor (PR #81622)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 57c70c53a3898d7fc45fd0a71368ae20fe8a1a85 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 6 Feb 2024 17:06:29 -0600
Subject: [PATCH] [flang][OpenMP] Convert unique clauses in ClauseProcessor

Temporarily rename old clause list to `clauses2`, old clause iterator
to `ClauseIterator2`.
Change `findUniqueClause` to iterate over `omp::Clause` objects,
modify all handlers to operate on 'omp::clause::xyz` equivalents.
---
 flang/lib/Lower/OpenMP.cpp | 242 +
 1 file changed, 114 insertions(+), 128 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index ae3619609b80ff..4156887c8ff531 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -1670,7 +1670,8 @@ class ClauseProcessor {
   ClauseProcessor(Fortran::lower::AbstractConverter &converter,
   Fortran::semantics::SemanticsContext &semaCtx,
   const Fortran::parser::OmpClauseList &clauses)
-  : converter(converter), semaCtx(semaCtx), clauses(clauses) {}
+  : converter(converter), semaCtx(semaCtx), clauses2(clauses),
+clauses(omp::makeList(clauses, semaCtx)) {}
 
   // 'Unique' clauses: They can appear at most once in the clause list.
   bool
@@ -1770,7 +1771,8 @@ class ClauseProcessor {
llvm::omp::Directive directive) const;
 
 private:
-  using ClauseIterator = std::list::const_iterator;
+  using ClauseIterator = omp::List::const_iterator;
+  using ClauseIterator2 = std::list::const_iterator;
 
   /// Utility to find a clause within a range in the clause list.
   template 
@@ -1783,14 +1785,26 @@ class ClauseProcessor {
 return end;
   }
 
+  /// Utility to find a clause within a range in the clause list.
+  template 
+  static ClauseIterator2 findClause2(ClauseIterator2 begin,
+ ClauseIterator2 end) {
+for (ClauseIterator2 it = begin; it != end; ++it) {
+  if (std::get_if(&it->u))
+return it;
+}
+
+return end;
+  }
+
   /// Return the first instance of the given clause found in the clause list or
   /// `nullptr` if not present. If more than one instance is expected, use
   /// `findRepeatableClause` instead.
   template 
   const T *
   findUniqueClause(const Fortran::parser::CharBlock **source = nullptr) const {
-ClauseIterator it = findClause(clauses.v.begin(), clauses.v.end());
-if (it != clauses.v.end()) {
+ClauseIterator it = findClause(clauses.begin(), clauses.end());
+if (it != clauses.end()) {
   if (source)
 *source = &it->source;
   return &std::get(it->u);
@@ -1805,9 +1819,9 @@ class ClauseProcessor {
   std::function
   callbackFn) const {
 bool found = false;
-ClauseIterator nextIt, endIt = clauses.v.end();
-for (ClauseIterator it = clauses.v.begin(); it != endIt; it = nextIt) {
-  nextIt = findClause(it, endIt);
+ClauseIterator2 nextIt, endIt = clauses2.v.end();
+for (ClauseIterator2 it = clauses2.v.begin(); it != endIt; it = nextIt) {
+  nextIt = findClause2(it, endIt);
 
   if (nextIt != endIt) {
 callbackFn(&std::get(nextIt->u), nextIt->source);
@@ -1830,7 +1844,8 @@ class ClauseProcessor {
 
   Fortran::lower::AbstractConverter &converter;
   Fortran::semantics::SemanticsContext &semaCtx;
-  const Fortran::parser::OmpClauseList &clauses;
+  const Fortran::parser::OmpClauseList &clauses2;
+  omp::List clauses;
 };
 
 
//===--===//
@@ -2295,64 +2310,55 @@ class ReductionProcessor {
 };
 
 static mlir::omp::ScheduleModifier
-translateScheduleModifier(const Fortran::parser::OmpScheduleModifierType &m) {
-  switch (m.v) {
-  case Fortran::parser::OmpScheduleModifierType::ModType::Monotonic:
+translateScheduleModifier(const omp::clause::Schedule::ModType &m) {
+  switch (m) {
+  case omp::clause::Schedule::ModType::Monotonic:
 return mlir::omp::ScheduleModifier::monotonic;
-  case Fortran::parser::OmpScheduleModifierType::ModType::Nonmonotonic:
+  case omp::clause::Schedule::ModType::Nonmonotonic:
 return mlir::omp::ScheduleModifier::nonmonotonic;
-  case Fortran::parser::OmpScheduleModifierType::ModType::Simd:
+  case omp::clause::Schedule::ModType::Simd:
 return mlir::omp::ScheduleModifier::simd;
   }
   return mlir::omp::ScheduleModifier::none;
 }
 
 static mlir::omp::ScheduleModifier
-getScheduleModifier(const Fortran::parser::OmpScheduleClause &x) {
-  const auto &modifier =
-  std::get>(x.t);
+getScheduleModifier(const omp::clause::Schedule &clause) {
+  using ScheduleModifier = omp::clause::Schedule::ScheduleModifier;
+  const auto &modifier = std::get>(clause.t);
   // The input may have the modifier any order, so we look for one that isn't
   // SIMD. If modifier is not set at all, fall down to the bottom and return
   // "none".
   if (modifier) {
-  

[llvm-branch-commits] [flang] [flang][OpenMP] Convert unique clauses in ClauseProcessor (PR #81622)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 57c70c53a3898d7fc45fd0a71368ae20fe8a1a85 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 6 Feb 2024 17:06:29 -0600
Subject: [PATCH] [flang][OpenMP] Convert unique clauses in ClauseProcessor

Temporarily rename old clause list to `clauses2`, old clause iterator
to `ClauseIterator2`.
Change `findUniqueClause` to iterate over `omp::Clause` objects,
modify all handlers to operate on 'omp::clause::xyz` equivalents.
---
 flang/lib/Lower/OpenMP.cpp | 242 +
 1 file changed, 114 insertions(+), 128 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index ae3619609b80ff..4156887c8ff531 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -1670,7 +1670,8 @@ class ClauseProcessor {
   ClauseProcessor(Fortran::lower::AbstractConverter &converter,
   Fortran::semantics::SemanticsContext &semaCtx,
   const Fortran::parser::OmpClauseList &clauses)
-  : converter(converter), semaCtx(semaCtx), clauses(clauses) {}
+  : converter(converter), semaCtx(semaCtx), clauses2(clauses),
+clauses(omp::makeList(clauses, semaCtx)) {}
 
   // 'Unique' clauses: They can appear at most once in the clause list.
   bool
@@ -1770,7 +1771,8 @@ class ClauseProcessor {
llvm::omp::Directive directive) const;
 
 private:
-  using ClauseIterator = std::list::const_iterator;
+  using ClauseIterator = omp::List::const_iterator;
+  using ClauseIterator2 = std::list::const_iterator;
 
   /// Utility to find a clause within a range in the clause list.
   template 
@@ -1783,14 +1785,26 @@ class ClauseProcessor {
 return end;
   }
 
+  /// Utility to find a clause within a range in the clause list.
+  template 
+  static ClauseIterator2 findClause2(ClauseIterator2 begin,
+ ClauseIterator2 end) {
+for (ClauseIterator2 it = begin; it != end; ++it) {
+  if (std::get_if(&it->u))
+return it;
+}
+
+return end;
+  }
+
   /// Return the first instance of the given clause found in the clause list or
   /// `nullptr` if not present. If more than one instance is expected, use
   /// `findRepeatableClause` instead.
   template 
   const T *
   findUniqueClause(const Fortran::parser::CharBlock **source = nullptr) const {
-ClauseIterator it = findClause(clauses.v.begin(), clauses.v.end());
-if (it != clauses.v.end()) {
+ClauseIterator it = findClause(clauses.begin(), clauses.end());
+if (it != clauses.end()) {
   if (source)
 *source = &it->source;
   return &std::get(it->u);
@@ -1805,9 +1819,9 @@ class ClauseProcessor {
   std::function
   callbackFn) const {
 bool found = false;
-ClauseIterator nextIt, endIt = clauses.v.end();
-for (ClauseIterator it = clauses.v.begin(); it != endIt; it = nextIt) {
-  nextIt = findClause(it, endIt);
+ClauseIterator2 nextIt, endIt = clauses2.v.end();
+for (ClauseIterator2 it = clauses2.v.begin(); it != endIt; it = nextIt) {
+  nextIt = findClause2(it, endIt);
 
   if (nextIt != endIt) {
 callbackFn(&std::get(nextIt->u), nextIt->source);
@@ -1830,7 +1844,8 @@ class ClauseProcessor {
 
   Fortran::lower::AbstractConverter &converter;
   Fortran::semantics::SemanticsContext &semaCtx;
-  const Fortran::parser::OmpClauseList &clauses;
+  const Fortran::parser::OmpClauseList &clauses2;
+  omp::List clauses;
 };
 
 
//===--===//
@@ -2295,64 +2310,55 @@ class ReductionProcessor {
 };
 
 static mlir::omp::ScheduleModifier
-translateScheduleModifier(const Fortran::parser::OmpScheduleModifierType &m) {
-  switch (m.v) {
-  case Fortran::parser::OmpScheduleModifierType::ModType::Monotonic:
+translateScheduleModifier(const omp::clause::Schedule::ModType &m) {
+  switch (m) {
+  case omp::clause::Schedule::ModType::Monotonic:
 return mlir::omp::ScheduleModifier::monotonic;
-  case Fortran::parser::OmpScheduleModifierType::ModType::Nonmonotonic:
+  case omp::clause::Schedule::ModType::Nonmonotonic:
 return mlir::omp::ScheduleModifier::nonmonotonic;
-  case Fortran::parser::OmpScheduleModifierType::ModType::Simd:
+  case omp::clause::Schedule::ModType::Simd:
 return mlir::omp::ScheduleModifier::simd;
   }
   return mlir::omp::ScheduleModifier::none;
 }
 
 static mlir::omp::ScheduleModifier
-getScheduleModifier(const Fortran::parser::OmpScheduleClause &x) {
-  const auto &modifier =
-  std::get>(x.t);
+getScheduleModifier(const omp::clause::Schedule &clause) {
+  using ScheduleModifier = omp::clause::Schedule::ScheduleModifier;
+  const auto &modifier = std::get>(clause.t);
   // The input may have the modifier any order, so we look for one that isn't
   // SIMD. If modifier is not set at all, fall down to the bottom and return
   // "none".
   if (modifier) {
-  

[llvm-branch-commits] [flang] [flang][OpenMP] Convert DataSharingProcessor to omp::Clause (PR #81629)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 61d3ad32f0b5ab4903319add4ca5b68cd3e5ad3d Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Sat, 10 Feb 2024 08:50:48 -0600
Subject: [PATCH] [flang][OpenMP] Convert DataSharingProcessor to omp::Clause

---
 flang/lib/Lower/OpenMP.cpp | 303 ++---
 1 file changed, 149 insertions(+), 154 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 51ed0fe03dbe38..e45ab842b15556 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -1278,14 +1278,15 @@ class DataSharingProcessor {
   llvm::SetVector symbolsInNestedRegions;
   llvm::SetVector symbolsInParentRegions;
   Fortran::lower::AbstractConverter &converter;
+  Fortran::semantics::SemanticsContext &semaCtx;
   fir::FirOpBuilder &firOpBuilder;
-  const Fortran::parser::OmpClauseList &opClauseList;
+  omp::List clauses;
   Fortran::lower::pft::Evaluation &eval;
 
   bool needBarrier();
   void collectSymbols(Fortran::semantics::Symbol::Flag flag);
   void collectOmpObjectListSymbol(
-  const Fortran::parser::OmpObjectList &ompObjectList,
+  const omp::ObjectList &objects,
   llvm::SetVector &symbolSet);
   void collectSymbolsForPrivatization();
   void insertBarrier();
@@ -1302,11 +1303,12 @@ class DataSharingProcessor {
 
 public:
   DataSharingProcessor(Fortran::lower::AbstractConverter &converter,
+   Fortran::semantics::SemanticsContext &semaCtx,
const Fortran::parser::OmpClauseList &opClauseList,
Fortran::lower::pft::Evaluation &eval)
-  : hasLastPrivateOp(false), converter(converter),
-firOpBuilder(converter.getFirOpBuilder()), opClauseList(opClauseList),
-eval(eval) {}
+  : hasLastPrivateOp(false), converter(converter), semaCtx(semaCtx),
+firOpBuilder(converter.getFirOpBuilder()),
+clauses(omp::makeList(opClauseList, semaCtx)), eval(eval) {}
   // Privatisation is split into two steps.
   // Step1 performs cloning of all privatisation clauses and copying for
   // firstprivates. Step1 is performed at the place where process/processStep1
@@ -1384,30 +1386,28 @@ void DataSharingProcessor::copyLastPrivateSymbol(
 }
 
 void DataSharingProcessor::collectOmpObjectListSymbol(
-const Fortran::parser::OmpObjectList &ompObjectList,
+const omp::ObjectList &objects,
 llvm::SetVector &symbolSet) {
-  for (const Fortran::parser::OmpObject &ompObject : ompObjectList.v) {
-Fortran::semantics::Symbol *sym = getOmpObjectSymbol(ompObject);
+  for (const omp::Object &object : objects) {
+Fortran::semantics::Symbol *sym = object.sym;
 symbolSet.insert(sym);
   }
 }
 
 void DataSharingProcessor::collectSymbolsForPrivatization() {
   bool hasCollapse = false;
-  for (const Fortran::parser::OmpClause &clause : opClauseList.v) {
+  for (const omp::Clause &clause : clauses) {
 if (const auto &privateClause =
-std::get_if(&clause.u)) {
+std::get_if(&clause.u)) {
   collectOmpObjectListSymbol(privateClause->v, privatizedSymbols);
 } else if (const auto &firstPrivateClause =
-   std::get_if(
-   &clause.u)) {
+   std::get_if(&clause.u)) {
   collectOmpObjectListSymbol(firstPrivateClause->v, privatizedSymbols);
 } else if (const auto &lastPrivateClause =
-   std::get_if(
-   &clause.u)) {
+   std::get_if(&clause.u)) {
   collectOmpObjectListSymbol(lastPrivateClause->v, privatizedSymbols);
   hasLastPrivateOp = true;
-} else if (std::get_if(&clause.u)) {
+} else if (std::get_if(&clause.u)) {
   hasCollapse = true;
 }
   }
@@ -1440,138 +1440,135 @@ void DataSharingProcessor::insertBarrier() {
 void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
   bool cmpCreated = false;
   mlir::OpBuilder::InsertPoint localInsPt = firOpBuilder.saveInsertionPoint();
-  for (const Fortran::parser::OmpClause &clause : opClauseList.v) {
-if (std::get_if(&clause.u)) {
-  // TODO: Add lastprivate support for simd construct
-  if (mlir::isa(op)) {
-if (&eval == &eval.parentConstruct->getLastNestedEvaluation()) {
-  // For `omp.sections`, lastprivatized variables occur in
-  // lexically final `omp.section` operation. The following FIR
-  // shall be generated for the same:
-  //
-  // omp.sections lastprivate(...) {
-  //  omp.section {...}
-  //  omp.section {...}
-  //  omp.section {
-  //  fir.allocate for `private`/`firstprivate`
-  //  
-  //  fir.if %true {
-  //  ^%lpv_update_blk
-  //  }
-  //  }
-  // }
-  //
-  // To keep code consistency while handling privatization
-  // through this control flow

[llvm-branch-commits] [flang] [flang][Lower] Convert OMP Map and related functions to evaluate::Expr (PR #81626)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 87437159da37749ad395d84a3fc1b729bd9e2480 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Thu, 8 Feb 2024 08:33:40 -0600
Subject: [PATCH] [flang][Lower] Convert OMP Map and related functions to
 evaluate::Expr

The related functions are `gatherDataOperandAddrAndBounds` and
`genBoundsOps`. The former is used in OpenACC as well, and it was
updated to pass evaluate::Expr instead of parser objects.

The difference in the test case comes from unfolded conversions
of index expressions, which are explicitly of type integer(kind=8).

Delete now unused `findRepeatableClause2` and `findClause2`.

Add `AsGenericExpr` that takes std::optional. It already returns optional
Expr. Making it accept an optional Expr as input would reduce the number
of necessary checks when handling frequent optional values in evaluator.
---
 flang/include/flang/Evaluate/tools.h |   8 +
 flang/lib/Lower/DirectivesCommon.h   | 389 ---
 flang/lib/Lower/OpenACC.cpp  |  54 ++--
 flang/lib/Lower/OpenMP.cpp   | 105 +++-
 4 files changed, 311 insertions(+), 245 deletions(-)

diff --git a/flang/include/flang/Evaluate/tools.h 
b/flang/include/flang/Evaluate/tools.h
index e974944e88..d5713cfe420a2e 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -148,6 +148,14 @@ inline Expr AsGenericExpr(Expr &&x) { 
return std::move(x); }
 std::optional> AsGenericExpr(DataRef &&);
 std::optional> AsGenericExpr(const Symbol &);
 
+// Propagate std::optional from input to output.
+template 
+std::optional> AsGenericExpr(std::optional &&x) {
+  if (!x)
+return std::nullopt;
+  return AsGenericExpr(std::move(*x));
+}
+
 template 
 common::IfNoLvalue::category>>, A> AsCategoryExpr(
 A &&x) {
diff --git a/flang/lib/Lower/DirectivesCommon.h 
b/flang/lib/Lower/DirectivesCommon.h
index 8d560db34e05bf..2fa90572bc63eb 100644
--- a/flang/lib/Lower/DirectivesCommon.h
+++ b/flang/lib/Lower/DirectivesCommon.h
@@ -808,6 +808,75 @@ genBaseBoundsOps(fir::FirOpBuilder &builder, 
mlir::Location loc,
   return bounds;
 }
 
+namespace detail {
+template  //
+static T &&AsRvalueRef(T &&t) {
+  return std::move(t);
+}
+template  //
+static T AsRvalueRef(T &t) {
+  return t;
+}
+template  //
+static T AsRvalueRef(const T &t) {
+  return t;
+}
+
+// Helper class for stripping enclosing parentheses and a conversion that
+// preserves type category. This is used for triplet elements, which are
+// always of type integer(kind=8). The lower/upper bounds are converted to
+// an "index" type, which is 64-bit, so the explicit conversion to kind=8
+// (if present) is not needed. When it's present, though, it causes generated
+// names to contain "int(..., kind=8)".
+struct PeelConvert {
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(
+  const Fortran::evaluate::Expr>
+  &expr) {
+return std::visit(
+[](auto &&s) { return visit_with_category(s); },
+expr.u);
+  }
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(
+  const Fortran::evaluate::Convert,
+   Category> &expr) {
+return AsGenericExpr(AsRvalueRef(expr.left()));
+  }
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(const T &) {
+return std::nullopt; //
+  }
+  template 
+  static Fortran::semantics::MaybeExpr visit_with_category(const T &) {
+return std::nullopt; //
+  }
+
+  template 
+  static Fortran::semantics::MaybeExpr
+  visit(const Fortran::evaluate::Expr>
+&expr) {
+return std::visit([](auto &&s) { return visit_with_category(s); 
},
+  expr.u);
+  }
+  static Fortran::semantics::MaybeExpr
+  visit(const Fortran::evaluate::Expr &expr) {
+return std::visit([](auto &&s) { return visit(s); }, expr.u);
+  }
+  template  //
+  static Fortran::semantics::MaybeExpr visit(const T &) {
+return std::nullopt;
+  }
+};
+
+static Fortran::semantics::SomeExpr
+peelOuterConvert(Fortran::semantics::SomeExpr &expr) {
+  if (auto peeled = PeelConvert::visit(expr))
+return *peeled;
+  return expr;
+}
+} // namespace detail
+
 /// Generate bounds operations for an array section when subscripts are
 /// provided.
 template 
@@ -815,7 +884,7 @@ llvm::SmallVector
 genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
  Fortran::lower::AbstractConverter &converter,
  Fortran::lower::StatementContext &stmtCtx,
- const std::list &subscripts,
+ const std::vector &subscripts,
  std::stringstream &asFortran, fir::ExtendedValue &dataExv,
  bool dataExvIsAssumedSize, AddrAndBoundsInfo &info,
  bool treatIndexAsSection = false) {
@@ -828,8 +897,7 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
   mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1)

[llvm-branch-commits] [flang] [flang][OpenMP] Convert repeatable clauses (except Map) in ClauseProc… (PR #81623)

2024-02-13 Thread Krzysztof Parzyszek via llvm-branch-commits

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

>From 841f10e44e5ec5cfc6b166421f878089a17c623c Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 6 Feb 2024 17:06:29 -0600
Subject: [PATCH] [flang][OpenMP] Convert repeatable clauses (except Map) in
 ClauseProcessor

Rename `findRepeatableClause` to `findRepeatableClause2`, and make the
new `findRepeatableClause` operate on new `omp::Clause` objects.

Leave `Map` unchanged, because it will require more changes for it to
work.
---
 flang/include/flang/Evaluate/tools.h |  23 +
 flang/lib/Lower/OpenMP.cpp   | 632 +--
 2 files changed, 328 insertions(+), 327 deletions(-)

diff --git a/flang/include/flang/Evaluate/tools.h 
b/flang/include/flang/Evaluate/tools.h
index d257da1a709642..e974944e88 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -430,6 +430,29 @@ template  std::optional 
ExtractCoarrayRef(const A &x) {
   }
 }
 
+struct ExtractSubstringHelper {
+  template  static std::optional visit(T &&) {
+return std::nullopt;
+  }
+
+  static std::optional visit(const Substring &e) { return e; }
+
+  template 
+  static std::optional visit(const Designator &e) {
+return std::visit([](auto &&s) { return visit(s); }, e.u);
+  }
+
+  template 
+  static std::optional visit(const Expr &e) {
+return std::visit([](auto &&s) { return visit(s); }, e.u);
+  }
+};
+
+template 
+std::optional ExtractSubstring(const A &x) {
+  return ExtractSubstringHelper::visit(x);
+}
+
 // If an expression is simply a whole symbol data designator,
 // extract and return that symbol, else null.
 template  const Symbol *UnwrapWholeSymbolDataRef(const A &x) {
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 4156887c8ff531..caae5c0cef9251 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -72,9 +72,9 @@ getOmpObjectSymbol(const Fortran::parser::OmpObject 
&ompObject) {
   return sym;
 }
 
-static void genObjectList(const Fortran::parser::OmpObjectList &objectList,
-  Fortran::lower::AbstractConverter &converter,
-  llvm::SmallVectorImpl &operands) {
+static void genObjectList2(const Fortran::parser::OmpObjectList &objectList,
+   Fortran::lower::AbstractConverter &converter,
+   llvm::SmallVectorImpl &operands) {
   auto addOperands = [&](Fortran::lower::SymbolRef sym) {
 const mlir::Value variable = converter.getSymbolAddress(sym);
 if (variable) {
@@ -93,27 +93,6 @@ static void genObjectList(const 
Fortran::parser::OmpObjectList &objectList,
   }
 }
 
-static void gatherFuncAndVarSyms(
-const Fortran::parser::OmpObjectList &objList,
-mlir::omp::DeclareTargetCaptureClause clause,
-llvm::SmallVectorImpl &symbolAndClause) {
-  for (const Fortran::parser::OmpObject &ompObject : objList.v) {
-Fortran::common::visit(
-Fortran::common::visitors{
-[&](const Fortran::parser::Designator &designator) {
-  if (const Fortran::parser::Name *name =
-  Fortran::semantics::getDesignatorNameIfDataRef(
-  designator)) {
-symbolAndClause.emplace_back(clause, *name->symbol);
-  }
-},
-[&](const Fortran::parser::Name &name) {
-  symbolAndClause.emplace_back(clause, *name.symbol);
-}},
-ompObject.u);
-  }
-}
-
 static Fortran::lower::pft::Evaluation *
 getCollapsedLoopEval(Fortran::lower::pft::Evaluation &eval, int collapseValue) 
{
   // Return the Evaluation of the innermost collapsed loop, or the current one
@@ -1258,6 +1237,32 @@ List makeList(const parser::OmpClauseList 
&clauses,
 }
 } // namespace omp
 
+static void genObjectList(const omp::ObjectList &objects,
+  Fortran::lower::AbstractConverter &converter,
+  llvm::SmallVectorImpl &operands) {
+  for (const omp::Object &object : objects) {
+const Fortran::semantics::Symbol *sym = object.sym;
+assert(sym && "Expected Symbol");
+if (mlir::Value variable = converter.getSymbolAddress(*sym)) {
+  operands.push_back(variable);
+} else {
+  if (const auto *details =
+  sym->detailsIf()) {
+operands.push_back(converter.getSymbolAddress(details->symbol()));
+converter.copySymbolBinding(details->symbol(), *sym);
+  }
+}
+  }
+}
+
+static void gatherFuncAndVarSyms(
+const omp::ObjectList &objects,
+mlir::omp::DeclareTargetCaptureClause clause,
+llvm::SmallVectorImpl &symbolAndClause) {
+  for (const omp::Object &object : objects)
+symbolAndClause.emplace_back(clause, *object.sym);
+}
+
 
//===--===//
 // DataSharingProcessor
 
//===--===//
@

[llvm-branch-commits] [clang] [llvm] [PowerPC] Update V18.1.0 release notes (PR #81631)

2024-02-13 Thread Maryam Moghadas via llvm-branch-commits

https://github.com/maryammo created 
https://github.com/llvm/llvm-project/pull/81631

Adding PowerPC updates for clang and llvm into the V18.1.0 release notes.

>From 627612dff3314b8250542ca951027b8ec8f7ac71 Mon Sep 17 00:00:00 2001
From: Maryam Moghadas 
Date: Mon, 12 Feb 2024 13:35:00 -0600
Subject: [PATCH] [PowerPC] Update V18.1.0 release notes

---
 clang/docs/ReleaseNotes.rst | 26 ++
 llvm/docs/ReleaseNotes.rst  | 37 +
 2 files changed, 63 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 95d44951ae7ee6..22eceea5d265ef 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -304,6 +304,10 @@ Non-comprehensive list of changes in this release
 
 * The version of Unicode used by Clang (primarily to parse identifiers) has 
been updated to 15.1.
 
+* Clang now defines macro ``__LLVM_INSTR_PROFILE_GENERATE`` when compiling with
+  PGO instrumentation profile generation, and ``__LLVM_INSTR_PROFILE_USE`` when
+  compiling with PGO profile use.
+
 New Compiler Flags
 --
 
@@ -344,6 +348,8 @@ New Compiler Flags
   attribute the replaceable global new and delete operators behave normally
   (like other functions) with respect to visibility attributes, pragmas and
   options (e.g ``--fvisibility=``).
+* Full register names can be used when printing assembly via ``-mregnames``.
+  This option now matches the one used by GCC.
 
 Deprecated Compiler Flags
 -
@@ -363,6 +369,7 @@ Modified Compiler Flags
 * ``-fvisibility-global-new-delete-hidden`` is now a deprecated spelling of
   ``-fvisibility-global-new-delete=force-hidden`` 
(``-fvisibility-global-new-delete=``
   is new in this release).
+* ``-fprofile-update`` is enabled for ``-fprofile-generate``.
 
 Removed Compiler Flags
 -
@@ -860,6 +867,9 @@ Bug Fixes in This Version
   Fixes (`#78290 `_)
 - Fixed assertion failure with deleted overloaded unary operators.
   Fixes (`#78314 `_)
+- The XCOFF object file format does not support aliases to symbols having 
common
+  linkage. Clang now diagnoses the use of an alias for a common symbol when
+  compiling for AIX.
 
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
@@ -1261,6 +1271,16 @@ CUDA Support
 - Clang now supports CUDA SDK up to 12.3
 - Added support for sm_90a
 
+PowerPC Support
+^^^
+
+- Added ``nmmintrin.h`` to intrinsics headers.
+- Added ``__builtin_ppc_fence`` as barrier of code motion, and
+  ``__builtin_ppc_mffsl`` for corresponding instruction.
+- Supported ``__attribute__((target("tune=cpu")))``.
+- Emit ``float-abi`` module flag on 64-bit ELFv2 PowerPC targets if
+  ``long double`` type is used in current module.
+
 AIX Support
 ^^^
 
@@ -1269,6 +1289,10 @@ AIX Support
   base is encoded as an immediate operand.
   This access sequence is not used for TLS variables larger than 32KB, and is
   currently only supported on 64-bit mode.
+- Inline assembler supports VSR register in pure digits.
+- Enabled ThinLTO support. Requires AIX 7.2 TL5 SP7 or newer, or AIX 7.3 TL2
+  or newer. Similar to the LTO support on AIX, ThinLTO is implemented with
+  the libLTO.so plugin.
 
 WebAssembly Support
 ^^^
@@ -1332,6 +1356,8 @@ libclang
 - Exposed arguments of ``clang::annotate``.
 - ``clang::getCursorKindForDecl`` now recognizes linkage specifications such as
   ``extern "C"`` and reports them as ``CXCursor_LinkageSpec``.
+- Changed the libclang library on AIX to export only the necessary symbols to
+  prevent issues of resolving to the wrong duplicate symbol.
 
 Static Analyzer
 ---
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 82f4a7a15c9c13..16acbb965c5c94 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -163,6 +163,30 @@ Changes to the MIPS Backend
 
 Changes to the PowerPC Backend
 --
+* LLJIT's JIT linker now defaults to JITLink on 64-bit ELFv2 targets.
+* Initial-exec TLS model is supported on AIX.
+* Implemented new resource based scheduling model of POWER7 and POWER8.
+* ``frexp`` libcall now references correct symbol name for ``fp128``.
+* Optimized materialization of 64-bit immediates, code generation of
+  ``vec_promote`` and atomics.
+
+* Global constant strings are pooled in the TOC under one entry to reduce the
+  number of entries in the TOC.
+* Added a number of missing Power10 extended mnemonics.
+* Added the SCV instruction.
+* Fixed register class for the paddi instruction.
+* Optimize VPERM and fix code order for swapping vector operands on LE.
+* Added various bug fixes and code gen improvements.
+
+AIX Support/improvements:
+
+* Support for a non-TOC-based access sequence for the local-exec TLS model 
(called

[llvm-branch-commits] [clang] [llvm] [PowerPC] Update V18.1.0 release notes (PR #81631)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Maryam Moghadas (maryammo)


Changes

Adding PowerPC updates for clang and llvm into the V18.1.0 release notes.

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


2 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+26) 
- (modified) llvm/docs/ReleaseNotes.rst (+37) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 95d44951ae7ee6..22eceea5d265ef 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -304,6 +304,10 @@ Non-comprehensive list of changes in this release
 
 * The version of Unicode used by Clang (primarily to parse identifiers) has 
been updated to 15.1.
 
+* Clang now defines macro ``__LLVM_INSTR_PROFILE_GENERATE`` when compiling with
+  PGO instrumentation profile generation, and ``__LLVM_INSTR_PROFILE_USE`` when
+  compiling with PGO profile use.
+
 New Compiler Flags
 --
 
@@ -344,6 +348,8 @@ New Compiler Flags
   attribute the replaceable global new and delete operators behave normally
   (like other functions) with respect to visibility attributes, pragmas and
   options (e.g ``--fvisibility=``).
+* Full register names can be used when printing assembly via ``-mregnames``.
+  This option now matches the one used by GCC.
 
 Deprecated Compiler Flags
 -
@@ -363,6 +369,7 @@ Modified Compiler Flags
 * ``-fvisibility-global-new-delete-hidden`` is now a deprecated spelling of
   ``-fvisibility-global-new-delete=force-hidden`` 
(``-fvisibility-global-new-delete=``
   is new in this release).
+* ``-fprofile-update`` is enabled for ``-fprofile-generate``.
 
 Removed Compiler Flags
 -
@@ -860,6 +867,9 @@ Bug Fixes in This Version
   Fixes (`#78290 `_)
 - Fixed assertion failure with deleted overloaded unary operators.
   Fixes (`#78314 `_)
+- The XCOFF object file format does not support aliases to symbols having 
common
+  linkage. Clang now diagnoses the use of an alias for a common symbol when
+  compiling for AIX.
 
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
@@ -1261,6 +1271,16 @@ CUDA Support
 - Clang now supports CUDA SDK up to 12.3
 - Added support for sm_90a
 
+PowerPC Support
+^^^
+
+- Added ``nmmintrin.h`` to intrinsics headers.
+- Added ``__builtin_ppc_fence`` as barrier of code motion, and
+  ``__builtin_ppc_mffsl`` for corresponding instruction.
+- Supported ``__attribute__((target("tune=cpu")))``.
+- Emit ``float-abi`` module flag on 64-bit ELFv2 PowerPC targets if
+  ``long double`` type is used in current module.
+
 AIX Support
 ^^^
 
@@ -1269,6 +1289,10 @@ AIX Support
   base is encoded as an immediate operand.
   This access sequence is not used for TLS variables larger than 32KB, and is
   currently only supported on 64-bit mode.
+- Inline assembler supports VSR register in pure digits.
+- Enabled ThinLTO support. Requires AIX 7.2 TL5 SP7 or newer, or AIX 7.3 TL2
+  or newer. Similar to the LTO support on AIX, ThinLTO is implemented with
+  the libLTO.so plugin.
 
 WebAssembly Support
 ^^^
@@ -1332,6 +1356,8 @@ libclang
 - Exposed arguments of ``clang::annotate``.
 - ``clang::getCursorKindForDecl`` now recognizes linkage specifications such as
   ``extern "C"`` and reports them as ``CXCursor_LinkageSpec``.
+- Changed the libclang library on AIX to export only the necessary symbols to
+  prevent issues of resolving to the wrong duplicate symbol.
 
 Static Analyzer
 ---
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 82f4a7a15c9c13..16acbb965c5c94 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -163,6 +163,30 @@ Changes to the MIPS Backend
 
 Changes to the PowerPC Backend
 --
+* LLJIT's JIT linker now defaults to JITLink on 64-bit ELFv2 targets.
+* Initial-exec TLS model is supported on AIX.
+* Implemented new resource based scheduling model of POWER7 and POWER8.
+* ``frexp`` libcall now references correct symbol name for ``fp128``.
+* Optimized materialization of 64-bit immediates, code generation of
+  ``vec_promote`` and atomics.
+
+* Global constant strings are pooled in the TOC under one entry to reduce the
+  number of entries in the TOC.
+* Added a number of missing Power10 extended mnemonics.
+* Added the SCV instruction.
+* Fixed register class for the paddi instruction.
+* Optimize VPERM and fix code order for swapping vector operands on LE.
+* Added various bug fixes and code gen improvements.
+
+AIX Support/improvements:
+
+* Support for a non-TOC-based access sequence for the local-exec TLS model 
(called small local-exec).
+* XCOFF toc-data peephole optimization and bug fixes.
+* Move less often used __ehinfo TOC entries to the end of the TOC section.
+* F

[llvm-branch-commits] [llvm] Backport [DAGCombine] Fix multi-use miscompile in load combine (#81586) (PR #81633)

2024-02-13 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic created https://github.com/llvm/llvm-project/pull/81633

(cherry picked from commit 25b9ed6e4964344e3710359bec4c831e5a8448b9)

>From 377c85908b8e0709c60d378eb3849f7c8bb0eb46 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Tue, 13 Feb 2024 16:41:00 +0100
Subject: [PATCH] [DAGCombine] Fix multi-use miscompile in load combine
 (#81586)

The load combine replaces a number of original loads with one new loads
and also replaces the output chains of the original loads with the
output chain of the new load. This is incorrect if the original load is
retained (due to multi-use), as it may get incorrectly reordered.

Fix this by using makeEquivalentMemoryOrdering() instead, which will
create a TokenFactor with both chains.

Fixes https://github.com/llvm/llvm-project/issues/80911.

(cherry picked from commit 25b9ed6e4964344e3710359bec4c831e5a8448b9)
---
 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp |  2 +-
 llvm/test/CodeGen/X86/load-combine.ll | 32 +++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp 
b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 98d8a6d9409f25..3135ec73a99e76 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -9253,7 +9253,7 @@ SDValue DAGCombiner::MatchLoadCombine(SDNode *N) {
 
   // Transfer chain users from old loads to the new load.
   for (LoadSDNode *L : Loads)
-DAG.ReplaceAllUsesOfValueWith(SDValue(L, 1), SDValue(NewLoad.getNode(), 
1));
+DAG.makeEquivalentMemoryOrdering(L, NewLoad);
 
   if (!NeedsBswap)
 return NewLoad;
diff --git a/llvm/test/CodeGen/X86/load-combine.ll 
b/llvm/test/CodeGen/X86/load-combine.ll
index 7f8115dc1ce389..b5f3e789918813 100644
--- a/llvm/test/CodeGen/X86/load-combine.ll
+++ b/llvm/test/CodeGen/X86/load-combine.ll
@@ -1282,3 +1282,35 @@ define i32 @zext_load_i32_by_i8_bswap_shl_16(ptr %arg) {
   %tmp8 = or i32 %tmp7, %tmp30
   ret i32 %tmp8
 }
+
+define i32 @pr80911_vector_load_multiuse(ptr %ptr, ptr %clobber) nounwind {
+; CHECK-LABEL: pr80911_vector_load_multiuse:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:pushl %esi
+; CHECK-NEXT:movl {{[0-9]+}}(%esp), %ecx
+; CHECK-NEXT:movl {{[0-9]+}}(%esp), %edx
+; CHECK-NEXT:movl (%edx), %esi
+; CHECK-NEXT:movzwl (%edx), %eax
+; CHECK-NEXT:movl $0, (%ecx)
+; CHECK-NEXT:movl %esi, (%edx)
+; CHECK-NEXT:popl %esi
+; CHECK-NEXT:retl
+;
+; CHECK64-LABEL: pr80911_vector_load_multiuse:
+; CHECK64:   # %bb.0:
+; CHECK64-NEXT:movl (%rdi), %ecx
+; CHECK64-NEXT:movzwl (%rdi), %eax
+; CHECK64-NEXT:movl $0, (%rsi)
+; CHECK64-NEXT:movl %ecx, (%rdi)
+; CHECK64-NEXT:retq
+  %load = load <4 x i8>, ptr %ptr, align 16
+  store i32 0, ptr %clobber
+  store <4 x i8> %load, ptr %ptr, align 16
+  %e1 = extractelement <4 x i8> %load, i64 1
+  %e1.ext = zext i8 %e1 to i32
+  %e1.ext.shift = shl nuw nsw i32 %e1.ext, 8
+  %e0 = extractelement <4 x i8> %load, i64 0
+  %e0.ext = zext i8 %e0 to i32
+  %res = or i32 %e1.ext.shift, %e0.ext
+  ret i32 %res
+}

___
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] Backport [DAGCombine] Fix multi-use miscompile in load combine (#81586) (PR #81633)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-selectiondag

Author: Nikita Popov (nikic)


Changes

(cherry picked from commit 25b9ed6e4964344e3710359bec4c831e5a8448b9)

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


2 Files Affected:

- (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+1-1) 
- (modified) llvm/test/CodeGen/X86/load-combine.ll (+32) 


``diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp 
b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 98d8a6d9409f25..3135ec73a99e76 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -9253,7 +9253,7 @@ SDValue DAGCombiner::MatchLoadCombine(SDNode *N) {
 
   // Transfer chain users from old loads to the new load.
   for (LoadSDNode *L : Loads)
-DAG.ReplaceAllUsesOfValueWith(SDValue(L, 1), SDValue(NewLoad.getNode(), 
1));
+DAG.makeEquivalentMemoryOrdering(L, NewLoad);
 
   if (!NeedsBswap)
 return NewLoad;
diff --git a/llvm/test/CodeGen/X86/load-combine.ll 
b/llvm/test/CodeGen/X86/load-combine.ll
index 7f8115dc1ce389..b5f3e789918813 100644
--- a/llvm/test/CodeGen/X86/load-combine.ll
+++ b/llvm/test/CodeGen/X86/load-combine.ll
@@ -1282,3 +1282,35 @@ define i32 @zext_load_i32_by_i8_bswap_shl_16(ptr %arg) {
   %tmp8 = or i32 %tmp7, %tmp30
   ret i32 %tmp8
 }
+
+define i32 @pr80911_vector_load_multiuse(ptr %ptr, ptr %clobber) nounwind {
+; CHECK-LABEL: pr80911_vector_load_multiuse:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:pushl %esi
+; CHECK-NEXT:movl {{[0-9]+}}(%esp), %ecx
+; CHECK-NEXT:movl {{[0-9]+}}(%esp), %edx
+; CHECK-NEXT:movl (%edx), %esi
+; CHECK-NEXT:movzwl (%edx), %eax
+; CHECK-NEXT:movl $0, (%ecx)
+; CHECK-NEXT:movl %esi, (%edx)
+; CHECK-NEXT:popl %esi
+; CHECK-NEXT:retl
+;
+; CHECK64-LABEL: pr80911_vector_load_multiuse:
+; CHECK64:   # %bb.0:
+; CHECK64-NEXT:movl (%rdi), %ecx
+; CHECK64-NEXT:movzwl (%rdi), %eax
+; CHECK64-NEXT:movl $0, (%rsi)
+; CHECK64-NEXT:movl %ecx, (%rdi)
+; CHECK64-NEXT:retq
+  %load = load <4 x i8>, ptr %ptr, align 16
+  store i32 0, ptr %clobber
+  store <4 x i8> %load, ptr %ptr, align 16
+  %e1 = extractelement <4 x i8> %load, i64 1
+  %e1.ext = zext i8 %e1 to i32
+  %e1.ext.shift = shl nuw nsw i32 %e1.ext, 8
+  %e0 = extractelement <4 x i8> %load, i64 0
+  %e0.ext = zext i8 %e0 to i32
+  %res = or i32 %e1.ext.shift, %e0.ext
+  ret i32 %res
+}

``




https://github.com/llvm/llvm-project/pull/81633
___
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] [llvm] [PowerPC] Update V18.1.0 release notes (PR #81631)

2024-02-13 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic milestoned 
https://github.com/llvm/llvm-project/pull/81631
___
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] Backport [DAGCombine] Fix multi-use miscompile in load combine (#81586) (PR #81633)

2024-02-13 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic milestoned 
https://github.com/llvm/llvm-project/pull/81633
___
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] Update compiler version expected that seems to be embedded in CHECK line of test at llvm/test/CodeGen/SystemZ/zos-ppa2.ll. (PR #79523)

2024-02-13 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic milestoned 
https://github.com/llvm/llvm-project/pull/79523
___
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] Update compiler version expected that seems to be embedded in CHECK line of test at llvm/test/CodeGen/SystemZ/zos-ppa2.ll. (PR #79523)

2024-02-13 Thread Nikita Popov via llvm-branch-commits

nikic wrote:

A different fix for this was backported in 
https://github.com/llvm/llvm-project/commit/147c623a86b39d6bc9993293487b5773de943dad,
 so closing this PR.

https://github.com/llvm/llvm-project/pull/79523
___
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] Update compiler version expected that seems to be embedded in CHECK line of test at llvm/test/CodeGen/SystemZ/zos-ppa2.ll. (PR #79523)

2024-02-13 Thread Nikita Popov via llvm-branch-commits

https://github.com/nikic closed https://github.com/llvm/llvm-project/pull/79523
___
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] [llvm] [PowerPC] Update V18.1.0 release notes (PR #81631)

2024-02-13 Thread Amy Kwan via llvm-branch-commits

https://github.com/amy-kwan approved this pull request.

LGTM.

https://github.com/llvm/llvm-project/pull/81631
___
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] 9fad04c - Revert "[clang] Remove #undef alloca workaround (#81534)"

2024-02-13 Thread via llvm-branch-commits

Author: Prabhuk
Date: 2024-02-13T10:53:32-08:00
New Revision: 9fad04c4a52e00ed1b056de01546af75cc4e366b

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

LOG: Revert "[clang] Remove #undef alloca workaround (#81534)"

This reverts commit 742a06f577b4c3b1c1f994e91bb6579ae89fe4b0.

Added: 


Modified: 
clang/include/clang/Basic/Builtins.h

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index 6700d1903a008..f955d21169556 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -20,6 +20,10 @@
 #include "llvm/ADT/StringRef.h"
 #include 
 
+// VC++ defines 'alloca' as an object-like macro, which interferes with our
+// builtins.
+#undef alloca
+
 namespace clang {
 class TargetInfo;
 class IdentifierTable;



___
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: [libc++][modules] Re-add build dir CMakeLists.txt. (#81370) (PR #81651)

2024-02-13 Thread via llvm-branch-commits

https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/81651

Backport fc0e9c8315564288f9079a633892abadace534cf

Requested by: @mordante

>From a941f2122038e2472bce7deb6291cce3c8da3046 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Tue, 13 Feb 2024 20:04:34 +0100
Subject: [PATCH] [libc++][modules] Re-add build dir CMakeLists.txt. (#81370)

This CMakeLists.txt is used to build modules without build system
support. This was removed in d06ae33ec32122bb526fb35025c1f0cf979f1090.
This is used in the documentation how to use modules.

Made some minor changes to make it work with the std.compat module using
the std module.

Note the CMakeLists.txt in the build dir should be removed once build
system support is generally available.

(cherry picked from commit fc0e9c8315564288f9079a633892abadace534cf)
---
 libcxx/docs/Modules.rst  |  4 ++
 libcxx/modules/CMakeLists.txt| 20 
 libcxx/modules/CMakeLists.txt.in | 88 
 3 files changed, 112 insertions(+)
 create mode 100644 libcxx/modules/CMakeLists.txt.in

diff --git a/libcxx/docs/Modules.rst b/libcxx/docs/Modules.rst
index 533c3fbd2a1eea..ee2b81d3b9e7ca 100644
--- a/libcxx/docs/Modules.rst
+++ b/libcxx/docs/Modules.rst
@@ -218,9 +218,13 @@ Building this project is done with the following steps, 
assuming the files
 
   $ mkdir build
   $ cmake -G Ninja -S . -B build -DCMAKE_CXX_COMPILER= 
-DLIBCXX_BUILD=
+  $ ninja -j1 std -C build
   $ ninja -C build
   $ build/main
 
+.. note:: The ``std`` dependencies of ``std.compat`` is not always resolved 
when
+  building the ``std`` target using multiple jobs.
+
 .. warning::  should point point to the real binary and
  not to a symlink.
 
diff --git a/libcxx/modules/CMakeLists.txt b/libcxx/modules/CMakeLists.txt
index 0388c048dacb8b..0dea8cfca94ac3 100644
--- a/libcxx/modules/CMakeLists.txt
+++ b/libcxx/modules/CMakeLists.txt
@@ -137,6 +137,25 @@ set(LIBCXX_MODULE_STD_COMPAT_SOURCES
   std.compat/cwctype.inc
 )
 
+# TODO MODULES the CMakeLists.txt in the build directory is only temporary.
+# This allows using as available in the build directory. Once build systems
+# have proper support for the installed files this will be removed.
+if ("${LIBCXX_GENERATED_INCLUDE_DIR}" STREQUAL 
"${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}")
+  # This typically happens when the target is not installed.
+  set(LIBCXX_CONFIGURED_INCLUDE_DIRS "${LIBCXX_GENERATED_INCLUDE_DIR}")
+else()
+  # It's important that the arch directory be included first so that its 
header files
+  # which interpose on the default include dir be included instead of the 
default ones.
+  set(LIBCXX_CONFIGURED_INCLUDE_DIRS
+"${LIBCXX_GENERATED_INCLUDE_TARGET_DIR};${LIBCXX_GENERATED_INCLUDE_DIR}"
+  )
+endif()
+configure_file(
+  "CMakeLists.txt.in"
+  "${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt"
+  @ONLY
+)
+
 set(LIBCXX_MODULE_STD_INCLUDE_SOURCES)
 foreach(file ${LIBCXX_MODULE_STD_SOURCES})
   set(
@@ -166,6 +185,7 @@ configure_file(
 )
 
 set(_all_modules)
+list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt")
 list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.cppm")
 list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.compat.cppm")
 foreach(file ${LIBCXX_MODULE_STD_SOURCES} ${LIBCXX_MODULE_STD_COMPAT_SOURCES})
diff --git a/libcxx/modules/CMakeLists.txt.in b/libcxx/modules/CMakeLists.txt.in
new file mode 100644
index 00..e332d70cc16333
--- /dev/null
+++ b/libcxx/modules/CMakeLists.txt.in
@@ -0,0 +1,88 @@
+cmake_minimum_required(VERSION 3.26)
+
+project(libc++-modules LANGUAGES CXX)
+
+# Enable CMake's module support
+if(CMAKE_VERSION VERSION_LESS "3.28.0")
+  if(CMAKE_VERSION VERSION_LESS "3.27.0")
+set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API 
"2182bf5c-ef0d-489a-91da-49dbc3090d2a")
+  else()
+set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API 
"aa1f7df0-828a-4fcd-9afc-2dc80491aca7")
+  endif()
+  set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
+else()
+  cmake_policy(VERSION 3.28)
+endif()
+
+# Default to C++ extensions being off. Libc++'s modules support have trouble
+# with extensions right now.
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+# Propagates the CMake options to the modules.
+#
+# This uses the std module hard-coded since the std.compat module does not
+# depend on these flags.
+macro(compile_define_if_not condition def)
+  if (NOT ${condition})
+target_compile_definitions(std PRIVATE ${def})
+  endif()
+endmacro()
+macro(compile_define_if condition def)
+  if (${condition})
+target_compile_definitions(std PRIVATE ${def})
+  endif()
+endmacro()
+
+### STD
+
+add_library(std)
+target_sources(std
+  PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
+std.cppm
+)
+
+target_include_directories(std SYSTEM PRIVATE @LIBCXX_CONFIGURED_INCLUDE_DIRS@)
+
+if (NOT @LIBCXX_ENABLE_EXCEPTIONS@)
+  target_compile_options(std PUBLIC -fno-exceptions)
+endif()
+
+target_compile_options(std
+  PUBLIC
+-nostdinc++
+

[llvm-branch-commits] [libcxx] release/18.x: [libc++][modules] Re-add build dir CMakeLists.txt. (#81370) (PR #81651)

2024-02-13 Thread via llvm-branch-commits

https://github.com/llvmbot milestoned 
https://github.com/llvm/llvm-project/pull/81651
___
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: [libc++][modules] Re-add build dir CMakeLists.txt. (#81370) (PR #81651)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:

@ldionne What do you think about merging this PR to the release branch?

https://github.com/llvm/llvm-project/pull/81651
___
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: [libc++][modules] Re-add build dir CMakeLists.txt. (#81370) (PR #81651)

2024-02-13 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: None (llvmbot)


Changes

Backport fc0e9c8315564288f9079a633892abadace534cf

Requested by: @mordante

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


3 Files Affected:

- (modified) libcxx/docs/Modules.rst (+4) 
- (modified) libcxx/modules/CMakeLists.txt (+20) 
- (added) libcxx/modules/CMakeLists.txt.in (+88) 


``diff
diff --git a/libcxx/docs/Modules.rst b/libcxx/docs/Modules.rst
index 533c3fbd2a1eea..ee2b81d3b9e7ca 100644
--- a/libcxx/docs/Modules.rst
+++ b/libcxx/docs/Modules.rst
@@ -218,9 +218,13 @@ Building this project is done with the following steps, 
assuming the files
 
   $ mkdir build
   $ cmake -G Ninja -S . -B build -DCMAKE_CXX_COMPILER= 
-DLIBCXX_BUILD=
+  $ ninja -j1 std -C build
   $ ninja -C build
   $ build/main
 
+.. note:: The ``std`` dependencies of ``std.compat`` is not always resolved 
when
+  building the ``std`` target using multiple jobs.
+
 .. warning::  should point point to the real binary and
  not to a symlink.
 
diff --git a/libcxx/modules/CMakeLists.txt b/libcxx/modules/CMakeLists.txt
index 0388c048dacb8b..0dea8cfca94ac3 100644
--- a/libcxx/modules/CMakeLists.txt
+++ b/libcxx/modules/CMakeLists.txt
@@ -137,6 +137,25 @@ set(LIBCXX_MODULE_STD_COMPAT_SOURCES
   std.compat/cwctype.inc
 )
 
+# TODO MODULES the CMakeLists.txt in the build directory is only temporary.
+# This allows using as available in the build directory. Once build systems
+# have proper support for the installed files this will be removed.
+if ("${LIBCXX_GENERATED_INCLUDE_DIR}" STREQUAL 
"${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}")
+  # This typically happens when the target is not installed.
+  set(LIBCXX_CONFIGURED_INCLUDE_DIRS "${LIBCXX_GENERATED_INCLUDE_DIR}")
+else()
+  # It's important that the arch directory be included first so that its 
header files
+  # which interpose on the default include dir be included instead of the 
default ones.
+  set(LIBCXX_CONFIGURED_INCLUDE_DIRS
+"${LIBCXX_GENERATED_INCLUDE_TARGET_DIR};${LIBCXX_GENERATED_INCLUDE_DIR}"
+  )
+endif()
+configure_file(
+  "CMakeLists.txt.in"
+  "${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt"
+  @ONLY
+)
+
 set(LIBCXX_MODULE_STD_INCLUDE_SOURCES)
 foreach(file ${LIBCXX_MODULE_STD_SOURCES})
   set(
@@ -166,6 +185,7 @@ configure_file(
 )
 
 set(_all_modules)
+list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/CMakeLists.txt")
 list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.cppm")
 list(APPEND _all_modules "${LIBCXX_GENERATED_MODULE_DIR}/std.compat.cppm")
 foreach(file ${LIBCXX_MODULE_STD_SOURCES} ${LIBCXX_MODULE_STD_COMPAT_SOURCES})
diff --git a/libcxx/modules/CMakeLists.txt.in b/libcxx/modules/CMakeLists.txt.in
new file mode 100644
index 00..e332d70cc16333
--- /dev/null
+++ b/libcxx/modules/CMakeLists.txt.in
@@ -0,0 +1,88 @@
+cmake_minimum_required(VERSION 3.26)
+
+project(libc++-modules LANGUAGES CXX)
+
+# Enable CMake's module support
+if(CMAKE_VERSION VERSION_LESS "3.28.0")
+  if(CMAKE_VERSION VERSION_LESS "3.27.0")
+set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API 
"2182bf5c-ef0d-489a-91da-49dbc3090d2a")
+  else()
+set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API 
"aa1f7df0-828a-4fcd-9afc-2dc80491aca7")
+  endif()
+  set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
+else()
+  cmake_policy(VERSION 3.28)
+endif()
+
+# Default to C++ extensions being off. Libc++'s modules support have trouble
+# with extensions right now.
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+# Propagates the CMake options to the modules.
+#
+# This uses the std module hard-coded since the std.compat module does not
+# depend on these flags.
+macro(compile_define_if_not condition def)
+  if (NOT ${condition})
+target_compile_definitions(std PRIVATE ${def})
+  endif()
+endmacro()
+macro(compile_define_if condition def)
+  if (${condition})
+target_compile_definitions(std PRIVATE ${def})
+  endif()
+endmacro()
+
+### STD
+
+add_library(std)
+target_sources(std
+  PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
+std.cppm
+)
+
+target_include_directories(std SYSTEM PRIVATE @LIBCXX_CONFIGURED_INCLUDE_DIRS@)
+
+if (NOT @LIBCXX_ENABLE_EXCEPTIONS@)
+  target_compile_options(std PUBLIC -fno-exceptions)
+endif()
+
+target_compile_options(std
+  PUBLIC
+-nostdinc++
+-Wno-reserved-module-identifier
+-Wno-reserved-user-defined-literal
+@LIBCXX_COMPILE_FLAGS@
+)
+set_target_properties(std
+  PROPERTIES
+OUTPUT_NAME   "c++std"
+)
+
+### STD.COMPAT
+
+add_library(std.compat)
+target_sources(std.compat
+  PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES
+std.compat.cppm
+)
+
+target_include_directories(std.compat SYSTEM PRIVATE 
@LIBCXX_CONFIGURED_INCLUDE_DIRS@)
+
+if (NOT @LIBCXX_ENABLE_EXCEPTIONS@)
+  target_compile_options(std.compat PUBLIC -fno-exceptions)
+endif()
+
+target_compile_options(std.compat
+  PUBLIC
+-nostdinc++
+-Wno-reserved-module-identifier
+-Wno-reserved-user-defined-literal
+   -fmodu

[llvm-branch-commits] [clang] [llvm] [PowerPC] Update V18.1.0 release notes (PR #81631)

2024-02-13 Thread Lei Huang via llvm-branch-commits

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

Just some nits for spacing.  Otherwise LGTM
Thx

https://github.com/llvm/llvm-project/pull/81631
___
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] [llvm] [PowerPC] Update V18.1.0 release notes (PR #81631)

2024-02-13 Thread Lei Huang via llvm-branch-commits


@@ -327,6 +352,12 @@ Changes to the LLVM tools
 
 * llvm-objcopy now supports ``--gap-fill`` and ``--pad-to`` options, for
   ELF input and binary output files only.
+* Supported parsing XCOFF auxiliary symbols in obj2yaml.

lei137 wrote:

nit: should be consistent for this section. Since other entries are all 
separated by empty line, we should follow suite.

https://github.com/llvm/llvm-project/pull/81631
___
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] [llvm] [PowerPC] Update V18.1.0 release notes (PR #81631)

2024-02-13 Thread Lei Huang via llvm-branch-commits


@@ -163,6 +163,30 @@ Changes to the MIPS Backend
 
 Changes to the PowerPC Backend
 --
+* LLJIT's JIT linker now defaults to JITLink on 64-bit ELFv2 targets.

lei137 wrote:

nit: Please add an empty line before this line.

https://github.com/llvm/llvm-project/pull/81631
___
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] [llvm] [PowerPC] Update V18.1.0 release notes (PR #81631)

2024-02-13 Thread Lei Huang via llvm-branch-commits

https://github.com/lei137 edited https://github.com/llvm/llvm-project/pull/81631
___
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] [llvm] [PowerPC] Update V18.1.0 release notes (PR #81631)

2024-02-13 Thread Lei Huang via llvm-branch-commits


@@ -163,6 +163,30 @@ Changes to the MIPS Backend
 
 Changes to the PowerPC Backend
 --
+* LLJIT's JIT linker now defaults to JITLink on 64-bit ELFv2 targets.
+* Initial-exec TLS model is supported on AIX.
+* Implemented new resource based scheduling model of POWER7 and POWER8.
+* ``frexp`` libcall now references correct symbol name for ``fp128``.
+* Optimized materialization of 64-bit immediates, code generation of
+  ``vec_promote`` and atomics.
+

lei137 wrote:

nit: don't need this empty line.

https://github.com/llvm/llvm-project/pull/81631
___
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] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-13 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 converted_to_draft 
https://github.com/llvm/llvm-project/pull/81051
___
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] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-13 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 updated 
https://github.com/llvm/llvm-project/pull/81051

>From 66dbbfef52bdc092cbd4ed619bba38c003f6063d Mon Sep 17 00:00:00 2001
From: mingmingl 
Date: Thu, 8 Feb 2024 09:07:27 -0800
Subject: [PATCH] [InstrProf] Add vtables with type metadata into symtab to
 look it up with GUID

---
 llvm/include/llvm/ProfileData/InstrProf.h| 19 +
 llvm/lib/ProfileData/InstrProf.cpp   | 87 ++--
 llvm/unittests/ProfileData/InstrProfTest.cpp | 55 +
 3 files changed, 138 insertions(+), 23 deletions(-)

diff --git a/llvm/include/llvm/ProfileData/InstrProf.h 
b/llvm/include/llvm/ProfileData/InstrProf.h
index 53108a093bf4dd..6e799cf8aa273e 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -487,8 +487,25 @@ class InstrProfSymtab {
 return "** External Symbol **";
   }
 
+  // Returns the canonical name of the given PGOName by stripping the names
+  // suffixes that begins with ".". If MayHaveUniqueSuffix is true, ".__uniq."
+  // suffix is kept in the canonical name.
+  StringRef getCanonicalName(StringRef PGOName, bool MayHaveUniqueSuffix);
+
+  // Add the function into the symbol table, by creating the following
+  // map entries:
+  // - 
+  // - 
+  // - 
+  // - 
+  // - (instrprof_error::malformed,
@@ -665,6 +683,7 @@ void InstrProfSymtab::finalizeSymtab() {
   if (Sorted)
 return;
   llvm::sort(MD5NameMap, less_first());
+  llvm::sort(MD5VTableMap, less_first());
   llvm::sort(MD5FuncMap, less_first());
   llvm::sort(AddrToMD5Map, less_first());
   AddrToMD5Map.erase(std::unique(AddrToMD5Map.begin(), AddrToMD5Map.end()),
diff --git a/llvm/lib/ProfileData/InstrProf.cpp 
b/llvm/lib/ProfileData/InstrProf.cpp
index 9ebcba10c860ff..a09a2bb0ba77cb 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -480,7 +480,9 @@ Error InstrProfSymtab::create(Module &M, bool InLTO) {
 Types.clear();
 G.getMetadata(LLVMContext::MD_type, Types);
 if (!Types.empty()) {
-  MD5VTableMap.emplace_back(G.getGUID(), &G);
+  if (Error E = addVTableWithName(
+  G, getIRPGOObjectName(G, InLTO, /* PGONameMetadata */ nullptr)))
+return E;
 }
   }
   Sorted = false;
@@ -488,6 +490,30 @@ Error InstrProfSymtab::create(Module &M, bool InLTO) {
   return Error::success();
 }
 
+Error InstrProfSymtab::addVTableWithName(GlobalVariable &VTable,
+ StringRef VTablePGOName) {
+  if (Error E = addVTableName(VTablePGOName))
+return E;
+
+  MD5VTableMap.emplace_back(GlobalValue::getGUID(VTablePGOName), &VTable);
+
+  // NOTE: `-funique-internal-linkage-names` doesn't uniqufy vtables, so no
+  // need to check ".__uniq."
+
+  // If a local-linkage vtable is promoted to have external linkage in ThinLTO,
+  // it will have `.llvm.` in its name. Use the name before externalization.
+  StringRef CanonicalName =
+  getCanonicalName(VTablePGOName, /* MayHaveUniqueSuffix= */ false);
+  if (CanonicalName != VTablePGOName) {
+if (Error E = addVTableName(CanonicalName))
+  return E;
+
+MD5VTableMap.emplace_back(GlobalValue::getGUID(CanonicalName), &VTable);
+  }
+
+  return Error::success();
+}
+
 /// \c NameStrings is a string composed of one of more possibly encoded
 /// sub-strings. The substrings are separated by 0 or more zero bytes. This
 /// method decodes the string and calls `NameCallback` for each substring.
@@ -560,35 +586,50 @@ Error 
InstrProfSymtab::initVTableNamesFromCompressedStrings(
   std::bind(&InstrProfSymtab::addVTableName, this, std::placeholders::_1));
 }
 
-Error InstrProfSymtab::addFuncWithName(Function &F, StringRef PGOFuncName) {
-  if (Error E = addFuncName(PGOFuncName))
-return E;
-  MD5FuncMap.emplace_back(Function::getGUID(PGOFuncName), &F);
+StringRef InstrProfSymtab::getCanonicalName(StringRef PGOName,
+bool MayHaveUniqueSuffix) {
+  size_t pos = 0;
   // In ThinLTO, local function may have been promoted to global and have
   // suffix ".llvm." added to the function name. We need to add the
   // stripped function name to the symbol table so that we can find a match
   // from profile.
   //
-  // We may have other suffixes similar as ".llvm." which are needed to
-  // be stripped before the matching, but ".__uniq." suffix which is used
-  // to differentiate internal linkage functions in different modules
-  // should be kept. Now this is the only suffix with the pattern ".xxx"
-  // which is kept before matching.
-  const std::string UniqSuffix = ".__uniq.";
-  auto pos = PGOFuncName.find(UniqSuffix);
-  // Search '.' after ".__uniq." if ".__uniq." exists, otherwise
-  // search '.' from the beginning.
-  if (pos != std::string::npos)
-pos += UniqSuffix.length();
-  else
-pos = 0;
-  pos = PGOFuncName.find('.', pos);
-  if (pos != std::string::npos && pos != 0) {
-StringRef OtherFuncName = PGOFuncName.s

[llvm-branch-commits] [mlir] release/18.x: [mlir] Skip invalid test on big endian platform (s390x) (#80246) (PR #81373)

2024-02-13 Thread via llvm-branch-commits

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/81373

>From 076953d250624b8fdf094f8bce260380e28595ad Mon Sep 17 00:00:00 2001
From: Kai Sasaki 
Date: Fri, 2 Feb 2024 17:07:44 +0900
Subject: [PATCH] [mlir] Skip invalid test on big endian platform (s390x)
 (#80246)

The buildbot test running on s390x platform keeps failing since [this
time](https://lab.llvm.org/buildbot/#/builders/199/builds/31136). This
is because of the dependency on the endianness of the platform. It
expects the format invalid in the big endian platform (s390x). We can
simply skip it.

See: https://discourse.llvm.org/t/mlir-s390x-linux-failure/76695
(cherry picked from commit 65ac8c16e028b23b49fd6b03817faa1ab6c0229d)
---
 .../Target/LLVMIR/llvmir-le-specific.mlir | 27 +++
 mlir/test/Target/LLVMIR/llvmir.mlir   | 23 
 2 files changed, 27 insertions(+), 23 deletions(-)
 create mode 100644 mlir/test/Target/LLVMIR/llvmir-le-specific.mlir

diff --git a/mlir/test/Target/LLVMIR/llvmir-le-specific.mlir 
b/mlir/test/Target/LLVMIR/llvmir-le-specific.mlir
new file mode 100644
index 00..f8d082082117cb
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/llvmir-le-specific.mlir
@@ -0,0 +1,27 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+// Decoding the attribute does not work on big-endian platforms currently
+// XFAIL: target=s390x-{{.*}}
+
+// CHECK{LITERAL}: @dense_resource_tensor_constant = internal constant [5 x 
float] [float 0x3FCA03408000, float 0xBFD04663, float 
0xBFD75DDF8000, float 0xBFDE074F4000, float 0x3FDDD3A1C000]
+llvm.mlir.global internal constant 
@dense_resource_tensor_constant(dense_resource : 
tensor<5xf32>) : !llvm.array<5 x f32>
+
+// CHECK{LITERAL}: @dense_resource_vector_constant = internal constant <5 x 
float> 
+llvm.mlir.global internal constant 
@dense_resource_vector_constant(dense_resource : 
vector<5xf32>) : vector<5xf32>
+
+
+// CHECK{LITERAL}: @dense_resource_multidim_tensor_constant = internal 
constant [1 x [2 x [2 x float]]] [[2 x [2 x float]] [[2 x float] [float 
0x3FD6B46A8000, float 0x3FD6781AC000], [2 x float] [float 
0xBFB45A2AA000, float 0x3FD77A5CA000]]]
+llvm.mlir.global internal constant 
@dense_resource_multidim_tensor_constant(dense_resource
 : tensor<1x2x2xf32>) : !llvm.array<1 x !llvm.array<2 x !llvm.array<2 x f32>>>
+
+// CHECK{LITERAL}: @dense_resource_multidim_vector_constant = internal 
constant [1 x [2 x <2 x float>]] [[2 x <2 x float>] [<2 x float> , <2 x float> ]]
+llvm.mlir.global internal constant 
@dense_resource_multidim_vector_constant(dense_resource
 : vector<1x2x2xf32>) : !llvm.array<1 x !llvm.array<2 x vector<2 x f32>>>
+
+// Resources are kept at end of file. New tests should be added above this.
+{-#
+  dialect_resources: {
+builtin: {
+  dense_resource_test_5xf32: 
"0x0800041A503E183382BEFCEEBABE7A3AF0BE0E9DEE3E",
+  dense_resource_test_2x2xf32: "0x080054A3B53ED6C0B33E55D1A2BDE5D2BB3E"
+}
+  }
+#-}
\ No newline at end of file
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir 
b/mlir/test/Target/LLVMIR/llvmir.mlir
index 448aa3a5d85d79..961c9484446845 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -101,19 +101,6 @@ llvm.mlir.global internal 
@dense_float_vector_3d(dense<[[[1.0, 2.0], [3.0, 4.0]]
 // CHECK{LITERAL}: @splat_float_vector_3d = internal global [2 x [2 x <2 x 
float>]] [[2 x <2 x float>] [<2 x float> , <2 x float> ], [2 x <2 x 
float>] [<2 x float> , <2 x float> 
]]
 llvm.mlir.global internal @splat_float_vector_3d(dense<42.0> : 
vector<2x2x2xf32>) : !llvm.array<2 x !llvm.array<2 x vector<2xf32>>>
 
-// CHECK{LITERAL}: @dense_resource_tensor_constant = internal constant [5 x 
float] [float 0x3FCA03408000, float 0xBFD04663, float 
0xBFD75DDF8000, float 0xBFDE074F4000, float 0x3FDDD3A1C000]
-llvm.mlir.global internal constant 
@dense_resource_tensor_constant(dense_resource : 
tensor<5xf32>) : !llvm.array<5 x f32>
-
-// CHECK{LITERAL}: @dense_resource_vector_constant = internal constant <5 x 
float> 
-llvm.mlir.global internal constant 
@dense_resource_vector_constant(dense_resource : 
vector<5xf32>) : vector<5xf32>
-
-
-// CHECK{LITERAL}: @dense_resource_multidim_tensor_constant = internal 
constant [1 x [2 x [2 x float]]] [[2 x [2 x float]] [[2 x float] [float 
0x3FD6B46A8000, float 0x3FD6781AC000], [2 x float] [float 
0xBFB45A2AA000, float 0x3FD77A5CA000]]]
-llvm.mlir.global internal constant 
@dense_resource_multidim_tensor_constant(dense_resource
 : tensor<1x2x2xf32>) : !llvm.array<1 x !llvm.array<2 x !llvm.array<2 x f32>>>
-
-// CHECK{LITERAL}: @dense_resource_multidim_vector_constant = internal 
constant [1 x [2 x <2 x float>]] [[2 x <2 x float>] [<2 x float> , <2 x float> ]]
-llvm.mlir.global internal constant 
@dense_resource_multidim_vector_constant(dense_resource
 : vector<1x2x2xf32>) : !llvm.array<1 x !ll

[llvm-branch-commits] [mlir] 076953d - [mlir] Skip invalid test on big endian platform (s390x) (#80246)

2024-02-13 Thread Tom Stellard via llvm-branch-commits

Author: Kai Sasaki
Date: 2024-02-13T11:39:15-08:00
New Revision: 076953d250624b8fdf094f8bce260380e28595ad

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

LOG: [mlir] Skip invalid test on big endian platform (s390x) (#80246)

The buildbot test running on s390x platform keeps failing since [this
time](https://lab.llvm.org/buildbot/#/builders/199/builds/31136). This
is because of the dependency on the endianness of the platform. It
expects the format invalid in the big endian platform (s390x). We can
simply skip it.

See: https://discourse.llvm.org/t/mlir-s390x-linux-failure/76695
(cherry picked from commit 65ac8c16e028b23b49fd6b03817faa1ab6c0229d)

Added: 
mlir/test/Target/LLVMIR/llvmir-le-specific.mlir

Modified: 
mlir/test/Target/LLVMIR/llvmir.mlir

Removed: 




diff  --git a/mlir/test/Target/LLVMIR/llvmir-le-specific.mlir 
b/mlir/test/Target/LLVMIR/llvmir-le-specific.mlir
new file mode 100644
index 00..f8d082082117cb
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/llvmir-le-specific.mlir
@@ -0,0 +1,27 @@
+// RUN: mlir-translate -mlir-to-llvmir -split-input-file %s | FileCheck %s
+
+// Decoding the attribute does not work on big-endian platforms currently
+// XFAIL: target=s390x-{{.*}}
+
+// CHECK{LITERAL}: @dense_resource_tensor_constant = internal constant [5 x 
float] [float 0x3FCA03408000, float 0xBFD04663, float 
0xBFD75DDF8000, float 0xBFDE074F4000, float 0x3FDDD3A1C000]
+llvm.mlir.global internal constant 
@dense_resource_tensor_constant(dense_resource : 
tensor<5xf32>) : !llvm.array<5 x f32>
+
+// CHECK{LITERAL}: @dense_resource_vector_constant = internal constant <5 x 
float> 
+llvm.mlir.global internal constant 
@dense_resource_vector_constant(dense_resource : 
vector<5xf32>) : vector<5xf32>
+
+
+// CHECK{LITERAL}: @dense_resource_multidim_tensor_constant = internal 
constant [1 x [2 x [2 x float]]] [[2 x [2 x float]] [[2 x float] [float 
0x3FD6B46A8000, float 0x3FD6781AC000], [2 x float] [float 
0xBFB45A2AA000, float 0x3FD77A5CA000]]]
+llvm.mlir.global internal constant 
@dense_resource_multidim_tensor_constant(dense_resource
 : tensor<1x2x2xf32>) : !llvm.array<1 x !llvm.array<2 x !llvm.array<2 x f32>>>
+
+// CHECK{LITERAL}: @dense_resource_multidim_vector_constant = internal 
constant [1 x [2 x <2 x float>]] [[2 x <2 x float>] [<2 x float> , <2 x float> ]]
+llvm.mlir.global internal constant 
@dense_resource_multidim_vector_constant(dense_resource
 : vector<1x2x2xf32>) : !llvm.array<1 x !llvm.array<2 x vector<2 x f32>>>
+
+// Resources are kept at end of file. New tests should be added above this.
+{-#
+  dialect_resources: {
+builtin: {
+  dense_resource_test_5xf32: 
"0x0800041A503E183382BEFCEEBABE7A3AF0BE0E9DEE3E",
+  dense_resource_test_2x2xf32: "0x080054A3B53ED6C0B33E55D1A2BDE5D2BB3E"
+}
+  }
+#-}
\ No newline at end of file

diff  --git a/mlir/test/Target/LLVMIR/llvmir.mlir 
b/mlir/test/Target/LLVMIR/llvmir.mlir
index 448aa3a5d85d79..961c9484446845 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -101,19 +101,6 @@ llvm.mlir.global internal 
@dense_float_vector_3d(dense<[[[1.0, 2.0], [3.0, 4.0]]
 // CHECK{LITERAL}: @splat_float_vector_3d = internal global [2 x [2 x <2 x 
float>]] [[2 x <2 x float>] [<2 x float> , <2 x float> ], [2 x <2 x 
float>] [<2 x float> , <2 x float> 
]]
 llvm.mlir.global internal @splat_float_vector_3d(dense<42.0> : 
vector<2x2x2xf32>) : !llvm.array<2 x !llvm.array<2 x vector<2xf32>>>
 
-// CHECK{LITERAL}: @dense_resource_tensor_constant = internal constant [5 x 
float] [float 0x3FCA03408000, float 0xBFD04663, float 
0xBFD75DDF8000, float 0xBFDE074F4000, float 0x3FDDD3A1C000]
-llvm.mlir.global internal constant 
@dense_resource_tensor_constant(dense_resource : 
tensor<5xf32>) : !llvm.array<5 x f32>
-
-// CHECK{LITERAL}: @dense_resource_vector_constant = internal constant <5 x 
float> 
-llvm.mlir.global internal constant 
@dense_resource_vector_constant(dense_resource : 
vector<5xf32>) : vector<5xf32>
-
-
-// CHECK{LITERAL}: @dense_resource_multidim_tensor_constant = internal 
constant [1 x [2 x [2 x float]]] [[2 x [2 x float]] [[2 x float] [float 
0x3FD6B46A8000, float 0x3FD6781AC000], [2 x float] [float 
0xBFB45A2AA000, float 0x3FD77A5CA000]]]
-llvm.mlir.global internal constant 
@dense_resource_multidim_tensor_constant(dense_resource
 : tensor<1x2x2xf32>) : !llvm.array<1 x !llvm.array<2 x !llvm.array<2 x f32>>>
-
-// CHECK{LITERAL}: @dense_resource_multidim_vector_constant = internal 
constant [1 x [2 x <2 x float>]] [[2 x <2 x float>] [<2 x float> , <2 x float> ]]
-llvm.mlir.global internal constant 
@dense_resource_multidim_vector_constant(dense_resource
 : vector<1x2x2xf32>) :

[llvm-branch-commits] [mlir] release/18.x: [mlir] Skip invalid test on big endian platform (s390x) (#80246) (PR #81373)

2024-02-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/81373
___
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] [llvm] release/18.x: [SPARC] Support reserving arbitrary general purpose registers (#74927) (PR #81397)

2024-02-13 Thread via llvm-branch-commits

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/81397

>From 50f8284ceadb56d8bb08d989b4563b9443e45b5f Mon Sep 17 00:00:00 2001
From: Koakuma 
Date: Sun, 11 Feb 2024 14:04:18 +0700
Subject: [PATCH] [SPARC] Support reserving arbitrary general purpose registers
 (#74927)

This adds support for marking arbitrary general purpose registers -
except for those with special purpose (G0, I6-I7, O6-O7) - as reserved,
as needed by some software like the Linux kernel.

(cherry picked from commit c2f9885a8aa3a820eefdacccf3fcc6b9d87e3284)
---
 clang/include/clang/Driver/Options.td |  12 ++
 clang/lib/Driver/ToolChains/Arch/Sparc.cpp|  81 
 clang/test/Driver/sparc-fixed-register.c  | 181 ++
 llvm/lib/Target/Sparc/Sparc.td|  14 ++
 llvm/lib/Target/Sparc/SparcISelLowering.cpp   |  43 +
 llvm/lib/Target/Sparc/SparcRegisterInfo.cpp   |  14 +-
 llvm/lib/Target/Sparc/SparcRegisterInfo.h |   1 +
 llvm/lib/Target/Sparc/SparcRegisterInfo.td|   4 +
 llvm/lib/Target/Sparc/SparcSubtarget.cpp  |   1 +
 llvm/lib/Target/Sparc/SparcSubtarget.h|  10 +
 llvm/test/CodeGen/SPARC/reserved-arg-regs.ll  |  25 +++
 .../test/CodeGen/SPARC/reserved-regs-named.ll |  13 ++
 .../SPARC/reserved-regs-unavailable.ll|  14 ++
 llvm/test/CodeGen/SPARC/reserved-regs.ll  |  17 ++
 14 files changed, 428 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/sparc-fixed-register.c
 create mode 100644 llvm/test/CodeGen/SPARC/reserved-arg-regs.ll
 create mode 100644 llvm/test/CodeGen/SPARC/reserved-regs-named.ll
 create mode 100644 llvm/test/CodeGen/SPARC/reserved-regs-unavailable.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e8d03fc2690235..175bedbfb4d01c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5815,6 +5815,18 @@ def mvis3 : Flag<["-"], "mvis3">, 
Group;
 def mno_vis3 : Flag<["-"], "mno-vis3">, Group;
 def mhard_quad_float : Flag<["-"], "mhard-quad-float">, 
Group;
 def msoft_quad_float : Flag<["-"], "msoft-quad-float">, 
Group;
+foreach i = 1 ... 7 in
+  def ffixed_g#i : Flag<["-"], "ffixed-g"#i>, Group,
+HelpText<"Reserve the G"#i#" register (SPARC only)">;
+foreach i = 0 ... 5 in
+  def ffixed_o#i : Flag<["-"], "ffixed-o"#i>, Group,
+HelpText<"Reserve the O"#i#" register (SPARC only)">;
+foreach i = 0 ... 7 in
+  def ffixed_l#i : Flag<["-"], "ffixed-l"#i>, Group,
+HelpText<"Reserve the L"#i#" register (SPARC only)">;
+foreach i = 0 ... 5 in
+  def ffixed_i#i : Flag<["-"], "ffixed-i"#i>, Group,
+HelpText<"Reserve the I"#i#" register (SPARC only)">;
 } // let Flags = [TargetSpecific]
 
 // M68k features flags
diff --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp 
b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index 22e583021515e5..ae1a4ba7882627 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -178,4 +178,85 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
ArgList &Args,
 else
   Features.push_back("-hard-quad-float");
   }
+
+  if (Args.hasArg(options::OPT_ffixed_g1))
+Features.push_back("+reserve-g1");
+
+  if (Args.hasArg(options::OPT_ffixed_g2))
+Features.push_back("+reserve-g2");
+
+  if (Args.hasArg(options::OPT_ffixed_g3))
+Features.push_back("+reserve-g3");
+
+  if (Args.hasArg(options::OPT_ffixed_g4))
+Features.push_back("+reserve-g4");
+
+  if (Args.hasArg(options::OPT_ffixed_g5))
+Features.push_back("+reserve-g5");
+
+  if (Args.hasArg(options::OPT_ffixed_g6))
+Features.push_back("+reserve-g6");
+
+  if (Args.hasArg(options::OPT_ffixed_g7))
+Features.push_back("+reserve-g7");
+
+  if (Args.hasArg(options::OPT_ffixed_o0))
+Features.push_back("+reserve-o0");
+
+  if (Args.hasArg(options::OPT_ffixed_o1))
+Features.push_back("+reserve-o1");
+
+  if (Args.hasArg(options::OPT_ffixed_o2))
+Features.push_back("+reserve-o2");
+
+  if (Args.hasArg(options::OPT_ffixed_o3))
+Features.push_back("+reserve-o3");
+
+  if (Args.hasArg(options::OPT_ffixed_o4))
+Features.push_back("+reserve-o4");
+
+  if (Args.hasArg(options::OPT_ffixed_o5))
+Features.push_back("+reserve-o5");
+
+  if (Args.hasArg(options::OPT_ffixed_l0))
+Features.push_back("+reserve-l0");
+
+  if (Args.hasArg(options::OPT_ffixed_l1))
+Features.push_back("+reserve-l1");
+
+  if (Args.hasArg(options::OPT_ffixed_l2))
+Features.push_back("+reserve-l2");
+
+  if (Args.hasArg(options::OPT_ffixed_l3))
+Features.push_back("+reserve-l3");
+
+  if (Args.hasArg(options::OPT_ffixed_l4))
+Features.push_back("+reserve-l4");
+
+  if (Args.hasArg(options::OPT_ffixed_l5))
+Features.push_back("+reserve-l5");
+
+  if (Args.hasArg(options::OPT_ffixed_l6))
+Features.push_back("+reserve-l6");
+
+  if (Args.hasArg(options::OPT_ffixed_l7))
+Features.push_back("+reserve-l7");
+
+  if (Args.hasArg(opti

[llvm-branch-commits] [clang] 50f8284 - [SPARC] Support reserving arbitrary general purpose registers (#74927)

2024-02-13 Thread Tom Stellard via llvm-branch-commits

Author: Koakuma
Date: 2024-02-13T11:42:37-08:00
New Revision: 50f8284ceadb56d8bb08d989b4563b9443e45b5f

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

LOG: [SPARC] Support reserving arbitrary general purpose registers (#74927)

This adds support for marking arbitrary general purpose registers -
except for those with special purpose (G0, I6-I7, O6-O7) - as reserved,
as needed by some software like the Linux kernel.

(cherry picked from commit c2f9885a8aa3a820eefdacccf3fcc6b9d87e3284)

Added: 
clang/test/Driver/sparc-fixed-register.c
llvm/test/CodeGen/SPARC/reserved-arg-regs.ll
llvm/test/CodeGen/SPARC/reserved-regs-named.ll
llvm/test/CodeGen/SPARC/reserved-regs-unavailable.ll

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Arch/Sparc.cpp
llvm/lib/Target/Sparc/Sparc.td
llvm/lib/Target/Sparc/SparcISelLowering.cpp
llvm/lib/Target/Sparc/SparcRegisterInfo.cpp
llvm/lib/Target/Sparc/SparcRegisterInfo.h
llvm/lib/Target/Sparc/SparcRegisterInfo.td
llvm/lib/Target/Sparc/SparcSubtarget.cpp
llvm/lib/Target/Sparc/SparcSubtarget.h
llvm/test/CodeGen/SPARC/reserved-regs.ll

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e8d03fc2690235..175bedbfb4d01c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5815,6 +5815,18 @@ def mvis3 : Flag<["-"], "mvis3">, 
Group;
 def mno_vis3 : Flag<["-"], "mno-vis3">, Group;
 def mhard_quad_float : Flag<["-"], "mhard-quad-float">, 
Group;
 def msoft_quad_float : Flag<["-"], "msoft-quad-float">, 
Group;
+foreach i = 1 ... 7 in
+  def ffixed_g#i : Flag<["-"], "ffixed-g"#i>, Group,
+HelpText<"Reserve the G"#i#" register (SPARC only)">;
+foreach i = 0 ... 5 in
+  def ffixed_o#i : Flag<["-"], "ffixed-o"#i>, Group,
+HelpText<"Reserve the O"#i#" register (SPARC only)">;
+foreach i = 0 ... 7 in
+  def ffixed_l#i : Flag<["-"], "ffixed-l"#i>, Group,
+HelpText<"Reserve the L"#i#" register (SPARC only)">;
+foreach i = 0 ... 5 in
+  def ffixed_i#i : Flag<["-"], "ffixed-i"#i>, Group,
+HelpText<"Reserve the I"#i#" register (SPARC only)">;
 } // let Flags = [TargetSpecific]
 
 // M68k features flags

diff  --git a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp 
b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
index 22e583021515e5..ae1a4ba7882627 100644
--- a/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Sparc.cpp
@@ -178,4 +178,85 @@ void sparc::getSparcTargetFeatures(const Driver &D, const 
ArgList &Args,
 else
   Features.push_back("-hard-quad-float");
   }
+
+  if (Args.hasArg(options::OPT_ffixed_g1))
+Features.push_back("+reserve-g1");
+
+  if (Args.hasArg(options::OPT_ffixed_g2))
+Features.push_back("+reserve-g2");
+
+  if (Args.hasArg(options::OPT_ffixed_g3))
+Features.push_back("+reserve-g3");
+
+  if (Args.hasArg(options::OPT_ffixed_g4))
+Features.push_back("+reserve-g4");
+
+  if (Args.hasArg(options::OPT_ffixed_g5))
+Features.push_back("+reserve-g5");
+
+  if (Args.hasArg(options::OPT_ffixed_g6))
+Features.push_back("+reserve-g6");
+
+  if (Args.hasArg(options::OPT_ffixed_g7))
+Features.push_back("+reserve-g7");
+
+  if (Args.hasArg(options::OPT_ffixed_o0))
+Features.push_back("+reserve-o0");
+
+  if (Args.hasArg(options::OPT_ffixed_o1))
+Features.push_back("+reserve-o1");
+
+  if (Args.hasArg(options::OPT_ffixed_o2))
+Features.push_back("+reserve-o2");
+
+  if (Args.hasArg(options::OPT_ffixed_o3))
+Features.push_back("+reserve-o3");
+
+  if (Args.hasArg(options::OPT_ffixed_o4))
+Features.push_back("+reserve-o4");
+
+  if (Args.hasArg(options::OPT_ffixed_o5))
+Features.push_back("+reserve-o5");
+
+  if (Args.hasArg(options::OPT_ffixed_l0))
+Features.push_back("+reserve-l0");
+
+  if (Args.hasArg(options::OPT_ffixed_l1))
+Features.push_back("+reserve-l1");
+
+  if (Args.hasArg(options::OPT_ffixed_l2))
+Features.push_back("+reserve-l2");
+
+  if (Args.hasArg(options::OPT_ffixed_l3))
+Features.push_back("+reserve-l3");
+
+  if (Args.hasArg(options::OPT_ffixed_l4))
+Features.push_back("+reserve-l4");
+
+  if (Args.hasArg(options::OPT_ffixed_l5))
+Features.push_back("+reserve-l5");
+
+  if (Args.hasArg(options::OPT_ffixed_l6))
+Features.push_back("+reserve-l6");
+
+  if (Args.hasArg(options::OPT_ffixed_l7))
+Features.push_back("+reserve-l7");
+
+  if (Args.hasArg(options::OPT_ffixed_i0))
+Features.push_back("+reserve-i0");
+
+  if (Args.hasArg(options::OPT_ffixed_i1))
+Features.push_back("+reserve-i1");
+
+  if (Args.hasArg(options::OPT_ffixed_i2))
+Features.push_back("+reserve-i2");
+
+  if (Args.hasArg(options::OPT_ffixed_i3))
+Featu

[llvm-branch-commits] [clang] [llvm] release/18.x: [SPARC] Support reserving arbitrary general purpose registers (#74927) (PR #81397)

2024-02-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/81397
___
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] release/18.x: [LLD] [test] Avoid printing timestamps past INT32_MAX with llvm-readobj (#81463) (PR #81468)

2024-02-13 Thread via llvm-branch-commits

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/81468

>From 58b2a6d3bcd0696e5014958d6e2fae967a1627f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Mon, 12 Feb 2024 13:22:45 +0200
Subject: [PATCH] [LLD] [test] Avoid printing timestamps past INT32_MAX with
 llvm-readobj (#81463)

If llvm-readobj is built with a 32 bit time_t, it can't print such
timestamps correctly.

(cherry picked from commit 0bf4ff29816c0eead99ba576a2df2e3c4d214b1f)
---
 lld/test/COFF/timestamp.test | 29 +++--
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/lld/test/COFF/timestamp.test b/lld/test/COFF/timestamp.test
index c0658d6109811b..cc73af13c38ca6 100644
--- a/lld/test/COFF/timestamp.test
+++ b/lld/test/COFF/timestamp.test
@@ -4,19 +4,28 @@ RUN: lld-link %t.obj /debug /Brepro /entry:main /nodefaultlib 
/out:%t.1.exe
 RUN: lld-link %t.obj /debug /Brepro /entry:main /nodefaultlib /out:%t.2.exe
 RUN: lld-link %t.obj /debug /timestamp:0 /entry:main /nodefaultlib 
/out:%t.3.exe
 RUN: env SOURCE_DATE_EPOCH=0 lld-link %t.obj /debug /entry:main /nodefaultlib 
/out:%t.4.exe
-RUN: lld-link %t.obj /debug /timestamp:4294967295 /entry:main /nodefaultlib 
/out:%t.5.exe
-RUN: env SOURCE_DATE_EPOCH=4294967295 lld-link %t.obj /debug /entry:main 
/nodefaultlib /out:%t.6.exe
+# Test timestamps corresponding to INT32_TMAX
+RUN: lld-link %t.obj /debug /timestamp:2147483647 /entry:main /nodefaultlib 
/out:%t.5.exe
+RUN: env SOURCE_DATE_EPOCH=2147483647 lld-link %t.obj /debug /entry:main 
/nodefaultlib /out:%t.6.exe
+# Test that the command line option /timestamp has precedence over 
SOURCE_DATE_EPOCH
 RUN: env SOURCE_DATE_EPOCH=12345 lld-link %t.obj /debug /timestamp:0 
/entry:main /nodefaultlib /out:%t.7.exe
-RUN: env LLD_IN_TEST=1 not lld-link %t.obj /debug /timestamp:4294967296 
/entry:main /nodefaultlib /out:%t.8.exe 2>&1 | FileCheck %s --check-prefix=ERROR
-RUN: env SOURCE_DATE_EPOCH=4294967296 env LLD_IN_TEST=1 not lld-link %t.obj 
/debug /entry:main /nodefaultlib /out:%t.9.exe 2>&1 | FileCheck %s 
--check-prefix=ERROR2
+# Test timestamps corresponding to UINT32_TMAX
+RUN: lld-link %t.obj /debug /timestamp:4294967295 /entry:main /nodefaultlib 
/out:%t.8.exe
+RUN: env SOURCE_DATE_EPOCH=4294967295 lld-link %t.obj /debug /entry:main 
/nodefaultlib /out:%t.9.exe
+# Test that setting UINT32_MAX+1 as timestamp fails.
+RUN: env LLD_IN_TEST=1 not lld-link %t.obj /debug /timestamp:4294967296 
/entry:main /nodefaultlib /out:%t.10.exe 2>&1 | FileCheck %s 
--check-prefix=ERROR
+RUN: env SOURCE_DATE_EPOCH=4294967296 env LLD_IN_TEST=1 not lld-link %t.obj 
/debug /entry:main /nodefaultlib /out:%t.11.exe 2>&1 | FileCheck %s 
--check-prefix=ERROR2
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.1.exe | FileCheck 
%s --check-prefix=HASH
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.2.exe | FileCheck 
%s --check-prefix=HASH
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.3.exe | FileCheck 
%s --check-prefix=ZERO
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.4.exe | FileCheck 
%s --check-prefix=ZERO
-RUN: llvm-readobj --file-headers --coff-debug-directory %t.5.exe | FileCheck 
%s --check-prefix=MAX
-RUN: llvm-readobj --file-headers --coff-debug-directory %t.6.exe | FileCheck 
%s --check-prefix=MAX
+RUN: llvm-readobj --file-headers --coff-debug-directory %t.5.exe | FileCheck 
%s --check-prefix=LARGE
+RUN: llvm-readobj --file-headers --coff-debug-directory %t.6.exe | FileCheck 
%s --check-prefix=LARGE
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.7.exe | FileCheck 
%s --check-prefix=ZERO
 
+# Not inspecting %t.8.exe and %t.9.exe; llvm-readobj with a 32 bit time_t 
fails to print dates
+# past INT32_MAX correctly.
+
 HASH: ImageFileHeader {
 HASH: TimeDateStamp: [[STAMP:.*]]
 HASH: DebugDirectory [
@@ -27,10 +36,10 @@ ZERO: TimeDateStamp: 1970-01-01 00:00:00 (0x0)
 ZERO: DebugDirectory [
 ZERO: TimeDateStamp: 1970-01-01 00:00:00 (0x0)
 
-MAX: ImageFileHeader {
-MAX: TimeDateStamp: 2106-02-07 06:28:15 (0x)
-MAX: DebugDirectory [
-MAX: TimeDateStamp: 2106-02-07 06:28:15 (0x)
+LARGE: ImageFileHeader {
+LARGE: TimeDateStamp: 2038-01-19 03:14:07 (0x7FFF)
+LARGE: DebugDirectory [
+LARGE: TimeDateStamp: 2038-01-19 03:14:07 (0x7FFF)
 
 ERROR: error: invalid timestamp: 4294967296.  Expected 32-bit integer
 ERROR2: error: invalid SOURCE_DATE_EPOCH timestamp: 4294967296.  Expected 
32-bit integer

___
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] 58b2a6d - [LLD] [test] Avoid printing timestamps past INT32_MAX with llvm-readobj (#81463)

2024-02-13 Thread Tom Stellard via llvm-branch-commits

Author: Martin Storsjö
Date: 2024-02-13T11:44:00-08:00
New Revision: 58b2a6d3bcd0696e5014958d6e2fae967a1627f3

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

LOG: [LLD] [test] Avoid printing timestamps past INT32_MAX with llvm-readobj 
(#81463)

If llvm-readobj is built with a 32 bit time_t, it can't print such
timestamps correctly.

(cherry picked from commit 0bf4ff29816c0eead99ba576a2df2e3c4d214b1f)

Added: 


Modified: 
lld/test/COFF/timestamp.test

Removed: 




diff  --git a/lld/test/COFF/timestamp.test b/lld/test/COFF/timestamp.test
index c0658d6109811b..cc73af13c38ca6 100644
--- a/lld/test/COFF/timestamp.test
+++ b/lld/test/COFF/timestamp.test
@@ -4,19 +4,28 @@ RUN: lld-link %t.obj /debug /Brepro /entry:main /nodefaultlib 
/out:%t.1.exe
 RUN: lld-link %t.obj /debug /Brepro /entry:main /nodefaultlib /out:%t.2.exe
 RUN: lld-link %t.obj /debug /timestamp:0 /entry:main /nodefaultlib 
/out:%t.3.exe
 RUN: env SOURCE_DATE_EPOCH=0 lld-link %t.obj /debug /entry:main /nodefaultlib 
/out:%t.4.exe
-RUN: lld-link %t.obj /debug /timestamp:4294967295 /entry:main /nodefaultlib 
/out:%t.5.exe
-RUN: env SOURCE_DATE_EPOCH=4294967295 lld-link %t.obj /debug /entry:main 
/nodefaultlib /out:%t.6.exe
+# Test timestamps corresponding to INT32_TMAX
+RUN: lld-link %t.obj /debug /timestamp:2147483647 /entry:main /nodefaultlib 
/out:%t.5.exe
+RUN: env SOURCE_DATE_EPOCH=2147483647 lld-link %t.obj /debug /entry:main 
/nodefaultlib /out:%t.6.exe
+# Test that the command line option /timestamp has precedence over 
SOURCE_DATE_EPOCH
 RUN: env SOURCE_DATE_EPOCH=12345 lld-link %t.obj /debug /timestamp:0 
/entry:main /nodefaultlib /out:%t.7.exe
-RUN: env LLD_IN_TEST=1 not lld-link %t.obj /debug /timestamp:4294967296 
/entry:main /nodefaultlib /out:%t.8.exe 2>&1 | FileCheck %s --check-prefix=ERROR
-RUN: env SOURCE_DATE_EPOCH=4294967296 env LLD_IN_TEST=1 not lld-link %t.obj 
/debug /entry:main /nodefaultlib /out:%t.9.exe 2>&1 | FileCheck %s 
--check-prefix=ERROR2
+# Test timestamps corresponding to UINT32_TMAX
+RUN: lld-link %t.obj /debug /timestamp:4294967295 /entry:main /nodefaultlib 
/out:%t.8.exe
+RUN: env SOURCE_DATE_EPOCH=4294967295 lld-link %t.obj /debug /entry:main 
/nodefaultlib /out:%t.9.exe
+# Test that setting UINT32_MAX+1 as timestamp fails.
+RUN: env LLD_IN_TEST=1 not lld-link %t.obj /debug /timestamp:4294967296 
/entry:main /nodefaultlib /out:%t.10.exe 2>&1 | FileCheck %s 
--check-prefix=ERROR
+RUN: env SOURCE_DATE_EPOCH=4294967296 env LLD_IN_TEST=1 not lld-link %t.obj 
/debug /entry:main /nodefaultlib /out:%t.11.exe 2>&1 | FileCheck %s 
--check-prefix=ERROR2
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.1.exe | FileCheck 
%s --check-prefix=HASH
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.2.exe | FileCheck 
%s --check-prefix=HASH
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.3.exe | FileCheck 
%s --check-prefix=ZERO
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.4.exe | FileCheck 
%s --check-prefix=ZERO
-RUN: llvm-readobj --file-headers --coff-debug-directory %t.5.exe | FileCheck 
%s --check-prefix=MAX
-RUN: llvm-readobj --file-headers --coff-debug-directory %t.6.exe | FileCheck 
%s --check-prefix=MAX
+RUN: llvm-readobj --file-headers --coff-debug-directory %t.5.exe | FileCheck 
%s --check-prefix=LARGE
+RUN: llvm-readobj --file-headers --coff-debug-directory %t.6.exe | FileCheck 
%s --check-prefix=LARGE
 RUN: llvm-readobj --file-headers --coff-debug-directory %t.7.exe | FileCheck 
%s --check-prefix=ZERO
 
+# Not inspecting %t.8.exe and %t.9.exe; llvm-readobj with a 32 bit time_t 
fails to print dates
+# past INT32_MAX correctly.
+
 HASH: ImageFileHeader {
 HASH: TimeDateStamp: [[STAMP:.*]]
 HASH: DebugDirectory [
@@ -27,10 +36,10 @@ ZERO: TimeDateStamp: 1970-01-01 00:00:00 (0x0)
 ZERO: DebugDirectory [
 ZERO: TimeDateStamp: 1970-01-01 00:00:00 (0x0)
 
-MAX: ImageFileHeader {
-MAX: TimeDateStamp: 2106-02-07 06:28:15 (0x)
-MAX: DebugDirectory [
-MAX: TimeDateStamp: 2106-02-07 06:28:15 (0x)
+LARGE: ImageFileHeader {
+LARGE: TimeDateStamp: 2038-01-19 03:14:07 (0x7FFF)
+LARGE: DebugDirectory [
+LARGE: TimeDateStamp: 2038-01-19 03:14:07 (0x7FFF)
 
 ERROR: error: invalid timestamp: 4294967296.  Expected 32-bit integer
 ERROR2: error: invalid SOURCE_DATE_EPOCH timestamp: 4294967296.  Expected 
32-bit integer



___
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] release/18.x: [LLD] [test] Avoid printing timestamps past INT32_MAX with llvm-readobj (#81463) (PR #81468)

2024-02-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/81468
___
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: [AArch64][GISel] Don't pointlessly lower G_TRUNC (#81479) (PR #81581)

2024-02-13 Thread via llvm-branch-commits

https://github.com/llvmbot updated 
https://github.com/llvm/llvm-project/pull/81581

>From 831b9a5db2b7be590dcb09d0bf909ba37765a70b Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Tue, 13 Feb 2024 09:29:56 +0100
Subject: [PATCH] [AArch64][GISel] Don't pointlessly lower G_TRUNC (#81479)

If we have something like G_TRUNC from v2s32 to v2s16, then lowering
this to a concat of two G_TRUNC s32 to s16 followed by G_TRUNC from
v2s16 to v2s8 does not bring us any closer to legality. In fact, the
first part of that is a G_BUILD_VECTOR whose legalization will produce a
new G_TRUNC from v2s32 to v2s16, and both G_TRUNCs will then get
combined to the original, causing a legalization cycle.

Make the lowering condition more precise, by requiring that the original
vector is >128 bits, which is I believe the only case where this
specific splitting approach is useful.

Note that this doesn't actually produce a legal result (the alwaysLegal
is a lie, as before), but it will cause a proper globalisel abort
instead of an infinite legalization loop.

Fixes https://github.com/llvm/llvm-project/issues/81244.

(cherry picked from commit 070848c17c2944afa494d42d3ad42929f3379842)
---
 .../AArch64/GISel/AArch64LegalizerInfo.cpp|  5 ++--
 .../AArch64/GlobalISel/legalize-xtn.mir   | 24 +++
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp 
b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index fd69a7d6c33d03..4b9d549e791142 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -622,9 +622,8 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const 
AArch64Subtarget &ST)
   .lowerIf([=](const LegalityQuery &Query) {
 LLT DstTy = Query.Types[0];
 LLT SrcTy = Query.Types[1];
-return DstTy.isVector() && (SrcTy.getSizeInBits() > 128 ||
-(DstTy.getScalarSizeInBits() * 2 <
- SrcTy.getScalarSizeInBits()));
+return DstTy.isVector() && SrcTy.getSizeInBits() > 128 &&
+   DstTy.getScalarSizeInBits() * 2 <= SrcTy.getScalarSizeInBits();
   })
 
   .alwaysLegal();
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir 
b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir
index 16b780a8397347..661265173ae82b 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir
@@ -529,3 +529,27 @@ body: |
 RET_ReallyLR implicit $q0
 
 ...
+
+---
+name:pr81244
+tracksRegLiveness: true
+body: |
+  bb.0:
+liveins: $d0
+; CHECK-LABEL: name: pr81244
+; CHECK: liveins: $d0
+; CHECK-NEXT: {{  $}}
+; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<2 x s32>) = COPY $d0
+; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(<2 x s8>) = G_TRUNC [[COPY]](<2 x s32>)
+; CHECK-NEXT: [[CONCAT_VECTORS:%[0-9]+]]:_(<4 x s8>) = G_CONCAT_VECTORS 
[[TRUNC]](<2 x s8>), [[TRUNC]](<2 x s8>)
+; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(<4 x s16>) = G_ANYEXT 
[[CONCAT_VECTORS]](<4 x s8>)
+; CHECK-NEXT: $d0 = COPY [[ANYEXT]](<4 x s16>)
+; CHECK-NEXT: RET_ReallyLR implicit $d0
+%0:_(<2 x s32>) = COPY $d0
+%1:_(<2 x s8>) = G_TRUNC %0(<2 x s32>)
+%2:_(<4 x s8>) = G_CONCAT_VECTORS %1(<2 x s8>), %1(<2 x s8>)
+%3:_(<4 x s16>) = G_ANYEXT %2(<4 x s8>)
+$d0 = COPY %3(<4 x s16>)
+RET_ReallyLR implicit $d0
+
+...

___
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] 831b9a5 - [AArch64][GISel] Don't pointlessly lower G_TRUNC (#81479)

2024-02-13 Thread Tom Stellard via llvm-branch-commits

Author: Nikita Popov
Date: 2024-02-13T11:51:23-08:00
New Revision: 831b9a5db2b7be590dcb09d0bf909ba37765a70b

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

LOG: [AArch64][GISel] Don't pointlessly lower G_TRUNC (#81479)

If we have something like G_TRUNC from v2s32 to v2s16, then lowering
this to a concat of two G_TRUNC s32 to s16 followed by G_TRUNC from
v2s16 to v2s8 does not bring us any closer to legality. In fact, the
first part of that is a G_BUILD_VECTOR whose legalization will produce a
new G_TRUNC from v2s32 to v2s16, and both G_TRUNCs will then get
combined to the original, causing a legalization cycle.

Make the lowering condition more precise, by requiring that the original
vector is >128 bits, which is I believe the only case where this
specific splitting approach is useful.

Note that this doesn't actually produce a legal result (the alwaysLegal
is a lie, as before), but it will cause a proper globalisel abort
instead of an infinite legalization loop.

Fixes https://github.com/llvm/llvm-project/issues/81244.

(cherry picked from commit 070848c17c2944afa494d42d3ad42929f3379842)

Added: 


Modified: 
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir

Removed: 




diff  --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp 
b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index fd69a7d6c33d03..4b9d549e791142 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -622,9 +622,8 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const 
AArch64Subtarget &ST)
   .lowerIf([=](const LegalityQuery &Query) {
 LLT DstTy = Query.Types[0];
 LLT SrcTy = Query.Types[1];
-return DstTy.isVector() && (SrcTy.getSizeInBits() > 128 ||
-(DstTy.getScalarSizeInBits() * 2 <
- SrcTy.getScalarSizeInBits()));
+return DstTy.isVector() && SrcTy.getSizeInBits() > 128 &&
+   DstTy.getScalarSizeInBits() * 2 <= SrcTy.getScalarSizeInBits();
   })
 
   .alwaysLegal();

diff  --git a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir 
b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir
index 16b780a8397347..661265173ae82b 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-xtn.mir
@@ -529,3 +529,27 @@ body: |
 RET_ReallyLR implicit $q0
 
 ...
+
+---
+name:pr81244
+tracksRegLiveness: true
+body: |
+  bb.0:
+liveins: $d0
+; CHECK-LABEL: name: pr81244
+; CHECK: liveins: $d0
+; CHECK-NEXT: {{  $}}
+; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<2 x s32>) = COPY $d0
+; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(<2 x s8>) = G_TRUNC [[COPY]](<2 x s32>)
+; CHECK-NEXT: [[CONCAT_VECTORS:%[0-9]+]]:_(<4 x s8>) = G_CONCAT_VECTORS 
[[TRUNC]](<2 x s8>), [[TRUNC]](<2 x s8>)
+; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(<4 x s16>) = G_ANYEXT 
[[CONCAT_VECTORS]](<4 x s8>)
+; CHECK-NEXT: $d0 = COPY [[ANYEXT]](<4 x s16>)
+; CHECK-NEXT: RET_ReallyLR implicit $d0
+%0:_(<2 x s32>) = COPY $d0
+%1:_(<2 x s8>) = G_TRUNC %0(<2 x s32>)
+%2:_(<4 x s8>) = G_CONCAT_VECTORS %1(<2 x s8>), %1(<2 x s8>)
+%3:_(<4 x s16>) = G_ANYEXT %2(<4 x s8>)
+$d0 = COPY %3(<4 x s16>)
+RET_ReallyLR implicit $d0
+
+...



___
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: [AArch64][GISel] Don't pointlessly lower G_TRUNC (#81479) (PR #81581)

2024-02-13 Thread Tom Stellard via llvm-branch-commits

https://github.com/tstellar closed 
https://github.com/llvm/llvm-project/pull/81581
___
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] [llvm] [PowerPC] Update V18.1.0 release notes (PR #81631)

2024-02-13 Thread Maryam Moghadas via llvm-branch-commits

https://github.com/maryammo updated 
https://github.com/llvm/llvm-project/pull/81631

>From 627612dff3314b8250542ca951027b8ec8f7ac71 Mon Sep 17 00:00:00 2001
From: Maryam Moghadas 
Date: Mon, 12 Feb 2024 13:35:00 -0600
Subject: [PATCH 1/2] [PowerPC] Update V18.1.0 release notes

---
 clang/docs/ReleaseNotes.rst | 26 ++
 llvm/docs/ReleaseNotes.rst  | 37 +
 2 files changed, 63 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 95d44951ae7ee6..22eceea5d265ef 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -304,6 +304,10 @@ Non-comprehensive list of changes in this release
 
 * The version of Unicode used by Clang (primarily to parse identifiers) has 
been updated to 15.1.
 
+* Clang now defines macro ``__LLVM_INSTR_PROFILE_GENERATE`` when compiling with
+  PGO instrumentation profile generation, and ``__LLVM_INSTR_PROFILE_USE`` when
+  compiling with PGO profile use.
+
 New Compiler Flags
 --
 
@@ -344,6 +348,8 @@ New Compiler Flags
   attribute the replaceable global new and delete operators behave normally
   (like other functions) with respect to visibility attributes, pragmas and
   options (e.g ``--fvisibility=``).
+* Full register names can be used when printing assembly via ``-mregnames``.
+  This option now matches the one used by GCC.
 
 Deprecated Compiler Flags
 -
@@ -363,6 +369,7 @@ Modified Compiler Flags
 * ``-fvisibility-global-new-delete-hidden`` is now a deprecated spelling of
   ``-fvisibility-global-new-delete=force-hidden`` 
(``-fvisibility-global-new-delete=``
   is new in this release).
+* ``-fprofile-update`` is enabled for ``-fprofile-generate``.
 
 Removed Compiler Flags
 -
@@ -860,6 +867,9 @@ Bug Fixes in This Version
   Fixes (`#78290 `_)
 - Fixed assertion failure with deleted overloaded unary operators.
   Fixes (`#78314 `_)
+- The XCOFF object file format does not support aliases to symbols having 
common
+  linkage. Clang now diagnoses the use of an alias for a common symbol when
+  compiling for AIX.
 
 - Clang now doesn't produce false-positive warning `-Wconstant-logical-operand`
   for logical operators in C23.
@@ -1261,6 +1271,16 @@ CUDA Support
 - Clang now supports CUDA SDK up to 12.3
 - Added support for sm_90a
 
+PowerPC Support
+^^^
+
+- Added ``nmmintrin.h`` to intrinsics headers.
+- Added ``__builtin_ppc_fence`` as barrier of code motion, and
+  ``__builtin_ppc_mffsl`` for corresponding instruction.
+- Supported ``__attribute__((target("tune=cpu")))``.
+- Emit ``float-abi`` module flag on 64-bit ELFv2 PowerPC targets if
+  ``long double`` type is used in current module.
+
 AIX Support
 ^^^
 
@@ -1269,6 +1289,10 @@ AIX Support
   base is encoded as an immediate operand.
   This access sequence is not used for TLS variables larger than 32KB, and is
   currently only supported on 64-bit mode.
+- Inline assembler supports VSR register in pure digits.
+- Enabled ThinLTO support. Requires AIX 7.2 TL5 SP7 or newer, or AIX 7.3 TL2
+  or newer. Similar to the LTO support on AIX, ThinLTO is implemented with
+  the libLTO.so plugin.
 
 WebAssembly Support
 ^^^
@@ -1332,6 +1356,8 @@ libclang
 - Exposed arguments of ``clang::annotate``.
 - ``clang::getCursorKindForDecl`` now recognizes linkage specifications such as
   ``extern "C"`` and reports them as ``CXCursor_LinkageSpec``.
+- Changed the libclang library on AIX to export only the necessary symbols to
+  prevent issues of resolving to the wrong duplicate symbol.
 
 Static Analyzer
 ---
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 82f4a7a15c9c13..16acbb965c5c94 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -163,6 +163,30 @@ Changes to the MIPS Backend
 
 Changes to the PowerPC Backend
 --
+* LLJIT's JIT linker now defaults to JITLink on 64-bit ELFv2 targets.
+* Initial-exec TLS model is supported on AIX.
+* Implemented new resource based scheduling model of POWER7 and POWER8.
+* ``frexp`` libcall now references correct symbol name for ``fp128``.
+* Optimized materialization of 64-bit immediates, code generation of
+  ``vec_promote`` and atomics.
+
+* Global constant strings are pooled in the TOC under one entry to reduce the
+  number of entries in the TOC.
+* Added a number of missing Power10 extended mnemonics.
+* Added the SCV instruction.
+* Fixed register class for the paddi instruction.
+* Optimize VPERM and fix code order for swapping vector operands on LE.
+* Added various bug fixes and code gen improvements.
+
+AIX Support/improvements:
+
+* Support for a non-TOC-based access sequence for the local-exec TLS model 
(called small local-exec).
+* XCOFF toc-data peephole optimization and bug fix

[llvm-branch-commits] [clang] [llvm] [PowerPC] Update V18.1.0 release notes (PR #81631)

2024-02-13 Thread Maryam Moghadas via llvm-branch-commits


@@ -327,6 +352,12 @@ Changes to the LLVM tools
 
 * llvm-objcopy now supports ``--gap-fill`` and ``--pad-to`` options, for
   ELF input and binary output files only.
+* Supported parsing XCOFF auxiliary symbols in obj2yaml.

maryammo wrote:

done

https://github.com/llvm/llvm-project/pull/81631
___
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] [llvm] [PowerPC] Update V18.1.0 release notes (PR #81631)

2024-02-13 Thread Maryam Moghadas via llvm-branch-commits


@@ -163,6 +163,30 @@ Changes to the MIPS Backend
 
 Changes to the PowerPC Backend
 --
+* LLJIT's JIT linker now defaults to JITLink on 64-bit ELFv2 targets.

maryammo wrote:

done

https://github.com/llvm/llvm-project/pull/81631
___
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] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-13 Thread Teresa Johnson via llvm-branch-commits


@@ -479,15 +479,37 @@ Error InstrProfSymtab::create(Module &M, bool InLTO) {
   continue;
 Types.clear();
 G.getMetadata(LLVMContext::MD_type, Types);
-if (!Types.empty()) {
-  MD5VTableMap.emplace_back(G.getGUID(), &G);
-}
+if (Types.empty())
+  continue;
+if (Error E = addVTableWithName(
+  G, getIRPGOObjectName(G, InLTO, /* PGONameMetadata */ nullptr)))
+return E;
   }
   Sorted = false;
   finalizeSymtab();
   return Error::success();
 }
 
+Error InstrProfSymtab::addVTableWithName(GlobalVariable &VTable,
+ StringRef VTablePGOName) {
+  
+  auto mapName = [&](StringRef Name) -> Error {
+if (Error E = addVTableName(Name))

teresajohnson wrote:

Where is addVTableName defined?

https://github.com/llvm/llvm-project/pull/81051
___
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] Don't remove parentheses in macro definitions (#81444) (PR #81566)

2024-02-13 Thread Björn Schäpers via llvm-branch-commits

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


https://github.com/llvm/llvm-project/pull/81566
___
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] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-13 Thread Mingming Liu via llvm-branch-commits

https://github.com/minglotus-6 updated 
https://github.com/llvm/llvm-project/pull/81051

>From 66dbbfef52bdc092cbd4ed619bba38c003f6063d Mon Sep 17 00:00:00 2001
From: mingmingl 
Date: Thu, 8 Feb 2024 09:07:27 -0800
Subject: [PATCH 1/2] [InstrProf] Add vtables with type metadata into symtab to
 look it up with GUID

---
 llvm/include/llvm/ProfileData/InstrProf.h| 19 +
 llvm/lib/ProfileData/InstrProf.cpp   | 87 ++--
 llvm/unittests/ProfileData/InstrProfTest.cpp | 55 +
 3 files changed, 138 insertions(+), 23 deletions(-)

diff --git a/llvm/include/llvm/ProfileData/InstrProf.h 
b/llvm/include/llvm/ProfileData/InstrProf.h
index 53108a093bf4dd..6e799cf8aa273e 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -487,8 +487,25 @@ class InstrProfSymtab {
 return "** External Symbol **";
   }
 
+  // Returns the canonical name of the given PGOName by stripping the names
+  // suffixes that begins with ".". If MayHaveUniqueSuffix is true, ".__uniq."
+  // suffix is kept in the canonical name.
+  StringRef getCanonicalName(StringRef PGOName, bool MayHaveUniqueSuffix);
+
+  // Add the function into the symbol table, by creating the following
+  // map entries:
+  // - 
+  // - 
+  // - 
+  // - 
+  // - (instrprof_error::malformed,
@@ -665,6 +683,7 @@ void InstrProfSymtab::finalizeSymtab() {
   if (Sorted)
 return;
   llvm::sort(MD5NameMap, less_first());
+  llvm::sort(MD5VTableMap, less_first());
   llvm::sort(MD5FuncMap, less_first());
   llvm::sort(AddrToMD5Map, less_first());
   AddrToMD5Map.erase(std::unique(AddrToMD5Map.begin(), AddrToMD5Map.end()),
diff --git a/llvm/lib/ProfileData/InstrProf.cpp 
b/llvm/lib/ProfileData/InstrProf.cpp
index 9ebcba10c860ff..a09a2bb0ba77cb 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -480,7 +480,9 @@ Error InstrProfSymtab::create(Module &M, bool InLTO) {
 Types.clear();
 G.getMetadata(LLVMContext::MD_type, Types);
 if (!Types.empty()) {
-  MD5VTableMap.emplace_back(G.getGUID(), &G);
+  if (Error E = addVTableWithName(
+  G, getIRPGOObjectName(G, InLTO, /* PGONameMetadata */ nullptr)))
+return E;
 }
   }
   Sorted = false;
@@ -488,6 +490,30 @@ Error InstrProfSymtab::create(Module &M, bool InLTO) {
   return Error::success();
 }
 
+Error InstrProfSymtab::addVTableWithName(GlobalVariable &VTable,
+ StringRef VTablePGOName) {
+  if (Error E = addVTableName(VTablePGOName))
+return E;
+
+  MD5VTableMap.emplace_back(GlobalValue::getGUID(VTablePGOName), &VTable);
+
+  // NOTE: `-funique-internal-linkage-names` doesn't uniqufy vtables, so no
+  // need to check ".__uniq."
+
+  // If a local-linkage vtable is promoted to have external linkage in ThinLTO,
+  // it will have `.llvm.` in its name. Use the name before externalization.
+  StringRef CanonicalName =
+  getCanonicalName(VTablePGOName, /* MayHaveUniqueSuffix= */ false);
+  if (CanonicalName != VTablePGOName) {
+if (Error E = addVTableName(CanonicalName))
+  return E;
+
+MD5VTableMap.emplace_back(GlobalValue::getGUID(CanonicalName), &VTable);
+  }
+
+  return Error::success();
+}
+
 /// \c NameStrings is a string composed of one of more possibly encoded
 /// sub-strings. The substrings are separated by 0 or more zero bytes. This
 /// method decodes the string and calls `NameCallback` for each substring.
@@ -560,35 +586,50 @@ Error 
InstrProfSymtab::initVTableNamesFromCompressedStrings(
   std::bind(&InstrProfSymtab::addVTableName, this, std::placeholders::_1));
 }
 
-Error InstrProfSymtab::addFuncWithName(Function &F, StringRef PGOFuncName) {
-  if (Error E = addFuncName(PGOFuncName))
-return E;
-  MD5FuncMap.emplace_back(Function::getGUID(PGOFuncName), &F);
+StringRef InstrProfSymtab::getCanonicalName(StringRef PGOName,
+bool MayHaveUniqueSuffix) {
+  size_t pos = 0;
   // In ThinLTO, local function may have been promoted to global and have
   // suffix ".llvm." added to the function name. We need to add the
   // stripped function name to the symbol table so that we can find a match
   // from profile.
   //
-  // We may have other suffixes similar as ".llvm." which are needed to
-  // be stripped before the matching, but ".__uniq." suffix which is used
-  // to differentiate internal linkage functions in different modules
-  // should be kept. Now this is the only suffix with the pattern ".xxx"
-  // which is kept before matching.
-  const std::string UniqSuffix = ".__uniq.";
-  auto pos = PGOFuncName.find(UniqSuffix);
-  // Search '.' after ".__uniq." if ".__uniq." exists, otherwise
-  // search '.' from the beginning.
-  if (pos != std::string::npos)
-pos += UniqSuffix.length();
-  else
-pos = 0;
-  pos = PGOFuncName.find('.', pos);
-  if (pos != std::string::npos && pos != 0) {
-StringRef OtherFuncName = PGOFuncNa

[llvm-branch-commits] [llvm] Revert "[RISCV] Recurse on first operand of two operand shuffles (#79180)" (PR #80238)

2024-02-13 Thread Philip Reames via llvm-branch-commits

preames wrote:

@tstellar This backport has been outstanding for a while now.

https://github.com/llvm/llvm-project/pull/80238
___
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] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-13 Thread Mingming Liu via llvm-branch-commits


@@ -479,15 +479,37 @@ Error InstrProfSymtab::create(Module &M, bool InLTO) {
   continue;
 Types.clear();
 G.getMetadata(LLVMContext::MD_type, Types);
-if (!Types.empty()) {
-  MD5VTableMap.emplace_back(G.getGUID(), &G);
-}
+if (Types.empty())
+  continue;
+if (Error E = addVTableWithName(
+  G, getIRPGOObjectName(G, InLTO, /* PGONameMetadata */ nullptr)))
+return E;
   }
   Sorted = false;
   finalizeSymtab();
   return Error::success();
 }
 
+Error InstrProfSymtab::addVTableWithName(GlobalVariable &VTable,
+ StringRef VTablePGOName) {
+  
+  auto mapName = [&](StringRef Name) -> Error {
+if (Error E = addVTableName(Name))

minglotus-6 wrote:

This is 
[defined](https://github.com/llvm/llvm-project/pull/66825/files#diff-da37bd91946b34b8d50ced64d8e9f79455b61e8d29b304d0ae9fe3148bc6R556-R564)
 in InstrProf.h in the PR to instrument vtables and 
[used](https://github.com/llvm/llvm-project/pull/66825/files#diff-da37bd91946b34b8d50ced64d8e9f79455b61e8d29b304d0ae9fe3148bc6R642-R645)
 to add vtable strings from raw profiles (`InstrProfSymtab::create` called 
[here](https://github.com/llvm/llvm-project/pull/66825/files#diff-b196b796c5a396c7cdf93b347fe47e2b29b72d0b7dd0e2b88abb964d376ee50eR544-R545))

The diff is not shown in this PR, but I got a 
[link](https://github.com/llvm/llvm-project/pull/81051/files#diff-da37bd91946b34b8d50ced64d8e9f79455b61e8d29b304d0ae9fe3148bc6L579-L587)
 pointing to it. 

https://github.com/llvm/llvm-project/pull/81051
___
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] [llvm] [PowerPC] Update V18.1.0 release notes (PR #81631)

2024-02-13 Thread Tom Stellard via llvm-branch-commits

tstellar wrote:

Is this ready to merge?

https://github.com/llvm/llvm-project/pull/81631
___
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] [InstrProf] Add vtables with type metadata into symtab to look it up with GUID (PR #81051)

2024-02-13 Thread Mingming Liu via llvm-branch-commits

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


  1   2   >