10b57cec5SDimitry Andric //===- MemorySSAUpdater.h - Memory SSA Updater-------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // \file
100b57cec5SDimitry Andric // An automatic updater for MemorySSA that handles arbitrary insertion,
110b57cec5SDimitry Andric // deletion, and moves.  It performs phi insertion where necessary, and
120b57cec5SDimitry Andric // automatically updates the MemorySSA IR to be correct.
130b57cec5SDimitry Andric // While updating loads or removing instructions is often easy enough to not
140b57cec5SDimitry Andric // need this, updating stores should generally not be attemped outside this
150b57cec5SDimitry Andric // API.
160b57cec5SDimitry Andric //
170b57cec5SDimitry Andric // Basic API usage:
180b57cec5SDimitry Andric // Create the memory access you want for the instruction (this is mainly so
190b57cec5SDimitry Andric // we know where it is, without having to duplicate the entire set of create
200b57cec5SDimitry Andric // functions MemorySSA supports).
210b57cec5SDimitry Andric // Call insertDef or insertUse depending on whether it's a MemoryUse or a
220b57cec5SDimitry Andric // MemoryDef.
230b57cec5SDimitry Andric // That's it.
240b57cec5SDimitry Andric //
250b57cec5SDimitry Andric // For moving, first, move the instruction itself using the normal SSA
260b57cec5SDimitry Andric // instruction moving API, then just call moveBefore, moveAfter,or moveTo with
270b57cec5SDimitry Andric // the right arguments.
280b57cec5SDimitry Andric //
290b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
300b57cec5SDimitry Andric 
310b57cec5SDimitry Andric #ifndef LLVM_ANALYSIS_MEMORYSSAUPDATER_H
320b57cec5SDimitry Andric #define LLVM_ANALYSIS_MEMORYSSAUPDATER_H
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric #include "llvm/ADT/SetVector.h"
350b57cec5SDimitry Andric #include "llvm/ADT/SmallPtrSet.h"
360b57cec5SDimitry Andric #include "llvm/ADT/SmallSet.h"
370b57cec5SDimitry Andric #include "llvm/ADT/SmallVector.h"
380b57cec5SDimitry Andric #include "llvm/Analysis/LoopInfo.h"
390b57cec5SDimitry Andric #include "llvm/Analysis/LoopIterator.h"
400b57cec5SDimitry Andric #include "llvm/Analysis/MemorySSA.h"
410b57cec5SDimitry Andric #include "llvm/IR/BasicBlock.h"
420b57cec5SDimitry Andric #include "llvm/IR/CFGDiff.h"
430b57cec5SDimitry Andric #include "llvm/IR/Dominators.h"
440b57cec5SDimitry Andric #include "llvm/IR/Module.h"
450b57cec5SDimitry Andric #include "llvm/IR/OperandTraits.h"
460b57cec5SDimitry Andric #include "llvm/IR/Type.h"
470b57cec5SDimitry Andric #include "llvm/IR/Use.h"
480b57cec5SDimitry Andric #include "llvm/IR/User.h"
490b57cec5SDimitry Andric #include "llvm/IR/Value.h"
500b57cec5SDimitry Andric #include "llvm/IR/ValueHandle.h"
510b57cec5SDimitry Andric #include "llvm/IR/ValueMap.h"
520b57cec5SDimitry Andric #include "llvm/Pass.h"
530b57cec5SDimitry Andric #include "llvm/Support/Casting.h"
540b57cec5SDimitry Andric #include "llvm/Support/ErrorHandling.h"
550b57cec5SDimitry Andric 
560b57cec5SDimitry Andric namespace llvm {
570b57cec5SDimitry Andric 
580b57cec5SDimitry Andric class Function;
590b57cec5SDimitry Andric class Instruction;
600b57cec5SDimitry Andric class MemoryAccess;
610b57cec5SDimitry Andric class LLVMContext;
620b57cec5SDimitry Andric class raw_ostream;
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric using ValueToValueMapTy = ValueMap<const Value *, WeakTrackingVH>;
650b57cec5SDimitry Andric using PhiToDefMap = SmallDenseMap<MemoryPhi *, MemoryAccess *>;
660b57cec5SDimitry Andric using CFGUpdate = cfg::Update<BasicBlock *>;
670b57cec5SDimitry Andric using GraphDiffInvBBPair =
680b57cec5SDimitry Andric     std::pair<const GraphDiff<BasicBlock *> *, Inverse<BasicBlock *>>;
690b57cec5SDimitry Andric 
700b57cec5SDimitry Andric class MemorySSAUpdater {
710b57cec5SDimitry Andric private:
720b57cec5SDimitry Andric   MemorySSA *MSSA;
730b57cec5SDimitry Andric 
740b57cec5SDimitry Andric   /// We use WeakVH rather than a costly deletion to deal with dangling pointers.
750b57cec5SDimitry Andric   /// MemoryPhis are created eagerly and sometimes get zapped shortly afterwards.
760b57cec5SDimitry Andric   SmallVector<WeakVH, 16> InsertedPHIs;
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric   SmallPtrSet<BasicBlock *, 8> VisitedBlocks;
790b57cec5SDimitry Andric   SmallSet<AssertingVH<MemoryPhi>, 8> NonOptPhis;
800b57cec5SDimitry Andric 
810b57cec5SDimitry Andric public:
820b57cec5SDimitry Andric   MemorySSAUpdater(MemorySSA *MSSA) : MSSA(MSSA) {}
830b57cec5SDimitry Andric 
840b57cec5SDimitry Andric   /// Insert a definition into the MemorySSA IR.  RenameUses will rename any use
850b57cec5SDimitry Andric   /// below the new def block (and any inserted phis).  RenameUses should be set
860b57cec5SDimitry Andric   /// to true if the definition may cause new aliases for loads below it.  This
870b57cec5SDimitry Andric   /// is not the case for hoisting or sinking or other forms of code *movement*.
880b57cec5SDimitry Andric   /// It *is* the case for straight code insertion.
890b57cec5SDimitry Andric   /// For example:
900b57cec5SDimitry Andric   /// store a
910b57cec5SDimitry Andric   /// if (foo) { }
920b57cec5SDimitry Andric   /// load a
930b57cec5SDimitry Andric   ///
940b57cec5SDimitry Andric   /// Moving the store into the if block, and calling insertDef, does not
950b57cec5SDimitry Andric   /// require RenameUses.
960b57cec5SDimitry Andric   /// However, changing it to:
970b57cec5SDimitry Andric   /// store a
980b57cec5SDimitry Andric   /// if (foo) { store b }
990b57cec5SDimitry Andric   /// load a
1000b57cec5SDimitry Andric   /// Where a mayalias b, *does* require RenameUses be set to true.
1010b57cec5SDimitry Andric   void insertDef(MemoryDef *Def, bool RenameUses = false);
1020b57cec5SDimitry Andric   void insertUse(MemoryUse *Use);
1030b57cec5SDimitry Andric   /// Update the MemoryPhi in `To` following an edge deletion between `From` and
1040b57cec5SDimitry Andric   /// `To`. If `To` becomes unreachable, a call to removeBlocks should be made.
1050b57cec5SDimitry Andric   void removeEdge(BasicBlock *From, BasicBlock *To);
1060b57cec5SDimitry Andric   /// Update the MemoryPhi in `To` to have a single incoming edge from `From`,
1070b57cec5SDimitry Andric   /// following a CFG change that replaced multiple edges (switch) with a direct
1080b57cec5SDimitry Andric   /// branch.
1090b57cec5SDimitry Andric   void removeDuplicatePhiEdgesBetween(const BasicBlock *From,
1100b57cec5SDimitry Andric                                       const BasicBlock *To);
1110b57cec5SDimitry Andric   /// Update MemorySSA when inserting a unique backedge block for a loop.
1120b57cec5SDimitry Andric   void updatePhisWhenInsertingUniqueBackedgeBlock(BasicBlock *LoopHeader,
1130b57cec5SDimitry Andric                                                   BasicBlock *LoopPreheader,
1140b57cec5SDimitry Andric                                                   BasicBlock *BackedgeBlock);
1150b57cec5SDimitry Andric   /// Update MemorySSA after a loop was cloned, given the blocks in RPO order,
1160b57cec5SDimitry Andric   /// the exit blocks and a 1:1 mapping of all blocks and instructions
1170b57cec5SDimitry Andric   /// cloned. This involves duplicating all defs and uses in the cloned blocks
1180b57cec5SDimitry Andric   /// Updating phi nodes in exit block successors is done separately.
1190b57cec5SDimitry Andric   void updateForClonedLoop(const LoopBlocksRPO &LoopBlocks,
1200b57cec5SDimitry Andric                            ArrayRef<BasicBlock *> ExitBlocks,
1210b57cec5SDimitry Andric                            const ValueToValueMapTy &VM,
1220b57cec5SDimitry Andric                            bool IgnoreIncomingWithNoClones = false);
1230b57cec5SDimitry Andric   // Block BB was fully or partially cloned into its predecessor P1. Map
1240b57cec5SDimitry Andric   // contains the 1:1 mapping of instructions cloned and VM[BB]=P1.
1250b57cec5SDimitry Andric   void updateForClonedBlockIntoPred(BasicBlock *BB, BasicBlock *P1,
1260b57cec5SDimitry Andric                                     const ValueToValueMapTy &VM);
1270b57cec5SDimitry Andric   /// Update phi nodes in exit block successors following cloning. Exit blocks
1280b57cec5SDimitry Andric   /// that were not cloned don't have additional predecessors added.
1290b57cec5SDimitry Andric   void updateExitBlocksForClonedLoop(ArrayRef<BasicBlock *> ExitBlocks,
1300b57cec5SDimitry Andric                                      const ValueToValueMapTy &VMap,
1310b57cec5SDimitry Andric                                      DominatorTree &DT);
1320b57cec5SDimitry Andric   void updateExitBlocksForClonedLoop(
1330b57cec5SDimitry Andric       ArrayRef<BasicBlock *> ExitBlocks,
1340b57cec5SDimitry Andric       ArrayRef<std::unique_ptr<ValueToValueMapTy>> VMaps, DominatorTree &DT);
1350b57cec5SDimitry Andric 
1360b57cec5SDimitry Andric   /// Apply CFG updates, analogous with the DT edge updates.
1370b57cec5SDimitry Andric   void applyUpdates(ArrayRef<CFGUpdate> Updates, DominatorTree &DT);
1380b57cec5SDimitry Andric   /// Apply CFG insert updates, analogous with the DT edge updates.
1390b57cec5SDimitry Andric   void applyInsertUpdates(ArrayRef<CFGUpdate> Updates, DominatorTree &DT);
1400b57cec5SDimitry Andric 
1410b57cec5SDimitry Andric   void moveBefore(MemoryUseOrDef *What, MemoryUseOrDef *Where);
1420b57cec5SDimitry Andric   void moveAfter(MemoryUseOrDef *What, MemoryUseOrDef *Where);
1430b57cec5SDimitry Andric   void moveToPlace(MemoryUseOrDef *What, BasicBlock *BB,
1440b57cec5SDimitry Andric                    MemorySSA::InsertionPlace Where);
1450b57cec5SDimitry Andric   /// `From` block was spliced into `From` and `To`. There is a CFG edge from
1460b57cec5SDimitry Andric   /// `From` to `To`. Move all accesses from `From` to `To` starting at
1470b57cec5SDimitry Andric   /// instruction `Start`. `To` is newly created BB, so empty of
1480b57cec5SDimitry Andric   /// MemorySSA::MemoryAccesses. Edges are already updated, so successors of
1490b57cec5SDimitry Andric   /// `To` with MPhi nodes need to update incoming block.
1500b57cec5SDimitry Andric   /// |------|        |------|
1510b57cec5SDimitry Andric   /// | From |        | From |
1520b57cec5SDimitry Andric   /// |      |        |------|
1530b57cec5SDimitry Andric   /// |      |           ||
1540b57cec5SDimitry Andric   /// |      |   =>      \/
1550b57cec5SDimitry Andric   /// |      |        |------|  <- Start
1560b57cec5SDimitry Andric   /// |      |        |  To  |
1570b57cec5SDimitry Andric   /// |------|        |------|
1580b57cec5SDimitry Andric   void moveAllAfterSpliceBlocks(BasicBlock *From, BasicBlock *To,
1590b57cec5SDimitry Andric                                 Instruction *Start);
1600b57cec5SDimitry Andric   /// `From` block was merged into `To`. There is a CFG edge from `To` to
1610b57cec5SDimitry Andric   /// `From`.`To` still branches to `From`, but all instructions were moved and
1620b57cec5SDimitry Andric   /// `From` is now an empty block; `From` is about to be deleted. Move all
1630b57cec5SDimitry Andric   /// accesses from `From` to `To` starting at instruction `Start`. `To` may
1640b57cec5SDimitry Andric   /// have multiple successors, `From` has a single predecessor. `From` may have
1650b57cec5SDimitry Andric   /// successors with MPhi nodes, replace their incoming block with `To`.
1660b57cec5SDimitry Andric   /// |------|        |------|
1670b57cec5SDimitry Andric   /// |  To  |        |  To  |
1680b57cec5SDimitry Andric   /// |------|        |      |
1690b57cec5SDimitry Andric   ///    ||      =>   |      |
1700b57cec5SDimitry Andric   ///    \/           |      |
1710b57cec5SDimitry Andric   /// |------|        |      |  <- Start
1720b57cec5SDimitry Andric   /// | From |        |      |
1730b57cec5SDimitry Andric   /// |------|        |------|
1740b57cec5SDimitry Andric   void moveAllAfterMergeBlocks(BasicBlock *From, BasicBlock *To,
1750b57cec5SDimitry Andric                                Instruction *Start);
1760b57cec5SDimitry Andric   /// A new empty BasicBlock (New) now branches directly to Old. Some of
1770b57cec5SDimitry Andric   /// Old's predecessors (Preds) are now branching to New instead of Old.
1780b57cec5SDimitry Andric   /// If New is the only predecessor, move Old's Phi, if present, to New.
1790b57cec5SDimitry Andric   /// Otherwise, add a new Phi in New with appropriate incoming values, and
1800b57cec5SDimitry Andric   /// update the incoming values in Old's Phi node too, if present.
1810b57cec5SDimitry Andric   void wireOldPredecessorsToNewImmediatePredecessor(
1820b57cec5SDimitry Andric       BasicBlock *Old, BasicBlock *New, ArrayRef<BasicBlock *> Preds,
1830b57cec5SDimitry Andric       bool IdenticalEdgesWereMerged = true);
1840b57cec5SDimitry Andric   // The below are utility functions. Other than creation of accesses to pass
1850b57cec5SDimitry Andric   // to insertDef, and removeAccess to remove accesses, you should generally
1860b57cec5SDimitry Andric   // not attempt to update memoryssa yourself. It is very non-trivial to get
1870b57cec5SDimitry Andric   // the edge cases right, and the above calls already operate in near-optimal
1880b57cec5SDimitry Andric   // time bounds.
1890b57cec5SDimitry Andric 
1900b57cec5SDimitry Andric   /// Create a MemoryAccess in MemorySSA at a specified point in a block,
1910b57cec5SDimitry Andric   /// with a specified clobbering definition.
1920b57cec5SDimitry Andric   ///
1930b57cec5SDimitry Andric   /// Returns the new MemoryAccess.
1940b57cec5SDimitry Andric   /// This should be called when a memory instruction is created that is being
1950b57cec5SDimitry Andric   /// used to replace an existing memory instruction. It will *not* create PHI
1960b57cec5SDimitry Andric   /// nodes, or verify the clobbering definition. The insertion place is used
1970b57cec5SDimitry Andric   /// solely to determine where in the memoryssa access lists the instruction
1980b57cec5SDimitry Andric   /// will be placed. The caller is expected to keep ordering the same as
1990b57cec5SDimitry Andric   /// instructions.
2000b57cec5SDimitry Andric   /// It will return the new MemoryAccess.
2010b57cec5SDimitry Andric   /// Note: If a MemoryAccess already exists for I, this function will make it
2020b57cec5SDimitry Andric   /// inaccessible and it *must* have removeMemoryAccess called on it.
2030b57cec5SDimitry Andric   MemoryAccess *createMemoryAccessInBB(Instruction *I, MemoryAccess *Definition,
2040b57cec5SDimitry Andric                                        const BasicBlock *BB,
2050b57cec5SDimitry Andric                                        MemorySSA::InsertionPlace Point);
2060b57cec5SDimitry Andric 
2070b57cec5SDimitry Andric   /// Create a MemoryAccess in MemorySSA before or after an existing
2080b57cec5SDimitry Andric   /// MemoryAccess.
2090b57cec5SDimitry Andric   ///
2100b57cec5SDimitry Andric   /// Returns the new MemoryAccess.
2110b57cec5SDimitry Andric   /// This should be called when a memory instruction is created that is being
2120b57cec5SDimitry Andric   /// used to replace an existing memory instruction. It will *not* create PHI
2130b57cec5SDimitry Andric   /// nodes, or verify the clobbering definition.
2140b57cec5SDimitry Andric   ///
2150b57cec5SDimitry Andric   /// Note: If a MemoryAccess already exists for I, this function will make it
2160b57cec5SDimitry Andric   /// inaccessible and it *must* have removeMemoryAccess called on it.
2170b57cec5SDimitry Andric   MemoryUseOrDef *createMemoryAccessBefore(Instruction *I,
2180b57cec5SDimitry Andric                                            MemoryAccess *Definition,
2190b57cec5SDimitry Andric                                            MemoryUseOrDef *InsertPt);
2200b57cec5SDimitry Andric   MemoryUseOrDef *createMemoryAccessAfter(Instruction *I,
2210b57cec5SDimitry Andric                                           MemoryAccess *Definition,
2220b57cec5SDimitry Andric                                           MemoryAccess *InsertPt);
2230b57cec5SDimitry Andric 
2240b57cec5SDimitry Andric   /// Remove a MemoryAccess from MemorySSA, including updating all
2250b57cec5SDimitry Andric   /// definitions and uses.
2260b57cec5SDimitry Andric   /// This should be called when a memory instruction that has a MemoryAccess
2270b57cec5SDimitry Andric   /// associated with it is erased from the program.  For example, if a store or
2280b57cec5SDimitry Andric   /// load is simply erased (not replaced), removeMemoryAccess should be called
2290b57cec5SDimitry Andric   /// on the MemoryAccess for that store/load.
2300b57cec5SDimitry Andric   void removeMemoryAccess(MemoryAccess *, bool OptimizePhis = false);
2310b57cec5SDimitry Andric 
2320b57cec5SDimitry Andric   /// Remove MemoryAccess for a given instruction, if a MemoryAccess exists.
2330b57cec5SDimitry Andric   /// This should be called when an instruction (load/store) is deleted from
2340b57cec5SDimitry Andric   /// the program.
2350b57cec5SDimitry Andric   void removeMemoryAccess(const Instruction *I, bool OptimizePhis = false) {
2360b57cec5SDimitry Andric     if (MemoryAccess *MA = MSSA->getMemoryAccess(I))
2370b57cec5SDimitry Andric       removeMemoryAccess(MA, OptimizePhis);
2380b57cec5SDimitry Andric   }
2390b57cec5SDimitry Andric 
2400b57cec5SDimitry Andric   /// Remove all MemoryAcceses in a set of BasicBlocks about to be deleted.
2410b57cec5SDimitry Andric   /// Assumption we make here: all uses of deleted defs and phi must either
2420b57cec5SDimitry Andric   /// occur in blocks about to be deleted (thus will be deleted as well), or
2430b57cec5SDimitry Andric   /// they occur in phis that will simply lose an incoming value.
2440b57cec5SDimitry Andric   /// Deleted blocks still have successor info, but their predecessor edges and
2450b57cec5SDimitry Andric   /// Phi nodes may already be updated. Instructions in DeadBlocks should be
2460b57cec5SDimitry Andric   /// deleted after this call.
2470b57cec5SDimitry Andric   void removeBlocks(const SmallSetVector<BasicBlock *, 8> &DeadBlocks);
2480b57cec5SDimitry Andric 
2490b57cec5SDimitry Andric   /// Instruction I will be changed to an unreachable. Remove all accesses in
2500b57cec5SDimitry Andric   /// I's block that follow I (inclusive), and update the Phis in the blocks'
2510b57cec5SDimitry Andric   /// successors.
2520b57cec5SDimitry Andric   void changeToUnreachable(const Instruction *I);
2530b57cec5SDimitry Andric 
2540b57cec5SDimitry Andric   /// Conditional branch BI is changed or replaced with an unconditional branch
2550b57cec5SDimitry Andric   /// to `To`. Update Phis in BI's successors to remove BI's BB.
2560b57cec5SDimitry Andric   void changeCondBranchToUnconditionalTo(const BranchInst *BI,
2570b57cec5SDimitry Andric                                          const BasicBlock *To);
2580b57cec5SDimitry Andric 
2590b57cec5SDimitry Andric   /// Get handle on MemorySSA.
2600b57cec5SDimitry Andric   MemorySSA* getMemorySSA() const { return MSSA; }
2610b57cec5SDimitry Andric 
2620b57cec5SDimitry Andric private:
2630b57cec5SDimitry Andric   // Move What before Where in the MemorySSA IR.
2640b57cec5SDimitry Andric   template <class WhereType>
2650b57cec5SDimitry Andric   void moveTo(MemoryUseOrDef *What, BasicBlock *BB, WhereType Where);
2660b57cec5SDimitry Andric   // Move all memory accesses from `From` to `To` starting at `Start`.
2670b57cec5SDimitry Andric   // Restrictions apply, see public wrappers of this method.
2680b57cec5SDimitry Andric   void moveAllAccesses(BasicBlock *From, BasicBlock *To, Instruction *Start);
2690b57cec5SDimitry Andric   MemoryAccess *getPreviousDef(MemoryAccess *);
2700b57cec5SDimitry Andric   MemoryAccess *getPreviousDefInBlock(MemoryAccess *);
2710b57cec5SDimitry Andric   MemoryAccess *
2720b57cec5SDimitry Andric   getPreviousDefFromEnd(BasicBlock *,
2730b57cec5SDimitry Andric                         DenseMap<BasicBlock *, TrackingVH<MemoryAccess>> &);
2740b57cec5SDimitry Andric   MemoryAccess *
2750b57cec5SDimitry Andric   getPreviousDefRecursive(BasicBlock *,
2760b57cec5SDimitry Andric                           DenseMap<BasicBlock *, TrackingVH<MemoryAccess>> &);
2770b57cec5SDimitry Andric   MemoryAccess *recursePhi(MemoryAccess *Phi);
2780b57cec5SDimitry Andric   template <class RangeType>
2790b57cec5SDimitry Andric   MemoryAccess *tryRemoveTrivialPhi(MemoryPhi *Phi, RangeType &Operands);
2800b57cec5SDimitry Andric   void tryRemoveTrivialPhis(ArrayRef<WeakVH> UpdatedPHIs);
2810b57cec5SDimitry Andric   void fixupDefs(const SmallVectorImpl<WeakVH> &);
2820b57cec5SDimitry Andric   // Clone all uses and defs from BB to NewBB given a 1:1 map of all
2830b57cec5SDimitry Andric   // instructions and blocks cloned, and a map of MemoryPhi : Definition
2840b57cec5SDimitry Andric   // (MemoryAccess Phi or Def). VMap maps old instructions to cloned
2850b57cec5SDimitry Andric   // instructions and old blocks to cloned blocks. MPhiMap, is created in the
2860b57cec5SDimitry Andric   // caller of this private method, and maps existing MemoryPhis to new
2870b57cec5SDimitry Andric   // definitions that new MemoryAccesses must point to. These definitions may
2880b57cec5SDimitry Andric   // not necessarily be MemoryPhis themselves, they may be MemoryDefs. As such,
2890b57cec5SDimitry Andric   // the map is between MemoryPhis and MemoryAccesses, where the MemoryAccesses
2900b57cec5SDimitry Andric   // may be MemoryPhis or MemoryDefs and not MemoryUses.
2910b57cec5SDimitry Andric   // If CloneWasSimplified = true, the clone was exact. Otherwise, assume that
2920b57cec5SDimitry Andric   // the clone involved simplifications that may have: (1) turned a MemoryUse
2930b57cec5SDimitry Andric   // into an instruction that MemorySSA has no representation for, or (2) turned
2940b57cec5SDimitry Andric   // a MemoryDef into a MemoryUse or an instruction that MemorySSA has no
2950b57cec5SDimitry Andric   // representation for. No other cases are supported.
2960b57cec5SDimitry Andric   void cloneUsesAndDefs(BasicBlock *BB, BasicBlock *NewBB,
2970b57cec5SDimitry Andric                         const ValueToValueMapTy &VMap, PhiToDefMap &MPhiMap,
2980b57cec5SDimitry Andric                         bool CloneWasSimplified = false);
2990b57cec5SDimitry Andric   template <typename Iter>
3000b57cec5SDimitry Andric   void privateUpdateExitBlocksForClonedLoop(ArrayRef<BasicBlock *> ExitBlocks,
3010b57cec5SDimitry Andric                                             Iter ValuesBegin, Iter ValuesEnd,
3020b57cec5SDimitry Andric                                             DominatorTree &DT);
3030b57cec5SDimitry Andric   void applyInsertUpdates(ArrayRef<CFGUpdate>, DominatorTree &DT,
3040b57cec5SDimitry Andric                           const GraphDiff<BasicBlock *> *GD);
3050b57cec5SDimitry Andric };
3060b57cec5SDimitry Andric } // end namespace llvm
3070b57cec5SDimitry Andric 
3080b57cec5SDimitry Andric #endif // LLVM_ANALYSIS_MEMORYSSAUPDATER_H
309