From 9f569d45e0e42bcf60fe8f43b847a133a1a38c12 Mon Sep 17 00:00:00 2001 From: Bruno Ricci Date: Fri, 21 Dec 2018 15:20:32 +0000 Subject: [AST] Store the callee and argument expressions of CallExpr in a trailing array. Since CallExpr::setNumArgs has been removed, it is now possible to store the callee expression and the argument expressions of CallExpr in a trailing array. This saves one pointer per CallExpr, CXXOperatorCallExpr, CXXMemberCallExpr, CUDAKernelCallExpr and UserDefinedLiteral. Given that CallExpr is used as a base of the above classes we cannot use llvm::TrailingObjects. Instead we store the offset in bytes from the this pointer to the start of the trailing objects and manually do the casts + arithmetic. Some notes: 1.) I did not try to fit the number of arguments in the bit-fields of Stmt. This leaves some space for future additions and avoid the discussion about whether x bits are sufficient to hold the number of arguments. 2.) It would be perfectly possible to recompute the offset to the trailing objects before accessing the trailing objects. However the trailing objects are frequently accessed and benchmarks show that it is slightly faster to just load the offset from the bit-fields. Additionally, because of 1), we have plenty of space in the bit-fields of Stmt. Differential Revision: https://reviews.llvm.org/D55771 Reviewed By: rjmccall git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349910 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/Rewrite/RewriteModernObjC.cpp | 67 ++++++++++++++---------------- lib/Frontend/Rewrite/RewriteObjC.cpp | 37 ++++++++--------- 2 files changed, 48 insertions(+), 56 deletions(-) (limited to 'lib/Frontend') diff --git a/lib/Frontend/Rewrite/RewriteModernObjC.cpp b/lib/Frontend/Rewrite/RewriteModernObjC.cpp index 9ed8b1568b..10ca9a7856 100644 --- a/lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -2107,9 +2107,8 @@ RewriteModernObjC::SynthesizeCallToFunctionDecl(FunctionDecl *FD, const FunctionType *FT = msgSendType->getAs(); - CallExpr *Exp = new (Context) CallExpr(*Context, ICE, Args, - FT->getCallResultType(*Context), - VK_RValue, EndLoc); + CallExpr *Exp = CallExpr::Create( + *Context, ICE, Args, FT->getCallResultType(*Context), VK_RValue, EndLoc); return Exp; } @@ -2689,8 +2688,8 @@ Stmt *RewriteModernObjC::RewriteObjCBoxedExpr(ObjCBoxedExpr *Exp) { ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs(); - CallExpr *CE = new (Context) - CallExpr(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); + CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), + VK_RValue, EndLoc); ReplaceStmt(Exp, CE); return CE; } @@ -2729,8 +2728,8 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { for (unsigned i = 0; i < NumElements; i++) InitExprs.push_back(Exp->getElement(i)); Expr *NSArrayCallExpr = - new (Context) CallExpr(*Context, NSArrayDRE, InitExprs, - NSArrayFType, VK_LValue, SourceLocation()); + CallExpr::Create(*Context, NSArrayDRE, InitExprs, NSArrayFType, VK_LValue, + SourceLocation()); FieldDecl *ARRFD = FieldDecl::Create(*Context, nullptr, SourceLocation(), SourceLocation(), @@ -2810,8 +2809,8 @@ Stmt *RewriteModernObjC::RewriteObjCArrayLiteralExpr(ObjCArrayLiteral *Exp) { ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs(); - CallExpr *CE = new (Context) - CallExpr(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); + CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), + VK_RValue, EndLoc); ReplaceStmt(Exp, CE); return CE; } @@ -2858,8 +2857,8 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral // (const id [])objects Expr *NSValueCallExpr = - new (Context) CallExpr(*Context, NSDictDRE, ValueExprs, - NSDictFType, VK_LValue, SourceLocation()); + CallExpr::Create(*Context, NSDictDRE, ValueExprs, NSDictFType, VK_LValue, + SourceLocation()); FieldDecl *ARRFD = FieldDecl::Create(*Context, nullptr, SourceLocation(), SourceLocation(), @@ -2877,9 +2876,8 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral CK_BitCast, DictLiteralValueME); // (const id [])keys - Expr *NSKeyCallExpr = - new (Context) CallExpr(*Context, NSDictDRE, KeyExprs, - NSDictFType, VK_LValue, SourceLocation()); + Expr *NSKeyCallExpr = CallExpr::Create( + *Context, NSDictDRE, KeyExprs, NSDictFType, VK_LValue, SourceLocation()); MemberExpr *DictLiteralKeyME = new (Context) MemberExpr(NSKeyCallExpr, false, SourceLocation(), ARRFD, @@ -2962,8 +2960,8 @@ Stmt *RewriteModernObjC::RewriteObjCDictionaryLiteralExpr(ObjCDictionaryLiteral ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs(); - CallExpr *CE = new (Context) - CallExpr(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); + CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), + VK_RValue, EndLoc); ReplaceStmt(Exp, CE); return CE; } @@ -3172,10 +3170,10 @@ Expr *RewriteModernObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFla FunctionDecl *FD = FunctionDecl::Create(*Context, TUDecl, SourceLocation(), SourceLocation(), ID, FuncType, nullptr, SC_Extern, false, false); - DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, FD, false, castType, - VK_RValue, SourceLocation()); - CallExpr *STCE = new (Context) CallExpr(*Context, DRE, MsgExprs, - castType, VK_LValue, SourceLocation()); + DeclRefExpr *DRE = new (Context) + DeclRefExpr(*Context, FD, false, castType, VK_RValue, SourceLocation()); + CallExpr *STCE = CallExpr::Create(*Context, DRE, MsgExprs, castType, + VK_LValue, SourceLocation()); FieldDecl *FieldD = FieldDecl::Create(*Context, nullptr, SourceLocation(), SourceLocation(), @@ -3276,9 +3274,8 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, SuperConstructorFunctionDecl, false, superType, VK_LValue, SourceLocation()); - SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, - superType, VK_LValue, - SourceLocation()); + SuperRep = CallExpr::Create(*Context, DRE, InitExprs, superType, + VK_LValue, SourceLocation()); // The code for super is a little tricky to prevent collision with // the structure definition in the header. The rewriter has it's own // internal definition (__rw_objc_super) that is uses. This is why @@ -3369,12 +3366,11 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, if (LangOpts.MicrosoftExt) { SynthSuperConstructorFunctionDecl(); // Simulate a constructor call... - DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, - SuperConstructorFunctionDecl, - false, superType, VK_LValue, - SourceLocation()); - SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, - superType, VK_LValue, SourceLocation()); + DeclRefExpr *DRE = new (Context) + DeclRefExpr(*Context, SuperConstructorFunctionDecl, false, superType, + VK_LValue, SourceLocation()); + SuperRep = CallExpr::Create(*Context, DRE, InitExprs, superType, + VK_LValue, SourceLocation()); // The code for super is a little tricky to prevent collision with // the structure definition in the header. The rewriter has it's own // internal definition (__rw_objc_super) that is uses. This is why @@ -3538,8 +3534,8 @@ Stmt *RewriteModernObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs(); - CallExpr *CE = new (Context) - CallExpr(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); + CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), + VK_RValue, EndLoc); Stmt *ReplacingStmt = CE; if (MsgSendStretFlavor) { // We have the method which returns a struct/union. Must also generate @@ -4650,9 +4646,8 @@ Stmt *RewriteModernObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp E = Exp->arg_end(); I != E; ++I) { BlkExprs.push_back(*I); } - CallExpr *CE = new (Context) CallExpr(*Context, PE, BlkExprs, - Exp->getType(), VK_RValue, - SourceLocation()); + CallExpr *CE = CallExpr::Create(*Context, PE, BlkExprs, Exp->getType(), + VK_RValue, SourceLocation()); return CE; } @@ -5395,8 +5390,8 @@ Stmt *RewriteModernObjC::SynthBlockInitExpr(BlockExpr *Exp, Context->IntTy, SourceLocation()); InitExprs.push_back(FlagExp); } - NewRep = new (Context) CallExpr(*Context, DRE, InitExprs, - FType, VK_LValue, SourceLocation()); + NewRep = CallExpr::Create(*Context, DRE, InitExprs, FType, VK_LValue, + SourceLocation()); if (GlobalBlockExpr) { assert (!GlobalConstructionExp && diff --git a/lib/Frontend/Rewrite/RewriteObjC.cpp b/lib/Frontend/Rewrite/RewriteObjC.cpp index 0bbf4266fd..3e018800b9 100644 --- a/lib/Frontend/Rewrite/RewriteObjC.cpp +++ b/lib/Frontend/Rewrite/RewriteObjC.cpp @@ -2020,9 +2020,8 @@ RewriteObjC::SynthesizeCallToFunctionDecl(FunctionDecl *FD, const FunctionType *FT = msgSendType->getAs(); - CallExpr *Exp = new (Context) CallExpr(*Context, ICE, Args, - FT->getCallResultType(*Context), - VK_RValue, EndLoc); + CallExpr *Exp = CallExpr::Create( + *Context, ICE, Args, FT->getCallResultType(*Context), VK_RValue, EndLoc); return Exp; } @@ -2607,8 +2606,8 @@ CallExpr *RewriteObjC::SynthMsgSendStretCallExpr(FunctionDecl *MsgSendStretFlavo ParenExpr *PE = new (Context) ParenExpr(SourceLocation(), SourceLocation(), cast); const FunctionType *FT = msgSendType->getAs(); - CallExpr *STCE = new (Context) CallExpr( - *Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, SourceLocation()); + CallExpr *STCE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), + VK_RValue, SourceLocation()); return STCE; } @@ -2700,9 +2699,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, SuperConstructorFunctionDecl, false, superType, VK_LValue, SourceLocation()); - SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, - superType, VK_LValue, - SourceLocation()); + SuperRep = CallExpr::Create(*Context, DRE, InitExprs, superType, + VK_LValue, SourceLocation()); // The code for super is a little tricky to prevent collision with // the structure definition in the header. The rewriter has it's own // internal definition (__rw_objc_super) that is uses. This is why @@ -2796,8 +2794,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, DeclRefExpr *DRE = new (Context) DeclRefExpr(*Context, SuperConstructorFunctionDecl, false, superType, VK_LValue, SourceLocation()); - SuperRep = new (Context) CallExpr(*Context, DRE, InitExprs, - superType, VK_LValue, SourceLocation()); + SuperRep = CallExpr::Create(*Context, DRE, InitExprs, superType, + VK_LValue, SourceLocation()); // The code for super is a little tricky to prevent collision with // the structure definition in the header. The rewriter has it's own // internal definition (__rw_objc_super) that is uses. This is why @@ -2961,8 +2959,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp, ParenExpr *PE = new (Context) ParenExpr(StartLoc, EndLoc, cast); const FunctionType *FT = msgSendType->getAs(); - CallExpr *CE = new (Context) - CallExpr(*Context, PE, MsgExprs, FT->getReturnType(), VK_RValue, EndLoc); + CallExpr *CE = CallExpr::Create(*Context, PE, MsgExprs, FT->getReturnType(), + VK_RValue, EndLoc); Stmt *ReplacingStmt = CE; if (MsgSendStretFlavor) { // We have the method which returns a struct/union. Must also generate @@ -3812,9 +3810,8 @@ Stmt *RewriteObjC::SynthesizeBlockCall(CallExpr *Exp, const Expr *BlockExp) { E = Exp->arg_end(); I != E; ++I) { BlkExprs.push_back(*I); } - CallExpr *CE = new (Context) CallExpr(*Context, PE, BlkExprs, - Exp->getType(), VK_RValue, - SourceLocation()); + CallExpr *CE = CallExpr::Create(*Context, PE, BlkExprs, Exp->getType(), + VK_RValue, SourceLocation()); return CE; } @@ -4524,11 +4521,11 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp, Context->IntTy, SourceLocation()); InitExprs.push_back(FlagExp); } - NewRep = new (Context) CallExpr(*Context, DRE, InitExprs, - FType, VK_LValue, SourceLocation()); - NewRep = new (Context) UnaryOperator(NewRep, UO_AddrOf, - Context->getPointerType(NewRep->getType()), - VK_RValue, OK_Ordinary, SourceLocation(), false); + NewRep = CallExpr::Create(*Context, DRE, InitExprs, FType, VK_LValue, + SourceLocation()); + NewRep = new (Context) UnaryOperator( + NewRep, UO_AddrOf, Context->getPointerType(NewRep->getType()), VK_RValue, + OK_Ordinary, SourceLocation(), false); NewRep = NoTypeInfoCStyleCastExpr(Context, FType, CK_BitCast, NewRep); BlockDeclRefs.clear(); -- cgit v1.2.3