LLDB  mainline
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
IRForTarget Class Reference

Transforms the IR for a function to run in the target. More...

#include "lldb/Expression/IRForTarget.h"

Inheritance diagram for IRForTarget:
Inheritance graph
[legend]
Collaboration diagram for IRForTarget:
Collaboration graph
[legend]

Classes

class  FunctionValueCache
 

Public Types

enum  LookupResult { LookupResult::Success, LookupResult::Fail, LookupResult::Ignore }
 

Public Member Functions

 IRForTarget (lldb_private::ClangExpressionDeclMap *decl_map, bool resolve_vars, lldb_private::IRExecutionUnit &execution_unit, lldb_private::Stream &error_stream, const char *func_name="$__lldb_expr")
 Constructor. More...
 
 ~IRForTarget () override
 Destructor. More...
 
bool runOnModule (llvm::Module &llvm_module) override
 Run this IR transformer on a single module. More...
 
void assignPassManager (llvm::PMStack &pass_mgr_stack, llvm::PassManagerType pass_mgr_type=llvm::PMT_ModulePassManager) override
 Interface stub. More...
 
llvm::PassManagerType getPotentialPassManagerType () const override
 Returns PMT_ModulePassManager. More...
 

Static Public Member Functions

static clang::NamedDecl * DeclForGlobal (const llvm::GlobalValue *global_val, llvm::Module *module)
 A function-level pass to take the generated global value $__lldb_expr_result and make it into a persistent variable. More...
 

Private Member Functions

bool FixFunctionLinkage (llvm::Function &llvm_function)
 Ensures that the current function's linkage is set to external. More...
 
bool HasSideEffects (llvm::Function &llvm_function)
 A module-level pass to replace all function pointers with their integer equivalents. More...
 
LookupResult GetFunctionAddress (llvm::Function *function, uint64_t &ptr, lldb_private::ConstString &name, llvm::Constant **&value_ptr)
 A function-level pass to check whether the function has side effects. More...
 
clang::NamedDecl * DeclForGlobal (llvm::GlobalValue *global)
 
void MaybeSetConstantResult (llvm::Constant *initializer, lldb_private::ConstString name, lldb_private::TypeFromParser type)
 Set the constant result variable m_const_result to the provided constant, assuming it can be evaluated. More...
 
void MaybeSetCastResult (lldb_private::TypeFromParser type)
 If the IR represents a cast of a variable, set m_const_result to the result of the cast. More...
 
bool CreateResultVariable (llvm::Function &llvm_function)
 The top-level pass implementation. More...
 
bool RewriteObjCConstString (llvm::GlobalVariable *NSStr, llvm::GlobalVariable *CStr)
 A module-level pass to find Objective-C constant strings and transform them to calls to CFStringCreateWithBytes. More...
 
bool RewriteObjCConstStrings ()
 The top-level pass implementation. More...
 
bool RewriteObjCSelector (llvm::Instruction *selector_load)
 A basic block-level pass to find all Objective-C method calls and rewrite them to use sel_registerName instead of statically allocated selectors. More...
 
bool RewriteObjCSelectors (llvm::BasicBlock &basic_block)
 The top-level pass implementation. More...
 
bool RewriteObjCClassReference (llvm::Instruction *class_load)
 A basic block-level pass to find all Objective-C class references that use the old-style Objective-C runtime and rewrite them to use class_getClass instead of statically allocated class references. More...
 
bool RewriteObjCClassReferences (llvm::BasicBlock &basic_block)
 The top-level pass implementation. More...
 
bool RewritePersistentAlloc (llvm::Instruction *persistent_alloc)
 A basic block-level pass to find all newly-declared persistent variables and register them with the ClangExprDeclMap. More...
 
bool RewritePersistentAllocs (llvm::BasicBlock &basic_block)
 The top-level pass implementation. More...
 
bool MaybeHandleVariable (llvm::Value *value)
 A function-level pass to find all external variables and functions used in the IR. More...
 
bool HandleSymbol (llvm::Value *symbol)
 Handle a single externally-defined symbol. More...
 
