Skip to content

[SandboxIR][NFC] Use accessor for DataLayout rather than passing it down #111447

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
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions llvm/include/llvm/SandboxIR/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand All @@ -84,17 +84,17 @@ 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.
/// Returns false if the difference cannot be determined, if the memory
/// 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;
Expand Down
24 changes: 12 additions & 12 deletions llvm/unittests/SandboxIR/UtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading