Oops...I committed too much.
[oota-llvm.git] / include / llvm / Analysis / ValueTracking.h
1 //===- llvm/Analysis/ValueTracking.h - Walk computations --------*- C++ -*-===//
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 contains routines that help analyze properties that chains of
11 // computations have.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_ANALYSIS_VALUETRACKING_H
16 #define LLVM_ANALYSIS_VALUETRACKING_H
17
18 #include "llvm/Support/DataTypes.h"
19 #include <string>
20
21 namespace llvm {
22   class Value;
23   class Instruction;
24   class APInt;
25   class TargetData;
26   
27   /// ComputeMaskedBits - Determine which of the bits specified in Mask are
28   /// known to be either zero or one and return them in the KnownZero/KnownOne
29   /// bit sets.  This code only analyzes bits in Mask, in order to short-circuit
30   /// processing.
31   void ComputeMaskedBits(Value *V, const APInt &Mask, APInt &KnownZero,
32                          APInt &KnownOne, TargetData *TD = 0,
33                          unsigned Depth = 0);
34   
35   /// MaskedValueIsZero - Return true if 'V & Mask' is known to be zero.  We use
36   /// this predicate to simplify operations downstream.  Mask is known to be
37   /// zero for bits that V cannot have.
38   bool MaskedValueIsZero(Value *V, const APInt &Mask, 
39                          TargetData *TD = 0, unsigned Depth = 0);
40
41   
42   /// ComputeNumSignBits - Return the number of times the sign bit of the
43   /// register is replicated into the other bits.  We know that at least 1 bit
44   /// is always equal to the sign bit (itself), but other cases can give us
45   /// information.  For example, immediately after an "ashr X, 2", we know that
46   /// the top 3 bits are all equal to each other, so we return 3.
47   ///
48   /// 'Op' must have a scalar integer type.
49   ///
50   unsigned ComputeNumSignBits(Value *Op, TargetData *TD = 0,
51                               unsigned Depth = 0);
52
53   /// CannotBeNegativeZero - Return true if we can prove that the specified FP 
54   /// value is never equal to -0.0.
55   ///
56   bool CannotBeNegativeZero(const Value *V, unsigned Depth = 0);
57
58   /// FindScalarValue - Given an aggregrate and an sequence of indices, see if
59   /// the scalar value indexed is already around as a register, for example if
60   /// it were inserted directly into the aggregrate.
61   ///
62   /// If InsertBefore is not null, this function will duplicate (modified)
63   /// insertvalues when a part of a nested struct is extracted.
64   Value *FindInsertedValue(Value *V,
65                            const unsigned *idx_begin,
66                            const unsigned *idx_end,
67                            Instruction *InsertBefore = 0);
68
69   /// This is a convenience wrapper for finding values indexed by a single index
70   /// only.
71   inline Value *FindInsertedValue(Value *V, const unsigned Idx,
72                                   Instruction *InsertBefore = 0) {
73     const unsigned Idxs[1] = { Idx };
74     return FindInsertedValue(V, &Idxs[0], &Idxs[1], InsertBefore);
75   }
76   
77   /// GetConstantStringInfo - This function computes the length of a
78   /// null-terminated C string pointed to by V.  If successful, it returns true
79   /// and returns the string in Str.  If unsuccessful, it returns false.  If
80   /// StopAtNul is set to true (the default), the returned string is truncated
81   /// by a nul character in the global.  If StopAtNul is false, the nul
82   /// character is included in the result string.
83   bool GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset = 0,
84                              bool StopAtNul = true);
85 } // end namespace llvm
86
87 #endif