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