class MemorySSAUpdater

Declaration

class MemorySSAUpdater { /* full declaration omitted */ };

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:54

Member Variables

private llvm::MemorySSA* MSSA
private SmallVector<llvm::WeakVH, 16> InsertedPHIs
We use WeakVH rather than a costly deletion to deal with dangling pointers. MemoryPhis are created eagerly and sometimes get zapped shortly afterwards.
private SmallPtrSet<llvm::BasicBlock*, 8> VisitedBlocks
private SmallSet<AssertingVH<llvm::MemoryPhi>, 8> NonOptPhis

Method Overview

  • public MemorySSAUpdater(llvm::MemorySSA * MSSA)
  • private void applyInsertUpdates(ArrayRef<llvm::CFGUpdate>, llvm::DominatorTree & DT, const GraphDiff<llvm::BasicBlock *> * GD)
  • public void applyInsertUpdates(ArrayRef<llvm::CFGUpdate> Updates, llvm::DominatorTree & DT)
  • public void applyUpdates(ArrayRef<llvm::CFGUpdate> Updates, llvm::DominatorTree & DT, bool UpdateDTFirst = false)
  • public void changeToUnreachable(const llvm::Instruction * I)
  • private void cloneUsesAndDefs(llvm::BasicBlock * BB, llvm::BasicBlock * NewBB, const llvm::ValueToValueMapTy & VMap, llvm::PhiToDefMap & MPhiMap, bool CloneWasSimplified = false)
  • public llvm::MemoryUseOrDef * createMemoryAccessAfter(llvm::Instruction * I, llvm::MemoryAccess * Definition, llvm::MemoryAccess * InsertPt)
  • public llvm::MemoryUseOrDef * createMemoryAccessBefore(llvm::Instruction * I, llvm::MemoryAccess * Definition, llvm::MemoryUseOrDef * InsertPt)
  • public llvm::MemoryAccess * createMemoryAccessInBB(llvm::Instruction * I, llvm::MemoryAccess * Definition, const llvm::BasicBlock * BB, MemorySSA::InsertionPlace Point)
  • private void fixupDefs(const SmallVectorImpl<llvm::WeakVH> &)
  • public llvm::MemorySSA * getMemorySSA() const
  • private llvm::MemoryAccess * getPreviousDef(llvm::MemoryAccess *)
  • private llvm::MemoryAccess * getPreviousDefFromEnd(llvm::BasicBlock *, DenseMap<llvm::BasicBlock *, TrackingVH<llvm::MemoryAccess>> &)
  • private llvm::MemoryAccess * getPreviousDefInBlock(llvm::MemoryAccess *)
  • private llvm::MemoryAccess * getPreviousDefRecursive(llvm::BasicBlock *, DenseMap<llvm::BasicBlock *, TrackingVH<llvm::MemoryAccess>> &)
  • public void insertDef(llvm::MemoryDef * Def, bool RenameUses = false)
  • public void insertUse(llvm::MemoryUse * Use, bool RenameUses = false)
  • public void moveAfter(llvm::MemoryUseOrDef * What, llvm::MemoryUseOrDef * Where)
  • private void moveAllAccesses(llvm::BasicBlock * From, llvm::BasicBlock * To, llvm::Instruction * Start)
  • public void moveAllAfterMergeBlocks(llvm::BasicBlock * From, llvm::BasicBlock * To, llvm::Instruction * Start)
  • public void moveAllAfterSpliceBlocks(llvm::BasicBlock * From, llvm::BasicBlock * To, llvm::Instruction * Start)
  • public void moveBefore(llvm::MemoryUseOrDef * What, llvm::MemoryUseOrDef * Where)
  • private template <class WhereType>void moveTo(llvm::MemoryUseOrDef * What, llvm::BasicBlock * BB, WhereType Where)
  • public void moveToPlace(llvm::MemoryUseOrDef * What, llvm::BasicBlock * BB, MemorySSA::InsertionPlace Where)
  • private template <typename Iter>void privateUpdateExitBlocksForClonedLoop(ArrayRef<llvm::BasicBlock *> ExitBlocks, Iter ValuesBegin, Iter ValuesEnd, llvm::DominatorTree & DT)
  • private llvm::MemoryAccess * recursePhi(llvm::MemoryAccess * Phi)
  • public void removeBlocks(const SmallSetVector<llvm::BasicBlock *, 8> & DeadBlocks)
  • public void removeDuplicatePhiEdgesBetween(const llvm::BasicBlock * From, const llvm::BasicBlock * To)
  • public void removeEdge(llvm::BasicBlock * From, llvm::BasicBlock * To)
  • public void removeMemoryAccess(llvm::MemoryAccess *, bool OptimizePhis = false)
  • public void removeMemoryAccess(const llvm::Instruction * I, bool OptimizePhis = false)
  • private template <class RangeType>llvm::MemoryAccess * tryRemoveTrivialPhi(llvm::MemoryPhi * Phi, RangeType & Operands)
  • private llvm::MemoryAccess * tryRemoveTrivialPhi(llvm::MemoryPhi * Phi)
  • private void tryRemoveTrivialPhis(ArrayRef<llvm::WeakVH> UpdatedPHIs)
  • public void updateExitBlocksForClonedLoop(ArrayRef<llvm::BasicBlock *> ExitBlocks, ArrayRef<std::unique_ptr<ValueToValueMapTy>> VMaps, llvm::DominatorTree & DT)
  • public void updateExitBlocksForClonedLoop(ArrayRef<llvm::BasicBlock *> ExitBlocks, const llvm::ValueToValueMapTy & VMap, llvm::DominatorTree & DT)
  • public void updateForClonedBlockIntoPred(llvm::BasicBlock * BB, llvm::BasicBlock * P1, const llvm::ValueToValueMapTy & VM)
  • public void updateForClonedLoop(const llvm::LoopBlocksRPO & LoopBlocks, ArrayRef<llvm::BasicBlock *> ExitBlocks, const llvm::ValueToValueMapTy & VM, bool IgnoreIncomingWithNoClones = false)
  • public void updatePhisWhenInsertingUniqueBackedgeBlock(llvm::BasicBlock * LoopHeader, llvm::BasicBlock * LoopPreheader, llvm::BasicBlock * BackedgeBlock)
  • public void wireOldPredecessorsToNewImmediatePredecessor(llvm::BasicBlock * Old, llvm::BasicBlock * New, ArrayRef<llvm::BasicBlock *> Preds, bool IdenticalEdgesWereMerged = true)

