LLVM 22.0.0git
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"
19#include "llvm/IR/BasicBlock.h"
20#include "llvm/IR/CFG.h"
21#include "llvm/IR/Constants.h"
22#include "llvm/IR/DebugInfo.h"
23#include "llvm/IR/DebugLoc.h"
24#include "llvm/IR/Instruction.h"
26#include "llvm/IR/Use.h"
27#include "llvm/IR/Value.h"
29#include "llvm/Support/Debug.h"
32#include <cassert>
33#include <utility>
34
35using namespace llvm;
36
37#define DEBUG_TYPE "ssaupdater"
38
40
42 return *static_cast<AvailableValsTy*>(AV);
43}
44
46 : InsertedPHIs(NewPHI) {}
47
49 delete static_cast<AvailableValsTy*>(AV);
50}
51
53 if (!AV)
54 AV = new AvailableValsTy();
55 else
57 ProtoType = Ty;
58 ProtoName = std::string(Name);
59}
60
62 return getAvailableVals(AV).count(BB);
63}
64
66 return getAvailableVals(AV).lookup(BB);
67}
68
70 assert(ProtoType && "Need to initialize SSAUpdater");
71 assert(ProtoType == V->getType() &&
72 "All rewritten values must have the same type");
73 getAvailableVals(AV)[BB] = V;
74}
75
78 unsigned PHINumValues = PHI->getNumIncomingValues();
79 if (PHINumValues != ValueMapping.size())
80 return false;
81
82 // Scan the phi to see if it matches.
83 for (unsigned i = 0, e = PHINumValues; i != e; ++i)
84 if (ValueMapping[PHI->getIncomingBlock(i)] !=
85 PHI->getIncomingValue(i)) {
86 return false;
87 }
88
89 return true;
90}
91
93 Value *Res = GetValueAtEndOfBlockInternal(BB);
94 return Res;
95}
96
98 // If there is no definition of the renamed variable in this block, just use
99 // GetValueAtEndOfBlock to do our work.
100 if (!HasValueForBlock(BB))
101 return GetValueAtEndOfBlock(BB);
102
103 // Otherwise, we have the hard case. Get the live-in values for each
104 // predecessor.
106 Value *SingularValue = nullptr;
107
108 // We can get our predecessor info by walking the pred_iterator list, but it
109 // is relatively slow. If we already have PHI nodes in this block, walk one
110 // of them to get the predecessor list instead.
111 if (PHINode *SomePhi = dyn_cast<PHINode>(BB->begin())) {
112 for (unsigned i = 0, e = SomePhi->getNumIncomingValues(); i != e; ++i) {
113 BasicBlock *PredBB = SomePhi->getIncomingBlock(i);
114 Value *PredVal = GetValueAtEndOfBlock(PredBB);
115 PredValues.push_back(std::make_pair(PredBB, PredVal));
116
117 // Compute SingularValue.
118 if (i == 0)
119 SingularValue = PredVal;
120 else if (PredVal != SingularValue)
121 SingularValue = nullptr;
122 }
123 } else {
124 bool isFirstPred = true;
125 for (BasicBlock *PredBB : predecessors(BB)) {
126 Value *PredVal = GetValueAtEndOfBlock(PredBB);
127 PredValues.push_back(std::make_pair(PredBB, PredVal));
128
129 // Compute SingularValue.
130 if (isFirstPred) {
131 SingularValue = PredVal;
132 isFirstPred = false;
133 } else if (PredVal != SingularValue)
134 SingularValue = nullptr;
135 }
136 }
137
138 // If there are no predecessors, just return poison.
139 if (PredValues.empty())
140 return PoisonValue::get(ProtoType);
141
142 // Otherwise, if all the merged values are the same, just use it.
143 if (SingularValue)
144 return SingularValue;
145
146 // Otherwise, we do need a PHI: check to see if we already have one available
147 // in this block that produces the right value.
148 if (isa<PHINode>(BB->begin())) {
149 SmallDenseMap<BasicBlock *, Value *, 8> ValueMapping(PredValues.begin(),
150 PredValues.end());
151 for (PHINode &SomePHI : BB->phis()) {
152 if (IsEquivalentPHI(&SomePHI, ValueMapping))
153 return &SomePHI;
154 }
155 }
156
157 // Ok, we have no way out, insert a new one now.
158 PHINode *InsertedPHI =
159 PHINode::Create(ProtoType, PredValues.size(), ProtoName);
160 InsertedPHI->insertBefore(BB->begin());
161
162 // Fill in all the predecessors of the PHI.
163 for (const auto &PredValue : PredValues)
164 InsertedPHI->addIncoming(PredValue.second, PredValue.first);
165
166 // See if the PHI node can be merged to a single value. This can happen in
167 // loop cases when we get a PHI of itself and one other value.
168 if (Value *V =
169 simplifyInstruction(InsertedPHI, BB->getDataLayout())) {
170 InsertedPHI->eraseFromParent();
171 return V;
172 }
173
174 // Set the DebugLoc of the inserted PHI, if available.
175 DebugLoc DL;
176 if (BasicBlock::iterator It = BB->getFirstNonPHIIt(); It != BB->end())
177 DL = It->getDebugLoc();
178 InsertedPHI->setDebugLoc(DL);
179
180 // If the client wants to know about all new instructions, tell it.
181 if (InsertedPHIs) InsertedPHIs->push_back(InsertedPHI);
182
183 LLVM_DEBUG(dbgs() << " Inserted PHI: " << *InsertedPHI << "\n");
184 return InsertedPHI;
185}
186
188 Instruction *User = cast<Instruction>(U.getUser());
189
190 Value *V;
191 if (PHINode *UserPN = dyn_cast<PHINode>(User))
192 V = GetValueAtEndOfBlock(UserPN->getIncomingBlock(U));
193 else
194 V = GetValueInMiddleOfBlock(User->getParent());
195
196 U.set(V);
197}
198
200 SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
201 llvm::findDbgValues(I, DbgVariableRecords);
202 for (auto &DVR : DbgVariableRecords) {
203 if (DVR->getParent() == I->getParent())
204 continue;
205 UpdateDebugValue(I, DVR);
206 }
207}
208
210 Instruction *I, SmallVectorImpl<DbgVariableRecord *> &DbgVariableRecords) {
211 for (auto &DVR : DbgVariableRecords) {
212 UpdateDebugValue(I, DVR);
213 }
214}
215
216void SSAUpdater::UpdateDebugValue(Instruction *I, DbgVariableRecord *DVR) {
217 BasicBlock *UserBB = DVR->getParent();
218 if (HasValueForBlock(UserBB)) {
219 Value *NewVal = GetValueAtEndOfBlock(UserBB);
220 DVR->replaceVariableLocationOp(I, NewVal);
221 } else
222 DVR->setKillLocation();
223}
224
226 Instruction *User = cast<Instruction>(U.getUser());
227
228 Value *V;
229 if (PHINode *UserPN = dyn_cast<PHINode>(User))
230 V = GetValueAtEndOfBlock(UserPN->getIncomingBlock(U));
231 else
232 V = GetValueAtEndOfBlock(User->getParent());
233
234 U.set(V);
235}
236
237namespace llvm {
238
239template<>
241public:
243 using ValT = Value *;
244 using PhiT = PHINode;
246
247 static BlkSucc_iterator BlkSucc_begin(BlkT *BB) { return succ_begin(BB); }
248 static BlkSucc_iterator BlkSucc_end(BlkT *BB) { return succ_end(BB); }
249
250 class PHI_iterator {
251 private:
252 PHINode *PHI;
253 unsigned idx;
254
255 public:
256 explicit PHI_iterator(PHINode *P) // begin iterator
257 : PHI(P), idx(0) {}
258 PHI_iterator(PHINode *P, bool) // end iterator
259 : PHI(P), idx(PHI->getNumIncomingValues()) {}
260
261 PHI_iterator &operator++() { ++idx; return *this; }
262 bool operator==(const PHI_iterator& x) const { return idx == x.idx; }
263 bool operator!=(const PHI_iterator& x) const { return !operator==(x); }
264
265 Value *getIncomingValue() { return PHI->getIncomingValue(idx); }
266 BasicBlock *getIncomingBlock() { return PHI->getIncomingBlock(idx); }
267 };
268
269 static PHI_iterator PHI_begin(PhiT *PHI) { return PHI_iterator(PHI); }
270 static PHI_iterator PHI_end(PhiT *PHI) {
271 return PHI_iterator(PHI, true);
272 }
273
274 /// FindPredecessorBlocks - Put the predecessors of Info->BB into the Preds
275 /// vector, set Info->NumPreds, and allocate space in Info->Preds.
278 // We can get our predecessor info by walking the pred_iterator list,
279 // but it is relatively slow. If we already have PHI nodes in this
280 // block, walk one of them to get the predecessor list instead.
281 if (PHINode *SomePhi = dyn_cast<PHINode>(BB->begin()))
282 append_range(*Preds, SomePhi->blocks());
283 else
284 append_range(*Preds, predecessors(BB));
285 }
286
287 /// GetPoisonVal - Get a poison value of the same type as the value
288 /// being handled.
289 static Value *GetPoisonVal(BasicBlock *BB, SSAUpdater *Updater) {
290 return PoisonValue::get(Updater->ProtoType);
291 }
292
293 /// CreateEmptyPHI - Create a new PHI instruction in the specified block.
294 /// Reserve space for the operands but do not fill them in yet.
295 static Value *CreateEmptyPHI(BasicBlock *BB, unsigned NumPreds,
296 SSAUpdater *Updater) {
297 PHINode *PHI =
298 PHINode::Create(Updater->ProtoType, NumPreds, Updater->ProtoName);
299 // FIXME: Ordinarily we don't care about or try to assign DebugLocs to PHI
300 // nodes, but loop optimizations may try to use a PHI node as a DebugLoc
301 // source (e.g. if this is an induction variable), and it's not clear what
302 // location we could attach here, so mark this unknown for now.
303 PHI->setDebugLoc(DebugLoc::getUnknown());
304 PHI->insertBefore(BB->begin());
305 return PHI;
306 }
307
308 /// AddPHIOperand - Add the specified value as an operand of the PHI for
309 /// the specified predecessor block.
310 static void AddPHIOperand(PHINode *PHI, Value *Val, BasicBlock *Pred) {
311 PHI->addIncoming(Val, Pred);
312 }
313
314 /// ValueIsPHI - Check if a value is a PHI.
315 static PHINode *ValueIsPHI(Value *Val, SSAUpdater *Updater) {
316 return dyn_cast<PHINode>(Val);
317 }
318
319 /// ValueIsNewPHI - Like ValueIsPHI but also check if the PHI has no source
320 /// operands, i.e., it was just added.
321 static PHINode *ValueIsNewPHI(Value *Val, SSAUpdater *Updater) {
322 PHINode *PHI = ValueIsPHI(Val, Updater);
323 if (PHI && PHI->getNumIncomingValues() == 0)
324 return PHI;
325 return nullptr;
326 }
327
328 /// GetPHIValue - For the specified PHI instruction, return the value
329 /// that it defines.
331 return PHI;
332 }
333};
334
335} // end namespace llvm
336
337/// Check to see if AvailableVals has an entry for the specified BB and if so,
338/// return it. If not, construct SSA form by first calculating the required
339/// placement of PHIs and then inserting new PHIs where needed.
340Value *SSAUpdater::GetValueAtEndOfBlockInternal(BasicBlock *BB) {
341 AvailableValsTy &AvailableVals = getAvailableVals(AV);
342 if (Value *V = AvailableVals[BB])
343 return V;
344
345 SSAUpdaterImpl<SSAUpdater> Impl(this, &AvailableVals, InsertedPHIs);
346 return Impl.GetValue(BB);
347}
348
349//===----------------------------------------------------------------------===//
350// LoadAndStorePromoter Implementation
351//===----------------------------------------------------------------------===//
352
355 SSAUpdater &S, StringRef BaseName) : SSA(S) {
356 if (Insts.empty()) return;
357
358 const Value *SomeVal;
359 if (const LoadInst *LI = dyn_cast<LoadInst>(Insts[0]))
360 SomeVal = LI;
361 else
362 SomeVal = cast<StoreInst>(Insts[0])->getOperand(0);
363
364 if (BaseName.empty())
365 BaseName = SomeVal->getName();
366 SSA.Initialize(SomeVal->getType(), BaseName);
367}
368
370 // First step: bucket up uses of the alloca by the block they occur in.
371 // This is important because we have to handle multiple defs/uses in a block
372 // ourselves: SSAUpdater is purely for cross-block references.
374
375 for (Instruction *User : Insts)
376 UsesByBlock[User->getParent()].push_back(User);
377
378 // Okay, now we can iterate over all the blocks in the function with uses,
379 // processing them. Keep track of which loads are loading a live-in value.
380 // Walk the uses in the use-list order to be determinstic.
381 SmallVector<LoadInst *, 32> LiveInLoads;
382 DenseMap<Value *, Value *> ReplacedLoads;
383
384 for (Instruction *User : Insts) {
385 BasicBlock *BB = User->getParent();
386 TinyPtrVector<Instruction *> &BlockUses = UsesByBlock[BB];
387
388 // If this block has already been processed, ignore this repeat use.
389 if (BlockUses.empty()) continue;
390
391 // Okay, this is the first use in the block. If this block just has a
392 // single user in it, we can rewrite it trivially.
393 if (BlockUses.size() == 1) {
394 // If it is a store, it is a trivial def of the value in the block.
395 if (StoreInst *SI = dyn_cast<StoreInst>(User)) {
396 updateDebugInfo(SI);
397 SSA.AddAvailableValue(BB, SI->getOperand(0));
398 } else if (auto *AI = dyn_cast<AllocaInst>(User)) {
399 // We treat AllocaInst as a store of an getValueToUseForAlloca value.
401 } else {
402 // Otherwise it is a load, queue it to rewrite as a live-in load.
403 LiveInLoads.push_back(cast<LoadInst>(User));
404 }
405 BlockUses.clear();
406 continue;
407 }
408
409 // Otherwise, check to see if this block is all loads.
410 bool HasStore = false;
411 for (Instruction *I : BlockUses) {
412 if (isa<StoreInst>(I) || isa<AllocaInst>(I)) {
413 HasStore = true;
414 break;
415 }
416 }
417
418 // If so, we can queue them all as live in loads.
419 if (!HasStore) {
420 for (Instruction *I : BlockUses)
421 LiveInLoads.push_back(cast<LoadInst>(I));
422 BlockUses.clear();
423 continue;
424 }
425
426 // Sort all of the interesting instructions in the block so that we don't
427 // have to scan a large block just to find a few instructions.
429 BlockUses.begin(), BlockUses.end(),
430 [](Instruction *A, Instruction *B) { return A->comesBefore(B); });
431
432 // Otherwise, we have mixed loads and stores (or just a bunch of stores).
433 // Since SSAUpdater is purely for cross-block values, we need to determine
434 // the order of these instructions in the block. If the first use in the
435 // block is a load, then it uses the live in value. The last store defines
436 // the live out value.
437 Value *StoredValue = nullptr;
438 for (Instruction *I : BlockUses) {
439 if (LoadInst *L = dyn_cast<LoadInst>(I)) {
440 // If we haven't seen a store yet, this is a live in use, otherwise
441 // use the stored value.
442 if (StoredValue) {
443 replaceLoadWithValue(L, StoredValue);
444 L->replaceAllUsesWith(StoredValue);
445 ReplacedLoads[L] = StoredValue;
446 } else {
447 LiveInLoads.push_back(L);
448 }
449 continue;
450 }
451
452 if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
453 updateDebugInfo(SI);
454
455 // Remember that this is the active value in the block.
456 StoredValue = SI->getOperand(0);
457 } else if (auto *AI = dyn_cast<AllocaInst>(I)) {
458 // Check if this an alloca, in which case we treat it as a store of
459 // getValueToUseForAlloca.
460 StoredValue = getValueToUseForAlloca(AI);
461 }
462 }
463
464 // The last stored value that happened is the live-out for the block.
465 assert(StoredValue && "Already checked that there is a store in block");
466 SSA.AddAvailableValue(BB, StoredValue);
467 BlockUses.clear();
468 }
469
470 // Okay, now we rewrite all loads that use live-in values in the loop,
471 // inserting PHI nodes as necessary.
472 for (LoadInst *ALoad : LiveInLoads) {
473 Value *NewVal = SSA.GetValueInMiddleOfBlock(ALoad->getParent());
474 replaceLoadWithValue(ALoad, NewVal);
475
476 // Avoid assertions in unreachable code.
477 if (NewVal == ALoad) NewVal = PoisonValue::get(NewVal->getType());
478 ALoad->replaceAllUsesWith(NewVal);
479 ReplacedLoads[ALoad] = NewVal;
480 }
481
482 // Allow the client to do stuff before we start nuking things.
484
485 // Now that everything is rewritten, delete the old instructions from the
486 // function. They should all be dead now.
487 for (Instruction *User : Insts) {
488 if (!shouldDelete(User))
489 continue;
490
491 // If this is a load that still has uses, then the load must have been added
492 // as a live value in the SSAUpdate data structure for a block (e.g. because
493 // the loaded value was stored later). In this case, we need to recursively
494 // propagate the updates until we get to the real value.
495 if (!User->use_empty()) {
496 Value *NewVal = ReplacedLoads[User];
497 assert(NewVal && "not a replaced load?");
498
499 // Propagate down to the ultimate replacee. The intermediately loads
500 // could theoretically already have been deleted, so we don't want to
501 // dereference the Value*'s.
502 DenseMap<Value*, Value*>::iterator RLI = ReplacedLoads.find(NewVal);
503 while (RLI != ReplacedLoads.end()) {
504 NewVal = RLI->second;
505 RLI = ReplacedLoads.find(NewVal);
506 }
507
508 replaceLoadWithValue(cast<LoadInst>(User), NewVal);
509 User->replaceAllUsesWith(NewVal);
510 }
511
513 User->eraseFromParent();
514 }
515}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Rewrite undef for PHI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
std::string Name
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This defines the Use class.
#define I(x, y, z)
Definition: MD5.cpp:58
static AvailableValsTy & getAvailableVals(void *AV)
DenseMap< MachineBasicBlock *, Register > AvailableValsTy
Memory SSA
Definition: MemorySSA.cpp:72
#define P(N)
static AvailableValsTy & getAvailableVals(void *AV)
Definition: SSAUpdater.cpp:41
static bool IsEquivalentPHI(PHINode *PHI, SmallDenseMap< BasicBlock *, Value *, 8 > &ValueMapping)
Definition: SSAUpdater.cpp:76
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallVector class.
#define LLVM_DEBUG(...)
Definition: Debug.h:119
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:142
LLVM Basic Block Representation.
Definition: BasicBlock.h:62
iterator end()
Definition: BasicBlock.h:472
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:459
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition: BasicBlock.h:528
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:337
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
Definition: BasicBlock.cpp:252
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:170
LLVM_ABI const BasicBlock * getParent() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
LLVM_ABI void replaceVariableLocationOp(Value *OldValue, Value *NewValue, bool AllowEmpty=false)
A debug info location.
Definition: DebugLoc.h:124
static DebugLoc getUnknown()
Definition: DebugLoc.h:162
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:203
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:177
unsigned size() const
Definition: DenseMap.h:120
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:173
iterator end()
Definition: DenseMap.h:87
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:510
virtual Value * getValueToUseForAlloca(Instruction *AI) const
Return the value to use for the point in the code that the alloca is positioned.
Definition: SSAUpdater.h:184
virtual void instructionDeleted(Instruction *I) const
Called before each instruction is deleted.
Definition: SSAUpdater.h:172
virtual void doExtraRewritesBeforeFinalDeletion()
This hook is invoked after all the stores are found and inserted as available values.
Definition: SSAUpdater.h:165
LoadAndStorePromoter(ArrayRef< const Instruction * > Insts, SSAUpdater &S, StringRef Name=StringRef())
Definition: SSAUpdater.cpp:354
virtual void replaceLoadWithValue(LoadInst *LI, Value *V) const
Clients can choose to implement this to get notified right before a load is RAUW'd another value.
Definition: SSAUpdater.h:169
void run(const SmallVectorImpl< Instruction * > &Insts)
This does the promotion.
Definition: SSAUpdater.cpp:369
virtual void updateDebugInfo(Instruction *I) const
Called to update debug info associated with the instruction.
Definition: SSAUpdater.h:175
virtual bool shouldDelete(Instruction *I) const
Return false if a sub-class wants to keep one of the loads/stores after the SSA construction.
Definition: SSAUpdater.h:179
An instruction for reading from memory.
Definition: Instructions.h:180
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1885
bool operator!=(const PHI_iterator &x) const
Definition: SSAUpdater.cpp:263
bool operator==(const PHI_iterator &x) const
Definition: SSAUpdater.cpp:262
static BlkSucc_iterator BlkSucc_end(BlkT *BB)
Definition: SSAUpdater.cpp:248
static BlkSucc_iterator BlkSucc_begin(BlkT *BB)
Definition: SSAUpdater.cpp:247
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:276
static Value * CreateEmptyPHI(BasicBlock *BB, unsigned NumPreds, SSAUpdater *Updater)
CreateEmptyPHI - Create a new PHI instruction in the specified block.
Definition: SSAUpdater.cpp:295
static PHINode * ValueIsNewPHI(Value *Val, SSAUpdater *Updater)
ValueIsNewPHI - Like ValueIsPHI but also check if the PHI has no source operands, i....
Definition: SSAUpdater.cpp:321
static PHI_iterator PHI_begin(PhiT *PHI)
Definition: SSAUpdater.cpp:269
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:310
static Value * GetPHIValue(PHINode *PHI)
GetPHIValue - For the specified PHI instruction, return the value that it defines.
Definition: SSAUpdater.cpp:330
static Value * GetPoisonVal(BasicBlock *BB, SSAUpdater *Updater)
GetPoisonVal - Get a poison value of the same type as the value being handled.
Definition: SSAUpdater.cpp:289
static PHI_iterator PHI_end(PhiT *PHI)
Definition: SSAUpdater.cpp:270
static PHINode * ValueIsPHI(Value *Val, SSAUpdater *Updater)
ValueIsPHI - Check if a value is a PHI.
Definition: SSAUpdater.cpp:315
Helper class for SSA formation on a set of values defined in multiple blocks.
Definition: SSAUpdater.h:39
void RewriteUse(Use &U)
Rewrite a use of the symbolic value.
Definition: SSAUpdater.cpp:187
void RewriteUseAfterInsertions(Use &U)
Rewrite a use like RewriteUse but handling in-block definitions.
Definition: SSAUpdater.cpp:225
Value * FindValueForBlock(BasicBlock *BB) const
Return the value for the specified block if the SSAUpdater has one, otherwise return nullptr.
Definition: SSAUpdater.cpp:65
void Initialize(Type *Ty, StringRef Name)
Reset this object to get ready for a new set of SSA updates with type 'Ty'.
Definition: SSAUpdater.cpp:52
Value * GetValueInMiddleOfBlock(BasicBlock *BB)
Construct SSA form, materializing a value that is live in the middle of the specified block.
Definition: SSAUpdater.cpp:97
SSAUpdater(SmallVectorImpl< PHINode * > *InsertedPHIs=nullptr)
If InsertedPHIs is specified, it will be filled in with all PHI Nodes created by rewriting.
Definition: SSAUpdater.cpp:45
void UpdateDebugValues(Instruction *I)
Rewrite debug value intrinsics to conform to a new SSA form.
Definition: SSAUpdater.cpp:199
bool HasValueForBlock(BasicBlock *BB) const
Return true if the SSAUpdater already has a value for the specified block.
Definition: SSAUpdater.cpp:61
Value * GetValueAtEndOfBlock(BasicBlock *BB)
Construct SSA form, materializing a value that is live at the end of the specified block.
Definition: SSAUpdater.cpp:92
void AddAvailableValue(BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value.
Definition: SSAUpdater.cpp:69
bool empty() const
Definition: SmallVector.h:82
size_t size() const
Definition: SmallVector.h:79
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
An instruction for storing to memory.
Definition: Instructions.h:296
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:151
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
Definition: TinyPtrVector.h:29
bool empty() const
unsigned size() const
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
A Use represents the edge between a Value definition and its users.
Definition: Use.h:35
LLVM Value Representation.
Definition: Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:256
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:546
bool use_empty() const
Definition: Value.h:346
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:322
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI void findDbgValues(Value *V, SmallVectorImpl< DbgVariableRecord * > &DbgVariableRecords)
Finds the dbg.values describing a value.
Definition: DebugInfo.cpp:124
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition: STLExtras.h:2155
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
LLVM_ABI Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1669
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:207
SuccIterator< Instruction, BasicBlock > succ_iterator
Definition: CFG.h:243
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)
auto predecessors(const MachineBasicBlock *BB)