ahatanak created this revision. ahatanak added reviewers: rjmccall, ab, efriedma. ahatanak added a project: clang. Herald added a subscriber: kristof.beyls. Herald added a project: All. ahatanak requested review of this revision.
The flag will be used for the arm64e work we plan to upstream in the future (see https://lists.llvm.org/pipermail/llvm-dev/2019-October/136091.html). Passing `KnownNonNull_t::True` allows clang to avoid emitting null checks on arm64e. Currently the flag has no effect on code generation on other targets. This is the first patch and there are many more places where `KnownNonNull_t::True` can be passed. I plan to fix those places in future patches. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D142584 Files: clang/lib/CodeGen/Address.h clang/lib/CodeGen/CGBlocks.cpp clang/lib/CodeGen/CGBuilder.h clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGCXXABI.cpp clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CGClass.cpp clang/lib/CodeGen/CGCleanup.cpp clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CGException.cpp clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CGExprAgg.cpp clang/lib/CodeGen/CGExprCXX.cpp clang/lib/CodeGen/CGExprScalar.cpp clang/lib/CodeGen/CGNonTrivialStruct.cpp clang/lib/CodeGen/CGValue.h clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/CodeGen/MicrosoftCXXABI.cpp
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp =================================================================== --- clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -1639,7 +1639,8 @@ llvm::Value *Implicit = getCXXDestructorImplicitParam(CGF, DD, Type, ForVirtualBase, Delegating); // = nullptr - CGF.EmitCXXDestructorCall(GD, Callee, This.getPointer(), ThisTy, + CGF.EmitCXXDestructorCall(GD, Callee, This.getPointer(KnownNonNull_t::True), + ThisTy, /*ImplicitParam=*/Implicit, /*ImplicitParamTy=*/QualType(), nullptr); if (BaseDtorEndBB) { Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -1698,8 +1698,8 @@ else Callee = CGCallee::forDirect(CGM.getAddrOfCXXStructor(GD), GD); - CGF.EmitCXXDestructorCall(GD, Callee, This.getPointer(), ThisTy, VTT, VTTTy, - nullptr); + CGF.EmitCXXDestructorCall(GD, Callee, This.getPointer(KnownNonNull_t::True), + ThisTy, VTT, VTTTy, nullptr); } void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables &CGVT, Index: clang/lib/CodeGen/CodeGenFunction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenFunction.cpp +++ clang/lib/CodeGen/CodeGenFunction.cpp @@ -1171,7 +1171,8 @@ LValue ThisFieldLValue = EmitLValueForLambdaField(LambdaThisCaptureField); if (!LambdaThisCaptureField->getType()->isPointerType()) { // If the enclosing object was captured by value, just use its address. - CXXThisValue = ThisFieldLValue.getAddress(*this).getPointer(); + CXXThisValue = ThisFieldLValue.getAddress(*this).getPointer( + KnownNonNull_t::True); } else { // Load the lvalue pointed to by the field, since '*this' was captured // by reference. Index: clang/lib/CodeGen/CGValue.h =================================================================== --- clang/lib/CodeGen/CGValue.h +++ clang/lib/CodeGen/CGValue.h @@ -334,7 +334,9 @@ void setBaseInfo(LValueBaseInfo Info) { BaseInfo = Info; } // simple lvalue - llvm::Value *getPointer(CodeGenFunction &CGF) const { + llvm::Value * + getPointer(CodeGenFunction &CGF, + KnownNonNull_t KnownNonNull = KnownNonNull_t::False) const { assert(isSimple()); return V; } Index: clang/lib/CodeGen/CGNonTrivialStruct.cpp =================================================================== --- clang/lib/CodeGen/CGNonTrivialStruct.cpp +++ clang/lib/CodeGen/CGNonTrivialStruct.cpp @@ -491,8 +491,9 @@ for (unsigned I = 0; I < N; ++I) { Alignments[I] = Addrs[I].getAlignment(); - Ptrs[I] = CallerCGF.Builder.CreateElementBitCast( - Addrs[I], CallerCGF.CGM.Int8PtrTy).getPointer(); + Ptrs[I] = CallerCGF.Builder + .CreateElementBitCast(Addrs[I], CallerCGF.CGM.Int8PtrTy) + .getPointer(KnownNonNull_t::True); } if (llvm::Function *F = Index: clang/lib/CodeGen/CGExprScalar.cpp =================================================================== --- clang/lib/CodeGen/CGExprScalar.cpp +++ clang/lib/CodeGen/CGExprScalar.cpp @@ -2240,7 +2240,8 @@ case CK_DerivedToBase: { // The EmitPointerWithAlignment path does this fine; just discard // the alignment. - return CGF.EmitPointerWithAlignment(CE).getPointer(); + return CGF.EmitPointerWithAlignment(CE).getPointer( + static_cast<KnownNonNull_t>(Kind == CK_UncheckedDerivedToBase)); } case CK_Dynamic: { Index: clang/lib/CodeGen/CGExprCXX.cpp =================================================================== --- clang/lib/CodeGen/CGExprCXX.cpp +++ clang/lib/CodeGen/CGExprCXX.cpp @@ -423,7 +423,8 @@ } return EmitCXXMemberOrOperatorCall( - CalleeDecl, Callee, ReturnValue, This.getPointer(*this), + CalleeDecl, Callee, ReturnValue, + This.getPointer(*this, KnownNonNull_t::True), /*ImplicitParam=*/nullptr, QualType(), CE, RtlArgs); } @@ -1947,9 +1948,9 @@ // Make sure that we call delete even if the dtor throws. // This doesn't have to a conditional cleanup because we're going // to pop it off in a second. - CGF.EHStack.pushCleanup<CallObjectDelete>(NormalAndEHCleanup, - Ptr.getPointer(), - OperatorDelete, ElementType); + CGF.EHStack.pushCleanup<CallObjectDelete>( + NormalAndEHCleanup, Ptr.getPointer(KnownNonNull_t::True), OperatorDelete, + ElementType); if (Dtor) CGF.EmitCXXDestructorCall(Dtor, Dtor_Complete, @@ -2036,7 +2037,7 @@ CharUnits elementAlign = deletedPtr.getAlignment().alignmentOfArrayElement(elementSize); - llvm::Value *arrayBegin = deletedPtr.getPointer(); + llvm::Value *arrayBegin = deletedPtr.getPointer(KnownNonNull_t::True); llvm::Value *arrayEnd = CGF.Builder.CreateInBoundsGEP( deletedPtr.getElementType(), arrayBegin, numElements, "delete.end"); Index: clang/lib/CodeGen/CGExprAgg.cpp =================================================================== --- clang/lib/CodeGen/CGExprAgg.cpp +++ clang/lib/CodeGen/CGExprAgg.cpp @@ -436,7 +436,8 @@ llvm::Value *Zero = llvm::ConstantInt::get(CGF.PtrDiffTy, 0); llvm::Value *IdxStart[] = { Zero, Zero }; llvm::Value *ArrayStart = Builder.CreateInBoundsGEP( - ArrayPtr.getElementType(), ArrayPtr.getPointer(), IdxStart, "arraystart"); + ArrayPtr.getElementType(), ArrayPtr.getPointer(KnownNonNull_t::True), + IdxStart, "arraystart"); CGF.EmitStoreThroughLValue(RValue::get(ArrayStart), Start); ++Field; @@ -453,7 +454,8 @@ // End pointer. llvm::Value *IdxEnd[] = { Zero, Size }; llvm::Value *ArrayEnd = Builder.CreateInBoundsGEP( - ArrayPtr.getElementType(), ArrayPtr.getPointer(), IdxEnd, "arrayend"); + ArrayPtr.getElementType(), ArrayPtr.getPointer(KnownNonNull_t::True), + IdxEnd, "arrayend"); CGF.EmitStoreThroughLValue(RValue::get(ArrayEnd), EndOrLength); } else if (Ctx.hasSameType(Field->getType(), Ctx.getSizeType())) { // Length. @@ -505,8 +507,8 @@ llvm::Value *zero = llvm::ConstantInt::get(CGF.SizeTy, 0); llvm::Value *indices[] = { zero, zero }; llvm::Value *begin = Builder.CreateInBoundsGEP( - DestPtr.getElementType(), DestPtr.getPointer(), indices, - "arrayinit.begin"); + DestPtr.getElementType(), DestPtr.getPointer(KnownNonNull_t::True), + indices, "arrayinit.begin"); CharUnits elementSize = CGF.getContext().getTypeSizeInChars(elementType); CharUnits elementAlign = @@ -1823,8 +1825,8 @@ llvm::Value *zero = llvm::ConstantInt::get(CGF.SizeTy, 0); llvm::Value *indices[] = {zero, zero}; llvm::Value *begin = Builder.CreateInBoundsGEP( - destPtr.getElementType(), destPtr.getPointer(), indices, - "arrayinit.begin"); + destPtr.getElementType(), destPtr.getPointer(KnownNonNull_t::True), + indices, "arrayinit.begin"); // Prepare to special-case multidimensional array initialization: we avoid // emitting multiple destructor loops in that case. Index: clang/lib/CodeGen/CGExpr.cpp =================================================================== --- clang/lib/CodeGen/CGExpr.cpp +++ clang/lib/CodeGen/CGExpr.cpp @@ -361,7 +361,8 @@ } else { CleanupFn = CGF.CGM.getAddrAndTypeOfCXXStructor( GlobalDecl(ReferenceTemporaryDtor, Dtor_Complete)); - CleanupArg = cast<llvm::Constant>(ReferenceTemporary.getPointer()); + CleanupArg = cast<llvm::Constant>( + ReferenceTemporary.getPointer(KnownNonNull_t::True)); } CGF.CGM.getCXXABI().registerGlobalDtor( CGF, *cast<VarDecl>(M->getExtendingDecl()), CleanupFn, CleanupArg); @@ -617,7 +618,7 @@ // Emit the expression as an lvalue. LValue LV = EmitLValue(E); assert(LV.isSimple()); - llvm::Value *Value = LV.getPointer(*this); + llvm::Value *Value = LV.getPointer(*this, KnownNonNull_t::True); if (sanitizePerformTypeCheck() && !E->getType()->isFunctionType()) { // C++11 [dcl.ref]p5 (as amended by core issue 453): @@ -2185,11 +2186,11 @@ assert(Dst.getBaseIvarExp() && "BaseIvarExp is NULL"); llvm::Type *ResultType = IntPtrTy; Address dst = EmitPointerWithAlignment(Dst.getBaseIvarExp()); - llvm::Value *RHS = dst.getPointer(); + llvm::Value *RHS = dst.getPointer(KnownNonNull_t::True); RHS = Builder.CreatePtrToInt(RHS, ResultType, "sub.ptr.rhs.cast"); llvm::Value *LHS = - Builder.CreatePtrToInt(LvalueDst.getPointer(), ResultType, - "sub.ptr.lhs.cast"); + Builder.CreatePtrToInt(LvalueDst.getPointer(KnownNonNull_t::True), + ResultType, "sub.ptr.lhs.cast"); llvm::Value *BytesBetween = Builder.CreateSub(LHS, RHS, "ivar.offset"); CGM.getObjCRuntime().EmitObjCIvarAssign(*this, src, dst, BytesBetween); @@ -2790,7 +2791,8 @@ CapturedStmtInfo->getContextValue()); Address LValueAddress = CapLVal.getAddress(*this); CapLVal = MakeAddrLValue( - Address(LValueAddress.getPointer(), LValueAddress.getElementType(), + Address(LValueAddress.getPointer(KnownNonNull_t::True), + LValueAddress.getElementType(), getContext().getDeclAlign(VD)), CapLVal.getType(), LValueBaseInfo(AlignmentSource::Decl), CapLVal.getTBAAInfo()); @@ -5106,7 +5108,7 @@ functionType = ptrType->getPointeeType(); } else { functionType = E->getType(); - calleePtr = EmitLValue(E).getPointer(*this); + calleePtr = EmitLValue(E).getPointer(*this, KnownNonNull_t::True); } assert(functionType->isFunctionType()); Index: clang/lib/CodeGen/CGException.cpp =================================================================== --- clang/lib/CodeGen/CGException.cpp +++ clang/lib/CodeGen/CGException.cpp @@ -414,8 +414,8 @@ /*IsInit*/ true); // Deactivate the cleanup block. - DeactivateCleanupBlock(cleanup, - cast<llvm::Instruction>(typedAddr.getPointer())); + DeactivateCleanupBlock(cleanup, cast<llvm::Instruction>(typedAddr.getPointer( + KnownNonNull_t::True))); } Address CodeGenFunction::getExceptionSlot() { Index: clang/lib/CodeGen/CGDecl.cpp =================================================================== --- clang/lib/CodeGen/CGDecl.cpp +++ clang/lib/CodeGen/CGDecl.cpp @@ -1794,7 +1794,7 @@ llvm::BasicBlock *OriginBB = Builder.GetInsertBlock(); EmitBlock(LoopBB); llvm::PHINode *Cur = Builder.CreatePHI(Begin.getType(), 2, "vla.cur"); - Cur->addIncoming(Begin.getPointer(), OriginBB); + Cur->addIncoming(Begin.getPointer(KnownNonNull_t::True), OriginBB); CharUnits CurAlign = Loc.getAlignment().alignmentOfArrayElement(EltSize); auto *I = Builder.CreateMemCpy(Address(Cur, Int8Ty, CurAlign), @@ -2216,7 +2216,7 @@ checkZeroLength = false; } - llvm::Value *begin = addr.getPointer(); + llvm::Value *begin = addr.getPointer(KnownNonNull_t::True); llvm::Value *end = Builder.CreateInBoundsGEP(addr.getElementType(), begin, length); emitArrayDestroy(begin, end, type, elementAlign, destroyer, @@ -2485,7 +2485,7 @@ // Indirect argument is in alloca address space, which may be different // from the default address space. auto AllocaAS = CGM.getASTAllocaAddressSpace(); - auto *V = DeclPtr.getPointer(); + auto *V = DeclPtr.getPointer(KnownNonNull_t::True); AllocaPtr = DeclPtr; auto SrcLangAS = getLangOpts().OpenCL ? LangAS::opencl_private : AllocaAS; auto DestLangAS = Index: clang/lib/CodeGen/CGCleanup.cpp =================================================================== --- clang/lib/CodeGen/CGCleanup.cpp +++ clang/lib/CodeGen/CGCleanup.cpp @@ -318,15 +318,16 @@ static void createStoreInstBefore(llvm::Value *value, Address addr, llvm::Instruction *beforeInst) { - auto store = new llvm::StoreInst(value, addr.getPointer(), beforeInst); + auto store = new llvm::StoreInst(value, addr.getPointer(KnownNonNull_t::True), + beforeInst); store->setAlignment(addr.getAlignment().getAsAlign()); } static llvm::LoadInst *createLoadInstBefore(Address addr, const Twine &name, llvm::Instruction *beforeInst) { - return new llvm::LoadInst(addr.getElementType(), addr.getPointer(), name, - false, addr.getAlignment().getAsAlign(), - beforeInst); + return new llvm::LoadInst(addr.getElementType(), + addr.getPointer(KnownNonNull_t::True), name, false, + addr.getAlignment().getAsAlign(), beforeInst); } /// All the branch fixups on the EH stack have propagated out past the Index: clang/lib/CodeGen/CGClass.cpp =================================================================== --- clang/lib/CodeGen/CGClass.cpp +++ clang/lib/CodeGen/CGClass.cpp @@ -2128,14 +2128,14 @@ LangAS SlotAS = ThisAVS.getQualifiers().getAddressSpace(); QualType ThisType = D->getThisType(); LangAS ThisAS = ThisType.getTypePtr()->getPointeeType().getAddressSpace(); - llvm::Value *ThisPtr = This.getPointer(); + llvm::Value *ThisPtr = This.getPointer(KnownNonNull_t::True); if (SlotAS != ThisAS) { unsigned TargetThisAS = getContext().getTargetAddressSpace(ThisAS); llvm::Type *NewType = llvm::PointerType::getWithSamePointeeType( This.getType(), TargetThisAS); - ThisPtr = getTargetHooks().performAddrSpaceCast(*this, This.getPointer(), - ThisAS, SlotAS, NewType); + ThisPtr = getTargetHooks().performAddrSpaceCast( + *this, This.getPointer(KnownNonNull_t::True), ThisAS, SlotAS, NewType); } // Push the this ptr. @@ -2273,7 +2273,8 @@ const CXXConstructorDecl *D, bool ForVirtualBase, Address This, bool InheritedFromVBase, const CXXInheritedCtorInitExpr *E) { CallArgList Args; - CallArg ThisArg(RValue::get(This.getPointer()), D->getThisType()); + CallArg ThisArg(RValue::get(This.getPointer(KnownNonNull_t::True)), + D->getThisType()); // Forward the parameters. if (InheritedFromVBase && @@ -2398,12 +2399,14 @@ CallArgList Args; // Push the this ptr. - Args.add(RValue::get(This.getPointer()), D->getThisType()); + Args.add(RValue::get(This.getPointer(KnownNonNull_t::True)), + D->getThisType()); // Push the src ptr. QualType QT = *(FPT->param_type_begin()); llvm::Type *t = CGM.getTypes().ConvertType(QT); - llvm::Value *SrcVal = Builder.CreateBitCast(Src.getPointer(), t); + llvm::Value *SrcVal = + Builder.CreateBitCast(Src.getPointer(KnownNonNull_t::True), t); Args.add(RValue::get(SrcVal), QT); // Skip over first argument (Src). @@ -2428,7 +2431,8 @@ // this Address This = LoadCXXThisAddress(); - DelegateArgs.add(RValue::get(This.getPointer()), (*I)->getType()); + DelegateArgs.add(RValue::get(This.getPointer(KnownNonNull_t::True)), + (*I)->getType()); ++I; // FIXME: The location of the VTT parameter in the parameter list is @@ -2993,7 +2997,7 @@ QualType ThisType = getContext().getPointerType(getContext().getRecordType(Lambda)); Address ThisPtr = GetAddrOfBlockDecl(variable); - CallArgs.add(RValue::get(ThisPtr.getPointer()), ThisType); + CallArgs.add(RValue::get(ThisPtr.getPointer(KnownNonNull_t::True)), ThisType); // Add the rest of the parameters. for (auto *param : BD->parameters()) Index: clang/lib/CodeGen/CGCall.cpp =================================================================== --- clang/lib/CodeGen/CGCall.cpp +++ clang/lib/CodeGen/CGCall.cpp @@ -1321,8 +1321,8 @@ Address Tmp = CreateTempAllocaForCoercion(CGF, Ty, Src.getAlignment(), Src.getName()); CGF.Builder.CreateMemCpy( - Tmp.getPointer(), Tmp.getAlignment().getAsAlign(), Src.getPointer(), - Src.getAlignment().getAsAlign(), + Tmp.getPointer(KnownNonNull_t::True), Tmp.getAlignment().getAsAlign(), + Src.getPointer(KnownNonNull_t::True), Src.getAlignment().getAsAlign(), llvm::ConstantInt::get(CGF.IntPtrTy, SrcSize.getKnownMinValue())); return CGF.Builder.CreateLoad(Tmp); } @@ -1409,8 +1409,8 @@ Address Tmp = CreateTempAllocaForCoercion(CGF, SrcTy, Dst.getAlignment()); CGF.Builder.CreateStore(Src, Tmp); CGF.Builder.CreateMemCpy( - Dst.getPointer(), Dst.getAlignment().getAsAlign(), Tmp.getPointer(), - Tmp.getAlignment().getAsAlign(), + Dst.getPointer(KnownNonNull_t::True), Dst.getAlignment().getAsAlign(), + Tmp.getPointer(KnownNonNull_t::True), Tmp.getAlignment().getAsAlign(), llvm::ConstantInt::get(CGF.IntPtrTy, DstSize.getFixedValue())); } } @@ -2823,8 +2823,10 @@ // copy. CharUnits Size = getContext().getTypeSizeInChars(Ty); Builder.CreateMemCpy( - AlignedTemp.getPointer(), AlignedTemp.getAlignment().getAsAlign(), - ParamAddr.getPointer(), ParamAddr.getAlignment().getAsAlign(), + AlignedTemp.getPointer(KnownNonNull_t::True), + AlignedTemp.getAlignment().getAsAlign(), + ParamAddr.getPointer(KnownNonNull_t::True), + ParamAddr.getAlignment().getAsAlign(), llvm::ConstantInt::get(IntPtrTy, Size.getQuantity())); V = AlignedTemp; } @@ -4021,7 +4023,7 @@ bool provablyNonNull = llvm::isKnownNonZero(srcAddr.getPointer(), CGF.CGM.getDataLayout()); if (provablyNonNull) { - finalArgument = temp.getPointer(); + finalArgument = temp.getPointer(KnownNonNull_t::True); } else { llvm::Value *isNull = CGF.Builder.CreateIsNull(srcAddr.getPointer(), "icr.isnull"); @@ -4833,11 +4835,12 @@ } } if (IRFunctionArgs.hasSRetArg()) { - IRCallArgs[IRFunctionArgs.getSRetArgNo()] = SRetPtr.getPointer(); + IRCallArgs[IRFunctionArgs.getSRetArgNo()] = + SRetPtr.getPointer(KnownNonNull_t::True); } else if (RetAI.isInAlloca()) { Address Addr = Builder.CreateStructGEP(ArgMemory, RetAI.getInAllocaFieldIndex()); - Builder.CreateStore(SRetPtr.getPointer(), Addr); + Builder.CreateStore(SRetPtr.getPointer(KnownNonNull_t::True), Addr); } } @@ -4928,9 +4931,9 @@ Address Addr = CreateMemTempWithoutCast( I->Ty, ArgInfo.getIndirectAlign(), "indirect-arg-temp"); - llvm::Value *Val = Addr.getPointer(); + llvm::Value *Val = Addr.getPointer(KnownNonNull_t::True); if (ArgHasMaybeUndefAttr) - Val = Builder.CreateFreeze(Addr.getPointer()); + Val = Builder.CreateFreeze(Addr.getPointer(KnownNonNull_t::True)); IRCallArgs[FirstIRArg] = Val; I->copyInto(*this, Addr); Index: clang/lib/CodeGen/CGCXXABI.cpp =================================================================== --- clang/lib/CodeGen/CGCXXABI.cpp +++ clang/lib/CodeGen/CGCXXABI.cpp @@ -44,7 +44,7 @@ llvm::Value *MemPtr, const MemberPointerType *MPT) { ErrorUnsupportedABI(CGF, "calls through member pointers"); - ThisPtrForCall = This.getPointer(); + ThisPtrForCall = This.getPointer(KnownNonNull_t::True); const auto *FPT = MPT->getPointeeType()->castAs<FunctionProtoType>(); const auto *RD = cast<CXXRecordDecl>(MPT->getClass()->castAs<RecordType>()->getDecl()); @@ -254,7 +254,7 @@ // If we don't need an array cookie, bail out early. if (!requiresArrayCookie(expr, eltTy)) { - allocPtr = ptr.getPointer(); + allocPtr = ptr.getPointer(KnownNonNull_t::True); numElements = nullptr; cookieSize = CharUnits::Zero(); return; @@ -263,7 +263,7 @@ cookieSize = getArrayCookieSizeImpl(eltTy); Address allocAddr = CGF.Builder.CreateConstInBoundsByteGEP(ptr, -cookieSize); - allocPtr = allocAddr.getPointer(); + allocPtr = allocAddr.getPointer(KnownNonNull_t::True); numElements = readArrayCookieImpl(CGF, allocAddr, cookieSize); } Index: clang/lib/CodeGen/CGBuiltin.cpp =================================================================== --- clang/lib/CodeGen/CGBuiltin.cpp +++ clang/lib/CodeGen/CGBuiltin.cpp @@ -1841,7 +1841,8 @@ // Ignore argument 1, the format string. It is not currently used. CallArgList Args; - Args.add(RValue::get(BufAddr.getPointer()), Ctx.VoidPtrTy); + Args.add(RValue::get(BufAddr.getPointer(KnownNonNull_t::True)), + Ctx.VoidPtrTy); for (const auto &Item : Layout.Items) { int Size = Item.getSizeByte(); Index: clang/lib/CodeGen/CGBuilder.h =================================================================== --- clang/lib/CodeGen/CGBuilder.h +++ clang/lib/CodeGen/CGBuilder.h @@ -69,20 +69,22 @@ // Note that we intentionally hide the CreateLoad APIs that don't // take an alignment. llvm::LoadInst *CreateLoad(Address Addr, const llvm::Twine &Name = "") { - return CreateAlignedLoad(Addr.getElementType(), Addr.getPointer(), + return CreateAlignedLoad(Addr.getElementType(), + Addr.getPointer(KnownNonNull_t::True), Addr.getAlignment().getAsAlign(), Name); } llvm::LoadInst *CreateLoad(Address Addr, const char *Name) { // This overload is required to prevent string literals from // ending up in the IsVolatile overload. - return CreateAlignedLoad(Addr.getElementType(), Addr.getPointer(), + return CreateAlignedLoad(Addr.getElementType(), + Addr.getPointer(KnownNonNull_t::True), Addr.getAlignment().getAsAlign(), Name); } llvm::LoadInst *CreateLoad(Address Addr, bool IsVolatile, const llvm::Twine &Name = "") { - return CreateAlignedLoad(Addr.getElementType(), Addr.getPointer(), - Addr.getAlignment().getAsAlign(), IsVolatile, - Name); + return CreateAlignedLoad( + Addr.getElementType(), Addr.getPointer(KnownNonNull_t::True), + Addr.getAlignment().getAsAlign(), IsVolatile, Name); } using CGBuilderBaseTy::CreateAlignedLoad; @@ -98,7 +100,7 @@ // take an alignment. llvm::StoreInst *CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile = false) { - return CreateAlignedStore(Val, Addr.getPointer(), + return CreateAlignedStore(Val, Addr.getPointer(KnownNonNull_t::True), Addr.getAlignment().getAsAlign(), IsVolatile); } @@ -311,43 +313,47 @@ using CGBuilderBaseTy::CreateMemCpy; llvm::CallInst *CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile = false) { - return CreateMemCpy(Dest.getPointer(), Dest.getAlignment().getAsAlign(), - Src.getPointer(), Src.getAlignment().getAsAlign(), Size, - IsVolatile); + return CreateMemCpy(Dest.getPointer(KnownNonNull_t::True), + Dest.getAlignment().getAsAlign(), + Src.getPointer(KnownNonNull_t::True), + Src.getAlignment().getAsAlign(), Size, IsVolatile); } llvm::CallInst *CreateMemCpy(Address Dest, Address Src, uint64_t Size, bool IsVolatile = false) { - return CreateMemCpy(Dest.getPointer(), Dest.getAlignment().getAsAlign(), - Src.getPointer(), Src.getAlignment().getAsAlign(), Size, - IsVolatile); + return CreateMemCpy(Dest.getPointer(KnownNonNull_t::True), + Dest.getAlignment().getAsAlign(), + Src.getPointer(KnownNonNull_t::True), + Src.getAlignment().getAsAlign(), Size, IsVolatile); } using CGBuilderBaseTy::CreateMemCpyInline; llvm::CallInst *CreateMemCpyInline(Address Dest, Address Src, uint64_t Size) { - return CreateMemCpyInline( - Dest.getPointer(), Dest.getAlignment().getAsAlign(), Src.getPointer(), - Src.getAlignment().getAsAlign(), getInt64(Size)); + return CreateMemCpyInline(Dest.getPointer(KnownNonNull_t::True), + Dest.getAlignment().getAsAlign(), + Src.getPointer(KnownNonNull_t::True), + Src.getAlignment().getAsAlign(), getInt64(Size)); } using CGBuilderBaseTy::CreateMemMove; llvm::CallInst *CreateMemMove(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile = false) { - return CreateMemMove(Dest.getPointer(), Dest.getAlignment().getAsAlign(), - Src.getPointer(), Src.getAlignment().getAsAlign(), - Size, IsVolatile); + return CreateMemMove(Dest.getPointer(KnownNonNull_t::True), + Dest.getAlignment().getAsAlign(), + Src.getPointer(KnownNonNull_t::True), + Src.getAlignment().getAsAlign(), Size, IsVolatile); } using CGBuilderBaseTy::CreateMemSet; llvm::CallInst *CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile = false) { - return CreateMemSet(Dest.getPointer(), Value, Size, + return CreateMemSet(Dest.getPointer(KnownNonNull_t::True), Value, Size, Dest.getAlignment().getAsAlign(), IsVolatile); } using CGBuilderBaseTy::CreateMemSetInline; llvm::CallInst *CreateMemSetInline(Address Dest, llvm::Value *Value, uint64_t Size) { - return CreateMemSetInline(Dest.getPointer(), + return CreateMemSetInline(Dest.getPointer(KnownNonNull_t::True), Dest.getAlignment().getAsAlign(), Value, getInt64(Size)); } Index: clang/lib/CodeGen/CGBlocks.cpp =================================================================== --- clang/lib/CodeGen/CGBlocks.cpp +++ clang/lib/CodeGen/CGBlocks.cpp @@ -964,7 +964,8 @@ if (CI.isNested()) byrefPointer = Builder.CreateLoad(src, "byref.capture"); else - byrefPointer = Builder.CreateBitCast(src.getPointer(), VoidPtrTy); + byrefPointer = Builder.CreateBitCast( + src.getPointer(KnownNonNull_t::True), VoidPtrTy); // Write that void* into the capture field. Builder.CreateStore(byrefPointer, blockField); @@ -987,7 +988,7 @@ // If it's a reference variable, copy the reference into the block field. } else if (type->isReferenceType()) { - Builder.CreateStore(src.getPointer(), blockField); + Builder.CreateStore(src.getPointer(KnownNonNull_t::True), blockField); // If type is const-qualified, copy the value into the block field. } else if (type.isConstQualified() && @@ -1528,7 +1529,7 @@ // frame setup instruction by llvm::DwarfDebug::beginFunction(). auto NL = ApplyDebugLocation::CreateEmpty(*this); Builder.CreateStore(BlockPointer, Alloca); - BlockPointerDbgLoc = Alloca.getPointer(); + BlockPointerDbgLoc = Alloca.getPointer(KnownNonNull_t::True); } // If we have a C++ 'this' reference, go ahead and force it into @@ -1585,8 +1586,8 @@ const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable); if (capture.isConstant()) { auto addr = LocalDeclMap.find(variable)->second; - (void)DI->EmitDeclareOfAutoVariable(variable, addr.getPointer(), - Builder); + (void)DI->EmitDeclareOfAutoVariable( + variable, addr.getPointer(KnownNonNull_t::True), Builder); continue; } @@ -1691,7 +1692,7 @@ BlockVarAddr = CGF.Builder.CreateLoad(Addr); BlockVarAddr = CGF.Builder.CreateBitCast(BlockVarAddr, CGF.VoidPtrTy); } else { - BlockVarAddr = Addr.getPointer(); + BlockVarAddr = Addr.getPointer(KnownNonNull_t::True); } CGF.BuildBlockRelease(BlockVarAddr, FieldFlags, CanThrow); @@ -2000,8 +2001,8 @@ case BlockCaptureEntityKind::BlockObject: { llvm::Value *srcValue = Builder.CreateLoad(srcField, "blockcopy.src"); srcValue = Builder.CreateBitCast(srcValue, VoidPtrTy); - llvm::Value *dstAddr = - Builder.CreateBitCast(dstField.getPointer(), VoidPtrTy); + llvm::Value *dstAddr = Builder.CreateBitCast( + dstField.getPointer(KnownNonNull_t::True), VoidPtrTy); llvm::Value *args[] = { dstAddr, srcValue, llvm::ConstantInt::get(Int32Ty, flags.getBitMask()) }; @@ -2172,7 +2173,8 @@ llvm::Value *flagsVal = llvm::ConstantInt::get(CGF.Int32Ty, flags); llvm::FunctionCallee fn = CGF.CGM.getBlockObjectAssign(); - llvm::Value *args[] = { destField.getPointer(), srcValue, flagsVal }; + llvm::Value *args[] = {destField.getPointer(KnownNonNull_t::True), srcValue, + flagsVal}; CGF.EmitNounwindRuntimeCall(fn, args); } @@ -2732,7 +2734,8 @@ storeHeaderField(V, getPointerSize(), "byref.isa"); // Store the address of the variable into its own forwarding pointer. - storeHeaderField(addr.getPointer(), getPointerSize(), "byref.forwarding"); + storeHeaderField(addr.getPointer(KnownNonNull_t::True), getPointerSize(), + "byref.forwarding"); // Blocks ABI: // c) the flags field is set to either 0 if no helper functions are Index: clang/lib/CodeGen/Address.h =================================================================== --- clang/lib/CodeGen/Address.h +++ clang/lib/CodeGen/Address.h @@ -22,6 +22,9 @@ namespace clang { namespace CodeGen { +// Indicates whether a pointer is known not to be null. +enum class KnownNonNull_t { False, True }; + // We try to save some space by using 6 bits over two PointerIntPairs to store // the alignment. However, some arches don't support 3 bits in a PointerIntPair // so we fallback to storing the alignment separately. @@ -90,7 +93,8 @@ static Address invalid() { return Address(nullptr); } bool isValid() const { return A.getPointer() != nullptr; } - llvm::Value *getPointer() const { + llvm::Value * + getPointer(KnownNonNull_t KnownNonNull = KnownNonNull_t::False) const { assert(isValid()); return A.getPointer(); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits