[PATCH] Introduce GlobalAlias::mayBeResolved().

Peter Collingbourne peter at pcc.me.uk
Mon Apr 1 14:08:48 PDT 2013


This controls whether the aliasee may be used instead of the alias.
Normally the same as mayBeOverridden(), except in the case where the
alias's visibility differs from the aliasee, as the visibility controls
whether accesses use the global offset table (which can be important).

http://llvm-reviews.chandlerc.com/D606

Files:
  include/llvm/IR/GlobalAlias.h
  lib/Analysis/BasicAliasAnalysis.cpp
  lib/Analysis/IPA/InlineCost.cpp
  lib/Analysis/InstructionSimplify.cpp
  lib/Analysis/MemoryBuiltins.cpp
  lib/Analysis/ScalarEvolution.cpp
  lib/Analysis/ValueTracking.cpp
  lib/IR/Globals.cpp
  lib/IR/Value.cpp
  lib/Transforms/IPO/GlobalOpt.cpp
  lib/Transforms/ObjCARC/ObjCARCContract.cpp
  lib/Transforms/Scalar/SROA.cpp

Index: include/llvm/IR/GlobalAlias.h
===================================================================
--- include/llvm/IR/GlobalAlias.h
+++ include/llvm/IR/GlobalAlias.h
@@ -75,6 +75,15 @@
   /// aliases.
   const GlobalValue *resolveAliasedGlobal(bool stopOnWeak = true) const;
 
+  /// Whether the aliasee may be used instead of the alias.  Normally the same
+  /// as mayBeOverridden(), except in the case where the alias's visibility
+  /// differs from the aliasee, as the visibility controls whether accesses use
+  /// the global offset table (which can be important).
+  bool mayBeResolved() const {
+    return !mayBeOverridden() &&
+           getVisibility() == getAliasedGlobal()->getVisibility();
+  }
+
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const Value *V) {
     return V->getValueID() == Value::GlobalAliasVal;
Index: lib/Analysis/BasicAliasAnalysis.cpp
===================================================================
--- lib/Analysis/BasicAliasAnalysis.cpp
+++ lib/Analysis/BasicAliasAnalysis.cpp
@@ -244,7 +244,7 @@
     if (Op == 0) {
       // The only non-operator case we can handle are GlobalAliases.
       if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
-        if (!GA->mayBeOverridden()) {
+        if (GA->mayBeResolved()) {
           V = GA->getAliasee();
           continue;
         }
Index: lib/Analysis/IPA/InlineCost.cpp
===================================================================
--- lib/Analysis/IPA/InlineCost.cpp
+++ lib/Analysis/IPA/InlineCost.cpp
@@ -872,7 +872,7 @@
     } else if (Operator::getOpcode(V) == Instruction::BitCast) {
       V = cast<Operator>(V)->getOperand(0);
     } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
-      if (GA->mayBeOverridden())
+      if (!GA->mayBeResolved())
         break;
       V = GA->getAliasee();
     } else {
Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -691,7 +691,7 @@
     } else if (Operator::getOpcode(V) == Instruction::BitCast) {
       V = cast<Operator>(V)->getOperand(0);
     } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
-      if (GA->mayBeOverridden())
+      if (!GA->mayBeResolved())
         break;
       V = GA->getAliasee();
     } else {
Index: lib/Analysis/MemoryBuiltins.cpp
===================================================================
--- lib/Analysis/MemoryBuiltins.cpp
+++ lib/Analysis/MemoryBuiltins.cpp
@@ -549,7 +549,7 @@
 }
 
 SizeOffsetType ObjectSizeOffsetVisitor::visitGlobalAlias(GlobalAlias &GA) {
-  if (GA.mayBeOverridden())
+  if (!GA.mayBeResolved())
     return unknown();
   return compute(GA.getAliasee());
 }
Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -3585,7 +3585,7 @@
   else if (isa<ConstantPointerNull>(V))
     return getConstant(V->getType(), 0);
   else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V))
-    return GA->mayBeOverridden() ? getUnknown(V) : getSCEV(GA->getAliasee());
+    return GA->mayBeResolved() ? getSCEV(GA->getAliasee()) : getUnknown(V);
   else
     return getUnknown(V);
 
Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -299,7 +299,7 @@
   // A weak GlobalAlias is totally unknown. A non-weak GlobalAlias has
   // the bits of its aliasee.
   if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
