mirror of
https://github.com/RPCS3/llvm.git
synced 2025-05-13 08:56:04 +00:00
[SROA] Simplify the computing of alignment: we only ever need the
alignment of the slice being rewritten, not any arbitrary offset. Every caller is really just trying to compute the alignment for the whole slice, never for some arbitrary alignment. They are also just passing a type when they have one to see if we can skip an explicit alignment in the IR by using the type's alignment. This makes for a much simpler interface. Another refactoring inspired by the addrspace patch for SROA, although only loosely related. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202230 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f28c057c42
commit
c9166f098c
@ -2136,22 +2136,16 @@ private:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Compute suitable alignment to access an offset into the new alloca.
|
/// \brief Compute suitable alignment to access this slice of the *new* alloca.
|
||||||
unsigned getOffsetAlign(uint64_t Offset) {
|
///
|
||||||
|
/// You can optionally pass a type to this routine and if that type's ABI
|
||||||
|
/// alignment is itself suitable, this will return zero.
|
||||||
|
unsigned getSliceAlign(Type *Ty = 0) {
|
||||||
unsigned NewAIAlign = NewAI.getAlignment();
|
unsigned NewAIAlign = NewAI.getAlignment();
|
||||||
if (!NewAIAlign)
|
if (!NewAIAlign)
|
||||||
NewAIAlign = DL.getABITypeAlignment(NewAI.getAllocatedType());
|
NewAIAlign = DL.getABITypeAlignment(NewAI.getAllocatedType());
|
||||||
return MinAlign(NewAIAlign, Offset);
|
unsigned Align = MinAlign(NewAIAlign, NewBeginOffset - NewAllocaBeginOffset);
|
||||||
}
|
return (Ty && Align == DL.getABITypeAlignment(Ty)) ? 0 : Align;
|
||||||
|
|
||||||
/// \brief Compute suitable alignment to access a type at an offset of the
|
|
||||||
/// new alloca.
|
|
||||||
///
|
|
||||||
/// \returns zero if the type's ABI alignment is a suitable alignment,
|
|
||||||
/// otherwise returns the maximal suitable alignment.
|
|
||||||
unsigned getOffsetTypeAlign(Type *Ty, uint64_t Offset) {
|
|
||||||
unsigned Align = getOffsetAlign(Offset);
|
|
||||||
return Align == DL.getABITypeAlignment(Ty) ? 0 : Align;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned getIndex(uint64_t Offset) {
|
unsigned getIndex(uint64_t Offset) {
|
||||||
@ -2212,10 +2206,9 @@ private:
|
|||||||
LI.isVolatile(), LI.getName());
|
LI.isVolatile(), LI.getName());
|
||||||
} else {
|
} else {
|
||||||
Type *LTy = TargetTy->getPointerTo();
|
Type *LTy = TargetTy->getPointerTo();
|
||||||
V = IRB.CreateAlignedLoad(
|
V = IRB.CreateAlignedLoad(getAdjustedAllocaPtr(IRB, NewBeginOffset, LTy),
|
||||||
getAdjustedAllocaPtr(IRB, NewBeginOffset, LTy),
|
getSliceAlign(TargetTy), LI.isVolatile(),
|
||||||
getOffsetTypeAlign(TargetTy, NewBeginOffset - NewAllocaBeginOffset),
|
LI.getName());
|
||||||
LI.isVolatile(), LI.getName());
|
|
||||||
IsPtrAdjusted = true;
|
IsPtrAdjusted = true;
|
||||||
}
|
}
|
||||||
V = convertValue(DL, IRB, V, TargetTy);
|
V = convertValue(DL, IRB, V, TargetTy);
|
||||||
@ -2338,10 +2331,8 @@ private:
|
|||||||
} else {
|
} else {
|
||||||
Value *NewPtr = getAdjustedAllocaPtr(IRB, NewBeginOffset,
|
Value *NewPtr = getAdjustedAllocaPtr(IRB, NewBeginOffset,
|
||||||
V->getType()->getPointerTo());
|
V->getType()->getPointerTo());
|
||||||
NewSI = IRB.CreateAlignedStore(
|
NewSI = IRB.CreateAlignedStore(V, NewPtr, getSliceAlign(V->getType()),
|
||||||
V, NewPtr, getOffsetTypeAlign(V->getType(),
|
SI.isVolatile());
|
||||||
NewBeginOffset - NewAllocaBeginOffset),
|
|
||||||
SI.isVolatile());
|
|
||||||
}
|
}
|
||||||
(void)NewSI;
|
(void)NewSI;
|
||||||
Pass.DeadInsts.insert(&SI);
|
Pass.DeadInsts.insert(&SI);
|
||||||
@ -2396,8 +2387,7 @@ private:
|
|||||||
assert(NewBeginOffset == BeginOffset);
|
assert(NewBeginOffset == BeginOffset);
|
||||||
II.setDest(getAdjustedAllocaPtr(IRB, NewBeginOffset, OldPtr->getType()));
|
II.setDest(getAdjustedAllocaPtr(IRB, NewBeginOffset, OldPtr->getType()));
|
||||||
Type *CstTy = II.getAlignmentCst()->getType();
|
Type *CstTy = II.getAlignmentCst()->getType();
|
||||||
II.setAlignment(ConstantInt::get(
|
II.setAlignment(ConstantInt::get(CstTy, getSliceAlign()));
|
||||||
CstTy, getOffsetAlign(NewBeginOffset - NewAllocaBeginOffset)));
|
|
||||||
|
|
||||||
deleteIfTriviallyDead(OldPtr);
|
deleteIfTriviallyDead(OldPtr);
|
||||||
return false;
|
return false;
|
||||||
@ -2409,8 +2399,6 @@ private:
|
|||||||
Type *AllocaTy = NewAI.getAllocatedType();
|
Type *AllocaTy = NewAI.getAllocatedType();
|
||||||
Type *ScalarTy = AllocaTy->getScalarType();
|
Type *ScalarTy = AllocaTy->getScalarType();
|
||||||
|
|
||||||
uint64_t SliceOffset = NewBeginOffset - NewAllocaBeginOffset;
|
|
||||||
|
|
||||||
// If this doesn't map cleanly onto the alloca type, and that type isn't
|
// If this doesn't map cleanly onto the alloca type, and that type isn't
|
||||||
// a single value type, just emit a memset.
|
// a single value type, just emit a memset.
|
||||||
if (!VecTy && !IntTy &&
|
if (!VecTy && !IntTy &&
|
||||||
@ -2423,7 +2411,7 @@ private:
|
|||||||
Constant *Size = ConstantInt::get(SizeTy, NewEndOffset - NewBeginOffset);
|
Constant *Size = ConstantInt::get(SizeTy, NewEndOffset - NewBeginOffset);
|
||||||
CallInst *New = IRB.CreateMemSet(
|
CallInst *New = IRB.CreateMemSet(
|
||||||
getAdjustedAllocaPtr(IRB, NewBeginOffset, OldPtr->getType()),
|
getAdjustedAllocaPtr(IRB, NewBeginOffset, OldPtr->getType()),
|
||||||
II.getValue(), Size, getOffsetAlign(SliceOffset), II.isVolatile());
|
II.getValue(), Size, getSliceAlign(), II.isVolatile());
|
||||||
(void)New;
|
(void)New;
|
||||||
DEBUG(dbgs() << " to: " << *New << "\n");
|
DEBUG(dbgs() << " to: " << *New << "\n");
|
||||||
return false;
|
return false;
|
||||||
@ -2509,11 +2497,9 @@ private:
|
|||||||
APInt RelOffset(IntPtrWidth, NewBeginOffset - BeginOffset);
|
APInt RelOffset(IntPtrWidth, NewBeginOffset - BeginOffset);
|
||||||
|
|
||||||
unsigned Align = II.getAlignment();
|
unsigned Align = II.getAlignment();
|
||||||
uint64_t SliceOffset = NewBeginOffset - NewAllocaBeginOffset;
|
|
||||||
if (Align > 1)
|
if (Align > 1)
|
||||||
Align =
|
Align = MinAlign(RelOffset.zextOrTrunc(64).getZExtValue(),
|
||||||
MinAlign(RelOffset.zextOrTrunc(64).getZExtValue(),
|
MinAlign(II.getAlignment(), getSliceAlign()));
|
||||||
MinAlign(II.getAlignment(), getOffsetAlign(SliceOffset)));
|
|
||||||
|
|
||||||
// For unsplit intrinsics, we simply modify the source and destination
|
// For unsplit intrinsics, we simply modify the source and destination
|
||||||
// pointers in place. This isn't just an optimization, it is a matter of
|
// pointers in place. This isn't just an optimization, it is a matter of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user