IR: Cleanup AttributeSet::get for AttrBuilder
[oota-llvm.git] / lib / IR / Globals.cpp
index 11152d5d6c21c9a941a62a192e0d36414f5abe00..a6cd03e622a2bc488636ff7b8625313c668e9ce4 100644 (file)
@@ -96,7 +96,7 @@ GlobalVariable::GlobalVariable(Type *Ty, bool constant, LinkageTypes Link,
   : GlobalValue(PointerType::get(Ty, AddressSpace),
                 Value::GlobalVariableVal,
                 OperandTraits<GlobalVariable>::op_begin(this),
-                InitVal != 0, Link, Name),
+                InitVal != nullptr, Link, Name),
     isConstantGlobal(constant), threadLocalMode(TLMode),
     isExternallyInitializedConstant(isExternallyInitialized) {
   if (InitVal) {
@@ -117,7 +117,7 @@ GlobalVariable::GlobalVariable(Module &M, Type *Ty, bool constant,
   : GlobalValue(PointerType::get(Ty, AddressSpace),
                 Value::GlobalVariableVal,
                 OperandTraits<GlobalVariable>::op_begin(this),
-                InitVal != 0, Link, Name),
+                InitVal != nullptr, Link, Name),
     isConstantGlobal(constant), threadLocalMode(TLMode),
     isExternallyInitializedConstant(isExternallyInitialized) {
   if (InitVal) {
@@ -171,9 +171,9 @@ void GlobalVariable::replaceUsesOfWithOnConstant(Value *From, Value *To,
 }
 
 void GlobalVariable::setInitializer(Constant *InitVal) {
-  if (InitVal == 0) {
+  if (!InitVal) {
     if (hasInitializer()) {
-      Op<0>().set(0);
+      Op<0>().set(nullptr);
       NumOperands = 0;
     }
   } else {
@@ -236,10 +236,10 @@ void GlobalAlias::setAliasee(Constant *Aliasee) {
   setOperand(0, Aliasee);
 }
 
-GlobalValue *GlobalAlias::getAliasedGlobal() {
-  Constant *C = getAliasee();
-  if (C == 0) return 0;
-  
+static GlobalValue *getAliaseeGV(GlobalAlias *GA) {
+  Constant *C = GA->getAliasee();
+  assert(C && "Must alias something");
+
   if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
     return GV;
 
@@ -248,30 +248,23 @@ GlobalValue *GlobalAlias::getAliasedGlobal() {
           CE->getOpcode() == Instruction::AddrSpaceCast ||
           CE->getOpcode() == Instruction::GetElementPtr) &&
          "Unsupported aliasee");
-  
+
   return cast<GlobalValue>(CE->getOperand(0));
 }
 
-GlobalValue *GlobalAlias::resolveAliasedGlobal(bool stopOnWeak) {
+GlobalValue *GlobalAlias::getAliasedGlobal() {
   SmallPtrSet<GlobalValue*, 3> Visited;
 
-  // Check if we need to stop early.
-  if (stopOnWeak && mayBeOverridden())
-    return this;
-
-  GlobalValue *GV = getAliasedGlobal();
-  Visited.insert(GV);
-
-  // Iterate over aliasing chain, stopping on weak alias if necessary.
-  while (GlobalAlias *GA = dyn_cast<GlobalAlias>(GV)) {
-    if (stopOnWeak && GA->mayBeOverridden())
-      break;
-
-    GV = GA->getAliasedGlobal();
+  GlobalAlias *GA = this;
 
+  for (;;) {
+    GlobalValue *GV = getAliaseeGV(GA);
     if (!Visited.insert(GV))
-      return 0;
-  }
+      return nullptr;
 
-  return GV;
+    // Iterate over aliasing chain.
+    GA = dyn_cast<GlobalAlias>(GV);
+    if (!GA)
+      return GV;
+  }
 }