-    if (GA->mayBeOverridden()) {
+    if (!GA->mayBeResolved()) {
       KnownZero.clearAllBits(); KnownOne.clearAllBits();
     } else {
       ComputeMaskedBits(GA->getAliasee(), KnownZero, KnownOne, TD, Depth+1);
@@ -1691,7 +1691,7 @@
     } else if (Operator::getOpcode(Ptr) == Instruction::BitCast) {
       Ptr = cast<Operator>(Ptr)->getOperand(0);
     } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(Ptr)) {
-      if (GA->mayBeOverridden())
+      if (!GA->mayBeResolved())
         break;
       Ptr = GA->getAliasee();
     } else {
@@ -1860,7 +1860,7 @@
     } else if (Operator::getOpcode(V) == Instruction::BitCast) {
       V = cast<Operator>(V)->getOperand(0);
     } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
-      if (GA->mayBeOverridden())
+      if (!GA->mayBeResolved())
         return V;
       V = GA->getAliasee();
     } else {
Index: lib/IR/Globals.cpp
===================================================================
--- lib/IR/Globals.cpp
+++ lib/IR/Globals.cpp
@@ -248,15 +248,15 @@
   SmallPtrSet<const GlobalValue*, 3> Visited;
 
   // Check if we need to stop early.
-  if (stopOnWeak && mayBeOverridden())
+  if (stopOnWeak && !mayBeResolved())
     return this;
 
   const GlobalValue *GV = getAliasedGlobal();
   Visited.insert(GV);
 
   // Iterate over aliasing chain, stopping on weak alias if necessary.
   while (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) {
-    if (stopOnWeak && GA->mayBeOverridden())
+    if (stopOnWeak && !GA->mayBeResolved())
       break;
 
     GV = GA->getAliasedGlobal();
Index: lib/IR/Value.cpp
===================================================================
--- lib/IR/Value.cpp
+++ lib/IR/Value.cpp
@@ -367,7 +367,7 @@
     } else if (Operator::getOpcode(V) == Instruction::BitCast) {
       V = cast<Operator>(V)->getOperand(0);
     } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
-      if (GA->mayBeOverridden())
+      if (!GA->mayBeResolved())
         return V;
       V = GA->getAliasee();
     } else {
Index: lib/Transforms/IPO/GlobalOpt.cpp
===================================================================
--- lib/Transforms/IPO/GlobalOpt.cpp
+++ lib/Transforms/IPO/GlobalOpt.cpp
@@ -3051,7 +3051,7 @@
     if (!J->hasName() && !J->isDeclaration())
       J->setLinkage(GlobalValue::InternalLinkage);
     // If the aliasee may change at link time, nothing can be done - bail out.
-    if (J->mayBeOverridden())
+    if (!J->mayBeResolved())
       continue;
 
     Constant *Aliasee = J->getAliasee();
Index: lib/Transforms/ObjCARC/ObjCARCContract.cpp
===================================================================
--- lib/Transforms/ObjCARC/ObjCARCContract.cpp
+++ lib/Transforms/ObjCARC/ObjCARCContract.cpp
@@ -522,7 +522,7 @@
                cast<GEPOperator>(Arg)->hasAllZeroIndices())
         Arg = cast<GEPOperator>(Arg)->getPointerOperand();
       else if (isa<GlobalAlias>(Arg) &&
-               !cast<GlobalAlias>(Arg)->mayBeOverridden())
+               cast<GlobalAlias>(Arg)->mayBeResolved())
         Arg = cast<GlobalAlias>(Arg)->getAliasee();
       else
         break;
Index: lib/Transforms/Scalar/SROA.cpp
===================================================================
--- lib/Transforms/Scalar/SROA.cpp
+++ lib/Transforms/Scalar/SROA.cpp
@@ -1942,7 +1942,7 @@
     if (Operator::getOpcode(Ptr) == Instruction::BitCast) {
       Ptr = cast<Operator>(Ptr)->getOperand(0);
     } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(Ptr)) {
-      if (GA->mayBeOverridden())
+      if (!GA->mayBeResolved())
         break;
       Ptr = GA->getAliasee();
     } else {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D606.1.patch
Type: text/x-patch
Size: 7318 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130401/6dfe6301/attachment.bin>


More information about the llvm-commits mailing list