00001
00002 #if !defined(oagFpgaAiAiModGraph_P)
00003 #define oagFpgaAiAiModGraph_P
00004
00005 #include <stdlib.h>
00006
00007 #include "oaDesignDB.h"
00008 #include "oagFpgaAiModRef.h"
00009 #include "oagFpgaManager.h"
00010 #include "oagAiGraph.h"
00011 #include <list>
00012 #include <set>
00013
00014 using namespace std;
00015
00016 namespace oagFpga {
00017
00018
00019
00020
00045
00046
00047
00048 class AiModGraph {
00049 friend class SimMod;
00050
00051 private:
00052
00053 AiModGraph();
00054
00055
00056 public:
00057
00058 typedef set<AiModRef> Cut;
00059 typedef list<Cut> CutSet;
00060
00063
00064 static AiModRef getNull(oa::oaModule *module) {
00074 return AiModRef(oagAi::Graph::getNull(), module);
00075 }
00076 static inline bool isNull(AiModRef x) {
00082 return oagAi::Graph::isNull(x.ref);
00083 }
00084 static inline AiModRef constantOne(oa::oaModule *module) {
00088 return AiModRef(getGraph(module)->constantOne(), module);
00089 }
00090 static inline AiModRef constantZero(oa::oaModule *module) {
00094 return AiModRef(getGraph(module)->constantZero(), module);
00095 }
00096 static inline AiModRef notOf(AiModRef x) {
00103 return AiModRef(oagAi::Graph::notOf(x.ref), x.module);
00104 }
00105 static inline bool isInverted(AiModRef x) {
00109 return oagAi::Graph::isInverted(x.ref);
00110 }
00111 static inline AiModRef getNonInverted(AiModRef x) {
00115 return AiModRef(oagAi::Graph::getNonInverted(x.ref), x.module);
00116 }
00117
00121
00122 static inline unsigned int getUserData(AiModRef x, unsigned int index) {
00128 return getGraph(x)->getUserData(x.ref, index);
00129 }
00130 static inline void setUserData(AiModRef x, unsigned int index, unsigned int data) {
00136 getGraph(x)->setUserData(x.ref, index, data);
00137 }
00138
00142
00143 static AiModRef newSequential(AiModRef nextState) {
00151 return AiModRef(getGraph(nextState)->newSequential(nextState.ref), nextState.module);
00152 }
00153 static AiModRef newTerminal(AiModRef terminal) {
00157 return AiModRef(getGraph(terminal)->newTerminal(terminal.ref), terminal.module);
00158 }
00159 static AiModRef newAnd(AiModRef x, AiModRef y);
00160 static AiModRef andOf(AiModRef x, AiModRef y);
00161 static void setTerminalDriver(AiModRef terminal, AiModRef driver);
00162 static void setNextState(AiModRef sequential, AiModRef nextState);
00163 static void setAndLeft(AiModRef x, AiModRef left);
00164 static void setAndRight(AiModRef x, AiModRef left);
00165
00166 static void resubstitute(AiModRef original, AiModRef replacement);
00167 static void resubstitute(AiModRef original, AiModRef replacement, AiModRef target);
00168 static void detach(AiModRef x);
00169
00173
00174 static inline oagAi::Node::Type getNodeType(AiModRef x) {
00178 return getGraph(x)->getNodeType(x.ref);
00179 }
00180
00181
00182 static AiModRef getTerminalDriver(AiModRef terminal) {
00194 return AiModRef(getGraph(terminal)->getTerminalDriver(terminal.ref), terminal.module);
00195 }
00196 static bool isTerminal(AiModRef x) {
00200 return getGraph(x)->isTerminal(x.ref);
00201 }
00202
00203 static AiModRef getNextState(AiModRef sequential) {
00210 return AiModRef(getGraph(sequential)->getNextState(sequential.ref), sequential.module);
00211 }
00212 static bool isSequential(AiModRef x) {
00216 return getGraph(x)->isSequential(x.ref);
00217 }
00218 static oagAi::Node::SequentialData *getSequentialData(AiModRef sequential) {
00225 return getGraph(sequential)->getSequentialData(sequential.ref);
00226 }
00227
00228 static bool isAnd(AiModRef x) {
00232 return getGraph(x)->isAnd(x.ref);
00233 }
00234 static inline AiModRef getAndLeft(AiModRef x) {
00241 return AiModRef(getGraph(x)->getAndLeft(x.ref), x.module);
00242 }
00243 static inline AiModRef getAndRight(AiModRef x) {
00250 return AiModRef(getGraph(x)->getAndRight(x.ref), x.module);
00251 }
00252
00253 static list<AiModRef> getFanout(AiModRef x);
00254 static void getFanout(AiModRef x, list<AiModRef> &result);
00255 static inline bool hasFanout(AiModRef x) {
00261 return getGraph(x)->hasFanout(x.ref);
00262 }
00263
00267
00268 static AiModRef prepareNetToAiConnection(oa::oaModBitNet *net);
00269 static oa::oaModBitNet * getNetToAiConnection(AiModRef ref);
00270 static AiModRef getNetToAiConnection(oa::oaModBitNet *net);
00271 static void setNetToAiConnection(oa::oaModBitNet *net, AiModRef ref);
00272 static void removeNetToAiConnection(oa::oaModBitNet *net);
00273
00274 static oa::oaModBitNet * findDriverOfEquivalentNets(oa::oaModBitNet *net);
00275 static void connectEquivalentNetsInGraph(oa::oaModule *module);
00276
00280
00281 static bool hasCombinationalCycle(oa::oaModule *module);
00282
00283 static CutSet enumerateKfeasibleCuts(AiModRef x, unsigned int maxCutSize,
00284 int maxCutCout = -1, int maxCutDepth = -1,
00285 bool includeConstantNode = true);
00286 static void clearKfeasibleCuts(oa::oaModule *module);
00287
00288 static void getTransitiveFanin(AiModRef x, list<AiModRef> &transitiveFanin,
00289 bool includeRoots = true, bool crossSequential = false);
00290 static void getTransitiveFanin(AiModRef x, vector<AiModRef> &transitiveFanin,
00291 bool includeRoots = true, bool crossSequential = false);
00292 static void getTransitiveFanin(list<AiModRef> x, list<AiModRef> &transitiveFanin,
00293 bool includeRoots = true, bool crossSequential = false);
00294 static void getTransitiveFanin(list<AiModRef> x, vector<AiModRef> &transitiveFanin,
00295 bool includeRoots = true, bool crossSequential = false);
00296
00297 static void getTransitiveFanout(AiModRef x, list<AiModRef> &transitiveFanout,
00298 bool includeRoots = true, bool crossSequential = false);
00299 static void getTransitiveFanout(AiModRef x, vector<AiModRef> &transitiveFanout,
00300 bool includeRoots = true, bool crossSequential = false);
00301 static void getTransitiveFanout(list<AiModRef> x, list<AiModRef> &transitiveFanout,
00302 bool includeRoots = true, bool crossSequential = false);
00303 static void getTransitiveFanout(list<AiModRef> x, vector<AiModRef> &transitiveFanout,
00304 bool includeRoots = true, bool crossSequential = false);
00305
00306 static void getFaninCone(AiModRef x, const list<AiModRef> &coneRoots,
00307 list<AiModRef> &transitiveFanin, bool includeRoots = true);
00308 static void getFanoutCone(AiModRef x, const list<AiModRef> &coneRoots,
00309 list<AiModRef> &transitiveFanout, bool includeRoots = true);
00310
00311 static void getFaninRoots(AiModRef x, list<AiModRef> &faninRoots);
00312 static void getFanoutRoots(AiModRef x, list<AiModRef> &fanoutRoots);
00313
00317
00318 static bool testEquivalence(AiModRef x, AiModRef y);
00319 static void setEquivalent(AiModRef x, AiModRef y);
00320 static void getEquivalents(AiModRef x, list<AiModRef> & result);
00321 static void removeEquivalences(AiModRef x) {
00328 getGraph(x)->removeEquivalences(x.ref);
00329 }
00330 static void chooseEquivalent(AiModRef x) {
00338 getGraph(x)->chooseEquivalent(x.ref);
00339 }
00340
00341 static void getFanoutOfEquivalentNodes(AiModRef x, list<AiModRef> & result);
00342
00346
00347 static void print(oa::oaModule *module);
00348
00349 static void getAllNodes(oa::oaModule *module, list<AiModRef> &result);
00350 static void getInputs(oa::oaModule *module, list<AiModRef> &result);
00351 static void getOutputs(oa::oaModule *module, list<AiModRef> &result);
00352 static void getLocalStates(oa::oaModule *module, list<AiModRef> &result);
00353
00354 static void getAllConnections(oa::oaModBitNet *net,
00355 set<oa::oaModBitNet*> &connectedNets,
00356 set<AiModRef> &connectedRefs,
00357 bool searchForwardThroughGraph = true,
00358 bool searchBackwardThroughGraph = true,
00359 bool searchThroughEquivNets = true,
00360 bool searchThroughEquivRefs = false,
00361 bool includeSelf = true);
00362 static void getAllConnections(AiModRef x,
00363 set<oa::oaModBitNet*> &connectedNets,
00364 set<AiModRef> &connectedRefs,
00365 bool searchForwardThroughGraph = true,
00366 bool searchBackwardThroughGraph = true,
00367 bool searchThroughEquivNets = true,
00368 bool searchThroughEquivRefs = false,
00369 bool includeSelf = true);
00370
00374
00375 static void incrementExternalReferences(AiModRef x) {
00385 getGraph(x)->incrementExternalReferences(x.ref);
00386 }
00387 static void decrementExternalReferences(AiModRef x) {
00395 getGraph(x)->decrementExternalReferences(x.ref);
00396 }
00397 static void clearExternalReferences(AiModRef x) {
00401 getGraph(x)->clearExternalReferences(x.ref);
00402 }
00403
00405
00406 protected:
00407
00408 static inline oagAi::Graph * getGraph(oa::oaDesign *design) {
00415 return &(Manager::get(design)->ai);
00416 }
00417 static inline oagAi::Graph * getGraph(oa::oaModule *module) {
00425 return &(Manager::get(module->getDesign())->ai);
00426 }
00427 static inline oagAi::Graph * getGraph(const AiModRef &x) {
00430 return &(Manager::get(x.module->getDesign())->ai);
00431 }
00432
00433 static void failIfInDifferentModules(oa::oaModule *x, oa::oaModule *y);
00434 static void failIfInDifferentModules(AiModRef x, AiModRef y) {
00438 failIfInDifferentModules(x.module, y.module);
00439 }
00440
00441 static oa::oaModule* convertAiModRefListToRefList(const list<AiModRef> & source,
00442 list<oagAi::Ref> & result);
00443 static void convertRefListToAiModRefList(const list<oagAi::Ref> & source,
00444 oa::oaModule *module,
00445 list<AiModRef> & result);
00446 static void convertRefVectorToAiModRefVector(const vector<oagAi::Ref> & source,
00447 oa::oaModule *module,
00448 vector<AiModRef> & result);
00449 };
00450
00451 }
00452
00453 #endif