Mercurial > hg > CbC > CbC_llvm
comparison lib/Transforms/ObjCARC/ObjCARCOpts.cpp @ 83:60c9769439b8 LLVM3.7
LLVM 3.7
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 18 Feb 2015 14:55:36 +0900 |
parents | 54457678186b |
children | afa8332a0e37 |
comparison
equal
deleted
inserted
replaced
78:af83660cff7b | 83:60c9769439b8 |
---|---|
186 P = GetUnderlyingObjCPtr(P); | 186 P = GetUnderlyingObjCPtr(P); |
187 | 187 |
188 if (isa<AllocaInst>(P)) | 188 if (isa<AllocaInst>(P)) |
189 return true; | 189 return true; |
190 | 190 |
191 if (!Visited.insert(P)) | 191 if (!Visited.insert(P).second) |
192 continue; | 192 continue; |
193 | 193 |
194 if (const SelectInst *SI = dyn_cast<const SelectInst>(P)) { | 194 if (const SelectInst *SI = dyn_cast<const SelectInst>(P)) { |
195 Worklist.push_back(SI->getTrueValue()); | 195 Worklist.push_back(SI->getTrueValue()); |
196 Worklist.push_back(SI->getFalseValue()); | 196 Worklist.push_back(SI->getFalseValue()); |
410 | 410 |
411 // Merge the insert point sets. If there are any differences, | 411 // Merge the insert point sets. If there are any differences, |
412 // that makes this a partial merge. | 412 // that makes this a partial merge. |
413 bool Partial = ReverseInsertPts.size() != Other.ReverseInsertPts.size(); | 413 bool Partial = ReverseInsertPts.size() != Other.ReverseInsertPts.size(); |
414 for (Instruction *Inst : Other.ReverseInsertPts) | 414 for (Instruction *Inst : Other.ReverseInsertPts) |
415 Partial |= ReverseInsertPts.insert(Inst); | 415 Partial |= ReverseInsertPts.insert(Inst).second; |
416 return Partial; | 416 return Partial; |
417 } | 417 } |
418 | 418 |
419 namespace { | 419 namespace { |
420 /// \brief This class summarizes several per-pointer runtime properties which | 420 /// \brief This class summarizes several per-pointer runtime properties which |
878 Value *Ptr, | 878 Value *Ptr, |
879 MDString *PtrSourceMDNodeID, | 879 MDString *PtrSourceMDNodeID, |
880 Sequence OldSeq, | 880 Sequence OldSeq, |
881 Sequence NewSeq) { | 881 Sequence NewSeq) { |
882 MDNode *Node = nullptr; | 882 MDNode *Node = nullptr; |
883 Value *tmp[3] = {PtrSourceMDNodeID, | 883 Metadata *tmp[3] = {PtrSourceMDNodeID, |
884 SequenceToMDString(Inst->getContext(), | 884 SequenceToMDString(Inst->getContext(), OldSeq), |
885 OldSeq), | 885 SequenceToMDString(Inst->getContext(), NewSeq)}; |
886 SequenceToMDString(Inst->getContext(), | |
887 NewSeq)}; | |
888 Node = MDNode::get(Inst->getContext(), tmp); | 886 Node = MDNode::get(Inst->getContext(), tmp); |
889 | 887 |
890 Inst->setMetadata(NodeId, Node); | 888 Inst->setMetadata(NodeId, Node); |
891 } | 889 } |
892 | 890 |
2192 TerminatorInst *TI = cast<TerminatorInst>(&CurrBB->back()); | 2190 TerminatorInst *TI = cast<TerminatorInst>(&CurrBB->back()); |
2193 succ_iterator SE(TI, false); | 2191 succ_iterator SE(TI, false); |
2194 | 2192 |
2195 while (SuccStack.back().second != SE) { | 2193 while (SuccStack.back().second != SE) { |
2196 BasicBlock *SuccBB = *SuccStack.back().second++; | 2194 BasicBlock *SuccBB = *SuccStack.back().second++; |
2197 if (Visited.insert(SuccBB)) { | 2195 if (Visited.insert(SuccBB).second) { |
2198 TerminatorInst *TI = cast<TerminatorInst>(&SuccBB->back()); | 2196 TerminatorInst *TI = cast<TerminatorInst>(&SuccBB->back()); |
2199 SuccStack.push_back(std::make_pair(SuccBB, succ_iterator(TI))); | 2197 SuccStack.push_back(std::make_pair(SuccBB, succ_iterator(TI))); |
2200 BBStates[CurrBB].addSucc(SuccBB); | 2198 BBStates[CurrBB].addSucc(SuccBB); |
2201 BBState &SuccStates = BBStates[SuccBB]; | 2199 BBState &SuccStates = BBStates[SuccBB]; |
2202 SuccStates.addPred(CurrBB); | 2200 SuccStates.addPred(CurrBB); |
2233 while (!PredStack.empty()) { | 2231 while (!PredStack.empty()) { |
2234 reverse_dfs_next_succ: | 2232 reverse_dfs_next_succ: |
2235 BBState::edge_iterator PE = BBStates[PredStack.back().first].pred_end(); | 2233 BBState::edge_iterator PE = BBStates[PredStack.back().first].pred_end(); |
2236 while (PredStack.back().second != PE) { | 2234 while (PredStack.back().second != PE) { |
2237 BasicBlock *BB = *PredStack.back().second++; | 2235 BasicBlock *BB = *PredStack.back().second++; |
2238 if (Visited.insert(BB)) { | 2236 if (Visited.insert(BB).second) { |
2239 PredStack.push_back(std::make_pair(BB, BBStates[BB].pred_begin())); | 2237 PredStack.push_back(std::make_pair(BB, BBStates[BB].pred_begin())); |
2240 goto reverse_dfs_next_succ; | 2238 goto reverse_dfs_next_succ; |
2241 } | 2239 } |
2242 } | 2240 } |
2243 ReverseCFGPostOrder.push_back(PredStack.pop_back_val().first); | 2241 ReverseCFGPostOrder.push_back(PredStack.pop_back_val().first); |
2388 // This can happen if we catch an additive overflow during path count | 2386 // This can happen if we catch an additive overflow during path count |
2389 // merging. | 2387 // merging. |
2390 if (!NewRetainReleaseRRI.Calls.count(NewRetain)) | 2388 if (!NewRetainReleaseRRI.Calls.count(NewRetain)) |
2391 return false; | 2389 return false; |
2392 | 2390 |
2393 if (ReleasesToMove.Calls.insert(NewRetainRelease)) { | 2391 if (ReleasesToMove.Calls.insert(NewRetainRelease).second) { |
2394 | 2392 |
2395 // If we overflow when we compute the path count, don't remove/move | 2393 // If we overflow when we compute the path count, don't remove/move |
2396 // anything. | 2394 // anything. |
2397 const BBState &NRRBBState = BBStates[NewRetainRelease->getParent()]; | 2395 const BBState &NRRBBState = BBStates[NewRetainRelease->getParent()]; |
2398 unsigned PathCount = BBState::OverflowOccurredValue; | 2396 unsigned PathCount = BBState::OverflowOccurredValue; |
2420 } | 2418 } |
2421 | 2419 |
2422 // Collect the optimal insertion points. | 2420 // Collect the optimal insertion points. |
2423 if (!KnownSafe) | 2421 if (!KnownSafe) |
2424 for (Instruction *RIP : NewRetainReleaseRRI.ReverseInsertPts) { | 2422 for (Instruction *RIP : NewRetainReleaseRRI.ReverseInsertPts) { |
2425 if (ReleasesToMove.ReverseInsertPts.insert(RIP)) { | 2423 if (ReleasesToMove.ReverseInsertPts.insert(RIP).second) { |
2426 // If we overflow when we compute the path count, don't | 2424 // If we overflow when we compute the path count, don't |
2427 // remove/move anything. | 2425 // remove/move anything. |
2428 const BBState &RIPBBState = BBStates[RIP->getParent()]; | 2426 const BBState &RIPBBState = BBStates[RIP->getParent()]; |
2429 PathCount = BBState::OverflowOccurredValue; | 2427 PathCount = BBState::OverflowOccurredValue; |
2430 if (RIPBBState.GetAllPathCountWithOverflow(PathCount)) | 2428 if (RIPBBState.GetAllPathCountWithOverflow(PathCount)) |
2465 // This can happen if we catch an additive overflow during path count | 2463 // This can happen if we catch an additive overflow during path count |
2466 // merging. | 2464 // merging. |
2467 if (!NewReleaseRetainRRI.Calls.count(NewRelease)) | 2465 if (!NewReleaseRetainRRI.Calls.count(NewRelease)) |
2468 return false; | 2466 return false; |
2469 | 2467 |
2470 if (RetainsToMove.Calls.insert(NewReleaseRetain)) { | 2468 if (RetainsToMove.Calls.insert(NewReleaseRetain).second) { |
2471 // If we overflow when we compute the path count, don't remove/move | 2469 // If we overflow when we compute the path count, don't remove/move |
2472 // anything. | 2470 // anything. |
2473 const BBState &NRRBBState = BBStates[NewReleaseRetain->getParent()]; | 2471 const BBState &NRRBBState = BBStates[NewReleaseRetain->getParent()]; |
2474 unsigned PathCount = BBState::OverflowOccurredValue; | 2472 unsigned PathCount = BBState::OverflowOccurredValue; |
2475 if (NRRBBState.GetAllPathCountWithOverflow(PathCount)) | 2473 if (NRRBBState.GetAllPathCountWithOverflow(PathCount)) |
2481 OldCount += PathCount; | 2479 OldCount += PathCount; |
2482 | 2480 |
2483 // Collect the optimal insertion points. | 2481 // Collect the optimal insertion points. |
2484 if (!KnownSafe) | 2482 if (!KnownSafe) |
2485 for (Instruction *RIP : NewReleaseRetainRRI.ReverseInsertPts) { | 2483 for (Instruction *RIP : NewReleaseRetainRRI.ReverseInsertPts) { |
2486 if (RetainsToMove.ReverseInsertPts.insert(RIP)) { | 2484 if (RetainsToMove.ReverseInsertPts.insert(RIP).second) { |
2487 // If we overflow when we compute the path count, don't | 2485 // If we overflow when we compute the path count, don't |
2488 // remove/move anything. | 2486 // remove/move anything. |
2489 const BBState &RIPBBState = BBStates[RIP->getParent()]; | 2487 const BBState &RIPBBState = BBStates[RIP->getParent()]; |
2490 | 2488 |
2491 PathCount = BBState::OverflowOccurredValue; | 2489 PathCount = BBState::OverflowOccurredValue; |