bool HandleObjCClass (llvm::Value *classlist_reference)
 Handle a single externally-defined Objective-C class. More...
 
bool MaybeHandleCallArguments (llvm::CallInst *call_inst)
 Handle all the arguments to a function call. More...
 
bool ResolveCalls (llvm::BasicBlock &basic_block)
 Resolve variable references in calls to external functions. More...
 
bool RemoveCXAAtExit (llvm::BasicBlock &basic_block)
 Remove calls to __cxa_atexit, which should never be generated by expressions. More...
 
bool ResolveExternals (llvm::Function &llvm_function)
 The top-level pass implementation. More...
 
void TurnGuardLoadIntoZero (llvm::Instruction *guard_load)
 A basic block-level pass to excise guard variables from the code. More...
 
bool RemoveGuards (llvm::BasicBlock &basic_block)
 The top-level pass implementation. More...
 
bool ReplaceVariables (llvm::Function &llvm_function)
 A function-level pass to make all external variable references point at the correct offsets from the void* passed into the function. More...
 
bool CompleteDataAllocation ()
 Commit the allocation in m_data_allocator and use its final location to replace m_reloc_placeholder. More...
 

Static Private Member Functions

static bool UnfoldConstant (llvm::Constant *old_constant, llvm::Function *llvm_function, FunctionValueCache &value_maker, FunctionValueCache &entry_instruction_finder, lldb_private::Stream &error_stream)
 UnfoldConstant operates on a constant [Old] which has just been replaced with a value [New]. More...
 

Private Attributes

bool m_resolve_vars
 Flags. More...
 
lldb_private::ConstString m_func_name
 The name of the function to translate. More...
 
lldb_private::ConstString m_result_name
 The name of the result variable ($0, $1, ...) More...
 
lldb_private::TypeFromParser m_result_type
 The type of the result variable. More...
 
llvm::Module * m_module
 The module being processed, or NULL if that has not been determined yet. More...
 
std::unique_ptr< llvm::DataLayout > m_target_data
 The target data for the module being processed, or NULL if there is no module. More...
 
lldb_private::ClangExpressionDeclMapm_decl_map
 The DeclMap containing the Decls. More...
 
llvm::FunctionCallee m_CFStringCreateWithBytes
 The address of the function CFStringCreateWithBytes, cast to the appropriate function pointer type. More...
 
llvm::FunctionCallee m_sel_registerName
 The address of the function sel_registerName, cast to the appropriate function pointer type. More...
 
llvm::FunctionCallee m_objc_getClass
 The address of the function objc_getClass, cast to the appropriate function pointer type. More...
 
llvm::IntegerType * m_intptr_ty
 The type of an integer large enough to hold a pointer. More...
 
lldb_private::Streamm_error_stream
 The stream on which errors should be printed. More...
 
lldb_private::IRExecutionUnitm_execution_unit
 The execution unit containing the IR being created. More...
 
llvm::StoreInst * m_result_store
 If non-NULL, the store instruction that writes to the result variable. More...
 
bool m_result_is_pointer
 True if the function's result in the AST is a pointer (see comments in ASTResultSynthesizer::SynthesizeBodyResult) More...
 
llvm::GlobalVariable * m_reloc_placeholder
 A placeholder that will be replaced by a pointer to the final location of the static allocation. More...
 
FunctionValueCache m_entry_instruction_finder
 

Detailed Description

Transforms the IR for a function to run in the target.

Once an expression has been parsed and converted to IR, it can run in two contexts: interpreted by LLDB as a DWARF location expression, or compiled by the JIT and inserted into the target process for execution.

IRForTarget makes the second possible, by applying a series of transformations to the IR which make it relocatable. These transformations are discussed in more detail next to their relevant functions.

Definition at line 61 of file IRForTarget.h.

Member Enumeration Documentation

◆ LookupResult

Enumerator
Success 
Fail 
Ignore 

Definition at line 63 of file IRForTarget.h.

Constructor & Destructor Documentation

◆ IRForTarget()

IRForTarget::IRForTarget ( lldb_private::ClangExpressionDeclMap decl_map,
bool  resolve_vars,
lldb_private::IRExecutionUnit execution_unit,
lldb_private::Stream error_stream,
const char *  func_name = "$__lldb_expr" 
)

Constructor.

Parameters
[in]decl_mapThe list of externally-referenced variables for the expression, for use in looking up globals and allocating the argument struct. See the documentation for ClangExpressionDeclMap.
[in]resolve_varsTrue if the external variable references (including persistent variables) should be resolved. If not, only external functions are resolved.
[in]execution_unitThe holder for raw data associated with the expression.
[in]error_streamIf non-NULL, a stream on which errors can be printed.
[in]func_nameThe name of the function to prepare for execution in the target.

Definition at line 70 of file IRForTarget.cpp.

◆ ~IRForTarget()

IRForTarget::~IRForTarget ( )
override

Destructor.

Definition at line 108 of file IRForTarget.cpp.

Member Function Documentation

◆ assignPassManager()

void IRForTarget::assignPassManager ( llvm::PMStack &  pass_mgr_stack,
llvm::PassManagerType  pass_mgr_type = llvm::PMT_ModulePassManager 
)
override

Interface stub.

Implementation of the llvm::ModulePass::assignPassManager() function.

Definition at line 2025 of file IRForTarget.cpp.

◆ CompleteDataAllocation()

bool IRForTarget::CompleteDataAllocation ( )
private

Commit the allocation in m_data_allocator and use its final location to replace m_reloc_placeholder.

Returns
True on success; false otherwise

◆ CreateResultVariable()

bool IRForTarget::CreateResultVariable ( llvm::Function &  llvm_function)
private

◆ DeclForGlobal() [1/2]

static clang::NamedDecl* IRForTarget::DeclForGlobal ( const llvm::GlobalValue *  global_val,
llvm::Module *  module 
)
static

A function-level pass to take the generated global value $__lldb_expr_result and make it into a persistent variable.

Also see ASTResultSynthesizer. Find the NamedDecl corresponding to a Value. This interface is exposed for the IR interpreter.

Parameters
[in]global_valThe global entity to search for
[in]moduleThe module containing metadata to search
Returns
The corresponding variable declaration

Referenced by CreateResultVariable(), FixFunctionLinkage(), MaybeHandleVariable(), and ResolveExternals().

◆ DeclForGlobal() [2/2]

clang::NamedDecl* IRForTarget::DeclForGlobal ( llvm::GlobalValue *  global)
private

◆ FixFunctionLinkage()

bool IRForTarget::FixFunctionLinkage ( llvm::Function &  llvm_function)
private

Ensures that the current function's linkage is set to external.

Otherwise the JIT may not return an address for it.

Parameters
[in]llvm_functionThe function whose linkage is to be fixed.
Returns
True on success; false otherwise.

Definition at line 110 of file IRForTarget.cpp.

References DeclForGlobal(), and m_module.

Referenced by runOnModule().

◆ GetFunctionAddress()

LookupResult IRForTarget::GetFunctionAddress ( llvm::Function *  function,
uint64_t &  ptr,
lldb_private::ConstString name,
llvm::Constant **&  value_ptr 
)
private

A function-level pass to check whether the function has side effects.

Get the address of a function, and a location to put the complete Value of the function if one is available.

Parameters
[in]functionThe function to find the location of.
[out]ptrThe location of the function in the target.
[out]nameThe resolved name of the function (matters for intrinsics).
[out]value_ptrA variable to put the function's completed Value* in, or NULL if the Value* shouldn't be stored anywhere.
Returns
The pointer.

◆ getPotentialPassManagerType()

PassManagerType IRForTarget::getPotentialPassManagerType ( ) const
override

Returns PMT_ModulePassManager.

Implementation of the llvm::ModulePass::getPotentialPassManagerType() function.

Definition at line 2028 of file IRForTarget.cpp.

◆ HandleObjCClass()

bool IRForTarget::HandleObjCClass ( llvm::Value *  classlist_reference)
private

Handle a single externally-defined Objective-C class.

