1 //===- Loads.h - Local load analysis --------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares simple local analyses for load instructions.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_LOADS_H
15 #define LLVM_ANALYSIS_LOADS_H
17 #include "llvm/Analysis/AliasAnalysis.h"
18 #include "llvm/IR/BasicBlock.h"
19 #include "llvm/Support/CommandLine.h"
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);
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,
40 const Instruction *CtxI = nullptr,
41 const DominatorTree *DT = nullptr);
43 /// isSafeToLoadUnconditionally - Return true if we know that executing a load
44 /// from this value cannot trap.
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.
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,
54 Instruction *ScanFrom = nullptr,
55 const DominatorTree *DT = nullptr);
57 /// DefMaxInstsToScan - the default number of maximum instructions
58 /// to scan in the block, used by FindAvailableLoadedValue().
59 extern cl::opt<unsigned> DefMaxInstsToScan;
61 /// \brief Scan backwards to see if we have the value of the given load
62 /// available locally within a small number of instructions.
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.
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.)
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
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.
86 /// \returns The found value, or nullptr if no value is found.
87 Value *FindAvailableLoadedValue(LoadInst *Load,
89 BasicBlock::iterator &ScanFrom,
90 unsigned MaxInstsToScan = DefMaxInstsToScan,
91 AliasAnalysis *AA = nullptr,
92 AAMDNodes *AATags = nullptr,
93 bool *IsLoadCSE = nullptr);