ROSE  0.11.145.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
Rose::BinaryAnalysis::SmtSolver::Memoizer Class Reference

Description

Memoizes calls to an SMT solver.

This class memoizes calls to the check function for a particular SMT solver, or across some collection of solvers. For every non-trivial call to check, the memoizer caches the input set of assertions and the output satisfiability and, if satisfiable, the output evidence of satisfiability. Moreover, it does this in such a way that assertions that only vary in their variable names can be matched to previously cached calls.

In order to use memoization, a non-null memoizer should be passed to the SmtSolver::instance factory, or a non-null memoizer pointer should be assigned to the memoizer property of the SmtSolver. To disable memoization, assign a null pointer to the memoizer property. Multiple SmtSolver objects can share the same memoizer, but this should generally only be done when all such solvers are guaranteed to return the same values for any given inputs, which is not always the case due to differences in implementation.

In order to match calls whose inputs vary only in order of assertions and/or variable names, the assertions are sorted and normalized before being stored in the cache. First, to sort the assertions each assertion is independently normalized by renaming its variables starting at "v0" in the order they're encountered in a depth-first-search traversal. Then the input assertions are sorted according to the hashes of their corresponding normalized versions. Finally, the variables in the sorted assertions are collectively renamed, producing a sorted-normalized set of assertions and a renaming map. When a new result is added to the cache, the variables in the evidence of satisfiability are renamed according to renaming map. The original assertions, original evidence of satisfiability, and renaming map are discarded. When a cache hit occurs and the evidence needs to be returned, the cached evidence is de-normalized using the inverse of the temporary renaming map for the current input assertions.

Thread safety: All member functions are thread safe unless otherwise noted.

Definition at line 228 of file SmtSolver.h.

#include <Rose/BinaryAnalysis/SmtSolver.h>

Inheritance diagram for Rose::BinaryAnalysis::SmtSolver::Memoizer:
Inheritance graph
[legend]
Collaboration diagram for Rose::BinaryAnalysis::SmtSolver::Memoizer:
Collaboration graph
[legend]

Classes

struct  Found
 

Public Types

using Ptr = Sawyer::SharedPointer< Memoizer >
 Reference counting pointer. More...
 

Public Member Functions

void clear ()
 Clear the entire cache as if it was just constructed. More...
 
Found find (const ExprList &assertions)
 Search for the specified assertions in the cache. More...
 
ExprExprMap evidence (const Found &) const
 Returns evidence of satisfiability. More...
 
void insert (const Found &, Satisfiable, const ExprExprMap &evidence)
 Insert a call record into the cache. More...
 
size_t size () const
 Number of call records cached. More...
 
Map::iterator searchNS (SymbolicExpression::Hash, const ExprList &sortedNormalized)
 
- Public Member Functions inherited from Sawyer::SharedObject
 SharedObject ()
 Default constructor. More...
 
 SharedObject (const SharedObject &)
 Copy constructor. More...
 
virtual ~SharedObject ()
 Virtual destructor. More...
 
SharedObjectoperator= (const SharedObject &)
 Assignment. More...
 

Static Public Member Functions

static Ptr instance ()
 Allocating constructor. More...
 

Member Typedef Documentation

Reference counting pointer.

Definition at line 231 of file SmtSolver.h.

Member Function Documentation

static Ptr Rose::BinaryAnalysis::SmtSolver::Memoizer::instance ( )
static

Allocating constructor.

void Rose::BinaryAnalysis::SmtSolver::Memoizer::clear ( )

Clear the entire cache as if it was just constructed.

Found Rose::BinaryAnalysis::SmtSolver::Memoizer::find ( const ExprList assertions)

Search for the specified assertions in the cache.

If this is a cache hit, then the return value evaluates to true in Boolean context and contains the satisfiability and normalized evidence. The evidence needs to be de-normalized by the evidence function before it can be used. If this is a cache miss, then the return value evaluates to false in Boolean context, but it contains enough information for the SMT solver results to be inserted into the cache later by the insert function.

The documentation for this class describes how the search works by sorting and normalizing the input assertions.

ExprExprMap Rose::BinaryAnalysis::SmtSolver::Memoizer::evidence ( const Found ) const

Returns evidence of satisfiability.

The argument is the result from find. If the argument evaluates to true in Boolean context (i.e., the find was a cache hit) then this function will de-normalize the cached evidence of satisfiability and return it. This function should not be called if the argument evaluates to false in a Boolean context (i.e., the find was a cache miss).

void Rose::BinaryAnalysis::SmtSolver::Memoizer::insert ( const Found ,
Satisfiable  ,
const ExprExprMap evidence 
)

Insert a call record into the cache.

The first argument is the return value from find which must have been a cache miss. The remaining arguments are the results from the SMT solver for the same assertions that were used in the find call. The evidence is normalized using the same variable mapping as was used for the input assertions during the find call, and then stored in the cache in normalized form.

size_t Rose::BinaryAnalysis::SmtSolver::Memoizer::size ( ) const

Number of call records cached.


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