@@ -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
@@ -361,8 +357,6 @@ class StructurizeCFG {
361357
362358 void rebuildSSA ();
363359
364- void setDebugLoc (BranchInst *Br, BasicBlock *BB);
365-
366360public:
367361 void init (Region *R);
368362 bool run (Region *R, DominatorTree *DT);
@@ -918,28 +912,18 @@ void StructurizeCFG::simplifyAffectedPhis() {
918912 } while (Changed);
919913}
920914
921- void StructurizeCFG::setDebugLoc (BranchInst *Br, BasicBlock *BB) {
922- auto I = TermDL.find (BB);
923- if (I == TermDL.end ())
924- return ;
925-
926- Br->setDebugLoc (I->second );
927- TermDL.erase (I);
928- }
929-
930915// / Remove phi values from all successors and then remove the terminator.
931- void StructurizeCFG::killTerminator (BasicBlock *BB) {
916+ DebugLoc StructurizeCFG::killTerminator (BasicBlock *BB) {
932917 Instruction *Term = BB->getTerminator ();
933918 if (!Term)
934- return ;
935-
936- if (const DebugLoc &DL = Term->getDebugLoc ())
937- TermDL[BB] = DL;
919+ return DebugLoc ();
938920
939921 for (BasicBlock *Succ : successors (BB))
940922 delPhiValues (BB, Succ);
941923
924+ DebugLoc DL = Term->getDebugLoc ();
942925 Term->eraseFromParent ();
926+ return DL;
943927}
944928
945929// / Let node exit(s) point to NewExit
@@ -978,9 +962,9 @@ void StructurizeCFG::changeExit(RegionNode *Node, BasicBlock *NewExit,
978962 SubRegion->replaceExit (NewExit);
979963 } else {
980964 BasicBlock *BB = Node->getNodeAs <BasicBlock>();
981- killTerminator (BB);
965+ DebugLoc DL = killTerminator (BB);
982966 BranchInst *Br = BranchInst::Create (NewExit, BB);
983- setDebugLoc (Br, BB );
967+ Br-> setDebugLoc (DL );
984968 addPhiValues (BB, NewExit);
985969 if (IncludeDominator)
986970 DT->changeImmediateDominator (NewExit, BB);
@@ -995,29 +979,20 @@ BasicBlock *StructurizeCFG::getNextFlow(BasicBlock *Dominator) {
995979 BasicBlock *Flow = BasicBlock::Create (Context, FlowBlockName,
996980 Func, Insert);
997981 FlowSet.insert (Flow);
998-
999- if (auto *Term = Dominator->getTerminator ()) {
1000- if (const DebugLoc &DL = Term->getDebugLoc ())
1001- TermDL[Flow] = DL;
1002- } else if (DebugLoc DLTemp = TermDL.lookup (Dominator)) {
1003- // Use a temporary copy to avoid a use-after-free if the map's storage
1004- // is reallocated.
1005- TermDL[Flow] = DLTemp;
1006- }
1007-
1008982 DT->addNewBlock (Flow, Dominator);
1009983 ParentRegion->getRegionInfo ()->setRegionFor (Flow, ParentRegion);
1010984 return Flow;
1011985}
1012986
1013- // / Create a new or reuse the previous node as flow node
1014- BasicBlock *StructurizeCFG::needPrefix (bool NeedEmpty) {
987+ // / Create a new or reuse the previous node as flow node. Returns a block and a
988+ // / debug location to be used for new instructions in that block.
989+ std::pair<BasicBlock *, DebugLoc> StructurizeCFG::needPrefix (bool NeedEmpty) {
1015990 BasicBlock *Entry = PrevNode->getEntry ();
1016991
1017992 if (!PrevNode->isSubRegion ()) {
1018- killTerminator (Entry);
993+ DebugLoc DL = killTerminator (Entry);
1019994 if (!NeedEmpty || Entry->getFirstInsertionPt () == Entry->end ())
1020- return Entry;
995+ return { Entry, DL} ;
1021996 }
1022997
1023998 // create a new flow node
@@ -1026,7 +1001,7 @@ BasicBlock *StructurizeCFG::needPrefix(bool NeedEmpty) {
10261001 // and wire it up
10271002 changeExit (PrevNode, Flow, true );
10281003 PrevNode = ParentRegion->getBBNode (Flow);
1029- return Flow;
1004+ return { Flow, DebugLoc ()} ;
10301005}
10311006
10321007// / Returns the region exit if possible, otherwise just a new flow node
@@ -1090,15 +1065,15 @@ void StructurizeCFG::wireFlow(bool ExitUseAllowed,
10901065 PrevNode = Node;
10911066 } else {
10921067 // Insert extra prefix node (or reuse last one)
1093- BasicBlock * Flow = needPrefix (false );
1068+ auto [ Flow, DL] = needPrefix (false );
10941069
10951070 // Insert extra postfix node (or use exit instead)
10961071 BasicBlock *Entry = Node->getEntry ();
10971072 BasicBlock *Next = needPostfix (Flow, ExitUseAllowed);
10981073
10991074 // let it point to entry and next block
11001075 BranchInst *Br = BranchInst::Create (Entry, Next, BoolPoison, Flow);
1101- setDebugLoc (Br, Flow );
1076+ Br-> setDebugLoc (DL );
11021077 Conditions.push_back (Br);
11031078 addPhiValues (Flow, Entry);
11041079 DT->changeImmediateDominator (Entry, Flow);
@@ -1125,7 +1100,7 @@ void StructurizeCFG::handleLoops(bool ExitUseAllowed,
11251100 }
11261101
11271102 if (!isPredictableTrue (Node))
1128- LoopStart = needPrefix (true );
1103+ LoopStart = needPrefix (true ). first ;
11291104
11301105 LoopEnd = Loops[Node->getEntry ()];
11311106 wireFlow (false , LoopEnd);
@@ -1136,10 +1111,11 @@ void StructurizeCFG::handleLoops(bool ExitUseAllowed,
11361111 assert (LoopStart != &LoopStart->getParent ()->getEntryBlock ());
11371112
11381113 // Create an extra loop end node
1139- LoopEnd = needPrefix (false );
1114+ DebugLoc DL;
1115+ std::tie (LoopEnd, DL) = needPrefix (false );
11401116 BasicBlock *Next = needPostfix (LoopEnd, ExitUseAllowed);
11411117 BranchInst *Br = BranchInst::Create (Next, LoopStart, BoolPoison, LoopEnd);
1142- setDebugLoc (Br, LoopEnd );
1118+ Br-> setDebugLoc (DL );
11431119 LoopConds.push_back (Br);
11441120 addPhiValues (LoopEnd, LoopStart);
11451121 setPrevNode (Next);
@@ -1339,7 +1315,6 @@ bool StructurizeCFG::run(Region *R, DominatorTree *DT) {
13391315 LoopPreds.clear ();
13401316 LoopConds.clear ();
13411317 FlowSet.clear ();
1342- TermDL.clear ();
13431318
13441319 return true ;
13451320}
0 commit comments