Skip to content

Commit 8e22539

Browse files
committed
[IR] Make some pointer element type accesses explicit (NFC)
Explicitly fetch the pointer element type in various deprecated methods, so we can hopefully remove support from this from the base GEP constructor.
1 parent 458c230 commit 8e22539

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,8 @@ class IRBuilderBase {
17861786

17871787
Value *CreateGEP(Value *Ptr, ArrayRef<Value *> IdxList,
17881788
const Twine &Name = "") {
1789-
return CreateGEP(nullptr, Ptr, IdxList, Name);
1789+
return CreateGEP(
1790+
Ptr->getType()->getPointerElementType(), Ptr, IdxList, Name);
17901791
}
17911792

17921793
Value *CreateGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
@@ -1805,7 +1806,8 @@ class IRBuilderBase {
18051806

18061807
Value *CreateInBoundsGEP(Value *Ptr, ArrayRef<Value *> IdxList,
18071808
const Twine &Name = "") {
1808-
return CreateInBoundsGEP(nullptr, Ptr, IdxList, Name);
1809+
return CreateInBoundsGEP(
1810+
Ptr->getType()->getPointerElementType(), Ptr, IdxList, Name);
18091811
}
18101812

18111813
Value *CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
@@ -1824,7 +1826,7 @@ class IRBuilderBase {
18241826
}
18251827

18261828
Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
1827-
return CreateGEP(nullptr, Ptr, Idx, Name);
1829+
return CreateGEP(Ptr->getType()->getPointerElementType(), Ptr, Idx, Name);
18281830
}
18291831

18301832
Value *CreateGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name = "") {
@@ -1843,7 +1845,8 @@ class IRBuilderBase {
18431845
}
18441846

18451847
Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") {
1846-
return CreateConstGEP1_32(nullptr, Ptr, Idx0, Name);
1848+
return CreateConstGEP1_32(
1849+
Ptr->getType()->getPointerElementType(), Ptr, Idx0, Name);
18471850
}
18481851

18491852
Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
@@ -1903,7 +1906,8 @@ class IRBuilderBase {
19031906
}
19041907

19051908
Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
1906-
return CreateConstGEP1_64(nullptr, Ptr, Idx0, Name);
1909+
return CreateConstGEP1_64(
1910+
Ptr->getType()->getPointerElementType(), Ptr, Idx0, Name);
19071911
}
19081912

19091913
Value *CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0,
@@ -1918,7 +1922,8 @@ class IRBuilderBase {
19181922

19191923
Value *CreateConstInBoundsGEP1_64(Value *Ptr, uint64_t Idx0,
19201924
const Twine &Name = "") {
1921-
return CreateConstInBoundsGEP1_64(nullptr, Ptr, Idx0, Name);
1925+
return CreateConstInBoundsGEP1_64(
1926+
Ptr->getType()->getPointerElementType(), Ptr, Idx0, Name);
19221927
}
19231928

19241929
Value *CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1,
@@ -1936,7 +1941,8 @@ class IRBuilderBase {
19361941

19371942
Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
19381943
const Twine &Name = "") {
1939-
return CreateConstGEP2_64(nullptr, Ptr, Idx0, Idx1, Name);
1944+
return CreateConstGEP2_64(
1945+
Ptr->getType()->getPointerElementType(), Ptr, Idx0, Idx1, Name);
19401946
}
19411947

19421948
Value *CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0,
@@ -1954,7 +1960,8 @@ class IRBuilderBase {
19541960

19551961
Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
19561962
const Twine &Name = "") {
1957-
return CreateConstInBoundsGEP2_64(nullptr, Ptr, Idx0, Idx1, Name);
1963+
return CreateConstInBoundsGEP2_64(
1964+
Ptr->getType()->getPointerElementType(), Ptr, Idx0, Idx1, Name);
19581965
}
19591966

19601967
Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
@@ -1963,7 +1970,8 @@ class IRBuilderBase {
19631970
}
19641971

19651972
Value *CreateStructGEP(Value *Ptr, unsigned Idx, const Twine &Name = "") {
1966-
return CreateConstInBoundsGEP2_32(nullptr, Ptr, 0, Idx, Name);
1973+
return CreateConstInBoundsGEP2_32(
1974+
Ptr->getType()->getPointerElementType(), Ptr, 0, Idx, Name);
19671975
}
19681976

19691977
/// Same as CreateGlobalString, but return a pointer with "i8*" type

llvm/include/llvm/IR/Instructions.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,8 @@ class GetElementPtrInst : public Instruction {
991991
Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr = "",
992992
Instruction *InsertBefore = nullptr),
993993
"Use the version with explicit element type instead") {
994-
return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore);
994+
return CreateInBounds(Ptr->getType()->getPointerElementType(), Ptr, IdxList,
995+
NameStr, InsertBefore);
995996
}
996997

997998
/// Create an "inbounds" getelementptr. See the documentation for the
@@ -1010,7 +1011,8 @@ class GetElementPtrInst : public Instruction {
10101011
Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr,
10111012
BasicBlock *InsertAtEnd),
10121013
"Use the version with explicit element type instead") {
1013-
return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd);
1014+
return CreateInBounds(Ptr->getType()->getPointerElementType(), Ptr, IdxList,
1015+
NameStr, InsertAtEnd);
10141016
}
10151017

10161018
static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr,

0 commit comments

Comments
 (0)