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