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"
25 /// isSafeToLoadUnconditionally - Return true if we know that executing a load
26 /// from this value cannot trap. If it is not obviously safe to load from the
27 /// specified pointer, we do a quick local scan of the basic block containing
28 /// ScanFrom, to determine if the address is already accessed.
29 bool isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom,
32 /// DEF_MAX_INSTS_TO_SCAN - the default number of maximum instructions
33 /// to scan in the block, used by FindAvailableLoadedValue().
34 /// FindAvailableLoadedValue() was introduced in r60148, to improve jump
35 /// threading in part by eliminating partially redundant loads.
36 /// At that point, the value of MaxInstsToScan was already set to '6'
37 /// without documented explanation.
38 /// FIXME: Ask r60148 author for details, and complete this documentation.
39 /// NOTE: As of now, every use of FindAvailableLoadedValue() uses this default
41 #ifndef DEF_MAX_INSTS_TO_SCAN
42 #define DEF_MAX_INSTS_TO_SCAN 6
45 /// FindAvailableLoadedValue - Scan the ScanBB block backwards (starting at
46 /// the instruction before ScanFrom) checking to see if we have the value at
47 /// the memory address *Ptr locally available within a small number of
48 /// instructions. If the value is available, return it.
50 /// If not, return the iterator for the last validated instruction that the
51 /// value would be live through. If we scanned the entire block and didn't
52 /// find something that invalidates *Ptr or provides it, ScanFrom would be
53 /// left at begin() and this returns null. ScanFrom could also be left
55 /// MaxInstsToScan specifies the maximum instructions to scan in the block.
56 /// If it is set to 0, it will scan the whole block. You can also optionally
57 /// specify an alias analysis implementation, which makes this more precise.
59 /// If AATags is non-null and a load or store is found, the AA tags from the
60 /// load or store are recorded there. If there are no AA tags or if no access
61 /// is found, it is left unmodified.
62 Value *FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB,
63 BasicBlock::iterator &ScanFrom,
64 unsigned MaxInstsToScan = DEF_MAX_INSTS_TO_SCAN,
65 AliasAnalysis *AA = nullptr,
66 AAMDNodes *AATags = nullptr);