1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[OpaquePtr] Clean up some uses of Type::getPointerElementType()

These depend on pointee types.
This commit is contained in:
Arthur Eubanks 2021-05-26 20:32:04 -07:00
parent 8967f0ab59
commit cfc7e26853
5 changed files with 16 additions and 19 deletions

View File

@ -425,8 +425,7 @@ void SafeStack::findInsts(Function &F,
for (Argument &Arg : F.args()) { for (Argument &Arg : F.args()) {
if (!Arg.hasByValAttr()) if (!Arg.hasByValAttr())
continue; continue;
uint64_t Size = uint64_t Size = DL.getTypeStoreSize(Arg.getParamByValType());
DL.getTypeStoreSize(Arg.getType()->getPointerElementType());
if (IsSafeStackAlloca(&Arg, Size)) if (IsSafeStackAlloca(&Arg, Size))
continue; continue;
@ -527,7 +526,7 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
} }
for (Argument *Arg : ByValArguments) { for (Argument *Arg : ByValArguments) {
Type *Ty = Arg->getType()->getPointerElementType(); Type *Ty = Arg->getParamByValType();
uint64_t Size = DL.getTypeStoreSize(Ty); uint64_t Size = DL.getTypeStoreSize(Ty);
if (Size == 0) if (Size == 0)
Size = 1; // Don't create zero-sized stack objects. Size = 1; // Don't create zero-sized stack objects.
@ -584,7 +583,7 @@ Value *SafeStack::moveStaticAllocasToUnsafeStack(
for (Argument *Arg : ByValArguments) { for (Argument *Arg : ByValArguments) {
unsigned Offset = SSL.getObjectOffset(Arg); unsigned Offset = SSL.getObjectOffset(Arg);
MaybeAlign Align(SSL.getObjectAlignment(Arg)); MaybeAlign Align(SSL.getObjectAlignment(Arg));
Type *Ty = Arg->getType()->getPointerElementType(); Type *Ty = Arg->getParamByValType();
uint64_t Size = DL.getTypeStoreSize(Ty); uint64_t Size = DL.getTypeStoreSize(Ty);
if (Size == 0) if (Size == 0)

View File

@ -880,7 +880,7 @@ Constant *llvm::ConstantFoldExtractElementInstruction(Constant *Val,
// ee (gep (ptr, idx0, ...), idx) -> gep (ee (ptr, idx), ee (idx0, idx), ...) // ee (gep (ptr, idx0, ...), idx) -> gep (ee (ptr, idx), ee (idx0, idx), ...)
if (auto *CE = dyn_cast<ConstantExpr>(Val)) { if (auto *CE = dyn_cast<ConstantExpr>(Val)) {
if (CE->getOpcode() == Instruction::GetElementPtr) { if (auto *GEP = dyn_cast<GEPOperator>(CE)) {
SmallVector<Constant *, 8> Ops; SmallVector<Constant *, 8> Ops;
Ops.reserve(CE->getNumOperands()); Ops.reserve(CE->getNumOperands());
for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) {
@ -894,7 +894,7 @@ Constant *llvm::ConstantFoldExtractElementInstruction(Constant *Val,
Ops.push_back(Op); Ops.push_back(Op);
} }
return CE->getWithOperands(Ops, ValVTy->getElementType(), false, return CE->getWithOperands(Ops, ValVTy->getElementType(), false,
Ops[0]->getType()->getPointerElementType()); GEP->getSourceElementType());
} else if (CE->getOpcode() == Instruction::InsertElement) { } else if (CE->getOpcode() == Instruction::InsertElement) {
if (const auto *IEIdx = dyn_cast<ConstantInt>(CE->getOperand(2))) { if (const auto *IEIdx = dyn_cast<ConstantInt>(CE->getOperand(2))) {
if (APSInt::isSameValue(APSInt(IEIdx->getValue()), if (APSInt::isSameValue(APSInt(IEIdx->getValue()),

View File

@ -114,9 +114,9 @@ void AMDGPUAnnotateUniformValues::visitLoadInst(LoadInst &I) {
Value *Idx = Constant::getIntegerValue( Value *Idx = Constant::getIntegerValue(
Type::getInt32Ty(Ptr->getContext()), APInt(64, 0)); Type::getInt32Ty(Ptr->getContext()), APInt(64, 0));
// Insert GEP at the entry to make it dominate all uses // Insert GEP at the entry to make it dominate all uses
PtrI = GetElementPtrInst::Create( PtrI = GetElementPtrInst::Create(I.getType(), Ptr,
Ptr->getType()->getPointerElementType(), Ptr, ArrayRef<Value *>(Idx), Twine(""),
ArrayRef<Value*>(Idx), Twine(""), F->getEntryBlock().getFirstNonPHI()); F->getEntryBlock().getFirstNonPHI());
} }
I.replaceUsesOfWith(Ptr, PtrI); I.replaceUsesOfWith(Ptr, PtrI);
} }

View File

@ -488,9 +488,9 @@ Value *MVEGatherScatterLowering::tryCreateMaskedGatherOffset(
if (Load) if (Load)
return Load; return Load;
int Scale = computeScale( int Scale =
BasePtr->getType()->getPointerElementType()->getPrimitiveSizeInBits(), computeScale(GEP->getSourceElementType()->getPrimitiveSizeInBits(),
OriginalTy->getScalarSizeInBits()); OriginalTy->getScalarSizeInBits());
if (Scale == -1) if (Scale == -1)
return nullptr; return nullptr;
Root = Extend; Root = Extend;
@ -630,9 +630,9 @@ Value *MVEGatherScatterLowering::tryCreateMaskedScatterOffset(
tryCreateIncrementingGatScat(I, BasePtr, Offsets, GEP, Builder); tryCreateIncrementingGatScat(I, BasePtr, Offsets, GEP, Builder);
if (Store) if (Store)
return Store; return Store;
int Scale = computeScale( int Scale =
BasePtr->getType()->getPointerElementType()->getPrimitiveSizeInBits(), computeScale(GEP->getSourceElementType()->getPrimitiveSizeInBits(),
MemoryTy->getScalarSizeInBits()); MemoryTy->getScalarSizeInBits());
if (Scale == -1) if (Scale == -1)
return nullptr; return nullptr;
@ -1143,9 +1143,8 @@ bool MVEGatherScatterLowering::optimiseAddress(Value *Address, BasicBlock *BB,
// (always i32 if it is not of vector type) and the base has to be a // (always i32 if it is not of vector type) and the base has to be a
// pointer. // pointer.
if (Offsets && Base && Base != GEP) { if (Offsets && Base && Base != GEP) {
PointerType *BaseType = cast<PointerType>(Base->getType());
GetElementPtrInst *NewAddress = GetElementPtrInst::Create( GetElementPtrInst *NewAddress = GetElementPtrInst::Create(
BaseType->getPointerElementType(), Base, Offsets, "gep.merged", GEP); GEP->getSourceElementType(), Base, Offsets, "gep.merged", GEP);
GEP->replaceAllUsesWith(NewAddress); GEP->replaceAllUsesWith(NewAddress);
GEP = NewAddress; GEP = NewAddress;
Changed = true; Changed = true;

View File

@ -1321,8 +1321,7 @@ auto HexagonVectorCombine::calculatePointerDifference(Value *Ptr0,
return None; return None;
Builder B(Gep0->getParent()); Builder B(Gep0->getParent());
Value *BasePtr = Gep0->getPointerOperand(); int Scale = DL.getTypeStoreSize(Gep0->getSourceElementType());
int Scale = DL.getTypeStoreSize(BasePtr->getType()->getPointerElementType());
// FIXME: for now only check GEPs with a single index. // FIXME: for now only check GEPs with a single index.
if (Gep0->getNumOperands() != 2 || Gep1->getNumOperands() != 2) if (Gep0->getNumOperands() != 2 || Gep1->getNumOperands() != 2)