Skip to content

Commit

Permalink
[lldb] Avoid calling DataLayout constructor accepting Module pointer …
Browse files Browse the repository at this point in the history
…(NFC) (llvm#102839)

The constructor initializes `*this` with a copy of `M->getDataLayout()`,
which can just be spelled as `DataLayout DL = M->getDataLayout()`. In
all places where the constructor is used, Module outlives DataLayout, so
store a reference to it instead of cloning.

Pull Request: llvm#102839
  • Loading branch information
s-barannikov authored Aug 12, 2024
1 parent b812e57 commit e26b42c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lldb/source/Expression/IRInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class InterpreterStackFrame {
typedef std::map<const Value *, lldb::addr_t> ValueMap;

ValueMap m_values;
DataLayout &m_target_data;
const DataLayout &m_target_data;
lldb_private::IRExecutionUnit &m_execution_unit;
const BasicBlock *m_bb = nullptr;
const BasicBlock *m_prev_bb = nullptr;
Expand All @@ -110,7 +110,7 @@ class InterpreterStackFrame {
lldb::ByteOrder m_byte_order;
size_t m_addr_byte_size;

InterpreterStackFrame(DataLayout &target_data,
InterpreterStackFrame(const DataLayout &target_data,
lldb_private::IRExecutionUnit &execution_unit,
lldb::addr_t stack_frame_bottom,
lldb::addr_t stack_frame_top)
Expand Down Expand Up @@ -703,7 +703,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function,
s.c_str());
}

DataLayout data_layout(&module);
const DataLayout &data_layout = module.getDataLayout();

InterpreterStackFrame frame(data_layout, execution_unit, stack_frame_bottom,
stack_frame_top);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,9 @@ class Instrumenter {

IntegerType *GetIntptrTy() {
if (!m_intptr_ty) {
llvm::DataLayout data_layout(&m_module);

m_intptr_ty = llvm::Type::getIntNTy(m_module.getContext(),
data_layout.getPointerSizeInBits());
m_intptr_ty = llvm::Type::getIntNTy(
m_module.getContext(),
m_module.getDataLayout().getPointerSizeInBits());
}

return m_intptr_ty;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ bool IRForTarget::runOnModule(Module &llvm_module) {
lldb_private::Log *log(GetLog(LLDBLog::Expressions));

m_module = &llvm_module;
m_target_data = std::make_unique<DataLayout>(m_module);
m_target_data = &m_module->getDataLayout();
m_intptr_ty = llvm::Type::getIntNTy(m_module->getContext(),
m_target_data->getPointerSizeInBits());

Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ class IRForTarget {
lldb_private::TypeFromParser m_result_type;
/// The module being processed, or NULL if that has not been determined yet.
llvm::Module *m_module = nullptr;
/// The target data for the module being processed, or NULL if there is no
/// The target data for the module being processed, or nullptr if there is no
/// module.
std::unique_ptr<llvm::DataLayout> m_target_data;
const llvm::DataLayout *m_target_data = nullptr;
/// The DeclMap containing the Decls
lldb_private::ClangExpressionDeclMap *m_decl_map;
/// The address of the function CFStringCreateWithBytes, cast to the
Expand Down

0 comments on commit e26b42c

Please sign in to comment.