Go to the documentation of this file.00001
00015 #include "ManagerUDDUChainsXAIF.hpp"
00016
00017
00018 namespace OA {
00019 namespace XAIF {
00020
00021 static bool debug = false;
00022
00025 ManagerUDDUChainsXAIF::ManagerUDDUChainsXAIF(OA_ptr<XAIFIRInterface> _ir) : mIR(_ir)
00026 {
00027 OA_DEBUG_CTRL_MACRO("DEBUG_ManagerUDDUChainsXAIF:ALL", debug);
00028 }
00029
00033 OA_ptr<UDDUChainsXAIF> ManagerUDDUChainsXAIF::performAnalysis(OA_ptr<CFG::CFGInterface> cfg,
00034 OA_ptr<UDDUChains::Interface> udChains,
00035 bool donotfilterBB) {
00036 if (debug) {
00037 std::cout << "In ReachDefs::ManagerUDDUChainsXAIF::performAnalysis" << std::endl;
00038 }
00039 OA_ptr<UDDUChainsXAIF> aUDDUChainsXAIF;
00040 aUDDUChainsXAIF = new UDDUChainsXAIF();
00041
00042
00043
00044
00045
00046 mStmtToBBMap[StmtHandle(0)] = cfg->getEntry();
00047 if (debug) { std::cout << "mStmtToBBMap[StmtHandle(0)] = "
00048 << mStmtToBBMap[StmtHandle(0)] << std::endl; }
00049 OA_ptr<DGraph::NodesIteratorInterface> nodeIterPtr;
00050 nodeIterPtr = cfg->getNodesIterator();
00051
00052 for ( ;nodeIterPtr->isValid(); ++(*nodeIterPtr) ) {
00053 OA_ptr<DGraph::NodeInterface> dnode = nodeIterPtr->current();
00054 OA_ptr<CFG::NodeInterface> node = dnode.convert<CFG::NodeInterface>();
00055 OA_ptr<CFG::NodeStatementsIteratorInterface> stmtIterPtr
00056 = node->getNodeStatementsIterator();
00057
00058 for (; stmtIterPtr->isValid(); ++(*stmtIterPtr)) {
00059 OA::StmtHandle stmt = stmtIterPtr->current();
00060
00061 mStmtToBBMap[stmt] = node;
00062 if (debug && !donotfilterBB) {
00063 std::cout << "mapping stmt: "
00064 << mIR->toString(stmt)
00065 << " to CFG node >";
00066 node->output(*mIR);
00067 std::cout << "< end of CFG node and the following memrefs are mapped to this statement: " << std::endl;
00068 }
00069
00070 OA_ptr<MemRefHandleIterator> mrItPtr = mIR->getAllMemRefs(stmt);
00071 for ( ; mrItPtr->isValid(); (*mrItPtr)++) {
00072 if (debug) {
00073 std::cout << "memref (" << mrItPtr->current().hval()
00074 << ") = " << mIR->toString(mrItPtr->current()) << std::endl;
00075 }
00076 mMemRefToStmt[mrItPtr->current()] = stmt;
00077 }
00078 }
00079 }
00080
00081 OA_ptr<UDDUChains::Interface::MemRefsWithUDChainIterator> useIterPtr;
00082 useIterPtr = udChains->getMemRefsWithUDChainIterator();
00083 for (; useIterPtr->isValid(); ++(*useIterPtr)) {
00084 bool haveDefinitionBeforeUse=false;
00085 MemRefHandle use = useIterPtr->current();
00086 if (debug) {
00087 std::cout << "use memref (" << use.hval() << ") = " << mIR->toString(use);
00088 std::cout << std::endl;
00089 }
00090
00091 OA_ptr<CFG::NodeInterface> useBB = mStmtToBBMap[mMemRefToStmt[use]];
00092 if (debug) {
00093 std::cout << " occurs in useBB = " << useBB << std::endl;
00094 }
00095 StmtSet subSet;
00096 OA_ptr<UDDUChains::Interface::ChainStmtIterator> defStmtIterPtr;
00097 defStmtIterPtr = udChains->getUDChainStmtIterator(use);
00098
00099 for (; defStmtIterPtr->isValid(); (*defStmtIterPtr)++) {
00100 StmtHandle defStmt = defStmtIterPtr->current();
00101 if (debug) {
00102 std::cout << " def stmt (" << defStmt.hval() << ") = "
00103 << mIR->toString(defStmt) << std::endl;
00104 std::cout << " mStmtToBBMap[defStmt] = " << mStmtToBBMap[defStmt]
00105 << std::endl;
00106 }
00107 if (donotfilterBB) {
00108 subSet.insert(defStmt);
00109 if (debug) { std::cout << " Filter off - inserting def stmt" << std::endl; }
00110 }
00111 else {
00112
00113
00114
00115
00116 if (mStmtToBBMap[defStmt]==useBB) {
00117 if (debug) { std::cout << " Filter on - stmts are in same basic block" << std::endl; }
00118
00119
00120 OA_ptr<CFG::NodeStatementsIteratorInterface> stmtIterPtr
00121 = useBB->getNodeStatementsIterator();
00122
00123 for (; stmtIterPtr->isValid(); ++(*stmtIterPtr)) {
00124 OA::StmtHandle stmt = stmtIterPtr->current();
00125 if (!haveDefinitionBeforeUse && stmt == mMemRefToStmt[use]) {
00126 if (debug) { std::cout << "Filter on - out of order - inserting StmtHandle(0)" << std::endl; }
00127 subSet.insert(StmtHandle(0));
00128 haveDefinitionBeforeUse=true;
00129 break;
00130 }
00131 if (stmt == defStmt) {
00132 if (debug) { std::cout << " Filter on - inserting def stmt" << std::endl; }
00133 subSet.insert(defStmt);
00134 haveDefinitionBeforeUse=true;
00135 break;
00136 }
00137 }
00138
00139 } else {
00140 if (debug) { std::cout << " Filter on - outside def - inserting StmtHandle(0)" << std::endl; }
00141 subSet.insert(StmtHandle(0));
00142 haveDefinitionBeforeUse=true;
00143 }
00144 }
00145 }
00146
00147 int chainId = aUDDUChainsXAIF->findChain(subSet);
00148 if (chainId != UDDUChainsXAIF::CHAIN_ID_NONE) {
00149
00150 aUDDUChainsXAIF->insertInto(use, chainId);
00151 if (debug) { std::cout << " found as existing chain id: " << chainId << std::endl; }
00152 } else {
00153
00154
00155 int newChainId = getNextChainId();
00156 aUDDUChainsXAIF->insertInto(use,newChainId);
00157 if (debug) { std::cout << " make new chain id: " << newChainId << std::endl; }
00158 aUDDUChainsXAIF->addStmtSet(subSet,newChainId);
00159 }
00160 }
00161
00162 OA_ptr<UDDUChains::Interface::MemRefsWithDUChainIterator> defIterPtr;
00163 defIterPtr = udChains->getMemRefsWithDUChainIterator();
00164 for (; defIterPtr->isValid(); ++(*defIterPtr)) {
00165 bool haveUseAfterDefinition=false;
00166 MemRefHandle def = defIterPtr->current();
00167 if (debug) {
00168 std::cout << "def memref (" << def.hval() << ") = " << mIR->toString(def);
00169 std::cout << std::endl;
00170 }
00171
00172 OA_ptr<CFG::NodeInterface> defBB
00173 = mStmtToBBMap[mMemRefToStmt[def]];
00174 if (debug) {
00175 std::cout << " occurs in defBB = " << defBB << std::endl;
00176 }
00177
00178
00179
00180 StmtSet subSet;
00181 OA_ptr<UDDUChains::Interface::ChainStmtIterator> useStmtIterPtr;
00182 useStmtIterPtr = udChains->getDUChainStmtIterator(def);
00183 for (; useStmtIterPtr->isValid(); (*useStmtIterPtr)++) {
00184 StmtHandle useStmt = useStmtIterPtr->current();
00185 if (debug) {
00186 std::cout << " useStmt (" << useStmt.hval() << ") = "
00187 << mIR->toString(useStmt) << std::endl;
00188 std::cout << " mStmtToBBMap[useStmt] = " << mStmtToBBMap[useStmt];
00189 std::cout << std::endl;
00190 }
00191 if (donotfilterBB) {
00192 subSet.insert(useStmt);
00193 if (debug) { std::cout << " Filter off - inserting use stmt" << std::endl; }
00194 }
00195 else {
00196
00197
00198
00199
00200 if (mStmtToBBMap[useStmt]==defBB) {
00201 if (debug) { std::cout << " Filter on - stmts are in same basic block" << std::endl; }
00202
00203
00204 OA_ptr<CFG::NodeStatementsIteratorInterface> stmtIterPtr
00205 = defBB->getNodeStatementsIterator();
00206
00207 for (; stmtIterPtr->isValid(); ++(*stmtIterPtr)) {
00208 OA::StmtHandle stmt = stmtIterPtr->current();
00209 if (!haveUseAfterDefinition && stmt == useStmt) {
00210 if (debug) { std::cout << " Filter on - out of order - inserting StmtHandle(0)" << std::endl; }
00211 subSet.insert(StmtHandle(0));
00212 haveUseAfterDefinition=true;
00213 break;
00214 }
00215 if (stmt == mMemRefToStmt[def]) {
00216 if (debug) { std::cout << " Filter on - inserting use stmt" << std::endl; }
00217 subSet.insert(useStmt);
00218 haveUseAfterDefinition=true;
00219 break;
00220 }
00221 }
00222 }
00223 else {
00224 if (debug) { std::cout << " Filter on - outside use - inserting StmtHandle(0)" << std::endl; }
00225 subSet.insert(StmtHandle(0));
00226 haveUseAfterDefinition=true;
00227 }
00228 }
00229 }
00230
00231 int chainId = aUDDUChainsXAIF->findChain(subSet);
00232 if (chainId != UDDUChainsXAIF::CHAIN_ID_NONE) {
00233
00234 aUDDUChainsXAIF->insertInto(def, chainId);
00235 if (debug) { std::cout << " found as existing chain id: " << chainId << std::endl; }
00236 }
00237 else {
00238
00239
00240 int newChainId = getNextChainId();
00241 aUDDUChainsXAIF->insertInto(def,newChainId);
00242 aUDDUChainsXAIF->addStmtSet(subSet,newChainId);
00243 if (debug) { std::cout << " make new chain id: " << newChainId << std::endl; }
00244 }
00245 }
00246
00247
00248
00249 StmtSet emptySet;
00250 aUDDUChainsXAIF->addStmtSet(emptySet,0);
00251 return aUDDUChainsXAIF;
00252 }
00253
00254 int ManagerUDDUChainsXAIF::ourCurrentStartId=3;
00255
00256 int ManagerUDDUChainsXAIF::getNextChainId() {
00257 return ourCurrentStartId++;
00258 }
00259
00260 }
00261
00262 }