[clang] [llvm] Recover performance loss after PagedVector introduction (PR #67972)

2024-05-29 Thread Giulio Eulisse via cfe-commits

ktf wrote:

I have updated the branch and I think the two changes in this PR are in any 
case good. However it's my understanding that the performance regression was 
actually due to some less aggressive inlining of the new code. I have no idea 
how to proceed for that though.

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


[clang] [llvm] Recover performance loss after PagedVector introduction (PR #67972)

2024-05-29 Thread Giulio Eulisse via cfe-commits

https://github.com/ktf updated https://github.com/llvm/llvm-project/pull/67972

>From 154f82bd0e35e9d8ad8f8812ba3eb1cf8d211003 Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Mon, 2 Oct 2023 13:01:14 +0200
Subject: [PATCH 1/3] Hint for branch likelihood

---
 llvm/include/llvm/ADT/PagedVector.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/ADT/PagedVector.h 
b/llvm/include/llvm/ADT/PagedVector.h
index 667bece6d7183..f8d014c9c84da 100644
--- a/llvm/include/llvm/ADT/PagedVector.h
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -84,7 +84,7 @@ template  
class PagedVector {
 assert(Index / PageSize < PageToDataPtrs.size());
 T * = PageToDataPtrs[Index / PageSize];
 // If the page was not yet allocated, allocate it.
-if (!PagePtr) {
+if (LLVM_UNLIKELY(!PagePtr)) {
   PagePtr = Allocator.getPointer()->template Allocate(PageSize);
   // We need to invoke the default constructor on all the elements of the
   // page.

>From f119cca040b2bebabff8db32394cc4650f5115d5 Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Mon, 2 Oct 2023 17:19:43 +0200
Subject: [PATCH 2/3] Change PageSize to 32 elements

Moves from 42 elements (automatically calculated) to 32. It should
both reduce memory usage (it does at least in my test) and avoid
the need for a division when indexing the elements.
---
 clang/include/clang/Basic/SourceManager.h | 2 +-
 clang/lib/Basic/SourceManager.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index c1b24eec2759c..ac077d1ab3508 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -700,7 +700,7 @@ class SourceManager : public RefCountedBase {
   ///
   /// Negative FileIDs are indexes into this table. To get from ID to an index,
   /// use (-ID - 2).
-  llvm::PagedVector LoadedSLocEntryTable;
+  llvm::PagedVector LoadedSLocEntryTable;
 
   /// The starting offset of the next local SLocEntry.
   ///
diff --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 3066cc53dbfd8..a9c6453da94a3 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -2102,7 +2102,7 @@ std::pair 
SourceManager::isInTheSameTranslationUnit(
 unsigned Offset;
 FileID ParentFID; // Used for breaking ties.
   };
-  llvm::SmallDenseMap LChain;
+  llvm::SmallDenseMap LChain;
 
   FileID Parent;
   do {

>From 684d85f0c889358fddd52ca2a805caaad025fe10 Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Mon, 2 Oct 2023 17:36:09 +0200
Subject: [PATCH 3/3] fix

---
 clang/include/clang/Basic/SourceManager.h | 2 +-
 clang/lib/Basic/SourceManager.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index ac077d1ab3508..1999e1ff4300b 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -700,7 +700,7 @@ class SourceManager : public RefCountedBase {
   ///
   /// Negative FileIDs are indexes into this table. To get from ID to an index,
   /// use (-ID - 2).
-  llvm::PagedVector LoadedSLocEntryTable;
+  llvm::PagedVector LoadedSLocEntryTable;
 
   /// The starting offset of the next local SLocEntry.
   ///
diff --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index a9c6453da94a3..3066cc53dbfd8 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -2102,7 +2102,7 @@ std::pair 
SourceManager::isInTheSameTranslationUnit(
 unsigned Offset;
 FileID ParentFID; // Used for breaking ties.
   };
-  llvm::SmallDenseMap LChain;
+  llvm::SmallDenseMap LChain;
 
   FileID Parent;
   do {

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


[clang] [llvm] Recover performance loss after PagedVector introduction (PR #67972)

2024-05-28 Thread via cfe-commits

cor3ntin wrote:

Should we abandon this?

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