Methods

MemorySSAUpdater(llvm::MemorySSA* MSSA)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:66

Parameters

llvm::MemorySSA* MSSA

void applyInsertUpdates(
    ArrayRef<llvm::CFGUpdate>,
    llvm::DominatorTree& DT,
    const GraphDiff<llvm::BasicBlock*>* GD)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:286

Parameters

ArrayRef<llvm::CFGUpdate>
llvm::DominatorTree& DT
const GraphDiff<llvm::BasicBlock*>* GD

void applyInsertUpdates(
    ArrayRef<llvm::CFGUpdate> Updates,
    llvm::DominatorTree& DT)

Description

Apply CFG insert updates, analogous with the DT edge updates.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:126

Parameters

ArrayRef<llvm::CFGUpdate> Updates
llvm::DominatorTree& DT

void applyUpdates(
    ArrayRef<llvm::CFGUpdate> Updates,
    llvm::DominatorTree& DT,
    bool UpdateDTFirst = false)

Description

Apply CFG updates, analogous with the DT edge updates. By default, the DT is assumed to be already up to date. If UpdateDTFirst is true, first update the DT with the same updates.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:123

Parameters

ArrayRef<llvm::CFGUpdate> Updates
llvm::DominatorTree& DT
bool UpdateDTFirst = false

void changeToUnreachable(
    const llvm::Instruction* I)

Description

Instruction I will be changed to an unreachable. Remove all accesses in I's block that follow I (inclusive), and update the Phis in the blocks' successors.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:239

Parameters

const llvm::Instruction* I

void cloneUsesAndDefs(
    llvm::BasicBlock* BB,
    llvm::BasicBlock* NewBB,
    const llvm::ValueToValueMapTy& VMap,
    llvm::PhiToDefMap& MPhiMap,
    bool CloneWasSimplified = false)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:279

Parameters

llvm::BasicBlock* BB
llvm::BasicBlock* NewBB
const llvm::ValueToValueMapTy& VMap
llvm::PhiToDefMap& MPhiMap
bool CloneWasSimplified = false

llvm::MemoryUseOrDef* createMemoryAccessAfter(
    llvm::Instruction* I,
    llvm::MemoryAccess* Definition,
    llvm::MemoryAccess* InsertPt)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:207

Parameters

