[llvm-commits] [llvm] r52134 - /llvm/trunk/lib/Linker/LinkModules.cpp

Chris Lattner sabre at nondot.org
Mon Jun 9 00:36:11 PDT 2008


Author: lattner
Date: Mon Jun  9 02:36:11 2008
New Revision: 52134

URL: http://llvm.org/viewvc/llvm-project?rev=52134&view=rev
Log:
minor changes to short circuit the 'no linkage' case earlier for
function bodies.  We now don't try to unify types or handling type
mismatches if when linking an internal foo to an external foo.

Modified:
    llvm/trunk/lib/Linker/LinkModules.cpp

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=52134&r1=52133&r2=52134&view=diff

==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Mon Jun  9 02:36:11 2008
@@ -817,21 +817,47 @@
   // Loop over all of the functions in the src module, mapping them over
   for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
     const Function *SF = I;   // SrcFunction
+    
     Function *DF = 0;
+    
+    // If this function is internal or has no name, it doesn't participate in
+    // linkage.
     if (SF->hasName() && !SF->hasInternalLinkage()) {
       // Check to see if may have to link the function.
       DF = Dest->getFunction(SF->getName());
-      if (DF && SF->getType() != DF->getType())
-        // If types don't agree because of opaque, try to resolve them
-        RecursiveResolveTypes(SF->getType(), DF->getType(), 
-                              &Dest->getTypeSymbolTable(), "");
+      if (DF && DF->hasInternalLinkage())
+        DF = 0;
+    }
+    
+    // If there is no linkage to be performed, just bring over SF without
+    // modifying it.
+    if (DF == 0) {
+      // Function does not already exist, simply insert an function signature
+      // identical to SF into the dest module.
+      Function *NewDF = Function::Create(SF->getFunctionType(),
+                                         SF->getLinkage(),
+                                         SF->getName(), Dest);
+      CopyGVAttributes(NewDF, SF);
+      
+      // If the LLVM runtime renamed the function, but it is an externally
+      // visible symbol, DF must be an existing function with internal linkage.
+      // Rename it.
+      if (!NewDF->hasInternalLinkage() && NewDF->getName() != SF->getName())
+        ForceRenaming(NewDF, SF->getName());
+      
+      // ... and remember this mapping...
+      ValueMap[SF] = NewDF;
+      continue;
     }
-
-    if (DF && DF->hasInternalLinkage())
-      DF = NULL;
     
-    // Check visibility
-    if (DF && SF->getVisibility() != DF->getVisibility()) {
+    
+    // If types don't agree because of opaque, try to resolve them.
+    if (SF->getType() != DF->getType())
+      RecursiveResolveTypes(SF->getType(), DF->getType(), 
+                            &Dest->getTypeSymbolTable(), "");
+    
+    // Check visibility, merging if a definition overrides a prototype.
+    if (SF->getVisibility() != DF->getVisibility()) {
       // If one is a prototype, ignore its visibility.  Prototypes are always
       // overridden by the definition.
       if (!SF->isDeclaration() && !DF->isDeclaration())
@@ -843,7 +869,7 @@
         DF->setVisibility(SF->getVisibility());
     }
     
-    if (DF && DF->getType() != SF->getType()) {
+    if (DF->getType() != SF->getType()) {
       if (DF->isDeclaration() && !SF->isDeclaration()) {
         // We have a definition of the same name but different type in the
         // source module. Copy the prototype to the destination and replace
@@ -882,23 +908,10 @@
                      ToStr(SF->getFunctionType(), Src) + "' and '" +
                      ToStr(DF->getFunctionType(), Dest) + "'");
       }
-    } else if (!DF || SF->hasInternalLinkage() || DF->hasInternalLinkage()) {
-      // Function does not already exist, simply insert an function signature
-      // identical to SF into the dest module.
-      Function *NewDF = Function::Create(SF->getFunctionType(),
-                                         SF->getLinkage(),
-                                         SF->getName(), Dest);
-      CopyGVAttributes(NewDF, SF);
-
-      // If the LLVM runtime renamed the function, but it is an externally
-      // visible symbol, DF must be an existing function with internal linkage.
-      // Rename it.
-      if (NewDF->getName() != SF->getName() && !NewDF->hasInternalLinkage())
-        ForceRenaming(NewDF, SF->getName());
-
-      // ... and remember this mapping...
-      ValueMap[SF] = NewDF;
-    } else if (SF->isDeclaration()) {
+      continue;
+    }
+    
+    if (SF->isDeclaration()) {
       // If SF is a declaration or if both SF & DF are declarations, just link 
       // the declarations, we aren't adding anything.
       if (SF->hasDLLImportLinkage()) {





More information about the llvm-commits mailing list