[llvm-branch-commits] [llvm] 72cb20f - Revert "[llvm/DWARF] Recursively resolve DW_AT_signature references (#97423)"

2024-07-18 Thread via llvm-branch-commits

Author: Pavel Labath
Date: 2024-07-18T10:10:38+02:00
New Revision: 72cb20f417d48810bff7826e949ffddbaf93a721

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

LOG: Revert "[llvm/DWARF] Recursively resolve DW_AT_signature references 
(#97423)"

This reverts commit e93df78bd46b585c0bdabdbdc95410e4c08b9d38.

Added: 


Modified: 
llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
llvm/test/tools/llvm-dwarfdump/X86/prettyprint_type_units.s

Removed: 




diff  --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h 
b/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
index 497d3bee048ab..421b84d644db6 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
@@ -181,6 +181,8 @@ class DWARFDie {
   DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const;
   DWARFDie getAttributeValueAsReferencedDie(const DWARFFormValue &V) const;
 
+  DWARFDie resolveTypeUnitReference() const;
+
   /// Extract the range base attribute from this DIE as absolute section 
offset.
   ///
   /// This is a utility function that checks for either the DW_AT_rnglists_base

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp 
b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index 345a91a6f3585..72e7464b68971 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -103,6 +103,10 @@ static void dumpLocationExpr(raw_ostream &OS, const 
DWARFFormValue &FormValue,
   .print(OS, DumpOpts, U);
 }
 
+static DWARFDie resolveReferencedType(DWARFDie D, DWARFFormValue F) {
+  return D.getAttributeValueAsReferencedDie(F).resolveTypeUnitReference();
+}
+
 static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
   const DWARFAttribute &AttrValue, unsigned Indent,
   DIDumpOptions DumpOpts) {
@@ -194,8 +198,8 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie 
&Die,
 DINameKind::LinkageName))
   OS << Space << "\"" << Name << '\"';
   } else if (Attr == DW_AT_type || Attr == DW_AT_containing_type) {
-if (DWARFDie D = Die.getAttributeValueAsReferencedDie(FormValue);
-D && !D.isNULL()) {
+DWARFDie D = resolveReferencedType(Die, FormValue);
+if (D && !D.isNULL()) {
   OS << Space << "\"";
   dumpTypeQualifiedName(D, OS);
   OS << '"';
@@ -287,12 +291,13 @@ DWARFDie::findRecursively(ArrayRef 
Attrs) const {
 if (auto Value = Die.find(Attrs))
   return Value;
 
-for (dwarf::Attribute Attr :
- {DW_AT_abstract_origin, DW_AT_specification, DW_AT_signature}) {
-  if (auto D = Die.getAttributeValueAsReferencedDie(Attr))
-if (Seen.insert(D).second)
-  Worklist.push_back(D);
-}
+if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
+  if (Seen.insert(D).second)
+Worklist.push_back(D);
+
+if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_specification))
+  if (Seen.insert(D).second)
+Worklist.push_back(D);
   }
 
   return std::nullopt;
@@ -314,14 +319,21 @@ DWARFDie::getAttributeValueAsReferencedDie(const 
DWARFFormValue &V) const {
   } else if (Offset = V.getAsDebugInfoReference(); Offset) {
 if (DWARFUnit *SpecUnit = U->getUnitVector().getUnitForOffset(*Offset))
   Result = SpecUnit->getDIEForOffset(*Offset);
-  } else if (std::optional Sig = V.getAsSignatureReference()) {
-if (DWARFTypeUnit *TU = U->getContext().getTypeUnitForHash(
-U->getVersion(), *Sig, U->isDWOUnit()))
-  Result = TU->getDIEForOffset(TU->getTypeOffset() + TU->getOffset());
   }
   return Result;
 }
 
+DWARFDie DWARFDie::resolveTypeUnitReference() const {
+  if (auto Attr = find(DW_AT_signature)) {
+if (std::optional Sig = Attr->getAsReferenceUVal()) {
+  if (DWARFTypeUnit *TU = U->getContext().getTypeUnitForHash(
+  U->getVersion(), *Sig, U->isDWOUnit()))
+return TU->getDIEForOffset(TU->getTypeOffset() + TU->getOffset());
+}
+  }
+  return *this;
+}
+
 std::optional DWARFDie::getRangesBaseAttribute() const {
   return toSectionOffset(find({DW_AT_rnglists_base, DW_AT_GNU_ranges_base}));
 }

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp 
b/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
index fc1aae77a9293..a26431e8313f6 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
@@ -62,10 +62,17 @@ void DWARFTypePrinter::appendArrayType(const DWARFDie &D) {
   EndedWithTemplate = false;
 }
 
