Make safer variant of alias resolution routine to be default
authorAnton Korobeynikov <asl@math.spbu.ru>
Tue, 9 Sep 2008 20:05:04 +0000 (20:05 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Tue, 9 Sep 2008 20:05:04 +0000 (20:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56005 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/GlobalAlias.h
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/ExecutionEngine/JIT/JITEmitter.cpp
lib/Linker/LinkModules.cpp
lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
lib/Transforms/IPO/GlobalOpt.cpp
lib/VMCore/Globals.cpp
lib/VMCore/Verifier.cpp

index 1081fc675fcc35d86a72a069acc735e0ed546938..d689ad756540226bccc53c813e69065e0bd1950d 100644 (file)
@@ -76,10 +76,10 @@ public:
 
   /// resolveAliasedGlobal() - This method tries to ultimately resolve the alias
   /// by going through the aliasing chain and trying to find the very last
-  /// global. Returns NULL if a cycle was found. If traverseWeak is true, then
+  /// global. Returns NULL if a cycle was found. If stopOnWeak is false, then
   /// the whole chain aliasing chain is traversed, otherwise - only strong
   /// aliases.
-  const GlobalValue* resolveAliasedGlobal(bool traverseWeak = true) const;
+  const GlobalValue* resolveAliasedGlobal(bool stopOnWeak = true) const;
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const GlobalAlias *) { return true; }
index 747c1400fcc71935001c9b3e72f4735e970476f3..31cd2e3393e7eac0fbf7338728f7a3031ab53b0d 100644 (file)
@@ -949,7 +949,7 @@ SDValue SelectionDAG::getGlobalAddress(const GlobalValue *GV,
   if (!GVar) {
     // If GV is an alias then use the aliasee for determining thread-localness.
     if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV))
-      GVar = dyn_cast_or_null<GlobalVariable>(GA->resolveAliasedGlobal());
+      GVar = dyn_cast_or_null<GlobalVariable>(GA->resolveAliasedGlobal(false));
   }
 
   if (GVar && GVar->isThreadLocal())
index da4cd095fad625845b0242f30882294df75148a0..02752a01cdd315f0eeddb3f94c3d671238183c68 100644 (file)
@@ -567,7 +567,7 @@ void *JITEmitter::getPointerToGlobal(GlobalValue *V, void *Reference,
     return TheJIT->getOrEmitGlobalVariable(GV);
   }
   if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
-    return TheJIT->getPointerToGlobal(GA->resolveAliasedGlobal());
+    return TheJIT->getPointerToGlobal(GA->resolveAliasedGlobal(false));
 
   // If we have already compiled the function, return a pointer to its body.
   Function *F = cast<Function>(V);
index f4ebe6b10c015a953a4137603c45e7ae44969f20..b867705fe12064ecc79e01afa3ea304a545c5b62 100644 (file)
@@ -1169,7 +1169,7 @@ static bool LinkAppendingVars(Module *M,
 static bool ResolveAliases(Module *Dest) {
   for (Module::alias_iterator I = Dest->alias_begin(), E = Dest->alias_end();
        I != E; ++I)
-    if (const GlobalValue *GV = I->resolveAliasedGlobal(/*traverseWeak*/ false))
+    if (const GlobalValue *GV = I->resolveAliasedGlobal())
       if (GV != I && !GV->isDeclaration())
         I->replaceAllUsesWith(const_cast<GlobalValue*>(GV));
 
index eb31752ded984bc5eeb84239c6349bd4703b748e..6977ead58e1b61513736dbd37410b29b1519b504 100644 (file)
@@ -369,7 +369,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
       // If GV is an alias then use the aliasee for determining
       // thread-localness.
       if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV))
-        GVar = dyn_cast_or_null<GlobalVariable>(GA->resolveAliasedGlobal());
+        GVar = dyn_cast_or_null<GlobalVariable>(GA->resolveAliasedGlobal(false));
     }
 
     bool isThreadLocal = GVar && GVar->isThreadLocal();
index 8c6631aa2bcbc25e4ab70e4ef2444cf62b351862..0c059ff01463afc7765e1688b97a3e09934e0ea5 100644 (file)
@@ -2223,7 +2223,7 @@ bool GlobalOpt::ResolveAliases(Module &M) {
     if (I->use_empty())
       continue;
 
-    if (const GlobalValue *GV = I->resolveAliasedGlobal(/*traverseWeak*/ false))
+    if (const GlobalValue *GV = I->resolveAliasedGlobal())
       if (GV != I) {
         I->replaceAllUsesWith(const_cast<GlobalValue*>(GV));
         Changed = true;
@@ -2252,7 +2252,6 @@ bool GlobalOpt::runOnModule(Module &M) {
     
     // Optimize non-address-taken globals.
     LocalChange |= OptimizeGlobalVars(M);
-    Changed |= LocalChange;
 
     // Resolve aliases, when possible.
     LocalChange |= ResolveAliases(M);
index 7ceda6cd53d3ffca9d8407ba21816db01312ad77..c917dfc3be7193709b4d6352109114a221fc7e36 100644 (file)
@@ -248,11 +248,11 @@ const GlobalValue *GlobalAlias::getAliasedGlobal() const {
   return 0;
 }
 
-const GlobalValue *GlobalAlias::resolveAliasedGlobal(bool traverseWeak) const {
+const GlobalValue *GlobalAlias::resolveAliasedGlobal(bool stopOnWeak) const {
   SmallPtrSet<const GlobalValue*, 3> Visited;
 
   // Check if we need to stop early.
-  if (!traverseWeak && hasWeakLinkage())
+  if (stopOnWeak && hasWeakLinkage())
     return this;
 
   const GlobalValue *GV = getAliasedGlobal();
@@ -260,7 +260,7 @@ const GlobalValue *GlobalAlias::resolveAliasedGlobal(bool traverseWeak) const {
 
   // Iterate over aliasing chain, stopping on weak alias if necessary.
   while (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) {
-    if (!traverseWeak && GA->hasWeakLinkage())
+    if (stopOnWeak && GA->hasWeakLinkage())
       break;
 
     GV = GA->getAliasedGlobal();
index af11fce5e7237ab52a4a2a7f16a0ddd97bf6e983..be053aba944c7d5a606a87c743583c223945bae8 100644 (file)
@@ -394,7 +394,7 @@ void Verifier::visitGlobalAlias(GlobalAlias &GA) {
             &GA);
   }
 
-  const GlobalValue* Aliasee = GA.resolveAliasedGlobal();
+  const GlobalValue* Aliasee = GA.resolveAliasedGlobal(/*stopOnWeak*/ false);
   Assert1(Aliasee,
           "Aliasing chain should end with function or global variable", &GA);