enum OrderType {SATC_PARTIAL, SATC_TOTAL};
typedef enum OrderType OrderType;
-enum HappenedBefore {SATC_FIRST, SATC_SECOND, SATC_UNORDERED};
-typedef enum HappenedBefore HappenedBefore;
-
/**
* SATC_FLAGFORCESOVERFLOW forces the operation to overflow if the boolean flag is true
* SATC_OVERFLOWSETSFLAG -- sets the flag if the operation overflows
}
}
-OrderNode *OrderGraph::getOrderNodeFromOrderGraph(uint64_t id, bool create) {
+OrderNode *OrderGraph::getOrderNodeFromOrderGraph(uint64_t id) {
OrderNode *node = new OrderNode(id);
OrderNode *tmp = nodes->get(node);
if ( tmp != NULL) {
delete node;
node = tmp;
- } else if (create) {
- nodes->add(node);
} else {
- delete node;
- return NULL;
+ nodes->add(node);
}
return node;
}
return tmp;
}
-OrderEdge *OrderGraph::getOrderEdgeFromOrderGraph(OrderNode *begin, OrderNode *end, bool create) {
+OrderEdge *OrderGraph::getOrderEdgeFromOrderGraph(OrderNode *begin, OrderNode *end) {
OrderEdge *edge = new OrderEdge(begin, end);
OrderEdge *tmp = edges->get(edge);
if ( tmp != NULL ) {
delete edge;
edge = tmp;
- } else if (create) {
- edges->add(edge);
} else {
- delete edge;
- return NULL;
+ edges->add(edge);
}
return edge;
}
~OrderGraph();
void addOrderConstraintToOrderGraph(BooleanOrder *bOrder);
void addMustOrderConstraintToOrderGraph(BooleanOrder *bOrder);
- OrderNode *getOrderNodeFromOrderGraph(uint64_t id, bool create = true);
- OrderEdge *getOrderEdgeFromOrderGraph(OrderNode *begin, OrderNode *end, bool create = true);
+ OrderNode *getOrderNodeFromOrderGraph(uint64_t id);
+ OrderEdge *getOrderEdgeFromOrderGraph(OrderNode *begin, OrderNode *end);
OrderNode *lookupOrderNodeFromOrderGraph(uint64_t id);
OrderEdge *lookupOrderEdgeFromOrderGraph(OrderNode *begin, OrderNode *end);
void addOrderEdge(OrderNode *node1, OrderNode *node2, BooleanOrder *constr);
DecomposeOrderResolver::~DecomposeOrderResolver() {
}
-HappenedBefore DecomposeOrderResolver::resolveOrder(uint64_t first, uint64_t second) {
- OrderNode *from = graph->getOrderNodeFromOrderGraph(first, false /*Don't create new node if doesn't exist*/);
- if (from == NULL) {
- return SATC_UNORDERED;
- }
- OrderNode *to = graph->getOrderNodeFromOrderGraph(second, false);
- if (from == NULL) {
- return SATC_UNORDERED;
- }
+bool DecomposeOrderResolver::resolveOrder(uint64_t first, uint64_t second) {
+ OrderNode *from = graph->lookupOrderNodeFromOrderGraph(first);
+ ASSERT(from != NULL);
+ OrderNode *to = graph->lookupOrderNodeFromOrderGraph(second);
+ ASSERT(to != NULL);
+
if (from->sccNum != to->sccNum) {
- OrderEdge *edge = graph->getOrderEdgeFromOrderGraph(from, to, false /* Don't create a new edge*/);
+ OrderEdge *edge = graph->lookupOrderEdgeFromOrderGraph(from, to);
if (edge != NULL && edge->mustPos) {
- return SATC_FIRST;
+ return true;
} else if ( edge != NULL && edge->mustNeg) {
- return SATC_SECOND;
+ return false;
} else {
switch (graph->getOrder()->type) {
case SATC_TOTAL:
- return from->sccNum < to->sccNum ? SATC_FIRST : SATC_SECOND;
+ return from->sccNum < to->sccNum;
case SATC_PARTIAL:
//Adding support for partial order ...
default:
class DecomposeOrderResolver : public OrderResolver {
public:
DecomposeOrderResolver(OrderGraph *graph, Vector<Order *> &orders);
- HappenedBefore resolveOrder(uint64_t first, uint64_t second);
+ bool resolveOrder(uint64_t first, uint64_t second);
virtual ~DecomposeOrderResolver();
private:
OrderGraph *graph;
}
-HappenedBefore IntegerEncOrderResolver::resolveOrder(uint64_t first, uint64_t second) {
+bool IntegerEncOrderResolver::resolveOrder(uint64_t first, uint64_t second) {
Element *elem1 = ierecord->getOrderIntegerElement(solver, first, false);
- if (elem1 == NULL)
- return SATC_UNORDERED;
+ ASSERT (elem1 != NULL);
Element *elem2 = ierecord->getOrderIntegerElement(solver, second, false);
- if (elem2 == NULL)
- return SATC_UNORDERED;
+ ASSERT (elem2 != NULL);
uint64_t val1 = getElementValueSATTranslator(solver, elem1);
uint64_t val2 = getElementValueSATTranslator(solver, elem2);
- return val1 < val2 ? SATC_FIRST : val1> val2 ? SATC_SECOND : SATC_UNORDERED;
+ return val1 < val2;
}
class IntegerEncOrderResolver : public OrderResolver {
public:
IntegerEncOrderResolver(CSolver *_solver, IntegerEncodingRecord *_ierecord);
- HappenedBefore resolveOrder(uint64_t first, uint64_t second);
+ bool resolveOrder(uint64_t first, uint64_t second);
virtual ~IntegerEncOrderResolver();
private:
CSolver *solver;
OrderPairResolver::~OrderPairResolver() {
}
-HappenedBefore OrderPairResolver::resolveOrder(uint64_t first, uint64_t second) {
+bool OrderPairResolver::resolveOrder(uint64_t first, uint64_t second) {
if (order->graph != NULL) {
// For the cases that tuning framework decides no to build a graph for order ...
OrderGraph *graph = order->graph;
- OrderNode *from = graph->getOrderNodeFromOrderGraph(first, false /*Don't create new node if doesn't exist*/);
- if (from == NULL) {
- return SATC_UNORDERED;
- }
- OrderNode *to = graph->getOrderNodeFromOrderGraph(second, false);
- if (from == NULL) {
- return SATC_UNORDERED;
- }
+ OrderNode *from = graph->lookupOrderNodeFromOrderGraph(first);
+ ASSERT(from != NULL);
+ OrderNode *to = graph->lookupOrderNodeFromOrderGraph(second);
+ ASSERT(to != NULL);
- OrderEdge *edge = graph->getOrderEdgeFromOrderGraph(from, to, false /* Don't create a new edge*/);
+ OrderEdge *edge = graph->lookupOrderEdgeFromOrderGraph(from, to);
+
if (edge != NULL && edge->mustPos) {
- return SATC_FIRST;
+ return true;
} else if ( edge != NULL && edge->mustNeg) {
- return SATC_SECOND;
+ return false;
}
}
}
-HappenedBefore OrderPairResolver::resolveTotalOrder(uint64_t first, uint64_t second) {
+bool OrderPairResolver::resolveTotalOrder(uint64_t first, uint64_t second) {
ASSERT(order->orderPairTable != NULL);
OrderPair pair(first, second, E_NULL);
Edge var = getOrderConstraint(order->orderPairTable, &pair);
if (edgeIsNull(var))
- return SATC_UNORDERED;
- return getValueCNF(solver->getSATEncoder()->getCNF(), var) ? SATC_FIRST : SATC_SECOND;
+ return false;
+ return getValueCNF(solver->getSATEncoder()->getCNF(), var);
}
class OrderPairResolver : public OrderResolver {
public:
OrderPairResolver(CSolver *_solver, Order *_order);
- HappenedBefore resolveOrder(uint64_t first, uint64_t second);
+ bool resolveOrder(uint64_t first, uint64_t second);
virtual ~OrderPairResolver();
private:
CSolver *solver;
Order *order;
- HappenedBefore resolveTotalOrder(uint64_t first, uint64_t second);
+ bool resolveTotalOrder(uint64_t first, uint64_t second);
};
#endif/* ORDERPAIRRESOLVER_H */
class OrderResolver {
public:
OrderResolver() {};
- virtual HappenedBefore resolveOrder(uint64_t first, uint64_t second) = 0;
+ virtual bool resolveOrder(uint64_t first, uint64_t second) = 0;
virtual ~OrderResolver() {};
CMEMALLOC;
};
DecomposeOrderTransform dot(this);
dot.doTransform();
- IntegerEncodingTransform iet(this);
- iet.doTransform();
+ //This leaks like crazy
+ // IntegerEncodingTransform iet(this);
+ //iet.doTransform();
naiveEncodingDecision(this);
satEncoder->encodeAllSATEncoder(this);
exit(-1);
}
-HappenedBefore CSolver::getOrderConstraintValue(Order *order, uint64_t first, uint64_t second) {
+bool CSolver::getOrderConstraintValue(Order *order, uint64_t first, uint64_t second) {
return order->encoding.resolver->resolveOrder(first, second);
}
/** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
bool getBooleanValue(Boolean *boolean);
- HappenedBefore getOrderConstraintValue(Order *order, uint64_t first, uint64_t second);
+ bool getOrderConstraintValue(Order *order, uint64_t first, uint64_t second);
bool isTrue(Boolean *b);
bool isFalse(Boolean *b);
void * ourcalloc(size_t count, size_t size);
void * ourrealloc(void *ptr, size_t size);
*/
- /*
+
+#if 0
void * model_malloc(size_t size);
void model_free(void *ptr);
void * model_calloc(size_t count, size_t size);
#define ourfree model_free
#define ourrealloc model_realloc
#define ourcalloc model_calloc
-*/
+#else
static inline void *ourmalloc(size_t size) { return malloc(size); }
static inline void ourfree(void *ptr) { free(ptr); }
static inline void *ourcalloc(size_t count, size_t size) { return calloc(count, size); }
static inline void *ourrealloc(void *ptr, size_t size) { return realloc(ptr, size); }
+#endif
#define CMEMALLOC \
void *operator new(size_t size) { \