@@ -129,8 +129,6 @@ using BBPredicates = DenseMap<BasicBlock *, PredInfo>;
129
129
using PredMap = DenseMap<BasicBlock *, BBPredicates>;
130
130
using BB2BBMap = DenseMap<BasicBlock *, BasicBlock *>;
131
131
132
- using BranchDebugLocMap = DenseMap<BasicBlock *, DebugLoc>;
133
-
134
132
// A traits type that is intended to be used in graph algorithms. The graph
135
133
// traits starts at an entry node, and traverses the RegionNodes that are in
136
134
// the Nodes set.
@@ -303,8 +301,6 @@ class StructurizeCFG {
303
301
PredMap LoopPreds;
304
302
BranchVector LoopConds;
305
303
306
- BranchDebugLocMap TermDL;
307
-
308
304
RegionNode *PrevNode;
309
305
310
306
void orderNodes ();
@@ -336,14 +332,14 @@ class StructurizeCFG {
336
332
337
333
void simplifyAffectedPhis ();
338
334
339
- void killTerminator (BasicBlock *BB);
335
+ DebugLoc killTerminator (BasicBlock *BB);
340
336
341
337
void changeExit (RegionNode *Node, BasicBlock *NewExit,
342
338
bool IncludeDominator);
343
339
344
340
BasicBlock *getNextFlow (BasicBlock *Dominator);
345
341
346
- BasicBlock *needPrefix (bool NeedEmpty);
342
+ std::pair< BasicBlock *, DebugLoc> needPrefix (bool NeedEmpty);
347
343
348
344
BasicBlock *needPostfix (BasicBlock *Flow, bool ExitUseAllowed);
349
345
@@ -361,8 +357,6 @@ class StructurizeCFG {
361
357
362
358
void rebuildSSA ();
363
359
364
- void setDebugLoc (BranchInst *Br, BasicBlock *BB);
365
-
366
360
public:
367
361
void init (Region *R);
368
362
bool run (Region *R, DominatorTree *DT);
@@ -918,28 +912,18 @@ void StructurizeCFG::simplifyAffectedPhis() {
918
912
} while (Changed);
919
913
}
920
914
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
-
930
915
// / Remove phi values from all successors and then remove the terminator.
931
- void StructurizeCFG::killTerminator (BasicBlock *BB) {
916
+ DebugLoc StructurizeCFG::killTerminator (BasicBlock *BB) {
932
917
Instruction *Term = BB->getTerminator ();
933
918
if (!Term)
934
- return ;
935
-
936
- if (const DebugLoc &DL = Term->getDebugLoc ())
937
- TermDL[BB] = DL;
919
+ return DebugLoc ();
938
920
939
921
for (BasicBlock *Succ : successors (BB))
940
922
delPhiValues (BB, Succ);
941
923
924
+ DebugLoc DL = Term->getDebugLoc ();
942
925
Term->eraseFromParent ();
926
+ return DL;
943
927
}
944
928
945
929
// / Let node exit(s) point to NewExit
@@ -978,9 +962,9 @@ void StructurizeCFG::changeExit(RegionNode *Node, BasicBlock *NewExit,
978
962
SubRegion->replaceExit (NewExit);
979
963
} else {
980
964
BasicBlock *BB = Node->getNodeAs <BasicBlock>();
981
- killTerminator (BB);
965
+ DebugLoc DL = killTerminator (BB);
982
966
BranchInst *Br = BranchInst::Create (NewExit, BB);
983
- setDebugLoc (Br, BB );
967
+ Br-> setDebugLoc (DL );
984
968
addPhiValues (BB, NewExit);
985
969
if (IncludeDominator)
986
970
DT->changeImmediateDominator (NewExit, BB);
@@ -995,29 +979,20 @@ BasicBlock *StructurizeCFG::getNextFlow(BasicBlock *Dominator) {
995
979
BasicBlock *Flow = BasicBlock::Create (Context, FlowBlockName,
996
980
Func, Insert);
997
981
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
-
1008
982
DT->addNewBlock (Flow, Dominator);
1009
983
ParentRegion->getRegionInfo ()->setRegionFor (Flow, ParentRegion);
1010
984
return Flow;
1011
985
}
1012
986
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) {
1015
990
BasicBlock *Entry = PrevNode->getEntry ();
1016
991
1017
992
if (!PrevNode->isSubRegion ()) {
1018
- killTerminator (Entry);
993
+ DebugLoc DL = killTerminator (Entry);
1019
994
if (!NeedEmpty || Entry->getFirstInsertionPt () == Entry->end ())
1020
- return Entry;
995
+ return { Entry, DL} ;
1021
996
}
1022
997
1023
998
// create a new flow node
@@ -1026,7 +1001,7 @@ BasicBlock *StructurizeCFG::needPrefix(bool NeedEmpty) {
1026
1001
// and wire it up
1027
1002
changeExit (PrevNode, Flow, true );
1028
1003
PrevNode = ParentRegion->getBBNode (Flow);
1029
- return Flow;
1004
+ return { Flow, DebugLoc ()} ;
1030
1005
}
1031
1006
1032
1007
// / Returns the region exit if possible, otherwise just a new flow node
@@ -1090,15 +1065,15 @@ void StructurizeCFG::wireFlow(bool ExitUseAllowed,
1090
1065
PrevNode = Node;
1091
1066
} else {
1092
1067
// Insert extra prefix node (or reuse last one)
1093
- BasicBlock * Flow = needPrefix (false );
1068
+ auto [ Flow, DL] = needPrefix (false );
1094
1069
1095
1070
// Insert extra postfix node (or use exit instead)
1096
1071
BasicBlock *Entry = Node->getEntry ();
1097
1072
BasicBlock *Next = needPostfix (Flow, ExitUseAllowed);
1098
1073
1099
1074
// let it point to entry and next block
1100
1075
BranchInst *Br = BranchInst::Create (Entry, Next, BoolPoison, Flow);
1101
- setDebugLoc (Br, Flow );
1076
+ Br-> setDebugLoc (DL );
1102
1077
Conditions.push_back (Br);
1103
1078
addPhiValues (Flow, Entry);
1104
1079
DT->changeImmediateDominator (Entry, Flow);
@@ -1125,7 +1100,7 @@ void StructurizeCFG::handleLoops(bool ExitUseAllowed,
1125
1100
}
1126
1101
1127
1102
if (!isPredictableTrue (Node))
1128
- LoopStart = needPrefix (true );
1103
+ LoopStart = needPrefix (true ). first ;
1129
1104
1130
1105
LoopEnd = Loops[Node->getEntry ()];
1131
1106
wireFlow (false , LoopEnd);
@@ -1136,10 +1111,11 @@ void StructurizeCFG::handleLoops(bool ExitUseAllowed,
1136
1111
assert (LoopStart != &LoopStart->getParent ()->getEntryBlock ());
1137
1112
1138
1113
// Create an extra loop end node
1139
- LoopEnd = needPrefix (false );
1114
+ DebugLoc DL;
1115
+ std::tie (LoopEnd, DL) = needPrefix (false );
1140
1116
BasicBlock *Next = needPostfix (LoopEnd, ExitUseAllowed);
1141
1117
BranchInst *Br = BranchInst::Create (Next, LoopStart, BoolPoison, LoopEnd);
1142
- setDebugLoc (Br, LoopEnd );
1118
+ Br-> setDebugLoc (DL );
1143
1119
LoopConds.push_back (Br);
1144
1120
addPhiValues (LoopEnd, LoopStart);
1145
1121
setPrevNode (Next);
@@ -1339,7 +1315,6 @@ bool StructurizeCFG::run(Region *R, DominatorTree *DT) {
1339
1315
LoopPreds.clear ();
1340
1316
LoopConds.clear ();
1341
1317
FlowSet.clear ();
1342
- TermDL.clear ();
1343
1318
1344
1319
return true ;
1345
1320
}
0 commit comments