Coverage Report

Created: 2019-02-21 13:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Analysis/SparsePropagation.h
Line
Count
Source (jump to first uncovered line)
1
//===- SparsePropagation.h - Sparse Conditional Property Propagation ------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements an abstract sparse conditional propagation algorithm,
10
// modeled after SCCP, but with a customizable lattice function.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_ANALYSIS_SPARSEPROPAGATION_H
15
#define LLVM_ANALYSIS_SPARSEPROPAGATION_H
16
17
#include "llvm/IR/Instructions.h"
18
#include "llvm/Support/Debug.h"
19
#include <set>
20
21
#define DEBUG_TYPE "sparseprop"
22
23
namespace llvm {
24
25
/// A template for translating between LLVM Values and LatticeKeys. Clients must
26
/// provide a specialization of LatticeKeyInfo for their LatticeKey type.
27
template <class LatticeKey> struct LatticeKeyInfo {
28
  // static inline Value *getValueFromLatticeKey(LatticeKey Key);
29
  // static inline LatticeKey getLatticeKeyFromValue(Value *V);
30
};
31
32
template <class LatticeKey, class LatticeVal,
33
          class KeyInfo = LatticeKeyInfo<LatticeKey>>
34
class SparseSolver;
35
36
/// AbstractLatticeFunction - This class is implemented by the dataflow instance
37
/// to specify what the lattice values are and how they handle merges etc.  This
38
/// gives the client the power to compute lattice values from instructions,
39
/// constants, etc.  The current requirement is that lattice values must be
40
/// copyable.  At the moment, nothing tries to avoid copying.  Additionally,
41
/// lattice keys must be able to be used as keys of a mapping data structure.
42
/// Internally, the generic solver currently uses a DenseMap to map lattice keys
43
/// to lattice values.  If the lattice key is a non-standard type, a
44
/// specialization of DenseMapInfo must be provided.
45
template <class LatticeKey, class LatticeVal> class AbstractLatticeFunction {
46
private:
47
  LatticeVal UndefVal, OverdefinedVal, UntrackedVal;
48
49
public:
50
  AbstractLatticeFunction(LatticeVal undefVal, LatticeVal overdefinedVal,
51
13.2k
                          LatticeVal untrackedVal) {
52
13.2k
    UndefVal = undefVal;
53
13.2k
    OverdefinedVal = overdefinedVal;
54
13.2k
    UntrackedVal = untrackedVal;
55
13.2k
  }
56
57
13.2k
  virtual ~AbstractLatticeFunction() = default;
58
59
1.42M
  LatticeVal getUndefVal()       const { return UndefVal; }
60
26.8M
  LatticeVal getOverdefinedVal() const { return OverdefinedVal; }
61
19.3M
  LatticeVal getUntrackedVal()   const { return UntrackedVal; }
62
63
  /// IsUntrackedValue - If the specified LatticeKey is obviously uninteresting
64
  /// to the analysis (i.e., it would always return UntrackedVal), this
65
  /// function can return true to avoid pointless work.
66
1.75M
  virtual bool IsUntrackedValue(LatticeKey Key) { return false; }
67
68
  /// ComputeLatticeVal - Compute and return a LatticeVal corresponding to the
69
  /// given LatticeKey.
70
0
  virtual LatticeVal ComputeLatticeVal(LatticeKey Key) {
71
0
    return getOverdefinedVal();
72
0
  }
73
74
  /// IsSpecialCasedPHI - Given a PHI node, determine whether this PHI node is
75
  /// one that the we want to handle through ComputeInstructionState.
76
2.13M
  virtual bool IsSpecialCasedPHI(PHINode *PN) { return false; }
77
78
  /// MergeValues - Compute and return the merge of the two specified lattice
79
  /// values.  Merging should only move one direction down the lattice to
80
  /// guarantee convergence (toward overdefined).
81
0
  virtual LatticeVal MergeValues(LatticeVal X, LatticeVal Y) {
82
0
    return getOverdefinedVal(); // always safe, never useful.
83
0
  }
84
85
  /// ComputeInstructionState - Compute the LatticeKeys that change as a result
86
  /// of executing instruction \p I. Their associated LatticeVals are store in
87
  /// \p ChangedValues.
88
  virtual void
89
  ComputeInstructionState(Instruction &I,
90
                          DenseMap<LatticeKey, LatticeVal> &ChangedValues,
91
                          SparseSolver<LatticeKey, LatticeVal> &SS) = 0;
92
93
  /// PrintLatticeVal - Render the given LatticeVal to the specified stream.
94
  virtual void PrintLatticeVal(LatticeVal LV, raw_ostream &OS);
95
96
  /// PrintLatticeKey - Render the given LatticeKey to the specified stream.
97
  virtual void PrintLatticeKey(LatticeKey Key, raw_ostream &OS);
98
99
  /// GetValueFromLatticeVal - If the given LatticeVal is representable as an
100
  /// LLVM value, return it; otherwise, return nullptr. If a type is given, the
101
  /// returned value must have the same type. This function is used by the
102
  /// generic solver in attempting to resolve branch and switch conditions.
103
0
  virtual Value *GetValueFromLatticeVal(LatticeVal LV, Type *Ty = nullptr) {
104
0
    return nullptr;
105
0
  }
106
};
107
108
/// SparseSolver - This class is a general purpose solver for Sparse Conditional
109
/// Propagation with a programmable lattice function.
110
template <class LatticeKey, class LatticeVal, class KeyInfo>
111
class SparseSolver {
112
113
  /// LatticeFunc - This is the object that knows the lattice and how to
114
  /// compute transfer functions.
115
  AbstractLatticeFunction<LatticeKey, LatticeVal> *LatticeFunc;
116
117
  /// ValueState - Holds the LatticeVals associated with LatticeKeys.
118
  DenseMap<LatticeKey, LatticeVal> ValueState;
119
120
  /// BBExecutable - Holds the basic blocks that are executable.
121
  SmallPtrSet<BasicBlock *, 16> BBExecutable;
122
123
  /// ValueWorkList - Holds values that should be processed.
124
  SmallVector<Value *, 64> ValueWorkList;
125
126
  /// BBWorkList - Holds basic blocks that should be processed.
127
  SmallVector<BasicBlock *, 64> BBWorkList;
128
129
  using Edge = std::pair<BasicBlock *, BasicBlock *>;
130
131
  /// KnownFeasibleEdges - Entries in this set are edges which have already had
132
  /// PHI nodes retriggered.
133
  std::set<Edge> KnownFeasibleEdges;
134
135
public:
136
  explicit SparseSolver(
137
      AbstractLatticeFunction<LatticeKey, LatticeVal> *Lattice)
138
13.2k
      : LatticeFunc(Lattice) {}
139
  SparseSolver(const SparseSolver &) = delete;
140
  SparseSolver &operator=(const SparseSolver &) = delete;
141
142
  /// Solve - Solve for constants and executable blocks.
143
  void Solve();
144
145
  void Print(raw_ostream &OS) const;
146
147
  /// getExistingValueState - Return the LatticeVal object corresponding to the
148
  /// given value from the ValueState map. If the value is not in the map,
149
  /// UntrackedVal is returned, unlike the getValueState method.
150
66.6k
  LatticeVal getExistingValueState(LatticeKey Key) const {
151
66.6k
    auto I = ValueState.find(Key);
152
66.6k
    return I != ValueState.end() ? 
I->second54.3k
:
LatticeFunc->getUntrackedVal()12.2k
;
153
66.6k
  }
154
155
  /// getValueState - Return the LatticeVal object corresponding to the given
156
  /// value from the ValueState map. If the value is not in the map, its state
157
  /// is initialized.
158
  LatticeVal getValueState(LatticeKey Key);
159
160
  /// isEdgeFeasible - Return true if the control flow edge from the 'From'
161
  /// basic block to the 'To' basic block is currently feasible.  If
162
  /// AggressiveUndef is true, then this treats values with unknown lattice
163
  /// values as undefined.  This is generally only useful when solving the
164
  /// lattice, not when querying it.
165
  bool isEdgeFeasible(BasicBlock *From, BasicBlock *To,
166
                      bool AggressiveUndef = false);
167
168
  /// isBlockExecutable - Return true if there are any known feasible
169
  /// edges into the basic block.  This is generally only useful when
170
  /// querying the lattice.
171
  bool isBlockExecutable(BasicBlock *BB) const {
172
    return BBExecutable.count(BB);
173
  }
174
175
  /// MarkBlockExecutable - This method can be used by clients to mark all of
176
  /// the blocks that are known to be intrinsically live in the processed unit.
177
  void MarkBlockExecutable(BasicBlock *BB);
178
179
private:
180
  /// UpdateState - When the state of some LatticeKey is potentially updated to
181
  /// the given LatticeVal, this function notices and adds the LLVM value
182
  /// corresponding the key to the work list, if needed.
183
  void UpdateState(LatticeKey Key, LatticeVal LV);
184
185
  /// markEdgeExecutable - Mark a basic block as executable, adding it to the BB
186
  /// work list if it is not already executable.
187
  void markEdgeExecutable(BasicBlock *Source, BasicBlock *Dest);
188
189
  /// getFeasibleSuccessors - Return a vector of booleans to indicate which
190
  /// successors are reachable from a given terminator instruction.
191
  void getFeasibleSuccessors(Instruction &TI, SmallVectorImpl<bool> &Succs,
192
                             bool AggressiveUndef);
193
194
  void visitInst(Instruction &I);
195
  void visitPHINode(PHINode &I);
196
  void visitTerminator(Instruction &TI);
197
};
198
199
//===----------------------------------------------------------------------===//
200
//                  AbstractLatticeFunction Implementation
201
//===----------------------------------------------------------------------===//
202
203
template <class LatticeKey, class LatticeVal>
204
void AbstractLatticeFunction<LatticeKey, LatticeVal>::PrintLatticeVal(
205
0
    LatticeVal V, raw_ostream &OS) {
206
0
  if (V == UndefVal)
207
0
    OS << "undefined";
208
0
  else if (V == OverdefinedVal)
209
0
    OS << "overdefined";
210
0
  else if (V == UntrackedVal)
211
0
    OS << "untracked";
212
0
  else
213
0
    OS << "unknown lattice value";
214
0
}
215
216
template <class LatticeKey, class LatticeVal>
217
void AbstractLatticeFunction<LatticeKey, LatticeVal>::PrintLatticeKey(
218
0
    LatticeKey Key, raw_ostream &OS) {
219
0
  OS << "unknown lattice key";
220
0
}
221
222
//===----------------------------------------------------------------------===//
223
//                          SparseSolver Implementation
224
//===----------------------------------------------------------------------===//
225
226
template <class LatticeKey, class LatticeVal, class KeyInfo>
227
LatticeVal
228
10.8M
SparseSolver<LatticeKey, LatticeVal, KeyInfo>::getValueState(LatticeKey Key) {
229
10.8M
  auto I = ValueState.find(Key);
230
10.8M
  if (I != ValueState.end())
231
9.04M
    return I->second; // Common case, in the map
232
1.75M
233
1.75M
  if (LatticeFunc->IsUntrackedValue(Key))
234
0
    return LatticeFunc->getUntrackedVal();
235
1.75M
  LatticeVal LV = LatticeFunc->ComputeLatticeVal(Key);
236
1.75M
237
1.75M
  // If this value is untracked, don't add it to the map.
238
1.75M
  if (LV == LatticeFunc->getUntrackedVal())
239
0
    return LV;
240
1.75M
  return ValueState[Key] = std::move(LV);
241
1.75M
}
242
243
template <class LatticeKey, class LatticeVal, class KeyInfo>
244
void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::UpdateState(LatticeKey Key,
245
17.4M
                                                                LatticeVal LV) {
246
17.4M
  auto I = ValueState.find(Key);
247
17.4M
  if (I != ValueState.end() && 
I->second == LV10.4M
)
248
9.36M
    return; // No change.
249
8.11M
250
8.11M
  // Update the state of the given LatticeKey and add its corresponding LLVM
251
8.11M
  // value to the work list.
252
8.11M
  ValueState[Key] = std::move(LV);
253
8.11M
  if (Value *V = KeyInfo::getValueFromLatticeKey(Key))
254
8.11M
    ValueWorkList.push_back(V);
255
8.11M
}
256
257
template <class LatticeKey, class LatticeVal, class KeyInfo>
258
void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::MarkBlockExecutable(
259
2.80M
    BasicBlock *BB) {
260
2.80M
  if (!BBExecutable.insert(BB).second)
261
418k
    return;
262
2.39M
  LLVM_DEBUG(dbgs() << "Marking Block Executable: " << BB->getName() << "\n");
263
2.39M
  BBWorkList.push_back(BB); // Add the block to the work list!
264
2.39M
}
265
266
template <class LatticeKey, class LatticeVal, class KeyInfo>
267
void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::markEdgeExecutable(
268
4.85M
    BasicBlock *Source, BasicBlock *Dest) {
269
4.85M
  if (!KnownFeasibleEdges.insert(Edge(Source, Dest)).second)
270
2.04M
    return; // This edge is already known to be executable!
271
2.80M
272
2.80M
  LLVM_DEBUG(dbgs() << "Marking Edge Executable: " << Source->getName()
273
2.80M
                    << " -> " << Dest->getName() << "\n");
274
2.80M
275
2.80M
  if (BBExecutable.count(Dest)) {
276
991k
    // The destination is already executable, but we just made an edge
277
991k
    // feasible that wasn't before.  Revisit the PHI nodes in the block
278
991k
    // because they have potentially new operands.
279
1.74M
    for (BasicBlock::iterator I = Dest->begin(); isa<PHINode>(I); 
++I756k
)
280
756k
      visitPHINode(*cast<PHINode>(I));
281
1.80M
  } else {
282
1.80M
    MarkBlockExecutable(Dest);
283
1.80M
  }
284
2.80M
}
285
286
template <class LatticeKey, class LatticeVal, class KeyInfo>
287
void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::getFeasibleSuccessors(
288
4.49M
    Instruction &TI, SmallVectorImpl<bool> &Succs, bool AggressiveUndef) {
289
4.49M
  Succs.resize(TI.getNumSuccessors());
290
4.49M
  if (TI.getNumSuccessors() == 0)
291
939k
    return;
292
3.56M
293
3.56M
  if (BranchInst *BI = dyn_cast<BranchInst>(&TI)) {
294
3.45M
    if (BI->isUnconditional()) {
295
1.19M
      Succs[0] = true;
296
1.19M
      return;
297
1.19M
    }
298
2.26M
299
2.26M
    LatticeVal BCValue;
300
2.26M
    if (AggressiveUndef)
301
2.26M
      BCValue =
302
2.26M
          getValueState(KeyInfo::getLatticeKeyFromValue(BI->getCondition()));
303
0
    else
304
0
      BCValue = getExistingValueState(
305
0
          KeyInfo::getLatticeKeyFromValue(BI->getCondition()));
306
2.26M
307
2.26M
    if (BCValue == LatticeFunc->getOverdefinedVal() ||
308
2.26M
        
BCValue == LatticeFunc->getUntrackedVal()140k
) {
309
2.11M
      // Overdefined condition variables can branch either way.
310
2.11M
      Succs[0] = Succs[1] = true;
311
2.11M
      return;
312
2.11M
    }
313
140k
314
140k
    // If undefined, neither is feasible yet.
315
140k
    if (BCValue == LatticeFunc->getUndefVal())
316
140k
      return;
317
0
318
0
    Constant *C =
319
0
        dyn_cast_or_null<Constant>(LatticeFunc->GetValueFromLatticeVal(
320
0
            std::move(BCValue), BI->getCondition()->getType()));
321
0
    if (!C || !isa<ConstantInt>(C)) {
322
0
      // Non-constant values can go either way.
323
0
      Succs[0] = Succs[1] = true;
324
0
      return;
325
0
    }
326
0
327
0
    // Constant condition variables mean the branch can only go a single way
328
0
    Succs[C->isNullValue()] = true;
329
0
    return;
330
0
  }
331
102k
332
102k
  if (TI.isExceptionalTerminator() ||
333
102k
      
TI.isIndirectTerminator()29.9k
) {
334
72.8k
    Succs.assign(Succs.size(), true);
335
72.8k
    return;
336
72.8k
  }
337
29.9k
338
29.9k
  SwitchInst &SI = cast<SwitchInst>(TI);
339
29.9k
  LatticeVal SCValue;
340
29.9k
  if (AggressiveUndef)
341
29.9k
    SCValue = getValueState(KeyInfo::getLatticeKeyFromValue(SI.getCondition()));
342
1
  else
343
1
    SCValue = getExistingValueState(
344
1
        KeyInfo::getLatticeKeyFromValue(SI.getCondition()));
345
29.9k
346
29.9k
  if (SCValue == LatticeFunc->getOverdefinedVal() ||
347
29.9k
      
SCValue == LatticeFunc->getUntrackedVal()988
) {
348
29.0k
    // All destinations are executable!
349
29.0k
    Succs.assign(TI.getNumSuccessors(), true);
350
29.0k
    return;
351
29.0k
  }
352
989
353
989
  // If undefined, neither is feasible yet.
354
989
  if (SCValue == LatticeFunc->getUndefVal())
355
988
    return;
356
1
357
1
  Constant *C = dyn_cast_or_null<Constant>(LatticeFunc->GetValueFromLatticeVal(
358
1
      std::move(SCValue), SI.getCondition()->getType()));
359
1
  if (!C || 
!isa<ConstantInt>(C)0
) {
360
0
    // All destinations are executable!
361
0
    Succs.assign(TI.getNumSuccessors(), true);
362
0
    return;
363
0
  }
364
1
  SwitchInst::CaseHandle Case = *SI.findCaseValue(cast<ConstantInt>(C));
365
1
  Succs[Case.getSuccessorIndex()] = true;
366
1
}
367
368
template <class LatticeKey, class LatticeVal, class KeyInfo>
369
bool SparseSolver<LatticeKey, LatticeVal, KeyInfo>::isEdgeFeasible(
370
774k
    BasicBlock *From, BasicBlock *To, bool AggressiveUndef) {
371
774k
  SmallVector<bool, 16> SuccFeasible;
372
774k
  Instruction *TI = From->getTerminator();
373
774k
  getFeasibleSuccessors(*TI, SuccFeasible, AggressiveUndef);
374
774k
375
1.18M
  for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; 
++i409k
)
376
1.04M
    if (TI->getSuccessor(i) == To && 
SuccFeasible[i]774k
)
377
634k
      return true;
378
774k
379
774k
  
return false140k
;
380
774k
}
381
382
template <class LatticeKey, class LatticeVal, class KeyInfo>
383
void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::visitTerminator(
384
3.72M
    Instruction &TI) {
385
3.72M
  SmallVector<bool, 16> SuccFeasible;
386
3.72M
  getFeasibleSuccessors(TI, SuccFeasible, true);
387
3.72M
388
3.72M
  BasicBlock *BB = TI.getParent();
389
3.72M
390
3.72M
  // Mark all feasible successors executable...
391
8.57M
  for (unsigned i = 0, e = SuccFeasible.size(); i != e; 
++i4.85M
)
392
4.85M
    if (SuccFeasible[i])
393
4.85M
      markEdgeExecutable(BB, TI.getSuccessor(i));
394
3.72M
}
395
396
template <class LatticeKey, class LatticeVal, class KeyInfo>
397
2.13M
void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::visitPHINode(PHINode &PN) {
398
2.13M
  // The lattice function may store more information on a PHINode than could be
399
2.13M
  // computed from its incoming values.  For example, SSI form stores its sigma
400
2.13M
  // functions as PHINodes with a single incoming value.
401
2.13M
  if (LatticeFunc->IsSpecialCasedPHI(&PN)) {
402
0
    DenseMap<LatticeKey, LatticeVal> ChangedValues;
403
0
    LatticeFunc->ComputeInstructionState(PN, ChangedValues, *this);
404
0
    for (auto &ChangedValue : ChangedValues)
405
0
      if (ChangedValue.second != LatticeFunc->getUntrackedVal())
406
0
        UpdateState(std::move(ChangedValue.first),
407
0
                    std::move(ChangedValue.second));
408
0
    return;
409
0
  }
410
2.13M
411
2.13M
  LatticeKey Key = KeyInfo::getLatticeKeyFromValue(&PN);
412
2.13M
  LatticeVal PNIV = getValueState(Key);
413
2.13M
  LatticeVal Overdefined = LatticeFunc->getOverdefinedVal();
414
2.13M
415
2.13M
  // If this value is already overdefined (common) just return.
416
2.13M
  if (PNIV == Overdefined || 
PNIV == LatticeFunc->getUntrackedVal()501k
)
417
1.63M
    return; // Quick exit
418
501k
419
501k
  // Super-extra-high-degree PHI nodes are unlikely to ever be interesting,
420
501k
  // and slow us down a lot.  Just mark them overdefined.
421
501k
  if (PN.getNumIncomingValues() > 64) {
422
24
    UpdateState(Key, Overdefined);
423
24
    return;
424
24
  }
425
501k
426
501k
  // Look at all of the executable operands of the PHI node.  If any of them
427
501k
  // are overdefined, the PHI becomes overdefined as well.  Otherwise, ask the
428
501k
  // transfer function to give us the merge of the incoming values.
429
787k
  
for (unsigned i = 0, e = PN.getNumIncomingValues(); 501k
i != e;
++i286k
) {
430
774k
    // If the edge is not yet known to be feasible, it doesn't impact the PHI.
431
774k
    if (!isEdgeFeasible(PN.getIncomingBlock(i), PN.getParent(), true))
432
140k
      continue;
433
634k
434
634k
    // Merge in this value.
435
634k
    LatticeVal OpVal =
436
634k
        getValueState(KeyInfo::getLatticeKeyFromValue(PN.getIncomingValue(i)));
437
634k
    if (OpVal != PNIV)
438
504k
      PNIV = LatticeFunc->MergeValues(PNIV, OpVal);
439
634k
440
634k
    if (PNIV == Overdefined)
441
488k
      break; // Rest of input values don't matter.
442
634k
  }
443
501k
444
501k
  // Update the PHI with the compute value, which is the merge of the inputs.
445
501k
  UpdateState(Key, PNIV);
446
501k
}
447
448
template <class LatticeKey, class LatticeVal, class KeyInfo>
449
24.3M
void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::visitInst(Instruction &I) {
450
24.3M
  // PHIs are handled by the propagation logic, they are never passed into the
451
24.3M
  // transfer functions.
452
24.3M
  if (PHINode *PN = dyn_cast<PHINode>(&I))
453
1.38M
    return visitPHINode(*PN);
454
22.9M
455
22.9M
  // Otherwise, ask the transfer function what the result is.  If this is
456
22.9M
  // something that we care about, remember it.
457
22.9M
  DenseMap<LatticeKey, LatticeVal> ChangedValues;
458
22.9M
  LatticeFunc->ComputeInstructionState(I, ChangedValues, *this);
459
22.9M
  for (auto &ChangedValue : ChangedValues)
460
16.9M
    if (ChangedValue.second != LatticeFunc->getUntrackedVal())
461
16.9M
      UpdateState(ChangedValue.first, ChangedValue.second);
462
22.9M
463
22.9M
  if (I.isTerminator())
464
3.72M
    visitTerminator(I);
465
22.9M
}
466
467
template <class LatticeKey, class LatticeVal, class KeyInfo>
468
13.2k
void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::Solve() {
469
13.2k
  // Process the work lists until they are empty!
470
37.1k
  while (!BBWorkList.empty() || 
!ValueWorkList.empty()25.2k
) {
471
23.9k
    // Process the value work list.
472
8.14M
    while (!ValueWorkList.empty()) {
473
8.11M
      Value *V = ValueWorkList.back();
474
8.11M
      ValueWorkList.pop_back();
475
8.11M
476
8.11M
      LLVM_DEBUG(dbgs() << "\nPopped off V-WL: " << *V << "\n");
477
8.11M
478
8.11M
      // "V" got into the work list because it made a transition. See if any
479
8.11M
      // users are both live and in need of updating.
480
8.11M
      for (User *U : V->users())
481
11.3M
        if (Instruction *Inst = dyn_cast<Instruction>(U))
482
11.3M
          if (BBExecutable.count(Inst->getParent())) // Inst is executable?
483
11.3M
            visitInst(*Inst);
484
8.11M
    }
485
23.9k
486
23.9k
    // Process the basic block work list.
487
2.41M
    while (!BBWorkList.empty()) {
488
2.39M
      BasicBlock *BB = BBWorkList.back();
489
2.39M
      BBWorkList.pop_back();
490
2.39M
491
2.39M
      LLVM_DEBUG(dbgs() << "\nPopped off BBWL: " << *BB);
492
2.39M
493
2.39M
      // Notify all instructions in this basic block that they are newly
494
2.39M
      // executable.
495
2.39M
      for (Instruction &I : *BB)
496
12.9M
        visitInst(I);
497
2.39M
    }
498
23.9k
  }
499
13.2k
}
500
501
template <class LatticeKey, class LatticeVal, class KeyInfo>
502
void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::Print(
503
    raw_ostream &OS) const {
504
  if (ValueState.empty())
505
    return;
506
507
  LatticeKey Key;
508
  LatticeVal LV;
509
510
  OS << "ValueState:\n";
511
  for (auto &Entry : ValueState) {
512
    std::tie(Key, LV) = Entry;
513
    if (LV == LatticeFunc->getUntrackedVal())
514
      continue;
515
    OS << "\t";
516
    LatticeFunc->PrintLatticeVal(LV, OS);
517
    OS << ": ";
518
    LatticeFunc->PrintLatticeKey(Key, OS);
519
    OS << "\n";
520
  }
521
}
522
} // end namespace llvm
523
524
#undef DEBUG_TYPE
525
526
#endif // LLVM_ANALYSIS_SPARSEPROPAGATION_H