xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
10b57cec5SDimitry Andric //===-- IRForTarget.h ---------------------------------------------*- C++
20b57cec5SDimitry Andric //-*-===//
30b57cec5SDimitry Andric //
40b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric //
80b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric 
105ffd83dbSDimitry Andric #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_IRFORTARGET_H
115ffd83dbSDimitry Andric #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_IRFORTARGET_H
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "lldb/Symbol/TaggedASTType.h"
140b57cec5SDimitry Andric #include "lldb/Utility/ConstString.h"
150b57cec5SDimitry Andric #include "lldb/Utility/Status.h"
160b57cec5SDimitry Andric #include "lldb/Utility/Stream.h"
170b57cec5SDimitry Andric #include "lldb/Utility/StreamString.h"
180b57cec5SDimitry Andric #include "lldb/lldb-public.h"
190b57cec5SDimitry Andric #include "llvm/IR/DerivedTypes.h"
200b57cec5SDimitry Andric #include "llvm/Pass.h"
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric #include <functional>
230b57cec5SDimitry Andric #include <map>
240b57cec5SDimitry Andric 
250b57cec5SDimitry Andric namespace llvm {
260b57cec5SDimitry Andric class BasicBlock;
270b57cec5SDimitry Andric class CallInst;
280b57cec5SDimitry Andric class Constant;
290b57cec5SDimitry Andric class ConstantInt;
300b57cec5SDimitry Andric class Function;
310b57cec5SDimitry Andric class GlobalValue;
320b57cec5SDimitry Andric class GlobalVariable;
330b57cec5SDimitry Andric class Instruction;
340b57cec5SDimitry Andric class Module;
350b57cec5SDimitry Andric class StoreInst;
360b57cec5SDimitry Andric class DataLayout;
370b57cec5SDimitry Andric class Value;
380b57cec5SDimitry Andric }
390b57cec5SDimitry Andric 
405ffd83dbSDimitry Andric namespace clang {
415ffd83dbSDimitry Andric class NamedDecl;
425ffd83dbSDimitry Andric }
435ffd83dbSDimitry Andric 
440b57cec5SDimitry Andric namespace lldb_private {
450b57cec5SDimitry Andric class ClangExpressionDeclMap;
460b57cec5SDimitry Andric class IRExecutionUnit;
470b57cec5SDimitry Andric class IRMemoryMap;
480b57cec5SDimitry Andric }
490b57cec5SDimitry Andric 
500b57cec5SDimitry Andric /// \class IRForTarget IRForTarget.h "lldb/Expression/IRForTarget.h"
510b57cec5SDimitry Andric /// Transforms the IR for a function to run in the target
520b57cec5SDimitry Andric ///
530b57cec5SDimitry Andric /// Once an expression has been parsed and converted to IR, it can run in two
540b57cec5SDimitry Andric /// contexts: interpreted by LLDB as a DWARF location expression, or compiled
550b57cec5SDimitry Andric /// by the JIT and inserted into the target process for execution.
560b57cec5SDimitry Andric ///
570b57cec5SDimitry Andric /// IRForTarget makes the second possible, by applying a series of
580b57cec5SDimitry Andric /// transformations to the IR which make it relocatable.  These
590b57cec5SDimitry Andric /// transformations are discussed in more detail next to their relevant
600b57cec5SDimitry Andric /// functions.
61*fe6060f1SDimitry Andric class IRForTarget {
620b57cec5SDimitry Andric public:
630b57cec5SDimitry Andric   enum class LookupResult { Success, Fail, Ignore };
640b57cec5SDimitry Andric 
650b57cec5SDimitry Andric   /// Constructor
660b57cec5SDimitry Andric   ///
670b57cec5SDimitry Andric   /// \param[in] decl_map
680b57cec5SDimitry Andric   ///     The list of externally-referenced variables for the expression,
690b57cec5SDimitry Andric   ///     for use in looking up globals and allocating the argument
700b57cec5SDimitry Andric   ///     struct.  See the documentation for ClangExpressionDeclMap.
710b57cec5SDimitry Andric   ///
720b57cec5SDimitry Andric   /// \param[in] resolve_vars
730b57cec5SDimitry Andric   ///     True if the external variable references (including persistent
740b57cec5SDimitry Andric   ///     variables) should be resolved.  If not, only external functions
750b57cec5SDimitry Andric   ///     are resolved.
760b57cec5SDimitry Andric   ///
770b57cec5SDimitry Andric   /// \param[in] execution_unit
780b57cec5SDimitry Andric   ///     The holder for raw data associated with the expression.
790b57cec5SDimitry Andric   ///
800b57cec5SDimitry Andric   /// \param[in] error_stream
810b57cec5SDimitry Andric   ///     If non-NULL, a stream on which errors can be printed.
820b57cec5SDimitry Andric   ///
830b57cec5SDimitry Andric   /// \param[in] func_name
840b57cec5SDimitry Andric   ///     The name of the function to prepare for execution in the target.
850b57cec5SDimitry Andric   IRForTarget(lldb_private::ClangExpressionDeclMap *decl_map, bool resolve_vars,
860b57cec5SDimitry Andric               lldb_private::IRExecutionUnit &execution_unit,
870b57cec5SDimitry Andric               lldb_private::Stream &error_stream,
880b57cec5SDimitry Andric               const char *func_name = "$__lldb_expr");
890b57cec5SDimitry Andric 
900b57cec5SDimitry Andric   /// Run this IR transformer on a single module
910b57cec5SDimitry Andric   ///
920b57cec5SDimitry Andric   /// Implementation of the llvm::ModulePass::runOnModule() function.
930b57cec5SDimitry Andric   ///
940b57cec5SDimitry Andric   /// \param[in] llvm_module
950b57cec5SDimitry Andric   ///     The module to run on.  This module is searched for the function
960b57cec5SDimitry Andric   ///     $__lldb_expr, and that function is passed to the passes one by
970b57cec5SDimitry Andric   ///     one.
980b57cec5SDimitry Andric   ///
990b57cec5SDimitry Andric   /// \return
1000b57cec5SDimitry Andric   ///     True on success; false otherwise
101*fe6060f1SDimitry Andric   bool runOnModule(llvm::Module &llvm_module);
1020b57cec5SDimitry Andric 
1030b57cec5SDimitry Andric private:
1040b57cec5SDimitry Andric   /// Ensures that the current function's linkage is set to external.
1050b57cec5SDimitry Andric   /// Otherwise the JIT may not return an address for it.
1060b57cec5SDimitry Andric   ///
1070b57cec5SDimitry Andric   /// \param[in] llvm_function
1080b57cec5SDimitry Andric   ///     The function whose linkage is to be fixed.
1090b57cec5SDimitry Andric   ///
1100b57cec5SDimitry Andric   /// \return
1110b57cec5SDimitry Andric   ///     True on success; false otherwise.
1120b57cec5SDimitry Andric   bool FixFunctionLinkage(llvm::Function &llvm_function);
1130b57cec5SDimitry Andric 
1140b57cec5SDimitry Andric   /// A function-level pass to take the generated global value
1150b57cec5SDimitry Andric   /// $__lldb_expr_result and make it into a persistent variable. Also see
1160b57cec5SDimitry Andric   /// ASTResultSynthesizer.
1170b57cec5SDimitry Andric 
1180b57cec5SDimitry Andric   /// Find the NamedDecl corresponding to a Value.  This interface is exposed
1190b57cec5SDimitry Andric   /// for the IR interpreter.
1200b57cec5SDimitry Andric   ///
121480093f4SDimitry Andric   /// \param[in] global_val
122480093f4SDimitry Andric   ///     The global entity to search for
123480093f4SDimitry Andric   ///
1240b57cec5SDimitry Andric   /// \param[in] module
1250b57cec5SDimitry Andric   ///     The module containing metadata to search
1260b57cec5SDimitry Andric   ///
1270b57cec5SDimitry Andric   /// \return
1280b57cec5SDimitry Andric   ///     The corresponding variable declaration
1290b57cec5SDimitry Andric public:
1300b57cec5SDimitry Andric   static clang::NamedDecl *DeclForGlobal(const llvm::GlobalValue *global_val,
1310b57cec5SDimitry Andric                                          llvm::Module *module);
1320b57cec5SDimitry Andric 
1330b57cec5SDimitry Andric private:
1340b57cec5SDimitry Andric   clang::NamedDecl *DeclForGlobal(llvm::GlobalValue *global);
1350b57cec5SDimitry Andric 
1360b57cec5SDimitry Andric   /// The top-level pass implementation
1370b57cec5SDimitry Andric   ///
1380b57cec5SDimitry Andric   /// \param[in] llvm_function
1390b57cec5SDimitry Andric   ///     The function currently being processed.
1400b57cec5SDimitry Andric   ///
1410b57cec5SDimitry Andric   /// \return
1420b57cec5SDimitry Andric   ///     True on success; false otherwise
1430b57cec5SDimitry Andric   bool CreateResultVariable(llvm::Function &llvm_function);
1440b57cec5SDimitry Andric 
1450b57cec5SDimitry Andric   /// A module-level pass to find Objective-C constant strings and
1460b57cec5SDimitry Andric   /// transform them to calls to CFStringCreateWithBytes.
1470b57cec5SDimitry Andric 
1480b57cec5SDimitry Andric   /// Rewrite a single Objective-C constant string.
1490b57cec5SDimitry Andric   ///
1500b57cec5SDimitry Andric   /// \param[in] NSStr
1510b57cec5SDimitry Andric   ///     The constant NSString to be transformed
1520b57cec5SDimitry Andric   ///
1530b57cec5SDimitry Andric   /// \param[in] CStr
1540b57cec5SDimitry Andric   ///     The constant C string inside the NSString.  This will be
1550b57cec5SDimitry Andric   ///     passed as the bytes argument to CFStringCreateWithBytes.
1560b57cec5SDimitry Andric   ///
1570b57cec5SDimitry Andric   /// \return
1580b57cec5SDimitry Andric   ///     True on success; false otherwise
1590b57cec5SDimitry Andric   bool RewriteObjCConstString(llvm::GlobalVariable *NSStr,
1600b57cec5SDimitry Andric                               llvm::GlobalVariable *CStr);
1610b57cec5SDimitry Andric 
1620b57cec5SDimitry Andric   /// The top-level pass implementation
1630b57cec5SDimitry Andric   ///
1640b57cec5SDimitry Andric   /// \return
1650b57cec5SDimitry Andric   ///     True on success; false otherwise
1660b57cec5SDimitry Andric   bool RewriteObjCConstStrings();
1670b57cec5SDimitry Andric 
1680b57cec5SDimitry Andric   /// A basic block-level pass to find all Objective-C method calls and
1690b57cec5SDimitry Andric   /// rewrite them to use sel_registerName instead of statically allocated
1700b57cec5SDimitry Andric   /// selectors.  The reason is that the selectors are created on the
1710b57cec5SDimitry Andric   /// assumption that the Objective-C runtime will scan the appropriate
1720b57cec5SDimitry Andric   /// section and prepare them.  This doesn't happen when code is copied into
1730b57cec5SDimitry Andric   /// the target, though, and there's no easy way to induce the runtime to
1740b57cec5SDimitry Andric   /// scan them.  So instead we get our selectors from sel_registerName.
1750b57cec5SDimitry Andric 
1760b57cec5SDimitry Andric   /// Replace a single selector reference
1770b57cec5SDimitry Andric   ///
1780b57cec5SDimitry Andric   /// \param[in] selector_load
1790b57cec5SDimitry Andric   ///     The load of the statically-allocated selector.
1800b57cec5SDimitry Andric   ///
1810b57cec5SDimitry Andric   /// \return
1820b57cec5SDimitry Andric   ///     True on success; false otherwise
1830b57cec5SDimitry Andric   bool RewriteObjCSelector(llvm::Instruction *selector_load);
1840b57cec5SDimitry Andric 
1850b57cec5SDimitry Andric   /// The top-level pass implementation
1860b57cec5SDimitry Andric   ///
1870b57cec5SDimitry Andric   /// \param[in] basic_block
1880b57cec5SDimitry Andric   ///     The basic block currently being processed.
1890b57cec5SDimitry Andric   ///
1900b57cec5SDimitry Andric   /// \return
1910b57cec5SDimitry Andric   ///     True on success; false otherwise
1920b57cec5SDimitry Andric   bool RewriteObjCSelectors(llvm::BasicBlock &basic_block);
1930b57cec5SDimitry Andric 
1940b57cec5SDimitry Andric   /// A basic block-level pass to find all newly-declared persistent
1950b57cec5SDimitry Andric   /// variables and register them with the ClangExprDeclMap.  This allows them
1960b57cec5SDimitry Andric   /// to be materialized and dematerialized like normal external variables.
1970b57cec5SDimitry Andric   /// Before transformation, these persistent variables look like normal
1980b57cec5SDimitry Andric   /// locals, so they have an allocation. This pass excises these allocations
1990b57cec5SDimitry Andric   /// and makes references look like external references where they will be
2000b57cec5SDimitry Andric   /// resolved -- like all other external references -- by ResolveExternals().
2010b57cec5SDimitry Andric 
2020b57cec5SDimitry Andric   /// Handle a single allocation of a persistent variable
2030b57cec5SDimitry Andric   ///
2040b57cec5SDimitry Andric   /// \param[in] persistent_alloc
2050b57cec5SDimitry Andric   ///     The allocation of the persistent variable.
2060b57cec5SDimitry Andric   ///
2070b57cec5SDimitry Andric   /// \return
2080b57cec5SDimitry Andric   ///     True on success; false otherwise
2090b57cec5SDimitry Andric   bool RewritePersistentAlloc(llvm::Instruction *persistent_alloc);
2100b57cec5SDimitry Andric 
2110b57cec5SDimitry Andric   /// The top-level pass implementation
2120b57cec5SDimitry Andric   ///
2130b57cec5SDimitry Andric   /// \param[in] basic_block
2140b57cec5SDimitry Andric   ///     The basic block currently being processed.
2150b57cec5SDimitry Andric   bool RewritePersistentAllocs(llvm::BasicBlock &basic_block);
2160b57cec5SDimitry Andric 
2170b57cec5SDimitry Andric   /// A function-level pass to find all external variables and functions
2180b57cec5SDimitry Andric   /// used in the IR.  Each found external variable is added to the struct,
2190b57cec5SDimitry Andric   /// and each external function is resolved in place, its call replaced with
2200b57cec5SDimitry Andric   /// a call to a function pointer whose value is the address of the function
2210b57cec5SDimitry Andric   /// in the target process.
2220b57cec5SDimitry Andric 
2230b57cec5SDimitry Andric   /// Handle a single externally-defined variable
2240b57cec5SDimitry Andric   ///
2250b57cec5SDimitry Andric   /// \param[in] value
2260b57cec5SDimitry Andric   ///     The variable.
2270b57cec5SDimitry Andric   ///
2280b57cec5SDimitry Andric   /// \return
2290b57cec5SDimitry Andric   ///     True on success; false otherwise
2300b57cec5SDimitry Andric   bool MaybeHandleVariable(llvm::Value *value);
2310b57cec5SDimitry Andric 
2320b57cec5SDimitry Andric   /// Handle a single externally-defined symbol
2330b57cec5SDimitry Andric   ///
2340b57cec5SDimitry Andric   /// \param[in] symbol
2350b57cec5SDimitry Andric   ///     The symbol.
2360b57cec5SDimitry Andric   ///
2370b57cec5SDimitry Andric   /// \return
2380b57cec5SDimitry Andric   ///     True on success; false otherwise
2390b57cec5SDimitry Andric   bool HandleSymbol(llvm::Value *symbol);
2400b57cec5SDimitry Andric 
2410b57cec5SDimitry Andric   /// Handle a single externally-defined Objective-C class
2420b57cec5SDimitry Andric   ///
2430b57cec5SDimitry Andric   /// \param[in] classlist_reference
2440b57cec5SDimitry Andric   ///     The reference, usually "01L_OBJC_CLASSLIST_REFERENCES_$_n"
2450b57cec5SDimitry Andric   ///     where n (if present) is an index.
2460b57cec5SDimitry Andric   ///
2470b57cec5SDimitry Andric   /// \return
2480b57cec5SDimitry Andric   ///     True on success; false otherwise
2490b57cec5SDimitry Andric   bool HandleObjCClass(llvm::Value *classlist_reference);
2500b57cec5SDimitry Andric 
2510b57cec5SDimitry Andric   /// Handle all the arguments to a function call
2520b57cec5SDimitry Andric   ///
253480093f4SDimitry Andric   /// \param[in] call_inst
2540b57cec5SDimitry Andric   ///     The call instruction.
2550b57cec5SDimitry Andric   ///
2560b57cec5SDimitry Andric   /// \return
2570b57cec5SDimitry Andric   ///     True on success; false otherwise
2580b57cec5SDimitry Andric   bool MaybeHandleCallArguments(llvm::CallInst *call_inst);
2590b57cec5SDimitry Andric 
2600b57cec5SDimitry Andric   /// Resolve variable references in calls to external functions
2610b57cec5SDimitry Andric   ///
2620b57cec5SDimitry Andric   /// \param[in] basic_block
2630b57cec5SDimitry Andric   ///     The basic block currently being processed.
2640b57cec5SDimitry Andric   ///
2650b57cec5SDimitry Andric   /// \return
2660b57cec5SDimitry Andric   ///     True on success; false otherwise
2670b57cec5SDimitry Andric   bool ResolveCalls(llvm::BasicBlock &basic_block);
2680b57cec5SDimitry Andric 
2690b57cec5SDimitry Andric   /// Remove calls to __cxa_atexit, which should never be generated by
2700b57cec5SDimitry Andric   /// expressions.
2710b57cec5SDimitry Andric   ///
272480093f4SDimitry Andric   /// \param[in] basic_block
273480093f4SDimitry Andric   ///     The basic block currently being processed.
2740b57cec5SDimitry Andric   ///
2750b57cec5SDimitry Andric   /// \return
2760b57cec5SDimitry Andric   ///     True if the scan was successful; false if some operation
2770b57cec5SDimitry Andric   ///     failed
2780b57cec5SDimitry Andric   bool RemoveCXAAtExit(llvm::BasicBlock &basic_block);
2790b57cec5SDimitry Andric 
2800b57cec5SDimitry Andric   /// The top-level pass implementation
2810b57cec5SDimitry Andric   ///
282480093f4SDimitry Andric   /// \param[in] llvm_function
2830b57cec5SDimitry Andric   ///     The function currently being processed.
2840b57cec5SDimitry Andric   ///
2850b57cec5SDimitry Andric   /// \return
2860b57cec5SDimitry Andric   ///     True on success; false otherwise
2870b57cec5SDimitry Andric   bool ResolveExternals(llvm::Function &llvm_function);
2880b57cec5SDimitry Andric 
2890b57cec5SDimitry Andric   /// A basic block-level pass to excise guard variables from the code.
2900b57cec5SDimitry Andric   /// The result for the function is passed through Clang as a static
2910b57cec5SDimitry Andric   /// variable.  Static variables normally have guard variables to ensure that
2920b57cec5SDimitry Andric   /// they are only initialized once.
2930b57cec5SDimitry Andric 
2940b57cec5SDimitry Andric   /// Rewrite a load to a guard variable to return constant 0.
2950b57cec5SDimitry Andric   ///
2960b57cec5SDimitry Andric   /// \param[in] guard_load
2970b57cec5SDimitry Andric   ///     The load instruction to zero out.
2980b57cec5SDimitry Andric   void TurnGuardLoadIntoZero(llvm::Instruction *guard_load);
2990b57cec5SDimitry Andric 
3000b57cec5SDimitry Andric   /// The top-level pass implementation
3010b57cec5SDimitry Andric   ///
3020b57cec5SDimitry Andric   /// \param[in] basic_block
3030b57cec5SDimitry Andric   ///     The basic block currently being processed.
3040b57cec5SDimitry Andric   ///
3050b57cec5SDimitry Andric   /// \return
3060b57cec5SDimitry Andric   ///     True on success; false otherwise
3070b57cec5SDimitry Andric   bool RemoveGuards(llvm::BasicBlock &basic_block);
3080b57cec5SDimitry Andric 
3090b57cec5SDimitry Andric   /// A function-level pass to make all external variable references
3100b57cec5SDimitry Andric   /// point at the correct offsets from the void* passed into the function.
3110b57cec5SDimitry Andric   /// ClangExpressionDeclMap::DoStructLayout() must be called beforehand, so
3120b57cec5SDimitry Andric   /// that the offsets are valid.
3130b57cec5SDimitry Andric 
3140b57cec5SDimitry Andric   /// The top-level pass implementation
3150b57cec5SDimitry Andric   ///
3160b57cec5SDimitry Andric   /// \param[in] llvm_function
3170b57cec5SDimitry Andric   ///     The function currently being processed.
3180b57cec5SDimitry Andric   ///
3190b57cec5SDimitry Andric   /// \return
3200b57cec5SDimitry Andric   ///     True on success; false otherwise
3210b57cec5SDimitry Andric   bool ReplaceVariables(llvm::Function &llvm_function);
3220b57cec5SDimitry Andric 
323*fe6060f1SDimitry Andric   /// True if external variable references and persistent variable references
324*fe6060f1SDimitry Andric   /// should be resolved
325*fe6060f1SDimitry Andric   bool m_resolve_vars;
326*fe6060f1SDimitry Andric   /// The name of the function to translate
327*fe6060f1SDimitry Andric   lldb_private::ConstString m_func_name;
328*fe6060f1SDimitry Andric   /// The name of the result variable ($0, $1, ...)
329*fe6060f1SDimitry Andric   lldb_private::ConstString m_result_name;
330*fe6060f1SDimitry Andric   /// The type of the result variable.
331*fe6060f1SDimitry Andric   lldb_private::TypeFromParser m_result_type;
332*fe6060f1SDimitry Andric   /// The module being processed, or NULL if that has not been determined yet.
333*fe6060f1SDimitry Andric   llvm::Module *m_module = nullptr;
334*fe6060f1SDimitry Andric   /// The target data for the module being processed, or NULL if there is no
3350b57cec5SDimitry Andric   /// module.
336*fe6060f1SDimitry Andric   std::unique_ptr<llvm::DataLayout> m_target_data;
337*fe6060f1SDimitry Andric   /// The DeclMap containing the Decls
338*fe6060f1SDimitry Andric   lldb_private::ClangExpressionDeclMap *m_decl_map;
339*fe6060f1SDimitry Andric   /// The address of the function CFStringCreateWithBytes, cast to the
3400b57cec5SDimitry Andric   /// appropriate function pointer type
341*fe6060f1SDimitry Andric   llvm::FunctionCallee m_CFStringCreateWithBytes;
342*fe6060f1SDimitry Andric   /// The address of the function sel_registerName, cast to the appropriate
343*fe6060f1SDimitry Andric   /// function pointer type.
344*fe6060f1SDimitry Andric   llvm::FunctionCallee m_sel_registerName;
345*fe6060f1SDimitry Andric   /// The type of an integer large enough to hold a pointer.
346*fe6060f1SDimitry Andric   llvm::IntegerType *m_intptr_ty = nullptr;
347*fe6060f1SDimitry Andric   /// The stream on which errors should be printed.
348*fe6060f1SDimitry Andric   lldb_private::Stream &m_error_stream;
349*fe6060f1SDimitry Andric   /// The execution unit containing the IR being created.
350*fe6060f1SDimitry Andric   lldb_private::IRExecutionUnit &m_execution_unit;
351*fe6060f1SDimitry Andric   /// True if the function's result in the AST is a pointer (see comments in
3520b57cec5SDimitry Andric   /// ASTResultSynthesizer::SynthesizeBodyResult)
353*fe6060f1SDimitry Andric   bool m_result_is_pointer = false;
3540b57cec5SDimitry Andric 
3550b57cec5SDimitry Andric   class FunctionValueCache {
3560b57cec5SDimitry Andric   public:
3570b57cec5SDimitry Andric     typedef std::function<llvm::Value *(llvm::Function *)> Maker;
3580b57cec5SDimitry Andric 
3590b57cec5SDimitry Andric     FunctionValueCache(Maker const &maker);
3600b57cec5SDimitry Andric     ~FunctionValueCache();
3610b57cec5SDimitry Andric     llvm::Value *GetValue(llvm::Function *function);
3620b57cec5SDimitry Andric 
3630b57cec5SDimitry Andric   private:
3640b57cec5SDimitry Andric     Maker const m_maker;
3650b57cec5SDimitry Andric     typedef std::map<llvm::Function *, llvm::Value *> FunctionValueMap;
3660b57cec5SDimitry Andric     FunctionValueMap m_values;
3670b57cec5SDimitry Andric   };
3680b57cec5SDimitry Andric 
3690b57cec5SDimitry Andric   FunctionValueCache m_entry_instruction_finder;
3700b57cec5SDimitry Andric 
371480093f4SDimitry Andric   /// UnfoldConstant operates on a constant [Old] which has just been replaced
372480093f4SDimitry Andric   /// with a value [New].  We assume that new_value has been properly placed
373480093f4SDimitry Andric   /// early in the function, in front of the first instruction in the entry
374480093f4SDimitry Andric   /// basic block [FirstEntryInstruction].
375480093f4SDimitry Andric   ///
376480093f4SDimitry Andric   /// UnfoldConstant reads through the uses of Old and replaces Old in those
377480093f4SDimitry Andric   /// uses with New.  Where those uses are constants, the function generates
378480093f4SDimitry Andric   /// new instructions to compute the result of the new, non-constant
379480093f4SDimitry Andric   /// expression and places them before FirstEntryInstruction.  These
380480093f4SDimitry Andric   /// instructions replace the constant uses, so UnfoldConstant calls itself
381480093f4SDimitry Andric   /// recursively for those.
382480093f4SDimitry Andric   ///
383480093f4SDimitry Andric   /// \return
384480093f4SDimitry Andric   ///     True on success; false otherwise
3850b57cec5SDimitry Andric   static bool UnfoldConstant(llvm::Constant *old_constant,
3860b57cec5SDimitry Andric                              llvm::Function *llvm_function,
3870b57cec5SDimitry Andric                              FunctionValueCache &value_maker,
3880b57cec5SDimitry Andric                              FunctionValueCache &entry_instruction_finder,
3890b57cec5SDimitry Andric                              lldb_private::Stream &error_stream);
3900b57cec5SDimitry Andric };
3910b57cec5SDimitry Andric 
3925ffd83dbSDimitry Andric #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_IRFORTARGET_H
393