diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/CodeGen/CGObjC.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/CodeGen/CGObjC.cpp | 196 |
1 files changed, 103 insertions, 93 deletions
diff --git a/contrib/llvm/tools/clang/lib/CodeGen/CGObjC.cpp b/contrib/llvm/tools/clang/lib/CodeGen/CGObjC.cpp index 0bda053..8ca8080 100644 --- a/contrib/llvm/tools/clang/lib/CodeGen/CGObjC.cpp +++ b/contrib/llvm/tools/clang/lib/CodeGen/CGObjC.cpp @@ -22,7 +22,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/CodeGen/CGFunctionInfo.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/Support/CallSite.h" +#include "llvm/IR/CallSite.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/InlineAsm.h" using namespace clang; @@ -79,10 +79,10 @@ CodeGenFunction::EmitObjCBoxedExpr(const ObjCBoxedExpr *E) { RValue RV = EmitAnyExpr(SubExpr); CallArgList Args; Args.add(RV, ArgQT); - - RValue result = Runtime.GenerateMessageSend(*this, ReturnValueSlot(), - BoxingMethod->getResultType(), Sel, Receiver, Args, - ClassDecl, BoxingMethod); + + RValue result = Runtime.GenerateMessageSend( + *this, ReturnValueSlot(), BoxingMethod->getReturnType(), Sel, Receiver, + Args, ClassDecl, BoxingMethod); return Builder.CreateBitCast(result.getScalarVal(), ConvertType(E->getType())); } @@ -90,7 +90,7 @@ CodeGenFunction::EmitObjCBoxedExpr(const ObjCBoxedExpr *E) { llvm::Value *CodeGenFunction::EmitObjCCollectionLiteral(const Expr *E, const ObjCMethodDecl *MethodWithObjects) { ASTContext &Context = CGM.getContext(); - const ObjCDictionaryLiteral *DLE = 0; + const ObjCDictionaryLiteral *DLE = nullptr; const ObjCArrayLiteral *ALE = dyn_cast<ObjCArrayLiteral>(E); if (!ALE) DLE = cast<ObjCDictionaryLiteral>(E); @@ -106,8 +106,8 @@ llvm::Value *CodeGenFunction::EmitObjCCollectionLiteral(const Expr *E, ArrayType::Normal, /*IndexTypeQuals=*/0); // Allocate the temporary array(s). - llvm::Value *Objects = CreateMemTemp(ElementArrayType, "objects"); - llvm::Value *Keys = 0; + llvm::Value *Objects = CreateMemTemp(ElementArrayType, "objects"); + llvm::Value *Keys = nullptr; if (DLE) Keys = CreateMemTemp(ElementArrayType, "keys"); @@ -186,12 +186,9 @@ llvm::Value *CodeGenFunction::EmitObjCCollectionLiteral(const Expr *E, llvm::Value *Receiver = Runtime.GetClass(*this, Class); // Generate the message send. - RValue result - = Runtime.GenerateMessageSend(*this, ReturnValueSlot(), - MethodWithObjects->getResultType(), - Sel, - Receiver, Args, Class, - MethodWithObjects); + RValue result = Runtime.GenerateMessageSend( + *this, ReturnValueSlot(), MethodWithObjects->getReturnType(), Sel, + Receiver, Args, Class, MethodWithObjects); // The above message send needs these objects, but in ARC they are // passed in a buffer that is essentially __unsafe_unretained. @@ -238,7 +235,7 @@ static RValue AdjustRelatedResultType(CodeGenFunction &CGF, return Result; if (!Method->hasRelatedResultType() || - CGF.getContext().hasSameType(ExpT, Method->getResultType()) || + CGF.getContext().hasSameType(ExpT, Method->getReturnType()) || !Result.isScalar()) return Result; @@ -317,10 +314,10 @@ RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E, CGObjCRuntime &Runtime = CGM.getObjCRuntime(); bool isSuperMessage = false; bool isClassMessage = false; - ObjCInterfaceDecl *OID = 0; + ObjCInterfaceDecl *OID = nullptr; // Find the receiver QualType ReceiverType; - llvm::Value *Receiver = 0; + llvm::Value *Receiver = nullptr; switch (E->getReceiverKind()) { case ObjCMessageExpr::Instance: ReceiverType = E->getInstanceReceiver()->getType(); @@ -369,8 +366,7 @@ RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E, shouldExtendReceiverForInnerPointerMessage(E)) Receiver = EmitARCRetainAutorelease(ReceiverType, Receiver); - QualType ResultType = - method ? method->getResultType() : E->getType(); + QualType ResultType = method ? method->getReturnType() : E->getType(); CallArgList Args; EmitCallArgs(Args, method, E->arg_begin(), E->arg_end()); @@ -435,7 +431,7 @@ RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E, namespace { struct FinishARCDealloc : EHScopeStack::Cleanup { - void Emit(CodeGenFunction &CGF, Flags flags) { + void Emit(CodeGenFunction &CGF, Flags flags) override { const ObjCMethodDecl *method = cast<ObjCMethodDecl>(CGF.CurCodeDecl); const ObjCImplDecl *impl = cast<ObjCImplDecl>(method->getDeclContext()); @@ -470,7 +466,7 @@ void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD, FunctionArgList args; // Check if we should generate debug info for this method. if (OMD->hasAttr<NoDebugAttr>()) - DebugInfo = NULL; // disable debug info indefinitely for this function + DebugInfo = nullptr; // disable debug info indefinitely for this function llvm::Function *Fn = CGM.getObjCRuntime().GenerateMethod(OMD, CD); @@ -480,13 +476,13 @@ void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD, args.push_back(OMD->getSelfDecl()); args.push_back(OMD->getCmdDecl()); - for (ObjCMethodDecl::param_const_iterator PI = OMD->param_begin(), - E = OMD->param_end(); PI != E; ++PI) - args.push_back(*PI); + for (const auto *PI : OMD->params()) + args.push_back(PI); CurGD = OMD; - StartFunction(OMD, OMD->getResultType(), Fn, FI, args, StartLoc); + StartFunction(OMD, OMD->getReturnType(), Fn, FI, args, + OMD->getLocation(), StartLoc); // In ARC, certain methods get an extra cleanup. if (CGM.getLangOpts().ObjCAutoRefCount && @@ -506,8 +502,14 @@ static llvm::Value *emitARCRetainLoadOfScalar(CodeGenFunction &CGF, /// its pointer, name, and types registered in the class struture. void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) { StartObjCMethod(OMD, OMD->getClassInterface(), OMD->getLocStart()); - EmitStmt(OMD->getBody()); + PGO.assignRegionCounters(OMD, CurFn); + assert(isa<CompoundStmt>(OMD->getBody())); + RegionCounter Cnt = getPGORegionCounter(OMD->getBody()); + Cnt.beginRegion(Builder); + EmitCompoundStmtWithoutScope(*cast<CompoundStmt>(OMD->getBody())); FinishFunction(OMD->getBodyRBrace()); + PGO.emitInstrumentationData(); + PGO.destroyRegionCounters(); } /// emitStructGetterCall - Call the runtime function to load a property @@ -622,8 +624,8 @@ PropertyImplStrategy::PropertyImplStrategy(CodeGenModule &CGM, // Evaluate the ivar's size and alignment. ObjCIvarDecl *ivar = propImpl->getPropertyIvarDecl(); QualType ivarType = ivar->getType(); - llvm::tie(IvarSize, IvarAlignment) - = CGM.getContext().getTypeInfoInChars(ivarType); + std::tie(IvarSize, IvarAlignment) = + CGM.getContext().getTypeInfoInChars(ivarType); // If we have a copy property, we always have to use getProperty/setProperty. // TODO: we could actually use setProperty and an expression for non-atomics. @@ -818,7 +820,7 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl, if (!hasTrivialGetExpr(propImpl)) { if (!AtomicHelperFn) { ReturnStmt ret(SourceLocation(), propImpl->getGetterCXXConstructor(), - /*nrvo*/ 0); + /*nrvo*/ nullptr); EmitReturnStmt(ret); } else { @@ -895,16 +897,21 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl, // FIXME: We shouldn't need to get the function info here, the // runtime already should have computed it to build the function. + llvm::Instruction *CallInstruction; RValue RV = EmitCall(getTypes().arrangeFreeFunctionCall(propType, args, FunctionType::ExtInfo(), RequiredArgs::All), - getPropertyFn, ReturnValueSlot(), args); + getPropertyFn, ReturnValueSlot(), args, nullptr, + &CallInstruction); + if (llvm::CallInst *call = dyn_cast<llvm::CallInst>(CallInstruction)) + call->setTailCall(); // We need to fix the type here. Ivars with copy & retain are // always objects so we don't need to worry about complex or // aggregates. - RV = RValue::get(Builder.CreateBitCast(RV.getScalarVal(), - getTypes().ConvertType(getterMethod->getResultType()))); + RV = RValue::get(Builder.CreateBitCast( + RV.getScalarVal(), + getTypes().ConvertType(getterMethod->getReturnType()))); EmitReturnOfRValue(RV, propType); @@ -955,8 +962,8 @@ CodeGenFunction::generateObjCGetterBody(const ObjCImplementationDecl *classImpl, } value = Builder.CreateBitCast(value, ConvertType(propType)); - value = Builder.CreateBitCast(value, - ConvertType(GetterMethodDecl->getResultType())); + value = Builder.CreateBitCast( + value, ConvertType(GetterMethodDecl->getReturnType())); } EmitReturnOfRValue(RValue::get(value), propType); @@ -1139,9 +1146,9 @@ CodeGenFunction::generateObjCSetterBody(const ObjCImplementationDecl *classImpl, case PropertyImplStrategy::GetSetProperty: case PropertyImplStrategy::SetPropertyAndExpressionGet: { - - llvm::Value *setOptimizedPropertyFn = 0; - llvm::Value *setPropertyFn = 0; + + llvm::Value *setOptimizedPropertyFn = nullptr; + llvm::Value *setPropertyFn = nullptr; if (UseOptimizedSetter(CGM)) { // 10.8 and iOS 6.0 code and GC is off setOptimizedPropertyFn = @@ -1292,7 +1299,7 @@ namespace { : addr(addr), ivar(ivar), destroyer(destroyer), useEHCleanupForArray(useEHCleanupForArray) {} - void Emit(CodeGenFunction &CGF, Flags flags) { + void Emit(CodeGenFunction &CGF, Flags flags) override { LValue lvalue = CGF.EmitLValueForIvar(CGF.TypeOfSelfObject(), addr, ivar, /*CVR*/ 0); CGF.emitDestroy(lvalue.getAddress(), ivar->getType(), destroyer, @@ -1324,7 +1331,7 @@ static void emitCXXDestructMethod(CodeGenFunction &CGF, QualType::DestructionKind dtorKind = type.isDestructedType(); if (!dtorKind) continue; - CodeGenFunction::Destroyer *destroyer = 0; + CodeGenFunction::Destroyer *destroyer = nullptr; // Use a call to objc_storeStrong to destroy strong ivars, for the // general benefit of the tools. @@ -1356,12 +1363,9 @@ void CodeGenFunction::GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, // Suppress the final autorelease in ARC. AutoreleaseResult = false; - SmallVector<CXXCtorInitializer *, 8> IvarInitializers; - for (ObjCImplementationDecl::init_const_iterator B = IMP->init_begin(), - E = IMP->init_end(); B != E; ++B) { - CXXCtorInitializer *IvarInit = (*B); + for (const auto *IvarInit : IMP->inits()) { FieldDecl *Field = IvarInit->getAnyMember(); - ObjCIvarDecl *Ivar = cast<ObjCIvarDecl>(Field); + ObjCIvarDecl *Ivar = cast<ObjCIvarDecl>(Field); LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), Ivar, 0); EmitAggExpr(IvarInit->getInit(), @@ -1506,9 +1510,13 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){ llvm::Value *zero = llvm::Constant::getNullValue(UnsignedLongLTy); // If the limit pointer was zero to begin with, the collection is - // empty; skip all this. + // empty; skip all this. Set the branch weight assuming this has the same + // probability of exiting the loop as any other loop exit. + uint64_t EntryCount = PGO.getCurrentRegionCount(); + RegionCounter Cnt = getPGORegionCounter(&S); Builder.CreateCondBr(Builder.CreateICmpEQ(initialBufferLimit, zero, "iszero"), - EmptyBB, LoopInitBB); + EmptyBB, LoopInitBB, + PGO.createBranchWeights(EntryCount, Cnt.getCount())); // Otherwise, initialize the loop. EmitBlock(LoopInitBB); @@ -1537,6 +1545,8 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){ llvm::PHINode *count = Builder.CreatePHI(UnsignedLongLTy, 3, "forcoll.count"); count->addIncoming(initialBufferLimit, LoopInitBB); + Cnt.beginRegion(Builder); + // Check whether the mutations value has changed from where it was // at start. StateMutationsPtr should actually be invariant between // refreshes. @@ -1644,8 +1654,12 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){ = Builder.CreateAdd(index, llvm::ConstantInt::get(UnsignedLongLTy, 1)); // If we haven't overrun the buffer yet, we can continue. + // Set the branch weights based on the simplifying assumption that this is + // like a while-loop, i.e., ignoring that the false branch fetches more + // elements and then returns to the loop. Builder.CreateCondBr(Builder.CreateICmpULT(indexPlusOne, count), - LoopBodyBB, FetchMoreBB); + LoopBodyBB, FetchMoreBB, + PGO.createBranchWeights(Cnt.getCount(), EntryCount)); index->addIncoming(indexPlusOne, AfterBody.getBlock()); count->addIncoming(count, AfterBody.getBlock()); @@ -1715,7 +1729,7 @@ namespace { CallObjCRelease(llvm::Value *object) : object(object) {} llvm::Value *object; - void Emit(CodeGenFunction &CGF, Flags flags) { + void Emit(CodeGenFunction &CGF, Flags flags) override { // Releases at the end of the full-expression are imprecise. CGF.EmitARCRelease(object, ARCImpreciseLifetime); } @@ -1857,7 +1871,7 @@ static llvm::Value *emitARCStoreOperation(CodeGenFunction &CGF, }; llvm::CallInst *result = CGF.EmitNounwindRuntimeCall(fn, args); - if (ignored) return 0; + if (ignored) return nullptr; return CGF.Builder.CreateBitCast(result, origType); } @@ -2055,7 +2069,7 @@ llvm::Value *CodeGenFunction::EmitARCStoreStrongCall(llvm::Value *addr, }; EmitNounwindRuntimeCall(fn, args); - if (ignored) return 0; + if (ignored) return nullptr; return value; } @@ -2324,7 +2338,7 @@ namespace { CallObjCAutoreleasePoolObject(llvm::Value *token) : Token(token) {} - void Emit(CodeGenFunction &CGF, Flags flags) { + void Emit(CodeGenFunction &CGF, Flags flags) override { CGF.EmitObjCAutoreleasePoolPop(Token); } }; @@ -2333,7 +2347,7 @@ namespace { CallObjCMRRAutoreleasePoolObject(llvm::Value *token) : Token(token) {} - void Emit(CodeGenFunction &CGF, Flags flags) { + void Emit(CodeGenFunction &CGF, Flags flags) override { CGF.EmitObjCMRRAutoreleasePoolPop(Token); } }; @@ -2550,7 +2564,7 @@ tryEmitARCRetainScalarExpr(CodeGenFunction &CGF, const Expr *e) { // The desired result type, if it differs from the type of the // ultimate opaque expression. - llvm::Type *resultType = 0; + llvm::Type *resultType = nullptr; while (true) { e = e->IgnoreParens(); @@ -2824,9 +2838,8 @@ void CodeGenFunction::EmitObjCAutoreleasePoolStmt( EHStack.pushCleanup<CallObjCMRRAutoreleasePoolObject>(NormalCleanup, token); } - for (CompoundStmt::const_body_iterator I = S.body_begin(), - E = S.body_end(); I != E; ++I) - EmitStmt(*I); + for (const auto *I : S.body()) + EmitStmt(I); if (DI) DI->EmitLexicalBlockEnd(Builder, S.getRBracLoc()); @@ -2857,16 +2870,16 @@ CodeGenFunction::GenerateObjCAtomicSetterCopyHelperFunction( const ObjCPropertyImplDecl *PID) { if (!getLangOpts().CPlusPlus || !getLangOpts().ObjCRuntime.hasAtomicCopyHelper()) - return 0; + return nullptr; QualType Ty = PID->getPropertyIvarDecl()->getType(); if (!Ty->isRecordType()) - return 0; + return nullptr; const ObjCPropertyDecl *PD = PID->getPropertyDecl(); if ((!(PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_atomic))) - return 0; - llvm::Constant * HelperFn = 0; + return nullptr; + llvm::Constant *HelperFn = nullptr; if (hasTrivialSetExpr(PID)) - return 0; + return nullptr; assert(PID->getSetterCXXAssignment() && "SetterCXXAssignment - null"); if ((HelperFn = CGM.getAtomicSetterHelperFnMap(Ty))) return HelperFn; @@ -2877,27 +2890,25 @@ CodeGenFunction::GenerateObjCAtomicSetterCopyHelperFunction( FunctionDecl *FD = FunctionDecl::Create(C, C.getTranslationUnitDecl(), SourceLocation(), - SourceLocation(), II, C.VoidTy, 0, - SC_Static, + SourceLocation(), II, C.VoidTy, + nullptr, SC_Static, false, false); - + QualType DestTy = C.getPointerType(Ty); QualType SrcTy = Ty; SrcTy.addConst(); SrcTy = C.getPointerType(SrcTy); FunctionArgList args; - ImplicitParamDecl dstDecl(FD, SourceLocation(), 0, DestTy); + ImplicitParamDecl dstDecl(getContext(), FD, SourceLocation(), nullptr,DestTy); args.push_back(&dstDecl); - ImplicitParamDecl srcDecl(FD, SourceLocation(), 0, SrcTy); + ImplicitParamDecl srcDecl(getContext(), FD, SourceLocation(), nullptr, SrcTy); args.push_back(&srcDecl); - - const CGFunctionInfo &FI = - CGM.getTypes().arrangeFunctionDeclaration(C.VoidTy, args, - FunctionType::ExtInfo(), - RequiredArgs::All); - + + const CGFunctionInfo &FI = CGM.getTypes().arrangeFreeFunctionDeclaration( + C.VoidTy, args, FunctionType::ExtInfo(), RequiredArgs::All); + llvm::FunctionType *LTy = CGM.getTypes().GetFunctionType(FI); llvm::Function *Fn = @@ -2905,7 +2916,7 @@ CodeGenFunction::GenerateObjCAtomicSetterCopyHelperFunction( "__assign_helper_atomic_property_", &CGM.getModule()); - StartFunction(FD, C.VoidTy, Fn, FI, args, SourceLocation()); + StartFunction(FD, C.VoidTy, Fn, FI, args); DeclRefExpr DstExpr(&dstDecl, false, DestTy, VK_RValue, SourceLocation()); @@ -2936,17 +2947,17 @@ CodeGenFunction::GenerateObjCAtomicGetterCopyHelperFunction( const ObjCPropertyImplDecl *PID) { if (!getLangOpts().CPlusPlus || !getLangOpts().ObjCRuntime.hasAtomicCopyHelper()) - return 0; + return nullptr; const ObjCPropertyDecl *PD = PID->getPropertyDecl(); QualType Ty = PD->getType(); if (!Ty->isRecordType()) - return 0; + return nullptr; if ((!(PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_atomic))) - return 0; - llvm::Constant * HelperFn = 0; - + return nullptr; + llvm::Constant *HelperFn = nullptr; + if (hasTrivialGetExpr(PID)) - return 0; + return nullptr; assert(PID->getGetterCXXConstructor() && "getGetterCXXConstructor - null"); if ((HelperFn = CGM.getAtomicGetterHelperFnMap(Ty))) return HelperFn; @@ -2958,34 +2969,32 @@ CodeGenFunction::GenerateObjCAtomicGetterCopyHelperFunction( FunctionDecl *FD = FunctionDecl::Create(C, C.getTranslationUnitDecl(), SourceLocation(), - SourceLocation(), II, C.VoidTy, 0, - SC_Static, + SourceLocation(), II, C.VoidTy, + nullptr, SC_Static, false, false); - + QualType DestTy = C.getPointerType(Ty); QualType SrcTy = Ty; SrcTy.addConst(); SrcTy = C.getPointerType(SrcTy); FunctionArgList args; - ImplicitParamDecl dstDecl(FD, SourceLocation(), 0, DestTy); + ImplicitParamDecl dstDecl(getContext(), FD, SourceLocation(), nullptr,DestTy); args.push_back(&dstDecl); - ImplicitParamDecl srcDecl(FD, SourceLocation(), 0, SrcTy); + ImplicitParamDecl srcDecl(getContext(), FD, SourceLocation(), nullptr, SrcTy); args.push_back(&srcDecl); - - const CGFunctionInfo &FI = - CGM.getTypes().arrangeFunctionDeclaration(C.VoidTy, args, - FunctionType::ExtInfo(), - RequiredArgs::All); - + + const CGFunctionInfo &FI = CGM.getTypes().arrangeFreeFunctionDeclaration( + C.VoidTy, args, FunctionType::ExtInfo(), RequiredArgs::All); + llvm::FunctionType *LTy = CGM.getTypes().GetFunctionType(FI); llvm::Function *Fn = llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage, "__copy_helper_atomic_property_", &CGM.getModule()); - StartFunction(FD, C.VoidTy, Fn, FI, args, SourceLocation()); + StartFunction(FD, C.VoidTy, Fn, FI, args); DeclRefExpr SrcExpr(&srcDecl, false, SrcTy, VK_RValue, SourceLocation()); @@ -3012,6 +3021,7 @@ CodeGenFunction::GenerateObjCAtomicGetterCopyHelperFunction( ConstructorArgs, CXXConstExpr->hadMultipleCandidates(), CXXConstExpr->isListInitialization(), + CXXConstExpr->isStdInitListInitialization(), CXXConstExpr->requiresZeroInitialization(), CXXConstExpr->getConstructionKind(), SourceRange()); @@ -3050,11 +3060,11 @@ CodeGenFunction::EmitBlockCopyAndAutorelease(llvm::Value *Block, QualType Ty) { RValue Result; Result = Runtime.GenerateMessageSend(*this, ReturnValueSlot(), Ty, CopySelector, - Val, CallArgList(), 0, 0); + Val, CallArgList(), nullptr, nullptr); Val = Result.getScalarVal(); Result = Runtime.GenerateMessageSend(*this, ReturnValueSlot(), Ty, AutoreleaseSelector, - Val, CallArgList(), 0, 0); + Val, CallArgList(), nullptr, nullptr); Val = Result.getScalarVal(); return Val; } |