Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[lldb] Use llvm::bit_ceil (NFC) #138723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2025

Conversation

kazutakahirata
Copy link
Contributor

This patch replaces a local implementation of bit_ceil with
llvm::bit_ceil. Technically, the local implementation evaluates to 0
on input 0, whereas llvm::bit_ceil evaluates to 1, but that doesn't
matter because we have:

// Can't watch zero bytes.
if (user_size == 0)
return {};

This patch replaces a local implementation of bit_ceil with
llvm::bit_ceil.  Technically, the local implementation evaluates to 0
on input 0, whereas llvm::bit_ceil evaluates to 1, but that doesn't
matter because we have:

  // Can't watch zero bytes.
  if (user_size == 0)
    return {};
@llvmbot
Copy link
Member

llvmbot commented May 6, 2025

@llvm/pr-subscribers-lldb

Author: Kazu Hirata (kazutakahirata)

Changes

This patch replaces a local implementation of bit_ceil with
llvm::bit_ceil. Technically, the local implementation evaluates to 0
on input 0, whereas llvm::bit_ceil evaluates to 1, but that doesn't
matter because we have:

// Can't watch zero bytes.
if (user_size == 0)
return {};


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

1 Files Affected:

  • (modified) lldb/source/Breakpoint/WatchpointAlgorithms.cpp (+1-11)
diff --git a/lldb/source/Breakpoint/WatchpointAlgorithms.cpp b/lldb/source/Breakpoint/WatchpointAlgorithms.cpp
index 3caf29b04317f..d65de13db1dad 100644
--- a/lldb/source/Breakpoint/WatchpointAlgorithms.cpp
+++ b/lldb/source/Breakpoint/WatchpointAlgorithms.cpp
@@ -58,16 +58,6 @@ WatchpointAlgorithms::AtomizeWatchpointRequest(
   return resources;
 }
 
-// This should be `std::bit_ceil(aligned_size)` but
-// that requires C++20.
-// Calculates the smallest integral power of two that is not smaller than x.
-static uint64_t bit_ceil(uint64_t input) {
-  if (input <= 1 || llvm::popcount(input) == 1)
-    return input;
-
-  return 1ULL << (64 - llvm::countl_zero(input));
-}
-
 /// Convert a user's watchpoint request (\a user_addr and \a user_size)
 /// into hardware watchpoints, for a target that can watch a power-of-2
 /// region of memory (1, 2, 4, 8, etc), aligned to that same power-of-2
@@ -102,7 +92,7 @@ WatchpointAlgorithms::PowerOf2Watchpoints(addr_t user_addr, size_t user_size,
   /// Round up \a user_size to the next power-of-2 size
   /// user_size == 8   -> aligned_size == 8
   /// user_size == 9   -> aligned_size == 16
-  aligned_size = bit_ceil(aligned_size);
+  aligned_size = llvm::bit_ceil(aligned_size);
 
   addr_t aligned_start = user_addr & ~(aligned_size - 1);
 

Copy link
Collaborator

@jasonmolenda jasonmolenda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kazutakahirata kazutakahirata merged commit 5c3ef62 into llvm:main May 6, 2025
10 of 11 checks passed
GeorgeARM pushed a commit to GeorgeARM/llvm-project that referenced this pull request May 7, 2025
This patch replaces a local implementation of bit_ceil with
llvm::bit_ceil.  Technically, the local implementation evaluates to 0
on input 0, whereas llvm::bit_ceil evaluates to 1, but that doesn't
matter because we have:

  // Can't watch zero bytes.
  if (user_size == 0)
    return {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants