[llvm] 473b059 - [ORC] Add ExecutorAddrRange::fromPtrRange convenience method.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 24 21:45:54 PDT 2025
Author: Lang Hames
Date: 2025-03-25T15:45:48+11:00
New Revision: 473b0595051aa3da2990d389eee05a41bc71e602
URL: https://github.com/llvm/llvm-project/commit/473b0595051aa3da2990d389eee05a41bc71e602
DIFF: https://github.com/llvm/llvm-project/commit/473b0595051aa3da2990d389eee05a41bc71e602.diff
LOG: [ORC] Add ExecutorAddrRange::fromPtrRange convenience method.
This can be used to construct an ExecutorAddrRange from a pair of pointers, or
a pointer and a size.
This will be used to reduce boilerplate in an upcoming patch.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h
llvm/unittests/ExecutionEngine/Orc/ExecutorAddressTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h b/llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h
index c9595ed4d99e7..a4a7fa4be8b9c 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h
@@ -226,6 +226,19 @@ struct ExecutorAddrRange {
ExecutorAddrRange(ExecutorAddr Start, ExecutorAddrDiff Size)
: Start(Start), End(Start + Size) {}
+ template <typename T, typename UnwrapFn = ExecutorAddr::defaultUnwrap<T>>
+ static ExecutorAddrRange fromPtrRange(T *Start, T *End,
+ UnwrapFn &&Unwrap = UnwrapFn()) {
+ return {ExecutorAddr::fromPtr(Start, Unwrap),
+ ExecutorAddr::fromPtr(End, Unwrap)};
+ }
+
+ template <typename T, typename UnwrapFn = ExecutorAddr::defaultUnwrap<T>>
+ static ExecutorAddrRange fromPtrRange(T *Ptr, ExecutorAddrDiff Size,
+ UnwrapFn &&Unwrap = UnwrapFn()) {
+ return {ExecutorAddr::fromPtr(Ptr, std::forward<UnwrapFn>(Unwrap)), Size};
+ }
+
bool empty() const { return Start == End; }
ExecutorAddrDiff size() const { return End - Start; }
diff --git a/llvm/unittests/ExecutionEngine/Orc/ExecutorAddressTest.cpp b/llvm/unittests/ExecutionEngine/Orc/ExecutorAddressTest.cpp
index 3de77031291c5..ae9db141bdd4a 100644
--- a/llvm/unittests/ExecutionEngine/Orc/ExecutorAddressTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/ExecutorAddressTest.cpp
@@ -106,6 +106,16 @@ TEST(ExecutorAddrTest, AddrRanges) {
EXPECT_LT(R0, R1);
EXPECT_GE(R0, R0);
EXPECT_GT(R1, R0);
+
+ // Check fromPtr support.
+ char A[10];
+ auto RP1 = ExecutorAddrRange::fromPtrRange(A, A + 10);
+ EXPECT_EQ(RP1.Start.toPtr<char *>(), A);
+ EXPECT_EQ(RP1.End.toPtr<char *>(), A + 10);
+
+ auto RP2 = ExecutorAddrRange::fromPtrRange(A, 10);
+ EXPECT_EQ(RP2.Start.toPtr<char *>(), A);
+ EXPECT_EQ(RP2.End.toPtr<char *>(), A + 10);
}
TEST(ExecutorSymbolDef, PointerConversion) {
More information about the llvm-commits
mailing list