@@ -129,8 +129,6 @@ using BBPredicates = DenseMap<BasicBlock *, PredInfo>;
129129using PredMap = DenseMap<BasicBlock *, BBPredicates>;
130130using BB2BBMap = DenseMap<BasicBlock *, BasicBlock *>;
131131
132- using BranchDebugLocMap = DenseMap<BasicBlock *, DebugLoc>;
133-
134132// A traits type that is intended to be used in graph algorithms. The graph
135133// traits starts at an entry node, and traverses the RegionNodes that are in
136134// the Nodes set.
@@ -303,8 +301,6 @@ class StructurizeCFG {
303301 PredMap LoopPreds;
304302 BranchVector LoopConds;
305303
306- BranchDebugLocMap TermDL;
307-
308304 RegionNode *PrevNode;
309305
310306 void orderNodes ();
@@ -336,14 +332,14 @@ class StructurizeCFG {
336332
337333 void simplifyAffectedPhis ();
338334
339- void killTerminator (BasicBlock *BB);
335+ DebugLoc killTerminator (BasicBlock *BB);
340336
341337 void changeExit (RegionNode *Node, BasicBlock *NewExit,
342338 bool IncludeDominator);
343339
344340 BasicBlock *getNextFlow (BasicBlock *Dominator);
345341
346- BasicBlock *needPrefix (bool NeedEmpty);
342+ std::pair< BasicBlock *, DebugLoc> needPrefix (bool NeedEmpty);
347343
348344 BasicBlock *needPostfix (BasicBlock *Flow, bool ExitUseAllowed);
349345
@@ -595,14 +591,14 @@ void StructurizeCFG::collectInfos() {
595591 // Find the last back edges
596592 analyzeLoops (RN);
597593 }
598-
594+ /*
599595 // Reset the collected term debug locations
600596 TermDL.clear();
601597
602598 for (BasicBlock &BB : *Func) {
603599 if (const DebugLoc &DL = BB.getTerminator()->getDebugLoc())
604600 TermDL[&BB] = DL;
605- }
601+ } */
606602}
607603
608604// / Insert the missing branch conditions
@@ -924,15 +920,17 @@ void StructurizeCFG::simplifyAffectedPhis() {
924920}
925921
926922// / Remove phi values from all successors and then remove the terminator.
927- void StructurizeCFG::killTerminator (BasicBlock *BB) {
923+ DebugLoc StructurizeCFG::killTerminator (BasicBlock *BB) {
928924 Instruction *Term = BB->getTerminator ();
929925 if (!Term)
930- return ;
926+ return DebugLoc () ;
931927
932928 for (BasicBlock *Succ : successors (BB))
933929 delPhiValues (BB, Succ);
934930
931+ DebugLoc DL = Term->getDebugLoc ();
935932 Term->eraseFromParent ();
933+ return DL;
936934}
937935
938936// / Let node exit(s) point to NewExit
@@ -971,9 +969,9 @@ void StructurizeCFG::changeExit(RegionNode *Node, BasicBlock *NewExit,
971969 SubRegion->replaceExit (NewExit);
972970 } else {
973971 BasicBlock *BB = Node->getNodeAs <BasicBlock>();
974- killTerminator (BB);
972+ DebugLoc DL = killTerminator (BB);
975973 BranchInst *Br = BranchInst::Create (NewExit, BB);
976- Br->setDebugLoc (TermDL[BB] );
974+ Br->setDebugLoc (DL );
977975 addPhiValues (BB, NewExit);
978976 if (IncludeDominator)
979977 DT->changeImmediateDominator (NewExit, BB);
@@ -988,25 +986,20 @@ BasicBlock *StructurizeCFG::getNextFlow(BasicBlock *Dominator) {
988986 BasicBlock *Flow = BasicBlock::Create (Context, FlowBlockName,
989987 Func, Insert);
990988 FlowSet.insert (Flow);
991-
992- // use a temporary variable to avoid a use-after-free if the map's storage is
993- // reallocated
994- DebugLoc DL = TermDL[Dominator];
995- TermDL[Flow] = std::move (DL);
996-
997989 DT->addNewBlock (Flow, Dominator);
998990 ParentRegion->getRegionInfo ()->setRegionFor (Flow, ParentRegion);
999991 return Flow;
1000992}
1001993
1002- // / Create a new or reuse the previous node as flow node
1003- BasicBlock *StructurizeCFG::needPrefix (bool NeedEmpty) {
994+ // / Create a new or reuse the previous node as flow node. Returns a block and a
995+ // / debug location to be used for new instructions in that block.
996+ std::pair<BasicBlock *, DebugLoc> StructurizeCFG::needPrefix (bool NeedEmpty) {
1004997 BasicBlock *Entry = PrevNode->getEntry ();
1005998
1006999 if (!PrevNode->isSubRegion ()) {
1007- killTerminator (Entry);
1000+ DebugLoc DL = killTerminator (Entry);
10081001 if (!NeedEmpty || Entry->getFirstInsertionPt () == Entry->end ())
1009- return Entry;
1002+ return { Entry, DL} ;
10101003 }
10111004
10121005 // create a new flow node
@@ -1015,7 +1008,7 @@ BasicBlock *StructurizeCFG::needPrefix(bool NeedEmpty) {
10151008 // and wire it up
10161009 changeExit (PrevNode, Flow, true );
10171010 PrevNode = ParentRegion->getBBNode (Flow);
1018- return Flow;
1011+ return { Flow, DebugLoc ()} ;
10191012}
10201013
10211014// / Returns the region exit if possible, otherwise just a new flow node
@@ -1079,15 +1072,15 @@ void StructurizeCFG::wireFlow(bool ExitUseAllowed,
10791072 PrevNode = Node;
10801073 } else {
10811074 // Insert extra prefix node (or reuse last one)
1082- BasicBlock * Flow = needPrefix (false );
1075+ auto [ Flow, DL] = needPrefix (false );
10831076
10841077 // Insert extra postfix node (or use exit instead)
10851078 BasicBlock *Entry = Node->getEntry ();
10861079 BasicBlock *Next = needPostfix (Flow, ExitUseAllowed);
10871080
10881081 // let it point to entry and next block
10891082 BranchInst *Br = BranchInst::Create (Entry, Next, BoolPoison, Flow);
1090- Br->setDebugLoc (TermDL[Flow] );
1083+ Br->setDebugLoc (DL );
10911084 Conditions.push_back (Br);
10921085 addPhiValues (Flow, Entry);
10931086 DT->changeImmediateDominator (Entry, Flow);
@@ -1114,7 +1107,7 @@ void StructurizeCFG::handleLoops(bool ExitUseAllowed,
11141107 }
11151108
11161109 if (!isPredictableTrue (Node))
1117- LoopStart = needPrefix (true );
1110+ LoopStart = needPrefix (true ). first ;
11181111
11191112 LoopEnd = Loops[Node->getEntry ()];
11201113 wireFlow (false , LoopEnd);
@@ -1125,10 +1118,11 @@ void StructurizeCFG::handleLoops(bool ExitUseAllowed,
11251118 assert (LoopStart != &LoopStart->getParent ()->getEntryBlock ());
11261119
11271120 // Create an extra loop end node
1128- LoopEnd = needPrefix (false );
1121+ DebugLoc DL;
1122+ std::tie (LoopEnd, DL) = needPrefix (false );
11291123 BasicBlock *Next = needPostfix (LoopEnd, ExitUseAllowed);
11301124 BranchInst *Br = BranchInst::Create (Next, LoopStart, BoolPoison, LoopEnd);
1131- Br->setDebugLoc (TermDL[LoopEnd] );
1125+ Br->setDebugLoc (DL );
11321126 LoopConds.push_back (Br);
11331127 addPhiValues (LoopEnd, LoopStart);
11341128 setPrevNode (Next);
@@ -1328,7 +1322,6 @@ bool StructurizeCFG::run(Region *R, DominatorTree *DT) {
13281322 LoopPreds.clear ();
13291323 LoopConds.clear ();
13301324 FlowSet.clear ();
1331- TermDL.clear ();
13321325
13331326 return true ;
13341327}
0 commit comments