Index: clang/lib/CodeGen/CGCall.cpp =================================================================== --- clang/lib/CodeGen/CGCall.cpp +++ clang/lib/CodeGen/CGCall.cpp @@ -3880,7 +3880,7 @@ } // Create the temporary. - Address temp = CGF.CreateTempAlloca(destType->getElementType(), + Address temp = CGF.CreateTempAlloca(destType->getPointerElementType(), CGF.getPointerAlign(), "icr.temp"); // Loading an l-value can introduce a cleanup if the l-value is __weak, @@ -3894,7 +3894,7 @@ if (!shouldCopy) { llvm::Value *null = llvm::ConstantPointerNull::get( - cast(destType->getElementType())); + cast(destType->getPointerElementType())); CGF.Builder.CreateStore(null, temp); } @@ -3936,7 +3936,7 @@ assert(srcRV.isScalar()); llvm::Value *src = srcRV.getScalarVal(); - src = CGF.Builder.CreateBitCast(src, destType->getElementType(), + src = CGF.Builder.CreateBitCast(src, destType->getPointerElementType(), "icr.cast"); // Use an ordinary store, not a store-to-lvalue. @@ -5076,7 +5076,7 @@ // Assert that these structs have equivalent element types. llvm::StructType *FullTy = CallInfo.getArgStruct(); llvm::StructType *DeclaredTy = cast( - cast(LastParamTy)->getElementType()); + LastParamTy->getPointerElementType()); assert(DeclaredTy->getNumElements() == FullTy->getNumElements()); for (llvm::StructType::element_iterator DI = DeclaredTy->element_begin(), DE = DeclaredTy->element_end(), Index: clang/lib/CodeGen/CGClass.cpp =================================================================== --- clang/lib/CodeGen/CGClass.cpp +++ clang/lib/CodeGen/CGClass.cpp @@ -2854,7 +2854,7 @@ return Builder.CreateBitCast( Builder.CreateExtractValue(CheckedLoad, 0), - cast(VTable->getType())->getElementType()); + VTable->getType()->getPointerElementType()); } void CodeGenFunction::EmitForwardingCallToLambda( Index: clang/lib/CodeGen/CGObjCGNU.cpp =================================================================== --- clang/lib/CodeGen/CGObjCGNU.cpp +++ clang/lib/CodeGen/CGObjCGNU.cpp @@ -2348,7 +2348,8 @@ } if (!SelValue) { SelValue = llvm::GlobalAlias::create( - SelectorTy->getElementType(), 0, llvm::GlobalValue::PrivateLinkage, + SelectorTy->getPointerElementType(), 0, + llvm::GlobalValue::PrivateLinkage, ".objc_selector_" + Sel.getAsString(), &TheModule); Types.emplace_back(TypeEncoding, SelValue); } @@ -2576,14 +2577,16 @@ if (IsClassMessage) { if (!MetaClassPtrAlias) { MetaClassPtrAlias = llvm::GlobalAlias::create( - IdTy->getElementType(), 0, llvm::GlobalValue::InternalLinkage, + IdTy->getPointerElementType(), 0, + llvm::GlobalValue::InternalLinkage, ".objc_metaclass_ref" + Class->getNameAsString(), &TheModule); } ReceiverClass = MetaClassPtrAlias; } else { if (!ClassPtrAlias) { ClassPtrAlias = llvm::GlobalAlias::create( - IdTy->getElementType(), 0, llvm::GlobalValue::InternalLinkage, + IdTy->getPointerElementType(), 0, + llvm::GlobalValue::InternalLinkage, ".objc_class_ref" + Class->getNameAsString(), &TheModule); } ReceiverClass = ClassPtrAlias; @@ -3706,7 +3709,7 @@ GenerateProtocolHolderCategory(); llvm::StructType *selStructTy = - dyn_cast(SelectorTy->getElementType()); + dyn_cast(SelectorTy->getPointerElementType()); llvm::Type *selStructPtrTy = SelectorTy; if (!selStructTy) { selStructTy = llvm::StructType::get(CGM.getLLVMContext(), Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -837,9 +837,8 @@ } llvm::Value *Size; llvm::Value *SizeInChars; - auto *ElemType = - cast(OrigAddresses[N].first.getPointer(CGF)->getType()) - ->getElementType(); + auto *ElemType = OrigAddresses[N].first.getPointer(CGF)->getType() + ->getPointerElementType(); auto *ElemSizeOf = llvm::ConstantExpr::getSizeOf(ElemType); if (AsArraySection) { Size = CGF.Builder.CreatePtrDiff(OrigAddresses[N].second.getPointer(CGF), Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -4472,8 +4472,7 @@ // pad. The best solution is to fix the personality function. } else { // Pull the pointer for the reference type off. - llvm::Type *PtrTy = - cast(LLVMCatchTy)->getElementType(); + llvm::Type *PtrTy = LLVMCatchTy->getPointerElementType(); // Create the temporary and write the adjusted pointer into it. Address ExnPtrTmp = Index: clang/lib/CodeGen/TargetInfo.cpp =================================================================== --- clang/lib/CodeGen/TargetInfo.cpp +++ clang/lib/CodeGen/TargetInfo.cpp @@ -8937,8 +8937,7 @@ unsigned ToAS) const { // Single value types. if (Ty->isPointerTy() && Ty->getPointerAddressSpace() == FromAS) - return llvm::PointerType::get( - cast(Ty)->getElementType(), ToAS); + return llvm::PointerType::get(Ty->getPointerElementType(), ToAS); return Ty; } @@ -9334,7 +9333,7 @@ return llvm::ConstantPointerNull::get(PT); auto &Ctx = CGM.getContext(); - auto NPT = llvm::PointerType::get(PT->getElementType(), + auto NPT = llvm::PointerType::get(PT->getPointerElementType(), Ctx.getTargetAddressSpace(LangAS::opencl_generic)); return llvm::ConstantExpr::getAddrSpaceCast( llvm::ConstantPointerNull::get(NPT), PT); @@ -10271,8 +10270,7 @@ auto DefaultAS = getContext().getTargetAddressSpace(LangAS::Default); auto GlobalAS = getContext().getTargetAddressSpace(LangAS::cuda_device); if (LTy->isPointerTy() && LTy->getPointerAddressSpace() == DefaultAS) { - LTy = llvm::PointerType::get( - cast(LTy)->getElementType(), GlobalAS); + LTy = llvm::PointerType::get(LTy->getPointerElementType(), GlobalAS); return ABIArgInfo::getDirect(LTy, 0, nullptr, false); } } Index: llvm/include/llvm/FuzzMutate/OpDescriptor.h =================================================================== --- llvm/include/llvm/FuzzMutate/OpDescriptor.h +++ llvm/include/llvm/FuzzMutate/OpDescriptor.h @@ -146,7 +146,7 @@ return false; if (const auto *PtrT = dyn_cast(V->getType())) - return PtrT->getElementType()->isSized(); + return PtrT->getPointerElementType()->isSized(); return false; }; auto Make = [](ArrayRef, ArrayRef Ts) { Index: llvm/include/llvm/IR/DerivedTypes.h =================================================================== --- llvm/include/llvm/IR/DerivedTypes.h +++ llvm/include/llvm/IR/DerivedTypes.h @@ -667,9 +667,11 @@ unsigned AddressSpace) { if (PT->isOpaque()) return get(PT->getContext(), AddressSpace); - return get(PT->getElementType(), AddressSpace); + return get(PT->PointeeTy, AddressSpace); } + [[deprecated("Pointer element types are deprecated. You can *temporarily* " + "use Type::getPointerElementType() instead")]] Type *getElementType() const { assert(!isOpaque() && "Attempting to get element type of opaque pointer"); return PointeeTy; Index: llvm/include/llvm/IR/MatrixBuilder.h =================================================================== --- llvm/include/llvm/IR/MatrixBuilder.h +++ llvm/include/llvm/IR/MatrixBuilder.h @@ -68,7 +68,7 @@ // Deal with the pointer PointerType *PtrTy = cast(DataPtr->getType()); - Type *EltTy = PtrTy->getElementType(); + Type *EltTy = PtrTy->getPointerElementType(); auto *RetType = FixedVectorType::get(EltTy, Rows * Columns); Index: llvm/include/llvm/IR/Statepoint.h =================================================================== --- llvm/include/llvm/IR/Statepoint.h +++ llvm/include/llvm/IR/Statepoint.h @@ -123,7 +123,7 @@ /// statepoint. Type *getActualReturnType() const { auto *CalleeTy = - cast(getActualCalledOperand()->getType())->getElementType(); + getActualCalledOperand()->getType()->getPointerElementType(); return cast(CalleeTy)->getReturnType(); } Index: llvm/lib/Analysis/AliasAnalysisEvaluator.cpp =================================================================== --- llvm/lib/Analysis/AliasAnalysisEvaluator.cpp +++ llvm/lib/Analysis/AliasAnalysisEvaluator.cpp @@ -142,13 +142,13 @@ for (SetVector::iterator I1 = Pointers.begin(), E = Pointers.end(); I1 != E; ++I1) { auto I1Size = LocationSize::afterPointer(); - Type *I1ElTy = cast((*I1)->getType())->getElementType(); + Type *I1ElTy = (*I1)->getType()->getPointerElementType(); if (I1ElTy->isSized()) I1Size = LocationSize::precise(DL.getTypeStoreSize(I1ElTy)); for (SetVector::iterator I2 = Pointers.begin(); I2 != I1; ++I2) { auto I2Size = LocationSize::afterPointer(); - Type *I2ElTy = cast((*I2)->getType())->getElementType(); + Type *I2ElTy = (*I2)->getType()->getPointerElementType(); if (I2ElTy->isSized()) I2Size = LocationSize::precise(DL.getTypeStoreSize(I2ElTy)); @@ -233,7 +233,7 @@ for (CallBase *Call : Calls) { for (auto Pointer : Pointers) { auto Size = LocationSize::afterPointer(); - Type *ElTy = cast(Pointer->getType())->getElementType(); + Type *ElTy = Pointer->getType()->getPointerElementType(); if (ElTy->isSized()) Size = LocationSize::precise(DL.getTypeStoreSize(ElTy)); Index: llvm/lib/Analysis/ConstantFolding.cpp =================================================================== --- llvm/lib/Analysis/ConstantFolding.cpp +++ llvm/lib/Analysis/ConstantFolding.cpp @@ -941,7 +941,7 @@ if (auto *GV = dyn_cast(Ptr)) SrcElemTy = GV->getValueType(); else if (!PTy->isOpaque()) - SrcElemTy = PTy->getElementType(); + SrcElemTy = PTy->getNonOpaquePointerElementType(); else SrcElemTy = Type::getInt8Ty(Ptr->getContext()); Index: llvm/lib/Analysis/IVDescriptors.cpp =================================================================== --- llvm/lib/Analysis/IVDescriptors.cpp +++ llvm/lib/Analysis/IVDescriptors.cpp @@ -1414,8 +1414,9 @@ // Always use i8 element type for opaque pointer inductions. PointerType *PtrTy = cast(PhiTy); - Type *ElementType = PtrTy->isOpaque() ? Type::getInt8Ty(PtrTy->getContext()) - : PtrTy->getElementType(); + Type *ElementType = PtrTy->isOpaque() + ? Type::getInt8Ty(PtrTy->getContext()) + : PtrTy->getNonOpaquePointerElementType(); if (!ElementType->isSized()) return false; Index: llvm/lib/Analysis/ScalarEvolution.cpp =================================================================== --- llvm/lib/Analysis/ScalarEvolution.cpp +++ llvm/lib/Analysis/ScalarEvolution.cpp @@ -7598,8 +7598,7 @@ continue; // Also make sure step was increased the same with sizeof allocated // element type. - const PointerType *GEPT = dyn_cast(GEP->getType()); - if (Ty->getElementType() != GEPT->getElementType()) + if (Ty->getElementType() != GEP->getType()->getPointerElementType()) continue; // FIXME: Since gep indices are silently zext to the indexing type, Index: llvm/lib/AsmParser/LLParser.cpp =================================================================== --- llvm/lib/AsmParser/LLParser.cpp +++ llvm/lib/AsmParser/LLParser.cpp @@ -990,10 +990,10 @@ ExplicitTypeLoc, typeComparisonErrorMessage( "explicit pointee type doesn't match operand's pointee type", Ty, - PTy->getElementType())); + PTy->getNonOpaquePointerElementType())); } - if (!IsAlias && !PTy->getElementType()->isFunctionTy()) { + if (!IsAlias && !PTy->getPointerElementType()->isFunctionTy()) { return error(ExplicitTypeLoc, "explicit pointee type should be a function type"); } @@ -3588,7 +3588,7 @@ ExplicitTypeLoc, typeComparisonErrorMessage( "explicit pointee type doesn't match operand's pointee type", - Ty, BasePointerType->getElementType())); + Ty, BasePointerType->getNonOpaquePointerElementType())); } unsigned GEPWidth = @@ -7205,7 +7205,7 @@ ExplicitTypeLoc, typeComparisonErrorMessage( "explicit pointee type doesn't match operand's pointee type", Ty, - cast(Val->getType())->getElementType())); + Val->getType()->getNonOpaquePointerElementType())); } SmallPtrSet Visited; if (!Alignment && !Ty->isSized(&Visited)) @@ -7465,7 +7465,7 @@ ExplicitTypeLoc, typeComparisonErrorMessage( "explicit pointee type doesn't match operand's pointee type", Ty, - BasePointerType->getElementType())); + BasePointerType->getNonOpaquePointerElementType())); } SmallVector Indices; Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2702,7 +2702,7 @@ PointerType *OrigPtrTy = cast(Elt0FullTy->getScalarType()); if (!PointeeType) - PointeeType = OrigPtrTy->getElementType(); + PointeeType = OrigPtrTy->getPointerElementType(); else if (!OrigPtrTy->isOpaqueOrPointeeTypeMatches(PointeeType)) return error("Explicit gep operator type does not match pointee type " "of pointer operand"); @@ -2825,9 +2825,8 @@ ConstrStr += (char)Record[3+AsmStrSize+i]; UpgradeInlineAsmString(&AsmStr); // FIXME: support upgrading in opaque pointers mode. - V = InlineAsm::get( - cast(cast(CurTy)->getElementType()), - AsmStr, ConstrStr, HasSideEffects, IsAlignStack); + V = InlineAsm::get(cast(CurTy->getPointerElementType()), + AsmStr, ConstrStr, HasSideEffects, IsAlignStack); break; } // This version adds support for the asm dialect keywords (e.g., @@ -2852,10 +2851,9 @@ ConstrStr += (char)Record[3+AsmStrSize+i]; UpgradeInlineAsmString(&AsmStr); // FIXME: support upgrading in opaque pointers mode. - V = InlineAsm::get( - cast(cast(CurTy)->getElementType()), - AsmStr, ConstrStr, HasSideEffects, IsAlignStack, - InlineAsm::AsmDialect(AsmDialect)); + V = InlineAsm::get(cast(CurTy->getPointerElementType()), + AsmStr, ConstrStr, HasSideEffects, IsAlignStack, + InlineAsm::AsmDialect(AsmDialect)); break; } // This version adds support for the unwind keyword. @@ -2884,10 +2882,9 @@ ConstrStr += (char)Record[OpNum + AsmStrSize + i]; UpgradeInlineAsmString(&AsmStr); // FIXME: support upgrading in opaque pointers mode. - V = InlineAsm::get( - cast(cast(CurTy)->getElementType()), - AsmStr, ConstrStr, HasSideEffects, IsAlignStack, - InlineAsm::AsmDialect(AsmDialect), CanThrow); + V = InlineAsm::get(cast(CurTy->getPointerElementType()), + AsmStr, ConstrStr, HasSideEffects, IsAlignStack, + InlineAsm::AsmDialect(AsmDialect), CanThrow); break; } // This version adds explicit function type. @@ -3282,7 +3279,7 @@ if (!Ty->isPointerTy()) return error("Invalid type for value"); AddressSpace = cast(Ty)->getAddressSpace(); - Ty = cast(Ty)->getElementType(); + Ty = Ty->getPointerElementType(); } uint64_t RawLinkage = Record[3]; @@ -3375,7 +3372,7 @@ if (!FTy) return error("Invalid record"); if (auto *PTy = dyn_cast(FTy)) - FTy = PTy->getElementType(); + FTy = PTy->getPointerElementType(); if (!isa(FTy)) return error("Invalid type for value"); @@ -3416,7 +3413,7 @@ Func->removeParamAttr(i, Kind); Type *PTy = cast(FTy)->getParamType(i); - Type *PtrEltTy = cast(PTy)->getElementType(); + Type *PtrEltTy = PTy->getPointerElementType(); Attribute NewAttr; switch (Kind) { case Attribute::ByVal: @@ -3539,7 +3536,7 @@ auto *PTy = dyn_cast(Ty); if (!PTy) return error("Invalid type for value"); - Ty = PTy->getElementType(); + Ty = PTy->getPointerElementType(); AddrSpace = PTy->getAddressSpace(); } else { AddrSpace = Record[OpNum++]; @@ -3908,7 +3905,7 @@ CB->removeParamAttr(i, Kind); - Type *PtrEltTy = cast(ArgsTys[i])->getElementType(); + Type *PtrEltTy = ArgsTys[i]->getPointerElementType(); Attribute NewAttr; switch (Kind) { case Attribute::ByVal: @@ -3949,7 +3946,7 @@ case Intrinsic::preserve_array_access_index: case Intrinsic::preserve_struct_access_index: if (!CB->getAttributes().getParamElementType(0)) { - Type *ElTy = cast(ArgsTys[0])->getElementType(); + Type *ElTy = ArgsTys[0]->getPointerElementType(); Attribute NewAttr = Attribute::get(Context, Attribute::ElementType, ElTy); CB->addParamAttr(0, NewAttr); } @@ -4239,8 +4236,7 @@ return error("Invalid record"); if (!Ty) { - Ty = cast(BasePtr->getType()->getScalarType()) - ->getElementType(); + Ty = BasePtr->getType()->getScalarType()->getPointerElementType(); } else if (!cast(BasePtr->getType()->getScalarType()) ->isOpaqueOrPointeeTypeMatches(Ty)) { return error( @@ -4756,8 +4752,8 @@ if (!CalleeTy) return error("Callee is not a pointer"); if (!FTy) { - FTy = dyn_cast( - cast(Callee->getType())->getElementType()); + FTy = + dyn_cast(Callee->getType()->getPointerElementType()); if (!FTy) return error("Callee is not of pointer to function type"); } else if (!CalleeTy->isOpaqueOrPointeeTypeMatches(FTy)) @@ -4837,8 +4833,8 @@ if (!OpTy) return error("Callee is not a pointer type"); if (!FTy) { - FTy = dyn_cast( - cast(Callee->getType())->getElementType()); + FTy = + dyn_cast(Callee->getType()->getPointerElementType()); if (!FTy) return error("Callee is not of pointer to function type"); } else if (!OpTy->isOpaqueOrPointeeTypeMatches(FTy)) @@ -5000,7 +4996,7 @@ auto *PTy = dyn_cast_or_null(Ty); if (!PTy) return error("Old-style alloca with a non-pointer type"); - Ty = PTy->getElementType(); + Ty = PTy->getPointerElementType(); } Type *OpTy = getTypeByID(Record[1]); Value *Size = getFnValueByID(Record[2], OpTy); @@ -5045,7 +5041,7 @@ if (OpNum + 3 == Record.size()) { Ty = getTypeByID(Record[OpNum++]); } else { - Ty = cast(Op->getType())->getElementType(); + Ty = Op->getType()->getPointerElementType(); } if (Error Err = typeCheckLoadStoreInst(Ty, Op->getType())) @@ -5078,7 +5074,7 @@ if (OpNum + 5 == Record.size()) { Ty = getTypeByID(Record[OpNum++]); } else { - Ty = cast(Op->getType())->getElementType(); + Ty = Op->getType()->getPointerElementType(); } if (Error Err = typeCheckLoadStoreInst(Ty, Op->getType())) @@ -5110,8 +5106,7 @@ (BitCode == bitc::FUNC_CODE_INST_STORE ? getValueTypePair(Record, OpNum, NextValueNo, Val) : popValue(Record, OpNum, NextValueNo, - cast(Ptr->getType())->getElementType(), - Val)) || + Ptr->getType()->getPointerElementType(), Val)) || OpNum + 2 != Record.size()) return error("Invalid record"); @@ -5139,8 +5134,7 @@ (BitCode == bitc::FUNC_CODE_INST_STOREATOMIC ? getValueTypePair(Record, OpNum, NextValueNo, Val) : popValue(Record, OpNum, NextValueNo, - cast(Ptr->getType())->getElementType(), - Val)) || + Ptr->getType()->getPointerElementType(), Val)) || OpNum + 4 != Record.size()) return error("Invalid record"); @@ -5391,8 +5385,8 @@ if (!OpTy) return error("Callee is not a pointer type"); if (!FTy) { - FTy = dyn_cast( - cast(Callee->getType())->getElementType()); + FTy = + dyn_cast(Callee->getType()->getPointerElementType()); if (!FTy) return error("Callee is not of pointer to function type"); } else if (!OpTy->isOpaqueOrPointeeTypeMatches(FTy)) Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -948,7 +948,7 @@ } else { // POINTER: [pointee type, address space] Code = bitc::TYPE_CODE_POINTER; - TypeVals.push_back(VE.getTypeID(PTy->getElementType())); + TypeVals.push_back(VE.getTypeID(PTy->getNonOpaquePointerElementType())); TypeVals.push_back(AddressSpace); if (AddressSpace == 0) AbbrevToUse = PtrAbbrev; Index: llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp =================================================================== --- llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp +++ llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp @@ -313,7 +313,7 @@ PointerType *PtrTy = dyn_cast(OpTy); if (!PtrTy) report_fatal_error("Indirect operand for inline asm not a pointer!"); - OpTy = PtrTy->getElementType(); + OpTy = PtrTy->getPointerElementType(); } // FIXME: Support aggregate input operands Index: llvm/lib/FuzzMutate/Operations.cpp =================================================================== --- llvm/lib/FuzzMutate/Operations.cpp +++ llvm/lib/FuzzMutate/Operations.cpp @@ -169,7 +169,7 @@ OpDescriptor llvm::fuzzerop::gepDescriptor(unsigned Weight) { auto buildGEP = [](ArrayRef Srcs, Instruction *Inst) { - Type *Ty = cast(Srcs[0]->getType())->getElementType(); + Type *Ty = Srcs[0]->getType()->getPointerElementType(); auto Indices = makeArrayRef(Srcs).drop_front(1); return GetElementPtrInst::Create(Ty, Srcs[0], Indices, "G", Inst); }; Index: llvm/lib/FuzzMutate/RandomIRBuilder.cpp =================================================================== --- llvm/lib/FuzzMutate/RandomIRBuilder.cpp +++ llvm/lib/FuzzMutate/RandomIRBuilder.cpp @@ -53,8 +53,8 @@ IP = ++I->getIterator(); assert(IP != BB.end() && "guaranteed by the findPointer"); } - auto *NewLoad = new LoadInst( - cast(Ptr->getType())->getElementType(), Ptr, "L", &*IP); + auto *NewLoad = + new LoadInst(Ptr->getType()->getPointerElementType(), Ptr, "L", &*IP); // Only sample this load if it really matches the descriptor if (Pred.matches(Srcs, NewLoad)) @@ -141,12 +141,12 @@ if (auto PtrTy = dyn_cast(Inst->getType())) { // We can never generate loads from non first class or non sized types - if (!PtrTy->getElementType()->isSized() || - !PtrTy->getElementType()->isFirstClassType()) + Type *ElemTy = PtrTy->getPointerElementType(); + if (!ElemTy->isSized() || !ElemTy->isFirstClassType()) return false; // TODO: Check if this is horribly expensive. - return Pred.matches(Srcs, UndefValue::get(PtrTy->getElementType())); + return Pred.matches(Srcs, UndefValue::get(ElemTy)); } return false; }; Index: llvm/lib/IR/AsmWriter.cpp =================================================================== --- llvm/lib/IR/AsmWriter.cpp +++ llvm/lib/IR/AsmWriter.cpp @@ -587,7 +587,7 @@ OS << " addrspace(" << AddressSpace << ')'; return; } - print(PTy->getElementType(), OS); + print(PTy->getNonOpaquePointerElementType(), OS); if (unsigned AddressSpace = PTy->getAddressSpace()) OS << " addrspace(" << AddressSpace << ')'; OS << '*'; Index: llvm/lib/IR/AutoUpgrade.cpp =================================================================== --- llvm/lib/IR/AutoUpgrade.cpp +++ llvm/lib/IR/AutoUpgrade.cpp @@ -4495,7 +4495,7 @@ if (F.getCallingConv() == CallingConv::X86_INTR && !F.arg_empty() && !F.hasParamAttribute(0, Attribute::ByVal)) { - Type *ByValTy = cast(F.getArg(0)->getType())->getElementType(); + Type *ByValTy = F.getArg(0)->getType()->getPointerElementType(); Attribute NewAttr = Attribute::getWithByValType(F.getContext(), ByValTy); F.addParamAttr(0, NewAttr); } Index: llvm/lib/IR/ConstantFold.cpp =================================================================== --- llvm/lib/IR/ConstantFold.cpp +++ llvm/lib/IR/ConstantFold.cpp @@ -119,21 +119,21 @@ if (PointerType *DPTy = dyn_cast(DestTy)) if (PTy->getAddressSpace() == DPTy->getAddressSpace() && !PTy->isOpaque() && !DPTy->isOpaque() && - PTy->getElementType()->isSized()) { + PTy->getNonOpaquePointerElementType()->isSized()) { SmallVector IdxList; Value *Zero = Constant::getNullValue(Type::getInt32Ty(DPTy->getContext())); IdxList.push_back(Zero); - Type *ElTy = PTy->getElementType(); - while (ElTy && ElTy != DPTy->getElementType()) { + Type *ElTy = PTy->getNonOpaquePointerElementType(); + while (ElTy && ElTy != DPTy->getNonOpaquePointerElementType()) { ElTy = GetElementPtrInst::getTypeAtIndex(ElTy, (uint64_t)0); IdxList.push_back(Zero); } - if (ElTy == DPTy->getElementType()) + if (ElTy == DPTy->getNonOpaquePointerElementType()) // This GEP is inbounds because all indices are zero. - return ConstantExpr::getInBoundsGetElementPtr(PTy->getElementType(), - V, IdxList); + return ConstantExpr::getInBoundsGetElementPtr( + PTy->getNonOpaquePointerElementType(), V, IdxList); } // Handle casts from one vector constant to another. We know that the src @@ -2098,9 +2098,9 @@ PointerType *DstPtrTy = dyn_cast(CE->getType()); if (SrcPtrTy && DstPtrTy) { ArrayType *SrcArrayTy = - dyn_cast(SrcPtrTy->getElementType()); + dyn_cast(SrcPtrTy->getPointerElementType()); ArrayType *DstArrayTy = - dyn_cast(DstPtrTy->getElementType()); + dyn_cast(DstPtrTy->getPointerElementType()); if (SrcArrayTy && DstArrayTy && SrcArrayTy->getElementType() == DstArrayTy->getElementType() && SrcPtrTy->getAddressSpace() == DstPtrTy->getAddressSpace()) Index: llvm/lib/IR/Core.cpp =================================================================== --- llvm/lib/IR/Core.cpp +++ llvm/lib/IR/Core.cpp @@ -796,7 +796,7 @@ LLVMTypeRef LLVMGetElementType(LLVMTypeRef WrappedTy) { auto *Ty = unwrap(WrappedTy); if (auto *PTy = dyn_cast(Ty)) - return wrap(PTy->getElementType()); + return wrap(PTy->getPointerElementType()); if (auto *ATy = dyn_cast(Ty)) return wrap(ATy->getElementType()); return wrap(cast(Ty)->getElementType()); Index: llvm/lib/IR/Function.cpp =================================================================== --- llvm/lib/IR/Function.cpp +++ llvm/lib/IR/Function.cpp @@ -817,7 +817,8 @@ // Opaque pointer doesn't have pointee type information, so we just mangle // address space for opaque pointer. if (!PTyp->isOpaque()) - Result += getMangledTypeStr(PTyp->getElementType(), HasUnnamedType); + Result += getMangledTypeStr(PTyp->getNonOpaquePointerElementType(), + HasUnnamedType); } else if (ArrayType *ATyp = dyn_cast(Ty)) { Result += "a" + utostr(ATyp->getNumElements()) + getMangledTypeStr(ATyp->getElementType(), HasUnnamedType); @@ -1465,8 +1466,8 @@ if (!PT || PT->getAddressSpace() != D.Pointer_AddressSpace) return true; if (!PT->isOpaque()) - return matchIntrinsicType(PT->getElementType(), Infos, ArgTys, - DeferredChecks, IsDeferredCheck); + return matchIntrinsicType(PT->getNonOpaquePointerElementType(), Infos, + ArgTys, DeferredChecks, IsDeferredCheck); // Consume IIT descriptors relating to the pointer element type. while (Infos.front().Kind == IITDescriptor::Pointer) Infos = Infos.slice(1); @@ -1573,7 +1574,8 @@ return IsDeferredCheck || DeferCheck(Ty); Type * ReferenceType = ArgTys[D.getArgumentNumber()]; PointerType *ThisArgType = dyn_cast(Ty); - return (!ThisArgType || ThisArgType->getElementType() != ReferenceType); + return (!ThisArgType || + ThisArgType->getPointerElementType() != ReferenceType); } case IITDescriptor::PtrToElt: { if (D.getArgumentNumber() >= ArgTys.size()) Index: llvm/lib/IR/IRBuilder.cpp =================================================================== --- llvm/lib/IR/IRBuilder.cpp +++ llvm/lib/IR/IRBuilder.cpp @@ -679,7 +679,7 @@ const Twine &Name) { // Extract out the type of the callee. auto *FuncPtrType = cast(ActualCallee->getType()); - assert(isa(FuncPtrType->getElementType()) && + assert(isa(FuncPtrType->getPointerElementType()) && "actual callee must be a callable value"); Module *M = Builder->GetInsertBlock()->getParent()->getParent(); @@ -736,7 +736,7 @@ ArrayRef GCArgs, const Twine &Name) { // Extract out the type of the callee. auto *FuncPtrType = cast(ActualInvokee->getType()); - assert(isa(FuncPtrType->getElementType()) && + assert(isa(FuncPtrType->getPointerElementType()) && "actual callee must be a callable value"); Module *M = Builder->GetInsertBlock()->getParent()->getParent(); @@ -1002,13 +1002,12 @@ const Twine &Name) { assert(LHS->getType() == RHS->getType() && "Pointer subtraction operand types must match!"); - auto *ArgType = cast(LHS->getType()); + auto *ArgElemType = LHS->getType()->getPointerElementType(); Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context)); Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context)); Value *Difference = CreateSub(LHS_int, RHS_int); - return CreateExactSDiv(Difference, - ConstantExpr::getSizeOf(ArgType->getElementType()), - Name); + return CreateExactSDiv( + Difference, ConstantExpr::getSizeOf(ArgElemType), Name); } Value *IRBuilderBase::CreateLaunderInvariantGroup(Value *Ptr) { Index: llvm/lib/IR/Verifier.cpp =================================================================== --- llvm/lib/IR/Verifier.cpp +++ llvm/lib/IR/Verifier.cpp @@ -1826,33 +1826,34 @@ "Attribute 'preallocated' does not support unsized types!", V); } if (!PTy->isOpaque()) { - if (!isa(PTy->getElementType())) + if (!isa(PTy->getNonOpaquePointerElementType())) Assert(!Attrs.hasAttribute(Attribute::SwiftError), "Attribute 'swifterror' only applies to parameters " "with pointer to pointer type!", V); if (Attrs.hasAttribute(Attribute::ByRef)) { - Assert(Attrs.getByRefType() == PTy->getElementType(), + Assert(Attrs.getByRefType() == PTy->getNonOpaquePointerElementType(), "Attribute 'byref' type does not match parameter!", V); } if (Attrs.hasAttribute(Attribute::ByVal) && Attrs.getByValType()) { - Assert(Attrs.getByValType() == PTy->getElementType(), + Assert(Attrs.getByValType() == PTy->getNonOpaquePointerElementType(), "Attribute 'byval' type does not match parameter!", V); } if (Attrs.hasAttribute(Attribute::Preallocated)) { - Assert(Attrs.getPreallocatedType() == PTy->getElementType(), + Assert(Attrs.getPreallocatedType() == + PTy->getNonOpaquePointerElementType(), "Attribute 'preallocated' type does not match parameter!", V); } if (Attrs.hasAttribute(Attribute::InAlloca)) { - Assert(Attrs.getInAllocaType() == PTy->getElementType(), + Assert(Attrs.getInAllocaType() == PTy->getNonOpaquePointerElementType(), "Attribute 'inalloca' type does not match parameter!", V); } if (Attrs.hasAttribute(Attribute::ElementType)) { - Assert(Attrs.getElementType() == PTy->getElementType(), + Assert(Attrs.getElementType() == PTy->getNonOpaquePointerElementType(), "Attribute 'elementtype' type does not match parameter!", V); } } @@ -2195,9 +2196,10 @@ const Value *Target = Call.getArgOperand(2); auto *PT = dyn_cast(Target->getType()); - Assert(PT && PT->getElementType()->isFunctionTy(), + Assert(PT && PT->getPointerElementType()->isFunctionTy(), "gc.statepoint callee must be of function pointer type", Call, Target); - FunctionType *TargetFuncType = cast(PT->getElementType()); + FunctionType *TargetFuncType = + cast(PT->getPointerElementType()); const int NumCallArgs = cast(Call.getArgOperand(3))->getZExtValue(); Assert(NumCallArgs >= 0, @@ -5005,7 +5007,7 @@ // Assert that result type matches wrapped callee. const Value *Target = StatepointCall->getArgOperand(2); auto *PT = cast(Target->getType()); - auto *TargetFuncType = cast(PT->getElementType()); + auto *TargetFuncType = cast(PT->getPointerElementType()); Assert(Call.getType() == TargetFuncType->getReturnType(), "gc.result result type does not match wrapped callee", Call); break; @@ -5312,7 +5314,7 @@ PointerType *Op0PtrTy = cast(Call.getArgOperand(0)->getType()); if (!Op0PtrTy->isOpaque()) - Op0ElemTy = Op0PtrTy->getElementType(); + Op0ElemTy = Op0PtrTy->getNonOpaquePointerElementType(); break; } case Intrinsic::matrix_column_major_store: { @@ -5326,7 +5328,7 @@ PointerType *Op1PtrTy = cast(Call.getArgOperand(1)->getType()); if (!Op1PtrTy->isOpaque()) - Op1ElemTy = Op1PtrTy->getElementType(); + Op1ElemTy = Op1PtrTy->getNonOpaquePointerElementType(); break; } default: Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp =================================================================== --- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -11781,10 +11781,10 @@ case Intrinsic::aarch64_ldxr: { PointerType *PtrTy = cast(I.getArgOperand(0)->getType()); Info.opc = ISD::INTRINSIC_W_CHAIN; - Info.memVT = MVT::getVT(PtrTy->getElementType()); + Info.memVT = MVT::getVT(PtrTy->getPointerElementType()); Info.ptrVal = I.getArgOperand(0); Info.offset = 0; - Info.align = DL.getABITypeAlign(PtrTy->getElementType()); + Info.align = DL.getABITypeAlign(PtrTy->getPointerElementType()); Info.flags = MachineMemOperand::MOLoad | MachineMemOperand::MOVolatile; return true; } @@ -11792,10 +11792,10 @@ case Intrinsic::aarch64_stxr: { PointerType *PtrTy = cast(I.getArgOperand(1)->getType()); Info.opc = ISD::INTRINSIC_W_CHAIN; - Info.memVT = MVT::getVT(PtrTy->getElementType()); + Info.memVT = MVT::getVT(PtrTy->getPointerElementType()); Info.ptrVal = I.getArgOperand(1); Info.offset = 0; - Info.align = DL.getABITypeAlign(PtrTy->getElementType()); + Info.align = DL.getABITypeAlign(PtrTy->getPointerElementType()); Info.flags = MachineMemOperand::MOStore | MachineMemOperand::MOVolatile; return true; } @@ -11823,7 +11823,7 @@ Info.memVT = MVT::getVT(I.getType()); Info.ptrVal = I.getArgOperand(1); Info.offset = 0; - Info.align = DL.getABITypeAlign(PtrTy->getElementType()); + Info.align = DL.getABITypeAlign(PtrTy->getPointerElementType()); Info.flags = MachineMemOperand::MOLoad | MachineMemOperand::MONonTemporal; return true; } @@ -11833,7 +11833,7 @@ Info.memVT = MVT::getVT(I.getOperand(0)->getType()); Info.ptrVal = I.getArgOperand(2); Info.offset = 0; - Info.align = DL.getABITypeAlign(PtrTy->getElementType()); + Info.align = DL.getABITypeAlign(PtrTy->getPointerElementType()); Info.flags = MachineMemOperand::MOStore | MachineMemOperand::MONonTemporal; return true; } Index: llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp @@ -331,8 +331,8 @@ if (auto PtrTy = dyn_cast(Arg.getType())) { if (PtrTy->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS) { // FIXME: Should report this for all address spaces - PointeeAlign = DL.getValueOrABITypeAlignment(Arg.getParamAlign(), - PtrTy->getElementType()); + PointeeAlign = DL.getValueOrABITypeAlignment( + Arg.getParamAlign(), PtrTy->getPointerElementType()); } } @@ -732,8 +732,8 @@ // FIXME: Need to distinguish in memory alignment from pointer alignment. if (auto PtrTy = dyn_cast(Ty)) { if (PtrTy->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS) { - PointeeAlign = DL.getValueOrABITypeAlignment(Arg.getParamAlign(), - PtrTy->getElementType()); + PointeeAlign = DL.getValueOrABITypeAlignment( + Arg.getParamAlign(), PtrTy->getPointerElementType()); } } Index: llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp +++ llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp @@ -433,7 +433,7 @@ PointerType *ArgType = cast(Arg.getType()); - auto *EltTy = ArgType->getElementType(); + auto *EltTy = ArgType->getPointerElementType(); const auto Align = DL->getValueOrABITypeAlignment(Arg.getParamAlign(), EltTy); Index: llvm/lib/Target/ARM/ARMISelLowering.cpp =================================================================== --- llvm/lib/Target/ARM/ARMISelLowering.cpp +++ llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -20789,10 +20789,10 @@ auto &DL = I.getCalledFunction()->getParent()->getDataLayout(); PointerType *PtrTy = cast(I.getArgOperand(0)->getType()); Info.opc = ISD::INTRINSIC_W_CHAIN; - Info.memVT = MVT::getVT(PtrTy->getElementType()); + Info.memVT = MVT::getVT(PtrTy->getPointerElementType()); Info.ptrVal = I.getArgOperand(0); Info.offset = 0; - Info.align = DL.getABITypeAlign(PtrTy->getElementType()); + Info.align = DL.getABITypeAlign(PtrTy->getPointerElementType()); Info.flags = MachineMemOperand::MOLoad | MachineMemOperand::MOVolatile; return true; } @@ -20801,10 +20801,10 @@ auto &DL = I.getCalledFunction()->getParent()->getDataLayout(); PointerType *PtrTy = cast(I.getArgOperand(1)->getType()); Info.opc = ISD::INTRINSIC_W_CHAIN; - Info.memVT = MVT::getVT(PtrTy->getElementType()); + Info.memVT = MVT::getVT(PtrTy->getPointerElementType()); Info.ptrVal = I.getArgOperand(1); Info.offset = 0; - Info.align = DL.getABITypeAlign(PtrTy->getElementType()); + Info.align = DL.getABITypeAlign(PtrTy->getPointerElementType()); Info.flags = MachineMemOperand::MOStore | MachineMemOperand::MOVolatile; return true; } Index: llvm/lib/Target/BPF/BTFDebug.cpp =================================================================== --- llvm/lib/Target/BPF/BTFDebug.cpp +++ llvm/lib/Target/BPF/BTFDebug.cpp @@ -1366,7 +1366,8 @@ // Calculate symbol size const DataLayout &DL = Global.getParent()->getDataLayout(); - uint32_t Size = DL.getTypeAllocSize(Global.getType()->getElementType()); + uint32_t Size = + DL.getTypeAllocSize(Global.getType()->getPointerElementType()); DataSecEntries[std::string(SecName)]->addDataSecEntry(VarId, Asm->getSymbol(&Global), Size); Index: llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp =================================================================== --- llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp +++ llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp @@ -443,7 +443,7 @@ // we don't need to do pointer casts. auto *PtrTy = cast(Ptr->getType()); if (!PtrTy->isOpaque()) { - Type *ElemTy = PtrTy->getElementType(); + Type *ElemTy = PtrTy->getNonOpaquePointerElementType(); int ElemSize = HVC.getAllocSizeOf(ElemTy); if (Adjust % ElemSize == 0 && Adjust != 0) { Value *Tmp0 = Index: llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp =================================================================== --- llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -1454,7 +1454,7 @@ if (static_cast(TM).getDrvInterface() != NVPTX::CUDA) { - Type *ETy = PTy->getElementType(); + Type *ETy = PTy->getPointerElementType(); int addrSpace = PTy->getAddressSpace(); switch (addrSpace) { default: @@ -1514,7 +1514,7 @@ // param has byVal attribute. So should be a pointer auto *PTy = dyn_cast(Ty); assert(PTy && "Param with byval attribute should be a pointer type"); - Type *ETy = PTy->getElementType(); + Type *ETy = PTy->getPointerElementType(); if (isABI || isKernelFunc) { // Just print .param .align .b8 .param[size]; Index: llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp =================================================================== --- llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp +++ llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp @@ -1354,7 +1354,7 @@ } auto *PTy = dyn_cast(Ty); assert(PTy && "Param with byval attribute should be a pointer type"); - Type *ETy = PTy->getElementType(); + Type *ETy = PTy->getPointerElementType(); Align align = Outs[OIdx].Flags.getNonZeroByValAlign(); unsigned sz = DL.getTypeAllocSize(ETy); @@ -1577,7 +1577,8 @@ SmallVector Offsets; auto *PTy = dyn_cast(Args[i].Ty); assert(PTy && "Type of a byval parameter should be pointer"); - ComputePTXValueVTs(*this, DL, PTy->getElementType(), VTs, &Offsets, 0); + ComputePTXValueVTs( + *this, DL, PTy->getPointerElementType(), VTs, &Offsets, 0); // declare .param .align .b8 .param[]; unsigned sz = Outs[OIdx].Flags.getByValSize(); @@ -2447,7 +2448,7 @@ if (!context) return false; - auto *STy = dyn_cast(PTy->getElementType()); + auto *STy = dyn_cast(PTy->getPointerElementType()); if (!STy || STy->isLiteral()) return false; Index: llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp =================================================================== --- llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp +++ llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp @@ -233,7 +233,7 @@ assert(PType && "Expecting pointer type in handleByValParam"); - Type *StructType = PType->getElementType(); + Type *StructType = PType->getPointerElementType(); auto IsALoadChain = [&](Value *Start) { SmallVector ValuesToCheck = {Start}; Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp =================================================================== --- llvm/lib/Target/PowerPC/PPCISelLowering.cpp +++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp @@ -17894,7 +17894,7 @@ assert(EnableQuadwordAtomics && Subtarget.hasQuadwordAtomics() && "Only support quadword now"); Module *M = Builder.GetInsertBlock()->getParent()->getParent(); - Type *ValTy = cast(AlignedAddr->getType())->getElementType(); + Type *ValTy = AlignedAddr->getType()->getPointerElementType(); assert(ValTy->getPrimitiveSizeInBits() == 128); Function *RMW = Intrinsic::getDeclaration( M, getIntrinsicForAtomicRMWBinOp128(AI->getOperation())); @@ -17919,7 +17919,7 @@ assert(EnableQuadwordAtomics && Subtarget.hasQuadwordAtomics() && "Only support quadword now"); Module *M = Builder.GetInsertBlock()->getParent()->getParent(); - Type *ValTy = cast(AlignedAddr->getType())->getElementType(); + Type *ValTy = AlignedAddr->getType()->getPointerElementType(); assert(ValTy->getPrimitiveSizeInBits() == 128); Function *IntCmpXchg = Intrinsic::getDeclaration(M, Intrinsic::ppc_cmpxchg_i128); Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp =================================================================== --- llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -1105,7 +1105,7 @@ case Intrinsic::riscv_masked_cmpxchg_i32: { PointerType *PtrTy = cast(I.getArgOperand(0)->getType()); Info.opc = ISD::INTRINSIC_W_CHAIN; - Info.memVT = MVT::getVT(PtrTy->getElementType()); + Info.memVT = MVT::getVT(PtrTy->getPointerElementType()); Info.ptrVal = I.getArgOperand(0); Info.offset = 0; Info.align = Align(4); Index: llvm/lib/Target/Sparc/SparcISelLowering.cpp =================================================================== --- llvm/lib/Target/Sparc/SparcISelLowering.cpp +++ llvm/lib/Target/Sparc/SparcISelLowering.cpp @@ -826,7 +826,7 @@ // sret only allowed on first argument assert(Outs[realArgIdx].OrigArgIndex == 0); PointerType *Ty = cast(CLI.getArgs()[0].Ty); - Type *ElementTy = Ty->getElementType(); + Type *ElementTy = Ty->getPointerElementType(); SRetArgSize = DAG.getDataLayout().getTypeAllocSize(ElementTy); continue; } Index: llvm/lib/Transforms/Coroutines/CoroFrame.cpp =================================================================== --- llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -808,7 +808,7 @@ if (Ty->isPointerTy()) { auto *PtrTy = cast(Ty); - Type *PointeeTy = PtrTy->getElementType(); + Type *PointeeTy = PtrTy->getPointerElementType(); auto Name = solveTypeName(PointeeTy); if (Name == "UnknownType") return "PointerType"; @@ -2278,7 +2278,7 @@ IRBuilder<> Builder(F.getEntryBlock().getFirstNonPHIOrDbg()); auto ArgTy = cast(Arg.getType()); - auto ValueTy = ArgTy->getElementType(); + auto ValueTy = ArgTy->getPointerElementType(); // Reduce to the alloca case: Index: llvm/lib/Transforms/IPO/ArgumentPromotion.cpp =================================================================== --- llvm/lib/Transforms/IPO/ArgumentPromotion.cpp +++ llvm/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -196,8 +196,7 @@ for (const auto &ArgIndex : ArgIndices) { // not allowed to dereference ->begin() if size() is 0 Params.push_back(GetElementPtrInst::getIndexedType( - cast(I->getType())->getElementType(), - ArgIndex.second)); + I->getType()->getPointerElementType(), ArgIndex.second)); ArgAttrVec.push_back(AttributeSet()); assert(Params.back()); } @@ -298,7 +297,7 @@ Ops.push_back(ConstantInt::get(IdxTy, II)); // Keep track of the type we're currently indexing. if (auto *ElPTy = dyn_cast(ElTy)) - ElTy = ElPTy->getElementType(); + ElTy = ElPTy->getPointerElementType(); else ElTy = GetElementPtrInst::getTypeAtIndex(ElTy, II); } @@ -928,7 +927,7 @@ SmallPtrSet ArgsToPromote; SmallPtrSet ByValArgsToTransform; for (Argument *PtrArg : PointerArgs) { - Type *AgTy = cast(PtrArg->getType())->getElementType(); + Type *AgTy = PtrArg->getType()->getPointerElementType(); // Replace sret attribute with noalias. This reduces register pressure by // avoiding a register copy. Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2520,7 +2520,7 @@ if (!Call.isByValArgument(ix)) return false; - Type *SrcElemTy = SrcTy->getElementType(); + Type *SrcElemTy = SrcTy->getNonOpaquePointerElementType(); Type *DstElemTy = Call.getParamByValType(ix); if (!SrcElemTy->isSized() || !DstElemTy->isSized()) return false; @@ -2785,7 +2785,7 @@ Call.removeParamAttr(ix, Attribute::ByVal); Call.addParamAttr( ix, Attribute::getWithByValType( - Call.getContext(), NewTy->getElementType())); + Call.getContext(), NewTy->getPointerElementType())); } Changed = true; } @@ -3034,12 +3034,12 @@ // sized type and the sized type has to have the same size as the old type. if (ParamTy != ActTy && CallerPAL.hasParamAttr(i, Attribute::ByVal)) { PointerType *ParamPTy = dyn_cast(ParamTy); - if (!ParamPTy || !ParamPTy->getElementType()->isSized()) + if (!ParamPTy || !ParamPTy->getPointerElementType()->isSized()) return false; Type *CurElTy = Call.getParamByValType(i); if (DL.getTypeAllocSize(CurElTy) != - DL.getTypeAllocSize(ParamPTy->getElementType())) + DL.getTypeAllocSize(ParamPTy->getPointerElementType())) return false; } } @@ -3053,16 +3053,16 @@ // call. We don't want to introduce a varargs call where one doesn't // already exist. PointerType *APTy = cast(Call.getCalledOperand()->getType()); - if (FT->isVarArg()!=cast(APTy->getElementType())->isVarArg()) + if (FT->isVarArg()!=cast(APTy->getPointerElementType())->isVarArg()) return false; // If both the callee and the cast type are varargs, we still have to make // sure the number of fixed parameters are the same or we have the same // ABI issues as if we introduce a varargs call. if (FT->isVarArg() && - cast(APTy->getElementType())->isVarArg() && + cast(APTy->getPointerElementType())->isVarArg() && FT->getNumParams() != - cast(APTy->getElementType())->getNumParams()) + cast(APTy->getPointerElementType())->getNumParams()) return false; } Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -91,7 +91,7 @@ // Get the type really allocated and the type casted to. Type *AllocElTy = AI.getAllocatedType(); - Type *CastElTy = PTy->getElementType(); + Type *CastElTy = PTy->getPointerElementType(); if (!AllocElTy->isSized() || !CastElTy->isSized()) return nullptr; // This optimisation does not work for cases where the cast type @@ -2649,8 +2649,8 @@ if (SrcPTy->isOpaque() || DstPTy->isOpaque()) return nullptr; - Type *DstElTy = DstPTy->getElementType(); - Type *SrcElTy = SrcPTy->getElementType(); + Type *DstElTy = DstPTy->getNonOpaquePointerElementType(); + Type *SrcElTy = SrcPTy->getNonOpaquePointerElementType(); // When the type pointed to is not sized the cast cannot be // turned into a gep. @@ -2669,8 +2669,8 @@ // If we found a path from the src to dest, create the getelementptr now. if (SrcElTy == DstElTy) { SmallVector Idxs(NumZeros + 1, Builder.getInt32(0)); - GetElementPtrInst *GEP = - GetElementPtrInst::Create(SrcPTy->getElementType(), Src, Idxs); + GetElementPtrInst *GEP = GetElementPtrInst::Create( + SrcPTy->getNonOpaquePointerElementType(), Src, Idxs); // If the source pointer is dereferenceable, then assume it points to an // allocated object and apply "inbounds" to the GEP. Index: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -345,7 +345,8 @@ #ifndef NDEBUG auto *PT = cast(I.getType()); auto *NT = cast(V->getType()); - assert(PT != NT && PT->getElementType() == NT->getElementType() && + assert(PT != NT && + PT->getPointerElementType() == NT->getPointerElementType() && "Invalid usage"); #endif WorkMap[&I] = V; Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1372,7 +1372,7 @@ Type * InstCombinerImpl::FindElementAtOffset(PointerType *PtrTy, int64_t IntOffset, SmallVectorImpl &NewIndices) { - Type *Ty = PtrTy->getElementType(); + Type *Ty = PtrTy->getPointerElementType(); if (!Ty->isSized()) return nullptr; @@ -2311,7 +2311,7 @@ // type. For now, skip these. if (StrippedPtr != PtrOp && !StrippedPtrTy->isOpaque()) { bool HasZeroPointerIndex = false; - Type *StrippedPtrEltTy = StrippedPtrTy->getElementType(); + Type *StrippedPtrEltTy = StrippedPtrTy->getNonOpaquePointerElementType(); if (auto *C = dyn_cast(GEP.getOperand(1))) HasZeroPointerIndex = C->isZero(); @@ -2498,7 +2498,7 @@ if (auto *BCI = dyn_cast(ASCStrippedPtrOp)) { Value *SrcOp = BCI->getOperand(0); PointerType *SrcType = cast(BCI->getSrcTy()); - Type *SrcEltType = SrcType->getElementType(); + Type *SrcEltType = SrcType->getPointerElementType(); // GEP directly using the source operand if this GEP is accessing an element // of a bitcasted pointer to vector or array of the same dimensions: Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1559,7 +1559,7 @@ auto BasePtr = CI->getOperand(OpOffset); if (ignoreAccess(LI, BasePtr)) return; - auto Ty = cast(BasePtr->getType())->getElementType(); + auto Ty = BasePtr->getType()->getPointerElementType(); MaybeAlign Alignment = Align(1); // Otherwise no alignment guarantees. We probably got Undef. if (auto *Op = dyn_cast(CI->getOperand(1 + OpOffset))) @@ -1656,8 +1656,7 @@ unsigned Granularity, uint32_t TypeSize, bool IsWrite, Value *SizeArgument, bool UseCalls, uint32_t Exp) { - auto *VTy = cast( - cast(Addr->getType())->getElementType()); + auto *VTy = cast(Addr->getType()->getPointerElementType()); uint64_t ElemTypeSize = DL.getTypeStoreSizeInBits(VTy->getScalarType()); unsigned Num = VTy->getNumElements(); auto Zero = ConstantInt::get(IntptrTy, 0); Index: llvm/lib/Transforms/Instrumentation/MemProfiler.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/MemProfiler.cpp +++ llvm/lib/Transforms/Instrumentation/MemProfiler.cpp @@ -384,7 +384,7 @@ } auto *BasePtr = CI->getOperand(0 + OpOffset); - auto *Ty = cast(BasePtr->getType())->getElementType(); + auto *Ty = BasePtr->getType()->getPointerElementType(); Access.TypeSize = DL.getTypeStoreSizeInBits(Ty); if (auto *AlignmentConstant = dyn_cast(CI->getOperand(1 + OpOffset))) @@ -419,8 +419,7 @@ Instruction *I, Value *Addr, unsigned Alignment, uint32_t TypeSize, bool IsWrite) { - auto *VTy = cast( - cast(Addr->getType())->getElementType()); + auto *VTy = cast(Addr->getType()->getPointerElementType()); uint64_t ElemTypeSize = DL.getTypeStoreSizeInBits(VTy->getScalarType()); unsigned Num = VTy->getNumElements(); auto *Zero = ConstantInt::get(IntptrTy, 0); Index: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -918,7 +918,7 @@ void ModuleSanitizerCoverage::InjectTraceForLoadsAndStores( Function &, ArrayRef Loads, ArrayRef Stores) { auto CallbackIdx = [&](const Value *Ptr) -> int { - auto ElementTy = cast(Ptr->getType())->getElementType(); + auto *ElementTy = Ptr->getType()->getPointerElementType(); uint64_t TypeSize = DL->getTypeStoreSizeInBits(ElementTy); return TypeSize == 8 ? 0 : TypeSize == 16 ? 1 Index: llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp =================================================================== --- llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -980,7 +980,7 @@ if (IsNullOrUndef(CI->getArgOperand(0))) { Changed = true; Type *Ty = CI->getArgOperand(0)->getType(); - new StoreInst(UndefValue::get(cast(Ty)->getElementType()), + new StoreInst(UndefValue::get(Ty->getPointerElementType()), Constant::getNullValue(Ty), CI); Value *NewValue = UndefValue::get(CI->getType()); LLVM_DEBUG( @@ -1000,7 +1000,7 @@ IsNullOrUndef(CI->getArgOperand(1))) { Changed = true; Type *Ty = CI->getArgOperand(0)->getType(); - new StoreInst(UndefValue::get(cast(Ty)->getElementType()), + new StoreInst(UndefValue::get(Ty->getPointerElementType()), Constant::getNullValue(Ty), CI); Value *NewValue = UndefValue::get(CI->getType()); Index: llvm/lib/Transforms/Scalar/SROA.cpp =================================================================== --- llvm/lib/Transforms/Scalar/SROA.cpp +++ llvm/lib/Transforms/Scalar/SROA.cpp @@ -1513,7 +1513,7 @@ if (Ty == IRB.getInt8PtrTy(Ty->getAddressSpace()) && TargetTy->isIntegerTy(8)) return nullptr; - Type *ElementTy = Ty->getElementType(); + Type *ElementTy = Ty->getNonOpaquePointerElementType(); if (!ElementTy->isSized()) return nullptr; // We can't GEP through an unsized element. @@ -1572,7 +1572,7 @@ APInt Int8PtrOffset(Offset.getBitWidth(), 0); PointerType *TargetPtrTy = cast(PointerTy); - Type *TargetTy = TargetPtrTy->getElementType(); + Type *TargetTy = TargetPtrTy->getNonOpaquePointerElementType(); // As `addrspacecast` is , `Ptr` (the storage pointer) may have different // address space from the expected `PointerTy` (the pointer to be used). Index: llvm/lib/Transforms/Scalar/Scalarizer.cpp =================================================================== --- llvm/lib/Transforms/Scalar/Scalarizer.cpp +++ llvm/lib/Transforms/Scalar/Scalarizer.cpp @@ -270,7 +270,7 @@ Type *Ty = V->getType(); PtrTy = dyn_cast(Ty); if (PtrTy) - Ty = PtrTy->getElementType(); + Ty = PtrTy->getPointerElementType(); Size = cast(Ty)->getNumElements(); if (!CachePtr) Tmp.resize(Size, nullptr); @@ -288,7 +288,8 @@ return CV[I]; IRBuilder<> Builder(BB, BBI); if (PtrTy) { - Type *ElTy = cast(PtrTy->getElementType())->getElementType(); + Type *ElTy = + cast(PtrTy->getPointerElementType())->getElementType(); if (!CV[0]) { Type *NewPtrTy = PointerType::get(ElTy, PtrTy->getAddressSpace()); CV[0] = Builder.CreateBitCast(V, NewPtrTy, V->getName() + ".i0"); Index: llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp =================================================================== --- llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp +++ llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp @@ -28,7 +28,7 @@ if (!PtrTy) return false; - auto IntTy = dyn_cast(PtrTy->getElementType()); + auto IntTy = dyn_cast(PtrTy->getPointerElementType()); if (!IntTy) return false; Index: llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp =================================================================== --- llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp +++ llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp @@ -297,7 +297,7 @@ Function *F = OrigBB->getParent(); const DataLayout &DL = F->getParent()->getDataLayout(); - Type *EltTy = cast(SrcAddr->getType())->getElementType(); + Type *EltTy = SrcAddr->getType()->getPointerElementType(); // Create the a comparison of src and dst, based on which we jump to either // the forward-copy part of the function (if src >= dst) or the backwards-copy Index: llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp =================================================================== --- llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -173,7 +173,7 @@ auto *PtrTy = cast(Ty); if (DL.isNonIntegralPointerType(PtrTy)) { auto *Int8PtrTy = Builder.getInt8PtrTy(PtrTy->getAddressSpace()); - assert(DL.getTypeAllocSize(Int8PtrTy->getElementType()) == 1 && + assert(DL.getTypeAllocSize(Int8PtrTy->getPointerElementType()) == 1 && "alloc size of i8 must by 1 byte for the GEP to be correct"); auto *GEP = Builder.CreateGEP( Builder.getInt8Ty(), Constant::getNullValue(Int8PtrTy), V, "uglygep"); @@ -471,7 +471,7 @@ // indexes into the array implied by the pointer operand; the rest of // the indices index into the element or field type selected by the // preceding index. - Type *ElTy = PTy->getElementType(); + Type *ElTy = PTy->getNonOpaquePointerElementType(); for (;;) { // If the scale size is not 0, attempt to factor out a scale for // array indexing. @@ -640,8 +640,8 @@ Value *Casted = V; if (V->getType() != PTy) Casted = InsertNoopCastOfTo(Casted, PTy); - Value *GEP = Builder.CreateGEP(PTy->getElementType(), Casted, GepIndices, - "scevgep"); + Value *GEP = Builder.CreateGEP( + PTy->getNonOpaquePointerElementType(), Casted, GepIndices, "scevgep"); Ops.push_back(SE.getUnknown(GEP)); } Index: llvm/tools/llvm-stress/llvm-stress.cpp =================================================================== --- llvm/tools/llvm-stress/llvm-stress.cpp +++ llvm/tools/llvm-stress/llvm-stress.cpp @@ -346,8 +346,7 @@ void Act() override { // Try to use predefined pointers. If non-exist, use undef pointer value; Value *Ptr = getRandomPointerValue(); - PointerType *Tp = cast(Ptr->getType()); - Value *V = new LoadInst(Tp->getElementType(), Ptr, "L", + Value *V = new LoadInst(Ptr->getType()->getPointerElementType(), Ptr, "L", BB->getTerminator()); PT->push_back(V); } @@ -360,8 +359,7 @@ void Act() override { // Try to use predefined pointers. If non-exist, use undef pointer value; Value *Ptr = getRandomPointerValue(); - PointerType *Tp = cast(Ptr->getType()); - Value *Val = getRandomValue(Tp->getElementType()); + Value *Val = getRandomValue(Ptr->getType()->getPointerElementType()); Type *ValTy = Val->getType(); // Do not store vectors of i1s because they are unsupported