LLVM  8.0.1
SSAUpdater.cpp
Go to the documentation of this file.
1 //===- SSAUpdater.cpp - Unstructured SSA Update Tool ----------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the SSAUpdater class.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/TinyPtrVector.h"
20 #include "llvm/IR/BasicBlock.h"
21 #include "llvm/IR/CFG.h"
22 #include "llvm/IR/Constants.h"
23 #include "llvm/IR/DebugLoc.h"
24 #include "llvm/IR/Instruction.h"
25 #include "llvm/IR/Instructions.h"
26 #include "llvm/IR/Module.h"
27 #include "llvm/IR/Use.h"
28 #include "llvm/IR/Value.h"
29 #include "llvm/IR/ValueHandle.h"
30 #include "llvm/Support/Casting.h"
31 #include "llvm/Support/Debug.h"
34 #include <cassert>
35 #include <utility>
36 
37 using namespace llvm;
38 
39 #define DEBUG_TYPE "ssaupdater"
40 
42 
43 static AvailableValsTy &getAvailableVals(void *AV) {
44  return *static_cast<AvailableValsTy*>(AV);
45 }
46 
48  : InsertedPHIs(NewPHI) {}
49 
51  delete static_cast<AvailableValsTy*>(AV);
52 }
53 
55  if (!AV)
56  AV = new AvailableValsTy();
57  else
58  getAvailableVals(AV).clear();
59  ProtoType = Ty;
60  ProtoName = Name;
61 }
62 
64  return getAvailableVals(AV).count(BB);
65 }
66 
69  return (AVI != getAvailableVals(AV).end()) ? AVI->second : nullptr;
70 }
71 
73  assert(ProtoType && "Need to initialize SSAUpdater");
74  assert(ProtoType == V->getType() &&
75  "All rewritten values must have the same type");
76  getAvailableVals(AV)[BB] = V;
77 }
78 
79 static bool IsEquivalentPHI(PHINode *PHI,
81  unsigned PHINumValues = PHI->getNumIncomingValues();
82  if (PHINumValues != ValueMapping.size())
83  return false;
84 
85  // Scan the phi to see if it matches.
86  for (unsigned i = 0, e = PHINumValues; i != e; ++i)
87  if (ValueMapping[PHI->getIncomingBlock(i)] !=
88  PHI->getIncomingValue(i)) {
89  return false;
90  }
91 
92  return true;
93 }
94 
96  Value *Res = GetValueAtEndOfBlockInternal(BB);
97  return Res;
98 }
99 
101  // If there is no definition of the renamed variable in this block, just use
102  // GetValueAtEndOfBlock to do our work.
103  if (!HasValueForBlock(BB))
104  return GetValueAtEndOfBlock(BB);
105 
106  // Otherwise, we have the hard case. Get the live-in values for each
107  // predecessor.
109  Value *SingularValue = nullptr;
110 
111  // We can get our predecessor info by walking the pred_iterator list, but it
112  // is relatively slow. If we already have PHI nodes in this block, walk one
113  // of them to get the predecessor list instead.
114  if (PHINode *SomePhi = dyn_cast<PHINode>(BB->begin())) {
115  for (unsigned i = 0, e = SomePhi->getNumIncomingValues(); i != e; ++i) {
116  BasicBlock *PredBB = SomePhi->getIncomingBlock(i);
117  Value *PredVal = GetValueAtEndOfBlock(PredBB);
118  PredValues.push_back(std::make_pair(PredBB, PredVal));
119 
120  // Compute SingularValue.
121  if (i == 0)
122  SingularValue = PredVal;
123  else if (PredVal != SingularValue)
124  SingularValue = nullptr;
125  }
126  } else {
127  bool isFirstPred = true;
128  for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
129  BasicBlock *PredBB = *PI;
130  Value *PredVal = GetValueAtEndOfBlock(PredBB);
131  PredValues.push_back(std::make_pair(PredBB, PredVal));
132 
133  // Compute SingularValue.
134  if (isFirstPred) {
135  SingularValue = PredVal;
136  isFirstPred = false;
137  } else if (PredVal != SingularValue)
138  SingularValue = nullptr;
139  }
140  }
141 
142  // If there are no predecessors, just return undef.
143  if (PredValues.empty())
144  return UndefValue::get(ProtoType);
145 
146  // Otherwise, if all the merged values are the same, just use it.
147  if (SingularValue)
148  return SingularValue;
149 
150  // Otherwise, we do need a PHI: check to see if we already have one available
151  // in this block that produces the right value.
152  if (isa<PHINode>(BB->begin())) {
154  PredValues.end());
155  for (PHINode &SomePHI : BB->phis()) {
156  if (IsEquivalentPHI(&SomePHI, ValueMapping))
157  return &SomePHI;
158  }
159  }
160 
161  // Ok, we have no way out, insert a new one now.
162  PHINode *InsertedPHI = PHINode::Create(ProtoType, PredValues.size(),
163  ProtoName, &BB->front());
164 
165  // Fill in all the predecessors of the PHI.
166  for (const auto &PredValue : PredValues)
167  InsertedPHI->addIncoming(PredValue.second, PredValue.first);
168 
169  // See if the PHI node can be merged to a single value. This can happen in
170  // loop cases when we get a PHI of itself and one other value.
171  if (Value *V =
172  SimplifyInstruction(InsertedPHI, BB->getModule()->getDataLayout())) {
173  InsertedPHI->eraseFromParent();
174  return V;
175  }
176 
177  // Set the DebugLoc of the inserted PHI, if available.
178  DebugLoc DL;
179  if (const Instruction *I = BB->getFirstNonPHI())
180  DL = I->getDebugLoc();
181  InsertedPHI->setDebugLoc(DL);
182 
183  // If the client wants to know about all new instructions, tell it.
184  if (InsertedPHIs) InsertedPHIs->push_back(InsertedPHI);
185 
186  LLVM_DEBUG(dbgs() << " Inserted PHI: " << *InsertedPHI << "\n");
187  return InsertedPHI;
188 }
189 
191  Instruction *User = cast<Instruction>(U.getUser());
192 
193  Value *V;
194  if (PHINode *UserPN = dyn_cast<PHINode>(User))
195  V = GetValueAtEndOfBlock(UserPN->getIncomingBlock(U));
196  else
197  V = GetValueInMiddleOfBlock(User->getParent());
198 
199  // Notify that users of the existing value that it is being replaced.
200  Value *OldVal = U.get();
201  if (OldVal != V && OldVal->hasValueHandle())
203 
204  U.set(V);
205 }
206 
208  Instruction *User = cast<Instruction>(U.getUser());
209 
210  Value *V;
211  if (PHINode *UserPN = dyn_cast<PHINode>(User))
212  V = GetValueAtEndOfBlock(UserPN->getIncomingBlock(U));
213  else
214  V = GetValueAtEndOfBlock(User->getParent());
215 
216  U.set(V);
217 }
218 
219 namespace llvm {
220 
221 template<>
223 public:
224  using BlkT = BasicBlock;
225  using ValT = Value *;
226  using PhiT = PHINode;
228 
229  static BlkSucc_iterator BlkSucc_begin(BlkT *BB) { return succ_begin(BB); }
230  static BlkSucc_iterator BlkSucc_end(BlkT *BB) { return succ_end(BB); }
231 
232  class PHI_iterator {
233  private:
234  PHINode *PHI;
235  unsigned idx;
236 
237  public:
238  explicit PHI_iterator(PHINode *P) // begin iterator
239  : PHI(P), idx(0) {}
240  PHI_iterator(PHINode *P, bool) // end iterator
241  : PHI(P), idx(PHI->getNumIncomingValues()) {}
242 
243  PHI_iterator &operator++() { ++idx; return *this; }
244  bool operator==(const PHI_iterator& x) const { return idx == x.idx; }
245  bool operator!=(const PHI_iterator& x) const { return !operator==(x); }
246 
247  Value *getIncomingValue() { return PHI->getIncomingValue(idx); }
249  };
250 
251  static PHI_iterator PHI_begin(PhiT *PHI) { return PHI_iterator(PHI); }
252  static PHI_iterator PHI_end(PhiT *PHI) {
253  return PHI_iterator(PHI, true);
254  }
255 
256  /// FindPredecessorBlocks - Put the predecessors of Info->BB into the Preds
257  /// vector, set Info->NumPreds, and allocate space in Info->Preds.
260  // We can get our predecessor info by walking the pred_iterator list,
261  // but it is relatively slow. If we already have PHI nodes in this
262  // block, walk one of them to get the predecessor list instead.
263  if (PHINode *SomePhi = dyn_cast<PHINode>(BB->begin())) {
264  Preds->append(SomePhi->block_begin(), SomePhi->block_end());
265  } else {
266  for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
267  Preds->push_back(*PI);
268  }
269  }
270 
271  /// GetUndefVal - Get an undefined value of the same type as the value
272  /// being handled.
273  static Value *GetUndefVal(BasicBlock *BB, SSAUpdater *Updater) {
274  return UndefValue::get(Updater->ProtoType);
275  }
276 
277  /// CreateEmptyPHI - Create a new PHI instruction in the specified block.
278  /// Reserve space for the operands but do not fill them in yet.
279  static Value *CreateEmptyPHI(BasicBlock *BB, unsigned NumPreds,
280  SSAUpdater *Updater) {
281  PHINode *PHI = PHINode::Create(Updater->ProtoType, NumPreds,
282  Updater->ProtoName, &BB->front());
283  return PHI;
284  }
285 
286  /// AddPHIOperand - Add the specified value as an operand of the PHI for
287  /// the specified predecessor block.
288  static void AddPHIOperand(PHINode *PHI, Value *Val, BasicBlock *Pred) {
289  PHI->addIncoming(Val, Pred);
290  }
291 
292  /// InstrIsPHI - Check if an instruction is a PHI.
293  ///
295  return dyn_cast<PHINode>(I);
296  }
297 
298  /// ValueIsPHI - Check if a value is a PHI.
299  static PHINode *ValueIsPHI(Value *Val, SSAUpdater *Updater) {
300  return dyn_cast<PHINode>(Val);
301  }
302 
303  /// ValueIsNewPHI - Like ValueIsPHI but also check if the PHI has no source
304  /// operands, i.e., it was just added.
305  static PHINode *ValueIsNewPHI(Value *Val, SSAUpdater *Updater) {
306  PHINode *PHI = ValueIsPHI(Val, Updater);
307  if (PHI && PHI->getNumIncomingValues() == 0)
308  return PHI;
309  return nullptr;
310  }
311 
312  /// GetPHIValue - For the specified PHI instruction, return the value
313  /// that it defines.
314  static Value *GetPHIValue(PHINode *PHI) {
315  return PHI;
316  }
317 };
318 
319 } // end namespace llvm
320 
321 /// Check to see if AvailableVals has an entry for the specified BB and if so,
322 /// return it. If not, construct SSA form by first calculating the required
323 /// placement of PHIs and then inserting new PHIs where needed.
324 Value *SSAUpdater::GetValueAtEndOfBlockInternal(BasicBlock *BB) {
325  AvailableValsTy &AvailableVals = getAvailableVals(AV);
326  if (Value *V = AvailableVals[BB])
327  return V;
328 
329  SSAUpdaterImpl<SSAUpdater> Impl(this, &AvailableVals, InsertedPHIs);
330  return Impl.GetValue(BB);
331 }
332 
333 //===----------------------------------------------------------------------===//
334 // LoadAndStorePromoter Implementation
335 //===----------------------------------------------------------------------===//
336 
339  SSAUpdater &S, StringRef BaseName) : SSA(S) {
340  if (Insts.empty()) return;
341 
342  const Value *SomeVal;
343  if (const LoadInst *LI = dyn_cast<LoadInst>(Insts[0]))
344  SomeVal = LI;
345  else
346  SomeVal = cast<StoreInst>(Insts[0])->getOperand(0);
347 
348  if (BaseName.empty())
349  BaseName = SomeVal->getName();
350  SSA.Initialize(SomeVal->getType(), BaseName);
351 }
352 
354 run(const SmallVectorImpl<Instruction *> &Insts) const {
355  // First step: bucket up uses of the alloca by the block they occur in.
356  // This is important because we have to handle multiple defs/uses in a block
357  // ourselves: SSAUpdater is purely for cross-block references.
359 
360  for (Instruction *User : Insts)
361  UsesByBlock[User->getParent()].push_back(User);
362 
363  // Okay, now we can iterate over all the blocks in the function with uses,
364  // processing them. Keep track of which loads are loading a live-in value.
365  // Walk the uses in the use-list order to be determinstic.
366  SmallVector<LoadInst *, 32> LiveInLoads;
367  DenseMap<Value *, Value *> ReplacedLoads;
368 
369  for (Instruction *User : Insts) {
370  BasicBlock *BB = User->getParent();
371  TinyPtrVector<Instruction *> &BlockUses = UsesByBlock[BB];
372 
373  // If this block has already been processed, ignore this repeat use.
374  if (BlockUses.empty()) continue;
375 
376  // Okay, this is the first use in the block. If this block just has a
377  // single user in it, we can rewrite it trivially.
378  if (BlockUses.size() == 1) {
379  // If it is a store, it is a trivial def of the value in the block.
380  if (StoreInst *SI = dyn_cast<StoreInst>(User)) {
382  SSA.AddAvailableValue(BB, SI->getOperand(0));
383  } else
384  // Otherwise it is a load, queue it to rewrite as a live-in load.
385  LiveInLoads.push_back(cast<LoadInst>(User));
386  BlockUses.clear();
387  continue;
388  }
389 
390  // Otherwise, check to see if this block is all loads.
391  bool HasStore = false;
392  for (Instruction *I : BlockUses) {
393  if (isa<StoreInst>(I)) {
394  HasStore = true;
395  break;
396  }
397  }
398 
399  // If so, we can queue them all as live in loads. We don't have an
400  // efficient way to tell which on is first in the block and don't want to
401  // scan large blocks, so just add all loads as live ins.
402  if (!HasStore) {
403  for (Instruction *I : BlockUses)
404  LiveInLoads.push_back(cast<LoadInst>(I));
405  BlockUses.clear();
406  continue;
407  }
408 
409  // Otherwise, we have mixed loads and stores (or just a bunch of stores).
410  // Since SSAUpdater is purely for cross-block values, we need to determine
411  // the order of these instructions in the block. If the first use in the
412  // block is a load, then it uses the live in value. The last store defines
413  // the live out value. We handle this by doing a linear scan of the block.
414  Value *StoredValue = nullptr;
415  for (Instruction &I : *BB) {
416  if (LoadInst *L = dyn_cast<LoadInst>(&I)) {
417  // If this is a load from an unrelated pointer, ignore it.
418  if (!isInstInList(L, Insts)) continue;
419 
420  // If we haven't seen a store yet, this is a live in use, otherwise
421  // use the stored value.
422  if (StoredValue) {
423  replaceLoadWithValue(L, StoredValue);
424  L->replaceAllUsesWith(StoredValue);
425  ReplacedLoads[L] = StoredValue;
426  } else {
427  LiveInLoads.push_back(L);
428  }
429  continue;
430  }
431 
432  if (StoreInst *SI = dyn_cast<StoreInst>(&I)) {
433  // If this is a store to an unrelated pointer, ignore it.
434  if (!isInstInList(SI, Insts)) continue;
436 
437  // Remember that this is the active value in the block.
438  StoredValue = SI->getOperand(0);
439  }
440  }
441 
442  // The last stored value that happened is the live-out for the block.
443  assert(StoredValue && "Already checked that there is a store in block");
444  SSA.AddAvailableValue(BB, StoredValue);
445  BlockUses.clear();
446  }
447 
448  // Okay, now we rewrite all loads that use live-in values in the loop,
449  // inserting PHI nodes as necessary.
450  for (LoadInst *ALoad : LiveInLoads) {
451  Value *NewVal = SSA.GetValueInMiddleOfBlock(ALoad->getParent());
452  replaceLoadWithValue(ALoad, NewVal);
453 
454  // Avoid assertions in unreachable code.
455  if (NewVal == ALoad) NewVal = UndefValue::get(NewVal->getType());
456  ALoad->replaceAllUsesWith(NewVal);
457  ReplacedLoads[ALoad] = NewVal;
458  }
459 
460  // Allow the client to do stuff before we start nuking things.
462 
463  // Now that everything is rewritten, delete the old instructions from the
464  // function. They should all be dead now.
465  for (Instruction *User : Insts) {
466  // If this is a load that still has uses, then the load must have been added
467  // as a live value in the SSAUpdate data structure for a block (e.g. because
468  // the loaded value was stored later). In this case, we need to recursively
469  // propagate the updates until we get to the real value.
470  if (!User->use_empty()) {
471  Value *NewVal = ReplacedLoads[User];
472  assert(NewVal && "not a replaced load?");
473 
474  // Propagate down to the ultimate replacee. The intermediately loads
475  // could theoretically already have been deleted, so we don't want to
476  // dereference the Value*'s.
477  DenseMap<Value*, Value*>::iterator RLI = ReplacedLoads.find(NewVal);
478  while (RLI != ReplacedLoads.end()) {
479  NewVal = RLI->second;
480  RLI = ReplacedLoads.find(NewVal);
481  }
482 
483  replaceLoadWithValue(cast<LoadInst>(User), NewVal);
484  User->replaceAllUsesWith(NewVal);
485  }
486 
488  User->eraseFromParent();
489  }
490 }
491 
492 bool
494  const SmallVectorImpl<Instruction *> &Insts)
495  const {
496  return is_contained(Insts, I);
497 }
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: Instruction.cpp:68
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:259
Helper class for SSA formation on a set of values defined in multiple blocks.
Definition: SSAUpdater.h:39
static BlkSucc_iterator BlkSucc_end(BlkT *BB)
Definition: SSAUpdater.cpp:230
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
DenseMap< BasicBlock *, Value * > AvailableValsTy
Definition: SSAUpdater.cpp:41
static void AddPHIOperand(PHINode *PHI, Value *Val, BasicBlock *Pred)
AddPHIOperand - Add the specified value as an operand of the PHI for the specified predecessor block...
Definition: SSAUpdater.cpp:288
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Various leaf nodes.
Definition: ISDOpcodes.h:60
void Initialize(Type *Ty, StringRef Name)
Reset this object to get ready for a new set of SSA updates with type &#39;Ty&#39;.
Definition: SSAUpdater.cpp:54
static BlkSucc_iterator BlkSucc_begin(BlkT *BB)
Definition: SSAUpdater.cpp:229
virtual void instructionDeleted(Instruction *I) const
Called before each instruction is deleted.
Definition: SSAUpdater.h:169
void AddAvailableValue(BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value...
Definition: SSAUpdater.cpp:72
static Value * CreateEmptyPHI(BasicBlock *BB, unsigned NumPreds, SSAUpdater *Updater)
CreateEmptyPHI - Create a new PHI instruction in the specified block.
Definition: SSAUpdater.cpp:279
A debug info location.
Definition: DebugLoc.h:34
ValT GetValue(BlkT *BB)
GetValue - Check to see if AvailableVals has an entry for the specified BB and if so...
An instruction for reading from memory.
Definition: Instructions.h:168
This defines the Use class.
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
Definition: TinyPtrVector.h:31
Value * get() const
Definition: Use.h:108
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:269
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
Definition: BasicBlock.cpp:134
amdgpu Simplify well known AMD library false Value Value const Twine & Name
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:371
virtual bool isInstInList(Instruction *I, const SmallVectorImpl< Instruction *> &Insts) const
Return true if the specified instruction is in the Inst list.
Definition: SSAUpdater.cpp:493
static PHINode * InstrIsPHI(Instruction *I)
InstrIsPHI - Check if an instruction is a PHI.
Definition: SSAUpdater.cpp:294
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
static PHI_iterator PHI_begin(PhiT *PHI)
Definition: SSAUpdater.cpp:251
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Definition: Interval.h:103
User * getUser() const LLVM_READONLY
Returns the User that contains this Use.
Definition: Use.cpp:41
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
virtual void doExtraRewritesBeforeFinalDeletion() const
This hook is invoked after all the stores are found and inserted as available values.
Definition: SSAUpdater.h:162
bool operator==(const PHI_iterator &x) const
Definition: SSAUpdater.cpp:244
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
Memory SSA
Definition: MemorySSA.cpp:65
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
An instruction for storing to memory.
Definition: Instructions.h:321
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:429
static void ValueIsRAUWd(Value *Old, Value *New)
Definition: Value.cpp:885
static Value * GetUndefVal(BasicBlock *BB, SSAUpdater *Updater)
GetUndefVal - Get an undefined value of the same type as the value being handled. ...
Definition: SSAUpdater.cpp:273
Value * FindValueForBlock(BasicBlock *BB) const
Return the value for the specified block if the SSAUpdater has one, otherwise return nullptr...
Definition: SSAUpdater.cpp:67
Interval::succ_iterator succ_end(Interval *I)
Definition: Interval.h:106
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:176
virtual void updateDebugInfo(Instruction *I) const
Called to update debug info associated with the instruction.
Definition: SSAUpdater.h:172
#define P(N)
Value * GetValueInMiddleOfBlock(BasicBlock *BB)
Construct SSA form, materializing a value that is live in the middle of the specified block...
Definition: SSAUpdater.cpp:100
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:190
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:308
void set(Value *Val)
Definition: Value.h:671
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
void RewriteUseAfterInsertions(Use &U)
Rewrite a use like RewriteUse but handling in-block definitions.
Definition: SSAUpdater.cpp:207
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:129
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const Instruction & front() const
Definition: BasicBlock.h:281
SSAUpdater(SmallVectorImpl< PHINode *> *InsertedPHIs=nullptr)
If InsertedPHIs is specified, it will be filled in with all PHI Nodes created by rewriting.
Definition: SSAUpdater.cpp:47
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Definition: Interval.h:113
bool empty() const
Interval::pred_iterator pred_end(Interval *I)
Definition: Interval.h:116
static UndefValue * get(Type *T)
Static factory methods - Return an &#39;undef&#39; object of the specified type.
Definition: Constants.cpp:1415
static AvailableValsTy & getAvailableVals(void *AV)
Definition: SSAUpdater.cpp:43
size_t size() const
Definition: SmallVector.h:53
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
static PHINode * ValueIsPHI(Value *Val, SSAUpdater *Updater)
ValueIsPHI - Check if a value is a PHI.
Definition: SSAUpdater.cpp:299
static void FindPredecessorBlocks(BasicBlock *BB, SmallVectorImpl< BasicBlock *> *Preds)
FindPredecessorBlocks - Put the predecessors of Info->BB into the Preds vector, set Info->NumPreds...
Definition: SSAUpdater.cpp:258
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
Module.h This file contains the declarations for the Module class.
void run(const SmallVectorImpl< Instruction *> &Insts) const
This does the promotion.
Definition: SSAUpdater.cpp:354
static bool IsEquivalentPHI(PHINode *PHI, SmallDenseMap< BasicBlock *, Value *, 8 > &ValueMapping)
Definition: SSAUpdater.cpp:79
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
virtual void replaceLoadWithValue(LoadInst *LI, Value *V) const
Clients can choose to implement this to get notified right before a load is RAUW&#39;d another value...
Definition: SSAUpdater.h:166
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:394
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:133
SuccIterator< Instruction, BasicBlock > succ_iterator
Definition: CFG.h:245
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:56
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:214
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
#define I(x, y, z)
Definition: MD5.cpp:58
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition: BasicBlock.h:325
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:171
Helper struct that represents how a value is mapped through different register banks.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
static PHI_iterator PHI_end(PhiT *PHI)
Definition: SSAUpdater.cpp:252
bool operator!=(const PHI_iterator &x) const
Definition: SSAUpdater.cpp:245
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
LoadAndStorePromoter(ArrayRef< const Instruction *> Insts, SSAUpdater &S, StringRef Name=StringRef())
Definition: SSAUpdater.cpp:338
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:1967
Value * GetValueAtEndOfBlock(BasicBlock *BB)
Construct SSA form, materializing a value that is live at the end of the specified block...
Definition: SSAUpdater.cpp:95
#define LLVM_DEBUG(X)
Definition: Debug.h:123
void RewriteUse(Use &U)
Rewrite a use of the symbolic value.
Definition: SSAUpdater.cpp:190
static Value * GetPHIValue(PHINode *PHI)
GetPHIValue - For the specified PHI instruction, return the value that it defines.
Definition: SSAUpdater.cpp:314
Value * SimplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
static PHINode * ValueIsNewPHI(Value *Val, SSAUpdater *Updater)
ValueIsNewPHI - Like ValueIsPHI but also check if the PHI has no source operands, i...
Definition: SSAUpdater.cpp:305
bool use_empty() const
Definition: Value.h:323
unsigned size() const
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:144
const BasicBlock * getParent() const
Definition: Instruction.h:67
bool HasValueForBlock(BasicBlock *BB) const
Return true if the SSAUpdater already has a value for the specified block.
Definition: SSAUpdater.cpp:63
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1245