1210006Srdivacky//===- Loads.h - Local load analysis --------------------------------------===//
2210006Srdivacky//
3210006Srdivacky//                     The LLVM Compiler Infrastructure
4210006Srdivacky//
5210006Srdivacky// This file is distributed under the University of Illinois Open Source
6210006Srdivacky// License. See LICENSE.TXT for details.
7210006Srdivacky//
8210006Srdivacky//===----------------------------------------------------------------------===//
9210006Srdivacky//
10210006Srdivacky// This file declares simple local analyses for load instructions.
11210006Srdivacky//
12210006Srdivacky//===----------------------------------------------------------------------===//
13210006Srdivacky
14210006Srdivacky#ifndef LLVM_ANALYSIS_LOADS_H
15210006Srdivacky#define LLVM_ANALYSIS_LOADS_H
16210006Srdivacky
17249423Sdim#include "llvm/IR/BasicBlock.h"
18210006Srdivacky
19210006Srdivackynamespace llvm {
20210006Srdivacky
21210006Srdivackyclass AliasAnalysis;
22243830Sdimclass DataLayout;
23234353Sdimclass MDNode;
24210006Srdivacky
25210006Srdivacky/// isSafeToLoadUnconditionally - Return true if we know that executing a load
26210006Srdivacky/// from this value cannot trap.  If it is not obviously safe to load from the
27210006Srdivacky/// specified pointer, we do a quick local scan of the basic block containing
28210006Srdivacky/// ScanFrom, to determine if the address is already accessed.
29210006Srdivackybool isSafeToLoadUnconditionally(Value *V, Instruction *ScanFrom,
30243830Sdim                                 unsigned Align, const DataLayout *TD = 0);
31210006Srdivacky
32210006Srdivacky/// FindAvailableLoadedValue - Scan the ScanBB block backwards (starting at
33210006Srdivacky/// the instruction before ScanFrom) checking to see if we have the value at
34210006Srdivacky/// the memory address *Ptr locally available within a small number of
35210006Srdivacky///  instructions. If the value is available, return it.
36210006Srdivacky///
37210006Srdivacky/// If not, return the iterator for the last validated instruction that the
38210006Srdivacky/// value would be live through.  If we scanned the entire block and didn't
39210006Srdivacky/// find something that invalidates *Ptr or provides it, ScanFrom would be
40210006Srdivacky/// left at begin() and this returns null.  ScanFrom could also be left
41210006Srdivacky///
42210006Srdivacky/// MaxInstsToScan specifies the maximum instructions to scan in the block.
43210006Srdivacky/// If it is set to 0, it will scan the whole block. You can also optionally
44210006Srdivacky/// specify an alias analysis implementation, which makes this more precise.
45234353Sdim///
46234353Sdim/// If TBAATag is non-null and a load or store is found, the TBAA tag from the
47234353Sdim/// load or store is recorded there.  If there is no TBAA tag or if no access
48234353Sdim/// is found, it is left unmodified.
49210006SrdivackyValue *FindAvailableLoadedValue(Value *Ptr, BasicBlock *ScanBB,
50210006Srdivacky                                BasicBlock::iterator &ScanFrom,
51210006Srdivacky                                unsigned MaxInstsToScan = 6,
52234353Sdim                                AliasAnalysis *AA = 0,
53234353Sdim                                MDNode **TBAATag = 0);
54210006Srdivacky
55210006Srdivacky}
56210006Srdivacky
57210006Srdivacky#endif
58