Skip to content

Commit 376b5c0

Browse files
[SandboxIR][NFC] Use accessor for DataLayout rather than passing it down (#111447)
1 parent 2918e77 commit 376b5c0

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

llvm/include/llvm/SandboxIR/Utils.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ class Utils {
7171
/// \Returns the gap between the memory locations accessed by \p I0 and
7272
/// \p I1 in bytes.
7373
template <typename LoadOrStoreT>
74-
static std::optional<int>
75-
getPointerDiffInBytes(LoadOrStoreT *I0, LoadOrStoreT *I1, ScalarEvolution &SE,
76-
const DataLayout &DL) {
74+
static std::optional<int> getPointerDiffInBytes(LoadOrStoreT *I0,
75+
LoadOrStoreT *I1,
76+
ScalarEvolution &SE) {
7777
static_assert(std::is_same_v<LoadOrStoreT, LoadInst> ||
7878
std::is_same_v<LoadOrStoreT, StoreInst>,
7979
"Expected sandboxir::Load or sandboxir::Store!");
@@ -84,17 +84,17 @@ class Utils {
8484
if (Ptr0 != Ptr1)
8585
return false;
8686
llvm::Type *ElemTy = llvm::Type::getInt8Ty(SE.getContext());
87-
return getPointersDiff(ElemTy, Opnd0, ElemTy, Opnd1, DL, SE,
88-
/*StrictCheck=*/false, /*CheckType=*/false);
87+
return getPointersDiff(ElemTy, Opnd0, ElemTy, Opnd1, I0->getDataLayout(),
88+
SE, /*StrictCheck=*/false, /*CheckType=*/false);
8989
}
9090

9191
/// \Returns true if \p I0 accesses a memory location lower than \p I1.
9292
/// Returns false if the difference cannot be determined, if the memory
9393
/// locations are equal, or if I1 accesses a memory location greater than I0.
9494
template <typename LoadOrStoreT>
9595
static bool atLowerAddress(LoadOrStoreT *I0, LoadOrStoreT *I1,
96-
ScalarEvolution &SE, const DataLayout &DL) {
97-
auto Diff = getPointerDiffInBytes(I0, I1, SE, DL);
96+
ScalarEvolution &SE) {
97+
auto Diff = getPointerDiffInBytes(I0, I1, SE);
9898
if (!Diff)
9999
return false;
100100
return *Diff > 0;

llvm/unittests/SandboxIR/UtilsTest.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,21 @@ define void @foo(ptr %ptr) {
119119
[[maybe_unused]] auto *V3L3 = cast<sandboxir::LoadInst>(&*It++);
120120

121121
// getPointerDiffInBytes
122-
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, L1, SE, DL), 4);
123-
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, L2, SE, DL), 8);
124-
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L1, L0, SE, DL), -4);
125-
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, V2L0, SE, DL), 0);
122+
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, L1, SE), 4);
123+
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, L2, SE), 8);
124+
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L1, L0, SE), -4);
125+
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, V2L0, SE), 0);
126126

127-
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, V2L1, SE, DL), 4);
128-
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, V3L1, SE, DL), 4);
129-
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(V2L0, V2L2, SE, DL), 8);
130-
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(V2L0, V2L3, SE, DL), 12);
131-
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(V2L3, V2L0, SE, DL), -12);
127+
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, V2L1, SE), 4);
128+
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(L0, V3L1, SE), 4);
129+
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(V2L0, V2L2, SE), 8);
130+
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(V2L0, V2L3, SE), 12);
131+
EXPECT_EQ(*sandboxir::Utils::getPointerDiffInBytes(V2L3, V2L0, SE), -12);
132132

133133
// atLowerAddress
134-
EXPECT_TRUE(sandboxir::Utils::atLowerAddress(L0, L1, SE, DL));
135-
EXPECT_FALSE(sandboxir::Utils::atLowerAddress(L1, L0, SE, DL));
136-
EXPECT_FALSE(sandboxir::Utils::atLowerAddress(L3, V3L3, SE, DL));
134+
EXPECT_TRUE(sandboxir::Utils::atLowerAddress(L0, L1, SE));
135+
EXPECT_FALSE(sandboxir::Utils::atLowerAddress(L1, L0, SE));
136+
EXPECT_FALSE(sandboxir::Utils::atLowerAddress(L3, V3L3, SE));
137137
}
138138

139139
TEST_F(UtilsTest, GetExpected) {

0 commit comments

Comments
 (0)