-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[llvm][Attributor] Strip AddressSpaceCast from 'constructPointer' #74742
Conversation
* Remove pointer AddressSpaceCast in function `constructPointer` * Remove 1st parameter (`ResTy`) of function `constructPointer` 1st input argument to function `constructPointer` in all 4 call-sites is `ptr addrspace(0)`. Function `constructPointer` performs a pointer AddressSpaceCast to `ResTy`, making the returned pointer have type `ptr addrspace(0)` in all 4 call-sites. Unless there's a clear reason to discard the addrspace info of input parameter `Ptr`, I think we should keep and forward that info to the returned pointer of `constructPointer`. Opaque ptr cleanup effort.
@llvm/pr-subscribers-llvm-transforms Author: Youngsuk Kim (JOE1994) Changes
1st input argument to function Unless there's a clear reason to discard the addrspace info of input parameter Opaque ptr cleanup effort. Full diff: https://github.com/llvm/llvm-project/pull/74742.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 889ebd7438bd5..cbe0a96976c3f 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -290,20 +290,19 @@ static const Value *getPointerOperand(const Instruction *I,
return nullptr;
}
-/// Helper function to create a pointer of type \p ResTy, based on \p Ptr, and
-/// advanced by \p Offset bytes. To aid later analysis the method tries to build
+/// Helper function to create a pointer based on \p Ptr, and advanced by \p
+/// Offset bytes. To aid later analysis the method tries to build
/// getelement pointer instructions that traverse the natural type of \p Ptr if
/// possible. If that fails, the remaining offset is adjusted byte-wise, hence
/// through a cast to i8*.
///
/// TODO: This could probably live somewhere more prominantly if it doesn't
/// already exist.
-static Value *constructPointer(Type *ResTy, Type *PtrElemTy, Value *Ptr,
- int64_t Offset, IRBuilder<NoFolder> &IRB,
- const DataLayout &DL) {
+static Value *constructPointer(Type *PtrElemTy, Value *Ptr, int64_t Offset,
+ IRBuilder<NoFolder> &IRB, const DataLayout &DL) {
assert(Offset >= 0 && "Negative offset not supported yet!");
LLVM_DEBUG(dbgs() << "Construct pointer: " << *Ptr << " + " << Offset
- << "-bytes as " << *ResTy << "\n");
+ << "-bytes\n");
if (Offset) {
Type *Ty = PtrElemTy;
@@ -327,10 +326,6 @@ static Value *constructPointer(Type *ResTy, Type *PtrElemTy, Value *Ptr,
}
}
- // Ensure the result has the requested type.
- Ptr = IRB.CreatePointerBitCastOrAddrSpaceCast(Ptr, ResTy,
- Ptr->getName() + ".cast");
-
LLVM_DEBUG(dbgs() << "Constructed pointer: " << *Ptr << "\n");
return Ptr;
}
@@ -7492,19 +7487,16 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl {
if (auto *PrivStructType = dyn_cast<StructType>(PrivType)) {
const StructLayout *PrivStructLayout = DL.getStructLayout(PrivStructType);
for (unsigned u = 0, e = PrivStructType->getNumElements(); u < e; u++) {
- Type *PointeeTy = PrivStructType->getElementType(u)->getPointerTo();
- Value *Ptr =
- constructPointer(PointeeTy, PrivType, &Base,
- PrivStructLayout->getElementOffset(u), IRB, DL);
+ Value *Ptr = constructPointer(
+ PrivType, &Base, PrivStructLayout->getElementOffset(u), IRB, DL);
new StoreInst(F.getArg(ArgNo + u), Ptr, &IP);
}
} else if (auto *PrivArrayType = dyn_cast<ArrayType>(PrivType)) {
Type *PointeeTy = PrivArrayType->getElementType();
- Type *PointeePtrTy = PointeeTy->getPointerTo();
uint64_t PointeeTySize = DL.getTypeStoreSize(PointeeTy);
for (unsigned u = 0, e = PrivArrayType->getNumElements(); u < e; u++) {
- Value *Ptr = constructPointer(PointeePtrTy, PrivType, &Base,
- u * PointeeTySize, IRB, DL);
+ Value *Ptr =
+ constructPointer(PrivType, &Base, u * PointeeTySize, IRB, DL);
new StoreInst(F.getArg(ArgNo + u), Ptr, &IP);
}
} else {
@@ -7524,19 +7516,13 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl {
IRBuilder<NoFolder> IRB(IP);
const DataLayout &DL = IP->getModule()->getDataLayout();
- Type *PrivPtrType = PrivType->getPointerTo();
- if (Base->getType() != PrivPtrType)
- Base = BitCastInst::CreatePointerBitCastOrAddrSpaceCast(
- Base, PrivPtrType, "", ACS.getInstruction());
-
// Traverse the type, build GEPs and loads.
if (auto *PrivStructType = dyn_cast<StructType>(PrivType)) {
const StructLayout *PrivStructLayout = DL.getStructLayout(PrivStructType);
for (unsigned u = 0, e = PrivStructType->getNumElements(); u < e; u++) {
Type *PointeeTy = PrivStructType->getElementType(u);
- Value *Ptr =
- constructPointer(PointeeTy->getPointerTo(), PrivType, Base,
- PrivStructLayout->getElementOffset(u), IRB, DL);
+ Value *Ptr = constructPointer(
+ PrivType, Base, PrivStructLayout->getElementOffset(u), IRB, DL);
LoadInst *L = new LoadInst(PointeeTy, Ptr, "", IP);
L->setAlignment(Alignment);
ReplacementValues.push_back(L);
@@ -7544,10 +7530,9 @@ struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl {
} else if (auto *PrivArrayType = dyn_cast<ArrayType>(PrivType)) {
Type *PointeeTy = PrivArrayType->getElementType();
uint64_t PointeeTySize = DL.getTypeStoreSize(PointeeTy);
- Type *PointeePtrTy = PointeeTy->getPointerTo();
for (unsigned u = 0, e = PrivArrayType->getNumElements(); u < e; u++) {
- Value *Ptr = constructPointer(PointeePtrTy, PrivType, Base,
- u * PointeeTySize, IRB, DL);
+ Value *Ptr =
+ constructPointer(PrivType, Base, u * PointeeTySize, IRB, DL);
LoadInst *L = new LoadInst(PointeeTy, Ptr, "", IP);
L->setAlignment(Alignment);
ReplacementValues.push_back(L);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
constructPointer
ResTy
) of functionconstructPointer
1st input argument to function
constructPointer
in all 4 call-sites isptr addrspace(0)
. FunctionconstructPointer
performs a pointer AddressSpaceCast toResTy
, making the returned pointer have typeptr addrspace(0)
in all 4 call-sites.Unless there's a clear reason to discard the addrspace info of input parameter
Ptr
, I think we should keep and forward that info to the returned pointer ofconstructPointer
.Opaque ptr cleanup effort.