24#define DEBUG_TYPE "ssaupdaterbulk"
30 auto *
User = cast<Instruction>(U->getUser());
32 if (
auto *UserPN = dyn_cast<PHINode>(
User))
33 return UserPN->getIncomingBlock(*U);
35 return User->getParent();
41 unsigned Var = Rewrites.
size();
42 LLVM_DEBUG(
dbgs() <<
"SSAUpdater: Var=" << Var <<
": initialized with Ty = "
43 << *Ty <<
", Name = " <<
Name <<
"\n");
44 RewriteInfo RI(
Name, Ty);
52 assert(Var < Rewrites.
size() &&
"Variable not found!");
54 <<
": added new available value " << *V <<
" in "
62 assert(Var < Rewrites.
size() &&
"Variable not found!");
63 LLVM_DEBUG(
dbgs() <<
"SSAUpdater: Var=" << Var <<
": added a use" << *U->get()
83 while (!LiveInBlockWorklist.
empty()) {
88 if (!LiveInBlocks.
insert(BB).second)
115 for (
auto &R : Rewrites) {
132 for (
Use *U : R.Uses)
144 for (
auto [BB, V] : R.Defines)
145 BBInfos[BB].LiveOutValue = V;
148 for (
auto *FrontierBB : IDFBlocks) {
150 PHINode *PN =
B.CreatePHI(R.Ty, 0, R.Name);
151 BBInfos[FrontierBB].LiveInValue = PN;
159 auto *BBInfo = &BBInfos[BB];
161 if (IsLiveOut && BBInfo->LiveOutValue)
162 return BBInfo->LiveOutValue;
164 if (BBInfo->LiveInValue)
165 return BBInfo->LiveInValue;
172 BBInfo = &BBInfos[BB];
174 if (BBInfo->LiveOutValue) {
175 V = BBInfo->LiveOutValue;
179 if (BBInfo->LiveInValue) {
180 V = BBInfo->LiveInValue;
184 Stack.emplace_back(BBInfo);
190 for (
auto *BBInfo : Stack)
193 BBInfo->LiveInValue = V;
199 for (
auto *BB : IDFBlocks) {
200 auto *
PHI = cast<PHINode>(&BB->
front());
202 PHI->addIncoming(ComputeValue(Pred,
true), Pred);
207 for (
Use *U : R.Uses) {
208 if (!ProcessedUses.
insert(U).second)
211 auto *
User = cast<Instruction>(U->getUser());
213 Value *V = ComputeValue(BB, BB !=
User->getParent());
214 Value *OldVal = U->get();
215 assert(OldVal &&
"Invalid use!");
219 LLVM_DEBUG(
dbgs() <<
"SSAUpdater: replacing " << *OldVal <<
" with " << *V
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This defines the Use class.
static StringRef getName(Value *V)
static BasicBlock * getUserBB(Use *U)
Helper function for finding a block which should have a value for the given user.
static void ComputeLiveInBlocks(const SmallPtrSetImpl< BasicBlock * > &UsingBlocks, const SmallPtrSetImpl< BasicBlock * > &DefBlocks, SmallPtrSetImpl< BasicBlock * > &LiveInBlocks, PredIteratorCache &PredCache)
Given sets of UsingBlocks and DefBlocks, compute the set of LiveInBlocks.
LLVM Basic Block Representation.
const Instruction & front() const
void reserve(size_type NumEntries)
Grow the densemap so that it can contain at least NumEntries items before resizing again.
DomTreeNodeBase * getIDom() const
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
void calculate(SmallVectorImpl< NodeTy * > &IDFBlocks)
Calculate iterated dominance frontiers.
void setLiveInBlocks(const SmallPtrSetImpl< NodeTy * > &Blocks)
Give the IDF calculator the set of blocks in which the value is live on entry to the block.
void setDefiningBlocks(const SmallPtrSetImpl< NodeTy * > &Blocks)
Give the IDF calculator the set of blocks in which the value is defined.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
PredIteratorCache - This class is an extremely trivial cache for predecessor iterator queries.
ArrayRef< BasicBlock * > get(BasicBlock *BB)
LLVM_ABI unsigned AddVariable(StringRef Name, Type *Ty)
Add a new variable to the SSA rewriter.
LLVM_ABI void AddAvailableValue(unsigned Var, BasicBlock *BB, Value *V)
Indicate that a rewritten value is available in the specified block with the specified value.
LLVM_ABI void RewriteAllUses(DominatorTree *DT, SmallVectorImpl< PHINode * > *InsertedPHIs=nullptr)
Perform all the necessary updates, including new PHI-nodes insertion and the requested uses update.
LLVM_ABI void AddUse(unsigned Var, Use *U)
Record a use of the symbolic value.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
A Use represents the edge between a Value definition and its users.
static LLVM_ABI void ValueIsRAUWd(Value *Old, Value *New)
LLVM Value Representation.
bool hasValueHandle() const
Return true if there is a value handle associated with this value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
This is an optimization pass for GlobalISel generic memory operations.
constexpr from_range_t from_range
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
auto make_first_range(ContainerTy &&c)
Given a container of pairs, return a range over the first elements.