diff options
| author | Sean Callanan <scallanan@apple.com> | 2013-04-27 02:19:33 +0000 |
|---|---|---|
| committer | Sean Callanan <scallanan@apple.com> | 2013-04-27 02:19:33 +0000 |
| commit | df56540a58271deae8b0da7ccd11141f73bd0e84 (patch) | |
| tree | 005507236d499afe698cbf5eb2b36e4312f89fa9 /lldb/source/Expression/ClangUserExpression.cpp | |
| parent | 956dca92888ebb3f770307d16f563c0e47cc0a39 (diff) | |
| download | bcm5719-llvm-df56540a58271deae8b0da7ccd11141f73bd0e84.tar.gz bcm5719-llvm-df56540a58271deae8b0da7ccd11141f73bd0e84.zip | |
Performance optimizations to ClangUserExpression,
mostly related to management of the stack frame
for the interpreter.
- First, if the expression can be interpreted,
allocate the stack frame in the target process
(to make sure pointers are valid) but only
read/write to the copy in the host's memory.
- Second, keep the memory allocations for the
stack frame and the materialized struct as
member variables of ClangUserExpression. This
avoids memory allocations and deallocations
each time the expression runs.
<rdar://problem/13043685>
llvm-svn: 180664
Diffstat (limited to 'lldb/source/Expression/ClangUserExpression.cpp')
| -rw-r--r-- | lldb/source/Expression/ClangUserExpression.cpp | 83 |
1 files changed, 61 insertions, 22 deletions
diff --git a/lldb/source/Expression/ClangUserExpression.cpp b/lldb/source/Expression/ClangUserExpression.cpp index 7357ea02e37..c72c3b10d54 100644 --- a/lldb/source/Expression/ClangUserExpression.cpp +++ b/lldb/source/Expression/ClangUserExpression.cpp @@ -56,6 +56,8 @@ ClangUserExpression::ClangUserExpression (const char *expr, lldb::LanguageType language, ResultType desired_type) : ClangExpression (), + m_stack_frame_bottom (LLDB_INVALID_ADDRESS), + m_stack_frame_top (LLDB_INVALID_ADDRESS), m_expr_text (expr), m_expr_prefix (expr_prefix ? expr_prefix : ""), m_language (language), @@ -68,7 +70,8 @@ ClangUserExpression::ClangUserExpression (const char *expr, m_needs_object_ptr (false), m_const_object (false), m_target (NULL), - m_can_interpret (false) + m_can_interpret (false), + m_materialized_address (LLDB_INVALID_ADDRESS) { switch (m_language) { @@ -641,22 +644,48 @@ ClangUserExpression::PrepareToExecuteJITExpression (Stream &error_stream, } } - Error alloc_error; - - struct_address = m_execution_unit_ap->Malloc(m_materializer_ap->GetStructByteSize(), - m_materializer_ap->GetStructAlignment(), - lldb::ePermissionsReadable | lldb::ePermissionsWritable, - IRMemoryMap::eAllocationPolicyMirror, - alloc_error); - - if (!alloc_error.Success()) + if (m_materialized_address == LLDB_INVALID_ADDRESS) { - error_stream.Printf("Couldn't allocate space for materialized struct: %s\n", alloc_error.AsCString()); - return false; + Error alloc_error; + + IRMemoryMap::AllocationPolicy policy = m_can_interpret ? IRMemoryMap::eAllocationPolicyHostOnly : IRMemoryMap::eAllocationPolicyMirror; + + m_materialized_address = m_execution_unit_ap->Malloc(m_materializer_ap->GetStructByteSize(), + m_materializer_ap->GetStructAlignment(), + lldb::ePermissionsReadable | lldb::ePermissionsWritable, + policy, + alloc_error); + + if (!alloc_error.Success()) + { + error_stream.Printf("Couldn't allocate space for materialized struct: %s\n", alloc_error.AsCString()); + return false; + } } - m_materialized_address = struct_address; + struct_address = m_materialized_address; + if (m_can_interpret && m_stack_frame_bottom == LLDB_INVALID_ADDRESS) + { + Error alloc_error; + + const size_t stack_frame_size = 512 * 1024; + + m_stack_frame_bottom = m_execution_unit_ap->Malloc(stack_frame_size, + 8, + lldb::ePermissionsReadable | lldb::ePermissionsWritable, + IRMemoryMap::eAllocationPolicyHostOnly, + alloc_error); + + m_stack_frame_top = m_stack_frame_bottom + stack_frame_size; + + if (!alloc_error.Success()) + { + error_stream.Printf("Couldn't allocate space for the stack frame: %s\n", alloc_error.AsCString()); + return false; + } + } + Error materialize_error; m_dematerializer_sp = m_materializer_ap->Materialize(frame, *m_execution_unit_ap, struct_address, materialize_error); @@ -703,7 +732,8 @@ bool ClangUserExpression::FinalizeJITExecution (Stream &error_stream, ExecutionContext &exe_ctx, lldb::ClangExpressionVariableSP &result, - lldb::addr_t function_stack_pointer) + lldb::addr_t function_stack_bottom, + lldb::addr_t function_stack_top) { Error expr_error; @@ -711,9 +741,7 @@ ClangUserExpression::FinalizeJITExecution (Stream &error_stream, if (log) log->Printf("-- [ClangUserExpression::FinalizeJITExecution] Dematerializing after execution --"); - - lldb::addr_t function_stack_bottom = function_stack_pointer - Host::GetPageSize(); - + if (!m_dematerializer_sp) { error_stream.Printf ("Couldn't dematerialize struct : no dematerializer is present"); @@ -722,7 +750,7 @@ ClangUserExpression::FinalizeJITExecution (Stream &error_stream, Error dematerialize_error; - m_dematerializer_sp->Dematerialize(dematerialize_error, result, function_stack_pointer, function_stack_bottom); + m_dematerializer_sp->Dematerialize(dematerialize_error, result, function_stack_bottom, function_stack_top); if (!dematerialize_error.Success()) { @@ -765,7 +793,8 @@ ClangUserExpression::Execute (Stream &error_stream, return eExecutionSetupError; } - lldb::addr_t function_stack_pointer = 0; + lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS; + lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS; if (m_can_interpret) { @@ -792,11 +821,16 @@ ClangUserExpression::Execute (Stream &error_stream, args.push_back(struct_address); + function_stack_bottom = m_stack_frame_bottom; + function_stack_top = m_stack_frame_top; + IRInterpreter::Interpret (*module, *function, args, *m_execution_unit_ap.get(), - interpreter_error); + interpreter_error, + function_stack_bottom, + function_stack_top); if (!interpreter_error.Success()) { @@ -823,8 +857,11 @@ ClangUserExpression::Execute (Stream &error_stream, if (!call_plan_sp || !call_plan_sp->ValidatePlan (&error_stream)) return eExecutionSetupError; - function_stack_pointer = static_cast<ThreadPlanCallFunction *>(call_plan_sp.get())->GetFunctionStackPointer(); + lldb::addr_t function_stack_pointer = static_cast<ThreadPlanCallFunction *>(call_plan_sp.get())->GetFunctionStackPointer(); + function_stack_bottom = function_stack_pointer - Host::GetPageSize(); + function_stack_top = function_stack_pointer; + if (log) log->Printf("-- [ClangUserExpression::Execute] Execution of expression begins --"); @@ -876,8 +913,10 @@ ClangUserExpression::Execute (Stream &error_stream, } } - if (FinalizeJITExecution (error_stream, exe_ctx, result, function_stack_pointer)) + if (FinalizeJITExecution (error_stream, exe_ctx, result, function_stack_bottom, function_stack_top)) + { return eExecutionCompleted; + } else { error_stream.Printf("Errored out in %s: Couldn't FinalizeJITExpression", __FUNCTION__); |

