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.

llvm-svn: 203599
This commit is contained in:
Sean Callanan 2014-03-11 19:19:16 +00:00
parent 0c325319cf
commit 339f61549f
1 changed files with 23 additions and 51 deletions
lldb/source/Expression

View File

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