Able to evaluate predicate expression against a 'context' and generate concrete predi...
[c11tester.git] / predicate.h
index bab7a7eee54363c01802bdf44616f0e814bb892e..6c83683dddfdfeff4a3fe502625b77a13695a04e 100644 (file)
+#ifndef __PREDICTAE_H__
+#define __PREDICATE_H__
+
 #include "funcinst.h"
+#include "hashset.h"
+
+unsigned int pred_expr_hash (struct pred_expr *);
+bool pred_expr_equal(struct pred_expr *, struct pred_expr *);
+typedef HashSet<struct pred_expr *, uintptr_t, 0, model_malloc, model_calloc, model_free, pred_expr_hash, pred_expr_equal> PredExprSet;
+typedef HSIterator<struct pred_expr *, uintptr_t, 0, model_malloc, model_calloc, model_free, pred_expr_hash, pred_expr_equal> PredExprSetIter;
 
 typedef enum predicate_token {
-       EQUALITY, NULLITY
+       NOPREDICATE, EQUALITY, NULLITY
 } token_t;
 
 /* If token is EQUALITY, then the predicate asserts whether
  * this load should read the same value as the last value
  * read at memory location specified in predicate_expr.
  */
-struct predicate_expr {
+struct pred_expr {
+       pred_expr(token_t token, FuncInst * inst, bool value) :
+               token(token),
+               func_inst(inst),
+               value(value)
+       {}
+
        token_t token;
-       void * location;
+       FuncInst * func_inst;
        bool value;
+
+       MEMALLOC
+};
+
+/* Used by predicate generator */
+struct half_pred_expr {
+       half_pred_expr(token_t token, FuncInst * inst) :
+               token(token),
+               func_inst(inst)
+       {}
+
+       token_t token;
+       FuncInst * func_inst;
+
+       SNAPSHOTALLOC
+};
+
+struct concrete_pred_expr {
+       concrete_pred_expr(token_t token, uint64_t value, bool equality) :
+               token(token),
+               value(value),
+               equality(equality)
+       {}
+
+       token_t token;
+       uint64_t value;
+       bool equality;
+
+       SNAPSHOTALLOC
 };
 
 class Predicate {
 public:
-       Predicate();
+       Predicate(FuncInst * func_inst, bool is_entry = false);
        ~Predicate();
 
        FuncInst * get_func_inst() { return func_inst; }
-       ModelList<predicate_expr> * get_predicates() { return &predicates; }
-       void add_predicate(predicate_expr predicate);
+       PredExprSet * get_pred_expressions() { return &pred_expressions; }
+
+       void add_predicate_expr(token_t token, FuncInst * func_inst, bool value);
+       void add_child(Predicate * child);
+       void set_parent(Predicate * parent_pred) { parent = parent_pred; }
+       void add_backedge(Predicate * back_pred) { backedges.add(back_pred); }
+       void copy_predicate_expr(Predicate * other);
+
+       ModelVector<Predicate *> * get_children() { return &children; }
+       Predicate * get_parent() { return parent; }
+       PredSet * get_backedges() { return &backedges; }
+
+       bool is_entry_predicate() { return entry_predicate; }
+       void set_entry_predicate() { entry_predicate = true; }
+
+       /* Whether func_inst does write or not */
+       bool is_write() { return does_write; }
+       void set_write(bool is_write) { does_write = is_write; }
+
+       SnapVector<struct concrete_pred_expr> evaluate(inst_act_map_t * inst_act_map);
+
+       void print_predicate();
+       void print_pred_subtree();
 
        MEMALLOC
 private:
        FuncInst * func_inst;
-       /* may have multiple precicates */
-       ModelList<predicate_expr> predicates;
+       bool entry_predicate;
+       bool does_write;
+
+       /* May have multiple predicate expressions */
+       PredExprSet pred_expressions;
+       ModelVector<Predicate *> children;
+
+       /* Only a single parent may exist */
+       Predicate * parent;
+
+       /* May have multiple back edges, e.g. nested loops */
+       PredSet backedges;
 };
+
+#endif /* __PREDICATE_H__ */