@@ -42,34 +42,23 @@ void DbgSSAPhi::print(raw_ostream &OS) const {
42
42
43
43
using AvailableValsTy = DenseMap<DbgSSABlock *, DbgValueDef>;
44
44
45
- static AvailableValsTy &getAvailableVals (void *AV) {
46
- return *static_cast <AvailableValsTy *>(AV);
47
- }
48
-
49
45
DebugSSAUpdater::DebugSSAUpdater (SmallVectorImpl<DbgSSAPhi *> *NewPHI)
50
46
: InsertedPHIs(NewPHI) {}
51
47
52
- DebugSSAUpdater::~DebugSSAUpdater () {
53
- delete static_cast <AvailableValsTy *>(AV);
54
- }
55
-
56
48
void DebugSSAUpdater::initialize () {
57
- if (!AV)
58
- AV = new AvailableValsTy ();
59
- else
60
- getAvailableVals (AV).clear ();
49
+ AV.clear ();
61
50
}
62
51
63
52
bool DebugSSAUpdater::hasValueForBlock (DbgSSABlock *BB) const {
64
- return getAvailableVals (AV) .count (BB);
53
+ return AV .count (BB);
65
54
}
66
55
67
56
DbgValueDef DebugSSAUpdater::findValueForBlock (DbgSSABlock *BB) const {
68
- return getAvailableVals (AV) .lookup (BB);
57
+ return AV .lookup (BB);
69
58
}
70
59
71
60
void DebugSSAUpdater::addAvailableValue (DbgSSABlock *BB, DbgValueDef DV) {
72
- getAvailableVals (AV) [BB] = DV;
61
+ AV [BB] = DV;
73
62
}
74
63
75
64
DbgValueDef DebugSSAUpdater::getValueAtEndOfBlock (DbgSSABlock *BB) {
@@ -171,8 +160,8 @@ template <> class SSAUpdaterTraits<DebugSSAUpdater> {
171
160
static PHI_iterator PHI_begin (PhiT *PHI) { return PHI_iterator (PHI); }
172
161
static PHI_iterator PHI_end (PhiT *PHI) { return PHI_iterator (PHI, true ); }
173
162
174
- // / FindPredecessorBlocks - Put the predecessors of Info-> BB into the Preds
175
- // / vector, set Info->NumPreds, and allocate space in Info->Preds .
163
+ // / FindPredecessorBlocks - Put the predecessors of BB into the Preds
164
+ // / vector.
176
165
static void FindPredecessorBlocks (DbgSSABlock *BB,
177
166
SmallVectorImpl<DbgSSABlock *> *Preds) {
178
167
for (auto PredIt = BB->pred_begin (); PredIt != BB->pred_end (); ++PredIt)
@@ -185,8 +174,7 @@ template <> class SSAUpdaterTraits<DebugSSAUpdater> {
185
174
return DbgValueDef ();
186
175
}
187
176
188
- // / CreateEmptyPHI - Create a new PHI instruction in the specified block.
189
- // / Reserve space for the operands (?) but do not fill them in yet.
177
+ // / CreateEmptyPHI - Create a new debug PHI entry for the specified block.
190
178
static DbgSSAPhi *CreateEmptyPHI (DbgSSABlock *BB, unsigned NumPreds,
191
179
DebugSSAUpdater *Updater) {
192
180
DbgSSAPhi *PHI = BB->newPHI ();
@@ -225,11 +213,10 @@ template <> class SSAUpdaterTraits<DebugSSAUpdater> {
225
213
// / return it. If not, construct SSA form by first calculating the required
226
214
// / placement of PHIs and then inserting new PHIs where needed.
227
215
DbgValueDef DebugSSAUpdater::getValueAtEndOfBlockInternal (DbgSSABlock *BB) {
228
- AvailableValsTy &AvailableVals = getAvailableVals (AV);
229
- if (AvailableVals.contains (BB))
230
- return AvailableVals[BB];
216
+ if (AV.contains (BB))
217
+ return AV[BB];
231
218
232
- SSAUpdaterImpl<DebugSSAUpdater> Impl (this , &AvailableVals , InsertedPHIs);
219
+ SSAUpdaterImpl<DebugSSAUpdater> Impl (this , &AV , InsertedPHIs);
233
220
return Impl.GetValue (BB);
234
221
}
235
222
@@ -263,21 +250,13 @@ void DbgValueRangeTable::addVariable(Function *F, DebugVariableAggregate DVA) {
263
250
for (DbgVariableRecord &DVR : filterDbgVars (I.getDbgRecordRange ())) {
264
251
if (DVR.getVariable () == Var &&
265
252
DVR.getDebugLoc ().getInlinedAt () == InlinedAt) {
266
- assert (!DVR.isDbgAssign () && " No support for #dbg_declare yet." );
253
+ assert (!DVR.isDbgAssign () && " No support for #dbg_assign yet." );
267
254
if (DVR.isDbgDeclare ())
268
255
DeclareRecordFound = true ;
269
256
++NumRecordsFound;
270
257
LastRecordFound = &DVR;
271
258
DbgRecordValues.push_back (&DVR);
272
259
}
273
- if (!FoundInstructionInScope && I.getDebugLoc ()) {
274
- if (I.getDebugLoc ().getInlinedAt () == InlinedAt &&
275
- isContained (cast<DILocalScope>(I.getDebugLoc ().getScope ()),
276
- Var->getScope ())) {
277
- FoundInstructionInScope = true ;
278
- HasAnyInstructionsInScope.insert (&BB);
279
- }
280
- }
281
260
}
282
261
if (!FoundInstructionInScope && I.getDebugLoc ()) {
283
262
if (I.getDebugLoc ().getInlinedAt () == InlinedAt &&
@@ -312,7 +291,8 @@ void DbgValueRangeTable::addVariable(Function *F, DebugVariableAggregate DVA) {
312
291
return ;
313
292
}
314
293
315
- // We don't have a single location, so let's have fun with liveness.
294
+ // We don't have a single location for the variable's entire scope, so instead
295
+ // we must now perform a liveness analysis to create a location list.
316
296
DenseMap<BasicBlock *, DbgValueDef> LiveInMap;
317
297
SmallVector<DbgSSAPhi *> HypotheticalPHIs;
318
298
DebugSSAUpdater SSAUpdater (&HypotheticalPHIs);
@@ -395,21 +375,17 @@ void DbgValueRangeTable::printValues(DebugVariableAggregate DVA,
395
375
}
396
376
}
397
377
398
- uint64_t DbgValueRangeTable::addVariableName (Value *V, uint64_t Size) {
399
- uint64_t Key = 0 ;
400
- auto I = VariableMapping.find (V);
401
- if (I == VariableMapping.end ()) {
402
- Key = KeyIndex;
403
- VariableMapping.try_emplace (V, Key);
404
- std::string &ValueText = VariableNameMapping[Key];
405
- raw_string_ostream Stream (ValueText);
406
- Stream << " " ;
407
- V->printAsOperand (Stream, true );
408
- KeyIndex += Size;
409
- } else {
410
- Key = I->second ;
411
- }
412
- LLVM_DEBUG (dbgs () << " Stashing Value: " << Key << " - " << *V << " \n " );
413
-
414
- return Key;
378
+ SSAValueNameMap::ValueID SSAValueNameMap::addValue (Value *V) {
379
+ auto ExistingID = ValueToIDMap.find (V);
380
+ if (ExistingID != ValueToIDMap.end ())
381
+ return ExistingID->second ;
382
+ // First, get a new ID and Map V to it.
383
+ ValueID NewID = NextID++;
384
+ ValueToIDMap.insert ({V, NewID});
385
+ // Then, get the name string for V and map NewID to it.
386
+ assert (!ValueIDToNameMap.contains (NewID) && " New value ID already maps to a name?" );
387
+ std::string &ValueText = ValueIDToNameMap[NewID];
388
+ raw_string_ostream Stream (ValueText);
389
+ V->printAsOperand (Stream, true );
390
+ return NewID;
415
391
}
0 commit comments