JOE1994 updated this revision to Diff 531889. JOE1994 added a comment. - Rebase onto latest llvm-project main : 2cd4dc59792578f833b838e3c9a376a4bcafc568 <https://reviews.llvm.org/rG2cd4dc59792578f833b838e3c9a376a4bcafc568>
- Use `llvm::PointerType::getUnqual` whenever possible Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D152321/new/ https://reviews.llvm.org/D152321 Files: clang/lib/CodeGen/CGAtomic.cpp clang/lib/CodeGen/CGBlocks.cpp clang/lib/CodeGen/CGBuilder.h clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGCUDANV.cpp clang/lib/CodeGen/CGCXX.cpp clang/lib/CodeGen/CGCXXABI.cpp clang/lib/CodeGen/CGClass.cpp clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CGDeclCXX.cpp clang/lib/CodeGen/CGException.cpp clang/lib/CodeGen/CGExprCXX.cpp clang/lib/CodeGen/CGExprConstant.cpp clang/lib/CodeGen/CGObjCRuntime.cpp clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/CodeGen/TargetInfo.cpp
Index: clang/lib/CodeGen/TargetInfo.cpp =================================================================== --- clang/lib/CodeGen/TargetInfo.cpp +++ clang/lib/CodeGen/TargetInfo.cpp @@ -402,7 +402,7 @@ llvm::Type *DirectTy = CGF.ConvertTypeForMem(ValueTy), *ElementTy = DirectTy; if (IsIndirect) { unsigned AllocaAS = CGF.CGM.getDataLayout().getAllocaAddrSpace(); - DirectTy = DirectTy->getPointerTo(AllocaAS); + DirectTy = llvm::PointerType::get(CGF.getLLVMContext(), AllocaAS); } Address Addr = emitVoidPtrDirectVAArg(CGF, VAListAddr, DirectTy, DirectSize, @@ -2054,7 +2054,7 @@ Info = ABIArgInfo::getInAlloca(FrameFields.size(), IsIndirect); llvm::Type *LLTy = CGT.ConvertTypeForMem(Type); if (IsIndirect) - LLTy = LLTy->getPointerTo(0); + LLTy = llvm::PointerType::getUnqual(getVMContext()); FrameFields.push_back(LLTy); StackOffset += IsIndirect ? WordSize : getContext().getTypeSizeInChars(Type); @@ -4863,7 +4863,8 @@ Builder.CreateCondBr(CC, UsingRegs, UsingOverflow); llvm::Type *DirectTy = CGF.ConvertType(Ty), *ElementTy = DirectTy; - if (isIndirect) DirectTy = DirectTy->getPointerTo(0); + if (isIndirect) + DirectTy = llvm::PointerType::getUnqual(CGF.getLLVMContext()); // Case 1: consume registers. Address RegAddr = Address::invalid(); Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -584,9 +584,6 @@ auto *RD = cast<CXXRecordDecl>(MPT->getClass()->castAs<RecordType>()->getDecl()); - llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType( - CGM.getTypes().arrangeCXXMethodType(RD, FPT, /*FD=*/nullptr)); - llvm::Constant *ptrdiff_1 = llvm::ConstantInt::get(CGM.PtrDiffTy, 1); llvm::BasicBlock *FnVirtual = CGF.createBasicBlock("memptr.virtual"); @@ -687,8 +684,6 @@ {VFPAddr, llvm::ConstantInt::get(CGM.Int32Ty, 0), TypeId}); CheckResult = Builder.CreateExtractValue(CheckedLoad, 1); VirtualFn = Builder.CreateExtractValue(CheckedLoad, 0); - VirtualFn = Builder.CreateBitCast(VirtualFn, FTy->getPointerTo(), - "memptr.virtualfn"); } else { // When not doing VFE, emit a normal load, as it allows more // optimisations than type.checked.load. @@ -709,15 +704,12 @@ CGM.getIntrinsic(llvm::Intrinsic::load_relative, {VTableOffset->getType()}), {VTable, VTableOffset}); - VirtualFn = CGF.Builder.CreateBitCast(VirtualFn, FTy->getPointerTo()); } else { llvm::Value *VFPAddr = CGF.Builder.CreateGEP(CGF.Int8Ty, VTable, VTableOffset); - VFPAddr = CGF.Builder.CreateBitCast( - VFPAddr, FTy->getPointerTo()->getPointerTo()); VirtualFn = CGF.Builder.CreateAlignedLoad( - FTy->getPointerTo(), VFPAddr, CGF.getPointerAlign(), - "memptr.virtualfn"); + llvm::PointerType::getUnqual(CGF.getLLVMContext()), VFPAddr, + CGF.getPointerAlign(), "memptr.virtualfn"); } } assert(VirtualFn && "Virtual fuction pointer not created!"); @@ -757,8 +749,9 @@ // In the non-virtual path, the function pointer is actually a // function pointer. CGF.EmitBlock(FnNonVirtual); - llvm::Value *NonVirtualFn = - Builder.CreateIntToPtr(FnAsInt, FTy->getPointerTo(), "memptr.nonvirtualfn"); + llvm::Value *NonVirtualFn = Builder.CreateIntToPtr( + FnAsInt, llvm::PointerType::getUnqual(CGF.getLLVMContext()), + "memptr.nonvirtualfn"); // Check the function pointer if CFI on member function pointers is enabled. if (ShouldEmitCFICheck) { @@ -799,7 +792,8 @@ // We're done. CGF.EmitBlock(FnEnd); - llvm::PHINode *CalleePtr = Builder.CreatePHI(FTy->getPointerTo(), 2); + llvm::PHINode *CalleePtr = + Builder.CreatePHI(llvm::PointerType::getUnqual(CGF.getLLVMContext()), 2); CalleePtr->addIncoming(VirtualFn, FnVirtual); CalleePtr->addIncoming(NonVirtualFn, FnNonVirtual); @@ -820,14 +814,8 @@ Base = Builder.CreateElementBitCast(Base, CGF.Int8Ty); // Apply the offset, which we assume is non-null. - llvm::Value *Addr = Builder.CreateInBoundsGEP( - Base.getElementType(), Base.getPointer(), MemPtr, "memptr.offset"); - - // Cast the address to the appropriate pointer type, adopting the - // address space of the base pointer. - llvm::Type *PType = CGF.ConvertTypeForMem(MPT->getPointeeType()) - ->getPointerTo(Base.getAddressSpace()); - return Builder.CreateBitCast(Addr, PType); + return Builder.CreateInBoundsGEP(Base.getElementType(), Base.getPointer(), + MemPtr, "memptr.offset"); } /// Perform a bitcast, derived-to-base, or base-to-derived member pointer @@ -1212,8 +1200,8 @@ // Grab the vtable pointer as an intptr_t*. auto *ClassDecl = cast<CXXRecordDecl>(ElementType->castAs<RecordType>()->getDecl()); - llvm::Value *VTable = - CGF.GetVTablePtr(Ptr, CGF.IntPtrTy->getPointerTo(), ClassDecl); + llvm::Value *VTable = CGF.GetVTablePtr( + Ptr, llvm::PointerType::getUnqual(CGF.getLLVMContext()), ClassDecl); // Track back to entry -2 and pull out the offset there. llvm::Value *OffsetPtr = CGF.Builder.CreateConstInBoundsGEP1_64( @@ -1417,8 +1405,8 @@ llvm::Type *StdTypeInfoPtrTy) { auto *ClassDecl = cast<CXXRecordDecl>(SrcRecordTy->castAs<RecordType>()->getDecl()); - llvm::Value *Value = - CGF.GetVTablePtr(ThisPtr, StdTypeInfoPtrTy->getPointerTo(), ClassDecl); + llvm::Value *Value = CGF.GetVTablePtr( + ThisPtr, llvm::PointerType::getUnqual(CGF.getLLVMContext()), ClassDecl); if (CGM.getItaniumVTableContext().isRelativeLayout()) { // Load the type info. @@ -1426,9 +1414,6 @@ Value = CGF.Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::load_relative, {CGM.Int32Ty}), {Value, llvm::ConstantInt::get(CGM.Int32Ty, -4)}); - - // Setup to dereference again since this is a proxy we accessed. - Value = CGF.Builder.CreateBitCast(Value, StdTypeInfoPtrTy->getPointerTo()); } else { // Load the type info. Value = @@ -1496,8 +1481,9 @@ llvm::Value *OffsetToTop; if (CGM.getItaniumVTableContext().isRelativeLayout()) { // Get the vtable pointer. - llvm::Value *VTable = - CGF.GetVTablePtr(ThisAddr, CGM.Int32Ty->getPointerTo(), ClassDecl); + llvm::Value *VTable = CGF.GetVTablePtr( + ThisAddr, llvm::PointerType::getUnqual(CGF.getLLVMContext()), + ClassDecl); // Get the offset-to-top from the vtable. OffsetToTop = @@ -1509,8 +1495,9 @@ CGF.ConvertType(CGF.getContext().getPointerDiffType()); // Get the vtable pointer. - llvm::Value *VTable = - CGF.GetVTablePtr(ThisAddr, PtrDiffLTy->getPointerTo(), ClassDecl); + llvm::Value *VTable = CGF.GetVTablePtr( + ThisAddr, llvm::PointerType::getUnqual(CGF.getLLVMContext()), + ClassDecl); // Get the offset-to-top from the vtable. OffsetToTop = @@ -1549,14 +1536,10 @@ llvm::Value *VBaseOffset; if (CGM.getItaniumVTableContext().isRelativeLayout()) { - VBaseOffsetPtr = - CGF.Builder.CreateBitCast(VBaseOffsetPtr, CGF.Int32Ty->getPointerTo()); VBaseOffset = CGF.Builder.CreateAlignedLoad( CGF.Int32Ty, VBaseOffsetPtr, CharUnits::fromQuantity(4), "vbase.offset"); } else { - VBaseOffsetPtr = CGF.Builder.CreateBitCast(VBaseOffsetPtr, - CGM.PtrDiffTy->getPointerTo()); VBaseOffset = CGF.Builder.CreateAlignedLoad( CGM.PtrDiffTy, VBaseOffsetPtr, CGF.getPointerAlign(), "vbase.offset"); } @@ -1922,16 +1905,15 @@ Address This, llvm::Type *Ty, SourceLocation Loc) { - llvm::Type *TyPtr = Ty->getPointerTo(); + llvm::Type *PtrTy = llvm::PointerType::getUnqual(CGF.getLLVMContext()); auto *MethodDecl = cast<CXXMethodDecl>(GD.getDecl()); - llvm::Value *VTable = CGF.GetVTablePtr( - This, TyPtr->getPointerTo(), MethodDecl->getParent()); + llvm::Value *VTable = CGF.GetVTablePtr(This, PtrTy, MethodDecl->getParent()); uint64_t VTableIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(GD); llvm::Value *VFunc; if (CGF.ShouldEmitVTableTypeCheckedLoad(MethodDecl->getParent())) { VFunc = CGF.EmitVTableTypeCheckedLoad( - MethodDecl->getParent(), VTable, TyPtr, + MethodDecl->getParent(), VTable, PtrTy, VTableIndex * CGM.getContext().getTargetInfo().getPointerWidth(LangAS::Default) / 8); @@ -1940,19 +1922,14 @@ llvm::Value *VFuncLoad; if (CGM.getItaniumVTableContext().isRelativeLayout()) { - VTable = CGF.Builder.CreateBitCast(VTable, CGM.Int8PtrTy); - llvm::Value *Load = CGF.Builder.CreateCall( + VFuncLoad = CGF.Builder.CreateCall( CGM.getIntrinsic(llvm::Intrinsic::load_relative, {CGM.Int32Ty}), {VTable, llvm::ConstantInt::get(CGM.Int32Ty, 4 * VTableIndex)}); - VFuncLoad = CGF.Builder.CreateBitCast(Load, TyPtr); } else { - VTable = - CGF.Builder.CreateBitCast(VTable, TyPtr->getPointerTo()); llvm::Value *VTableSlotPtr = CGF.Builder.CreateConstInBoundsGEP1_64( - TyPtr, VTable, VTableIndex, "vfn"); - VFuncLoad = - CGF.Builder.CreateAlignedLoad(TyPtr, VTableSlotPtr, - CGF.getPointerAlign()); + PtrTy, VTable, VTableIndex, "vfn"); + VFuncLoad = CGF.Builder.CreateAlignedLoad(PtrTy, VTableSlotPtr, + CGF.getPointerAlign()); } // Add !invariant.load md to virtual function load to indicate that @@ -2094,8 +2071,6 @@ CGF.Int8Ty, VTablePtr, VirtualAdjustment); if (CGF.CGM.getItaniumVTableContext().isRelativeLayout()) { // Load the adjustment offset from the vtable as a 32-bit int. - OffsetPtr = - CGF.Builder.CreateBitCast(OffsetPtr, CGF.Int32Ty->getPointerTo()); Offset = CGF.Builder.CreateAlignedLoad(CGF.Int32Ty, OffsetPtr, CharUnits::fromQuantity(4)); @@ -2103,9 +2078,6 @@ llvm::Type *PtrDiffTy = CGF.ConvertType(CGF.getContext().getPointerDiffType()); - OffsetPtr = - CGF.Builder.CreateBitCast(OffsetPtr, PtrDiffTy->getPointerTo()); - // Load the adjustment offset from the vtable. Offset = CGF.Builder.CreateAlignedLoad(PtrDiffTy, OffsetPtr, CGF.getPointerAlign()); @@ -2229,8 +2201,8 @@ // cookie, otherwise return 0 to avoid an infinite loop calling DTORs. // We can't simply ignore this load using nosanitize metadata because // the metadata may be lost. - llvm::FunctionType *FTy = - llvm::FunctionType::get(CGF.SizeTy, CGF.SizeTy->getPointerTo(0), false); + llvm::FunctionType *FTy = llvm::FunctionType::get( + CGF.SizeTy, llvm::PointerType::getUnqual(CGF.getLLVMContext()), false); llvm::FunctionCallee F = CGM.CreateRuntimeFunction(FTy, "__asan_load_cxx_array_cookie"); return CGF.Builder.CreateCall(F, numElementsPtr.getPointer()); @@ -2380,7 +2352,8 @@ CharUnits::fromQuantity(CGM.getDataLayout().getABITypeAlign(guardTy)); } } - llvm::PointerType *guardPtrTy = guardTy->getPointerTo( + llvm::PointerType *guardPtrTy = llvm::PointerType::get( + CGF.CGM.getLLVMContext(), CGF.CGM.getDataLayout().getDefaultGlobalsAddressSpace()); // Create the guard variable if we don't already have it (as we @@ -2571,15 +2544,11 @@ } // We're assuming that the destructor function is something we can - // reasonably call with the default CC. Go ahead and cast it to the - // right prototype. - llvm::Type *dtorTy = - llvm::FunctionType::get(CGF.VoidTy, CGF.Int8PtrTy, false)->getPointerTo(); + // reasonably call with the default CC. + llvm::Type *dtorTy = llvm::PointerType::getUnqual(CGF.getLLVMContext()); // Preserve address space of addr. - auto AddrAS = addr ? addr->getType()->getPointerAddressSpace() : 0; - auto AddrInt8PtrTy = - AddrAS ? CGF.Int8Ty->getPointerTo(AddrAS) : CGF.Int8PtrTy; + auto AddrPtrTy = addr->getType(); // Create a variable that binds the atexit to this shared object. llvm::Constant *handle = @@ -2588,7 +2557,7 @@ GV->setVisibility(llvm::GlobalValue::HiddenVisibility); // extern "C" int __cxa_atexit(void (*f)(void *), void *p, void *d); - llvm::Type *paramTys[] = {dtorTy, AddrInt8PtrTy, handle->getType()}; + llvm::Type *paramTys[] = {dtorTy, AddrPtrTy, handle->getType()}; llvm::FunctionType *atexitTy = llvm::FunctionType::get(CGF.IntTy, paramTys, false); @@ -2604,10 +2573,7 @@ // function. addr = llvm::Constant::getNullValue(CGF.Int8PtrTy); - llvm::Value *args[] = {llvm::ConstantExpr::getBitCast( - cast<llvm::Constant>(dtor.getCallee()), dtorTy), - llvm::ConstantExpr::getBitCast(addr, AddrInt8PtrTy), - handle}; + llvm::Value *args[] = {dtor.getCallee(), addr, handle}; CGF.EmitNounwindRuntimeCall(atexit, args); } @@ -2639,7 +2605,6 @@ // Get the destructor function type, void(*)(void). llvm::FunctionType *dtorFuncTy = llvm::FunctionType::get(CGF.VoidTy, false); - llvm::Type *dtorTy = dtorFuncTy->getPointerTo(); // Destructor functions are run/unregistered in non-ascending // order of their priorities. @@ -2649,10 +2614,8 @@ llvm::Function *Dtor = *itv; // We're assuming that the destructor function is something we can - // reasonably call with the correct CC. Go ahead and cast it to the - // right prototype. - llvm::Constant *dtor = llvm::ConstantExpr::getBitCast(Dtor, dtorTy); - llvm::Value *V = CGF.unregisterGlobalDtorWithUnAtExit(dtor); + // reasonably call with the correct CC. + llvm::Value *V = CGF.unregisterGlobalDtorWithUnAtExit(Dtor); llvm::Value *NeedsDestruct = CGF.Builder.CreateIsNull(V, "needs_destruct"); @@ -2667,7 +2630,7 @@ CGF.EmitBlock(DestructCallBlock); // Emit the call to casted Dtor. - llvm::CallInst *CI = CGF.Builder.CreateCall(dtorFuncTy, dtor); + llvm::CallInst *CI = CGF.Builder.CreateCall(dtorFuncTy, Dtor); // Make sure the call and the callee agree on calling convention. CI->setCallingConv(Dtor->getCallingConv()); @@ -2707,15 +2670,9 @@ if (getCodeGenOpts().CXAAtExit) { emitGlobalDtorWithCXAAtExit(CGF, Dtor, nullptr, false); } else { - // Get the destructor function type, void(*)(void). - llvm::Type *dtorTy = - llvm::FunctionType::get(CGF.VoidTy, false)->getPointerTo(); - // We're assuming that the destructor function is something we can - // reasonably call with the correct CC. Go ahead and cast it to the - // right prototype. - CGF.registerGlobalDtorWithAtExit( - llvm::ConstantExpr::getBitCast(Dtor, dtorTy)); + // reasonably call with the correct CC. + CGF.registerGlobalDtorWithAtExit(Dtor); } } @@ -4567,10 +4524,7 @@ // Otherwise, it returns a pointer into the exception object. - llvm::Type *PtrTy = LLVMCatchTy->getPointerTo(0); // addrspace 0 ok - llvm::Value *Cast = CGF.Builder.CreateBitCast(AdjustedExn, PtrTy); - - LValue srcLV = CGF.MakeNaturalAlignAddrLValue(Cast, CatchType); + LValue srcLV = CGF.MakeNaturalAlignAddrLValue(AdjustedExn, CatchType); LValue destLV = CGF.MakeAddrLValue(ParamAddr, CatchType); switch (TEK) { case TEK_Complex: @@ -4592,7 +4546,8 @@ auto catchRD = CatchType->getAsCXXRecordDecl(); CharUnits caughtExnAlignment = CGF.CGM.getClassPointerAlignment(catchRD); - llvm::Type *PtrTy = LLVMCatchTy->getPointerTo(0); // addrspace 0 ok + llvm::Type *PtrTy = + llvm::PointerType::getUnqual(CGF.getLLVMContext()); // addrspace 0 ok // Check for a copy expression. If we don't have a copy expression, // that means a trivial copy is okay. @@ -4780,14 +4735,12 @@ llvm::FunctionCallee Dtor, llvm::Constant *Addr) { if (D.getTLSKind() != VarDecl::TLS_None) { - // atexit routine expects "int(*)(int,...)" - llvm::FunctionType *FTy = - llvm::FunctionType::get(CGM.IntTy, CGM.IntTy, true); - llvm::PointerType *FpTy = FTy->getPointerTo(); + llvm::PointerType *PtrTy = + llvm::PointerType::getUnqual(CGF.getLLVMContext()); // extern "C" int __pt_atexit_np(int flags, int(*)(int,...), ...); llvm::FunctionType *AtExitTy = - llvm::FunctionType::get(CGM.IntTy, {CGM.IntTy, FpTy}, true); + llvm::FunctionType::get(CGM.IntTy, {CGM.IntTy, PtrTy}, true); // Fetch the actual function. llvm::FunctionCallee AtExit = Index: clang/lib/CodeGen/CGObjCRuntime.cpp =================================================================== --- clang/lib/CodeGen/CGObjCRuntime.cpp +++ clang/lib/CodeGen/CGObjCRuntime.cpp @@ -364,14 +364,14 @@ CallArgList &callArgs) { unsigned ProgramAS = CGM.getDataLayout().getProgramAddressSpace(); + llvm::PointerType *signatureType = + llvm::PointerType::get(CGM.getLLVMContext(), ProgramAS); + // If there's a method, use information from that. if (method) { const CGFunctionInfo &signature = CGM.getTypes().arrangeObjCMessageSendSignature(method, callArgs[0].Ty); - llvm::PointerType *signatureType = - CGM.getTypes().GetFunctionType(signature)->getPointerTo(ProgramAS); - const CGFunctionInfo &signatureForCall = CGM.getTypes().arrangeCall(signature, callArgs); @@ -382,9 +382,6 @@ const CGFunctionInfo &argsInfo = CGM.getTypes().arrangeUnprototypedObjCMessageSend(resultType, callArgs); - // Derive the signature to call from that. - llvm::PointerType *signatureType = - CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo(ProgramAS); return MessageSendInfo(argsInfo, signatureType); } Index: clang/lib/CodeGen/CGExprConstant.cpp =================================================================== --- clang/lib/CodeGen/CGExprConstant.cpp +++ clang/lib/CodeGen/CGExprConstant.cpp @@ -1833,9 +1833,6 @@ return C; llvm::Type *origPtrTy = C->getType(); - unsigned AS = origPtrTy->getPointerAddressSpace(); - llvm::Type *charPtrTy = CGM.Int8Ty->getPointerTo(AS); - C = llvm::ConstantExpr::getBitCast(C, charPtrTy); C = llvm::ConstantExpr::getGetElementPtr(CGM.Int8Ty, C, getOffset()); C = llvm::ConstantExpr::getPointerCast(C, origPtrTy); return C; @@ -1945,15 +1942,8 @@ } // Handle typeid(T). - if (TypeInfoLValue TI = base.dyn_cast<TypeInfoLValue>()) { - llvm::Type *StdTypeInfoPtrTy = - CGM.getTypes().ConvertType(base.getTypeInfoType())->getPointerTo(); - llvm::Constant *TypeInfo = - CGM.GetAddrOfRTTIDescriptor(QualType(TI.getType(), 0)); - if (TypeInfo->getType() != StdTypeInfoPtrTy) - TypeInfo = llvm::ConstantExpr::getBitCast(TypeInfo, StdTypeInfoPtrTy); - return TypeInfo; - } + if (TypeInfoLValue TI = base.dyn_cast<TypeInfoLValue>()) + return CGM.GetAddrOfRTTIDescriptor(QualType(TI.getType(), 0)); // Otherwise, it must be an expression. return Visit(base.get<const Expr*>()); Index: clang/lib/CodeGen/CGExprCXX.cpp =================================================================== --- clang/lib/CodeGen/CGExprCXX.cpp +++ clang/lib/CodeGen/CGExprCXX.cpp @@ -2195,13 +2195,12 @@ } llvm::Value *CodeGenFunction::EmitCXXTypeidExpr(const CXXTypeidExpr *E) { - llvm::Type *StdTypeInfoPtrTy = - ConvertType(E->getType())->getPointerTo(); + llvm::Type *PtrTy = llvm::PointerType::getUnqual(getLLVMContext()); if (E->isTypeOperand()) { llvm::Constant *TypeInfo = CGM.GetAddrOfRTTIDescriptor(E->getTypeOperand(getContext())); - return Builder.CreateBitCast(TypeInfo, StdTypeInfoPtrTy); + return TypeInfo; } // C++ [expr.typeid]p2: @@ -2211,12 +2210,10 @@ // type) to which the glvalue refers. // If the operand is already most derived object, no need to look up vtable. if (E->isPotentiallyEvaluated() && !E->isMostDerived(getContext())) - return EmitTypeidFromVTable(*this, E->getExprOperand(), - StdTypeInfoPtrTy); + return EmitTypeidFromVTable(*this, E->getExprOperand(), PtrTy); QualType OperandTy = E->getExprOperand()->getType(); - return Builder.CreateBitCast(CGM.GetAddrOfRTTIDescriptor(OperandTy), - StdTypeInfoPtrTy); + return CGM.GetAddrOfRTTIDescriptor(OperandTy); } static llvm::Value *EmitDynamicCastToNull(CodeGenFunction &CGF, Index: clang/lib/CodeGen/CGException.cpp =================================================================== --- clang/lib/CodeGen/CGException.cpp +++ clang/lib/CodeGen/CGException.cpp @@ -2101,7 +2101,6 @@ // pointer is stored in the second field. So, GEP 20 bytes backwards and // load the pointer. SEHInfo = Builder.CreateConstInBoundsGEP1_32(Int8Ty, EntryFP, -20); - SEHInfo = Builder.CreateBitCast(SEHInfo, Int8PtrTy->getPointerTo()); SEHInfo = Builder.CreateAlignedLoad(Int8PtrTy, SEHInfo, getPointerAlign()); SEHCodeSlotStack.push_back(recoverAddrOfEscapedLocal( ParentCGF, ParentCGF.SEHCodeSlotStack.back(), ParentFP)); @@ -2114,10 +2113,9 @@ // CONTEXT *ContextRecord; // }; // int exceptioncode = exception_pointers->ExceptionRecord->ExceptionCode; - llvm::Type *RecordTy = CGM.Int32Ty->getPointerTo(); + llvm::Type *RecordTy = llvm::PointerType::getUnqual(getLLVMContext()); llvm::Type *PtrsTy = llvm::StructType::get(RecordTy, CGM.VoidPtrTy); - llvm::Value *Ptrs = Builder.CreateBitCast(SEHInfo, PtrsTy->getPointerTo()); - llvm::Value *Rec = Builder.CreateStructGEP(PtrsTy, Ptrs, 0); + llvm::Value *Rec = Builder.CreateStructGEP(PtrsTy, SEHInfo, 0); Rec = Builder.CreateAlignedLoad(RecordTy, Rec, getPointerAlign()); llvm::Value *Code = Builder.CreateAlignedLoad(Int32Ty, Rec, getIntAlign()); assert(!SEHCodeSlotStack.empty() && "emitting EH code outside of __except"); Index: clang/lib/CodeGen/CGDeclCXX.cpp =================================================================== --- clang/lib/CodeGen/CGDeclCXX.cpp +++ clang/lib/CodeGen/CGDeclCXX.cpp @@ -122,8 +122,8 @@ if (CGF.getContext().getLangOpts().OpenCL) { auto DestAS = CGM.getTargetCodeGenInfo().getAddrSpaceOfCxaAtexitPtrParam(); - auto DestTy = CGF.getTypes().ConvertType(Type)->getPointerTo( - CGM.getContext().getTargetAddressSpace(DestAS)); + auto DestTy = llvm::PointerType::get( + CGM.getLLVMContext(), CGM.getContext().getTargetAddressSpace(DestAS)); auto SrcAS = D.getType().getQualifiers().getAddressSpace(); if (DestAS == SrcAS) Argument = llvm::ConstantExpr::getBitCast(Addr.getPointer(), DestTy); @@ -132,8 +132,7 @@ // of the global destructor function should be adjusted accordingly. Argument = llvm::ConstantPointerNull::get(DestTy); } else { - Argument = llvm::ConstantExpr::getBitCast( - Addr.getPointer(), CGF.getTypes().ConvertType(Type)->getPointerTo()); + Argument = Addr.getPointer(); } // Otherwise, the standard logic requires a helper function. } else { Index: clang/lib/CodeGen/CGDecl.cpp =================================================================== --- clang/lib/CodeGen/CGDecl.cpp +++ clang/lib/CodeGen/CGDecl.cpp @@ -292,7 +292,8 @@ if (AS != ExpectedAS) { Addr = getTargetCodeGenInfo().performAddrSpaceCast( *this, GV, AS, ExpectedAS, - LTy->getPointerTo(getContext().getTargetAddressSpace(ExpectedAS))); + llvm::PointerType::get(getLLVMContext(), + getContext().getTargetAddressSpace(ExpectedAS))); } setStaticLocalDeclAddress(&D, Addr); @@ -2510,7 +2511,7 @@ assert(getContext().getTargetAddressSpace(SrcLangAS) == CGM.getDataLayout().getAllocaAddrSpace()); auto DestAS = getContext().getTargetAddressSpace(DestLangAS); - auto *T = DeclPtr.getElementType()->getPointerTo(DestAS); + auto *T = llvm::PointerType::get(getLLVMContext(), DestAS); DeclPtr = DeclPtr.withPointer(getTargetHooks().performAddrSpaceCast( *this, V, SrcLangAS, DestLangAS, T, true), Index: clang/lib/CodeGen/CGClass.cpp =================================================================== --- clang/lib/CodeGen/CGClass.cpp +++ clang/lib/CodeGen/CGClass.cpp @@ -272,8 +272,6 @@ // Apply the base offset. llvm::Value *ptr = addr.getPointer(); - unsigned AddrSpace = ptr->getType()->getPointerAddressSpace(); - ptr = CGF.Builder.CreateBitCast(ptr, CGF.Int8Ty->getPointerTo(AddrSpace)); ptr = CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, ptr, baseOffset, "add.ptr"); // If we have a virtual component, the alignment of the result will @@ -329,8 +327,8 @@ // Get the base pointer type. llvm::Type *BaseValueTy = ConvertType((PathEnd[-1])->getType()); - llvm::Type *BasePtrTy = - BaseValueTy->getPointerTo(Value.getType()->getPointerAddressSpace()); + llvm::Type *PtrTy = llvm::PointerType::get( + CGM.getLLVMContext(), Value.getType()->getPointerAddressSpace()); QualType DerivedTy = getContext().getRecordType(Derived); CharUnits DerivedAlign = CGM.getClassPointerAlignment(Derived); @@ -389,9 +387,9 @@ Builder.CreateBr(endBB); EmitBlock(endBB); - llvm::PHINode *PHI = Builder.CreatePHI(BasePtrTy, 2, "cast.result"); + llvm::PHINode *PHI = Builder.CreatePHI(PtrTy, 2, "cast.result"); PHI->addIncoming(Value.getPointer(), notNullBB); - PHI->addIncoming(llvm::Constant::getNullValue(BasePtrTy), origBB); + PHI->addIncoming(llvm::Constant::getNullValue(PtrTy), origBB); Value = Value.withPointer(PHI, NotKnownNonNull); } @@ -410,7 +408,8 @@ getContext().getCanonicalType(getContext().getTagDeclType(Derived)); unsigned AddrSpace = BaseAddr.getAddressSpace(); llvm::Type *DerivedValueTy = ConvertType(DerivedTy); - llvm::Type *DerivedPtrTy = DerivedValueTy->getPointerTo(AddrSpace); + llvm::Type *DerivedPtrTy = + llvm::PointerType::get(getLLVMContext(), AddrSpace); llvm::Value *NonVirtualOffset = CGM.GetNonVirtualBaseClassOffset(Derived, PathBegin, PathEnd); @@ -2579,18 +2578,13 @@ // Finally, store the address point. Use the same LLVM types as the field to // support optimization. unsigned GlobalsAS = CGM.getDataLayout().getDefaultGlobalsAddressSpace(); - unsigned ProgAS = CGM.getDataLayout().getProgramAddressSpace(); - llvm::Type *VTablePtrTy = - llvm::FunctionType::get(CGM.Int32Ty, /*isVarArg=*/true) - ->getPointerTo(ProgAS) - ->getPointerTo(GlobalsAS); + llvm::Type *PtrTy = llvm::PointerType::get(CGM.getLLVMContext(), GlobalsAS); // vtable field is derived from `this` pointer, therefore they should be in // the same addr space. Note that this might not be LLVM address space 0. - VTableField = Builder.CreateElementBitCast(VTableField, VTablePtrTy); - VTableAddressPoint = Builder.CreateBitCast(VTableAddressPoint, VTablePtrTy); + VTableField = Builder.CreateElementBitCast(VTableField, PtrTy); llvm::StoreInst *Store = Builder.CreateStore(VTableAddressPoint, VTableField); - TBAAAccessInfo TBAAInfo = CGM.getTBAAVTablePtrAccessInfo(VTablePtrTy); + TBAAAccessInfo TBAAInfo = CGM.getTBAAVTablePtrAccessInfo(PtrTy); CGM.DecorateInstructionWithTBAA(Store, TBAAInfo); if (CGM.getCodeGenOpts().OptimizationLevel > 0 && CGM.getCodeGenOpts().StrictVTablePointers) Index: clang/lib/CodeGen/CGCXXABI.cpp =================================================================== --- clang/lib/CodeGen/CGCXXABI.cpp +++ clang/lib/CodeGen/CGCXXABI.cpp @@ -46,11 +46,8 @@ ThisPtrForCall = This.getPointer(); const auto *FPT = MPT->getPointeeType()->castAs<FunctionProtoType>(); - const auto *RD = - cast<CXXRecordDecl>(MPT->getClass()->castAs<RecordType>()->getDecl()); - llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType( - CGM.getTypes().arrangeCXXMethodType(RD, FPT, /*FD=*/nullptr)); - llvm::Constant *FnPtr = llvm::Constant::getNullValue(FTy->getPointerTo()); + llvm::Constant *FnPtr = llvm::Constant::getNullValue( + llvm::PointerType::getUnqual(CGM.getLLVMContext())); return CGCallee::forDirect(FnPtr, FPT); } @@ -59,8 +56,8 @@ Address Base, llvm::Value *MemPtr, const MemberPointerType *MPT) { ErrorUnsupportedABI(CGF, "loads of member pointers"); - llvm::Type *Ty = CGF.ConvertType(MPT->getPointeeType()) - ->getPointerTo(Base.getAddressSpace()); + llvm::Type *Ty = + llvm::PointerType::get(CGF.getLLVMContext(), Base.getAddressSpace()); return llvm::Constant::getNullValue(Ty); } Index: clang/lib/CodeGen/CGCXX.cpp =================================================================== --- clang/lib/CodeGen/CGCXX.cpp +++ clang/lib/CodeGen/CGCXX.cpp @@ -131,17 +131,10 @@ if (Replacements.count(MangledName)) return false; - // Derive the type for the alias. llvm::Type *AliasValueType = getTypes().GetFunctionType(AliasDecl); - llvm::PointerType *AliasType = AliasValueType->getPointerTo(); - // Find the referent. Some aliases might require a bitcast, in - // which case the caller is responsible for ensuring the soundness - // of these semantics. - auto *Ref = cast<llvm::GlobalValue>(GetAddrOfGlobal(TargetDecl)); - llvm::Constant *Aliasee = Ref; - if (Ref->getType() != AliasType) - Aliasee = llvm::ConstantExpr::getBitCast(Ref, AliasType); + // Find the referent. + auto *Aliasee = cast<llvm::GlobalValue>(GetAddrOfGlobal(TargetDecl)); // Instead of creating as alias to a linkonce_odr, replace all of the uses // of the aliasee. @@ -170,7 +163,7 @@ // If we don't have a definition for the destructor yet or the definition is // avaialable_externally, don't emit an alias. We can't emit aliases to // declarations; that's just not how aliases work. - if (Ref->isDeclarationForLinker()) + if (Aliasee->isDeclarationForLinker()) return true; // Don't create an alias to a linker weak symbol. This avoids producing @@ -189,7 +182,8 @@ // Switch any previous uses to the alias. if (Entry) { - assert(Entry->getType() == AliasType && + assert(Entry->getValueType() == AliasValueType && + Entry->getAddressSpace() == Alias->getAddressSpace() && "declaration exists with different type"); Alias->takeName(Entry); Entry->replaceAllUsesWith(Alias); @@ -252,8 +246,7 @@ "No kext in Microsoft ABI"); CodeGenModule &CGM = CGF.CGM; llvm::Value *VTable = CGM.getCXXABI().getAddrOfVTable(RD, CharUnits()); - Ty = Ty->getPointerTo(); - VTable = CGF.Builder.CreateBitCast(VTable, Ty->getPointerTo()); + Ty = llvm::PointerType::getUnqual(CGM.getLLVMContext()); assert(VTable && "BuildVirtualCall = kext vtbl pointer is null"); uint64_t VTableIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(GD); const VTableLayout &VTLayout = CGM.getItaniumVTableContext().getVTableLayout(RD); Index: clang/lib/CodeGen/CGCUDANV.cpp =================================================================== --- clang/lib/CodeGen/CGCUDANV.cpp +++ clang/lib/CodeGen/CGCUDANV.cpp @@ -237,7 +237,7 @@ CharPtrTy = llvm::PointerType::getUnqual(Types.ConvertType(Ctx.CharTy)); VoidPtrTy = cast<llvm::PointerType>(Types.ConvertType(Ctx.VoidPtrTy)); - VoidPtrPtrTy = VoidPtrTy->getPointerTo(); + VoidPtrPtrTy = llvm::PointerType::getUnqual(CGM.getLLVMContext()); } llvm::FunctionCallee CGNVCUDARuntime::getSetupArgumentFn() const { @@ -268,10 +268,8 @@ } llvm::FunctionType *CGNVCUDARuntime::getRegisterLinkedBinaryFnTy() const { - auto *CallbackFnTy = getCallbackFnTy(); - auto *RegisterGlobalsFnTy = getRegisterGlobalsFnTy(); - llvm::Type *Params[] = {RegisterGlobalsFnTy->getPointerTo(), VoidPtrTy, - VoidPtrTy, CallbackFnTy->getPointerTo()}; + llvm::Type *Params[] = {llvm::PointerType::getUnqual(Context), VoidPtrTy, + VoidPtrTy, llvm::PointerType::getUnqual(Context)}; return llvm::FunctionType::get(VoidTy, Params, false); } @@ -537,8 +535,11 @@ // void __cudaRegisterFunction(void **, const char *, char *, const char *, // int, uint3*, uint3*, dim3*, dim3*, int*) llvm::Type *RegisterFuncParams[] = { - VoidPtrPtrTy, CharPtrTy, CharPtrTy, CharPtrTy, IntTy, - VoidPtrTy, VoidPtrTy, VoidPtrTy, VoidPtrTy, IntTy->getPointerTo()}; + VoidPtrPtrTy, CharPtrTy, + CharPtrTy, CharPtrTy, + IntTy, VoidPtrTy, + VoidPtrTy, VoidPtrTy, + VoidPtrTy, llvm::PointerType::getUnqual(Context)}; llvm::FunctionCallee RegisterFunc = CGM.CreateRuntimeFunction( llvm::FunctionType::get(IntTy, RegisterFuncParams, false), addUnderscoredPrefixToName("RegisterFunction")); @@ -561,7 +562,7 @@ NullPtr, NullPtr, NullPtr, - llvm::ConstantPointerNull::get(IntTy->getPointerTo())}; + llvm::ConstantPointerNull::get(llvm::PointerType::getUnqual(Context))}; Builder.CreateCall(RegisterFunc, Args); } Index: clang/lib/CodeGen/CGBuiltin.cpp =================================================================== --- clang/lib/CodeGen/CGBuiltin.cpp +++ clang/lib/CodeGen/CGBuiltin.cpp @@ -219,7 +219,8 @@ llvm::IntegerType *IntType = llvm::IntegerType::get(CGF.getLLVMContext(), CGF.getContext().getTypeSize(T)); - llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); + llvm::Type *IntPtrType = + llvm::PointerType::get(CGF.getLLVMContext(), AddrSpace); llvm::Value *Args[2]; Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); @@ -276,18 +277,15 @@ assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType())); llvm::Value *DestPtr = CheckAtomicAlignment(CGF, E); - unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); - llvm::IntegerType *IntType = - llvm::IntegerType::get(CGF.getLLVMContext(), - CGF.getContext().getTypeSize(T)); - llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); + llvm::IntegerType *IntType = llvm::IntegerType::get( + CGF.getLLVMContext(), CGF.getContext().getTypeSize(T)); llvm::Value *Args[2]; Args[1] = CGF.EmitScalarExpr(E->getArg(1)); llvm::Type *ValueType = Args[1]->getType(); Args[1] = EmitToInt(CGF, Args[1], T, IntType); - Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); + Args[0] = DestPtr; llvm::Value *Result = CGF.Builder.CreateAtomicRMW( Kind, Args[0], Args[1], llvm::AtomicOrdering::SequentiallyConsistent); @@ -318,14 +316,12 @@ bool ReturnBool) { QualType T = ReturnBool ? E->getArg(1)->getType() : E->getType(); llvm::Value *DestPtr = CheckAtomicAlignment(CGF, E); - unsigned AddrSpace = DestPtr->getType()->getPointerAddressSpace(); llvm::IntegerType *IntType = llvm::IntegerType::get( CGF.getLLVMContext(), CGF.getContext().getTypeSize(T)); - llvm::Type *IntPtrType = IntType->getPointerTo(AddrSpace); Value *Args[3]; - Args[0] = CGF.Builder.CreateBitCast(DestPtr, IntPtrType); + Args[0] = DestPtr; Args[1] = CGF.EmitScalarExpr(E->getArg(1)); llvm::Type *ValueType = Args[1]->getType(); Args[1] = EmitToInt(CGF, Args[1], T, IntType); @@ -417,10 +413,8 @@ // Convert to i128 pointers and values. llvm::Type *Int128Ty = llvm::IntegerType::get(CGF.getLLVMContext(), 128); - llvm::Type *Int128PtrTy = Int128Ty->getPointerTo(); - Destination = CGF.Builder.CreateBitCast(Destination, Int128PtrTy); - Address ComparandResult(CGF.Builder.CreateBitCast(ComparandPtr, Int128PtrTy), - Int128Ty, CGF.getContext().toCharUnitsFromBits(128)); + Address ComparandResult(ComparandPtr, Int128Ty, + CGF.getContext().toCharUnitsFromBits(128)); // (((i128)hi) << 64) | ((i128)lo) ExchangeHigh = CGF.Builder.CreateZExt(ExchangeHigh, Int128Ty); @@ -483,7 +477,6 @@ CharUnits LoadSize = CGF.getContext().getTypeSizeInChars(ElTy); llvm::Type *ITy = llvm::IntegerType::get(CGF.getLLVMContext(), LoadSize.getQuantity() * 8); - Ptr = CGF.Builder.CreateBitCast(Ptr, ITy->getPointerTo()); llvm::LoadInst *Load = CGF.Builder.CreateAlignedLoad(ITy, Ptr, LoadSize); Load->setVolatile(true); return Load; @@ -495,9 +488,6 @@ Value *Value = CGF.EmitScalarExpr(E->getArg(1)); QualType ElTy = E->getArg(0)->getType()->getPointeeType(); CharUnits StoreSize = CGF.getContext().getTypeSizeInChars(ElTy); - llvm::Type *ITy = - llvm::IntegerType::get(CGF.getLLVMContext(), StoreSize.getQuantity() * 8); - Ptr = CGF.Builder.CreateBitCast(Ptr, ITy->getPointerTo()); llvm::StoreInst *Store = CGF.Builder.CreateAlignedStore(Value, Ptr, StoreSize); Store->setVolatile(true); @@ -982,9 +972,9 @@ llvm::IntegerType *IntType = llvm::IntegerType::get( CGF.getLLVMContext(), CGF.getContext().getTypeSize(E->getArg(1)->getType())); - llvm::Type *IntPtrType = IntType->getPointerTo(); + llvm::Type *PtrType = llvm::PointerType::getUnqual(CGF.getLLVMContext()); llvm::FunctionType *FTy = - llvm::FunctionType::get(CGF.Int8Ty, {IntPtrType, IntType}, false); + llvm::FunctionType::get(CGF.Int8Ty, {PtrType, IntType}, false); llvm::InlineAsm *IA = llvm::InlineAsm::get(FTy, Asm, Constraints, /*hasSideEffects=*/true); @@ -1123,9 +1113,8 @@ Constraints += MachineClobbers; } - llvm::Type *IntPtrType = RetType->getPointerTo(); - llvm::FunctionType *FTy = - llvm::FunctionType::get(RetType, {IntPtrType}, false); + llvm::Type *PtrType = llvm::PointerType::getUnqual(CGF.getLLVMContext()); + llvm::FunctionType *FTy = llvm::FunctionType::get(RetType, {PtrType}, false); llvm::InlineAsm *IA = llvm::InlineAsm::get(FTy, Asm, Constraints, /*hasSideEffects=*/true); @@ -4090,9 +4079,8 @@ Value *Ptr = CheckAtomicAlignment(*this, E); QualType ElTy = E->getArg(0)->getType()->getPointeeType(); CharUnits StoreSize = getContext().getTypeSizeInChars(ElTy); - llvm::Type *ITy = llvm::IntegerType::get(getLLVMContext(), - StoreSize.getQuantity() * 8); - Ptr = Builder.CreateBitCast(Ptr, ITy->getPointerTo()); + llvm::Type *ITy = + llvm::IntegerType::get(getLLVMContext(), StoreSize.getQuantity() * 8); llvm::StoreInst *Store = Builder.CreateAlignedStore(llvm::Constant::getNullValue(ITy), Ptr, StoreSize); @@ -4147,8 +4135,6 @@ PtrTy->castAs<PointerType>()->getPointeeType().isVolatileQualified(); Value *Ptr = EmitScalarExpr(E->getArg(0)); - unsigned AddrSpace = Ptr->getType()->getPointerAddressSpace(); - Ptr = Builder.CreateBitCast(Ptr, Int8Ty->getPointerTo(AddrSpace)); Value *NewVal = Builder.getInt8(1); Value *Order = EmitScalarExpr(E->getArg(1)); if (isa<llvm::ConstantInt>(Order)) { @@ -4666,13 +4652,10 @@ case Builtin::BI_InterlockedCompareExchangePointer: case Builtin::BI_InterlockedCompareExchangePointer_nf: { llvm::Type *RTy; - llvm::IntegerType *IntType = - IntegerType::get(getLLVMContext(), - getContext().getTypeSize(E->getType())); - llvm::Type *IntPtrType = IntType->getPointerTo(); + llvm::IntegerType *IntType = IntegerType::get( + getLLVMContext(), getContext().getTypeSize(E->getType())); - llvm::Value *Destination = - Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)), IntPtrType); + llvm::Value *Destination = EmitScalarExpr(E->getArg(0)); llvm::Value *Exchange = EmitScalarExpr(E->getArg(1)); RTy = Exchange->getType(); @@ -5118,8 +5101,8 @@ } // Any calls now have event arguments passed. if (NumArgs >= 7) { - llvm::Type *EventTy = ConvertType(getContext().OCLClkEventTy); - llvm::PointerType *EventPtrTy = EventTy->getPointerTo( + llvm::PointerType *PtrTy = llvm::PointerType::get( + CGM.getLLVMContext(), CGM.getContext().getTargetAddressSpace(LangAS::opencl_generic)); llvm::Value *NumEvents = @@ -5131,21 +5114,21 @@ llvm::Value *EventWaitList = nullptr; if (E->getArg(4)->isNullPointerConstant( getContext(), Expr::NPC_ValueDependentIsNotNull)) { - EventWaitList = llvm::ConstantPointerNull::get(EventPtrTy); + EventWaitList = llvm::ConstantPointerNull::get(PtrTy); } else { EventWaitList = E->getArg(4)->getType()->isArrayType() ? EmitArrayToPointerDecay(E->getArg(4)).getPointer() : EmitScalarExpr(E->getArg(4)); // Convert to generic address space. - EventWaitList = Builder.CreatePointerCast(EventWaitList, EventPtrTy); + EventWaitList = Builder.CreatePointerCast(EventWaitList, PtrTy); } llvm::Value *EventRet = nullptr; if (E->getArg(5)->isNullPointerConstant( getContext(), Expr::NPC_ValueDependentIsNotNull)) { - EventRet = llvm::ConstantPointerNull::get(EventPtrTy); + EventRet = llvm::ConstantPointerNull::get(PtrTy); } else { EventRet = - Builder.CreatePointerCast(EmitScalarExpr(E->getArg(5)), EventPtrTy); + Builder.CreatePointerCast(EmitScalarExpr(E->getArg(5)), PtrTy); } auto Info = @@ -5156,8 +5139,8 @@ Builder.CreatePointerCast(Info.BlockArg, GenericVoidPtrTy); std::vector<llvm::Type *> ArgTys = { - QueueTy, Int32Ty, RangeTy, Int32Ty, - EventPtrTy, EventPtrTy, GenericVoidPtrTy, GenericVoidPtrTy}; + QueueTy, Int32Ty, RangeTy, Int32Ty, + PtrTy, PtrTy, GenericVoidPtrTy, GenericVoidPtrTy}; std::vector<llvm::Value *> Args = {Queue, Flags, Range, NumEvents, EventWaitList, EventRet, @@ -5475,8 +5458,8 @@ if (PtrTy->getAddressSpace() != ArgValue->getType()->getPointerAddressSpace()) { ArgValue = Builder.CreateAddrSpaceCast( - ArgValue, - ArgValue->getType()->getPointerTo(PtrTy->getAddressSpace())); + ArgValue, llvm::PointerType::get(getLLVMContext(), + PtrTy->getAddressSpace())); } } @@ -5506,7 +5489,8 @@ if (auto *PtrTy = dyn_cast<llvm::PointerType>(RetTy)) { if (PtrTy->getAddressSpace() != V->getType()->getPointerAddressSpace()) { V = Builder.CreateAddrSpaceCast( - V, V->getType()->getPointerTo(PtrTy->getAddressSpace())); + V, llvm::PointerType::get(getLLVMContext(), + PtrTy->getAddressSpace())); } } @@ -8039,8 +8023,7 @@ llvm::Type *RealResTy = ConvertType(Ty); llvm::Type *IntTy = llvm::IntegerType::get(getLLVMContext(), getContext().getTypeSize(Ty)); - llvm::Type *PtrTy = IntTy->getPointerTo(); - LoadAddr = Builder.CreateBitCast(LoadAddr, PtrTy); + llvm::Type *PtrTy = llvm::PointerType::getUnqual(getLLVMContext()); Function *F = CGM.getIntrinsic( BuiltinID == clang::ARM::BI__builtin_arm_ldaex ? Intrinsic::arm_ldaex @@ -8088,9 +8071,8 @@ Value *StoreAddr = EmitScalarExpr(E->getArg(1)); QualType Ty = E->getArg(0)->getType(); - llvm::Type *StoreTy = llvm::IntegerType::get(getLLVMContext(), - getContext().getTypeSize(Ty)); - StoreAddr = Builder.CreateBitCast(StoreAddr, StoreTy->getPointerTo()); + llvm::Type *StoreTy = + llvm::IntegerType::get(getLLVMContext(), getContext().getTypeSize(Ty)); if (StoreVal->getType()->isPointerTy()) StoreVal = Builder.CreatePtrToInt(StoreVal, Int32Ty); @@ -9365,13 +9347,9 @@ Value *BasePtr = Ops[1]; // Implement the index operand if not omitted. - if (Ops.size() > 3) { - BasePtr = Builder.CreateBitCast(BasePtr, MemoryTy->getPointerTo()); + if (Ops.size() > 3) BasePtr = Builder.CreateGEP(MemoryTy, BasePtr, Ops[2]); - } - // Prefetch intriniscs always expect an i8* - BasePtr = Builder.CreateBitCast(BasePtr, llvm::PointerType::getUnqual(Int8Ty)); Value *PrfOp = Ops.back(); Function *F = CGM.getIntrinsic(BuiltinID, Predicate->getType()); @@ -9393,13 +9371,12 @@ auto MemoryTy = llvm::ScalableVectorType::get(MemEltTy, VectorTy); Value *Predicate = EmitSVEPredicateCast(Ops[0], MemoryTy); - Value *BasePtr = Builder.CreateBitCast(Ops[1], MemoryTy->getPointerTo()); + Value *BasePtr = Ops[1]; // Does the load have an offset? if (Ops.size() > 2) BasePtr = Builder.CreateGEP(MemoryTy, BasePtr, Ops[2]); - BasePtr = Builder.CreateBitCast(BasePtr, MemEltTy->getPointerTo()); Function *F = CGM.getIntrinsic(BuiltinID, MemoryTy); auto *Load = cast<llvm::Instruction>(Builder.CreateCall(F, {Predicate, BasePtr})); @@ -9423,7 +9400,7 @@ auto MemoryTy = llvm::ScalableVectorType::get(MemEltTy, VectorTy); Value *Predicate = EmitSVEPredicateCast(Ops[0], MemoryTy); - Value *BasePtr = Builder.CreateBitCast(Ops[1], MemoryTy->getPointerTo()); + Value *BasePtr = Ops[1]; // Does the store have an offset? if (Ops.size() == 4) @@ -9432,7 +9409,6 @@ // Last value is always the data llvm::Value *Val = Builder.CreateTrunc(Ops.back(), MemoryTy); - BasePtr = Builder.CreateBitCast(BasePtr, MemEltTy->getPointerTo()); Function *F = CGM.getIntrinsic(BuiltinID, MemoryTy); auto *Store = cast<llvm::Instruction>(Builder.CreateCall(F, {Val, Predicate, BasePtr})); @@ -10152,8 +10128,7 @@ llvm::Type *RealResTy = ConvertType(Ty); llvm::Type *IntTy = llvm::IntegerType::get(getLLVMContext(), getContext().getTypeSize(Ty)); - llvm::Type *PtrTy = IntTy->getPointerTo(); - LoadAddr = Builder.CreateBitCast(LoadAddr, PtrTy); + llvm::Type *PtrTy = llvm::PointerType::getUnqual(getLLVMContext()); Function *F = CGM.getIntrinsic(BuiltinID == clang::AArch64::BI__builtin_arm_ldaex @@ -10201,9 +10176,8 @@ Value *StoreAddr = EmitScalarExpr(E->getArg(1)); QualType Ty = E->getArg(0)->getType(); - llvm::Type *StoreTy = llvm::IntegerType::get(getLLVMContext(), - getContext().getTypeSize(Ty)); - StoreAddr = Builder.CreateBitCast(StoreAddr, StoreTy->getPointerTo()); + llvm::Type *StoreTy = + llvm::IntegerType::get(getLLVMContext(), getContext().getTypeSize(Ty)); if (StoreVal->getType()->isPointerTy()) StoreVal = Builder.CreatePtrToInt(StoreVal, Int64Ty); @@ -15971,9 +15945,8 @@ // If the user wants the entire vector, just load the entire vector. if (NumBytes == 16) { - Value *BC = Builder.CreateBitCast(Op0, ResTy->getPointerTo()); Value *LD = - Builder.CreateLoad(Address(BC, ResTy, CharUnits::fromQuantity(1))); + Builder.CreateLoad(Address(Op0, ResTy, CharUnits::fromQuantity(1))); if (!IsLE) return LD; @@ -16026,7 +15999,6 @@ // Storing the whole vector, simply store it on BE and reverse bytes and // store on LE. if (Width == 16) { - Value *BC = Builder.CreateBitCast(Op0, Op2->getType()->getPointerTo()); Value *StVec = Op2; if (IsLE) { SmallVector<int, 16> RevMask; @@ -16035,7 +16007,7 @@ StVec = Builder.CreateShuffleVector(Op2, Op2, RevMask); } return Builder.CreateStore( - StVec, Address(BC, Op2->getType(), CharUnits::fromQuantity(1))); + StVec, Address(Op0, Op2->getType(), CharUnits::fromQuantity(1))); } auto *ConvTy = Int64Ty; unsigned NumElts = 0; @@ -16063,14 +16035,13 @@ Op2, llvm::FixedVectorType::get(ConvTy, NumElts)); Value *Ptr = Builder.CreateGEP(Int8Ty, Op0, ConstantInt::get(Int64Ty, Offset)); - Value *PtrBC = Builder.CreateBitCast(Ptr, ConvTy->getPointerTo()); Value *Elt = Builder.CreateExtractElement(Vec, EltNo); if (IsLE && Width > 1) { Function *F = CGM.getIntrinsic(Intrinsic::bswap, ConvTy); Elt = Builder.CreateCall(F, Elt); } return Builder.CreateStore( - Elt, Address(PtrBC, ConvTy, CharUnits::fromQuantity(1))); + Elt, Address(Ptr, ConvTy, CharUnits::fromQuantity(1))); }; unsigned Stored = 0; unsigned RemainingBytes = NumBytes; @@ -16718,7 +16689,7 @@ Value *Vec = Builder.CreateLoad(Addr); Value *Call = Builder.CreateCall(F, {Vec}); llvm::Type *VTy = llvm::FixedVectorType::get(Int8Ty, 16); - Value *Ptr = Builder.CreateBitCast(Ops[0], VTy->getPointerTo()); + Value *Ptr = Ops[0]; for (unsigned i=0; i<NumVecs; i++) { Value *Vec = Builder.CreateExtractValue(Call, i); llvm::ConstantInt* Index = llvm::ConstantInt::get(IntTy, i); @@ -17011,11 +16982,8 @@ } auto *GEP = CGF.Builder.CreateGEP(CGF.Int8Ty, DP, Offset); - auto *DstTy = - CGF.Int16Ty->getPointerTo(GEP->getType()->getPointerAddressSpace()); - auto *Cast = CGF.Builder.CreateBitCast(GEP, DstTy); auto *LD = CGF.Builder.CreateLoad( - Address(Cast, CGF.Int16Ty, CharUnits::fromQuantity(2))); + Address(GEP, CGF.Int16Ty, CharUnits::fromQuantity(2))); llvm::MDBuilder MDHelper(CGF.getLLVMContext()); llvm::MDNode *RNode = MDHelper.createRange(APInt(16, 1), APInt(16, CGF.getTarget().getMaxOpenCLWorkGroupSize() + 1)); @@ -17034,11 +17002,8 @@ // Indexing the HSA kernel_dispatch_packet struct. auto *Offset = llvm::ConstantInt::get(CGF.Int32Ty, XOffset + Index * 4); auto *GEP = CGF.Builder.CreateGEP(CGF.Int8Ty, DP, Offset); - auto *DstTy = - CGF.Int32Ty->getPointerTo(GEP->getType()->getPointerAddressSpace()); - auto *Cast = CGF.Builder.CreateBitCast(GEP, DstTy); auto *LD = CGF.Builder.CreateLoad( - Address(Cast, CGF.Int32Ty, CharUnits::fromQuantity(4))); + Address(GEP, CGF.Int32Ty, CharUnits::fromQuantity(4))); LD->setMetadata(llvm::LLVMContext::MD_invariant_load, llvm::MDNode::get(CGF.getLLVMContext(), std::nullopt)); return LD; @@ -19939,8 +19904,7 @@ // generate one (NewBase). The new base address needs to be stored. llvm::Value *NewBase = IsLoad ? Builder.CreateExtractValue(Result, 1) : Result; - llvm::Value *LV = Builder.CreateBitCast( - EmitScalarExpr(E->getArg(0)), NewBase->getType()->getPointerTo()); + llvm::Value *LV = EmitScalarExpr(E->getArg(0)); Address Dest = EmitPointerWithAlignment(E->getArg(0)); llvm::Value *RetVal = Builder.CreateAlignedStore(NewBase, LV, Dest.getAlignment()); @@ -19981,9 +19945,7 @@ // to be handled with stores of respective destination type. DestVal = Builder.CreateTrunc(DestVal, DestTy); - llvm::Value *DestForStore = - Builder.CreateBitCast(DestAddress, DestVal->getType()->getPointerTo()); - Builder.CreateAlignedStore(DestVal, DestForStore, DestAddr.getAlignment()); + Builder.CreateAlignedStore(DestVal, DestAddress, DestAddr.getAlignment()); // The updated value of the base pointer is returned. return Builder.CreateExtractValue(Result, 1); }; Index: clang/lib/CodeGen/CGBuilder.h =================================================================== --- clang/lib/CodeGen/CGBuilder.h +++ clang/lib/CodeGen/CGBuilder.h @@ -159,9 +159,8 @@ /// preserving information like the alignment and address space. Address CreateElementBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name = "") { - auto *PtrTy = Ty->getPointerTo(Addr.getAddressSpace()); - return Address(CreateBitCast(Addr.getPointer(), PtrTy, Name), Ty, - Addr.getAlignment(), Addr.isKnownNonNull()); + return Address(Addr.getPointer(), Ty, Addr.getAlignment(), + Addr.isKnownNonNull()); } using CGBuilderBaseTy::CreatePointerBitCastOrAddrSpaceCast; Index: clang/lib/CodeGen/CGBlocks.cpp =================================================================== --- clang/lib/CodeGen/CGBlocks.cpp +++ clang/lib/CodeGen/CGBlocks.cpp @@ -1427,7 +1427,8 @@ // directly as BlockPointer. BlockPointer = Builder.CreatePointerCast( arg, - BlockInfo->StructureType->getPointerTo( + llvm::PointerType::get( + getLLVMContext(), getContext().getLangOpts().OpenCL ? getContext().getTargetAddressSpace(LangAS::opencl_generic) : 0), Index: clang/lib/CodeGen/CGAtomic.cpp =================================================================== --- clang/lib/CodeGen/CGAtomic.cpp +++ clang/lib/CodeGen/CGAtomic.cpp @@ -88,7 +88,8 @@ CGF.Int8Ty, VoidPtrAddr, OffsetInChars.getQuantity()); llvm::Type *IntTy = CGF.Builder.getIntNTy(AtomicSizeInBits); auto Addr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast( - VoidPtrAddr, IntTy->getPointerTo(), "atomic_bitfield_base"); + VoidPtrAddr, llvm::PointerType::getUnqual(CGF.getLLVMContext()), + "atomic_bitfield_base"); BFI = OrigBFI; BFI.Offset = Offset; BFI.StorageSize = AtomicSizeInBits; @@ -796,8 +797,7 @@ ValTy = CGF.getContext().getIntTypeForBitwidth(SizeInBits, /*Signed=*/false); llvm::Type *ITy = llvm::IntegerType::get(CGF.getLLVMContext(), SizeInBits); - Address Ptr = Address(CGF.Builder.CreateBitCast(Val, ITy->getPointerTo()), - ITy, Align); + Address Ptr = Address(Val, ITy, Align); Val = CGF.EmitLoadOfScalar(Ptr, false, CGF.getContext().getPointerType(ValTy), Loc);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits