-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
[lldb] Use BasicBlock::iterator instead of InsertPosition (NFC) #112307
Conversation
InsertPosition has been deprecated in favor of using BasicBlock::iterator. (See llvm#102608)
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesInsertPosition has been deprecated in favor of using BasicBlock::iterator. (See #102608) Full diff: https://github.com/llvm/llvm-project/pull/112307.diff 2 Files Affected:
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp b/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
index 45bdc7272936ca..ae0682d7179488 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/IRDynamicChecks.cpp
@@ -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;
}
@@ -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;
}
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
index 3764668fb27e82..6c728f34474898 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
@@ -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());
LLDB_LOG(log, "Synthesized result store \"{0}\"\n",
PrintValue(synthesized_store));
@@ -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");
@@ -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());
});
if (!UnfoldConstant(ns_str, nullptr, CFSCWB_Caller, m_entry_instruction_finder,
@@ -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
@@ -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));
@@ -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,
@@ -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,
@@ -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 {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, there are a couple of scenarios here which come close to needing to store-and-pass-around BasicBlock::iterator
s to encode a position correctly, but in all these situations it's correct to just call getIterator
.
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()); |
There was a problem hiding this comment.
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)
m_entry_instruction_finder.GetValue(function))); | ||
m_entry_instruction_finder.GetValue(function)) | ||
->getIterator()); |
There was a problem hiding this comment.
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.
Thanks @jmorse! |
…#112307) InsertPosition has been deprecated in favor of using BasicBlock::iterator. (See llvm#102608)
…#112307) InsertPosition has been deprecated in favor of using BasicBlock::iterator. (See llvm#102608) (cherry picked from commit 74eb079)
InsertPosition has been deprecated in favor of using BasicBlock::iterator. (See #102608)