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