Brought LLDB top-of-tree into sync with LLVM/Clang
top-of-tree.  Removed all local patches and llvm.zip.

The intent is that fron now on top-of-tree will
always build against LLVM/Clang top-of-tree, and
that problems building will be resolved as they
occur.  Stable release branches of LLDB can be
constructed as needed and linked to specific release
branches of LLVM/Clang.


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@164563 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/IRForTarget.cpp b/source/Expression/IRForTarget.cpp
index 544c4bc..b74e9f9 100644
--- a/source/Expression/IRForTarget.cpp
+++ b/source/Expression/IRForTarget.cpp
@@ -15,7 +15,9 @@
 #include "llvm/Instructions.h"
 #include "llvm/Intrinsics.h"
 #include "llvm/Module.h"
+#include "llvm/PassManager.h"
 #include "llvm/Target/TargetData.h"
+#include "llvm/Transforms/IPO.h"
 #include "llvm/ValueSymbolTable.h"
 
 #include "clang/AST/ASTContext.h"
@@ -2630,6 +2632,55 @@
 }
 
 bool
+IRForTarget::StripAllGVs (Module &llvm_module)
+{
+    lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));    
+    std::vector<GlobalVariable *> global_vars;
+    std::set<GlobalVariable *>erased_vars;
+    
+    bool erased = true;
+    
+    while (erased)
+    {
+        erased = false;
+        
+        for (Module::global_iterator gi = llvm_module.global_begin(), ge = llvm_module.global_end();
+             gi != ge;
+             ++gi)
+        {
+            GlobalVariable *global_var = dyn_cast<GlobalVariable>(gi);
+        
+            global_var->removeDeadConstantUsers();
+            
+            if (global_var->use_empty())
+            {
+                if (log)
+                    log->Printf("Did remove %s",
+                                PrintValue(global_var).c_str());
+                global_var->eraseFromParent();
+                erased = true;
+                break;
+            }
+        }
+    }
+    
+    for (Module::global_iterator gi = llvm_module.global_begin(), ge = llvm_module.global_end();
+         gi != ge;
+         ++gi)
+    {
+        GlobalVariable *global_var = dyn_cast<GlobalVariable>(gi);
+
+        GlobalValue::use_iterator ui = global_var->use_begin();
+        
+        log->Printf("Couldn't remove %s because of %s",
+                    PrintValue(global_var).c_str(),
+                    PrintValue(*ui).c_str());
+    }
+    
+    return true;
+}
+
+bool
 IRForTarget::runOnModule (Module &llvm_module)
 {
     lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
@@ -2674,12 +2725,12 @@
     
     m_reloc_placeholder = new llvm::GlobalVariable((*m_module), 
                                                    intptr_ty,
-                                                   false /* isConstant */,
+                                                   false /* IsConstant */,
                                                    GlobalVariable::InternalLinkage,
                                                    Constant::getNullValue(intptr_ty),
                                                    "reloc_placeholder",
                                                    NULL /* InsertBefore */,
-                                                   false /* ThreadLocal */,
+                                                   GlobalVariable::NotThreadLocal /* ThreadLocal */,
                                                    0 /* AddressSpace */);
         
     Function::iterator bbi;
@@ -2876,6 +2927,12 @@
         return false;
     }
     
+    if (!StripAllGVs(llvm_module))
+    {
+        if (log)
+            log->Printf("StripAllGVs() failed");
+    }
+    
     if (log && log->GetVerbose())
     {
         std::string s;