llvm::Instruction* I
llvm::MemoryAccess* Definition
llvm::MemoryAccess* InsertPt

llvm::MemoryUseOrDef* createMemoryAccessBefore(
    llvm::Instruction* I,
    llvm::MemoryAccess* Definition,
    llvm::MemoryUseOrDef* InsertPt)

Description

Create a MemoryAccess in MemorySSA before or after an existing MemoryAccess. Returns the new MemoryAccess. This should be called when a memory instruction is created that is being used to replace an existing memory instruction. It will *not* create PHI nodes, or verify the clobbering definition. Note: If a MemoryAccess already exists for I, this function will make it inaccessible and it *must* have removeMemoryAccess called on it.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:204

Parameters

llvm::Instruction* I
llvm::MemoryAccess* Definition
llvm::MemoryUseOrDef* InsertPt

llvm::MemoryAccess* createMemoryAccessInBB(
    llvm::Instruction* I,
    llvm::MemoryAccess* Definition,
    const llvm::BasicBlock* BB,
    MemorySSA::InsertionPlace Point)

Description

Create a MemoryAccess in MemorySSA at a specified point in a block, with a specified clobbering definition. Returns the new MemoryAccess. This should be called when a memory instruction is created that is being used to replace an existing memory instruction. It will *not* create PHI nodes, or verify the clobbering definition. The insertion place is used solely to determine where in the memoryssa access lists the instruction will be placed. The caller is expected to keep ordering the same as instructions. It will return the new MemoryAccess. Note: If a MemoryAccess already exists for I, this function will make it inaccessible and it *must* have removeMemoryAccess called on it.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:190

Parameters

llvm::Instruction* I
llvm::MemoryAccess* Definition
const llvm::BasicBlock* BB
MemorySSA::InsertionPlace Point

void fixupDefs(
    const SmallVectorImpl<llvm::WeakVH>&)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:264

Parameters

const SmallVectorImpl<llvm::WeakVH>&

llvm::MemorySSA* getMemorySSA() const

Description

Get handle on MemorySSA.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:242

llvm::MemoryAccess* getPreviousDef(
    llvm::MemoryAccess*)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:251

Parameters

llvm::MemoryAccess*

llvm::MemoryAccess* getPreviousDefFromEnd(
    llvm::BasicBlock*,
    DenseMap<llvm::BasicBlock*,
             TrackingVH<llvm::MemoryAccess>>&)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:254

Parameters

llvm::BasicBlock*
DenseMap<llvm::BasicBlock*, TrackingVH<llvm::MemoryAccess>>&

llvm::MemoryAccess* getPreviousDefInBlock(
    llvm::MemoryAccess*)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:252

Parameters

llvm::MemoryAccess*

llvm::MemoryAccess* getPreviousDefRecursive(
    llvm::BasicBlock*,
    DenseMap<llvm::BasicBlock*,
             TrackingVH<llvm::MemoryAccess>>&)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:257

Parameters

llvm::BasicBlock*
DenseMap<llvm::BasicBlock*, TrackingVH<llvm::MemoryAccess>>&

void insertDef(llvm::MemoryDef* Def,
               bool RenameUses = false)

Description

Insert a definition into the MemorySSA IR. RenameUses will rename any use below the new def block (and any inserted phis). RenameUses should be set to true if the definition may cause new aliases for loads below it. This is not the case for hoisting or sinking or other forms of code *movement*. It *is* the case for straight code insertion. For example: store a if (foo) { } load a Moving the store into the if block, and calling insertDef, does not require RenameUses. However, changing it to: store a if (foo) { store b } load a Where a mayalias b, *does* require RenameUses be set to true.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:85

Parameters

llvm::MemoryDef* Def
bool RenameUses = false

void insertUse(llvm::MemoryUse* Use,
               bool RenameUses = false)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:86

Parameters

llvm::MemoryUse* Use
bool RenameUses = false

void moveAfter(llvm::MemoryUseOrDef* What,
               llvm::MemoryUseOrDef* Where)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:129

Parameters

llvm::MemoryUseOrDef* What
llvm::MemoryUseOrDef* Where

void moveAllAccesses(llvm::BasicBlock* From,
                     llvm::BasicBlock* To,
                     llvm::Instruction* Start)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:250

Parameters

llvm::BasicBlock* From
llvm::BasicBlock* To
llvm::Instruction* Start

void moveAllAfterMergeBlocks(
    llvm::BasicBlock* From,
    llvm::BasicBlock* To,
    llvm::Instruction* Start)