+static DWARFDie resolveReferencedType(DWARFDie D,
+  dwarf::Attribute Attr = DW_AT_type) {
+  return D.getAttributeValueAs

[llvm-branch-commits] [lld][ELF][LoongArch] Add support for R_LARCH_LE_{HI20, ADD, LO12}_R relocations (PR #99486)

2024-07-18 Thread via llvm-branch-commits

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

None


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


[llvm-branch-commits] [lld][ELF][LoongArch] Add support for R_LARCH_LE_{HI20, ADD, LO12}_R relocations (PR #99486)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lld-elf

Author: wanglei (wangleiat)


Changes



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


2 Files Affected:

- (modified) lld/ELF/Arch/LoongArch.cpp (+9) 
- (modified) lld/test/ELF/loongarch-tls-le.s (+44-3) 


``diff
diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index c6ee73f23d471..9466e8b1ce54d 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -11,6 +11,7 @@
 #include "Symbols.h"
 #include "SyntheticSections.h"
 #include "Target.h"
+#include "llvm/BinaryFormat/ELF.h"
 #include "llvm/Support/LEB128.h"
 
 using namespace llvm;
@@ -407,7 +408,9 @@ RelExpr LoongArch::getRelExpr(const RelType type, const 
Symbol &s,
   case R_LARCH_TLS_TPREL32:
   case R_LARCH_TLS_TPREL64:
   case R_LARCH_TLS_LE_HI20:
+  case R_LARCH_TLS_LE_HI20_R:
   case R_LARCH_TLS_LE_LO12:
+  case R_LARCH_TLS_LE_LO12_R:
   case R_LARCH_TLS_LE64_LO20:
   case R_LARCH_TLS_LE64_HI12:
 return R_TPREL;
@@ -490,6 +493,7 @@ RelExpr LoongArch::getRelExpr(const RelType type, const 
Symbol &s,
 return R_TLSLD_GOT;
   case R_LARCH_TLS_GD_HI20:
 return R_TLSGD_GOT;
+  case R_LARCH_TLS_LE_ADD_R:
   case R_LARCH_RELAX:
 return config->relax ? R_RELAX_HINT : R_NONE;
   case R_LARCH_ALIGN:
@@ -617,6 +621,7 @@ void LoongArch::relocate(uint8_t *loc, const Relocation 
&rel,
   case R_LARCH_TLS_LE_LO12:
   case R_LARCH_TLS_IE_PC_LO12:
   case R_LARCH_TLS_IE_LO12:
+  case R_LARCH_TLS_LE_LO12_R:
   case R_LARCH_TLS_DESC_PC_LO12:
   case R_LARCH_TLS_DESC_LO12:
 write32le(loc, setK12(read32le(loc), extractBits(val, 11, 0)));
@@ -638,6 +643,9 @@ void LoongArch::relocate(uint8_t *loc, const Relocation 
&rel,
   case R_LARCH_TLS_DESC_HI20:
 write32le(loc, setJ20(read32le(loc), extractBits(val, 31, 12)));
 return;
+  case R_LARCH_TLS_LE_HI20_R:
+write32le(loc, setJ20(read32le(loc), extractBits(val + 0x800, 31, 12)));
+return;
 
   // Relocs intended for `lu32i.d`.
   case R_LARCH_ABS64_LO20:
@@ -707,6 +715,7 @@ void LoongArch::relocate(uint8_t *loc, const Relocation 
&rel,
 // no-op
 return;
 
+  case R_LARCH_TLS_LE_ADD_R:
   case R_LARCH_RELAX:
 return; // Ignored (for now)
 
diff --git a/lld/test/ELF/loongarch-tls-le.s b/lld/test/ELF/loongarch-tls-le.s
index a20d7d83bae3f..394c60f67bce8 100644
--- a/lld/test/ELF/loongarch-tls-le.s
+++ b/lld/test/ELF/loongarch-tls-le.s
@@ -1,14 +1,14 @@
 # REQUIRES: loongarch
 
-# RUN: llvm-mc --filetype=obj --triple=loongarch32 %s -o %t.32.o
+# RUN: llvm-mc --filetype=obj --triple=loongarch32 --defsym ELF32=1 %s -o 
%t.32.o
 # RUN: llvm-mc --filetype=obj --triple=loongarch64 %s -o %t.64.o
 
 # RUN: ld.lld %t.32.o -o %t.32
 # RUN: llvm-nm -p %t.32 | FileCheck --check-prefixes=NM %s
-# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck 
--check-prefixes=LE %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck 
--check-prefixes=LE,LE32 %s
 
 # RUN: ld.lld %t.64.o -o %t.64
-# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck 
--check-prefixes=LE %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck 
--check-prefixes=LE,LE64 %s
 
 # RUN: not ld.lld -shared %t.32.o -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=ERR --implicit-check-not=error:
 
@@ -16,6 +16,10 @@
 # ERR: error: relocation R_LARCH_TLS_LE_LO12 against .LANCHOR0 cannot be used 
with -shared
 # ERR: error: relocation R_LARCH_TLS_LE_HI20 against a cannot be used with 
-shared
 # ERR: error: relocation R_LARCH_TLS_LE_LO12 against a cannot be used with 
-shared
+# ERR: error: relocation R_LARCH_TLS_LE_HI20_R against .LANCHOR0 cannot be 
used with -shared
+# ERR: error: relocation R_LARCH_TLS_LE_LO12_R against .LANCHOR0 cannot be 
used with -shared
+# ERR: error: relocation R_LARCH_TLS_LE_HI20_R against a cannot be used with 
-shared
+# ERR: error: relocation R_LARCH_TLS_LE_LO12_R against a cannot be used with 
-shared
 
 # NM: {{0*}}0008 b .LANCHOR0
 # NM: {{0*}}0800 B a
@@ -26,13 +30,50 @@
 # LE-NEXT: ori $a0, $a0, 8
 # LE-NEXT: lu12i.w $a1, 0
 # LE-NEXT: ori $a1, $a1, 2048
+
+# LE32:  add.w   $a0, $a0, $tp
+# LE32-NEXT: addi.w  $a0, $a0, 8
+# LE32-NEXT: lu12i.w $a0, 1
+# LE32-NEXT: add.w   $a0, $a0, $tp
+# LE32-NEXT: addi.w  $a0, $a0, -2048
+
+# LE64:  add.d   $a0, $a0, $tp
+# LE64-NEXT: addi.d  $a0, $a0, 8
+# LE64-NEXT: lu12i.w $a0, 1
+# LE64-NEXT: add.d   $a0, $a0, $tp
+# LE64-NEXT: addi.d  $a0, $a0, -2048
+
 # LE-EMPTY:
 
+.macro add dst, src1, src2, src3
+.ifdef ELF32
+add.w \dst, \src1, \src2, \src3
+.else
+add.d \dst, \src1, \src2, \src3
+.endif
+.endm
+.macro addi dst, src1, src2
+.ifdef ELF32
+addi.w \dst, \src1, \src2
+.else
+addi.d \dst, \src1, \src2
+.endif
+.endm
+
 .text
+
 _start:
 la.tls.le $a0, .LANCHOR0
 la.tls.le $a1, a
 
+lu12i.w $a0, %le_hi20_r(.LANCHOR0)
+add $a0, $a0, $tp, %le_add_r(.LANCHOR0)
+addi $a0, $a0, %le_lo12_r(.LANCHOR0)
+
+lu12i.w $a0, %le_hi20_r(a)
+add $a0, $a0, $tp, %le_add_r(a)
+addi $a0, $a0, %le_lo12_r(a)
+
 .s

[llvm-branch-commits] [lld][ELF][LoongArch] Add support for R_LARCH_LE_{HI20, ADD, LO12}_R relocations (PR #99486)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-lld

Author: wanglei (wangleiat)


Changes



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


2 Files Affected:

- (modified) lld/ELF/Arch/LoongArch.cpp (+9) 
- (modified) lld/test/ELF/loongarch-tls-le.s (+44-3) 


``diff
diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index c6ee73f23d471..9466e8b1ce54d 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -11,6 +11,7 @@
 #include "Symbols.h"
 #include "SyntheticSections.h"
 #include "Target.h"
+#include "llvm/BinaryFormat/ELF.h"
 #include "llvm/Support/LEB128.h"
 
 using namespace llvm;
@@ -407,7 +408,9 @@ RelExpr LoongArch::getRelExpr(const RelType type, const 
Symbol &s,
   case R_LARCH_TLS_TPREL32:
   case R_LARCH_TLS_TPREL64:
   case R_LARCH_TLS_LE_HI20:
+  case R_LARCH_TLS_LE_HI20_R:
   case R_LARCH_TLS_LE_LO12:
+  case R_LARCH_TLS_LE_LO12_R:
   case R_LARCH_TLS_LE64_LO20:
   case R_LARCH_TLS_LE64_HI12:
 return R_TPREL;
@@ -490,6 +493,7 @@ RelExpr LoongArch::getRelExpr(const RelType type, const 
Symbol &s,
 return R_TLSLD_GOT;
   case R_LARCH_TLS_GD_HI20:
 return R_TLSGD_GOT;
+  case R_LARCH_TLS_LE_ADD_R:
   case R_LARCH_RELAX:
 return config->relax ? R_RELAX_HINT : R_NONE;
   case R_LARCH_ALIGN:
@@ -617,6 +621,7 @@ void LoongArch::relocate(uint8_t *loc, const Relocation 
&rel,
   case R_LARCH_TLS_LE_LO12:
   case R_LARCH_TLS_IE_PC_LO12:
   case R_LARCH_TLS_IE_LO12:
+  case R_LARCH_TLS_LE_LO12_R:
   case R_LARCH_TLS_DESC_PC_LO12:
   case R_LARCH_TLS_DESC_LO12:
 write32le(loc, setK12(read32le(loc), extractBits(val, 11, 0)));
@@ -638,6 +643,9 @@ void LoongArch::relocate(uint8_t *loc, const Relocation 
&rel,
   case R_LARCH_TLS_DESC_HI20:
 write32le(loc, setJ20(read32le(loc), extractBits(val, 31, 12)));
 return;
+  case R_LARCH_TLS_LE_HI20_R:
+write32le(loc, setJ20(read32le(loc), extractBits(val + 0x800, 31, 12)));
+return;
 
   // Relocs intended for `lu32i.d`.
   case R_LARCH_ABS64_LO20:
@@ -707,6 +715,7 @@ void LoongArch::relocate(uint8_t *loc, const Relocation 
&rel,
 // no-op
 return;
 
+  case R_LARCH_TLS_LE_ADD_R:
   case R_LARCH_RELAX:
 return; // Ignored (for now)
 
diff --git a/lld/test/ELF/loongarch-tls-le.s b/lld/test/ELF/loongarch-tls-le.s
index a20d7d83bae3f..394c60f67bce8 100644
--- a/lld/test/ELF/loongarch-tls-le.s
+++ b/lld/test/ELF/loongarch-tls-le.s
@@ -1,14 +1,14 @@
 # REQUIRES: loongarch
 
-# RUN: llvm-mc --filetype=obj --triple=loongarch32 %s -o %t.32.o
+# RUN: llvm-mc --filetype=obj --triple=loongarch32 --defsym ELF32=1 %s -o 
%t.32.o
 # RUN: llvm-mc --filetype=obj --triple=loongarch64 %s -o %t.64.o
 
 # RUN: ld.lld %t.32.o -o %t.32
 # RUN: llvm-nm -p %t.32 | FileCheck --check-prefixes=NM %s
-# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck 
--check-prefixes=LE %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck 
--check-prefixes=LE,LE32 %s
 
 # RUN: ld.lld %t.64.o -o %t.64
-# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck 
--check-prefixes=LE %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck 
--check-prefixes=LE,LE64 %s
 
 # RUN: not ld.lld -shared %t.32.o -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=ERR --implicit-check-not=error:
 
@@ -16,6 +16,10 @@
 # ERR: error: relocation R_LARCH_TLS_LE_LO12 against .LANCHOR0 cannot be used 
with -shared
 # ERR: error: relocation R_LARCH_TLS_LE_HI20 against a cannot be used with 
-shared
 # ERR: error: relocation R_LARCH_TLS_LE_LO12 against a cannot be used with 
-shared
+# ERR: error: relocation R_LARCH_TLS_LE_HI20_R against .LANCHOR0 cannot be 
used with -shared
+# ERR: error: relocation R_LARCH_TLS_LE_LO12_R against .LANCHOR0 cannot be 
used with -shared
+# ERR: error: relocation R_LARCH_TLS_LE_HI20_R against a cannot be used with 
-shared
+# ERR: error: relocation R_LARCH_TLS_LE_LO12_R against a cannot be used with 
-shared
 
 # NM: {{0*}}0008 b .LANCHOR0
 # NM: {{0*}}0800 B a
@@ -26,13 +30,50 @@
 # LE-NEXT: ori $a0, $a0, 8
 # LE-NEXT: lu12i.w $a1, 0
 # LE-NEXT: ori $a1, $a1, 2048
+
+# LE32:  add.w   $a0, $a0, $tp
+# LE32-NEXT: addi.w  $a0, $a0, 8
+# LE32-NEXT: lu12i.w $a0, 1
+# LE32-NEXT: add.w   $a0, $a0, $tp
+# LE32-NEXT: addi.w  $a0, $a0, -2048
+
+# LE64:  add.d   $a0, $a0, $tp
+# LE64-NEXT: addi.d  $a0, $a0, 8
+# LE64-NEXT: lu12i.w $a0, 1
+# LE64-NEXT: add.d   $a0, $a0, $tp
+# LE64-NEXT: addi.d  $a0, $a0, -2048
+
 # LE-EMPTY:
 
+.macro add dst, src1, src2, src3
+.ifdef ELF32
+add.w \dst, \src1, \src2, \src3
+.else
+add.d \dst, \src1, \src2, \src3
+.endif
+.endm
+.macro addi dst, src1, src2
+.ifdef ELF32
+addi.w \dst, \src1, \src2
+.else
+addi.d \dst, \src1, \src2
+.endif
+.endm
+
 .text
+
 _start:
 la.tls.le $a0, .LANCHOR0
 la.tls.le $a1, a
 
+lu12i.w $a0, %le_hi20_r(.LANCHOR0)
+add $a0, $a0, $tp, %le_add_r(.LANCHOR0)
+addi $a0, $a0, %le_lo12_r(.LANCHOR0)
+
+lu12i.w $a0, %le_hi20_r(a)
+add $a0, $a0, $tp, %le_add_r(a)
+addi $a0, $a0, %le_lo12_r(a)
+
 .secti

[llvm-branch-commits] [lld][ELF][LoongArch] Add support for R_LARCH_LE_{HI20, ADD, LO12}_R relocations (PR #99486)

2024-07-18 Thread via llvm-branch-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/99486


___
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][ELF][LoongArch] Add support for R_LARCH_LE_{HI20, ADD, LO12}_R relocations (PR #99486)

2024-07-18 Thread via llvm-branch-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/99486


___
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] [mlir] [MLIR][OpenMP][Flang] Normalize clause arguments names (PR #99505)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: Sergio Afonso (skatrak)


Changes

Currently, there are some inconsistencies to how clause arguments are named in 
the OpenMP dialect. Additionally, the clause operand structures associated to 
them also diverge in certain cases. The purpose of this patch is to normalize 
argument names across all `OpenMP_Clause` tablegen definitions and clause 
operand structures.

This has the benefit of providing more consistent representations for clauses 
in the dialect, but the main short-term advantage is that it enables the 
development of an OpenMP-specific tablegen backend to automatically generate 
the clause operand structures without breaking dependent code.

The main re-naming decisions made in this patch are the following:
  - Variadic arguments (i.e. multiple values) have the "_vars" suffix. This and 
other similar suffixes are removed from array attribute arguments.
  - Individual required or optional value arguments do not have any suffix 
added to them (e.g. "val", "var", "expr", ...), except for `if` which would 
otherwise result in an invalid C++ variable name.
  - The associated clause's name is prepended to argument names that don't 
already contain it as part of its name. This avoids future collisions between 
arguments named the same way on different clauses and adding both clauses to 
the same operation.
  - Privatization and reduction related arguments that contain lists of symbols 
pointing to privatizer/reducer operations use the "_syms" suffix. This removes 
the inconsistencies between the names for "copyprivate_funcs", 
"[in]reductions", "privatizers", etc.
  - General improvements to names, replacement of camel case for snake case 
everywhere, etc.
  - Renaming of operation-associated operand structures to use the "Operands" 
suffix in place of "ClauseOps", to better differentiate between clause operand 
structures and operation operand structures.
  - Fields on clause operand structures are sorted according to the tablegen 
definition of the same clause.

The assembly format for a few arguments is updated to better reflect the clause 
they are associated with:
  - `chunk_size` -> `dist_schedule_chunk_size`
  - `grain_size` -> `grainsize`
  - `simd` -> `par_level_simd`

---

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


14 Files Affected:

- (modified) flang/lib/Lower/OpenMP/ClauseProcessor.cpp (+45-48) 
- (modified) flang/lib/Lower/OpenMP/DataSharingProcessor.cpp (+3-3) 
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+55-57) 
- (modified) flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp (+12-12) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h (+70-70) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td (+114-109) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+64-70) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td (+4-4) 
- (modified) mlir/lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp (+15-15) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+395-422) 
- (modified) 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+96-97) 
- (modified) mlir/test/Dialect/OpenMP/invalid.mlir (+20-20) 
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+23-23) 
- (modified) mlir/test/Target/LLVMIR/openmp-llvm.mlir (+4-4) 


``diff
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp 
b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index b26c1679086b9..76402f0b2aeb3 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -187,13 +187,13 @@ static void convertLoopBounds(lower::AbstractConverter 
&converter,
   // The types of lower bound, upper bound, and step are converted into the
   // type of the loop variable if necessary.
   mlir::Type loopVarType = getLoopVarType(converter, loopVarTypeSize);
-  for (unsigned it = 0; it < (unsigned)result.loopLBVar.size(); it++) {
-result.loopLBVar[it] =
-firOpBuilder.createConvert(loc, loopVarType, result.loopLBVar[it]);
-result.loopUBVar[it] =
-firOpBuilder.createConvert(loc, loopVarType, result.loopUBVar[it]);
-result.loopStepVar[it] =
-firOpBuilder.createConvert(loc, loopVarType, result.loopStepVar[it]);
+  for (unsigned it = 0; it < (unsigned)result.collapseLowerBound.size(); it++) 
{
+result.collapseLowerBound[it] = firOpBuilder.createConvert(
+loc, loopVarType, result.collapseLowerBound[it]);
+result.collapseUpperBound[it] = firOpBuilder.createConvert(
+loc, loopVarType, result.collapseUpperBound[it]);
+result.collapseStep[it] =
+firOpBuilder.createConvert(loc, loopVarType, result.collapseStep[it]);
   }
 }
 
@@ -232,15 +232,15 @@ bool ClauseProcessor::processCollapse(
 std::get_if(&loopControl->u);
 assert(bounds && "Expected bounds for worksharing do loop");
 lower::StatementConte

[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP][Flang] Normalize clause arguments names (PR #99505)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:



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

@llvm/pr-subscribers-mlir-llvm

Author: Sergio Afonso (skatrak)


Changes

Currently, there are some inconsistencies to how clause arguments are named in 
the OpenMP dialect. Additionally, the clause operand structures associated to 
them also diverge in certain cases. The purpose of this patch is to normalize 
argument names across all `OpenMP_Clause` tablegen definitions and clause 
operand structures.

This has the benefit of providing more consistent representations for clauses 
in the dialect, but the main short-term advantage is that it enables the 
development of an OpenMP-specific tablegen backend to automatically generate 
the clause operand structures without breaking dependent code.

The main re-naming decisions made in this patch are the following:
  - Variadic arguments (i.e. multiple values) have the "_vars" suffix. This and 
other similar suffixes are removed from array attribute arguments.
  - Individual required or optional value arguments do not have any suffix 
added to them (e.g. "val", "var", "expr", ...), except for `if` which would 
otherwise result in an invalid C++ variable name.
  - The associated clause's name is prepended to argument names that don't 
already contain it as part of its name. This avoids future collisions between 
arguments named the same way on different clauses and adding both clauses to 
the same operation.
  - Privatization and reduction related arguments that contain lists of symbols 
pointing to privatizer/reducer operations use the "_syms" suffix. This removes 
the inconsistencies between the names for "copyprivate_funcs", 
"[in]reductions", "privatizers", etc.
  - General improvements to names, replacement of camel case for snake case 
everywhere, etc.
  - Renaming of operation-associated operand structures to use the "Operands" 
suffix in place of "ClauseOps", to better differentiate between clause operand 
structures and operation operand structures.
  - Fields on clause operand structures are sorted according to the tablegen 
definition of the same clause.

The assembly format for a few arguments is updated to better reflect the clause 
they are associated with:
  - `chunk_size` -> `dist_schedule_chunk_size`
  - `grain_size` -> `grainsize`
  - `simd` -> `par_level_simd`

---

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


14 Files Affected:

- (modified) flang/lib/Lower/OpenMP/ClauseProcessor.cpp (+45-48) 
- (modified) flang/lib/Lower/OpenMP/DataSharingProcessor.cpp (+3-3) 
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+55-57) 
- (modified) flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp (+12-12) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h (+70-70) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td (+114-109) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+64-70) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td (+4-4) 
- (modified) mlir/lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp (+15-15) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+395-422) 
- (modified) 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+96-97) 
- (modified) mlir/test/Dialect/OpenMP/invalid.mlir (+20-20) 
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+23-23) 
- (modified) mlir/test/Target/LLVMIR/openmp-llvm.mlir (+4-4) 


``diff
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp 
b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index b26c1679086b9..76402f0b2aeb3 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -187,13 +187,13 @@ static void convertLoopBounds(lower::AbstractConverter 
&converter,
   // The types of lower bound, upper bound, and step are converted into the
   // type of the loop variable if necessary.
   mlir::Type loopVarType = getLoopVarType(converter, loopVarTypeSize);
-  for (unsigned it = 0; it < (unsigned)result.loopLBVar.size(); it++) {
-result.loopLBVar[it] =
-firOpBuilder.createConvert(loc, loopVarType, result.loopLBVar[it]);
-result.loopUBVar[it] =
-firOpBuilder.createConvert(loc, loopVarType, result.loopUBVar[it]);
-result.loopStepVar[it] =
-firOpBuilder.createConvert(loc, loopVarType, result.loopStepVar[it]);
+  for (unsigned it = 0; it < (unsigned)result.collapseLowerBound.size(); it++) 
{
+result.collapseLowerBound[it] = firOpBuilder.createConvert(
+loc, loopVarType, result.collapseLowerBound[it]);
+result.collapseUpperBound[it] = firOpBuilder.createConvert(
+loc, loopVarType, result.collapseUpperBound[it]);
+result.collapseStep[it] =
+firOpBuilder.createConvert(loc, loopVarType, result.collapseStep[it]);
   }
 }
 
@@ -232,15 +232,15 @@ bool ClauseProcessor::processCollapse(
 std::get_if(&loopControl->u);
 assert(bounds && "Expected 

[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP][Flang] Normalize clause arguments names (PR #99505)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-openmp

Author: Sergio Afonso (skatrak)


Changes

Currently, there are some inconsistencies to how clause arguments are named in 
the OpenMP dialect. Additionally, the clause operand structures associated to 
them also diverge in certain cases. The purpose of this patch is to normalize 
argument names across all `OpenMP_Clause` tablegen definitions and clause 
operand structures.

This has the benefit of providing more consistent representations for clauses 
in the dialect, but the main short-term advantage is that it enables the 
development of an OpenMP-specific tablegen backend to automatically generate 
the clause operand structures without breaking dependent code.

The main re-naming decisions made in this patch are the following:
  - Variadic arguments (i.e. multiple values) have the "_vars" suffix. This and 
other similar suffixes are removed from array attribute arguments.
  - Individual required or optional value arguments do not have any suffix 
added to them (e.g. "val", "var", "expr", ...), except for `if` which would 
otherwise result in an invalid C++ variable name.
  - The associated clause's name is prepended to argument names that don't 
already contain it as part of its name. This avoids future collisions between 
arguments named the same way on different clauses and adding both clauses to 
the same operation.
  - Privatization and reduction related arguments that contain lists of symbols 
pointing to privatizer/reducer operations use the "_syms" suffix. This removes 
the inconsistencies between the names for "copyprivate_funcs", 
"[in]reductions", "privatizers", etc.
  - General improvements to names, replacement of camel case for snake case 
everywhere, etc.
  - Renaming of operation-associated operand structures to use the "Operands" 
suffix in place of "ClauseOps", to better differentiate between clause operand 
structures and operation operand structures.
  - Fields on clause operand structures are sorted according to the tablegen 
definition of the same clause.

The assembly format for a few arguments is updated to better reflect the clause 
they are associated with:
  - `chunk_size` -> `dist_schedule_chunk_size`
  - `grain_size` -> `grainsize`
  - `simd` -> `par_level_simd`

---

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


14 Files Affected:

- (modified) flang/lib/Lower/OpenMP/ClauseProcessor.cpp (+45-48) 
- (modified) flang/lib/Lower/OpenMP/DataSharingProcessor.cpp (+3-3) 
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+55-57) 
- (modified) flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp (+12-12) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h (+70-70) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td (+114-109) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+64-70) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td (+4-4) 
- (modified) mlir/lib/Conversion/SCFToOpenMP/SCFToOpenMP.cpp (+15-15) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+395-422) 
- (modified) 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+96-97) 
- (modified) mlir/test/Dialect/OpenMP/invalid.mlir (+20-20) 
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+23-23) 
- (modified) mlir/test/Target/LLVMIR/openmp-llvm.mlir (+4-4) 


``diff
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp 
b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index b26c1679086b9..76402f0b2aeb3 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -187,13 +187,13 @@ static void convertLoopBounds(lower::AbstractConverter 
&converter,
   // The types of lower bound, upper bound, and step are converted into the
   // type of the loop variable if necessary.
   mlir::Type loopVarType = getLoopVarType(converter, loopVarTypeSize);
-  for (unsigned it = 0; it < (unsigned)result.loopLBVar.size(); it++) {
-result.loopLBVar[it] =
-firOpBuilder.createConvert(loc, loopVarType, result.loopLBVar[it]);
-result.loopUBVar[it] =
-firOpBuilder.createConvert(loc, loopVarType, result.loopUBVar[it]);
-result.loopStepVar[it] =
-firOpBuilder.createConvert(loc, loopVarType, result.loopStepVar[it]);
+  for (unsigned it = 0; it < (unsigned)result.collapseLowerBound.size(); it++) 
{
+result.collapseLowerBound[it] = firOpBuilder.createConvert(
+loc, loopVarType, result.collapseLowerBound[it]);
+result.collapseUpperBound[it] = firOpBuilder.createConvert(
+loc, loopVarType, result.collapseUpperBound[it]);
+result.collapseStep[it] =
+firOpBuilder.createConvert(loc, loopVarType, result.collapseStep[it]);
   }
 }
 
@@ -232,15 +232,15 @@ bool ClauseProcessor::processCollapse(
 std::get_if(&loopControl->u);
 assert(bounds && "Expected bounds for worksharing do loop");
 lower::StatementContex

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Create `LoopRelatedClause` (PR #99506)

2024-07-18 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak created 
https://github.com/llvm/llvm-project/pull/99506

This patch introduces a new OpenMP clause definition not defined by the spec.

Its main purpose is to define the `loop_inclusive` (previously "inclusive", 
renamed according to the parent of this PR in the stack) argument of 
`omp.loop_nest` in such a way that a followup implementation of a tablegen 
backend to automatically generate clause and operation operand structures 
directly from `OpenMP_Op` and `OpenMP_Clause` definitions can properly generate 
the `LoopNestOperands` structure.

>From dd05f1e30b0460705886b020047638a92e71a74c Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Tue, 16 Jul 2024 15:48:00 +0100
Subject: [PATCH] [MLIR][OpenMP] Create `LoopRelatedClause`

This patch introduces a new OpenMP clause definition not defined by the spec.

Its main purpose is to define the `loop_inclusive` (previously "inclusive",
renamed according to the parent of this PR in the stack) argument of
`omp.loop_nest` in such a way that a followup implementation of a tablegen
backend to automatically generate clause and operation operand structures
directly from `OpenMP_Op` and `OpenMP_Clause` definitions can properly generate
the `LoopNestOperands` structure.
---
 .../mlir/Dialect/OpenMP/OpenMPClauses.td  | 19 +++
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td |  6 ++
 mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp  |  4 ++--
 .../OpenMP/OpenMPToLLVMIRTranslation.cpp  |  2 +-
 mlir/test/Dialect/OpenMP/ops.mlir |  2 +-
 5 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
index 0846bc9d2189c..859801ca28da0 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
@@ -559,6 +559,25 @@ class OpenMP_LinearClauseSkip<
 
 def OpenMP_LinearClause : OpenMP_LinearClauseSkip<>;
 
+//===--===//
+// Not in the spec: Clause-like structure to hold loop related information.
+//===--===//
+
+class OpenMP_LoopRelatedClauseSkip<
+bit traits = false, bit arguments = false, bit assemblyFormat = false,
+bit description = false, bit extraClassDeclaration = false
+  > : OpenMP_Clause {
+  let arguments = (ins
+UnitAttr:$loop_inclusive
+  );
+
+  // Description and formatting integrated in the `omp.loop_nest` operation,
+  // which is the only one currently accepting this clause.
+}
+
+def OpenMP_LoopRelatedClause : OpenMP_LoopRelatedClauseSkip<>;
+
 
//===--===//
 // V5.2: [5.8.3] `map` clause
 
//===--===//
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 4b3120dddfa54..a4aeeacfea672 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -297,7 +297,7 @@ def SingleOp : OpenMP_Op<"single", traits = [
 def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
 RecursiveMemoryEffects, SameVariadicOperandSize
   ], clauses = [
-OpenMP_CollapseClause
+OpenMP_CollapseClause, OpenMP_LoopRelatedClause
   ], singleRegion = true> {
   let summary = "rectangular loop nest";
   let description = [{
@@ -306,7 +306,7 @@ def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
 lower and upper bounds, as well as a step variable, must be defined.
 
 The lower and upper bounds specify a half-open range: the range includes 
the
-lower bound but does not include the upper bound. If the `inclusive`
+lower bound but does not include the upper bound. If the `loop_inclusive`
 attribute is specified then the upper bound is also included.
 
 The body region can contain any number of blocks. The region is terminated
@@ -335,8 +335,6 @@ def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
 non-perfectly nested loops.
   }];
 
-  let arguments = !con(clausesArgs, (ins UnitAttr:$inclusive));
-
   let builders = [
 OpBuilder<(ins CArg<"const LoopNestOperands &">:$clauses)>
   ];
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 575133a4dfe2e..761eaa810038c 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -2047,7 +2047,7 @@ ParseResult LoopNestOp::parse(OpAsmParser &parser, 
OperationState &result) {
 
   // Parse "inclusive" flag.
   if (succeeded(parser.parseOptionalKeyword("inclusive")))
-result.addAttribute("inclusive",
+result.addAttribute("loop_inclusive",
 UnitAttr::get(parser.getBuilder().getContext()));
 
   // Parse step values.
@@ -2076,7 +2076,7 @@ void LoopNestOp::print(OpAsmP

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Create `LoopRelatedClause` (PR #99506)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-openmp

Author: Sergio Afonso (skatrak)


Changes

This patch introduces a new OpenMP clause definition not defined by the spec.

Its main purpose is to define the `loop_inclusive` (previously "inclusive", 
renamed according to the parent of this PR in the stack) argument of 
`omp.loop_nest` in such a way that a followup implementation of a tablegen 
backend to automatically generate clause and operation operand structures 
directly from `OpenMP_Op` and `OpenMP_Clause` definitions can properly generate 
the `LoopNestOperands` structure.

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


5 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td (+19) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+2-4) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+2-2) 
- (modified) 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+1-1) 
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+1-1) 


``diff
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
index 0846bc9d2189c..859801ca28da0 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
@@ -559,6 +559,25 @@ class OpenMP_LinearClauseSkip<
 
 def OpenMP_LinearClause : OpenMP_LinearClauseSkip<>;
 
+//===--===//
+// Not in the spec: Clause-like structure to hold loop related information.
+//===--===//
+
+class OpenMP_LoopRelatedClauseSkip<
+bit traits = false, bit arguments = false, bit assemblyFormat = false,
+bit description = false, bit extraClassDeclaration = false
+  > : OpenMP_Clause {
+  let arguments = (ins
+UnitAttr:$loop_inclusive
+  );
+
+  // Description and formatting integrated in the `omp.loop_nest` operation,
+  // which is the only one currently accepting this clause.
+}
+
+def OpenMP_LoopRelatedClause : OpenMP_LoopRelatedClauseSkip<>;
+
 
//===--===//
 // V5.2: [5.8.3] `map` clause
 
//===--===//
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 4b3120dddfa54..a4aeeacfea672 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -297,7 +297,7 @@ def SingleOp : OpenMP_Op<"single", traits = [
 def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
 RecursiveMemoryEffects, SameVariadicOperandSize
   ], clauses = [
-OpenMP_CollapseClause
+OpenMP_CollapseClause, OpenMP_LoopRelatedClause
   ], singleRegion = true> {
   let summary = "rectangular loop nest";
   let description = [{
@@ -306,7 +306,7 @@ def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
 lower and upper bounds, as well as a step variable, must be defined.
 
 The lower and upper bounds specify a half-open range: the range includes 
the
-lower bound but does not include the upper bound. If the `inclusive`
+lower bound but does not include the upper bound. If the `loop_inclusive`
 attribute is specified then the upper bound is also included.
 
 The body region can contain any number of blocks. The region is terminated
@@ -335,8 +335,6 @@ def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
 non-perfectly nested loops.
   }];
 
-  let arguments = !con(clausesArgs, (ins UnitAttr:$inclusive));
-
   let builders = [
 OpBuilder<(ins CArg<"const LoopNestOperands &">:$clauses)>
   ];
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 575133a4dfe2e..761eaa810038c 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -2047,7 +2047,7 @@ ParseResult LoopNestOp::parse(OpAsmParser &parser, 
OperationState &result) {
 
   // Parse "inclusive" flag.
   if (succeeded(parser.parseOptionalKeyword("inclusive")))
-result.addAttribute("inclusive",
+result.addAttribute("loop_inclusive",
 UnitAttr::get(parser.getBuilder().getContext()));
 
   // Parse step values.
@@ -2076,7 +2076,7 @@ void LoopNestOp::print(OpAsmPrinter &p) {
   auto args = region.getArguments();
   p << " (" << args << ") : " << args[0].getType() << " = ("
 << getCollapseLowerBound() << ") to (" << getCollapseUpperBound() << ") ";
-  if (getInclusive())
+  if (getLoopInclusive())
 p << "inclusive ";
   p << "step (" << getCollapseStep() << ") ";
   p.printRegion(region, /*printEntryBlockArgs=*/false);
diff --git 
a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp 
b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index b353468711047..fb6da86474b84 100644
-

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Create `LoopRelatedClause` (PR #99506)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-llvm

Author: Sergio Afonso (skatrak)


Changes

This patch introduces a new OpenMP clause definition not defined by the spec.

Its main purpose is to define the `loop_inclusive` (previously "inclusive", 
renamed according to the parent of this PR in the stack) argument of 
`omp.loop_nest` in such a way that a followup implementation of a tablegen 
backend to automatically generate clause and operation operand structures 
directly from `OpenMP_Op` and `OpenMP_Clause` definitions can properly generate 
the `LoopNestOperands` structure.

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


5 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td (+19) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+2-4) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+2-2) 
- (modified) 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+1-1) 
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+1-1) 


``diff
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
index 0846bc9d2189c..859801ca28da0 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauses.td
@@ -559,6 +559,25 @@ class OpenMP_LinearClauseSkip<
 
 def OpenMP_LinearClause : OpenMP_LinearClauseSkip<>;
 
+//===--===//
+// Not in the spec: Clause-like structure to hold loop related information.
+//===--===//
+
+class OpenMP_LoopRelatedClauseSkip<
+bit traits = false, bit arguments = false, bit assemblyFormat = false,
+bit description = false, bit extraClassDeclaration = false
+  > : OpenMP_Clause {
+  let arguments = (ins
+UnitAttr:$loop_inclusive
+  );
+
+  // Description and formatting integrated in the `omp.loop_nest` operation,
+  // which is the only one currently accepting this clause.
+}
+
+def OpenMP_LoopRelatedClause : OpenMP_LoopRelatedClauseSkip<>;
+
 
//===--===//
 // V5.2: [5.8.3] `map` clause
 
//===--===//
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 4b3120dddfa54..a4aeeacfea672 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -297,7 +297,7 @@ def SingleOp : OpenMP_Op<"single", traits = [
 def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
 RecursiveMemoryEffects, SameVariadicOperandSize
   ], clauses = [
-OpenMP_CollapseClause
+OpenMP_CollapseClause, OpenMP_LoopRelatedClause
   ], singleRegion = true> {
   let summary = "rectangular loop nest";
   let description = [{
@@ -306,7 +306,7 @@ def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
 lower and upper bounds, as well as a step variable, must be defined.
 
 The lower and upper bounds specify a half-open range: the range includes 
the
-lower bound but does not include the upper bound. If the `inclusive`
+lower bound but does not include the upper bound. If the `loop_inclusive`
 attribute is specified then the upper bound is also included.
 
 The body region can contain any number of blocks. The region is terminated
@@ -335,8 +335,6 @@ def LoopNestOp : OpenMP_Op<"loop_nest", traits = [
 non-perfectly nested loops.
   }];
 
-  let arguments = !con(clausesArgs, (ins UnitAttr:$inclusive));
-
   let builders = [
 OpBuilder<(ins CArg<"const LoopNestOperands &">:$clauses)>
   ];
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 575133a4dfe2e..761eaa810038c 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -2047,7 +2047,7 @@ ParseResult LoopNestOp::parse(OpAsmParser &parser, 
OperationState &result) {
 
   // Parse "inclusive" flag.
   if (succeeded(parser.parseOptionalKeyword("inclusive")))
-result.addAttribute("inclusive",
+result.addAttribute("loop_inclusive",
 UnitAttr::get(parser.getBuilder().getContext()));
 
   // Parse step values.
@@ -2076,7 +2076,7 @@ void LoopNestOp::print(OpAsmPrinter &p) {
   auto args = region.getArguments();
   p << " (" << args << ") : " << args[0].getType() << " = ("
 << getCollapseLowerBound() << ") to (" << getCollapseUpperBound() << ") ";
-  if (getInclusive())
+  if (getLoopInclusive())
 p << "inclusive ";
   p << "step (" << getCollapseStep() << ") ";
   p.printRegion(region, /*printEntryBlockArgs=*/false);
diff --git 
a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp 
b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index b353468711047..fb6da86474b84 100644
---

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Add missing clauses to OpenMP op definitions (PR #99507)

2024-07-18 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak created 
https://github.com/llvm/llvm-project/pull/99507

This patch adds the missing `OpenMP_Clause` definitions to all existing 
`OpenMP_Op`s and updates their operand structure based builders to initialize 
the new arguments.

The result of this change is that operation operand structures are now based in 
the same list of clauses as their tablegen counterparts. This means that all of 
the information needed is now in place to automatically generate OpenMP operand 
structures from tablegen defitions.

Since this change doesn't involve the introduction of actual support for these 
clauses, new arguments are not initialized from values stored in the 
corresponding operand structure fields but rather set to empty or null. Those 
should be updated when support for these clauses on the corresponding operation 
is added.

>From 20213d580acb3f76b45ec5d85e1f717bccd97f81 Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Tue, 16 Jul 2024 17:18:13 +0100
Subject: [PATCH] [MLIR][OpenMP] Add missing clauses to OpenMP op definitions

This patch adds the missing `OpenMP_Clause` definitions to all existing
`OpenMP_Op`s and updates their operand structure based builders to initialize
the new arguments.

The result of this change is that operation operand structures are now based in
the same list of clauses as their tablegen counterparts. This means that all of
the information needed is now in place to automatically generate OpenMP operand
structures from tablegen defitions.

Since this change doesn't involve the introduction of actual support for these
clauses, new arguments are not initialized from values stored in the
corresponding operand structure fields but rather set to empty or null. Those
should be updated when support for these clauses on the corresponding operation
is added.
---
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td | 51 ++-
 mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp  | 46 +++--
 mlir/test/Dialect/OpenMP/invalid.mlir | 40 +++
 mlir/test/Dialect/OpenMP/ops.mlir | 26 +-
 4 files changed, 91 insertions(+), 72 deletions(-)

diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index a4aeeacfea672..04af5dd61dac0 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -195,10 +195,9 @@ def TerminatorOp : OpenMP_Op<"terminator", [Terminator, 
Pure]> {
 def TeamsOp : OpenMP_Op<"teams", traits = [
 AttrSizedOperandSegments, RecursiveMemoryEffects
   ], clauses = [
-// TODO: Complete clause list (private).
 // TODO: Sort clauses alphabetically.
 OpenMP_NumTeamsClause, OpenMP_IfClause, OpenMP_ThreadLimitClause,
-OpenMP_AllocateClause, OpenMP_ReductionClause
+OpenMP_AllocateClause, OpenMP_ReductionClause, OpenMP_PrivateClause
   ], singleRegion = true> {
   let summary = "teams construct";
   let description = [{
@@ -238,9 +237,9 @@ def SectionOp : OpenMP_Op<"section", 
[HasParent<"SectionsOp">],
 def SectionsOp : OpenMP_Op<"sections", traits = [
 AttrSizedOperandSegments
   ], clauses = [
-// TODO: Complete clause list (private).
 // TODO: Sort clauses alphabetically.
-OpenMP_ReductionClause, OpenMP_AllocateClause, OpenMP_NowaitClause
+OpenMP_ReductionClause, OpenMP_AllocateClause, OpenMP_NowaitClause,
+OpenMP_PrivateClause
   ], singleRegion = true> {
   let summary = "sections construct";
   let description = [{
@@ -271,8 +270,8 @@ def SectionsOp : OpenMP_Op<"sections", traits = [
 def SingleOp : OpenMP_Op<"single", traits = [
 AttrSizedOperandSegments
   ], clauses = [
-// TODO: Complete clause list (private).
-OpenMP_AllocateClause, OpenMP_CopyprivateClause, OpenMP_NowaitClause
+OpenMP_AllocateClause, OpenMP_CopyprivateClause, OpenMP_NowaitClause,
+OpenMP_PrivateClause
   ], singleRegion = true> {
   let summary = "single directive";
   let description = [{
@@ -363,14 +362,15 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [
 AttrSizedOperandSegments, DeclareOpInterfaceMethods,
 RecursiveMemoryEffects, SingleBlock
   ], clauses = [
-// TODO: Complete clause list (allocate, private).
 // TODO: Sort clauses alphabetically.
 OpenMP_LinearClauseSkip,
 OpenMP_ReductionClauseSkip,
 OpenMP_ScheduleClauseSkip,
 OpenMP_NowaitClauseSkip,
 OpenMP_OrderedClauseSkip,
-OpenMP_OrderClauseSkip
+OpenMP_OrderClauseSkip,
+OpenMP_AllocateClauseSkip,
+OpenMP_PrivateClauseSkip
   ], singleRegion = true> {
   let summary = "worksharing-loop construct";
   let description = [{
@@ -417,6 +417,13 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [
   |`nowait` $nowait
   |`ordered` `(` $ordered `)`
   |`order` `(` custom($order, $order_mod) `)`
+  |`allocate` `(`
+custom(
+  $allocate_vars, type($allocate_vars), $allocator_vars,
+  t

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Add missing clauses to OpenMP op definitions (PR #99507)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-openmp

Author: Sergio Afonso (skatrak)


Changes

This patch adds the missing `OpenMP_Clause` definitions to all existing 
`OpenMP_Op`s and updates their operand structure based builders to initialize 
the new arguments.

The result of this change is that operation operand structures are now based in 
the same list of clauses as their tablegen counterparts. This means that all of 
the information needed is now in place to automatically generate OpenMP operand 
structures from tablegen defitions.

Since this change doesn't involve the introduction of actual support for these 
clauses, new arguments are not initialized from values stored in the 
corresponding operand structure fields but rather set to empty or null. Those 
should be updated when support for these clauses on the corresponding operation 
is added.

---

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


4 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+28-23) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+30-16) 
- (modified) mlir/test/Dialect/OpenMP/invalid.mlir (+20-20) 
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+13-13) 


``diff
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index a4aeeacfea672..04af5dd61dac0 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -195,10 +195,9 @@ def TerminatorOp : OpenMP_Op<"terminator", [Terminator, 
Pure]> {
 def TeamsOp : OpenMP_Op<"teams", traits = [
 AttrSizedOperandSegments, RecursiveMemoryEffects
   ], clauses = [
-// TODO: Complete clause list (private).
 // TODO: Sort clauses alphabetically.
 OpenMP_NumTeamsClause, OpenMP_IfClause, OpenMP_ThreadLimitClause,
-OpenMP_AllocateClause, OpenMP_ReductionClause
+OpenMP_AllocateClause, OpenMP_ReductionClause, OpenMP_PrivateClause
   ], singleRegion = true> {
   let summary = "teams construct";
   let description = [{
@@ -238,9 +237,9 @@ def SectionOp : OpenMP_Op<"section", 
[HasParent<"SectionsOp">],
 def SectionsOp : OpenMP_Op<"sections", traits = [
 AttrSizedOperandSegments
   ], clauses = [
-// TODO: Complete clause list (private).
 // TODO: Sort clauses alphabetically.
-OpenMP_ReductionClause, OpenMP_AllocateClause, OpenMP_NowaitClause
+OpenMP_ReductionClause, OpenMP_AllocateClause, OpenMP_NowaitClause,
+OpenMP_PrivateClause
   ], singleRegion = true> {
   let summary = "sections construct";
   let description = [{
@@ -271,8 +270,8 @@ def SectionsOp : OpenMP_Op<"sections", traits = [
 def SingleOp : OpenMP_Op<"single", traits = [
 AttrSizedOperandSegments
   ], clauses = [
-// TODO: Complete clause list (private).
-OpenMP_AllocateClause, OpenMP_CopyprivateClause, OpenMP_NowaitClause
+OpenMP_AllocateClause, OpenMP_CopyprivateClause, OpenMP_NowaitClause,
+OpenMP_PrivateClause
   ], singleRegion = true> {
   let summary = "single directive";
   let description = [{
@@ -363,14 +362,15 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [
 AttrSizedOperandSegments, DeclareOpInterfaceMethods,
 RecursiveMemoryEffects, SingleBlock
   ], clauses = [
-// TODO: Complete clause list (allocate, private).
 // TODO: Sort clauses alphabetically.
 OpenMP_LinearClauseSkip,
 OpenMP_ReductionClauseSkip,
 OpenMP_ScheduleClauseSkip,
 OpenMP_NowaitClauseSkip,
 OpenMP_OrderedClauseSkip,
-OpenMP_OrderClauseSkip
+OpenMP_OrderClauseSkip,
+OpenMP_AllocateClauseSkip,
+OpenMP_PrivateClauseSkip
   ], singleRegion = true> {
   let summary = "worksharing-loop construct";
   let description = [{
@@ -417,6 +417,13 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [
   |`nowait` $nowait
   |`ordered` `(` $ordered `)`
   |`order` `(` custom($order, $order_mod) `)`
+  |`allocate` `(`
+custom(
+  $allocate_vars, type($allocate_vars), $allocator_vars,
+  type($allocator_vars)) `)`
+  |`private` `(`
+custom(
+  $private_vars, type($private_vars), $private_syms) `)`
 ) custom($region, $reduction_vars, type($reduction_vars),
  $reduction_byref, $reduction_syms) attr-dict
   }];
@@ -432,9 +439,10 @@ def SimdOp : OpenMP_Op<"simd", traits = [
 AttrSizedOperandSegments, DeclareOpInterfaceMethods,
 RecursiveMemoryEffects, SingleBlock
   ], clauses = [
-// TODO: Complete clause list (linear, private, reduction).
+// TODO: Complete clause list (linear).
 OpenMP_AlignedClause, OpenMP_IfClause, OpenMP_NontemporalClause,
-OpenMP_OrderClause, OpenMP_SafelenClause, OpenMP_SimdlenClause
+OpenMP_OrderClause, OpenMP_PrivateClause, OpenMP_ReductionClause,
+OpenMP_SafelenClause, OpenMP_SimdlenClause
   ], singleRegion = true> {
   let summ

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Add missing clauses to OpenMP op definitions (PR #99507)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir

Author: Sergio Afonso (skatrak)


Changes

This patch adds the missing `OpenMP_Clause` definitions to all existing 
`OpenMP_Op`s and updates their operand structure based builders to initialize 
the new arguments.

The result of this change is that operation operand structures are now based in 
the same list of clauses as their tablegen counterparts. This means that all of 
the information needed is now in place to automatically generate OpenMP operand 
structures from tablegen defitions.

Since this change doesn't involve the introduction of actual support for these 
clauses, new arguments are not initialized from values stored in the 
corresponding operand structure fields but rather set to empty or null. Those 
should be updated when support for these clauses on the corresponding operation 
is added.

---

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


4 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+28-23) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+30-16) 
- (modified) mlir/test/Dialect/OpenMP/invalid.mlir (+20-20) 
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+13-13) 


``diff
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index a4aeeacfea672..04af5dd61dac0 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -195,10 +195,9 @@ def TerminatorOp : OpenMP_Op<"terminator", [Terminator, 
Pure]> {
 def TeamsOp : OpenMP_Op<"teams", traits = [
 AttrSizedOperandSegments, RecursiveMemoryEffects
   ], clauses = [
-// TODO: Complete clause list (private).
 // TODO: Sort clauses alphabetically.
 OpenMP_NumTeamsClause, OpenMP_IfClause, OpenMP_ThreadLimitClause,
-OpenMP_AllocateClause, OpenMP_ReductionClause
+OpenMP_AllocateClause, OpenMP_ReductionClause, OpenMP_PrivateClause
   ], singleRegion = true> {
   let summary = "teams construct";
   let description = [{
@@ -238,9 +237,9 @@ def SectionOp : OpenMP_Op<"section", 
[HasParent<"SectionsOp">],
 def SectionsOp : OpenMP_Op<"sections", traits = [
 AttrSizedOperandSegments
   ], clauses = [
-// TODO: Complete clause list (private).
 // TODO: Sort clauses alphabetically.
-OpenMP_ReductionClause, OpenMP_AllocateClause, OpenMP_NowaitClause
+OpenMP_ReductionClause, OpenMP_AllocateClause, OpenMP_NowaitClause,
+OpenMP_PrivateClause
   ], singleRegion = true> {
   let summary = "sections construct";
   let description = [{
@@ -271,8 +270,8 @@ def SectionsOp : OpenMP_Op<"sections", traits = [
 def SingleOp : OpenMP_Op<"single", traits = [
 AttrSizedOperandSegments
   ], clauses = [
-// TODO: Complete clause list (private).
-OpenMP_AllocateClause, OpenMP_CopyprivateClause, OpenMP_NowaitClause
+OpenMP_AllocateClause, OpenMP_CopyprivateClause, OpenMP_NowaitClause,
+OpenMP_PrivateClause
   ], singleRegion = true> {
   let summary = "single directive";
   let description = [{
@@ -363,14 +362,15 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [
 AttrSizedOperandSegments, DeclareOpInterfaceMethods,
 RecursiveMemoryEffects, SingleBlock
   ], clauses = [
-// TODO: Complete clause list (allocate, private).
 // TODO: Sort clauses alphabetically.
 OpenMP_LinearClauseSkip,
 OpenMP_ReductionClauseSkip,
 OpenMP_ScheduleClauseSkip,
 OpenMP_NowaitClauseSkip,
 OpenMP_OrderedClauseSkip,
-OpenMP_OrderClauseSkip
+OpenMP_OrderClauseSkip,
+OpenMP_AllocateClauseSkip,
+OpenMP_PrivateClauseSkip
   ], singleRegion = true> {
   let summary = "worksharing-loop construct";
   let description = [{
@@ -417,6 +417,13 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [
   |`nowait` $nowait
   |`ordered` `(` $ordered `)`
   |`order` `(` custom($order, $order_mod) `)`
+  |`allocate` `(`
+custom(
+  $allocate_vars, type($allocate_vars), $allocator_vars,
+  type($allocator_vars)) `)`
+  |`private` `(`
+custom(
+  $private_vars, type($private_vars), $private_syms) `)`
 ) custom($region, $reduction_vars, type($reduction_vars),
  $reduction_byref, $reduction_syms) attr-dict
   }];
@@ -432,9 +439,10 @@ def SimdOp : OpenMP_Op<"simd", traits = [
 AttrSizedOperandSegments, DeclareOpInterfaceMethods,
 RecursiveMemoryEffects, SingleBlock
   ], clauses = [
-// TODO: Complete clause list (linear, private, reduction).
+// TODO: Complete clause list (linear).
 OpenMP_AlignedClause, OpenMP_IfClause, OpenMP_NontemporalClause,
-OpenMP_OrderClause, OpenMP_SafelenClause, OpenMP_SimdlenClause
+OpenMP_OrderClause, OpenMP_PrivateClause, OpenMP_ReductionClause,
+OpenMP_SafelenClause, OpenMP_SimdlenClause
   ], singleRegion = true> {
   let summary = "

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Add missing clauses to OpenMP op definitions (PR #99507)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: Sergio Afonso (skatrak)


Changes

This patch adds the missing `OpenMP_Clause` definitions to all existing 
`OpenMP_Op`s and updates their operand structure based builders to initialize 
the new arguments.

The result of this change is that operation operand structures are now based in 
the same list of clauses as their tablegen counterparts. This means that all of 
the information needed is now in place to automatically generate OpenMP operand 
structures from tablegen defitions.

Since this change doesn't involve the introduction of actual support for these 
clauses, new arguments are not initialized from values stored in the 
corresponding operand structure fields but rather set to empty or null. Those 
should be updated when support for these clauses on the corresponding operation 
is added.

---

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


4 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+28-23) 
- (modified) mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp (+30-16) 
- (modified) mlir/test/Dialect/OpenMP/invalid.mlir (+20-20) 
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+13-13) 


``diff
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index a4aeeacfea672..04af5dd61dac0 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -195,10 +195,9 @@ def TerminatorOp : OpenMP_Op<"terminator", [Terminator, 
Pure]> {
 def TeamsOp : OpenMP_Op<"teams", traits = [
 AttrSizedOperandSegments, RecursiveMemoryEffects
   ], clauses = [
-// TODO: Complete clause list (private).
 // TODO: Sort clauses alphabetically.
 OpenMP_NumTeamsClause, OpenMP_IfClause, OpenMP_ThreadLimitClause,
-OpenMP_AllocateClause, OpenMP_ReductionClause
+OpenMP_AllocateClause, OpenMP_ReductionClause, OpenMP_PrivateClause
   ], singleRegion = true> {
   let summary = "teams construct";
   let description = [{
@@ -238,9 +237,9 @@ def SectionOp : OpenMP_Op<"section", 
[HasParent<"SectionsOp">],
 def SectionsOp : OpenMP_Op<"sections", traits = [
 AttrSizedOperandSegments
   ], clauses = [
-// TODO: Complete clause list (private).
 // TODO: Sort clauses alphabetically.
-OpenMP_ReductionClause, OpenMP_AllocateClause, OpenMP_NowaitClause
+OpenMP_ReductionClause, OpenMP_AllocateClause, OpenMP_NowaitClause,
+OpenMP_PrivateClause
   ], singleRegion = true> {
   let summary = "sections construct";
   let description = [{
@@ -271,8 +270,8 @@ def SectionsOp : OpenMP_Op<"sections", traits = [
 def SingleOp : OpenMP_Op<"single", traits = [
 AttrSizedOperandSegments
   ], clauses = [
-// TODO: Complete clause list (private).
-OpenMP_AllocateClause, OpenMP_CopyprivateClause, OpenMP_NowaitClause
+OpenMP_AllocateClause, OpenMP_CopyprivateClause, OpenMP_NowaitClause,
+OpenMP_PrivateClause
   ], singleRegion = true> {
   let summary = "single directive";
   let description = [{
@@ -363,14 +362,15 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [
 AttrSizedOperandSegments, DeclareOpInterfaceMethods,
 RecursiveMemoryEffects, SingleBlock
   ], clauses = [
-// TODO: Complete clause list (allocate, private).
 // TODO: Sort clauses alphabetically.
 OpenMP_LinearClauseSkip,
 OpenMP_ReductionClauseSkip,
 OpenMP_ScheduleClauseSkip,
 OpenMP_NowaitClauseSkip,
 OpenMP_OrderedClauseSkip,
-OpenMP_OrderClauseSkip
+OpenMP_OrderClauseSkip,
+OpenMP_AllocateClauseSkip,
+OpenMP_PrivateClauseSkip
   ], singleRegion = true> {
   let summary = "worksharing-loop construct";
   let description = [{
@@ -417,6 +417,13 @@ def WsloopOp : OpenMP_Op<"wsloop", traits = [
   |`nowait` $nowait
   |`ordered` `(` $ordered `)`
   |`order` `(` custom($order, $order_mod) `)`
+  |`allocate` `(`
+custom(
+  $allocate_vars, type($allocate_vars), $allocator_vars,
+  type($allocator_vars)) `)`
+  |`private` `(`
+custom(
+  $private_vars, type($private_vars), $private_syms) `)`
 ) custom($region, $reduction_vars, type($reduction_vars),
  $reduction_byref, $reduction_syms) attr-dict
   }];
@@ -432,9 +439,10 @@ def SimdOp : OpenMP_Op<"simd", traits = [
 AttrSizedOperandSegments, DeclareOpInterfaceMethods,
 RecursiveMemoryEffects, SingleBlock
   ], clauses = [
-// TODO: Complete clause list (linear, private, reduction).
+// TODO: Complete clause list (linear).
 OpenMP_AlignedClause, OpenMP_IfClause, OpenMP_NontemporalClause,
-OpenMP_OrderClause, OpenMP_SafelenClause, OpenMP_SimdlenClause
+OpenMP_OrderClause, OpenMP_PrivateClause, OpenMP_ReductionClause,
+OpenMP_SafelenClause, OpenMP_SimdlenClause
   ], singleRegion = true> {
   let sum

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Automate operand structure definition (PR #99508)

2024-07-18 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak created 
https://github.com/llvm/llvm-project/pull/99508

This patch adds the "gen-openmp-clause-ops" `mlir-tblgen` generator to produce 
the structure definitions previously in OpenMPClauseOperands.h automatically 
from the information contained in OpenMPOps.td and OpenMPClauses.td.

Changes introduced to the `ElementsAttrBase` common tablegen class, as well as 
some of its subclasses, add more fine-grained information on their shape and 
type of their elements. This information is needed in order to properly 
generate the corresponding types to represent these attributes within the 
produced operand structures.

The original header is maintained to enable the definition of similar 
structures that are not directly related to any single `OpenMP_Clause` or 
`OpenMP_Op` tablegen definition.

>From 1d99939c020aab8650cd20df24e0b1e71726ae90 Mon Sep 17 00:00:00 2001
From: Sergio Afonso 
Date: Wed, 17 Jul 2024 13:26:09 +0100
Subject: [PATCH] [MLIR][OpenMP] Automate operand structure definition

This patch adds the "gen-openmp-clause-ops" `mlir-tblgen` generator to produce
the structure definitions previously in OpenMPClauseOperands.h automatically
from the information contained in OpenMPOps.td and OpenMPClauses.td.

Changes introduced to the `ElementsAttrBase` common tablegen class, as well as
some of its subclasses, add more fine-grained information on their shape and
type of their elements. This information is needed in order to properly
generate the corresponding types to represent these attributes within the
produced operand structures.

The original header is maintained to enable the definition of similar
structures that are not directly related to any single `OpenMP_Clause` or
`OpenMP_Op` tablegen definition.
---
 .../mlir/Dialect/OpenMP/CMakeLists.txt|   1 +
 .../Dialect/OpenMP/OpenMPClauseOperands.h | 290 +-
 mlir/include/mlir/IR/CommonAttrConstraints.td |  18 +-
 mlir/test/mlir-tblgen/openmp-clause-ops.td|  78 +
 mlir/tools/mlir-tblgen/OmpOpGen.cpp   | 174 ++-
 5 files changed, 266 insertions(+), 295 deletions(-)
 create mode 100644 mlir/test/mlir-tblgen/openmp-clause-ops.td

diff --git a/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt 
b/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
index d3422f6e48b06..23ccba3067bcb 100644
--- a/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
@@ -17,6 +17,7 @@ mlir_tablegen(OpenMPOpsDialect.h.inc -gen-dialect-decls 
-dialect=omp)
 mlir_tablegen(OpenMPOpsDialect.cpp.inc -gen-dialect-defs -dialect=omp)
 mlir_tablegen(OpenMPOps.h.inc -gen-op-decls)
 mlir_tablegen(OpenMPOps.cpp.inc -gen-op-defs)
+mlir_tablegen(OpenMPClauseOps.h.inc -gen-openmp-clause-ops)
 mlir_tablegen(OpenMPOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=omp)
 mlir_tablegen(OpenMPOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=omp)
 mlir_tablegen(OpenMPOpsEnums.h.inc -gen-enum-decls)
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h
index f4a87d52a172e..e5b4de4908966 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h
@@ -23,303 +23,31 @@
 #define GET_ATTRDEF_CLASSES
 #include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.h.inc"
 
+#include "mlir/Dialect/OpenMP/OpenMPClauseOps.h.inc"
+
 namespace mlir {
 namespace omp {
 
 
//===--===//
-// Mixin structures defining MLIR operands associated with each OpenMP clause.
+// Extra clause operand structures.
 
//===--===//
 
-struct AlignedClauseOps {
-  llvm::SmallVector alignedVars;
-  llvm::SmallVector alignments;
-};
-
-struct AllocateClauseOps {
-  llvm::SmallVector allocateVars, allocatorVars;
-};
-
-struct CancelDirectiveNameClauseOps {
-  ClauseCancellationConstructTypeAttr cancelDirective;
-};
-
-struct CollapseClauseOps {
-  llvm::SmallVector collapseLowerBound, collapseUpperBound, 
collapseStep;
-};
-
-struct CopyprivateClauseOps {
-  llvm::SmallVector copyprivateVars;
-  llvm::SmallVector copyprivateSyms;
-};
-
-struct CriticalNameClauseOps {
-  StringAttr symName;
-};
-
-struct DependClauseOps {
-  llvm::SmallVector dependKinds;
-  llvm::SmallVector dependVars;
-};
-
-struct DeviceClauseOps {
-  Value device;
-};
-
 struct DeviceTypeClauseOps {
   // The default capture type.
   DeclareTargetDeviceType deviceType = DeclareTargetDeviceType::any;
 };
 
-struct DistScheduleClauseOps {
-  UnitAttr distScheduleStatic;
-  Value distScheduleChunkSize;
-};
-
-struct DoacrossClauseOps {
-  ClauseDependAttr doacrossDependType;
-  IntegerAttr doacrossNumLoops;
-  llvm::SmallVector doacrossDependVars;
-};
-
-struct FilterClauseOps {
-  Value filteredThreadId;
-};
-
-struct FinalClauseOps {
-  Value final;
-};
-
-struct GrainsizeClause

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Automate operand structure definition (PR #99508)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-mlir-openmp

@llvm/pr-subscribers-mlir-ods

Author: Sergio Afonso (skatrak)


Changes

This patch adds the "gen-openmp-clause-ops" `mlir-tblgen` generator to produce 
the structure definitions previously in OpenMPClauseOperands.h automatically 
from the information contained in OpenMPOps.td and OpenMPClauses.td.

Changes introduced to the `ElementsAttrBase` common tablegen class, as well as 
some of its subclasses, add more fine-grained information on their shape and 
type of their elements. This information is needed in order to properly 
generate the corresponding types to represent these attributes within the 
produced operand structures.

The original header is maintained to enable the definition of similar 
structures that are not directly related to any single `OpenMP_Clause` or 
`OpenMP_Op` tablegen definition.

---

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


5 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt (+1) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h (+9-281) 
- (modified) mlir/include/mlir/IR/CommonAttrConstraints.td (+17-1) 
- (added) mlir/test/mlir-tblgen/openmp-clause-ops.td (+78) 
- (modified) mlir/tools/mlir-tblgen/OmpOpGen.cpp (+161-13) 


``diff
diff --git a/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt 
b/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
index d3422f6e48b06..23ccba3067bcb 100644
--- a/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
@@ -17,6 +17,7 @@ mlir_tablegen(OpenMPOpsDialect.h.inc -gen-dialect-decls 
-dialect=omp)
 mlir_tablegen(OpenMPOpsDialect.cpp.inc -gen-dialect-defs -dialect=omp)
 mlir_tablegen(OpenMPOps.h.inc -gen-op-decls)
 mlir_tablegen(OpenMPOps.cpp.inc -gen-op-defs)
+mlir_tablegen(OpenMPClauseOps.h.inc -gen-openmp-clause-ops)
 mlir_tablegen(OpenMPOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=omp)
 mlir_tablegen(OpenMPOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=omp)
 mlir_tablegen(OpenMPOpsEnums.h.inc -gen-enum-decls)
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h
index f4a87d52a172e..e5b4de4908966 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h
@@ -23,303 +23,31 @@
 #define GET_ATTRDEF_CLASSES
 #include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.h.inc"
 
+#include "mlir/Dialect/OpenMP/OpenMPClauseOps.h.inc"
+
 namespace mlir {
 namespace omp {
 
 
//===--===//
-// Mixin structures defining MLIR operands associated with each OpenMP clause.
+// Extra clause operand structures.
 
//===--===//
 
-struct AlignedClauseOps {
-  llvm::SmallVector alignedVars;
-  llvm::SmallVector alignments;
-};
-
-struct AllocateClauseOps {
-  llvm::SmallVector allocateVars, allocatorVars;
-};
-
-struct CancelDirectiveNameClauseOps {
-  ClauseCancellationConstructTypeAttr cancelDirective;
-};
-
-struct CollapseClauseOps {
-  llvm::SmallVector collapseLowerBound, collapseUpperBound, 
collapseStep;
-};
-
-struct CopyprivateClauseOps {
-  llvm::SmallVector copyprivateVars;
-  llvm::SmallVector copyprivateSyms;
-};
-
-struct CriticalNameClauseOps {
-  StringAttr symName;
-};
-
-struct DependClauseOps {
-  llvm::SmallVector dependKinds;
-  llvm::SmallVector dependVars;
-};
-
-struct DeviceClauseOps {
-  Value device;
-};
-
 struct DeviceTypeClauseOps {
   // The default capture type.
   DeclareTargetDeviceType deviceType = DeclareTargetDeviceType::any;
 };
 
-struct DistScheduleClauseOps {
-  UnitAttr distScheduleStatic;
-  Value distScheduleChunkSize;
-};
-
-struct DoacrossClauseOps {
-  ClauseDependAttr doacrossDependType;
-  IntegerAttr doacrossNumLoops;
-  llvm::SmallVector doacrossDependVars;
-};
-
-struct FilterClauseOps {
-  Value filteredThreadId;
-};
-
-struct FinalClauseOps {
-  Value final;
-};
-
-struct GrainsizeClauseOps {
-  Value grainsize;
-};
-
-struct HasDeviceAddrClauseOps {
-  llvm::SmallVector hasDeviceAddrVars;
-};
-
-struct HintClauseOps {
-  IntegerAttr hint;
-};
-
-struct IfClauseOps {
-  Value ifVar;
-};
-
-struct InReductionClauseOps {
-  llvm::SmallVector inReductionVars;
-  llvm::SmallVector inReductionByref;
-  llvm::SmallVector inReductionSyms;
-};
-
-struct IsDevicePtrClauseOps {
-  llvm::SmallVector isDevicePtrVars;
-};
-
-struct LinearClauseOps {
-  llvm::SmallVector linearVars, linearStepVars;
-};
-
-struct LoopRelatedOps {
-  UnitAttr loopInclusive;
-};
-
-struct MapClauseOps {
-  llvm::SmallVector mapVars;
-};
-
-struct MergeableClauseOps {
-  UnitAttr mergeable;
-};
-
-struct NogroupClauseOps {
-  UnitAttr nogroup;
-};
-
-struct NontemporalClauseOps {
-  llvm::SmallVector nontemporalVars;
-};
-
-struct Nowa

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Automate operand structure definition (PR #99508)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir

Author: Sergio Afonso (skatrak)


Changes

This patch adds the "gen-openmp-clause-ops" `mlir-tblgen` generator to produce 
the structure definitions previously in OpenMPClauseOperands.h automatically 
from the information contained in OpenMPOps.td and OpenMPClauses.td.

Changes introduced to the `ElementsAttrBase` common tablegen class, as well as 
some of its subclasses, add more fine-grained information on their shape and 
type of their elements. This information is needed in order to properly 
generate the corresponding types to represent these attributes within the 
produced operand structures.

The original header is maintained to enable the definition of similar 
structures that are not directly related to any single `OpenMP_Clause` or 
`OpenMP_Op` tablegen definition.

---

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


5 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt (+1) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h (+9-281) 
- (modified) mlir/include/mlir/IR/CommonAttrConstraints.td (+17-1) 
- (added) mlir/test/mlir-tblgen/openmp-clause-ops.td (+78) 
- (modified) mlir/tools/mlir-tblgen/OmpOpGen.cpp (+161-13) 


``diff
diff --git a/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt 
b/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
index d3422f6e48b06..23ccba3067bcb 100644
--- a/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
@@ -17,6 +17,7 @@ mlir_tablegen(OpenMPOpsDialect.h.inc -gen-dialect-decls 
-dialect=omp)
 mlir_tablegen(OpenMPOpsDialect.cpp.inc -gen-dialect-defs -dialect=omp)
 mlir_tablegen(OpenMPOps.h.inc -gen-op-decls)
 mlir_tablegen(OpenMPOps.cpp.inc -gen-op-defs)
+mlir_tablegen(OpenMPClauseOps.h.inc -gen-openmp-clause-ops)
 mlir_tablegen(OpenMPOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=omp)
 mlir_tablegen(OpenMPOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=omp)
 mlir_tablegen(OpenMPOpsEnums.h.inc -gen-enum-decls)
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h
index f4a87d52a172e..e5b4de4908966 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h
@@ -23,303 +23,31 @@
 #define GET_ATTRDEF_CLASSES
 #include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.h.inc"
 
+#include "mlir/Dialect/OpenMP/OpenMPClauseOps.h.inc"
+
 namespace mlir {
 namespace omp {
 
 
//===--===//
-// Mixin structures defining MLIR operands associated with each OpenMP clause.
+// Extra clause operand structures.
 
//===--===//
 
-struct AlignedClauseOps {
-  llvm::SmallVector alignedVars;
-  llvm::SmallVector alignments;
-};
-
-struct AllocateClauseOps {
-  llvm::SmallVector allocateVars, allocatorVars;
-};
-
-struct CancelDirectiveNameClauseOps {
-  ClauseCancellationConstructTypeAttr cancelDirective;
-};
-
-struct CollapseClauseOps {
-  llvm::SmallVector collapseLowerBound, collapseUpperBound, 
collapseStep;
-};
-
-struct CopyprivateClauseOps {
-  llvm::SmallVector copyprivateVars;
-  llvm::SmallVector copyprivateSyms;
-};
-
-struct CriticalNameClauseOps {
-  StringAttr symName;
-};
-
-struct DependClauseOps {
-  llvm::SmallVector dependKinds;
-  llvm::SmallVector dependVars;
-};
-
-struct DeviceClauseOps {
-  Value device;
-};
-
 struct DeviceTypeClauseOps {
   // The default capture type.
   DeclareTargetDeviceType deviceType = DeclareTargetDeviceType::any;
 };
 
-struct DistScheduleClauseOps {
-  UnitAttr distScheduleStatic;
-  Value distScheduleChunkSize;
-};
-
-struct DoacrossClauseOps {
-  ClauseDependAttr doacrossDependType;
-  IntegerAttr doacrossNumLoops;
-  llvm::SmallVector doacrossDependVars;
-};
-
-struct FilterClauseOps {
-  Value filteredThreadId;
-};
-
-struct FinalClauseOps {
-  Value final;
-};
-
-struct GrainsizeClauseOps {
-  Value grainsize;
-};
-
-struct HasDeviceAddrClauseOps {
-  llvm::SmallVector hasDeviceAddrVars;
-};
-
-struct HintClauseOps {
-  IntegerAttr hint;
-};
-
-struct IfClauseOps {
-  Value ifVar;
-};
-
-struct InReductionClauseOps {
-  llvm::SmallVector inReductionVars;
-  llvm::SmallVector inReductionByref;
-  llvm::SmallVector inReductionSyms;
-};
-
-struct IsDevicePtrClauseOps {
-  llvm::SmallVector isDevicePtrVars;
-};
-
-struct LinearClauseOps {
-  llvm::SmallVector linearVars, linearStepVars;
-};
-
-struct LoopRelatedOps {
-  UnitAttr loopInclusive;
-};
-
-struct MapClauseOps {
-  llvm::SmallVector mapVars;
-};
-
-struct MergeableClauseOps {
-  UnitAttr mergeable;
-};
-
-struct NogroupClauseOps {
-  UnitAttr nogroup;
-};
-
-struct NontemporalClauseOps {
-  llvm::SmallVector nontemporalVars;
-};
-
-struct NowaitClauseOps {
-  UnitAttr nowait;
-};

[llvm-branch-commits] [mlir] [MLIR][OpenMP] Automate operand structure definition (PR #99508)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-core

Author: Sergio Afonso (skatrak)


Changes

This patch adds the "gen-openmp-clause-ops" `mlir-tblgen` generator to produce 
the structure definitions previously in OpenMPClauseOperands.h automatically 
from the information contained in OpenMPOps.td and OpenMPClauses.td.

Changes introduced to the `ElementsAttrBase` common tablegen class, as well as 
some of its subclasses, add more fine-grained information on their shape and 
type of their elements. This information is needed in order to properly 
generate the corresponding types to represent these attributes within the 
produced operand structures.

The original header is maintained to enable the definition of similar 
structures that are not directly related to any single `OpenMP_Clause` or 
`OpenMP_Op` tablegen definition.

---

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


5 Files Affected:

- (modified) mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt (+1) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h (+9-281) 
- (modified) mlir/include/mlir/IR/CommonAttrConstraints.td (+17-1) 
- (added) mlir/test/mlir-tblgen/openmp-clause-ops.td (+78) 
- (modified) mlir/tools/mlir-tblgen/OmpOpGen.cpp (+161-13) 


``diff
diff --git a/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt 
b/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
index d3422f6e48b06..23ccba3067bcb 100644
--- a/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt
@@ -17,6 +17,7 @@ mlir_tablegen(OpenMPOpsDialect.h.inc -gen-dialect-decls 
-dialect=omp)
 mlir_tablegen(OpenMPOpsDialect.cpp.inc -gen-dialect-defs -dialect=omp)
 mlir_tablegen(OpenMPOps.h.inc -gen-op-decls)
 mlir_tablegen(OpenMPOps.cpp.inc -gen-op-defs)
+mlir_tablegen(OpenMPClauseOps.h.inc -gen-openmp-clause-ops)
 mlir_tablegen(OpenMPOpsTypes.h.inc -gen-typedef-decls -typedefs-dialect=omp)
 mlir_tablegen(OpenMPOpsTypes.cpp.inc -gen-typedef-defs -typedefs-dialect=omp)
 mlir_tablegen(OpenMPOpsEnums.h.inc -gen-enum-decls)
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h 
b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h
index f4a87d52a172e..e5b4de4908966 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h
@@ -23,303 +23,31 @@
 #define GET_ATTRDEF_CLASSES
 #include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.h.inc"
 
+#include "mlir/Dialect/OpenMP/OpenMPClauseOps.h.inc"
+
 namespace mlir {
 namespace omp {
 
 
//===--===//
-// Mixin structures defining MLIR operands associated with each OpenMP clause.
+// Extra clause operand structures.
 
//===--===//
 
-struct AlignedClauseOps {
-  llvm::SmallVector alignedVars;
-  llvm::SmallVector alignments;
-};
-
-struct AllocateClauseOps {
-  llvm::SmallVector allocateVars, allocatorVars;
-};
-
-struct CancelDirectiveNameClauseOps {
-  ClauseCancellationConstructTypeAttr cancelDirective;
-};
-
-struct CollapseClauseOps {
-  llvm::SmallVector collapseLowerBound, collapseUpperBound, 
collapseStep;
-};
-
-struct CopyprivateClauseOps {
-  llvm::SmallVector copyprivateVars;
-  llvm::SmallVector copyprivateSyms;
-};
-
-struct CriticalNameClauseOps {
-  StringAttr symName;
-};
-
-struct DependClauseOps {
-  llvm::SmallVector dependKinds;
-  llvm::SmallVector dependVars;
-};
-
-struct DeviceClauseOps {
-  Value device;
-};
-
 struct DeviceTypeClauseOps {
   // The default capture type.
   DeclareTargetDeviceType deviceType = DeclareTargetDeviceType::any;
 };
 
-struct DistScheduleClauseOps {
-  UnitAttr distScheduleStatic;
-  Value distScheduleChunkSize;
-};
-
-struct DoacrossClauseOps {
-  ClauseDependAttr doacrossDependType;
-  IntegerAttr doacrossNumLoops;
-  llvm::SmallVector doacrossDependVars;
-};
-
-struct FilterClauseOps {
-  Value filteredThreadId;
-};
-
-struct FinalClauseOps {
-  Value final;
-};
-
-struct GrainsizeClauseOps {
-  Value grainsize;
-};
-
-struct HasDeviceAddrClauseOps {
-  llvm::SmallVector hasDeviceAddrVars;
-};
-
-struct HintClauseOps {
-  IntegerAttr hint;
-};
-
-struct IfClauseOps {
-  Value ifVar;
-};
-
-struct InReductionClauseOps {
-  llvm::SmallVector inReductionVars;
-  llvm::SmallVector inReductionByref;
-  llvm::SmallVector inReductionSyms;
-};
-
-struct IsDevicePtrClauseOps {
-  llvm::SmallVector isDevicePtrVars;
-};
-
-struct LinearClauseOps {
-  llvm::SmallVector linearVars, linearStepVars;
-};
-
-struct LoopRelatedOps {
-  UnitAttr loopInclusive;
-};
-
-struct MapClauseOps {
-  llvm::SmallVector mapVars;
-};
-
-struct MergeableClauseOps {
-  UnitAttr mergeable;
-};
-
-struct NogroupClauseOps {
-  UnitAttr nogroup;
-};
-
-struct NontemporalClauseOps {
-  llvm::SmallVector nontemporalVars;
-};
-
-struct NowaitClauseOps {
-  UnitAttr nowait

[llvm-branch-commits] [llvm] [BOLT] Match functions with call graph (PR #98125)

2024-07-18 Thread Shaw Young via llvm-branch-commits

https://github.com/shawbyoung updated 
https://github.com/llvm/llvm-project/pull/98125

>From cf32a43e7c2b04079c6123fe13df4fb7226d771f Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Tue, 9 Jul 2024 10:04:25 -0700
Subject: [PATCH 01/15] Comments

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileReader.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp 
b/bolt/lib/Profile/YAMLProfileReader.cpp
index 69ea0899c5f2c..6753337c24ea7 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -501,7 +501,6 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 
   // Maps binary functions to adjacent functions in the FCG.
   for (const BinaryFunction *CallerBF : BFs) {
-// Add all call targets to the hash map.
 for (const BinaryBasicBlock &BB : CallerBF->blocks()) {
   for (const MCInst &Inst : BB) {
 if (!BC.MIB->isCall(Instr))
@@ -533,7 +532,8 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 }
   }
 
-  // Create mapping from neighbor hash to BFs.
+  // Using the constructed adjacent function mapping, creates mapping from
+  // neighbor hash to BFs.
   std::unordered_map>
   NeighborHashToBFs;
   for (const BinaryFunction *BF : BFs) {
@@ -552,12 +552,12 @@ size_t 
YAMLProfileReader::matchWithCallGraph(BinaryContext &BC) {
 .push_back(BF);
   }
 
-  // TODO: change call anchor PR to have this representation - we need it here
+  // TODO: note, this will be introduced in the matching functions with calls
+  // as anchors pr
   DenseMap
   IdToYAMLBF;
-  // TODO: change call anchor PR to have this representation - we need it here
 
-  // Maps hashes to profiled functions.
+  // Maps YAML functions to adjacent functions in the profile FCG.
   std::unordered_map
   YamlBFToHashes(BFs.size());
@@ -590,7 +590,7 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 }
   }
 
-  // Matching YAMLBF with neighbor hashes.
+  // Matches YAMLBF to BFs with neighbor hashes.
   for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) {
 if (YamlBF.Used)
   continue;

>From ee9049fc4bd3d4203c19c9c0982a78ab3b47666f Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Tue, 9 Jul 2024 13:52:05 -0700
Subject: [PATCH 02/15] Moved blended hash definition

Created using spr 1.3.4
---
 bolt/include/bolt/Profile/YAMLProfileReader.h |  69 ++-
 bolt/lib/Profile/StaleProfileMatching.cpp |  65 ---
 bolt/lib/Profile/YAMLProfileReader.cpp| 110 --
 3 files changed, 119 insertions(+), 125 deletions(-)

diff --git a/bolt/include/bolt/Profile/YAMLProfileReader.h 
b/bolt/include/bolt/Profile/YAMLProfileReader.h
index 36e8f8739eee1..e8a34ecad9a08 100644
--- a/bolt/include/bolt/Profile/YAMLProfileReader.h
+++ b/bolt/include/bolt/Profile/YAMLProfileReader.h
@@ -16,6 +16,73 @@
 namespace llvm {
 namespace bolt {
 
+/// An object wrapping several components of a basic block hash. The combined
+/// (blended) hash is represented and stored as one uint64_t, while individual
+/// components are of smaller size (e.g., uint16_t or uint8_t).
+struct BlendedBlockHash {
+private:
+  using ValueOffset = Bitfield::Element;
+  using ValueOpcode = Bitfield::Element;
+  using ValueInstr = Bitfield::Element;
+  using ValuePred = Bitfield::Element;
+  using ValueSucc = Bitfield::Element;
+
+public:
+  explicit BlendedBlockHash() {}
+
+  explicit BlendedBlockHash(uint64_t Hash) {
+Offset = Bitfield::get(Hash);
+OpcodeHash = Bitfield::get(Hash);
+InstrHash = Bitfield::get(Hash);
+PredHash = Bitfield::get(Hash);
+SuccHash = Bitfield::get(Hash);
+  }
+
+  /// Combine the blended hash into uint64_t.
+  uint64_t combine() const {
+uint64_t Hash = 0;
+Bitfield::set(Hash, Offset);
+Bitfield::set(Hash, OpcodeHash);
+Bitfield::set(Hash, InstrHash);
+Bitfield::set(Hash, PredHash);
+Bitfield::set(Hash, SuccHash);
+return Hash;
+  }
+
+  /// Compute a distance between two given blended hashes. The smaller the
+  /// distance, the more similar two blocks are. For identical basic blocks,
+  /// the distance is zero.
+  uint64_t distance(const BlendedBlockHash &BBH) const {
+assert(OpcodeHash == BBH.OpcodeHash &&
+   "incorrect blended hash distance computation");
+uint64_t Dist = 0;
+// Account for NeighborHash
+Dist += SuccHash == BBH.SuccHash ? 0 : 1;
+Dist += PredHash == BBH.PredHash ? 0 : 1;
+Dist <<= 16;
+// Account for InstrHash
+Dist += InstrHash == BBH.InstrHash ? 0 : 1;
+Dist <<= 16;
+// Account for Offset
+Dist += (Offset >= BBH.Offset ? Offset - BBH.Offset : BBH.Offset - Offset);
+return Dist;
+  }
+
+  /// The offset of the basic block from the function start.
+  uint16_t Offset{0};
+  /// (Loose) Hash of the basic block instructions, excluding operands.
+  uint16_t OpcodeHash{0};
+  /// (Str

[llvm-branch-commits] [llvm] [BOLT] Match functions with call graph (PR #98125)

2024-07-18 Thread Shaw Young via llvm-branch-commits

https://github.com/shawbyoung updated 
https://github.com/llvm/llvm-project/pull/98125

>From cf32a43e7c2b04079c6123fe13df4fb7226d771f Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Tue, 9 Jul 2024 10:04:25 -0700
Subject: [PATCH 01/15] Comments

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileReader.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp 
b/bolt/lib/Profile/YAMLProfileReader.cpp
index 69ea0899c5f2c..6753337c24ea7 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -501,7 +501,6 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 
   // Maps binary functions to adjacent functions in the FCG.
   for (const BinaryFunction *CallerBF : BFs) {
-// Add all call targets to the hash map.
 for (const BinaryBasicBlock &BB : CallerBF->blocks()) {
   for (const MCInst &Inst : BB) {
 if (!BC.MIB->isCall(Instr))
@@ -533,7 +532,8 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 }
   }
 
-  // Create mapping from neighbor hash to BFs.
+  // Using the constructed adjacent function mapping, creates mapping from
+  // neighbor hash to BFs.
   std::unordered_map>
   NeighborHashToBFs;
   for (const BinaryFunction *BF : BFs) {
@@ -552,12 +552,12 @@ size_t 
YAMLProfileReader::matchWithCallGraph(BinaryContext &BC) {
 .push_back(BF);
   }
 
-  // TODO: change call anchor PR to have this representation - we need it here
+  // TODO: note, this will be introduced in the matching functions with calls
+  // as anchors pr
   DenseMap
   IdToYAMLBF;
-  // TODO: change call anchor PR to have this representation - we need it here
 
-  // Maps hashes to profiled functions.
+  // Maps YAML functions to adjacent functions in the profile FCG.
   std::unordered_map
   YamlBFToHashes(BFs.size());
@@ -590,7 +590,7 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 }
   }
 
-  // Matching YAMLBF with neighbor hashes.
+  // Matches YAMLBF to BFs with neighbor hashes.
   for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) {
 if (YamlBF.Used)
   continue;

>From ee9049fc4bd3d4203c19c9c0982a78ab3b47666f Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Tue, 9 Jul 2024 13:52:05 -0700
Subject: [PATCH 02/15] Moved blended hash definition

Created using spr 1.3.4
---
 bolt/include/bolt/Profile/YAMLProfileReader.h |  69 ++-
 bolt/lib/Profile/StaleProfileMatching.cpp |  65 ---
 bolt/lib/Profile/YAMLProfileReader.cpp| 110 --
 3 files changed, 119 insertions(+), 125 deletions(-)

diff --git a/bolt/include/bolt/Profile/YAMLProfileReader.h 
b/bolt/include/bolt/Profile/YAMLProfileReader.h
index 36e8f8739eee1..e8a34ecad9a08 100644
--- a/bolt/include/bolt/Profile/YAMLProfileReader.h
+++ b/bolt/include/bolt/Profile/YAMLProfileReader.h
@@ -16,6 +16,73 @@
 namespace llvm {
 namespace bolt {
 
+/// An object wrapping several components of a basic block hash. The combined
+/// (blended) hash is represented and stored as one uint64_t, while individual
+/// components are of smaller size (e.g., uint16_t or uint8_t).
+struct BlendedBlockHash {
+private:
+  using ValueOffset = Bitfield::Element;
+  using ValueOpcode = Bitfield::Element;
+  using ValueInstr = Bitfield::Element;
+  using ValuePred = Bitfield::Element;
+  using ValueSucc = Bitfield::Element;
+
+public:
+  explicit BlendedBlockHash() {}
+
+  explicit BlendedBlockHash(uint64_t Hash) {
+Offset = Bitfield::get(Hash);
+OpcodeHash = Bitfield::get(Hash);
+InstrHash = Bitfield::get(Hash);
+PredHash = Bitfield::get(Hash);
+SuccHash = Bitfield::get(Hash);
+  }
+
+  /// Combine the blended hash into uint64_t.
+  uint64_t combine() const {
+uint64_t Hash = 0;
+Bitfield::set(Hash, Offset);
+Bitfield::set(Hash, OpcodeHash);
+Bitfield::set(Hash, InstrHash);
+Bitfield::set(Hash, PredHash);
+Bitfield::set(Hash, SuccHash);
+return Hash;
+  }
+
+  /// Compute a distance between two given blended hashes. The smaller the
+  /// distance, the more similar two blocks are. For identical basic blocks,
+  /// the distance is zero.
+  uint64_t distance(const BlendedBlockHash &BBH) const {
+assert(OpcodeHash == BBH.OpcodeHash &&
+   "incorrect blended hash distance computation");
+uint64_t Dist = 0;
+// Account for NeighborHash
+Dist += SuccHash == BBH.SuccHash ? 0 : 1;
+Dist += PredHash == BBH.PredHash ? 0 : 1;
+Dist <<= 16;
+// Account for InstrHash
+Dist += InstrHash == BBH.InstrHash ? 0 : 1;
+Dist <<= 16;
+// Account for Offset
+Dist += (Offset >= BBH.Offset ? Offset - BBH.Offset : BBH.Offset - Offset);
+return Dist;
+  }
+
+  /// The offset of the basic block from the function start.
+  uint16_t Offset{0};
+  /// (Loose) Hash of the basic block instructions, excluding operands.
+  uint16_t OpcodeHash{0};
+  /// (Str

[llvm-branch-commits] [llvm] [BOLT] Match functions with call graph (PR #98125)

2024-07-18 Thread Shaw Young via llvm-branch-commits

https://github.com/shawbyoung updated 
https://github.com/llvm/llvm-project/pull/98125

>From cf32a43e7c2b04079c6123fe13df4fb7226d771f Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Tue, 9 Jul 2024 10:04:25 -0700
Subject: [PATCH 01/16] Comments

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileReader.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp 
b/bolt/lib/Profile/YAMLProfileReader.cpp
index 69ea0899c5f2c..6753337c24ea7 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -501,7 +501,6 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 
   // Maps binary functions to adjacent functions in the FCG.
   for (const BinaryFunction *CallerBF : BFs) {
-// Add all call targets to the hash map.
 for (const BinaryBasicBlock &BB : CallerBF->blocks()) {
   for (const MCInst &Inst : BB) {
 if (!BC.MIB->isCall(Instr))
@@ -533,7 +532,8 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 }
   }
 
-  // Create mapping from neighbor hash to BFs.
+  // Using the constructed adjacent function mapping, creates mapping from
+  // neighbor hash to BFs.
   std::unordered_map>
   NeighborHashToBFs;
   for (const BinaryFunction *BF : BFs) {
@@ -552,12 +552,12 @@ size_t 
YAMLProfileReader::matchWithCallGraph(BinaryContext &BC) {
 .push_back(BF);
   }
 
-  // TODO: change call anchor PR to have this representation - we need it here
+  // TODO: note, this will be introduced in the matching functions with calls
+  // as anchors pr
   DenseMap
   IdToYAMLBF;
-  // TODO: change call anchor PR to have this representation - we need it here
 
-  // Maps hashes to profiled functions.
+  // Maps YAML functions to adjacent functions in the profile FCG.
   std::unordered_map
   YamlBFToHashes(BFs.size());
@@ -590,7 +590,7 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 }
   }
 
-  // Matching YAMLBF with neighbor hashes.
+  // Matches YAMLBF to BFs with neighbor hashes.
   for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) {
 if (YamlBF.Used)
   continue;

>From ee9049fc4bd3d4203c19c9c0982a78ab3b47666f Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Tue, 9 Jul 2024 13:52:05 -0700
Subject: [PATCH 02/16] Moved blended hash definition

Created using spr 1.3.4
---
 bolt/include/bolt/Profile/YAMLProfileReader.h |  69 ++-
 bolt/lib/Profile/StaleProfileMatching.cpp |  65 ---
 bolt/lib/Profile/YAMLProfileReader.cpp| 110 --
 3 files changed, 119 insertions(+), 125 deletions(-)

diff --git a/bolt/include/bolt/Profile/YAMLProfileReader.h 
b/bolt/include/bolt/Profile/YAMLProfileReader.h
index 36e8f8739eee1..e8a34ecad9a08 100644
--- a/bolt/include/bolt/Profile/YAMLProfileReader.h
+++ b/bolt/include/bolt/Profile/YAMLProfileReader.h
@@ -16,6 +16,73 @@
 namespace llvm {
 namespace bolt {
 
+/// An object wrapping several components of a basic block hash. The combined
+/// (blended) hash is represented and stored as one uint64_t, while individual
+/// components are of smaller size (e.g., uint16_t or uint8_t).
+struct BlendedBlockHash {
+private:
+  using ValueOffset = Bitfield::Element;
+  using ValueOpcode = Bitfield::Element;
+  using ValueInstr = Bitfield::Element;
+  using ValuePred = Bitfield::Element;
+  using ValueSucc = Bitfield::Element;
+
+public:
+  explicit BlendedBlockHash() {}
+
+  explicit BlendedBlockHash(uint64_t Hash) {
+Offset = Bitfield::get(Hash);
+OpcodeHash = Bitfield::get(Hash);
+InstrHash = Bitfield::get(Hash);
+PredHash = Bitfield::get(Hash);
+SuccHash = Bitfield::get(Hash);
+  }
+
+  /// Combine the blended hash into uint64_t.
+  uint64_t combine() const {
+uint64_t Hash = 0;
+Bitfield::set(Hash, Offset);
+Bitfield::set(Hash, OpcodeHash);
+Bitfield::set(Hash, InstrHash);
+Bitfield::set(Hash, PredHash);
+Bitfield::set(Hash, SuccHash);
+return Hash;
+  }
+
+  /// Compute a distance between two given blended hashes. The smaller the
+  /// distance, the more similar two blocks are. For identical basic blocks,
+  /// the distance is zero.
+  uint64_t distance(const BlendedBlockHash &BBH) const {
+assert(OpcodeHash == BBH.OpcodeHash &&
+   "incorrect blended hash distance computation");
+uint64_t Dist = 0;
+// Account for NeighborHash
+Dist += SuccHash == BBH.SuccHash ? 0 : 1;
+Dist += PredHash == BBH.PredHash ? 0 : 1;
+Dist <<= 16;
+// Account for InstrHash
+Dist += InstrHash == BBH.InstrHash ? 0 : 1;
+Dist <<= 16;
+// Account for Offset
+Dist += (Offset >= BBH.Offset ? Offset - BBH.Offset : BBH.Offset - Offset);
+return Dist;
+  }
+
+  /// The offset of the basic block from the function start.
+  uint16_t Offset{0};
+  /// (Loose) Hash of the basic block instructions, excluding operands.
+  uint16_t OpcodeHash{0};
+  /// (Str

[llvm-branch-commits] [llvm] 532a2f4 - Revert "Add source file name for template instantiations in -ftime-trace (#98…"

2024-07-18 Thread via llvm-branch-commits

Author: Utkarsh Saxena
Date: 2024-07-18T19:47:06+02:00
New Revision: 532a2f4a7405a37413fac10f772aa2d83c8d57a3

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

LOG: Revert "Add source file name for template instantiations in -ftime-trace 
(#98…"

This reverts commit cd495d2cdd84a22026a115c7e9923c27b196732e.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/FrontendOptions.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/Driver/ftime-trace-sections.cpp
clang/test/Driver/ftime-trace.cpp
clang/tools/driver/cc1_main.cpp
clang/unittests/Support/TimeProfilerTest.cpp
llvm/include/llvm/Support/TimeProfiler.h
llvm/lib/Support/TimeProfiler.cpp

Removed: 
a-abfdec1d.o.tmp



diff  --git a/a-abfdec1d.o.tmp b/a-abfdec1d.o.tmp
deleted file mode 100644
index e69de29bb2d1d..0

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 971df672b6ca1..e0e86af257a19 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -736,9 +736,6 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
-- Clang now adds source file infomation for template instantiations as 
``event["args"]["filename"]``. This
-  added behind an option ``-ftime-trace-verbose``. This is expected to 
increase the size of trace by 2-3 times.
-
 Improvements to Coverage Mapping
 
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d3068c1b30a7a..1675e435d210c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3988,10 +3988,6 @@ def ftime_trace_granularity_EQ : Joined<["-"], 
"ftime-trace-granularity=">, Grou
   HelpText<"Minimum time granularity (in microseconds) traced by time 
profiler">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoInt, "500u">;
-def ftime_trace_verbose : Joined<["-"], "ftime-trace-verbose">, Group,
-  HelpText<"Make time trace capture verbose event details (e.g. source 
filenames). This can increase the size of the output by 2-3 times">,
-  Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
-  MarshallingInfoFlag>;
 def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,

diff  --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 8241925c98476..5e5034fe01eb5 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -580,11 +580,6 @@ class FrontendOptions {
   /// Minimum time granularity (in microseconds) traced by time profiler.
   unsigned TimeTraceGranularity;
 
-  /// Make time trace capture verbose event details (e.g. source filenames).
-  /// This can increase the size of the output by 2-3 times.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned TimeTraceVerbose : 1;
-
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
@@ -606,8 +601,7 @@ class FrontendOptions {
 EmitSymbolGraph(false), EmitExtensionSymbolGraphs(false),
 EmitSymbolGraphSymbolLabelsForTesting(false),
 EmitPrettySymbolGraphs(false), GenReducedBMI(false),
-UseClangIRPipeline(false), TimeTraceGranularity(500),
-TimeTraceVerbose(false) {}
+UseClangIRPipeline(false), TimeTraceGranularity(500) {}
 
   /// getInputKindForExtension - Return the appropriate input kind for a file
   /// extension. For example, "c" would return Language::C.

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 6b33301d36401..1fd6fba210042 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6754,7 +6754,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (const char *Name = C.getTimeTraceFile(&JA)) {
 CmdArgs.push_back(Args.MakeArgString("-ftime-trace=" + Twine(Name)));
 Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
-Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_verbose);
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) {

diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 725b62db5e80a..a7bc6749c

[llvm-branch-commits] [libcxx] [libc++][spaceship] Marks P1614 as complete. (PR #99375)

2024-07-18 Thread Louis Dionne via llvm-branch-commits


@@ -1,5 +1,5 @@
 "Number","Name","Status","First released version"

ldionne wrote:

Could we actually get rid of this file? I don't think it serves much of a 
purpose anymore. We should make sure that all the information in that file is 
tracked in our other `Cxx20Papers.rst` & friends and then get rid of it.

https://github.com/llvm/llvm-project/pull/99375
___
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] [MC][NFC] Use std::map for AddressProbesMap (PR #99553)

2024-07-18 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov created 
https://github.com/llvm/llvm-project/pull/99553

AddressProbesMap is keyed by binary addresses, and it makes sense to
treat them as ordered. This also enables slicing by binary function/
binary basic block, to be used in BOLT.

Test Plan: NFC



___
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] [BOLT] Attach pseudo probes to blocks in YAML profile (PR #99554)

2024-07-18 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov created 
https://github.com/llvm/llvm-project/pull/99554

Read pseudo probes in regular and BAT YAML profile generation, and
attach them to YAML profile basic blocks. This exposes GUID, probe id,
and probe type in profile for future use in stale profile matching.

Test Plan: updated pseudoprobe-decoding-inline.test



___
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] [BOLT] Attach pseudo probes to blocks in YAML profile (PR #99554)

2024-07-18 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-bolt

Author: Amir Ayupov (aaupov)


Changes

Read pseudo probes in regular and BAT YAML profile generation, and
attach them to YAML profile basic blocks. This exposes GUID, probe id,
and probe type in profile for future use in stale profile matching.

Test Plan: updated pseudoprobe-decoding-inline.test


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


4 Files Affected:

- (modified) bolt/include/bolt/Profile/ProfileYAMLMapping.h (+28) 
- (modified) bolt/lib/Profile/DataAggregator.cpp (+27) 
- (modified) bolt/lib/Profile/YAMLProfileWriter.cpp (+15) 
- (modified) bolt/test/X86/pseudoprobe-decoding-inline.test (+8) 


``diff
diff --git a/bolt/include/bolt/Profile/ProfileYAMLMapping.h 
b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
index c4e5f2b284a86..2bc6901e5f591 100644
--- a/bolt/include/bolt/Profile/ProfileYAMLMapping.h
+++ b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
@@ -93,11 +93,36 @@ template <> struct MappingTraits {
   static const bool flow = true;
 };
 
+namespace bolt {
+struct PseudoProbeInfo {
+  llvm::yaml::Hex64 GUID;
+  uint64_t Index;
+  uint8_t Type;
+
+  bool operator==(const PseudoProbeInfo &Other) const {
+return Index == Other.Index;
+  }
+  bool operator!=(const PseudoProbeInfo &Other) const {
+return !(*this == Other);
+  }
+};
+} // end namespace bolt
+
+template <> struct MappingTraits {
+  static void mapping(IO &YamlIO, bolt::PseudoProbeInfo &PI) {
+YamlIO.mapRequired("guid", PI.GUID);
+YamlIO.mapRequired("id", PI.Index);
+YamlIO.mapRequired("type", PI.Type);
+  }
+
+  static const bool flow = true;
+};
 } // end namespace yaml
 } // end namespace llvm
 
 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::bolt::CallSiteInfo)
 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::bolt::SuccessorInfo)
+LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::bolt::PseudoProbeInfo)
 
 namespace llvm {
 namespace yaml {
@@ -111,6 +136,7 @@ struct BinaryBasicBlockProfile {
   uint64_t EventCount{0};
   std::vector CallSites;
   std::vector Successors;
+  std::vector PseudoProbes;
 
   bool operator==(const BinaryBasicBlockProfile &Other) const {
 return Index == Other.Index;
@@ -132,6 +158,8 @@ template <> struct 
MappingTraits {
std::vector());
 YamlIO.mapOptional("succ", BBP.Successors,
std::vector());
+YamlIO.mapOptional("pseudo_probes", BBP.PseudoProbes,
+   std::vector());
   }
 };
 
diff --git a/bolt/lib/Profile/DataAggregator.cpp 
b/bolt/lib/Profile/DataAggregator.cpp
index beb03a952d658..85e583c75728f 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -2406,6 +2406,33 @@ std::error_code 
DataAggregator::writeBATYAML(BinaryContext &BC,
   PseudoProbeDecoder->getFuncDescForGUID(YamlBF.GUID);
   YamlBF.PseudoProbeDescHash = FuncDesc->FuncHash;
 }
+// Fetch probes belonging to all fragments
+const AddressProbesMap &ProbeMap =
+PseudoProbeDecoder->getAddress2ProbesMap();
+BinaryFunction::FragmentsSetTy Fragments(BF->Fragments);
+Fragments.insert(BF);
+for (const BinaryFunction *F : Fragments) {
+  const uint64_t FuncAddr = F->getAddress();
+  const auto &FragmentProbes =
+  llvm::make_range(ProbeMap.lower_bound(FuncAddr),
+   ProbeMap.lower_bound(FuncAddr + F->getSize()));
+  for (const auto &[OutputAddress, Probes] : FragmentProbes) {
+const uint32_t InputOffset = BAT->translate(
+FuncAddr, OutputAddress - FuncAddr, /*IsBranchSrc=*/true);
+if (!BlockMap.isInputBlock(InputOffset)) {
+  if (opts::Verbosity >= 1)
+errs() << "BOLT-WARNING: Couldn't map pseudo probe at 0x"
+   << Twine::utohexstr(InputOffset) << " to a block in "
+   << F->getPrintName() << '\n';
+  continue;
+}
+const unsigned BlockIndex = BlockMap.getBBIndex(InputOffset);
+for (const MCDecodedPseudoProbe &Probe : Probes)
+  YamlBF.Blocks[BlockIndex].PseudoProbes.emplace_back(
+  yaml::bolt::PseudoProbeInfo{Probe.getGuid(), 
Probe.getIndex(),
+  Probe.getType()});
+  }
+}
   }
   // Drop blocks without a hash, won't be useful for stale matching.
   llvm::erase_if(YamlBF.Blocks,
diff --git a/bolt/lib/Profile/YAMLProfileWriter.cpp 
b/bolt/lib/Profile/YAMLProfileWriter.cpp
index 38345da73df7c..cfad75bd5a404 100644
--- a/bolt/lib/Profile/YAMLProfileWriter.cpp
+++ b/bolt/lib/Profile/YAMLProfileWriter.cpp
@@ -185,6 +185,21 @@ YAMLProfileWriter::convert(const BinaryFunction &BF, bool 
UseDFS,
   ++BranchInfo;
 }
 
+if (PseudoProbeDecoder) {
+  const AddressProbesMap &ProbeMap =
+  PseudoProbeDecoder->getAddress2Prob

[llvm-branch-commits] [MC][NFC] Use std::map for AddressProbesMap (PR #99553)

2024-07-18 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov edited https://github.com/llvm/llvm-project/pull/99553
___
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] [BOLT] Attach pseudo probes to blocks in YAML profile (PR #99554)

2024-07-18 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/99554

>From 9498f8f38cea050fd363d5d4591e8401e5de8bd5 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 18 Jul 2024 12:49:23 -0700
Subject: [PATCH] Fix operator==

Created using spr 1.3.4
---
 bolt/include/bolt/Profile/ProfileYAMLMapping.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/include/bolt/Profile/ProfileYAMLMapping.h 
b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
index 2bc6901e5f591..2a0514d7d9304 100644
--- a/bolt/include/bolt/Profile/ProfileYAMLMapping.h
+++ b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
@@ -100,7 +100,7 @@ struct PseudoProbeInfo {
   uint8_t Type;
 
   bool operator==(const PseudoProbeInfo &Other) const {
-return Index == Other.Index;
+return GUID == Other.GUID && Index == Other.Index;
   }
   bool operator!=(const PseudoProbeInfo &Other) const {
 return !(*this == Other);

___
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] [BOLT] Attach pseudo probes to blocks in YAML profile (PR #99554)

2024-07-18 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/99554

>From 9498f8f38cea050fd363d5d4591e8401e5de8bd5 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 18 Jul 2024 12:49:23 -0700
Subject: [PATCH 1/2] Fix operator==

Created using spr 1.3.4
---
 bolt/include/bolt/Profile/ProfileYAMLMapping.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/include/bolt/Profile/ProfileYAMLMapping.h 
b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
index 2bc6901e5f591..2a0514d7d9304 100644
--- a/bolt/include/bolt/Profile/ProfileYAMLMapping.h
+++ b/bolt/include/bolt/Profile/ProfileYAMLMapping.h
@@ -100,7 +100,7 @@ struct PseudoProbeInfo {
   uint8_t Type;
 
   bool operator==(const PseudoProbeInfo &Other) const {
-return Index == Other.Index;
+return GUID == Other.GUID && Index == Other.Index;
   }
   bool operator!=(const PseudoProbeInfo &Other) const {
 return !(*this == Other);

>From 956084a3b4078f10d953ecab20720e9cf2d25554 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 18 Jul 2024 12:55:50 -0700
Subject: [PATCH 2/2] Fix probe mapping to block in BAT mode

Created using spr 1.3.4
---
 bolt/lib/Profile/DataAggregator.cpp | 9 +
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/bolt/lib/Profile/DataAggregator.cpp 
b/bolt/lib/Profile/DataAggregator.cpp
index 85e583c75728f..1da018c346d36 100644
--- a/bolt/lib/Profile/DataAggregator.cpp
+++ b/bolt/lib/Profile/DataAggregator.cpp
@@ -2419,14 +2419,7 @@ std::error_code 
DataAggregator::writeBATYAML(BinaryContext &BC,
   for (const auto &[OutputAddress, Probes] : FragmentProbes) {
 const uint32_t InputOffset = BAT->translate(
 FuncAddr, OutputAddress - FuncAddr, /*IsBranchSrc=*/true);
-if (!BlockMap.isInputBlock(InputOffset)) {
-  if (opts::Verbosity >= 1)
-errs() << "BOLT-WARNING: Couldn't map pseudo probe at 0x"
-   << Twine::utohexstr(InputOffset) << " to a block in "
-   << F->getPrintName() << '\n';
-  continue;
-}
-const unsigned BlockIndex = BlockMap.getBBIndex(InputOffset);
+const unsigned BlockIndex = getBlock(InputOffset).second;
 for (const MCDecodedPseudoProbe &Probe : Probes)
   YamlBF.Blocks[BlockIndex].PseudoProbes.emplace_back(
   yaml::bolt::PseudoProbeInfo{Probe.getGuid(), 
Probe.getIndex(),

___
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] [BOLT] Support POSSIBLE_PIC_FIXED_BRANCH (PR #91667)

2024-07-18 Thread Rafael Auler via llvm-branch-commits

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

Thanks for working on this, Amir

https://github.com/llvm/llvm-project/pull/91667
___
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] [BOLT] Support POSSIBLE_PIC_FIXED_BRANCH (PR #91667)

2024-07-18 Thread Rafael Auler via llvm-branch-commits

https://github.com/rafaelauler edited 
https://github.com/llvm/llvm-project/pull/91667
___
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] [BOLT] Support POSSIBLE_PIC_FIXED_BRANCH (PR #91667)

2024-07-18 Thread Rafael Auler via llvm-branch-commits


@@ -2523,6 +2523,16 @@ BinaryFunction 
*BinaryContext::getBinaryFunctionAtAddress(uint64_t Address) {
   return nullptr;
 }
 
+/// Deregister JumpTable registered at a given \p Address and delete it.
+void BinaryContext::deleteJumpTable(uint64_t Address) {
+  JumpTable *JT = getJumpTableContainingAddress(Address);
+  assert(JT && "Must have a jump table at address");

rafaelauler wrote:

Maybe assert that the jump table you're trying to delete is also _exactly_ at 
Address? If I understand correctly the logic here, you don't expect the jump 
table to start at any other address other than Address. If it does, we are 
accidentally deleting something that we shouldn't be, no?

Or do you want to cover cases where the reference is not exactly to Address as 
well?

https://github.com/llvm/llvm-project/pull/91667
___
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] [BOLT] Support POSSIBLE_PIC_FIXED_BRANCH (PR #91667)

2024-07-18 Thread Rafael Auler via llvm-branch-commits


@@ -1876,6 +1876,13 @@ class X86MCPlusBuilder : public MCPlusBuilder {
 //add %r2, %r1
 //jmp *%r1
 //
+// or a fixed indirect jump template:
+//
+//movslq En(%rip), {%r2|%r1}
+//lea PIC_JUMP_TABLE(%rip), {%r1|%r2} <- MemLocInstr

rafaelauler wrote:

Update this comment and the one above it to reflect the new matching logic: 
there is no MemLocInstr anymore

https://github.com/llvm/llvm-project/pull/91667
___
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] [BOLT] Match functions with call graph (PR #98125)

2024-07-18 Thread Davide Italiano via llvm-branch-commits

https://github.com/dcci commented:

LG

https://github.com/llvm/llvm-project/pull/98125
___
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] [BOLT] Attach pseudo probes to blocks in YAML profile (PR #99554)

2024-07-18 Thread Rafael Auler via llvm-branch-commits

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

LGTM, though not an expert in pseudo probes

https://github.com/llvm/llvm-project/pull/99554
___
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] [libc] 635c7a9 - Revert "[libc] implement cached process/thread identity (#98989)"

2024-07-18 Thread via llvm-branch-commits

Author: Schrodinger ZHU Yifan
Date: 2024-07-18T13:29:32-07:00
New Revision: 635c7a937b7e4f593af53054bff07c86ca00e51c

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

LOG: Revert "[libc] implement cached process/thread identity (#98989)"

This reverts commit 5c9fc3cdd7acae4ede998f2983e6107f3c0ea36a.

Added: 


Modified: 
libc/config/config.json
libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/riscv/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/docs/configure.rst
libc/docs/dev/undefined_behavior.rst
libc/spec/posix.td
libc/src/__support/OSUtil/CMakeLists.txt
libc/src/__support/OSUtil/linux/CMakeLists.txt
libc/src/__support/threads/CMakeLists.txt
libc/src/__support/threads/linux/CMakeLists.txt
libc/src/__support/threads/linux/rwlock.h
libc/src/__support/threads/linux/thread.cpp
libc/src/__support/threads/thread.h
libc/src/unistd/CMakeLists.txt
libc/src/unistd/getpid.h
libc/src/unistd/linux/CMakeLists.txt
libc/src/unistd/linux/fork.cpp
libc/src/unistd/linux/getpid.cpp
libc/startup/linux/CMakeLists.txt
libc/startup/linux/do_start.cpp
libc/test/integration/src/unistd/CMakeLists.txt
libc/test/integration/src/unistd/fork_test.cpp
libc/test/src/unistd/CMakeLists.txt

Removed: 
libc/src/__support/OSUtil/linux/pid.cpp
libc/src/__support/OSUtil/pid.h
libc/src/__support/threads/tid.h
libc/src/unistd/gettid.cpp
libc/src/unistd/gettid.h
libc/test/src/unistd/gettid_test.cpp



diff  --git a/libc/config/config.json b/libc/config/config.json
index 0fc88e2b8dbd5..94bfed894c173 100644
--- a/libc/config/config.json
+++ b/libc/config/config.json
@@ -75,16 +75,6 @@
 "LIBC_CONF_FREELIST_MALLOC_BUFFER_SIZE": {
   "value": 1073741824,
   "doc": "Default size for the constinit freelist buffer used for the 
freelist malloc implementation (default 1o 1GB)."
-},
-  },
-  "unistd": {
-"LIBC_CONF_ENABLE_TID_CACHE": {
-  "value": true,
-  "doc": "Enable caching mechanism for gettid to avoid syscall (only 
effective in fullbuild mode, default to true). Please refer to Undefined 
Behavior documentation for implications."
-},
-"LIBC_CONF_ENABLE_PID_CACHE": {
-  "value": true,
-  "doc": "Enable caching mechanism for getpid to avoid syscall (default to 
true). Please refer to Undefined Behavior documentation for implications."
 }
   },
   "math": {

diff  --git a/libc/config/linux/aarch64/entrypoints.txt 
b/libc/config/linux/aarch64/entrypoints.txt
index fc2b61226c3fc..208889ba34a59 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -297,7 +297,6 @@ set(TARGET_LIBC_ENTRYPOINTS
 libc.src.unistd.geteuid
 libc.src.unistd.getpid
 libc.src.unistd.getppid
-libc.src.unistd.gettid
 libc.src.unistd.getuid
 libc.src.unistd.isatty
 libc.src.unistd.link

diff  --git a/libc/config/linux/riscv/entrypoints.txt 
b/libc/config/linux/riscv/entrypoints.txt
index b2e68fdaa86e9..266c94d54a9df 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -296,7 +296,6 @@ set(TARGET_LIBC_ENTRYPOINTS
 libc.src.unistd.geteuid
 libc.src.unistd.getpid
 libc.src.unistd.getppid
-libc.src.unistd.gettid
 libc.src.unistd.getuid
 libc.src.unistd.isatty
 libc.src.unistd.link

diff  --git a/libc/config/linux/x86_64/entrypoints.txt 
b/libc/config/linux/x86_64/entrypoints.txt
index 9074bd8aea1f1..cbdee084aa199 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -315,7 +315,6 @@ set(TARGET_LIBC_ENTRYPOINTS
 libc.src.unistd.geteuid
 libc.src.unistd.getpid
 libc.src.unistd.getppid
-libc.src.unistd.gettid
 libc.src.unistd.getuid
 libc.src.unistd.isatty
 libc.src.unistd.link

diff  --git a/libc/docs/configure.rst b/libc/docs/configure.rst
index 5c55e4ab0f181..dfb35f6a6611a 100644
--- a/libc/docs/configure.rst
+++ b/libc/docs/configure.rst
@@ -52,6 +52,3 @@ to learn about the defaults for your platform and target.
 * **"string" options**
 - ``LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING``: Inserts prefetch for 
write instructions (PREFETCHW) for memset on x86 to recover performance when 
hardware prefetcher is disabled.
 - ``LIBC_CONF_STRING_UNSAFE_WIDE_READ``: Read more than a byte at a time 
to perform byte-string operations like strlen.
-* **"unistd" options**
-- ``LIBC_CONF_ENABLE_PID_CACHE``: Enable caching mechanism for getpid to 
avoid syscall (default to true). Please refer to Undefined Behavior 
documentation for implications.
-- ``LIBC_CONF_ENABLE_TID_CACHE``: Enable caching mechanism for gettid to 
avoid syscall (only 

[llvm-branch-commits] [llvm] [BOLT] Match functions with call graph (PR #98125)

2024-07-18 Thread Shaw Young via llvm-branch-commits

https://github.com/shawbyoung updated 
https://github.com/llvm/llvm-project/pull/98125

>From cf32a43e7c2b04079c6123fe13df4fb7226d771f Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Tue, 9 Jul 2024 10:04:25 -0700
Subject: [PATCH 01/16] Comments

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileReader.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp 
b/bolt/lib/Profile/YAMLProfileReader.cpp
index 69ea0899c5f2c..6753337c24ea7 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -501,7 +501,6 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 
   // Maps binary functions to adjacent functions in the FCG.
   for (const BinaryFunction *CallerBF : BFs) {
-// Add all call targets to the hash map.
 for (const BinaryBasicBlock &BB : CallerBF->blocks()) {
   for (const MCInst &Inst : BB) {
 if (!BC.MIB->isCall(Instr))
@@ -533,7 +532,8 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 }
   }
 
-  // Create mapping from neighbor hash to BFs.
+  // Using the constructed adjacent function mapping, creates mapping from
+  // neighbor hash to BFs.
   std::unordered_map>
   NeighborHashToBFs;
   for (const BinaryFunction *BF : BFs) {
@@ -552,12 +552,12 @@ size_t 
YAMLProfileReader::matchWithCallGraph(BinaryContext &BC) {
 .push_back(BF);
   }
 
-  // TODO: change call anchor PR to have this representation - we need it here
+  // TODO: note, this will be introduced in the matching functions with calls
+  // as anchors pr
   DenseMap
   IdToYAMLBF;
-  // TODO: change call anchor PR to have this representation - we need it here
 
-  // Maps hashes to profiled functions.
+  // Maps YAML functions to adjacent functions in the profile FCG.
   std::unordered_map
   YamlBFToHashes(BFs.size());
@@ -590,7 +590,7 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 }
   }
 
-  // Matching YAMLBF with neighbor hashes.
+  // Matches YAMLBF to BFs with neighbor hashes.
   for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) {
 if (YamlBF.Used)
   continue;

>From ee9049fc4bd3d4203c19c9c0982a78ab3b47666f Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Tue, 9 Jul 2024 13:52:05 -0700
Subject: [PATCH 02/16] Moved blended hash definition

Created using spr 1.3.4
---
 bolt/include/bolt/Profile/YAMLProfileReader.h |  69 ++-
 bolt/lib/Profile/StaleProfileMatching.cpp |  65 ---
 bolt/lib/Profile/YAMLProfileReader.cpp| 110 --
 3 files changed, 119 insertions(+), 125 deletions(-)

diff --git a/bolt/include/bolt/Profile/YAMLProfileReader.h 
b/bolt/include/bolt/Profile/YAMLProfileReader.h
index 36e8f8739eee1..e8a34ecad9a08 100644
--- a/bolt/include/bolt/Profile/YAMLProfileReader.h
+++ b/bolt/include/bolt/Profile/YAMLProfileReader.h
@@ -16,6 +16,73 @@
 namespace llvm {
 namespace bolt {
 
+/// An object wrapping several components of a basic block hash. The combined
+/// (blended) hash is represented and stored as one uint64_t, while individual
+/// components are of smaller size (e.g., uint16_t or uint8_t).
+struct BlendedBlockHash {
+private:
+  using ValueOffset = Bitfield::Element;
+  using ValueOpcode = Bitfield::Element;
+  using ValueInstr = Bitfield::Element;
+  using ValuePred = Bitfield::Element;
+  using ValueSucc = Bitfield::Element;
+
+public:
+  explicit BlendedBlockHash() {}
+
+  explicit BlendedBlockHash(uint64_t Hash) {
+Offset = Bitfield::get(Hash);
+OpcodeHash = Bitfield::get(Hash);
+InstrHash = Bitfield::get(Hash);
+PredHash = Bitfield::get(Hash);
+SuccHash = Bitfield::get(Hash);
+  }
+
+  /// Combine the blended hash into uint64_t.
+  uint64_t combine() const {
+uint64_t Hash = 0;
+Bitfield::set(Hash, Offset);
+Bitfield::set(Hash, OpcodeHash);
+Bitfield::set(Hash, InstrHash);
+Bitfield::set(Hash, PredHash);
+Bitfield::set(Hash, SuccHash);
+return Hash;
+  }
+
+  /// Compute a distance between two given blended hashes. The smaller the
+  /// distance, the more similar two blocks are. For identical basic blocks,
+  /// the distance is zero.
+  uint64_t distance(const BlendedBlockHash &BBH) const {
+assert(OpcodeHash == BBH.OpcodeHash &&
+   "incorrect blended hash distance computation");
+uint64_t Dist = 0;
+// Account for NeighborHash
+Dist += SuccHash == BBH.SuccHash ? 0 : 1;
+Dist += PredHash == BBH.PredHash ? 0 : 1;
+Dist <<= 16;
+// Account for InstrHash
+Dist += InstrHash == BBH.InstrHash ? 0 : 1;
+Dist <<= 16;
+// Account for Offset
+Dist += (Offset >= BBH.Offset ? Offset - BBH.Offset : BBH.Offset - Offset);
+return Dist;
+  }
+
+  /// The offset of the basic block from the function start.
+  uint16_t Offset{0};
+  /// (Loose) Hash of the basic block instructions, excluding operands.
+  uint16_t OpcodeHash{0};
+  /// (Str

[llvm-branch-commits] [llvm] [BOLT] Match functions with call graph (PR #98125)

2024-07-18 Thread Shaw Young via llvm-branch-commits

https://github.com/shawbyoung updated 
https://github.com/llvm/llvm-project/pull/98125

>From cf32a43e7c2b04079c6123fe13df4fb7226d771f Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Tue, 9 Jul 2024 10:04:25 -0700
Subject: [PATCH 01/16] Comments

Created using spr 1.3.4
---
 bolt/lib/Profile/YAMLProfileReader.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp 
b/bolt/lib/Profile/YAMLProfileReader.cpp
index 69ea0899c5f2c..6753337c24ea7 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -501,7 +501,6 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 
   // Maps binary functions to adjacent functions in the FCG.
   for (const BinaryFunction *CallerBF : BFs) {
-// Add all call targets to the hash map.
 for (const BinaryBasicBlock &BB : CallerBF->blocks()) {
   for (const MCInst &Inst : BB) {
 if (!BC.MIB->isCall(Instr))
@@ -533,7 +532,8 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 }
   }
 
-  // Create mapping from neighbor hash to BFs.
+  // Using the constructed adjacent function mapping, creates mapping from
+  // neighbor hash to BFs.
   std::unordered_map>
   NeighborHashToBFs;
   for (const BinaryFunction *BF : BFs) {
@@ -552,12 +552,12 @@ size_t 
YAMLProfileReader::matchWithCallGraph(BinaryContext &BC) {
 .push_back(BF);
   }
 
-  // TODO: change call anchor PR to have this representation - we need it here
+  // TODO: note, this will be introduced in the matching functions with calls
+  // as anchors pr
   DenseMap
   IdToYAMLBF;
-  // TODO: change call anchor PR to have this representation - we need it here
 
-  // Maps hashes to profiled functions.
+  // Maps YAML functions to adjacent functions in the profile FCG.
   std::unordered_map
   YamlBFToHashes(BFs.size());
@@ -590,7 +590,7 @@ size_t YAMLProfileReader::matchWithCallGraph(BinaryContext 
&BC) {
 }
   }
 
-  // Matching YAMLBF with neighbor hashes.
+  // Matches YAMLBF to BFs with neighbor hashes.
   for (yaml::bolt::BinaryFunctionProfile &YamlBF : YamlBP.Functions) {
 if (YamlBF.Used)
   continue;

>From ee9049fc4bd3d4203c19c9c0982a78ab3b47666f Mon Sep 17 00:00:00 2001
From: shawbyoung 
Date: Tue, 9 Jul 2024 13:52:05 -0700
Subject: [PATCH 02/16] Moved blended hash definition

Created using spr 1.3.4
---
 bolt/include/bolt/Profile/YAMLProfileReader.h |  69 ++-
 bolt/lib/Profile/StaleProfileMatching.cpp |  65 ---
 bolt/lib/Profile/YAMLProfileReader.cpp| 110 --
 3 files changed, 119 insertions(+), 125 deletions(-)

diff --git a/bolt/include/bolt/Profile/YAMLProfileReader.h 
b/bolt/include/bolt/Profile/YAMLProfileReader.h
index 36e8f8739eee1..e8a34ecad9a08 100644
--- a/bolt/include/bolt/Profile/YAMLProfileReader.h
+++ b/bolt/include/bolt/Profile/YAMLProfileReader.h
@@ -16,6 +16,73 @@
 namespace llvm {
 namespace bolt {
 
+/// An object wrapping several components of a basic block hash. The combined
+/// (blended) hash is represented and stored as one uint64_t, while individual
+/// components are of smaller size (e.g., uint16_t or uint8_t).
+struct BlendedBlockHash {
+private:
+  using ValueOffset = Bitfield::Element;
+  using ValueOpcode = Bitfield::Element;
+  using ValueInstr = Bitfield::Element;
+  using ValuePred = Bitfield::Element;
+  using ValueSucc = Bitfield::Element;
+
+public:
+  explicit BlendedBlockHash() {}
+
+  explicit BlendedBlockHash(uint64_t Hash) {
+Offset = Bitfield::get(Hash);
+OpcodeHash = Bitfield::get(Hash);
+InstrHash = Bitfield::get(Hash);
+PredHash = Bitfield::get(Hash);
+SuccHash = Bitfield::get(Hash);
+  }
+
+  /// Combine the blended hash into uint64_t.
+  uint64_t combine() const {
+uint64_t Hash = 0;
+Bitfield::set(Hash, Offset);
+Bitfield::set(Hash, OpcodeHash);
+Bitfield::set(Hash, InstrHash);
+Bitfield::set(Hash, PredHash);
+Bitfield::set(Hash, SuccHash);
+return Hash;
+  }
+
+  /// Compute a distance between two given blended hashes. The smaller the
+  /// distance, the more similar two blocks are. For identical basic blocks,
+  /// the distance is zero.
+  uint64_t distance(const BlendedBlockHash &BBH) const {
+assert(OpcodeHash == BBH.OpcodeHash &&
+   "incorrect blended hash distance computation");
+uint64_t Dist = 0;
+// Account for NeighborHash
+Dist += SuccHash == BBH.SuccHash ? 0 : 1;
+Dist += PredHash == BBH.PredHash ? 0 : 1;
+Dist <<= 16;
+// Account for InstrHash
+Dist += InstrHash == BBH.InstrHash ? 0 : 1;
+Dist <<= 16;
+// Account for Offset
+Dist += (Offset >= BBH.Offset ? Offset - BBH.Offset : BBH.Offset - Offset);
+return Dist;
+  }
+
+  /// The offset of the basic block from the function start.
+  uint16_t Offset{0};
+  /// (Loose) Hash of the basic block instructions, excluding operands.
+  uint16_t OpcodeHash{0};
+  /// (Str

[llvm-branch-commits] [MC][NFC] Use std::map for AddressProbesMap (PR #99553)

2024-07-18 Thread Lei Wang via llvm-branch-commits

https://github.com/wlei-llvm approved this pull request.

LGTM.

https://github.com/llvm/llvm-project/pull/99553
___
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] [misexpect] Support diagnostics from frontend profile data (PR #96524)

2024-07-18 Thread Paul Kirth via llvm-branch-commits

https://github.com/ilovepi edited 
https://github.com/llvm/llvm-project/pull/96524
___
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] [BOLT] Support POSSIBLE_PIC_FIXED_BRANCH (PR #91667)

2024-07-18 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/91667

>From dd4d0de42048c063d5e5095a0c2594c7cc578df5 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 9 May 2024 19:35:26 -0700
Subject: [PATCH 1/5] Fix RISCVMCPlusBuilder

Created using spr 1.3.4
---
 bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp 
b/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
index 74f2f0aae91e6..020e62463ee2f 100644
--- a/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
+++ b/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
@@ -177,13 +177,14 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
   MCInst &Instruction, InstructionIterator Begin, InstructionIterator End,
   const unsigned PtrSize, MCInst *&MemLocInstr, unsigned &BaseRegNum,
   unsigned &IndexRegNum, int64_t &DispValue, const MCExpr *&DispExpr,
-  MCInst *&PCRelBaseOut) const override {
+  MCInst *&PCRelBaseOut, MCInst *&FixedEntryLoadInst) const override {
 MemLocInstr = nullptr;
 BaseRegNum = 0;
 IndexRegNum = 0;
 DispValue = 0;
 DispExpr = nullptr;
 PCRelBaseOut = nullptr;
+FixedEntryLoadInst = nullptr;
 
 // Check for the following long tail call sequence:
 // 1: auipc xi, %pcrel_hi(sym)

>From 62391bb5aa01f2b77d4315d1e72a9924eec9ecc0 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Fri, 5 Jul 2024 14:54:51 -0700
Subject: [PATCH 2/5] Drop deregisterJumpTable

Created using spr 1.3.4
---
 bolt/lib/Core/BinaryFunction.cpp | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 09a6ca1d68730..f587d5a2cadd4 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -899,17 +899,9 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, 
unsigned Size,
 
 TargetAddress = ArrayStart + *Value;
 
-// Remove spurious JumpTable at EntryAddress caused by PIC reference from
-// the load instruction.
-JumpTable *JT = BC.getJumpTableContainingAddress(EntryAddress);
-assert(JT && "Must have a jump table at fixed entry address");
-BC.deregisterJumpTable(EntryAddress);
-JumpTables.erase(EntryAddress);
-delete JT;
-
 // Replace FixedEntryDispExpr used in target address calculation with outer
 // jump table reference.
-JT = BC.getJumpTableContainingAddress(ArrayStart);
+JumpTable *JT = BC.getJumpTableContainingAddress(ArrayStart);
 assert(JT && "Must have a containing jump table for PIC fixed branch");
 BC.MIB->replaceMemOperandDisp(*FixedEntryLoadInstr, JT->getFirstLabel(),
   EntryAddress - ArrayStart, &*BC.Ctx);

>From 5336879ab68aedb1217e2c6c139d171f31e89e03 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Sat, 6 Jul 2024 22:26:14 -0700
Subject: [PATCH 3/5] Surgically drop spurious jump table

Created using spr 1.3.4
---
 bolt/include/bolt/Core/BinaryContext.h  |  5 +
 bolt/lib/Core/BinaryFunction.cpp| 12 ++--
 bolt/test/X86/jump-table-fixed-ref-pic.test | 11 ---
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/bolt/include/bolt/Core/BinaryContext.h 
b/bolt/include/bolt/Core/BinaryContext.h
index 73932c4ca2fb3..c5e2c6cd02179 100644
--- a/bolt/include/bolt/Core/BinaryContext.h
+++ b/bolt/include/bolt/Core/BinaryContext.h
@@ -431,6 +431,11 @@ class BinaryContext {
 return nullptr;
   }
 
+  /// Deregister JumpTable registered at a given \p Address.
+  bool deregisterJumpTable(uint64_t Address) {
+return JumpTables.erase(Address);
+  }
+
   unsigned getDWARFEncodingSize(unsigned Encoding) {
 if (Encoding == dwarf::DW_EH_PE_omit)
   return 0;
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index f587d5a2cadd4..2ecca32a5985c 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -899,9 +899,17 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, 
unsigned Size,
 
 TargetAddress = ArrayStart + *Value;
 
+// Remove spurious JumpTable at EntryAddress caused by PIC reference from
+// the load instruction.
+JumpTable *JT = BC.getJumpTableContainingAddress(EntryAddress);
+assert(JT && "Must have a jump table at fixed entry address");
+BC.deregisterJumpTable(EntryAddress);
+JumpTables.erase(EntryAddress);
+delete JT;
+
 // Replace FixedEntryDispExpr used in target address calculation with outer
 // jump table reference.
-JumpTable *JT = BC.getJumpTableContainingAddress(ArrayStart);
+JT = BC.getJumpTableContainingAddress(ArrayStart);
 assert(JT && "Must have a containing jump table for PIC fixed branch");
 BC.MIB->replaceMemOperandDisp(*FixedEntryLoadInstr, JT->getFirstLabel(),
   EntryAddress - ArrayStart, &*BC.Ctx);
@@ -1158,10 +1166,10 @@ void BinaryFunction:

[llvm-branch-commits] [llvm] [BOLT] Support POSSIBLE_PIC_FIXED_BRANCH (PR #91667)

2024-07-18 Thread Amir Ayupov via llvm-branch-commits


@@ -1876,6 +1876,13 @@ class X86MCPlusBuilder : public MCPlusBuilder {
 //add %r2, %r1
 //jmp *%r1
 //
+// or a fixed indirect jump template:
+//
+//movslq En(%rip), {%r2|%r1}
+//lea PIC_JUMP_TABLE(%rip), {%r1|%r2} <- MemLocInstr

aaupov wrote:

Updated the comment. There's still MemLocInstr as a return argument.

https://github.com/llvm/llvm-project/pull/91667
___
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] [BOLT] Support POSSIBLE_PIC_FIXED_BRANCH (PR #91667)

2024-07-18 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/91667

>From dd4d0de42048c063d5e5095a0c2594c7cc578df5 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Thu, 9 May 2024 19:35:26 -0700
Subject: [PATCH 1/6] Fix RISCVMCPlusBuilder

Created using spr 1.3.4
---
 bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp 
b/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
index 74f2f0aae91e6..020e62463ee2f 100644
--- a/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
+++ b/bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp
@@ -177,13 +177,14 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
   MCInst &Instruction, InstructionIterator Begin, InstructionIterator End,
   const unsigned PtrSize, MCInst *&MemLocInstr, unsigned &BaseRegNum,
   unsigned &IndexRegNum, int64_t &DispValue, const MCExpr *&DispExpr,
-  MCInst *&PCRelBaseOut) const override {
+  MCInst *&PCRelBaseOut, MCInst *&FixedEntryLoadInst) const override {
 MemLocInstr = nullptr;
 BaseRegNum = 0;
 IndexRegNum = 0;
 DispValue = 0;
 DispExpr = nullptr;
 PCRelBaseOut = nullptr;
+FixedEntryLoadInst = nullptr;
 
 // Check for the following long tail call sequence:
 // 1: auipc xi, %pcrel_hi(sym)

>From 62391bb5aa01f2b77d4315d1e72a9924eec9ecc0 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Fri, 5 Jul 2024 14:54:51 -0700
Subject: [PATCH 2/6] Drop deregisterJumpTable

Created using spr 1.3.4
---
 bolt/lib/Core/BinaryFunction.cpp | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 09a6ca1d68730..f587d5a2cadd4 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -899,17 +899,9 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, 
unsigned Size,
 
 TargetAddress = ArrayStart + *Value;
 
-// Remove spurious JumpTable at EntryAddress caused by PIC reference from
-// the load instruction.
-JumpTable *JT = BC.getJumpTableContainingAddress(EntryAddress);
-assert(JT && "Must have a jump table at fixed entry address");
-BC.deregisterJumpTable(EntryAddress);
-JumpTables.erase(EntryAddress);
-delete JT;
-
 // Replace FixedEntryDispExpr used in target address calculation with outer
 // jump table reference.
-JT = BC.getJumpTableContainingAddress(ArrayStart);
+JumpTable *JT = BC.getJumpTableContainingAddress(ArrayStart);
 assert(JT && "Must have a containing jump table for PIC fixed branch");
 BC.MIB->replaceMemOperandDisp(*FixedEntryLoadInstr, JT->getFirstLabel(),
   EntryAddress - ArrayStart, &*BC.Ctx);

>From 5336879ab68aedb1217e2c6c139d171f31e89e03 Mon Sep 17 00:00:00 2001
From: Amir Ayupov 
Date: Sat, 6 Jul 2024 22:26:14 -0700
Subject: [PATCH 3/6] Surgically drop spurious jump table

Created using spr 1.3.4
---
 bolt/include/bolt/Core/BinaryContext.h  |  5 +
 bolt/lib/Core/BinaryFunction.cpp| 12 ++--
 bolt/test/X86/jump-table-fixed-ref-pic.test | 11 ---
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/bolt/include/bolt/Core/BinaryContext.h 
b/bolt/include/bolt/Core/BinaryContext.h
index 73932c4ca2fb3..c5e2c6cd02179 100644
--- a/bolt/include/bolt/Core/BinaryContext.h
+++ b/bolt/include/bolt/Core/BinaryContext.h
@@ -431,6 +431,11 @@ class BinaryContext {
 return nullptr;
   }
 
+  /// Deregister JumpTable registered at a given \p Address.
+  bool deregisterJumpTable(uint64_t Address) {
+return JumpTables.erase(Address);
+  }
+
   unsigned getDWARFEncodingSize(unsigned Encoding) {
 if (Encoding == dwarf::DW_EH_PE_omit)
   return 0;
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index f587d5a2cadd4..2ecca32a5985c 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -899,9 +899,17 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, 
unsigned Size,
 
 TargetAddress = ArrayStart + *Value;
 
+// Remove spurious JumpTable at EntryAddress caused by PIC reference from
+// the load instruction.
+JumpTable *JT = BC.getJumpTableContainingAddress(EntryAddress);
+assert(JT && "Must have a jump table at fixed entry address");
+BC.deregisterJumpTable(EntryAddress);
+JumpTables.erase(EntryAddress);
+delete JT;
+
 // Replace FixedEntryDispExpr used in target address calculation with outer
 // jump table reference.
-JumpTable *JT = BC.getJumpTableContainingAddress(ArrayStart);
+JT = BC.getJumpTableContainingAddress(ArrayStart);
 assert(JT && "Must have a containing jump table for PIC fixed branch");
 BC.MIB->replaceMemOperandDisp(*FixedEntryLoadInstr, JT->getFirstLabel(),
   EntryAddress - ArrayStart, &*BC.Ctx);
@@ -1158,10 +1166,10 @@ void BinaryFunction:

[llvm-branch-commits] [lld][ELF][LoongArch] Add support for R_LARCH_LE_{HI20, ADD, LO12}_R relocations (PR #99486)

2024-07-18 Thread via llvm-branch-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/99486


___
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][ELF][LoongArch] Add support for R_LARCH_LE_{HI20, ADD, LO12}_R relocations (PR #99486)

2024-07-18 Thread via llvm-branch-commits

https://github.com/wangleiat updated 
https://github.com/llvm/llvm-project/pull/99486


___
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] [BOLT] Support POSSIBLE_PIC_FIXED_BRANCH (PR #91667)

2024-07-18 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov closed https://github.com/llvm/llvm-project/pull/91667
___
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] [MC][NFC] Use std::map for AddressProbesMap (PR #99553)

2024-07-18 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/99553


___
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] [MC][NFC] Use std::map for AddressProbesMap (PR #99553)

2024-07-18 Thread Amir Ayupov via llvm-branch-commits

https://github.com/aaupov updated 
https://github.com/llvm/llvm-project/pull/99553


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