Parameters
[in]classlist_referenceThe reference, usually "01L_OBJC_CLASSLIST_REFERENCES_$_n" where n (if present) is an index.
Returns
True on success; false otherwise

Definition at line 1325 of file IRForTarget.cpp.

References lldb::eSymbolTypeObjCClass, lldb_private::GetLogIfAllCategoriesSet(), lldb_private::ClangExpressionDeclMap::GetSymbolAddress(), LIBLLDB_LOG_EXPRESSIONS, LLDB_INVALID_ADDRESS, LLDB_LOG, m_decl_map, and m_intptr_ty.

Referenced by ResolveExternals().

◆ HandleSymbol()

bool IRForTarget::HandleSymbol ( llvm::Value *  symbol)
private

Handle a single externally-defined symbol.

Parameters
[in]symbolThe symbol.
Returns
True on success; false otherwise

Definition at line 1274 of file IRForTarget.cpp.

References lldb::eSymbolTypeAny, lldb_private::GetLogIfAllCategoriesSet(), lldb_private::ClangExpressionDeclMap::GetSymbolAddress(), LIBLLDB_LOG_EXPRESSIONS, LLDB_INVALID_ADDRESS, LLDB_LOG, m_decl_map, m_intptr_ty, and PrintValue().

Referenced by ResolveExternals().

◆ HasSideEffects()

bool IRForTarget::HasSideEffects ( llvm::Function &  llvm_function)
private

A module-level pass to replace all function pointers with their integer equivalents.

The top-level pass implementation

Parameters
[in]llvm_functionThe function currently being processed.
Returns
True on success; false otherwise.

◆ MaybeHandleCallArguments()

bool IRForTarget::MaybeHandleCallArguments ( llvm::CallInst *  call_inst)
private

Handle all the arguments to a function call.

Parameters
[in]call_instThe call instruction.
Returns
True on success; false otherwise

Definition at line 1306 of file IRForTarget.cpp.