Description

`From` block was merged into `To`. There is a CFG edge from `To` to `From`.`To` still branches to `From`, but all instructions were moved and `From` is now an empty block; `From` is about to be deleted. Move all accesses from `From` to `To` starting at instruction `Start`. `To` may have multiple successors, `From` has a single predecessor. `From` may have successors with MPhi nodes, replace their incoming block with `To`. |------| |------| | To | | To | |------| | | || => | | \ / | | |------| | | < - Start | From | | | |------| |------|

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:161

Parameters

llvm::BasicBlock* From
llvm::BasicBlock* To
llvm::Instruction* Start

void moveAllAfterSpliceBlocks(
    llvm::BasicBlock* From,
    llvm::BasicBlock* To,
    llvm::Instruction* Start)

Description

`From` block was spliced into `From` and `To`. There is a CFG edge from `From` to `To`. Move all accesses from `From` to `To` starting at instruction `Start`. `To` is newly created BB, so empty of MemorySSA::MemoryAccesses. Edges are already updated, so successors of `To` with MPhi nodes need to update incoming block. |------| |------| | From | | From | | | |------| | | || | | => \ / | | |------| < - Start | | | To | |------| |------|

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:145

Parameters

llvm::BasicBlock* From
llvm::BasicBlock* To
llvm::Instruction* Start

void moveBefore(llvm::MemoryUseOrDef* What,
                llvm::MemoryUseOrDef* Where)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:128

Parameters

llvm::MemoryUseOrDef* What
llvm::MemoryUseOrDef* Where

template <class WhereType>
void moveTo(llvm::MemoryUseOrDef* What,
            llvm::BasicBlock* BB,
            WhereType Where)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:247

Templates

WhereType

Parameters

llvm::MemoryUseOrDef* What
llvm::BasicBlock* BB
WhereType Where

void moveToPlace(llvm::MemoryUseOrDef* What,
                 llvm::BasicBlock* BB,
                 MemorySSA::InsertionPlace Where)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:130

Parameters

llvm::MemoryUseOrDef* What
llvm::BasicBlock* BB
MemorySSA::InsertionPlace Where

template <typename Iter>
void privateUpdateExitBlocksForClonedLoop(
    ArrayRef<llvm::BasicBlock*> ExitBlocks,
    Iter ValuesBegin,
    Iter ValuesEnd,
    llvm::DominatorTree& DT)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:283

Templates

Iter

Parameters

ArrayRef<llvm::BasicBlock*> ExitBlocks
Iter ValuesBegin
Iter ValuesEnd
llvm::DominatorTree& DT

llvm::MemoryAccess* recursePhi(
    llvm::MemoryAccess* Phi)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:259

Parameters

llvm::MemoryAccess* Phi

void removeBlocks(
    const SmallSetVector<llvm::BasicBlock*, 8>&
        DeadBlocks)

Description

Remove all MemoryAcceses in a set of BasicBlocks about to be deleted. Assumption we make here: all uses of deleted defs and phi must either occur in blocks about to be deleted (thus will be deleted as well), or they occur in phis that will simply lose an incoming value. Deleted blocks still have successor info, but their predecessor edges and Phi nodes may already be updated. Instructions in DeadBlocks should be deleted after this call.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:234

Parameters

const SmallSetVector<llvm::BasicBlock*, 8>& DeadBlocks

void removeDuplicatePhiEdgesBetween(
    const llvm::BasicBlock* From,
    const llvm::BasicBlock* To)

Description

Update the MemoryPhi in `To` to have a single incoming edge from `From`, following a CFG change that replaced multiple edges (switch) with a direct branch.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:93

Parameters

const llvm::BasicBlock* From
const llvm::BasicBlock* To

void removeEdge(llvm::BasicBlock* From,
                llvm::BasicBlock* To)

Description

Update the MemoryPhi in `To` following an edge deletion between `From` and `To`. If `To` becomes unreachable, a call to removeBlocks should be made.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:89

Parameters

llvm::BasicBlock* From
llvm::BasicBlock* To

void removeMemoryAccess(llvm::MemoryAccess*,
                        bool OptimizePhis = false)

Description

Remove a MemoryAccess from MemorySSA, including updating all definitions and uses. This should be called when a memory instruction that has a MemoryAccess associated with it is erased from the program. For example, if a store or load is simply erased (not replaced), removeMemoryAccess should be called on the MemoryAccess for that store/load.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:217

