[Lldb-commits] [lldb] r203599 - Followed up on Ed Maste's patch with a few more

Sean Callanan scallanan at apple.com
Tue Mar 11 12:19:16 PDT 2014


Author: spyffe
Date: Tue Mar 11 14:19:16 2014
New Revision: 203599

URL: http://llvm.org/viewvc/llvm-project?rev=203599&view=rev
Log:
Followed up on Ed Maste's patch with a few more
User fixes.  Also changed our iterations across
global variables and instruction operands to
reflect the new C++11 approach.

Modified:
    lldb/trunk/source/Expression/IRForTarget.cpp

Modified: lldb/trunk/source/Expression/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRForTarget.cpp?rev=203599&r1=203598&r2=203599&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRForTarget.cpp (original)
+++ lldb/trunk/source/Expression/IRForTarget.cpp Tue Mar 11 14:19:16 2014
@@ -332,7 +332,7 @@ IRForTarget::ResolveFunctionPointers(llv
         if (!is_decl)
             continue;
         
-        if (fun->hasNUses(0))
+        if (fun->use_empty())
             continue; // ignore
         
         uint64_t addr = LLDB_INVALID_ADDRESS;
@@ -639,7 +639,7 @@ IRForTarget::CreateResultVariable (llvm:
                     PrintValue(result_global).c_str(),
                     PrintValue(new_result_global).c_str());
     
-    if (result_global->hasNUses(0))
+    if (result_global->use_empty())
     {
         // We need to synthesize a store for this variable, because otherwise
         // there's nothing to put into its equivalent persistent variable.
@@ -687,7 +687,6 @@ IRForTarget::CreateResultVariable (llvm:
     return true;
 }
 
-#if 0
 static void DebugUsers(lldb_private::Log *log, Value *value, uint8_t depth)
 {    
     if (!depth)
@@ -708,7 +707,6 @@ static void DebugUsers(lldb_private::Log
     if (log)
         log->Printf("  <End uses>");
 }
-#endif
 
 bool
 IRForTarget::RewriteObjCConstString (llvm::GlobalVariable *ns_str,
@@ -1753,28 +1751,18 @@ IRForTarget::ResolveExternals (Function
 {
     lldb_private::Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
     
-    for (Module::global_iterator global = m_module->global_begin(), end = m_module->global_end();
-         global != end;
-         ++global)
+    for (GlobalVariable &global_var : m_module->globals())
     {
-        if (!global)
-        {
-            if (m_error_stream)
-                m_error_stream->Printf("Internal error [IRForTarget]: global variable is NULL");
-            
-            return false;
-        }
-        
-        std::string global_name = (*global).getName().str();
+        std::string global_name = global_var.getName().str();
         
         if (log)
             log->Printf("Examining %s, DeclForGlobalValue returns %p", 
                         global_name.c_str(),
-                        DeclForGlobal(global));
+                        DeclForGlobal(&global_var));
         
         if (global_name.find("OBJC_IVAR") == 0)
         {
-            if (!HandleSymbol(global))
+            if (!HandleSymbol(&global_var))
             {
                 if (m_error_stream)
                     m_error_stream->Printf("Error [IRForTarget]: Couldn't find Objective-C indirect ivar symbol %s\n", global_name.c_str());
@@ -1784,7 +1772,7 @@ IRForTarget::ResolveExternals (Function
         }
         else if (global_name.find("OBJC_CLASSLIST_REFERENCES_$") != global_name.npos)
         {
-            if (!HandleObjCClass(global))
+            if (!HandleObjCClass(&global_var))
             {
                 if (m_error_stream)
                     m_error_stream->Printf("Error [IRForTarget]: Couldn't resolve the class for an Objective-C static method call\n");
@@ -1794,7 +1782,7 @@ IRForTarget::ResolveExternals (Function
         }
         else if (global_name.find("OBJC_CLASSLIST_SUP_REFS_$") != global_name.npos)
         {
-            if (!HandleObjCClass(global))
+            if (!HandleObjCClass(&global_var))
             {
                 if (m_error_stream)
                     m_error_stream->Printf("Error [IRForTarget]: Couldn't resolve the class for an Objective-C static method call\n");
@@ -1802,9 +1790,9 @@ IRForTarget::ResolveExternals (Function
                 return false;
             }
         }
-        else if (DeclForGlobal(global))
+        else if (DeclForGlobal(&global_var))
         {
-            if (!MaybeHandleVariable (global))
+            if (!MaybeHandleVariable (&global_var))
             {
                 if (m_error_stream)
                     m_error_stream->Printf("Internal error [IRForTarget]: Couldn't rewrite external variable %s\n", global_name.c_str());
@@ -1826,16 +1814,12 @@ IRForTarget::ReplaceStrings ()
     
     OffsetsTy offsets;
     
-    for (Module::global_iterator gi = m_module->global_begin(), ge = m_module->global_end();
-         gi != ge;
-         ++gi)
+    for (GlobalVariable &gv : m_module->globals())
     {
-        GlobalVariable *gv = gi;
-        
-        if (!gv->hasInitializer())
+        if (!gv.hasInitializer())
             continue;
         
-        Constant *gc = gv->getInitializer();
+        Constant *gc = gv.getInitializer();
         
         std::string str;
         
@@ -1873,7 +1857,7 @@ IRForTarget::ReplaceStrings ()
             str = gc_array->getAsString();
         }
             
-        offsets[gv] = m_data_allocator.GetStream().GetSize();
+        offsets[&gv] = m_data_allocator.GetStream().GetSize();
         
         m_data_allocator.GetStream().Write(str.c_str(), str.length() + 1);
     }
@@ -1955,12 +1939,8 @@ IRForTarget::ReplaceStaticLiterals (llvm
     {
         llvm::Instruction &inst = *ii;
         
-        for (Instruction::op_iterator oi = inst.op_begin(), oe = inst.op_end();
-             oi != oe;
-             ++oi)
+        for (Value *operand_val : inst.operand_values())
         {
-            Value *operand_val = oi->get();
-            
             ConstantFP *operand_constant_fp = dyn_cast<ConstantFP>(operand_val);
             
             if (operand_constant_fp/* && operand_constant_fp->getType()->isX86_FP80Ty()*/)
@@ -2527,37 +2507,29 @@ IRForTarget::StripAllGVs (Module &llvm_m
     {
         erased = false;
         
-        for (Module::global_iterator gi = llvm_module.global_begin(), ge = llvm_module.global_end();
-             gi != ge;
-             ++gi)
+        for (GlobalVariable &global_var : llvm_module.globals())
         {
-            GlobalVariable *global_var = dyn_cast<GlobalVariable>(gi);
-        
-            global_var->removeDeadConstantUsers();
+            global_var.removeDeadConstantUsers();
             
-            if (global_var->use_empty())
+            if (global_var.use_empty())
             {
                 if (log)
                     log->Printf("Did remove %s",
-                                PrintValue(global_var).c_str());
-                global_var->eraseFromParent();
+                                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)
+    for (GlobalVariable &global_var : llvm_module.globals())
     {
-        GlobalVariable *global_var = dyn_cast<GlobalVariable>(gi);
-
-        GlobalValue::user_iterator ui = global_var->user_begin();
+        GlobalValue::user_iterator ui = global_var.user_begin();
         
         if (log)
             log->Printf("Couldn't remove %s because of %s",
-                        PrintValue(global_var).c_str(),
+                        PrintValue(&global_var).c_str(),
                         PrintValue(*ui).c_str());
     }
     





More information about the lldb-commits mailing list