4 #ifndef ILANG_MCM_MEMORY_MODEL_H__
5 #define ILANG_MCM_MEMORY_MODEL_H__
14 #define FINAL_STEP_SUFFIX "final"
50 typedef std::unordered_map<std::string, AddrDataVec>
MRFVal;
59 static unsigned trace_step_seq_no;
63 void InitReadSetForProperty(
const ExprPtr& e);
71 mutable bool already_searched_for_memreadpair_;
74 FindAddrDataPairVecInExpr(
const ExprPtr& node,
78 void VisitNodeForMemoryRead(
const ExprPtr& node,
84 FindAddrDataPairVecInInst(
const std::string& sname,
165 ZExpr _ts_overwrite,
size_t pos);
168 const std::string& fevt_name,
size_t pos);
191 std::string
Print(z3::model& m)
const;
281 void virtual SetLocalState(
const std::vector<bool>& ordered);
290 std::function<
void(
const z3::expr&)> collector);
329 enum StaticResult { STATIC_TRUE = 1, STATIC_FALSE, STATIC_UNKNOWN };
339 z3::expr HB(
const TraceStep& l,
const TraceStep& r)
const;
341 z3::expr Sync(
const TraceStep& l,
const TraceStep& r)
const;
343 z3::expr PO(
const TraceStep& l,
const TraceStep& r)
const;
345 z3::expr SameAddress(
const TraceStep& l,
const TraceStep& r,
346 const std::string& sname,
347 AxiomFuncHint lhint = HINT_NONE,
348 AxiomFuncHint rhint = HINT_NONE)
const;
350 z3::expr Decode(
const TraceStep& l)
const;
352 z3::expr SameData(
const TraceStep& l,
const TraceStep& r,
353 const std::string& sname, AxiomFuncHint lhint = HINT_NONE,
354 AxiomFuncHint rhint = HINT_NONE)
const;
356 bool SameCore(
const TraceStep& l,
const TraceStep& r)
const;
358 StaticResult SameAddressStatic(
const TraceStep& l,
const TraceStep& r)
const;
360 StaticResult DecodeStatic(
const TraceStep& l)
const;
362 StaticResult SameCoreStatic(
const TraceStep& l,
const TraceStep& r)
const;
371 z3::expr MemVarSameAddress(
const ExprPtr& leftWAddr,
375 const TraceStep& traceL,
376 const TraceStep& traceR)
const;
378 z3::expr MemVarSameData(
const std::pair<ExprPtr, ExprPtr>& leftAddrDataPair,
380 const std::pair<ExprPtr, ExprPtr>& rightAddrDataPair,
382 const TraceStep& traceL,
const TraceStep& traceR,
388 z3::expr NonMemVarSameData(
const TraceStep& l,
const TraceStep& r,
389 const std::string& sname, AxiomFuncHint lhint,
390 AxiomFuncHint rhint)
const;
394 void SameAddrDataSanityCheck(
const TraceStep& l,
const TraceStep& r,
395 const std::string& sname)
const;
401 #endif // ILANG_MCM_MEMORY_MODEL_H__
std::vector< InstrVec > ProgramTemplate
Definition: memory_model.h:217
ZExprVec & _constr
A reference to the constraint list.
Definition: memory_model.h:253
std::string name() const
Return the name.
Definition: memory_model.h:132
ZExprVec & _cstr
Definition: memory_model.h:111
z3::context & _ctx_
Definition: memory_model.h:251
Z3ExprAdapter _expr2z3_
Definition: memory_model.h:256
std::vector< std::vector< TraceStepPtr > > PerILATraceStepPtrSet
Definition: memory_model.h:220
NestedMemAddrDataAvoider nested_finder_
An AST traversor, make sure there are no nested asts.
Definition: memory_model.h:319
void AddStateAccess(const std::string &name, AccessType acc_type)
To update the set for FACET_EVT.
std::string Print(z3::model &m) const
Print out a trace step for debug purpose.
TraceStep::TraceStepPtrSet TraceStepPtrSet
Type of trace steps, we need to collect the set of trace steps (WRITE)
Definition: memory_model.h:206
TraceStep(const InstrPtr &inst, ZExprVec &cstr, z3::context &ctx, size_t pos)
TraceStepPtrSet _all_inst_trace_steps
The set of all instruction trace steps.
Definition: memory_model.h:236
PerILATraceStepPtrSet _ila_trace_steps
Definition: memory_model.h:239
Expr::ExprPtr ExprPtr
Pointer type for normal use of Expr.
Definition: expr.h:138
std::vector< InstrPtr > InstrVec
Type for storing a set of Instr.
Definition: instr.h:136
InstrLvlAbsPtr _host_final_
Host for Final Event.
Definition: memory_model.h:123
size_t pos_suffix() const
std::map< std::string, StateNameSet > ILANameStateNameSetMap
Type of map ila-name to state-set.
Definition: memory_model.h:222
ZExpr ConvertZ3OnThisStep(const ExprPtr &ast) const
const ILANameStateNameSetMap & m_ila_private_state_names
The internal storage of all private states of all ilas.
Definition: memory_model.h:245
Z3ExprAdapter _expr2z3_
Keep an adapter that trace steps (won't shared w. others)
Definition: memory_model.h:119
z3::expr timestamp
The time stamp.
Definition: memory_model.h:115
The class for trace step (an instance of instruction) As in the unrolling, there may be multiple inst...
Definition: memory_model.h:28
InstrLvlAbsPtr host() const
Return the host ILA.
std::unordered_map< std::string, AddrDataVec > MRFVal
Map from state name to memory read pair.
Definition: memory_model.h:50
virtual void SetFinalProperty(const ExprPtr &property)=0
Set the assertion on the final state.
InstrPtr _inst
The pointer to the instruction executed in this step.
Definition: memory_model.h:93
TraceStepType _type
the type of this trace step (event)
Definition: memory_model.h:90
z3::expr Z3ForallList(const ZExprVec &l) const
This is to deal with forall (if does not exist, it should be true also)
StateNameSet _write_state_set
Definition: memory_model.h:102
TraceStepPtr _final_trace_step
The pointer to the final trace step.
Definition: memory_model.h:231
z3::context & ctx() const
Return the context (for variable creation)
Definition: memory_model.h:260
bool is_init_tracestep() const
Decide if the trace step is the initial trace step (a short-cut)
Definition: memory_model.h:140
TraceStep::ZExprVec ZExprVec
Type for containing a vector of z3::expr.
Definition: memory_model.h:202
const StateNameSet & get_inst_write_set() const
Return the set of states written by inst/parent-inst.
Definition: memory_model.h:136
Instr::InstrPtr InstrPtr
Pointer type for normal use of Instr.
Definition: instr.h:132
ExprPtr final_property()
Return final property.
Definition: memory_model.h:156
StateNameSet _read_state_set
Definition: memory_model.h:99
ExprPtr _final_property
The cache for the property to witness on the final step.
Definition: memory_model.h:125
InstrPtr inst() const
Return the associated instruction for facet / instruction event.
StateNameSet _inst_write_set
Set of states (that are written by inst or parent-inst)
Definition: memory_model.h:107
InstrPtr _parent_inst
The pointer to the referred instruction.
Definition: memory_model.h:96
std::string _name
The name of trace step.
Definition: memory_model.h:113
TraceStepPtrSet _all_trace_steps
The set of all trace steps.
Definition: memory_model.h:233
size_t _pos_suffix
The relative position.
Definition: memory_model.h:117
TraceStep::TraceStepPtr TraceStepPtr
Type of trace step shared pointers.
Definition: memory_model.h:204
std::vector< InstrPtr > InstrVec
Type of an instruction vector to represent a sequence.
Definition: memory_model.h:214
z3::expr GetExpr(const ExprPtr &expr, const std::string &suffix="")
Get the z3 expression of the AST node.
const StateNameSet & m_shared_state_names
The set of names of shared states.
Definition: memory_model.h:242
virtual void RegisterSteps(size_t regIdx, const InstrVec &_inst_seq)=0
virtual void GetSingleTraceStepProperty(const ExprPtr &property, std::function< bool(const TraceStep &)> filter, std::function< void(const z3::expr &)> collector)
Get the z3 expression of a property on a trace step.
InstrLvlAbs::InstrLvlAbsPtr InstrLvlAbsPtr
Pointer type for normal use of InstrLvlAbs.
Definition: instr_lvl_abs.h:326
std::set< std::string > StateNameSet
Type of state name set.
Definition: memory_model.h:42
Class of traversing to avoid nested memory access in address.
Definition: ast_helper.h:57
TraceStep::StateNameSet StateNameSet
Type of set of state names.
Definition: memory_model.h:210
virtual void AddSingleTraceStepProperty(const ExprPtr &property, std::function< bool(const TraceStep &)> filter)
Assert a property that some trace step (decided by filter) should follow.
Z3ExprAdapter & z3adapter() const
Return the adapter.
Definition: memory_model.h:152
bool is_final_tracestep() const
Decide if the trace step is the facet trace step (a short-cut)
Definition: memory_model.h:144
virtual void ApplyAxioms()=0
To apply the axioms, the complete program should be given.
TraceStepType
The type of trace step type.
Definition: memory_model.h:44
TraceStep::AddrDataVec AddrDataVec
Type of vector of (addr,data) pair.
Definition: memory_model.h:212
z3::context & ctx()
Return the context (for variable creation)
Definition: memory_model.h:154
virtual void InitSize(const ProgramTemplate &_tmpl)
To initialize the inner storage space.
z3::expr Z3ExistsList(const ZExprVec &l) const
This is to apply to exists, (if does not exist, it should be false)
bool is_facet_tracestep() const
Decide if the trace step is the facet trace step (a short-cut)
Definition: memory_model.h:142
virtual ~TraceStep()
Destructor, make it virtual.
Definition: memory_model.h:173
TraceStepPtr CreateGlobalInitStep()
A function for dervied classes to create init trace step.
const TraceStepPtrSet & GetAllTraceSteps() const
Determine if an instruction access a shared state.
Definition: memory_model.h:313
virtual void SetLocalState(const std::vector< bool > &ordered)
TraceStepPtr _init_trace_step
The pointer to the initial trace step.
Definition: memory_model.h:228
The class for generating z3 expression from an ILA.
Definition: z3_expr_adapter.h:20
AccessType
Type of state read or write.
Definition: memory_model.h:17
std::vector< std::pair< ExprPtr, ExprPtr > > AddrDataVec
Type of (addr,data) pair vector.
Definition: memory_model.h:48
InstrLvlAbsPtr m_p_global_ila
The pointer to the (dummy) global ILA.
Definition: memory_model.h:247
bool Access(AccessType acc_type, const std::string &name) const
To determine if the instruction READ/WRITE a certain state.
z3::expr ZExpr
Type alias for z3::expr.
Definition: memory_model.h:34
ZExpr ConvertZ3(const ExprPtr &ast, const std::string &suffix) const
Return the z3 converter used by this memory model.
Definition: memory_model.h:264
The base class for memory models.
Definition: memory_model.h:196
const TraceStepType & type() const
Return the type of the trace step.
Definition: memory_model.h:138
z3::context & _ctx_
Keep a context to allocate z3 vars.
Definition: memory_model.h:121
const StateNameSet & get_inst_read_set() const
Return the set of states read by inst/parent-inst.
Definition: memory_model.h:134
StateNameSet _inst_read_set
Set of states (that are read by inst or parent-inst)
Definition: memory_model.h:105
TraceStepPtr CreateGlobalFinalStep(const ExprPtr &property)
A function for dervied classes to create final trace step.
virtual void FinishRegisterSteps()=0
TraceStep::ZExpr ZExpr
Type alias for z3::expr.
Definition: memory_model.h:200
std::shared_ptr< TraceStep > TraceStepPtr
Type of trace step pointer.
Definition: memory_model.h:38
std::vector< ZExpr > ZExprVec
Type for containing a set of z3::expr.
Definition: memory_model.h:36
std::set< TraceStepPtr > TraceStepPtrSet
Type of set of trace steps.
Definition: memory_model.h:40
virtual void AddDoubleTraceStepProperty(std::function< z3::expr(const TraceStep &, const TraceStep &)>, std::function< bool(const TraceStep &, const TraceStep &)>)