LCOV - code coverage report
Current view: top level - include/llvm/Analysis - MemorySSAUpdater.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 2 2 100.0 %
Date: 2018-06-17 00:07:59 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- MemorySSAUpdater.h - Memory SSA Updater-------------------*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // \file
      11             : // An automatic updater for MemorySSA that handles arbitrary insertion,
      12             : // deletion, and moves.  It performs phi insertion where necessary, and
      13             : // automatically updates the MemorySSA IR to be correct.
      14             : // While updating loads or removing instructions is often easy enough to not
      15             : // need this, updating stores should generally not be attemped outside this
      16             : // API.
      17             : //
      18             : // Basic API usage:
      19             : // Create the memory access you want for the instruction (this is mainly so
      20             : // we know where it is, without having to duplicate the entire set of create
      21             : // functions MemorySSA supports).
      22             : // Call insertDef or insertUse depending on whether it's a MemoryUse or a
      23             : // MemoryDef.
      24             : // That's it.
      25             : //
      26             : // For moving, first, move the instruction itself using the normal SSA
      27             : // instruction moving API, then just call moveBefore, moveAfter,or moveTo with
      28             : // the right arguments.
      29             : //
      30             : //===----------------------------------------------------------------------===//
      31             : 
      32             : #ifndef LLVM_ANALYSIS_MEMORYSSAUPDATER_H
      33             : #define LLVM_ANALYSIS_MEMORYSSAUPDATER_H
      34             : 
      35             : #include "llvm/ADT/SmallPtrSet.h"
      36             : #include "llvm/ADT/SmallSet.h"
      37             : #include "llvm/ADT/SmallVector.h"
      38             : #include "llvm/Analysis/MemorySSA.h"
      39             : #include "llvm/IR/BasicBlock.h"
      40             : #include "llvm/IR/Dominators.h"
      41             : #include "llvm/IR/Module.h"
      42             : #include "llvm/IR/OperandTraits.h"
      43             : #include "llvm/IR/Type.h"
      44             : #include "llvm/IR/Use.h"
      45             : #include "llvm/IR/User.h"
      46             : #include "llvm/IR/Value.h"
      47             : #include "llvm/IR/ValueHandle.h"
      48             : #include "llvm/Pass.h"
      49             : #include "llvm/Support/Casting.h"
      50             : #include "llvm/Support/ErrorHandling.h"
      51             : 
      52             : namespace llvm {
      53             : 
      54             : class Function;
      55             : class Instruction;
      56             : class MemoryAccess;
      57             : class LLVMContext;
      58             : class raw_ostream;
      59             : 
      60      283684 : class MemorySSAUpdater {
      61             : private:
      62             :   MemorySSA *MSSA;
      63             :   SmallVector<MemoryPhi *, 8> InsertedPHIs;
      64             :   SmallPtrSet<BasicBlock *, 8> VisitedBlocks;
      65             :   SmallSet<AssertingVH<MemoryPhi>, 8> NonOptPhis;
      66             : 
      67             : public:
      68      141842 :   MemorySSAUpdater(MemorySSA *MSSA) : MSSA(MSSA) {}
      69             :   /// Insert a definition into the MemorySSA IR.  RenameUses will rename any use
      70             :   /// below the new def block (and any inserted phis).  RenameUses should be set
      71             :   /// to true if the definition may cause new aliases for loads below it.  This
      72             :   /// is not the case for hoisting or sinking or other forms of code *movement*.
      73             :   /// It *is* the case for straight code insertion.
      74             :   /// For example:
      75             :   /// store a
      76             :   /// if (foo) { }
      77             :   /// load a
      78             :   ///
      79             :   /// Moving the store into the if block, and calling insertDef, does not
      80             :   /// require RenameUses.
      81             :   /// However, changing it to:
      82             :   /// store a
      83             :   /// if (foo) { store b }
      84             :   /// load a
      85             :   /// Where a mayalias b, *does* require RenameUses be set to true.
      86             :   void insertDef(MemoryDef *Def, bool RenameUses = false);
      87             :   void insertUse(MemoryUse *Use);
      88             :   void moveBefore(MemoryUseOrDef *What, MemoryUseOrDef *Where);
      89             :   void moveAfter(MemoryUseOrDef *What, MemoryUseOrDef *Where);
      90             :   void moveToPlace(MemoryUseOrDef *What, BasicBlock *BB,
      91             :                    MemorySSA::InsertionPlace Where);
      92             : 
      93             :   // The below are utility functions. Other than creation of accesses to pass
      94             :   // to insertDef, and removeAccess to remove accesses, you should generally
      95             :   // not attempt to update memoryssa yourself. It is very non-trivial to get
      96             :   // the edge cases right, and the above calls already operate in near-optimal
      97             :   // time bounds.
      98             : 
      99             :   /// Create a MemoryAccess in MemorySSA at a specified point in a block,
     100             :   /// with a specified clobbering definition.
     101             :   ///
     102             :   /// Returns the new MemoryAccess.
     103             :   /// This should be called when a memory instruction is created that is being
     104             :   /// used to replace an existing memory instruction. It will *not* create PHI
     105             :   /// nodes, or verify the clobbering definition. The insertion place is used
     106             :   /// solely to determine where in the memoryssa access lists the instruction
     107             :   /// will be placed. The caller is expected to keep ordering the same as
     108             :   /// instructions.
     109             :   /// It will return the new MemoryAccess.
     110             :   /// Note: If a MemoryAccess already exists for I, this function will make it
     111             :   /// inaccessible and it *must* have removeMemoryAccess called on it.
     112             :   MemoryAccess *createMemoryAccessInBB(Instruction *I, MemoryAccess *Definition,
     113             :                                        const BasicBlock *BB,
     114             :                                        MemorySSA::InsertionPlace Point);
     115             : 
     116             :   /// Create a MemoryAccess in MemorySSA before or after an existing
     117             :   /// MemoryAccess.
     118             :   ///
     119             :   /// Returns the new MemoryAccess.
     120             :   /// This should be called when a memory instruction is created that is being
     121             :   /// used to replace an existing memory instruction. It will *not* create PHI
     122             :   /// nodes, or verify the clobbering definition.
     123             :   ///
     124             :   /// Note: If a MemoryAccess already exists for I, this function will make it
     125             :   /// inaccessible and it *must* have removeMemoryAccess called on it.
     126             :   MemoryUseOrDef *createMemoryAccessBefore(Instruction *I,
     127             :                                            MemoryAccess *Definition,
     128             :                                            MemoryUseOrDef *InsertPt);
     129             :   MemoryUseOrDef *createMemoryAccessAfter(Instruction *I,
     130             :                                           MemoryAccess *Definition,
     131             :                                           MemoryAccess *InsertPt);
     132             : 
     133             :   /// Remove a MemoryAccess from MemorySSA, including updating all
     134             :   /// definitions and uses.
     135             :   /// This should be called when a memory instruction that has a MemoryAccess
     136             :   /// associated with it is erased from the program.  For example, if a store or
     137             :   /// load is simply erased (not replaced), removeMemoryAccess should be called
     138             :   /// on the MemoryAccess for that store/load.
     139             :   void removeMemoryAccess(MemoryAccess *);
     140             : 
     141             : private:
     142             :   // Move What before Where in the MemorySSA IR.
     143             :   template <class WhereType>
     144             :   void moveTo(MemoryUseOrDef *What, BasicBlock *BB, WhereType Where);
     145             :   MemoryAccess *getPreviousDef(MemoryAccess *);
     146             :   MemoryAccess *getPreviousDefInBlock(MemoryAccess *);
     147             :   MemoryAccess *
     148             :   getPreviousDefFromEnd(BasicBlock *,
     149             :                         DenseMap<BasicBlock *, TrackingVH<MemoryAccess>> &);
     150             :   MemoryAccess *
     151             :   getPreviousDefRecursive(BasicBlock *,
     152             :                           DenseMap<BasicBlock *, TrackingVH<MemoryAccess>> &);
     153             :   MemoryAccess *recursePhi(MemoryAccess *Phi);
     154             :   template <class RangeType>
     155             :   MemoryAccess *tryRemoveTrivialPhi(MemoryPhi *Phi, RangeType &Operands);
     156             :   void fixupDefs(const SmallVectorImpl<MemoryAccess *> &);
     157             : };
     158             : } // end namespace llvm
     159             : 
     160             : #endif // LLVM_ANALYSIS_MEMORYSSAUPDATER_H

Generated by: LCOV version 1.13