From 5d0c8be1e7d652a85d36827074f4c72661e7457f Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 5 Feb 2013 17:13:28 -0800 Subject: [PATCH] cyclegraph: template-ize addRMWEdge() --- cyclegraph.cc | 18 ++++++++++++++---- cyclegraph.h | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cyclegraph.cc b/cyclegraph.cc index e834cb67..1ff9d70b 100644 --- a/cyclegraph.cc +++ b/cyclegraph.cc @@ -118,12 +118,18 @@ bool CycleGraph::mergeNodes(CycleNode *w_node, CycleNode *p_node, { ASSERT(!w_node->is_promise()); ASSERT(p_node->is_promise()); + const Promise *promise = p_node->getPromise(); if (!promise->is_compatible(w_node->getAction())) { hasCycles = true; return false; } + /* Transfer the RMW */ + CycleNode *promise_rmw = p_node->getRMW(); + if (promise_rmw && promise_rmw != w_node->getRMW() && w_node->setRMW(promise_rmw)) + hasCycles = true; + /* Transfer back edges to w_node */ while (p_node->getNumBackEdges() > 0) { CycleNode *back = p_node->removeBackEdge(); @@ -201,15 +207,16 @@ bool CycleGraph::addNodeEdge(CycleNode *fromnode, CycleNode *tonode) * @brief Add an edge between a write and the RMW which reads from it * * Handles special case of a RMW action, where the ModelAction rmw reads from - * the ModelAction from. The key differences are: + * the ModelAction/Promise from. The key differences are: * (1) no write can occur in between the rmw and the from action. * (2) Only one RMW action can read from a given write. * - * @param from The edge comes from this ModelAction + * @param from The edge comes from this ModelAction/Promise * @param rmw The edge points to this ModelAction; this action must read from - * ModelAction from + * the ModelAction/Promise from */ -void CycleGraph::addRMWEdge(const ModelAction *from, const ModelAction *rmw) +template +void CycleGraph::addRMWEdge(const T *from, const ModelAction *rmw) { ASSERT(from); ASSERT(rmw); @@ -240,6 +247,9 @@ void CycleGraph::addRMWEdge(const ModelAction *from, const ModelAction *rmw) addNodeEdge(fromnode, rmwnode); } +/* Instantiate two forms of CycleGraph::addRMWEdge */ +template void CycleGraph::addRMWEdge(const ModelAction *from, const ModelAction *rmw); +template void CycleGraph::addRMWEdge(const Promise *from, const ModelAction *rmw); #if SUPPORT_MOD_ORDER_DUMP void CycleGraph::dumpNodes(FILE *file) const diff --git a/cyclegraph.h b/cyclegraph.h index fcb1d309..a9e46120 100644 --- a/cyclegraph.h +++ b/cyclegraph.h @@ -30,8 +30,10 @@ class CycleGraph { template bool addEdge(const T from, const U to); + template + void addRMWEdge(const T *from, const ModelAction *rmw); + bool checkForCycles() const; - void addRMWEdge(const ModelAction *from, const ModelAction *rmw); bool checkPromise(const ModelAction *from, Promise *p) const; template -- 2.34.1