Home | History | Annotate | Download | only in Analysis
      1 //===- Loads.h - Local load analysis --------------------------------------===//
      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 // This file declares simple local analyses for load instructions.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_ANALYSIS_LOADS_H
     15 #define LLVM_ANALYSIS_LOADS_H
     16 
     17 #include "llvm/Analysis/AliasAnalysis.h"
     18 #include "llvm/IR/BasicBlock.h"
     19 #include "llvm/Support/CommandLine.h"
     20 
     21 namespace llvm {
     22 
     23 class DataLayout;
     24 class MDNode;
     25 
     26 /// isDereferenceablePointer - Return true if this is always a dereferenceable
     27 /// pointer. If the context instruction is specified perform context-sensitive
     28 /// analysis and return true if the pointer is dereferenceable at the
     29 /// specified instruction.
     30 bool isDereferenceablePointer(const Value *V, const DataLayout &DL,
     31                               const Instruction *CtxI = nullptr,
     32                               const DominatorTree *DT = nullptr);
     33 
     34 /// Returns true if V is always a dereferenceable pointer with alignment
     35 /// greater or equal than requested. If the context instruction is specified
     36 /// performs context-sensitive analysis and returns true if the pointer is
     37 /// dereferenceable at the specified instruction.
     38 bool isDereferenceableAndAlignedPointer(const Value *V, unsigned Align,
     39                                         const DataLayout &DL,
     40                                         const Instruction *CtxI = nullptr,
     41                                         const DominatorTree *DT = nullptr);
     42 
     43 /// isSafeToLoadUnconditionally - Return true if we know that executing a load
     44 /// from this value cannot trap.
     45 ///
     46 /// If DT and ScanFrom are specified this method performs context-sensitive
     47 /// analysis and returns true if it is safe to load immediately before ScanFrom.
     48 ///
     49 /// If it is not obviously safe to load from the specified pointer, we do a
     50 /// quick local scan of the basic block containing ScanFrom, to determine if
     51 /// the address is already accessed.
     52 bool isSafeToLoadUnconditionally(Value *V, unsigned Align,
     53                                  const DataLayout &DL,
     54                                  Instruction *ScanFrom = nullptr,
     55                                  const DominatorTree *DT = nullptr);
     56 
     57 /// DefMaxInstsToScan - the default number of maximum instructions
     58 /// to scan in the block, used by FindAvailableLoadedValue().
     59 extern cl::opt<unsigned> DefMaxInstsToScan;
     60 
     61 /// \brief Scan backwards to see if we have the value of the given load
     62 /// available locally within a small number of instructions.
     63 ///
     64 /// You can use this function to scan across multiple blocks: after you call
     65 /// this function, if ScanFrom points at the beginning of the block, it's safe
     66 /// to continue scanning the predecessors.
     67 ///
     68 /// Note that performing load CSE requires special care to make sure the
     69 /// metadata is set appropriately.  In particular, aliasing metadata needs
     70 /// to be merged.  (This doesn't matter for store-to-load forwarding because
     71 /// the only relevant load gets deleted.)
     72 ///
     73 /// \param Load The load we want to replace.
     74 /// \param ScanBB The basic block to scan. FIXME: This is redundant.
     75 /// \param [in,out] ScanFrom The location to start scanning from. When this
     76 /// function returns, it points at the last instruction scanned.
     77 /// \param MaxInstsToScan The maximum number of instructions to scan. If this
     78 /// is zero, the whole block will be scanned.
     79 /// \param AA Optional pointer to alias analysis, to make the scan more
     80 /// precise.
     81 /// \param [out] AATags The aliasing metadata for the operation which produced
     82 /// the value. FIXME: This is basically useless.
     83 /// \param [out] IsLoadCSE Whether the returned value is a load from the same
     84 /// location in memory, as opposed to the value operand of a store.
     85 ///
     86 /// \returns The found value, or nullptr if no value is found.
     87 Value *FindAvailableLoadedValue(LoadInst *Load,
     88                                 BasicBlock *ScanBB,
     89                                 BasicBlock::iterator &ScanFrom,
     90                                 unsigned MaxInstsToScan = DefMaxInstsToScan,
     91                                 AliasAnalysis *AA = nullptr,
     92                                 AAMDNodes *AATags = nullptr,
     93                                 bool *IsLoadCSE = nullptr);
     94 
     95 }
     96 
     97 #endif
     98