References lldb_private::GetLogIfAllCategoriesSet(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, m_error_stream, MaybeHandleVariable(), lldb_private::Stream::Printf(), and PrintValue().

Referenced by ResolveCalls().

◆ MaybeHandleVariable()

bool IRForTarget::MaybeHandleVariable ( llvm::Value *  value)
private

A function-level pass to find all external variables and functions used in the IR.

Each found external variable is added to the struct, and each external function is resolved in place, its call replaced with a call to a function pointer whose value is the address of the function in the target process. Handle a single externally-defined variable

Parameters
[in]valueThe variable.
Returns
True on success; false otherwise

Definition at line 1181 of file IRForTarget.cpp.

References lldb_private::ClangExpressionDeclMap::AddValueToStruct(), DeclForGlobal(), lldb_private::CompilerType::GetByteSize(), lldb_private::GetLogIfAllCategoriesSet(), lldb_private::CompilerType::GetPointerType(), lldb_private::ClangUtil::GetQualType(), lldb_private::TypeSystemClang::GetType(), lldb_private::CompilerType::GetTypeBitAlign(), lldb_private::ClangASTSource::GetTypeSystem(), IsObjCSelectorRef(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, m_decl_map, PrintType(), and PrintValue().

Referenced by MaybeHandleCallArguments(), and ResolveExternals().

◆ MaybeSetCastResult()

void IRForTarget::MaybeSetCastResult ( lldb_private::TypeFromParser  type)
private

If the IR represents a cast of a variable, set m_const_result to the result of the cast.

The result variable will be reset to NULL latger if the expression has side effects.

Parameters
[in]typeThe Clang type of the result variable.

◆ MaybeSetConstantResult()

void IRForTarget::MaybeSetConstantResult ( llvm::Constant *  initializer,
lldb_private::ConstString  name,
lldb_private::TypeFromParser  type 
)
private

Set the constant result variable m_const_result to the provided constant, assuming it can be evaluated.

The result variable will be reset to NULL later if the expression has side effects.

Parameters
[in]initializerThe constant initializer for the variable.
[in]nameThe name of the result variable.
[in]typeThe Clang type of the result variable.

◆ RemoveCXAAtExit()

bool IRForTarget::RemoveCXAAtExit ( llvm::BasicBlock &  basic_block)
private

Remove calls to __cxa_atexit, which should never be generated by expressions.

Parameters
[in]basic_blockThe basic block currently being processed.
Returns
True if the scan was successful; false if some operation failed

Definition at line 1381 of file IRForTarget.cpp.

Referenced by runOnModule().

◆ RemoveGuards()

bool IRForTarget::RemoveGuards ( llvm::BasicBlock &  basic_block)
private

The top-level pass implementation.

Parameters
[in]basic_blockThe basic block currently being processed.
Returns
True on success; false otherwise

Definition at line 1504 of file IRForTarget.cpp.

References ExciseGuardStore(), isGuardVariableRef(), and TurnGuardLoadIntoZero().

Referenced by runOnModule().

◆ ReplaceVariables()

bool IRForTarget::ReplaceVariables ( llvm::Function &  llvm_function)
private

A function-level pass to make all external variable references point at the correct offsets from the void* passed into the function.

ClangExpressionDeclMap::DoStructLayout() must be called beforehand, so that the offsets are valid. The top-level pass implementation

Parameters
[in]llvm_functionThe function currently being processed.
Returns
True on success; false otherwise

Definition at line 1649 of file IRForTarget.cpp.

References lldb_private::ClangExpressionDeclMap::DoStructLayout(), lldb_private::Stream::Format(), lldb_private::GetLogIfAllCategoriesSet(), lldb_private::ClangExpressionDeclMap::GetStructElement(), lldb_private::ClangExpressionDeclMap::GetStructInfo(), IRForTarget::FunctionValueCache::GetValue(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, m_decl_map, m_entry_instruction_finder, m_error_stream, m_module, m_resolve_vars, m_result_is_pointer, m_result_name, lldb_private::Stream::Printf(), PrintValue(), lldb_private::Stream::PutCString(), and UnfoldConstant().

Referenced by runOnModule().

◆ ResolveCalls()

bool IRForTarget::ResolveCalls ( llvm::BasicBlock &  basic_block)
private

Resolve variable references in calls to external functions.

Parameters
[in]basic_blockThe basic block currently being processed.
Returns
True on success; false otherwise

Definition at line 1413 of file IRForTarget.cpp.

References MaybeHandleCallArguments().

Referenced by runOnModule().

◆ ResolveExternals()

bool IRForTarget::ResolveExternals ( llvm::Function &  llvm_function)
private

The top-level pass implementation.

Parameters
[in]llvm_functionThe function currently being processed.
Returns
True on success; false otherwise

Definition at line 1427 of file IRForTarget.cpp.

References DeclForGlobal(), lldb_private::Stream::Format(), lldb_private::GetLogIfAllCategoriesSet(), HandleObjCClass(), HandleSymbol(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, m_error_stream, m_module, MaybeHandleVariable(), and lldb_private::Stream::Printf().

Referenced by runOnModule().

◆ RewriteObjCClassReference()

bool IRForTarget::RewriteObjCClassReference ( llvm::Instruction *  class_load)
private

A basic block-level pass to find all Objective-C class references that use the old-style Objective-C runtime and rewrite them to use class_getClass instead of statically allocated class references.

Replace a single old-style class reference

Parameters
[in]class_loadThe load of the statically-allocated selector.
Returns
True on success; false otherwise

Definition at line 922 of file IRForTarget.cpp.

References lldb_private::IRExecutionUnit::FindSymbol(), lldb_private::GetLogIfAllCategoriesSet(), LIBLLDB_LOG_EXPRESSIONS, LLDB_INVALID_ADDRESS, LLDB_LOG, m_execution_unit, m_intptr_ty, m_module, and m_objc_getClass.

Referenced by RewriteObjCClassReferences().

◆ RewriteObjCClassReferences()

bool IRForTarget::RewriteObjCClassReferences ( llvm::BasicBlock &  basic_block)
private

The top-level pass implementation.

Parameters
[in]basic_blockThe basic block currently being processed.
Returns
True on success; false otherwise

Definition at line 1039 of file IRForTarget.cpp.

References lldb_private::GetLogIfAllCategoriesSet(), IsObjCClassReference(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, m_error_stream, lldb_private::Stream::Printf(), and RewriteObjCClassReference().

Referenced by runOnModule().

◆ RewriteObjCConstString()

bool IRForTarget::RewriteObjCConstString ( llvm::GlobalVariable *  NSStr,
llvm::GlobalVariable *  CStr 
)
private

A module-level pass to find Objective-C constant strings and transform them to calls to CFStringCreateWithBytes.

Rewrite a single Objective-C constant string.

Parameters
[in]NSStrThe constant NSString to be transformed
[in]CStrThe constant C string inside the NSString. This will be passed as the bytes argument to CFStringCreateWithBytes.
Returns
True on success; false otherwise

Definition at line 408 of file IRForTarget.cpp.

References lldb_private::IRExecutionUnit::FindSymbol(), lldb_private::GetLogIfAllCategoriesSet(), IRForTarget::FunctionValueCache::GetValue(), LIBLLDB_LOG_EXPRESSIONS, LLDB_INVALID_ADDRESS, LLDB_LOG, m_CFStringCreateWithBytes, m_entry_instruction_finder, m_error_stream, m_execution_unit, m_intptr_ty, m_module, lldb_private::Stream::Printf(), UnfoldConstant(), and arm64_dwarf::x0.

Referenced by RewriteObjCConstStrings().

◆ RewriteObjCConstStrings()

bool IRForTarget::RewriteObjCConstStrings ( )
private

The top-level pass implementation.

Returns
True on success; false otherwise

Definition at line 547 of file IRForTarget.cpp.

References lldb_private::GetLogIfAllCategoriesSet(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, m_error_stream, m_module, lldb_private::Stream::Printf(), and RewriteObjCConstString().

Referenced by runOnModule().

◆ RewriteObjCSelector()

bool IRForTarget::RewriteObjCSelector ( llvm::Instruction *  selector_load)
private

A basic block-level pass to find all Objective-C method calls and rewrite them to use sel_registerName instead of statically allocated selectors.

The reason is that the selectors are created on the assumption that the Objective-C runtime will scan the appropriate section and prepare them. This doesn't happen when code is copied into the target, though, and there's no easy way to induce the runtime to scan them. So instead we get our selectors from sel_registerName. Replace a single selector reference

Parameters
[in]selector_loadThe load of the statically-allocated selector.
Returns
True on success; false otherwise

Definition at line 760 of file IRForTarget.cpp.

References lldb_private::IRExecutionUnit::FindSymbol(), lldb_private::GetLogIfAllCategoriesSet(), LIBLLDB_LOG_EXPRESSIONS, LLDB_INVALID_ADDRESS, LLDB_LOG, m_execution_unit, m_intptr_ty, m_module, and m_sel_registerName.

Referenced by RewriteObjCSelectors().

◆ RewriteObjCSelectors()

bool IRForTarget::RewriteObjCSelectors ( llvm::BasicBlock &  basic_block)
private

The top-level pass implementation.

Parameters
[in]basic_blockThe basic block currently being processed.
Returns
True on success; false otherwise

Definition at line 887 of file IRForTarget.cpp.

References lldb_private::GetLogIfAllCategoriesSet(), IsObjCSelectorRef(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, m_error_stream, lldb_private::Stream::Printf(), and RewriteObjCSelector().

Referenced by runOnModule().

◆ RewritePersistentAlloc()

bool IRForTarget::RewritePersistentAlloc ( llvm::Instruction *  persistent_alloc)
private

A basic block-level pass to find all newly-declared persistent variables and register them with the ClangExprDeclMap.

This allows them to be materialized and dematerialized like normal external variables. Before transformation, these persistent variables look like normal locals, so they have an allocation. This pass excises these allocations and makes references look like external references where they will be resolved – like all other external references – by ResolveExternals(). Handle a single allocation of a persistent variable

Parameters
[in]persistent_allocThe allocation of the persistent variable.
Returns
True on success; false otherwise

Definition at line 1067 of file IRForTarget.cpp.

References lldb_private::ClangExpressionDeclMap::AddPersistentVariable(), lldb_private::GetLogIfAllCategoriesSet(), lldb_private::TypeSystemClang::GetType(), lldb_private::ClangASTSource::GetTypeSystem(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, m_decl_map, m_module, and PrintValue().

Referenced by RewritePersistentAllocs().

◆ RewritePersistentAllocs()

bool IRForTarget::RewritePersistentAllocs ( llvm::BasicBlock &  basic_block)
private

The top-level pass implementation.

Parameters
[in]basic_blockThe basic block currently being processed.

Definition at line 1136 of file IRForTarget.cpp.

References lldb_private::GetLogIfAllCategoriesSet(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, m_error_stream, m_resolve_vars, lldb_private::Stream::Printf(), and RewritePersistentAlloc().

Referenced by runOnModule().

◆ runOnModule()

bool IRForTarget::runOnModule ( llvm::Module &  llvm_module)
override

Run this IR transformer on a single module.

Implementation of the llvm::ModulePass::runOnModule() function.

Parameters
[in]llvm_moduleThe module to run on. This module is searched for the function $__lldb_expr, and that function is passed to the passes one by one.
Returns
True on success; false otherwise

Definition at line 1840 of file IRForTarget.cpp.

References CreateResultVariable(), FixFunctionLinkage(), lldb_private::Stream::Format(), lldb_private::GetLogIfAllCategoriesSet(), lldb_private::ConstString::GetStringRef(), lldb_private::Log::GetVerbose(), lldb_private::ConstString::IsEmpty(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOG, m_error_stream, m_func_name, m_intptr_ty, m_module, m_reloc_placeholder, m_target_data, RemoveCXAAtExit(), RemoveGuards(), ReplaceVariables(), ResolveCalls(), ResolveExternals(), RewriteObjCClassReferences(), RewriteObjCConstStrings(), RewriteObjCSelectors(), and RewritePersistentAllocs().

◆ TurnGuardLoadIntoZero()

void IRForTarget::TurnGuardLoadIntoZero ( llvm::Instruction *  guard_load)
private

A basic block-level pass to excise guard variables from the code.

The result for the function is passed through Clang as a static variable. Static variables normally have guard variables to ensure that they are only initialized once. Rewrite a load to a guard variable to return constant 0.

Parameters
[in]guard_loadThe load instruction to zero out.

Definition at line 1494 of file IRForTarget.cpp.

Referenced by RemoveGuards().

◆ UnfoldConstant()

bool IRForTarget::UnfoldConstant ( llvm::Constant *  old_constant,
llvm::Function *  llvm_function,
FunctionValueCache value_maker,
FunctionValueCache entry_instruction_finder,
lldb_private::Stream error_stream 
)
staticprivate

UnfoldConstant operates on a constant [Old] which has just been replaced with a value [New].

We assume that new_value has been properly placed early in the function, in front of the first instruction in the entry basic block [FirstEntryInstruction].

UnfoldConstant reads through the uses of Old and replaces Old in those uses with New. Where those uses are constants, the function generates new instructions to compute the result of the new, non-constant expression and places them before FirstEntryInstruction. These instructions replace the constant uses, so UnfoldConstant calls itself recursively for those.

Returns
True on success; false otherwise

Definition at line 1531 of file IRForTarget.cpp.

References IRForTarget::FunctionValueCache::GetValue(), lldb_private::Stream::Printf(), PrintValue(), and lldb_private::Stream::PutCString().

Referenced by ReplaceVariables(), and RewriteObjCConstString().

Member Data Documentation

◆ m_CFStringCreateWithBytes

llvm::FunctionCallee IRForTarget::m_CFStringCreateWithBytes
private

The address of the function CFStringCreateWithBytes, cast to the appropriate function pointer type.

Definition at line 440 of file IRForTarget.h.

Referenced by RewriteObjCConstString().

◆ m_decl_map

lldb_private::ClangExpressionDeclMap* IRForTarget::m_decl_map
private

The DeclMap containing the Decls.

Definition at line 438 of file IRForTarget.h.

Referenced by CreateResultVariable(), HandleObjCClass(), HandleSymbol(), MaybeHandleVariable(), ReplaceVariables(), and RewritePersistentAlloc().

◆ m_entry_instruction_finder

FunctionValueCache IRForTarget::m_entry_instruction_finder
private

Definition at line 482 of file IRForTarget.h.

Referenced by ReplaceVariables(), and RewriteObjCConstString().

◆ m_error_stream

lldb_private::Stream& IRForTarget::m_error_stream
private

◆ m_execution_unit

lldb_private::IRExecutionUnit& IRForTarget::m_execution_unit
private

The execution unit containing the IR being created.

Definition at line 454 of file IRForTarget.h.

Referenced by CreateResultVariable(), RewriteObjCClassReference(), RewriteObjCConstString(), and RewriteObjCSelector().

◆ m_func_name

lldb_private::ConstString IRForTarget::m_func_name
private

The name of the function to translate.

Definition at line 426 of file IRForTarget.h.

Referenced by runOnModule().

◆ m_intptr_ty

llvm::IntegerType* IRForTarget::m_intptr_ty
private

The type of an integer large enough to hold a pointer.

Definition at line 450 of file IRForTarget.h.

Referenced by HandleObjCClass(), HandleSymbol(), RewriteObjCClassReference(), RewriteObjCConstString(), RewriteObjCSelector(), and runOnModule().

◆ m_module

llvm::Module* IRForTarget::m_module
private

◆ m_objc_getClass

llvm::FunctionCallee IRForTarget::m_objc_getClass
private

The address of the function objc_getClass, cast to the appropriate function pointer type.

Definition at line 446 of file IRForTarget.h.

Referenced by RewriteObjCClassReference().

◆ m_reloc_placeholder

llvm::GlobalVariable* IRForTarget::m_reloc_placeholder
private

A placeholder that will be replaced by a pointer to the final location of the static allocation.

Definition at line 466 of file IRForTarget.h.

Referenced by runOnModule().

◆ m_resolve_vars

bool IRForTarget::m_resolve_vars
private

Flags.

True if external variable references and persistent variable references should be resolved

Definition at line 423 of file IRForTarget.h.

Referenced by CreateResultVariable(), ReplaceVariables(), and RewritePersistentAllocs().

◆ m_result_is_pointer

bool IRForTarget::m_result_is_pointer
private

True if the function's result in the AST is a pointer (see comments in ASTResultSynthesizer::SynthesizeBodyResult)

Definition at line 460 of file IRForTarget.h.

Referenced by CreateResultVariable(), and ReplaceVariables().

◆ m_result_name

lldb_private::ConstString IRForTarget::m_result_name
private

The name of the result variable ($0, $1, ...)

Definition at line 428 of file IRForTarget.h.

Referenced by CreateResultVariable(), and ReplaceVariables().

◆ m_result_store

llvm::StoreInst* IRForTarget::m_result_store
private

If non-NULL, the store instruction that writes to the result variable.

If m_has_side_effects is true, this is NULL.

Definition at line 456 of file IRForTarget.h.

◆ m_result_type

lldb_private::TypeFromParser IRForTarget::m_result_type
private

The type of the result variable.

Definition at line 430 of file IRForTarget.h.

Referenced by CreateResultVariable().

◆ m_sel_registerName

llvm::FunctionCallee IRForTarget::m_sel_registerName
private

The address of the function sel_registerName, cast to the appropriate function pointer type.

Definition at line 443 of file IRForTarget.h.

Referenced by RewriteObjCSelector().

◆ m_target_data

std::unique_ptr<llvm::DataLayout> IRForTarget::m_target_data
private

The target data for the module being processed, or NULL if there is no module.

Definition at line 433 of file IRForTarget.h.

Referenced by runOnModule().


The documentation for this class was generated from the following files: