[llvm-commits] [dragonegg] r90877 - /dragonegg/trunk/llvm-backend.cpp

Duncan Sands baldrick at free.fr
Tue Dec 8 13:17:07 PST 2009


Author: baldrick
Date: Tue Dec  8 15:17:07 2009
New Revision: 90877

URL: http://llvm.org/viewvc/llvm-project?rev=90877&view=rev
Log:
After some experimentation, these linkage settings for aliases seem
both fairly logical and result in much the same output as with gcc.
(Now that there are also same-body aliases, which are basically multiple
names for the same C++ ctor/dtor, the alias zoo became larger and harder
to get right, or close to right).

Modified:
    dragonegg/trunk/llvm-backend.cpp

Modified: dragonegg/trunk/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-backend.cpp?rev=90877&r1=90876&r2=90877&view=diff

==============================================================================
--- dragonegg/trunk/llvm-backend.cpp (original)
+++ dragonegg/trunk/llvm-backend.cpp Tue Dec  8 15:17:07 2009
@@ -1677,38 +1677,41 @@
     Aliasee = cast<GlobalValue>(DECL_LLVM(target));
   }
 
-  GlobalValue::LinkageTypes Linkage;
+  GlobalValue::LinkageTypes Linkage = GlobalValue::ExternalLinkage;
 
-  if (!TREE_PUBLIC(decl))
+  if (DECL_COMDAT(decl))
+    // Need not be put out unless needed in this translation unit.
     Linkage = GlobalValue::InternalLinkage;
+  else if (DECL_ONE_ONLY(decl))
+    // Copies of this DECL in multiple translation units should be merged.
+    Linkage = GlobalValue::WeakODRLinkage;
   else if (DECL_WEAK(decl))
     // The user may have explicitly asked for weak linkage - ignore flag_odr.
     Linkage = GlobalValue::WeakAnyLinkage;
-  else
-    Linkage = GlobalValue::ExternalLinkage;
-
-  GlobalAlias* GA = new GlobalAlias(Aliasee->getType(), Linkage, "",
-                                    Aliasee, TheModule);
+  else if (!TREE_PUBLIC(decl))
+    // Not accessible from outside this translation unit.
+    Linkage = GlobalValue::InternalLinkage;
+  else if (DECL_EXTERNAL(decl))
+    // Do not allocate storage, and refer to a definition elsewhere.
+    Linkage = GlobalValue::InternalLinkage;
 
-  handleVisibility(decl, GA);
+  if (Linkage != GlobalValue::InternalLinkage) {
+    // Create the LLVM alias.
+    GlobalAlias* GA = new GlobalAlias(Aliasee->getType(), Linkage, "",
+                                      Aliasee, TheModule);
+    handleVisibility(decl, GA);
 
-  if (GA->getType()->canLosslesslyBitCastTo(V->getType()))
+    // Associate it with decl instead of V.
     V->replaceAllUsesWith(ConstantExpr::getBitCast(GA, V->getType()));
-  else if (!V->use_empty()) {
-    error ("%J Alias %qD used with invalid type!", decl, decl);
-    return;
+    changeLLVMConstant(V, GA);
+    GA->takeName(V);
+  } else {
+    // Make all users of the alias directly use the aliasee instead.
+    V->replaceAllUsesWith(ConstantExpr::getBitCast(Aliasee, V->getType()));
+    changeLLVMConstant(V, Aliasee);
   }
 
-  changeLLVMConstant(V, GA);
-  GA->takeName(V);
-  if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
-    GV->eraseFromParent();
-  else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
-    GA->eraseFromParent();
-  else if (Function *F = dyn_cast<Function>(V))
-    F->eraseFromParent();
-  else
-    assert(0 && "Unsuported global value");
+  V->eraseFromParent();
 
   // Mark the alias as written so gcc doesn't waste time outputting it.
   TREE_ASM_WRITTEN(decl) = 1;





More information about the llvm-commits mailing list