JOE1994 updated this revision to Diff 532421. JOE1994 added a comment. Herald added subscribers: jrtc27, fedor.sergeev, jyknight.
- Rebase onto latest llvm-project main - Remove awkward empty line in `clang/lib/CodeGen/CGBlocks.cpp`, as suggested by barannikov88 Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D153196/new/ https://reviews.llvm.org/D153196 Files: clang/lib/CodeGen/Address.h clang/lib/CodeGen/CGBlocks.cpp clang/lib/CodeGen/CGBuilder.h clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CGException.cpp clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CGExprScalar.cpp clang/lib/CodeGen/CGObjC.cpp clang/lib/CodeGen/CGObjCMac.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/CodeGen/CGStmtOpenMP.cpp clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/MicrosoftCXXABI.cpp clang/lib/CodeGen/Targets/Hexagon.cpp clang/lib/CodeGen/Targets/Sparc.cpp clang/lib/CodeGen/Targets/SystemZ.cpp
Index: clang/lib/CodeGen/Targets/SystemZ.cpp =================================================================== --- clang/lib/CodeGen/Targets/SystemZ.cpp +++ clang/lib/CodeGen/Targets/SystemZ.cpp @@ -302,8 +302,7 @@ Address OverflowArgArea = Address(CGF.Builder.CreateLoad(OverflowArgAreaPtr, "overflow_arg_area"), CGF.Int8Ty, TyInfo.Align); - Address MemAddr = - CGF.Builder.CreateElementBitCast(OverflowArgArea, DirectTy, "mem_addr"); + Address MemAddr = OverflowArgArea.withElementType(DirectTy); // Update overflow_arg_area_ptr pointer llvm::Value *NewOverflowArgArea = CGF.Builder.CreateGEP( @@ -360,8 +359,7 @@ Address RawRegAddr( CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, RegOffset, "raw_reg_addr"), CGF.Int8Ty, PaddedSize); - Address RegAddr = - CGF.Builder.CreateElementBitCast(RawRegAddr, DirectTy, "reg_addr"); + Address RegAddr = RawRegAddr.withElementType(DirectTy); // Update the register count llvm::Value *One = llvm::ConstantInt::get(IndexTy, 1); @@ -381,8 +379,7 @@ CGF.Int8Ty, PaddedSize); Address RawMemAddr = CGF.Builder.CreateConstByteGEP(OverflowArgArea, Padding, "raw_mem_addr"); - Address MemAddr = - CGF.Builder.CreateElementBitCast(RawMemAddr, DirectTy, "mem_addr"); + Address MemAddr = RawMemAddr.withElementType(DirectTy); // Update overflow_arg_area_ptr pointer llvm::Value *NewOverflowArgArea = Index: clang/lib/CodeGen/Targets/Sparc.cpp =================================================================== --- clang/lib/CodeGen/Targets/Sparc.cpp +++ clang/lib/CodeGen/Targets/Sparc.cpp @@ -315,7 +315,7 @@ case ABIArgInfo::Indirect: case ABIArgInfo::IndirectAliased: Stride = SlotSize; - ArgAddr = Builder.CreateElementBitCast(Addr, ArgPtrTy, "indirect"); + ArgAddr = Addr.withElementType(ArgPtrTy); ArgAddr = Address(Builder.CreateLoad(ArgAddr, "indirect.arg"), ArgTy, TypeInfo.Align); break; @@ -328,7 +328,7 @@ Address NextPtr = Builder.CreateConstInBoundsByteGEP(Addr, Stride, "ap.next"); Builder.CreateStore(NextPtr.getPointer(), VAListAddr); - return Builder.CreateElementBitCast(ArgAddr, ArgTy, "arg.addr"); + return ArgAddr.withElementType(ArgTy); } void SparcV9ABIInfo::computeInfo(CGFunctionInfo &FI) const { Index: clang/lib/CodeGen/Targets/Hexagon.cpp =================================================================== --- clang/lib/CodeGen/Targets/Hexagon.cpp +++ clang/lib/CodeGen/Targets/Hexagon.cpp @@ -236,7 +236,7 @@ // FIXME: Need to handle alignment llvm::Type *BP = CGF.Int8PtrTy; CGBuilderTy &Builder = CGF.Builder; - Address VAListAddrAsBPP = Builder.CreateElementBitCast(VAListAddr, BP, "ap"); + Address VAListAddrAsBPP = VAListAddr.withElementType(BP); llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur"); // Handle address alignment for type alignment > 32 bits uint64_t TyAlign = CGF.getContext().getTypeAlign(Ty) / 8; Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp =================================================================== --- clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -1279,7 +1279,7 @@ void MicrosoftCXXABI::EmitVBPtrStores(CodeGenFunction &CGF, const CXXRecordDecl *RD) { Address This = getThisAddress(CGF); - This = CGF.Builder.CreateElementBitCast(This, CGM.Int8Ty, "this.int8"); + This = This.withElementType(CGM.Int8Ty); const ASTContext &Context = getContext(); const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); @@ -1296,8 +1296,7 @@ Address VBPtr = CGF.Builder.CreateConstInBoundsByteGEP(This, Offs); llvm::Value *GVPtr = CGF.Builder.CreateConstInBoundsGEP2_32(GV->getValueType(), GV, 0, 0); - VBPtr = CGF.Builder.CreateElementBitCast(VBPtr, GVPtr->getType(), - "vbptr." + VBT->ObjectWithVPtr->getName()); + VBPtr = VBPtr.withElementType(GVPtr->getType()); CGF.Builder.CreateStore(GVPtr, VBPtr); } } Index: clang/lib/CodeGen/CodeGenFunction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenFunction.cpp +++ clang/lib/CodeGen/CodeGenFunction.cpp @@ -1935,8 +1935,7 @@ llvm::Value *baseSizeInChars = llvm::ConstantInt::get(CGF.IntPtrTy, baseSize.getQuantity()); - Address begin = - Builder.CreateElementBitCast(dest, CGF.Int8Ty, "vla.begin"); + Address begin = dest.withElementType(CGF.Int8Ty); llvm::Value *end = Builder.CreateInBoundsGEP( begin.getElementType(), begin.getPointer(), sizeInChars, "vla.end"); @@ -1980,9 +1979,8 @@ } } - // Cast the dest ptr to the appropriate i8 pointer type. if (DestPtr.getElementType() != Int8Ty) - DestPtr = Builder.CreateElementBitCast(DestPtr, Int8Ty); + DestPtr = DestPtr.withElementType(Int8Ty); // Get size and alignment info for this aggregate. CharUnits size = getContext().getTypeSizeInChars(Ty); @@ -2142,7 +2140,7 @@ } llvm::Type *baseType = ConvertType(eltType); - addr = Builder.CreateElementBitCast(addr, baseType, "array.begin"); + addr = addr.withElementType(baseType); } else { // Create the actual GEP. addr = Address(Builder.CreateInBoundsGEP( Index: clang/lib/CodeGen/CGStmtOpenMP.cpp =================================================================== --- clang/lib/CodeGen/CGStmtOpenMP.cpp +++ clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -1266,10 +1266,9 @@ // implicit variable. PrivateScope.addPrivate(LHSVD, RedCG.getSharedLValue(Count).getAddress(*this)); - PrivateScope.addPrivate(RHSVD, Builder.CreateElementBitCast( - GetAddrOfLocalVar(PrivateVD), - ConvertTypeForMem(RHSVD->getType()), - "rhs.begin")); + PrivateScope.addPrivate(RHSVD, + GetAddrOfLocalVar(PrivateVD).withElementType( + ConvertTypeForMem(RHSVD->getType()))); } else { QualType Type = PrivateVD->getType(); bool IsArray = getContext().getAsArrayType(Type) != nullptr; @@ -1277,14 +1276,13 @@ // Store the address of the original variable associated with the LHS // implicit variable. if (IsArray) { - OriginalAddr = Builder.CreateElementBitCast( - OriginalAddr, ConvertTypeForMem(LHSVD->getType()), "lhs.begin"); + OriginalAddr = + OriginalAddr.withElementType(ConvertTypeForMem(LHSVD->getType())); } PrivateScope.addPrivate(LHSVD, OriginalAddr); PrivateScope.addPrivate( - RHSVD, IsArray ? Builder.CreateElementBitCast( - GetAddrOfLocalVar(PrivateVD), - ConvertTypeForMem(RHSVD->getType()), "rhs.begin") + RHSVD, IsArray ? GetAddrOfLocalVar(PrivateVD).withElementType( + ConvertTypeForMem(RHSVD->getType())) : GetAddrOfLocalVar(PrivateVD)); } ++ILHS; Index: clang/lib/CodeGen/CGStmt.cpp =================================================================== --- clang/lib/CodeGen/CGStmt.cpp +++ clang/lib/CodeGen/CGStmt.cpp @@ -2193,9 +2193,9 @@ getTargetHooks().isScalarizableAsmOperand(*this, Ty)) { Ty = llvm::IntegerType::get(getLLVMContext(), Size); - return {Builder.CreateLoad(Builder.CreateElementBitCast( - InputValue.getAddress(*this), Ty)), - nullptr}; + return { + Builder.CreateLoad(InputValue.getAddress(*this).withElementType(Ty)), + nullptr}; } } @@ -2395,8 +2395,7 @@ // ResultTypeRequiresCast.size() elements of RegResults. if ((i < ResultTypeRequiresCast.size()) && ResultTypeRequiresCast[i]) { unsigned Size = CGF.getContext().getTypeSize(ResultRegQualTys[i]); - Address A = - Builder.CreateElementBitCast(Dest.getAddress(CGF), ResultRegTypes[i]); + Address A = Dest.getAddress(CGF).withElementType(ResultRegTypes[i]); if (CGF.getTargetHooks().isScalarizableAsmOperand(CGF, TruncTy)) { Builder.CreateStore(Tmp, A); continue; @@ -2576,8 +2575,7 @@ // Otherwise there will be a mis-match if the matrix is also an // input-argument which is represented as vector. if (isa<MatrixType>(OutExpr->getType().getCanonicalType())) - DestAddr = Builder.CreateElementBitCast( - DestAddr, ConvertType(OutExpr->getType())); + DestAddr = DestAddr.withElementType(ConvertType(OutExpr->getType())); ArgTypes.push_back(DestAddr.getType()); ArgElemTypes.push_back(DestAddr.getElementType()); Index: clang/lib/CodeGen/CGObjCMac.cpp =================================================================== --- clang/lib/CodeGen/CGObjCMac.cpp +++ clang/lib/CodeGen/CGObjCMac.cpp @@ -5017,11 +5017,8 @@ } void CGObjCMac::EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF, - Address DestPtr, - Address SrcPtr, + Address DestPtr, Address SrcPtr, llvm::Value *size) { - SrcPtr = CGF.Builder.CreateElementBitCast(SrcPtr, CGF.Int8Ty); - DestPtr = CGF.Builder.CreateElementBitCast(DestPtr, CGF.Int8Ty); llvm::Value *args[] = { DestPtr.getPointer(), SrcPtr.getPointer(), size }; CGF.EmitNounwindRuntimeCall(ObjCTypes.GcMemmoveCollectableFn(), args); } @@ -7690,12 +7687,8 @@ } void CGObjCNonFragileABIMac::EmitGCMemmoveCollectable( - CodeGen::CodeGenFunction &CGF, - Address DestPtr, - Address SrcPtr, - llvm::Value *Size) { - SrcPtr = CGF.Builder.CreateElementBitCast(SrcPtr, CGF.Int8Ty); - DestPtr = CGF.Builder.CreateElementBitCast(DestPtr, CGF.Int8Ty); + CodeGen::CodeGenFunction &CGF, Address DestPtr, Address SrcPtr, + llvm::Value *Size) { llvm::Value *args[] = { DestPtr.getPointer(), SrcPtr.getPointer(), Size }; CGF.EmitNounwindRuntimeCall(ObjCTypes.GcMemmoveCollectableFn(), args); } Index: clang/lib/CodeGen/CGObjC.cpp =================================================================== --- clang/lib/CodeGen/CGObjC.cpp +++ clang/lib/CodeGen/CGObjC.cpp @@ -1190,7 +1190,7 @@ // Perform an atomic load. This does not impose ordering constraints. Address ivarAddr = LV.getAddress(*this); - ivarAddr = Builder.CreateElementBitCast(ivarAddr, bitcastType); + ivarAddr = ivarAddr.withElementType(bitcastType); llvm::LoadInst *load = Builder.CreateLoad(ivarAddr, "load"); load->setAtomic(llvm::AtomicOrdering::Unordered); @@ -1204,8 +1204,7 @@ bitcastType = llvm::Type::getIntNTy(getLLVMContext(), retTySize); ivarVal = Builder.CreateTrunc(load, bitcastType); } - Builder.CreateStore(ivarVal, - Builder.CreateElementBitCast(ReturnValue, bitcastType)); + Builder.CreateStore(ivarVal, ReturnValue.withElementType(bitcastType)); // Make sure we don't do an autorelease. AutoreleaseResult = false; @@ -1485,15 +1484,13 @@ // Currently, all atomic accesses have to be through integer // types, so there's no point in trying to pick a prettier type. - llvm::Type *bitcastType = - llvm::Type::getIntNTy(getLLVMContext(), - getContext().toBits(strategy.getIvarSize())); + llvm::Type *castType = llvm::Type::getIntNTy( + getLLVMContext(), getContext().toBits(strategy.getIvarSize())); // Cast both arguments to the chosen operation type. - argAddr = Builder.CreateElementBitCast(argAddr, bitcastType); - ivarAddr = Builder.CreateElementBitCast(ivarAddr, bitcastType); + argAddr = argAddr.withElementType(castType); + ivarAddr = ivarAddr.withElementType(castType); - // This bitcast load is likely to cause some nasty IR. llvm::Value *load = Builder.CreateLoad(argAddr); // Perform an atomic store. There are no memory ordering requirements. @@ -2205,18 +2202,7 @@ if (!fn) fn = getARCIntrinsic(IntID, CGF.CGM); - // Cast the argument to 'id*'. - llvm::Type *origType = addr.getElementType(); - addr = CGF.Builder.CreateElementBitCast(addr, CGF.Int8PtrTy); - - // Call the function. - llvm::Value *result = CGF.EmitNounwindRuntimeCall(fn, addr.getPointer()); - - // Cast the result back to a dereference of the original type. - if (origType != CGF.Int8PtrTy) - result = CGF.Builder.CreateBitCast(result, origType); - - return result; + return CGF.EmitNounwindRuntimeCall(fn, addr.getPointer()); } /// Perform an operation having the following signature: @@ -2661,9 +2647,6 @@ if (!fn) fn = getARCIntrinsic(llvm::Intrinsic::objc_destroyWeak, CGM); - // Cast the argument to 'id*'. - addr = Builder.CreateElementBitCast(addr, Int8PtrTy); - EmitNounwindRuntimeCall(fn, addr.getPointer()); } Index: clang/lib/CodeGen/CGExprScalar.cpp =================================================================== --- clang/lib/CodeGen/CGExprScalar.cpp +++ clang/lib/CodeGen/CGExprScalar.cpp @@ -2046,15 +2046,15 @@ case CK_LValueBitCast: case CK_ObjCObjectLValueCast: { Address Addr = EmitLValue(E).getAddress(CGF); - Addr = Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(DestTy)); + Addr = Addr.withElementType(CGF.ConvertTypeForMem(DestTy)); LValue LV = CGF.MakeAddrLValue(Addr, DestTy); return EmitLoadOfLValue(LV, CE->getExprLoc()); } case CK_LValueToRValueBitCast: { LValue SourceLVal = CGF.EmitLValue(E); - Address Addr = Builder.CreateElementBitCast(SourceLVal.getAddress(CGF), - CGF.ConvertTypeForMem(DestTy)); + Address Addr = SourceLVal.getAddress(CGF).withElementType( + CGF.ConvertTypeForMem(DestTy)); LValue DestLV = CGF.MakeAddrLValue(Addr, DestTy); DestLV.setTBAAInfo(TBAAAccessInfo::getMayAliasInfo()); return EmitLoadOfLValue(DestLV, CE->getExprLoc()); @@ -2177,8 +2177,7 @@ Address Addr = CGF.CreateDefaultAlignTempAlloca(SrcTy, "saved-value"); LValue LV = CGF.MakeAddrLValue(Addr, E->getType()); CGF.EmitStoreOfScalar(Src, LV); - Addr = Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(DestTy), - "castFixedSve"); + Addr = Addr.withElementType(CGF.ConvertTypeForMem(DestTy)); LValue DestLV = CGF.MakeAddrLValue(Addr, DestTy); DestLV.setTBAAInfo(TBAAAccessInfo::getMayAliasInfo()); return EmitLoadOfLValue(DestLV, CE->getExprLoc()); @@ -5144,7 +5143,7 @@ } // Cast the address to Class*. - Addr = Builder.CreateElementBitCast(Addr, ConvertType(E->getType())); + Addr = Addr.withElementType(ConvertType(E->getType())); return MakeAddrLValue(Addr, E->getType()); } Index: clang/lib/CodeGen/CGExpr.cpp =================================================================== --- clang/lib/CodeGen/CGExpr.cpp +++ clang/lib/CodeGen/CGExpr.cpp @@ -1755,10 +1755,9 @@ if (!CGM.getCodeGenOpts().PreserveVec3Type && VTy->getNumElements() == 3) { - // Bitcast to vec4 type. llvm::VectorType *vec4Ty = llvm::FixedVectorType::get(VTy->getElementType(), 4); - Address Cast = Builder.CreateElementBitCast(Addr, vec4Ty, "castToVec4"); + Address Cast = Addr.withElementType(vec4Ty); // Now load value. llvm::Value *V = Builder.CreateLoad(Cast, Volatile, "loadVec4"); @@ -1898,7 +1897,7 @@ SrcTy = llvm::FixedVectorType::get(VecTy->getElementType(), 4); } if (Addr.getElementType() != SrcTy) { - Addr = Builder.CreateElementBitCast(Addr, SrcTy, "storetmp"); + Addr = Addr.withElementType(SrcTy); } } } @@ -2080,9 +2079,7 @@ QualType EQT = LV.getType()->castAs<VectorType>()->getElementType(); llvm::Type *VectorElementTy = CGM.getTypes().ConvertType(EQT); - Address CastToPointerElement = - Builder.CreateElementBitCast(VectorAddress, VectorElementTy, - "conv.ptr.element"); + Address CastToPointerElement = VectorAddress.withElementType(VectorElementTy); const llvm::Constant *Elts = LV.getExtVectorElts(); unsigned ix = getAccessedFieldNo(0, Elts); @@ -4501,8 +4498,7 @@ } if (FieldType->isReferenceType()) - addr = Builder.CreateElementBitCast( - addr, CGM.getTypes().ConvertTypeForMem(FieldType), field->getName()); + addr = addr.withElementType(CGM.getTypes().ConvertTypeForMem(FieldType)); } else { if (!IsInPreservedAIRegion && (!getDebugInfo() || !rec->hasAttr<BPFPreserveAccessIndexAttr>())) @@ -4527,11 +4523,8 @@ } // Make sure that the address is pointing to the right type. This is critical - // for both unions and structs. A union needs a bitcast, a struct element - // will need a bitcast if the LLVM type laid out doesn't match the desired - // type. - addr = Builder.CreateElementBitCast( - addr, CGM.getTypes().ConvertTypeForMem(FieldType), field->getName()); + // for both unions and structs. + addr = addr.withElementType(CGM.getTypes().ConvertTypeForMem(FieldType)); if (field->hasAttr<AnnotateAttr>()) addr = EmitFieldAnnotations(field, addr); @@ -4558,7 +4551,7 @@ // Make sure that the address is pointing to the right type. llvm::Type *llvmType = ConvertTypeForMem(FieldType); - V = Builder.CreateElementBitCast(V, llvmType, Field->getName()); + V = V.withElementType(llvmType); // TODO: Generate TBAA information that describes this access as a structure // member access and not just an access to an object of the field's type. This Index: clang/lib/CodeGen/CGException.cpp =================================================================== --- clang/lib/CodeGen/CGException.cpp +++ clang/lib/CodeGen/CGException.cpp @@ -401,7 +401,7 @@ // __cxa_allocate_exception returns a void*; we need to cast this // to the appropriate type for the object. llvm::Type *ty = ConvertTypeForMem(e->getType()); - Address typedAddr = Builder.CreateElementBitCast(addr, ty); + Address typedAddr = addr.withElementType(ty); // FIXME: this isn't quite right! If there's a final unelided call // to a copy constructor, then according to [except.terminate]p1 we Index: clang/lib/CodeGen/CGDecl.cpp =================================================================== --- clang/lib/CodeGen/CGDecl.cpp +++ clang/lib/CodeGen/CGDecl.cpp @@ -727,8 +727,8 @@ // Handle a formal type change to avoid asserting. auto srcAddr = srcLV.getAddress(CGF); if (needsCast) { - srcAddr = CGF.Builder.CreateElementBitCast( - srcAddr, destLV.getAddress(CGF).getElementType()); + srcAddr = + srcAddr.withElementType(destLV.getAddress(CGF).getElementType()); } // If it was an l-value, use objc_copyWeak. @@ -1173,7 +1173,7 @@ llvm::Constant *Constant, CharUnits Align) { Address SrcPtr = CGM.createUnnamedGlobalFrom(D, Constant, Align); - return Builder.CreateElementBitCast(SrcPtr, CGM.Int8Ty); + return SrcPtr.withElementType(CGM.Int8Ty); } static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D, @@ -1207,7 +1207,7 @@ bool valueAlreadyCorrect = constant->isNullValue() || isa<llvm::UndefValue>(constant); if (!valueAlreadyCorrect) { - Loc = Builder.CreateElementBitCast(Loc, Ty); + Loc = Loc.withElementType(Ty); emitStoresForInitAfterBZero(CGM, constant, Loc, isVolatile, Builder, IsAutoInit); } @@ -1790,7 +1790,7 @@ SizeVal = Builder.CreateNUWMul(SizeVal, CGM.getSize(EltSize)); llvm::Value *BaseSizeInChars = llvm::ConstantInt::get(IntPtrTy, EltSize.getQuantity()); - Address Begin = Builder.CreateElementBitCast(Loc, Int8Ty, "vla.begin"); + Address Begin = Loc.withElementType(Int8Ty); llvm::Value *End = Builder.CreateInBoundsGEP( Begin.getElementType(), Begin.getPointer(), SizeVal, "vla.end"); llvm::BasicBlock *OriginBB = Builder.GetInsertBlock(); @@ -1921,7 +1921,7 @@ return EmitStoreThroughLValue(RValue::get(constant), lv, true); } - emitStoresForConstant(CGM, D, Builder.CreateElementBitCast(Loc, CGM.Int8Ty), + emitStoresForConstant(CGM, D, Loc.withElementType(CGM.Int8Ty), type.isVolatileQualified(), Builder, constant, /*IsAutoInit=*/false); } @@ -2482,10 +2482,8 @@ // If we already have a pointer to the argument, reuse the input pointer. if (Arg.isIndirect()) { - // If we have a prettier pointer type at this point, bitcast to that. DeclPtr = Arg.getIndirectAddress(); - DeclPtr = Builder.CreateElementBitCast(DeclPtr, ConvertTypeForMem(Ty), - D.getName()); + DeclPtr = DeclPtr.withElementType(ConvertTypeForMem(Ty)); // Indirect argument is in alloca address space, which may be different // from the default address space. auto AllocaAS = CGM.getASTAllocaAddressSpace(); Index: clang/lib/CodeGen/CGBuiltin.cpp =================================================================== --- clang/lib/CodeGen/CGBuiltin.cpp +++ clang/lib/CodeGen/CGBuiltin.cpp @@ -1858,8 +1858,7 @@ Address Arg = GetAddrOfLocalVar(Args[I]); Address Addr = Builder.CreateConstByteGEP(BufAddr, Offset, "argData"); - Addr = - Builder.CreateElementBitCast(Addr, Arg.getElementType(), "argDataCast"); + Addr = Addr.withElementType(Arg.getElementType()); Builder.CreateStore(Builder.CreateLoad(Arg), Addr); Offset += Size; ++I; Index: clang/lib/CodeGen/CGBuilder.h =================================================================== --- clang/lib/CodeGen/CGBuilder.h +++ clang/lib/CodeGen/CGBuilder.h @@ -155,10 +155,8 @@ Addr.isKnownNonNull()); } - /// Cast the element type of the given address to a different type, - /// preserving information like the alignment and address space. - Address CreateElementBitCast(Address Addr, llvm::Type *Ty, - const llvm::Twine &Name = "") { + /// This method is to be deprecated. Use `Address::withElementType` instead. + Address CreateElementBitCast(Address Addr, llvm::Type *Ty) { return Address(Addr.getPointer(), Ty, Addr.getAlignment(), Addr.isKnownNonNull()); } Index: clang/lib/CodeGen/CGBlocks.cpp =================================================================== --- clang/lib/CodeGen/CGBlocks.cpp +++ clang/lib/CodeGen/CGBlocks.cpp @@ -1260,8 +1260,7 @@ auto &byrefInfo = getBlockByrefInfo(variable); addr = Address(Builder.CreateLoad(addr), Int8Ty, byrefInfo.ByrefAlignment); - - addr = Builder.CreateElementBitCast(addr, byrefInfo.Type, "byref.addr"); + addr = addr.withElementType(byrefInfo.Type); addr = emitBlockByrefAddress(addr, byrefInfo, /*follow*/ true, variable->getName()); @@ -1935,14 +1934,12 @@ auto AL = ApplyDebugLocation::CreateArtificial(*this); Address src = GetAddrOfLocalVar(&SrcDecl); - src = Address(Builder.CreateLoad(src), Int8Ty, blockInfo.BlockAlign); - src = Builder.CreateElementBitCast(src, blockInfo.StructureType, - "block.source"); + src = Address(Builder.CreateLoad(src), blockInfo.StructureType, + blockInfo.BlockAlign); Address dst = GetAddrOfLocalVar(&DstDecl); - dst = Address(Builder.CreateLoad(dst), Int8Ty, blockInfo.BlockAlign); - dst = - Builder.CreateElementBitCast(dst, blockInfo.StructureType, "block.dest"); + dst = Address(Builder.CreateLoad(dst), blockInfo.StructureType, + blockInfo.BlockAlign); for (auto &capture : blockInfo.SortedCaptures) { if (capture.isConstantOrTrivial()) @@ -2125,8 +2122,8 @@ auto AL = ApplyDebugLocation::CreateArtificial(*this); Address src = GetAddrOfLocalVar(&SrcDecl); - src = Address(Builder.CreateLoad(src), Int8Ty, blockInfo.BlockAlign); - src = Builder.CreateElementBitCast(src, blockInfo.StructureType, "block"); + src = Address(Builder.CreateLoad(src), blockInfo.StructureType, + blockInfo.BlockAlign); CodeGenFunction::RunCleanupsScope cleanups(*this); @@ -2163,9 +2160,9 @@ void emitCopy(CodeGenFunction &CGF, Address destField, Address srcField) override { - destField = CGF.Builder.CreateElementBitCast(destField, CGF.Int8Ty); + destField = destField.withElementType(CGF.Int8Ty); - srcField = CGF.Builder.CreateElementBitCast(srcField, CGF.Int8PtrTy); + srcField = srcField.withElementType(CGF.Int8PtrTy); llvm::Value *srcValue = CGF.Builder.CreateLoad(srcField); unsigned flags = (Flags | BLOCK_BYREF_CALLER).getBitMask(); @@ -2178,7 +2175,7 @@ } void emitDispose(CodeGenFunction &CGF, Address field) override { - field = CGF.Builder.CreateElementBitCast(field, CGF.Int8PtrTy); + field = field.withElementType(CGF.Int8PtrTy); llvm::Value *value = CGF.Builder.CreateLoad(field); CGF.BuildBlockRelease(value, Flags | BLOCK_BYREF_CALLER, false); @@ -2370,17 +2367,15 @@ if (generator.needsCopy()) { // dst->x Address destField = CGF.GetAddrOfLocalVar(&Dst); - destField = Address(CGF.Builder.CreateLoad(destField), CGF.Int8Ty, + destField = Address(CGF.Builder.CreateLoad(destField), byrefInfo.Type, byrefInfo.ByrefAlignment); - destField = CGF.Builder.CreateElementBitCast(destField, byrefInfo.Type); destField = CGF.emitBlockByrefAddress(destField, byrefInfo, false, "dest-object"); // src->x Address srcField = CGF.GetAddrOfLocalVar(&Src); - srcField = Address(CGF.Builder.CreateLoad(srcField), CGF.Int8Ty, + srcField = Address(CGF.Builder.CreateLoad(srcField), byrefInfo.Type, byrefInfo.ByrefAlignment); - srcField = CGF.Builder.CreateElementBitCast(srcField, byrefInfo.Type); srcField = CGF.emitBlockByrefAddress(srcField, byrefInfo, false, "src-object"); @@ -2436,9 +2431,8 @@ if (generator.needsDispose()) { Address addr = CGF.GetAddrOfLocalVar(&Src); - addr = Address(CGF.Builder.CreateLoad(addr), CGF.Int8Ty, + addr = Address(CGF.Builder.CreateLoad(addr), byrefInfo.Type, byrefInfo.ByrefAlignment); - addr = CGF.Builder.CreateElementBitCast(addr, byrefInfo.Type); addr = CGF.emitBlockByrefAddress(addr, byrefInfo, false, "object"); generator.emitDispose(CGF, addr); Index: clang/lib/CodeGen/Address.h =================================================================== --- clang/lib/CodeGen/Address.h +++ clang/lib/CodeGen/Address.h @@ -95,6 +95,12 @@ isKnownNonNull()); } + /// Return address with different element type, but same pointer and + /// alignment. + Address withElementType(llvm::Type *ElemTy) const { + return Address(getPointer(), ElemTy, getAlignment(), isKnownNonNull()); + } + /// Whether the pointer is known not to be null. KnownNonNull_t isKnownNonNull() const { assert(isValid());
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits