[llvm] 376b5c0 - [SandboxIR][NFC] Use accessor for DataLayout rather than passing it down (#111447)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 7 15:34:37 PDT 2024
Author: Sterling-Augustine
Date: 2024-10-07T15:34:33-07:00
New Revision: 376b5c0cb6d5c2e559c8689acb1bb1d30f5325aa
URL: https://github.com/llvm/llvm-project/commit/376b5c0cb6d5c2e559c8689acb1bb1d30f5325aa
DIFF: https://github.com/llvm/llvm-project/commit/376b5c0cb6d5c2e559c8689acb1bb1d30f5325aa.diff
LOG: [SandboxIR][NFC] Use accessor for DataLayout rather than passing it down (#111447)
Added:
Modified:
llvm/include/llvm/SandboxIR/Utils.h
llvm/unittests/SandboxIR/UtilsTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/SandboxIR/Utils.h b/llvm/include/llvm/SandboxIR/Utils.h
index e50621b4c1228e..e4156c6af9a220 100644
--- a/llvm/include/llvm/SandboxIR/Utils.h
+++ b/llvm/include/llvm/SandboxIR/Utils.h
@@ -71,9 +71,9 @@ class Utils {
/// \Returns the gap between the memory locations accessed by \p I0 and
/// \p I1 in bytes.
template <typename LoadOrStoreT>
- static std::optional<int>
- getPointerDiffInBytes(LoadOrStoreT *I0, LoadOrStoreT *I1, ScalarEvolution &SE,
- const DataLayout &DL) {
+ static std::optional<int> getPointerDiffInBytes(LoadOrStoreT *I0,
+ LoadOrStoreT *I1,
+ ScalarEvolution &SE) {
static_assert(std::is_same_v<LoadOrStoreT, LoadInst> ||
std::is_same_v<LoadOrStoreT, StoreInst>,
"Expected sandboxir::Load or sandboxir::Store!");
@@ -84,8 +84,8 @@ class Utils {
if (Ptr0 != Ptr1)
return false;
llvm::Type *ElemTy = llvm::Type::getInt8Ty(SE.getContext());
- return getPointersDiff(ElemTy, Opnd0, ElemTy, Opnd1, DL, SE,
- /*StrictCheck=*/false, /*CheckType=*/false);
+ return getPointersDiff(ElemTy, Opnd0, ElemTy, Opnd1, I0->getDataLayout(),
+ SE, /*StrictCheck=*/false, /*CheckType=*/false);
}
/// \Returns true if \p I0 accesses a memory location lower than \p I1.
@@ -93,8 +93,8 @@ class Utils {
/// locations are equal, or if I1 accesses a memory location greater than I0.
template <typename LoadOrStoreT>
static bool atLowerAddress(LoadOrStoreT *I0, LoadOrStoreT *I1,
- ScalarEvolution &SE, const DataLayout &DL) {
- auto Diff = getPointerDiffInBytes(I0, I1, SE, DL);
+ ScalarEvolution &SE) {
+ auto Diff = getPointerDiffInBytes(I0, I1, SE);
if (!Diff)
return false;
return *Diff > 0;
diff --git a/llvm/unittests/SandboxIR/UtilsTest.cpp b/llvm/unittests/SandboxIR/UtilsTest.cpp
index a803c2a1cf977c..90396eaa53ab38 100644
--- a/llvm/unittests/SandboxIR/UtilsTest.cpp
+++ b/llvm/unittests/SandboxIR/UtilsTest.cpp
@@ -119,21 +119,21 @@ define void @foo(ptr %ptr) {
[[maybe_unused]] auto *V3L3 = cast<sandboxir::LoadInst>(&*It++);
// getPointerDiffInBytes
- EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, L1, SE, DL), 4);
- EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, L2, SE, DL), 8);
- EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L1, L0, SE, DL), -4);
- EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, V2L0, SE, DL), 0);
+ EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, L1, SE), 4);
+ EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, L2, SE), 8);
+ EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L1, L0, SE), -4);
+ EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, V2L0, SE), 0);
- EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, V2L1, SE, DL), 4);
- EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, V3L1, SE, DL), 4);
- EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(V2L0, V2L2, SE, DL), 8);
- EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(V2L0, V2L3, SE, DL), 12);
- EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(V2L3, V2L0, SE, DL), -12);
+ EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, V2L1, SE), 4);
+ EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, V3L1, SE), 4);
+ EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(V2L0, V2L2, SE), 8);
+ EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(V2L0, V2L3, SE), 12);
+ EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(V2L3, V2L0, SE), -12);
// atLowerAddress
- EXPECT_TRUE(sandboxir::Utils::atLowerAddress(L0, L1, SE, DL));
- EXPECT_FALSE(sandboxir::Utils::atLowerAddress(L1, L0, SE, DL));
- EXPECT_FALSE(sandboxir::Utils::atLowerAddress(L3, V3L3, SE, DL));
+ EXPECT_TRUE(sandboxir::Utils::atLowerAddress(L0, L1, SE));
+ EXPECT_FALSE(sandboxir::Utils::atLowerAddress(L1, L0, SE));
+ EXPECT_FALSE(sandboxir::Utils::atLowerAddress(L3, V3L3, SE));
}
TEST_F(UtilsTest, GetExpected) {
More information about the llvm-commits
mailing list