[cfe-commits] r96403 - in /cfe/trunk/lib/CodeGen: CGCXX.cpp CGClass.cpp CodeGenFunction.cpp CodeGenFunction.h

John McCall rjmccall at apple.com
Tue Feb 16 14:04:36 PST 2010


Author: rjmccall
Date: Tue Feb 16 16:04:33 2010
New Revision: 96403

URL: http://llvm.org/viewvc/llvm-project?rev=96403&view=rev
Log:
IRgen optimization:  cache the value of 'this' and 'vtt' instead of
repeatedly reloading from an alloca.  We still need to create the alloca
for debug info purposes (although we currently create it in all cases
because of some abstraction boundaries that're hard to break down).


Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CGClass.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=96403&r1=96402&r2=96403&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Feb 16 16:04:33 2010
@@ -28,18 +28,6 @@
 
 
 
-llvm::Value *CodeGenFunction::LoadCXXThis() {
-  assert(isa<CXXMethodDecl>(CurFuncDecl) &&
-         "Must be in a C++ member function decl to load 'this'");
-  assert(cast<CXXMethodDecl>(CurFuncDecl)->isInstance() &&
-         "Must be in a C++ member function decl to load 'this'");
-
-  // FIXME: What if we're inside a block?
-  // ans: See how CodeGenFunction::LoadObjCSelf() uses
-  // CodeGenFunction::BlockForwardSelf() for how to do this.
-  return Builder.CreateLoad(LocalDeclMap[CXXThisDecl], "this");
-}
-
 void CodeGenModule::EmitCXXConstructors(const CXXConstructorDecl *D) {
   EmitGlobal(GlobalDecl(D, Ctor_Complete));
   EmitGlobal(GlobalDecl(D, Ctor_Base));

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=96403&r1=96402&r2=96403&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Tue Feb 16 16:04:33 2010
@@ -1405,11 +1405,3 @@
   // Store address point
   Builder.CreateStore(VtableAddressPoint, VtableField);
 }
-
-llvm::Value *CodeGenFunction::LoadCXXVTT() {
-  assert((isa<CXXConstructorDecl>(CurFuncDecl) ||
-          isa<CXXDestructorDecl>(CurFuncDecl)) &&
-         "Must be in a C++ ctor or dtor to load the vtt parameter");
-
-  return Builder.CreateLoad(LocalDeclMap[CXXVTTDecl], "vtt");
-}

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=96403&r1=96402&r2=96403&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Feb 16 16:04:33 2010
@@ -30,7 +30,7 @@
     Builder(cgm.getModule().getContext()),
     DebugInfo(0), IndirectBranch(0),
     SwitchInsn(0), CaseRangeBlock(0), InvokeDest(0),
-    CXXThisDecl(0), CXXVTTDecl(0),
+    CXXThisDecl(0), CXXThisValue(0), CXXVTTDecl(0), CXXVTTValue(0),
     ConditionalBranchLevel(0), TerminateHandler(0), TrapBB(0),
     UniqueAggrDestructorCount(0) {
   LLVMIntTy = ConvertType(getContext().IntTy);
@@ -225,6 +225,11 @@
   EmitStartEHSpec(CurCodeDecl);
   EmitFunctionProlog(*CurFnInfo, CurFn, Args);
 
+  if (CXXThisDecl)
+    CXXThisValue = Builder.CreateLoad(LocalDeclMap[CXXThisDecl], "this");
+  if (CXXVTTDecl)
+    CXXVTTValue = Builder.CreateLoad(LocalDeclMap[CXXVTTDecl], "vtt");
+
   // If any of the arguments have a variably modified type, make sure to
   // emit the type size.
   for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
@@ -252,7 +257,8 @@
       // Create the implicit 'this' decl.
       // FIXME: I'm not entirely sure I like using a fake decl just for code
       // generation. Maybe we can come up with a better way?
-      CXXThisDecl = ImplicitParamDecl::Create(getContext(), 0, SourceLocation(),
+      CXXThisDecl = ImplicitParamDecl::Create(getContext(), 0,
+                                              FD->getLocation(),
                                               &getContext().Idents.get("this"),
                                               MD->getThisType(getContext()));
       Args.push_back(std::make_pair(CXXThisDecl, CXXThisDecl->getType()));
@@ -262,7 +268,7 @@
         // FIXME: The comment about using a fake decl above applies here too.
         QualType T = getContext().getPointerType(getContext().VoidPtrTy);
         CXXVTTDecl = 
-          ImplicitParamDecl::Create(getContext(), 0, SourceLocation(),
+          ImplicitParamDecl::Create(getContext(), 0, FD->getLocation(),
                                     &getContext().Idents.get("vtt"), T);
         Args.push_back(std::make_pair(CXXVTTDecl, CXXVTTDecl->getType()));
       }

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=96403&r1=96402&r2=96403&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Feb 16 16:04:33 2010
@@ -382,11 +382,13 @@
   /// CXXThisDecl - When generating code for a C++ member function,
   /// this will hold the implicit 'this' declaration.
   ImplicitParamDecl *CXXThisDecl;
+  llvm::Value *CXXThisValue;
 
   /// CXXVTTDecl - When generating code for a base object constructor or
   /// base object destructor with virtual bases, this will hold the implicit
   /// VTT parameter.
   ImplicitParamDecl *CXXVTTDecl;
+  llvm::Value *CXXVTTValue;
   
   /// CXXLiveTemporaryInfo - Holds information about a live C++ temporary.
   struct CXXLiveTemporaryInfo {
@@ -745,11 +747,17 @@
 
   /// LoadCXXThis - Load the value of 'this'. This function is only valid while
   /// generating code for an C++ member function.
-  llvm::Value *LoadCXXThis();
+  llvm::Value *LoadCXXThis() {
+    assert(CXXThisValue && "no 'this' value for this function");
+    return CXXThisValue;
+  }
 
   /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have
   /// virtual bases.
-  llvm::Value *LoadCXXVTT();
+  llvm::Value *LoadCXXVTT() {
+    assert(CXXVTTValue && "no VTT value for this function");
+    return CXXVTTValue;
+  }
 
   /// GetAddressOfBaseOfCompleteClass - Convert the given pointer to a
   /// complete class down to one of its virtual bases.





More information about the cfe-commits mailing list