日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

dsa算法(17)

發布時間:2024/1/8 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 dsa算法(17) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.3.2.2.3.Lengauer-Tarjan算法第四步

在第四步,240行的DT.Vertex[i]得到的是序號為i的節點。如果DT.IDoms中的節點與Semi所指的節點不一致(即直接支配者節點與半支配者節點不一致),把DT.IDoms調整為DT.IDoms[DT.IDoms[W]]。因為推論1中,當sdom(w) != sdom(v)時,Idom(w) = Idom(v),第三步并沒有計算該部分,這由第四步來完成,并且239行的循環從靠近樹根處開始,以確保DT.IDoms[DT.IDoms[W]]一定有意義。

?

Calculate(續)

?

238??? ? // Step #4:Explicitly define the immediate dominator of ea ch vertex

239??? ? for (unsignedi = 2; i <= N; ++i) {

240??? ??? typenameGraphT::NodeType* W = DT.Vertex[i];

241??? ??? typenameGraphT::NodeType*& WIDom = DT.IDoms[W];

242??? ??? if (WIDom != DT.Vertex[DT.Info[W].Semi])

243??? ????? WIDom = DT.IDoms[WIDom];

244??? ? }

245???

246??? ? if (DT.Roots.empty()) return;

247???

248??? ? // Add a node forthe root.? This node might be the actualroot, if there is

249??? ? // one exit block,or it may be the virtual exit (denoted by (BasicBlock *)0)

250??? ? // which postdominates all real exits ifthere are multiple exit blocks, or

251??? ? // an infiniteloop.

252??? ? typenameGraphT::NodeType* Root = !MultipleRoots ? DT.Roots[0] : 0;

253???

254??? ? DT.DomTreeNodes[Root] = DT.RootNode =

255??? ??????????????????????? new DomTreeNodeBase<typenameGraphT::NodeType>(Root, 0);

256???

257??? ? // Loop over all ofthe reachable blocks in the function...

258??? ? for (unsignedi = 2; i <= N; ++i) {

259??? ??? typenameGraphT::NodeType* W = DT.Vertex[i];

260???

261??? ??? DomTreeNodeBase<typenameGraphT::NodeType> *BBNode = DT.DomTreeNodes[W];

262??? ??? if (BBNode) continue;? // Haven'tcalculated this node yet?

263???

264??? ??? typenameGraphT::NodeType* ImmDom = DT.getIDom(W);

265???

266??? ??? assert(ImmDom|| DT.DomTreeNodes[NULL]);

267???

268??? ??? // Get orcalculate the node for the immediate dominator

269??? ??? DomTreeNodeBase<typenameGraphT::NodeType> *IDomNode =

270??? ????????????????????????????????????????????????????DT.getNodeForBlock(ImmDom);

271???

272??? ??? // Add a new treenode for this BasicBlock, and link it as a child of

273??? ??? // IDomNode

274??? ??? DomTreeNodeBase<typenameGraphT::NodeType> *C =

275??? ??????????????????? newDomTreeNodeBase<typenameGraphT::NodeType>(W, IDomNode);

276??? ??? DT.DomTreeNodes[W] = IDomNode->addChild(C);

277??? ? }

278???

279??? ? // Free temporarymemory used to construct idom's

280??? ? DT.IDoms.clear();

281??? ? DT.Info.clear();

282??? ? std::vector<typenameGraphT::NodeType*>().swap(DT.Vertex);

283???

284??? ? DT.updateDFSNumbers();

285??? }

?

余下的代碼則是構建一棵支配樹(dominator tree)。我們例子的支配樹如下圖所示。


284行的updateDFSNumbers函數以深度優先序遍歷配置樹,對DomTreeNodeBase中的DFSNumIn及DFSNumOut域賦值。

?

579??? ? void updateDFSNumbers(){

580??? ??? unsigned DFSNum = 0;

581???

582??? ??? SmallVector<std::pair<DomTreeNodeBase<NodeT>*,

583??? ??????????????? typenameDomTreeNodeBase<NodeT>::iterator>, 32> WorkStack;

584???

585??? ??? DomTreeNodeBase<NodeT> *ThisRoot =getRootNode();

586???

587??? ??? if (!ThisRoot)

588??? ????? return;

589???

590??? ??? // Even in thecase of multiple exits that form the post dominator root

591??? ??? // nodes, do notiterate over all exits, but start from the virtual root

592??? ??? // node.Otherwise bbs, that are not post dominated by any exit but by the

593??? ??? // virtual rootnode, will never be assigned a DFS number.

594??? ???WorkStack.push_back(std::make_pair(ThisRoot, ThisRoot->begin()));

595??? ??? ThisRoot->DFSNumIn = DFSNum++;

596???

597??? ??? while(!WorkStack.empty()) {

598??? ????? DomTreeNodeBase<NodeT> *Node =WorkStack.back().first;

599??? ????? typename DomTreeNodeBase<NodeT>::iteratorChildIt =

600??? ??????? WorkStack.back().second;

601???

602??? ????? // If wevisited all of the children of this node, "recurse" back up the

603??? ????? // stacksetting the DFOutNum.

604??? ????? if (ChildIt == Node->end()) {

605??? ??????? Node->DFSNumOut = DFSNum++;

606??? ??????? WorkStack.pop_back();

607??? ????? } else {

608??? ??????? // Otherwise,recursively visit this child.

609??? ??????? DomTreeNodeBase<NodeT> *Child =*ChildIt;

610??? ??????? ++WorkStack.back().second;

611???

612??? ??????? WorkStack.push_back(std::make_pair(Child,Child->begin()));

613??? ??????? Child->DFSNumIn = DFSNum++;

614??? ????? }

615??? ??? }

616???

617??? ??? SlowQueries = 0;

618??? ??? DFSInfoValid = true;

619??? ? }

?

編號的結果如上圖所示。注意DT是DominatorTree中的成員,因此這些內容可以帶到下一個遍使用。


總結

以上是生活随笔為你收集整理的dsa算法(17)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。