[llvm] 8e22539 - [IR] Make some pointer element type accesses explicit (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 7 13:05:42 PDT 2021


Author: Nikita Popov
Date: 2021-07-07T22:05:30+02:00
New Revision: 8e22539067d9376c4f808b25f543feba728d40c9

URL: https://github.com/llvm/llvm-project/commit/8e22539067d9376c4f808b25f543feba728d40c9
DIFF: https://github.com/llvm/llvm-project/commit/8e22539067d9376c4f808b25f543feba728d40c9.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/include/llvm/IR/IRBuilder.h
    llvm/include/llvm/IR/Instructions.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 9bd5ae1908cf5..c76ebb06d44ad 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -1786,7 +1786,8 @@ class IRBuilderBase {
 
   Value *CreateGEP(Value *Ptr, ArrayRef<Value *> IdxList,
                    const Twine &Name = "") {
-    return CreateGEP(nullptr, Ptr, IdxList, Name);
+    return CreateGEP(
+        Ptr->getType()->getPointerElementType(), Ptr, IdxList, Name);
   }
 
   Value *CreateGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
@@ -1805,7 +1806,8 @@ class IRBuilderBase {
 
   Value *CreateInBoundsGEP(Value *Ptr, ArrayRef<Value *> IdxList,
                            const Twine &Name = "") {
-    return CreateInBoundsGEP(nullptr, Ptr, IdxList, Name);
+    return CreateInBoundsGEP(
+        Ptr->getType()->getPointerElementType(), Ptr, IdxList, Name);
   }
 
   Value *CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
@@ -1824,7 +1826,7 @@ class IRBuilderBase {
   }
 
   Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
-    return CreateGEP(nullptr, Ptr, Idx, Name);
+    return CreateGEP(Ptr->getType()->getPointerElementType(), Ptr, Idx, Name);
   }
 
   Value *CreateGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name = "") {
@@ -1843,7 +1845,8 @@ class IRBuilderBase {
   }
 
   Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") {
-    return CreateConstGEP1_32(nullptr, Ptr, Idx0, Name);
+    return CreateConstGEP1_32(
+        Ptr->getType()->getPointerElementType(), Ptr, Idx0, Name);
   }
 
   Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
@@ -1903,7 +1906,8 @@ class IRBuilderBase {
   }
 
   Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
-    return CreateConstGEP1_64(nullptr, Ptr, Idx0, Name);
+    return CreateConstGEP1_64(
+        Ptr->getType()->getPointerElementType(), Ptr, Idx0, Name);
   }
 
   Value *CreateConstInBoundsGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0,
@@ -1918,7 +1922,8 @@ class IRBuilderBase {
 
   Value *CreateConstInBoundsGEP1_64(Value *Ptr, uint64_t Idx0,
                                     const Twine &Name = "") {
-    return CreateConstInBoundsGEP1_64(nullptr, Ptr, Idx0, Name);
+    return CreateConstInBoundsGEP1_64(
+        Ptr->getType()->getPointerElementType(), Ptr, Idx0, Name);
   }
 
   Value *CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1,
@@ -1936,7 +1941,8 @@ class IRBuilderBase {
 
   Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
                             const Twine &Name = "") {
-    return CreateConstGEP2_64(nullptr, Ptr, Idx0, Idx1, Name);
+    return CreateConstGEP2_64(
+        Ptr->getType()->getPointerElementType(), Ptr, Idx0, Idx1, Name);
   }
 
   Value *CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0,
@@ -1954,7 +1960,8 @@ class IRBuilderBase {
 
   Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
                                     const Twine &Name = "") {
-    return CreateConstInBoundsGEP2_64(nullptr, Ptr, Idx0, Idx1, Name);
+    return CreateConstInBoundsGEP2_64(
+        Ptr->getType()->getPointerElementType(), Ptr, Idx0, Idx1, Name);
   }
 
   Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
@@ -1963,7 +1970,8 @@ class IRBuilderBase {
   }
 
   Value *CreateStructGEP(Value *Ptr, unsigned Idx, const Twine &Name = "") {
-    return CreateConstInBoundsGEP2_32(nullptr, Ptr, 0, Idx, Name);
+    return CreateConstInBoundsGEP2_32(
+        Ptr->getType()->getPointerElementType(), Ptr, 0, Idx, Name);
   }
 
   /// Same as CreateGlobalString, but return a pointer with "i8*" type

diff  --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index 9d9471f111537..5de72de77f839 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -991,7 +991,8 @@ class GetElementPtrInst : public Instruction {
         Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr = "",
         Instruction *InsertBefore = nullptr),
       "Use the version with explicit element type instead") {
-    return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore);
+    return CreateInBounds(Ptr->getType()->getPointerElementType(), Ptr, IdxList,
+                          NameStr, InsertBefore);
   }
 
   /// Create an "inbounds" getelementptr. See the documentation for the
@@ -1010,7 +1011,8 @@ class GetElementPtrInst : public Instruction {
         Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr,
         BasicBlock *InsertAtEnd),
       "Use the version with explicit element type instead") {
-    return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd);
+    return CreateInBounds(Ptr->getType()->getPointerElementType(), Ptr, IdxList,
+                          NameStr, InsertAtEnd);
   }
 
   static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr,


        


More information about the llvm-commits mailing list