ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
v_eq_check_refinement.h
Go to the documentation of this file.
1 
5 #ifndef ILANG_ILA_MNGR_V_EQ_CHECK_REFINEMENT_H__
6 #define ILANG_ILA_MNGR_V_EQ_CHECK_REFINEMENT_H__
7 
8 #include <z3++.h>
9 
12 
14 namespace ilang {
15 
22 public:
24  typedef std::shared_ptr<RefinementMap> RefPtr;
25 
26  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
28  RefinementMap();
31 
32  // ------------------------- ACCESSORS/MUTATORS --------------------------- //
34  inline InstrLvlAbsPtr coi() const { return coi_; }
36  inline InstrLvlAbsPtr ila() const { return coi_; }
38  inline ExprPtr appl() const { return appl_; }
40  inline ExprPtr flush() const { return flush_; }
42  inline ExprPtr cmpl() const { return cmpl_; }
44  inline const int& step_appl() const { return step_appl_; }
46  inline const int& step_orig() const { return step_orig_; }
48  inline const int& step() const { return step_orig(); }
50  inline size_t inv_num() const { return invs_.size(); }
52  inline ExprPtr inv(const size_t& i) const { return invs_.at(i); }
53 
55  void set_tgt(const InstrLvlAbsPtr& tgt);
57  void set_tgt(const InstrPtr& tgt);
59  void set_appl(const ExprPtr& appl);
61  void set_flush(const ExprPtr& flush);
63  void set_cmpl(const ExprPtr& cmpl);
65  inline void set_step(const int& step) { set_step_orig(step); }
67  void set_step_appl(const int& step);
69  void set_step_orig(const int& step);
71  void add_inv(const ExprPtr& inv);
72 
73  // ------------------------- HELPERS -------------------------------------- //
76  static RefPtr New();
77 
78 private:
79  // ------------------------- MEMBERS -------------------------------------- //
81  InstrLvlAbsPtr coi_ = nullptr;
83  ExprPtr appl_ = nullptr;
85  ExprPtr flush_ = nullptr;
87  ExprPtr cmpl_ = asthub::BoolConst(true);
89  int step_appl_ = -1;
91  int step_orig_ = -1;
93  std::vector<ExprPtr> invs_;
94 
95 }; // RefinementMap
96 
99 
102 class RelationMap {
103 public:
105  typedef std::shared_ptr<RelationMap> RelPtr;
106 
107  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
109  RelationMap();
111  ~RelationMap();
112 
113  // ------------------------- ACCESSORS/MUTATORS --------------------------- //
115  void add(const ExprPtr& rel);
117  inline ExprPtr get() const { return acc_; }
118 
119  // ------------------------- HELPERS -------------------------------------- //
122  static RelPtr New();
123 
124 private:
125  // ------------------------- MEMBERS -------------------------------------- //
127  ExprPtr acc_ = asthub::BoolConst(true);
128 
129 }; // RelationMap
130 
133 
139 class CompRefRel {
140 public:
141  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
143  typedef std::shared_ptr<CompRefRel> CrrPtr;
144 
146  CompRefRel(const RefPtr ref_a, const RefPtr ref_b, const RelPtr rel);
148  ~CompRefRel();
149 
150  // ------------------------- ACCESSORS/MUTATORS --------------------------- //
152  inline RefPtr refine_a() const { return ref_a_; }
154  inline RefPtr refine_b() const { return ref_b_; }
156  inline RelPtr relation() const { return rel_; }
157 
158  // ------------------------- HELPERS -------------------------------------- //
161  static CrrPtr New(const RefPtr ref_a = RefinementMap::New(),
162  const RefPtr ref_b = RefinementMap::New(),
163  const RelPtr rel = RelationMap::New());
164 
165 private:
166  // ------------------------- MEMBERS -------------------------------------- //
168  RefPtr ref_a_;
170  RefPtr ref_b_;
172  RelPtr rel_;
173 
174 }; // CompRefRel
175 
178 
180 class CommDiag {
181 public:
182  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
184  CommDiag(z3::context& ctx, const CrrPtr crr);
186  ~CommDiag();
187 
188  // ------------------------- METHODS -------------------------------------- //
192  bool EqCheck(const int& max = 10);
193 
198  bool IncEqCheck(const int& min = 0, const int& max = 10, const int& step = 1);
199 
200  bool IncCheck(const int& min = 0, const int& max = 10, const int& step = 1);
201 
202  typedef MonoUnroll Unroll;
203 
204 private:
205  // ------------------------- MEMBERS -------------------------------------- //
207  z3::context& ctx_;
209  CrrPtr crr_;
210 
211  // ------------------------- IncCheck ------------------------------------- //
212 
213  void Init();
214 
215  enum UID { A_OLD, A_NEW, B_OLD, B_NEW };
216 
217  struct UnrlUnit {
218  int lo = 0;
219  int hi = 0;
220  } uu_a_old_, uu_a_new_, uu_b_old_, uu_b_new_;
221 
222  Unroll unrl_a_old_ = Unroll(ctx_, k_suff_old_);
223  Unroll unrl_a_new_ = Unroll(ctx_, k_suff_new_);
224  Unroll unrl_b_old_ = Unroll(ctx_, k_suff_old_);
225  Unroll unrl_b_new_ = Unroll(ctx_, k_suff_new_);
226 
227  ExprSet stts_a_;
228  ExprSet stts_b_;
229 
230  Unroll& GetUnrl(const UID& uid);
231  Unroll& GetUnrlOld();
232  Unroll& GetUnrlNew();
233  Unroll& GetUnrlApl();
234 
235  RefPtr GetRefine(const UID& uid);
236  UnrlUnit& GetUnrlUnit(const UID& uid);
237  const ExprSet& GetStts(const UID& uid);
238 
239  z3::expr GetZ3IncFlsh(const UID& uid);
240  z3::expr GetZ3IncCmpl(const UID& uid);
241 
242  // ------------------------- IncEqCheck ----------------------------------- //
243  static const std::string k_suff_old_;
244  static const std::string k_suff_new_;
245  static const std::string k_suff_apl_;
246  MonoUnroll unrl_old_ = MonoUnroll(ctx_, k_suff_old_);
247  MonoUnroll unrl_new_ = MonoUnroll(ctx_, k_suff_new_);
248  MonoUnroll unrl_apl_ = MonoUnroll(ctx_, k_suff_apl_);
249 
250  z3::expr GetZ3ApplInstr(const ExprSet& stts, const RefPtr ref);
251  z3::expr GetZ3Assm();
252  z3::expr GetZ3Prop();
253  z3::expr GetZ3Cmpl(const ExprPtr& cmpl, MonoUnroll& un, const int& begin,
254  const int& end) const;
255  z3::expr GetZ3IncUnrl(MonoUnroll& un, const RefPtr ref, const int& begin,
256  const int& length, const ExprSet& stts) const;
257  bool CheckCmpl(z3::solver& s, z3::expr& cmpl_expr) const;
258 
259  // ------------------------- MonoCheck ------------------------------------ //
260  static const std::string k_suff_orig_;
261  static const std::string k_suff_appl_;
262  MonoUnroll unroll_appl_ = MonoUnroll(ctx_, k_suff_appl_);
263  MonoUnroll unroll_orig_ = MonoUnroll(ctx_, k_suff_orig_);
264 
265  bool SanityCheck();
266  bool SanityCheckRefinement(const RefPtr ref);
267  bool SanityCheckRelation(const RelPtr rel, const InstrLvlAbsPtr& ma,
268  const InstrLvlAbsPtr& mb) const;
269 
270  int DetStepOrig(const RefPtr ref, const int& max);
271  int DetStepAppl(const RefPtr ref, const int& max);
272  bool CheckStepOrig(const RefPtr ref, const int& k);
273  bool CheckStepAppl(const RefPtr ref, const int& k);
274 
275  z3::expr GenInit(const RefPtr ref);
276  z3::expr GenTranRel(const RefPtr ref, const int& k_orig, const int& k_appl);
277  z3::expr GenAssm();
278  z3::expr GenProp();
279 
280  z3::expr AtLeastOnce(MonoUnroll& unroller, const ExprPtr& cmpl,
281  const int& start, const int& end) const;
282  z3::expr AtMostOnce(MonoUnroll& unroller, const ExprPtr& cmpl,
283  const int& start, const int& end) const;
284  z3::expr UnrollFlush(MonoUnroll& unroller, const RefPtr ref, const int& base,
285  const int& length, const int& start);
286 
287 }; // class CommDiag
288 
289 } // namespace ilang
290 
291 #endif // ILANG_ILA_MNGR_V_EQ_CHECK_REFINEMENT_H__
~CommDiag()
Default destructor.
bool IncEqCheck(const int &min=0, const int &max=10, const int &step=1)
Incrementally checking equivalence between two models based on the refinement relation up to the give...
void set_step_orig(const int &step)
Specify the number of steps required for flushing original path.
std::shared_ptr< CompRefRel > CrrPtr
Pointer type for passing around the compositional relation mapping.
Definition: v_eq_check_refinement.h:143
ExprPtr flush() const
Return the constraint for flushing (stall).
Definition: v_eq_check_refinement.h:40
static RelPtr New()
Create a new relation mapping. Used for hiding implementation specific type details.
size_t inv_num() const
Return the number of invariant.
Definition: v_eq_check_refinement.h:50
Expr::ExprPtr ExprPtr
Pointer type for normal use of Expr.
Definition: expr.h:138
CompRefRel(const RefPtr ref_a, const RefPtr ref_b, const RelPtr rel)
Default constructor.
RelPtr relation() const
Return the relation (state mapping) between model A and B.
Definition: v_eq_check_refinement.h:156
RelationMap()
Default constructor.
~CompRefRel()
Default destructor.
Application class for unrolling the ILA as a monolithic transition system.
Definition: u_unroller.h:232
ExprPtr cmpl() const
Return the constraint for completion indicator.
Definition: v_eq_check_refinement.h:42
CompRefRel::CrrPtr CrrPtr
Pointer type for passing around the compositional relation mapping.
Definition: v_eq_check_refinement.h:177
RefinementMap()
Default constructor.
std::unordered_set< ExprPtr, ExprHash > ExprSet
Type for storing a set of Expr.
Definition: expr.h:153
void set_tgt(const InstrLvlAbsPtr &tgt)
Define the target ILA (source for coi).
bool EqCheck(const int &max=10)
Check equivalence between two models based on the refinement relation up to the given unrolling bound...
RefinementMap::RefPtr RefPtr
Pointer type for passing around the refinement mapping.
Definition: v_eq_check_refinement.h:98
Relation mapping defines how arch states of two models are mapped, i.e., state mapping.
Definition: v_eq_check_refinement.h:102
Instr::InstrPtr InstrPtr
Pointer type for normal use of Instr.
Definition: instr.h:132
ExprPtr inv(const size_t &i) const
Access the i-th invariant.
Definition: v_eq_check_refinement.h:52
static RefPtr New()
Create a new refinement mapping. Used for hiding implementation specific type details.
Refinement mapping defines how to map micro-architectural states to architectural states for comparis...
Definition: v_eq_check_refinement.h:21
const int & step() const
Return the number of steps required for flushing. XXX.
Definition: v_eq_check_refinement.h:48
~RefinementMap()
Default destructor.
InstrLvlAbsPtr ila() const
Return the target (top-ILA).
Definition: v_eq_check_refinement.h:36
InstrLvlAbsPtr coi() const
Return the target (top-ILA containing the COI).
Definition: v_eq_check_refinement.h:34
InstrLvlAbs::InstrLvlAbsPtr InstrLvlAbsPtr
Pointer type for normal use of InstrLvlAbs.
Definition: instr_lvl_abs.h:326
void add_inv(const ExprPtr &inv)
Add an invariant.
const int & step_appl() const
Return the number of steps required for flushing apply path.
Definition: v_eq_check_refinement.h:44
RefPtr refine_b() const
Return the refinement for model B.
Definition: v_eq_check_refinement.h:154
void add(const ExprPtr &rel)
Add one relation.
~RelationMap()
Default destructor.
Compositional refinement relation defines a unit (element for the composition) of refinement relation...
Definition: v_eq_check_refinement.h:139
void set_step_appl(const int &step)
Specify the number of steps required for flushing apply path.
const int & step_orig() const
Return the number of steps required for flushing original path.
Definition: v_eq_check_refinement.h:46
std::shared_ptr< RelationMap > RelPtr
Pointer type for passing around the relation mapping.
Definition: v_eq_check_refinement.h:105
ExprPtr appl() const
Return the apply function.
Definition: v_eq_check_refinement.h:38
static CrrPtr New(const RefPtr ref_a=RefinementMap::New(), const RefPtr ref_b=RefinementMap::New(), const RelPtr rel=RelationMap::New())
Create a new CRR object. Used for hiding implementation specific type details.
RelationMap::RelPtr RelPtr
Pointer type for passing around the relation mapping.
Definition: v_eq_check_refinement.h:132
Generator for commutating diagram-based equivalence checking.
Definition: v_eq_check_refinement.h:180
RefPtr refine_a() const
Return the refinement for model A.
Definition: v_eq_check_refinement.h:152
void set_flush(const ExprPtr &flush)
Define the flushing function.
std::shared_ptr< RefinementMap > RefPtr
Pointer type for passing around the refinement mapping.
Definition: v_eq_check_refinement.h:24
void set_cmpl(const ExprPtr &cmpl)
Define the completion scenario (e.g. dummy end).
CommDiag(z3::context &ctx, const CrrPtr crr)
Default constructor.
void set_appl(const ExprPtr &appl)
Define the apply function.
void set_step(const int &step)
Specify the number of steps required for flushing. XXX.
Definition: v_eq_check_refinement.h:65