Parameters

llvm::MemoryAccess*
bool OptimizePhis = false

void removeMemoryAccess(
    const llvm::Instruction* I,
    bool OptimizePhis = false)

Description

Remove MemoryAccess for a given instruction, if a MemoryAccess exists. This should be called when an instruction (load/store) is deleted from the program.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:222

Parameters

const llvm::Instruction* I
bool OptimizePhis = false

template <class RangeType>
llvm::MemoryAccess* tryRemoveTrivialPhi(
    llvm::MemoryPhi* Phi,
    RangeType& Operands)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:262

Templates

RangeType

Parameters

llvm::MemoryPhi* Phi
RangeType& Operands

llvm::MemoryAccess* tryRemoveTrivialPhi(
    llvm::MemoryPhi* Phi)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:260

Parameters

llvm::MemoryPhi* Phi

void tryRemoveTrivialPhis(
    ArrayRef<llvm::WeakVH> UpdatedPHIs)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:263

Parameters

ArrayRef<llvm::WeakVH> UpdatedPHIs

void updateExitBlocksForClonedLoop(
    ArrayRef<llvm::BasicBlock*> ExitBlocks,
    ArrayRef<std::unique_ptr<ValueToValueMapTy>>
        VMaps,
    llvm::DominatorTree& DT)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:116

Parameters

ArrayRef<llvm::BasicBlock*> ExitBlocks
ArrayRef<std::unique_ptr<ValueToValueMapTy>> VMaps
llvm::DominatorTree& DT

void updateExitBlocksForClonedLoop(
    ArrayRef<llvm::BasicBlock*> ExitBlocks,
    const llvm::ValueToValueMapTy& VMap,
    llvm::DominatorTree& DT)

Description

Update phi nodes in exit block successors following cloning. Exit blocks that were not cloned don't have additional predecessors added.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:113

Parameters

ArrayRef<llvm::BasicBlock*> ExitBlocks
const llvm::ValueToValueMapTy& VMap
llvm::DominatorTree& DT

void updateForClonedBlockIntoPred(
    llvm::BasicBlock* BB,
    llvm::BasicBlock* P1,
    const llvm::ValueToValueMapTy& VM)

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:109

Parameters

llvm::BasicBlock* BB
llvm::BasicBlock* P1
const llvm::ValueToValueMapTy& VM

void updateForClonedLoop(
    const llvm::LoopBlocksRPO& LoopBlocks,
    ArrayRef<llvm::BasicBlock*> ExitBlocks,
    const llvm::ValueToValueMapTy& VM,
    bool IgnoreIncomingWithNoClones = false)

Description

Update MemorySSA after a loop was cloned, given the blocks in RPO order, the exit blocks and a 1:1 mapping of all blocks and instructions cloned. This involves duplicating all defs and uses in the cloned blocks Updating phi nodes in exit block successors is done separately.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:103

Parameters

const llvm::LoopBlocksRPO& LoopBlocks
ArrayRef<llvm::BasicBlock*> ExitBlocks
const llvm::ValueToValueMapTy& VM
bool IgnoreIncomingWithNoClones = false

void updatePhisWhenInsertingUniqueBackedgeBlock(
    llvm::BasicBlock* LoopHeader,
    llvm::BasicBlock* LoopPreheader,
    llvm::BasicBlock* BackedgeBlock)

Description

Update MemorySSA when inserting a unique backedge block for a loop.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:96

Parameters

llvm::BasicBlock* LoopHeader
llvm::BasicBlock* LoopPreheader
llvm::BasicBlock* BackedgeBlock

void wireOldPredecessorsToNewImmediatePredecessor(
    llvm::BasicBlock* Old,
    llvm::BasicBlock* New,
    ArrayRef<llvm::BasicBlock*> Preds,
    bool IdenticalEdgesWereMerged = true)

Description

A new empty BasicBlock (New) now branches directly to Old. Some of Old's predecessors (Preds) are now branching to New instead of Old. If New is the only predecessor, move Old's Phi, if present, to New. Otherwise, add a new Phi in New with appropriate incoming values, and update the incoming values in Old's Phi node too, if present.

Declared at: llvm/include/llvm/Analysis/MemorySSAUpdater.h:168

Parameters

llvm::BasicBlock* Old
llvm::BasicBlock* New
ArrayRef<llvm::BasicBlock*> Preds
bool IdenticalEdgesWereMerged = true