Skip to content

[lldb] Use BasicBlock::iterator instead of InsertPosition (NFC) #112307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ class ValidPointerChecker : public Instrumenter {
return false;

// Insert an instruction to call the helper with the result
CallInst::Create(m_valid_pointer_check_func, dereferenced_ptr, "", inst);
CallInst::Create(m_valid_pointer_check_func, dereferenced_ptr, "",
inst->getIterator());

return true;
}
Expand Down Expand Up @@ -417,7 +418,7 @@ class ObjcObjectChecker : public Instrumenter {

ArrayRef<llvm::Value *> args(arg_array, 2);

CallInst::Create(m_objc_object_check_func, args, "", inst);
CallInst::Create(m_objc_object_check_func, args, "", inst->getIterator());

return true;
}
Expand Down
38 changes: 22 additions & 16 deletions lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ bool IRForTarget::CreateResultVariable(llvm::Function &llvm_function) {

Constant *initializer = result_global->getInitializer();

StoreInst *synthesized_store =
new StoreInst(initializer, new_result_global, first_entry_instruction);
StoreInst *synthesized_store = new StoreInst(
initializer, new_result_global, first_entry_instruction->getIterator());
Comment on lines -381 to +382
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the more interesting use cases -- first_entry_instruction is initialized from the start of a block and in the "RemoveDIs" model there's ambiguity over whether the insert position is before-or-after debug records at the start of the block. However, because you're using getFirstNonPHIOrDbg the intention is clearly to insert after any debug records and this code is achieving that.

(No change needed)


LLDB_LOG(log, "Synthesized result store \"{0}\"\n",
PrintValue(synthesized_store));
Expand Down Expand Up @@ -413,9 +413,8 @@ bool IRForTarget::RewriteObjCConstString(llvm::GlobalVariable *ns_str,
"CFStringCreateWithBytes");

bool missing_weak = false;
CFStringCreateWithBytes_addr =
m_execution_unit.FindSymbol(g_CFStringCreateWithBytes_str,
missing_weak);
CFStringCreateWithBytes_addr = m_execution_unit.FindSymbol(
g_CFStringCreateWithBytes_str, missing_weak);
if (CFStringCreateWithBytes_addr == LLDB_INVALID_ADDRESS || missing_weak) {
LLDB_LOG(log, "Couldn't find CFStringCreateWithBytes in the target");

Expand Down Expand Up @@ -514,7 +513,8 @@ bool IRForTarget::RewriteObjCConstString(llvm::GlobalVariable *ns_str,
m_CFStringCreateWithBytes, CFSCWB_arguments,
"CFStringCreateWithBytes",
llvm::cast<Instruction>(
m_entry_instruction_finder.GetValue(function)));
m_entry_instruction_finder.GetValue(function))
->getIterator());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar story to above, FindEntryInstruction uses a debug-intrinsic skipping function, so there's no need to pass around the iterator as a position.

});

if (!UnfoldConstant(ns_str, nullptr, CFSCWB_Caller, m_entry_instruction_finder,
Expand Down Expand Up @@ -821,7 +821,7 @@ bool IRForTarget::RewriteObjCSelector(Instruction *selector_load) {

CallInst *srN_call =
CallInst::Create(m_sel_registerName, _objc_meth_var_name_,
"sel_registerName", selector_load);
"sel_registerName", selector_load->getIterator());

// Replace the load with the call in all users

Expand Down Expand Up @@ -914,8 +914,9 @@ bool IRForTarget::RewritePersistentAlloc(llvm::Instruction *persistent_alloc) {
// Now, since the variable is a pointer variable, we will drop in a load of
// that pointer variable.

LoadInst *persistent_load = new LoadInst(persistent_global->getValueType(),
persistent_global, "", alloc);
LoadInst *persistent_load =
new LoadInst(persistent_global->getValueType(), persistent_global, "",
alloc->getIterator());

LLDB_LOG(log, "Replacing \"{0}\" with \"{1}\"", PrintValue(alloc),
PrintValue(persistent_load));
Expand Down Expand Up @@ -1341,8 +1342,10 @@ bool IRForTarget::UnfoldConstant(Constant *old_constant,

return new BitCastInst(
value_maker.GetValue(function), constant_expr->getType(),
"", llvm::cast<Instruction>(
entry_instruction_finder.GetValue(function)));
"",
llvm::cast<Instruction>(
entry_instruction_finder.GetValue(function))
->getIterator());
});

if (!UnfoldConstant(constant_expr, llvm_function, bit_cast_maker,
Expand Down Expand Up @@ -1376,7 +1379,8 @@ bool IRForTarget::UnfoldConstant(Constant *old_constant,
return GetElementPtrInst::Create(
gep->getSourceElementType(), ptr, indices, "",
llvm::cast<Instruction>(
entry_instruction_finder.GetValue(function)));
entry_instruction_finder.GetValue(function))
->getIterator());
});

if (!UnfoldConstant(constant_expr, llvm_function,
Expand Down Expand Up @@ -1556,12 +1560,14 @@ bool IRForTarget::ReplaceVariables(Function &llvm_function) {
Type *int8Ty = Type::getInt8Ty(function->getContext());
ConstantInt *offset_int(
ConstantInt::get(offset_type, offset, true));
GetElementPtrInst *get_element_ptr = GetElementPtrInst::Create(
int8Ty, argument, offset_int, "", entry_instruction);
GetElementPtrInst *get_element_ptr =
GetElementPtrInst::Create(int8Ty, argument, offset_int, "",
entry_instruction->getIterator());

if (name == m_result_name && !m_result_is_pointer) {
LoadInst *load = new LoadInst(value->getType(), get_element_ptr,
"", entry_instruction);
LoadInst *load =
new LoadInst(value->getType(), get_element_ptr, "",
entry_instruction->getIterator());

return load;
} else {
Expand Down
Loading