1 //===- llvm/Analysis/ValueTracking.h - Walk computations --------*- C++ -*-===//
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 contains routines that help analyze properties that chains of
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_ANALYSIS_VALUETRACKING_H
16 #define LLVM_ANALYSIS_VALUETRACKING_H
18 #include "llvm/Support/DataTypes.h"
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
33 /// This function is defined on values with integer type, values with pointer
34 /// type (but only if TD is non-null), and vectors of integers. In the case
35 /// where V is a vector, the mask, known zero, and known one values are the
36 /// same width as the vector element, and the bit is set only if it is true
37 /// for all of the elements in the vector.
38 void ComputeMaskedBits(Value *V, const APInt &Mask, APInt &KnownZero,
39 APInt &KnownOne, const TargetData *TD = 0,
42 /// MaskedValueIsZero - Return true if 'V & Mask' is known to be zero. We use
43 /// this predicate to simplify operations downstream. Mask is known to be
44 /// zero for bits that V cannot have.
46 /// This function is defined on values with integer type, values with pointer
47 /// type (but only if TD is non-null), and vectors of integers. In the case
48 /// where V is a vector, the mask, known zero, and known one values are the
49 /// same width as the vector element, and the bit is set only if it is true
50 /// for all of the elements in the vector.
51 bool MaskedValueIsZero(Value *V, const APInt &Mask,
52 const TargetData *TD = 0, unsigned Depth = 0);
55 /// ComputeNumSignBits - Return the number of times the sign bit of the
56 /// register is replicated into the other bits. We know that at least 1 bit
57 /// is always equal to the sign bit (itself), but other cases can give us
58 /// information. For example, immediately after an "ashr X, 2", we know that
59 /// the top 3 bits are all equal to each other, so we return 3.
61 /// 'Op' must have a scalar integer type.
63 unsigned ComputeNumSignBits(Value *Op, const TargetData *TD = 0,
66 /// CannotBeNegativeZero - Return true if we can prove that the specified FP
67 /// value is never equal to -0.0.
69 bool CannotBeNegativeZero(const Value *V, unsigned Depth = 0);
71 /// FindScalarValue - Given an aggregrate and an sequence of indices, see if
72 /// the scalar value indexed is already around as a register, for example if
73 /// it were inserted directly into the aggregrate.
75 /// If InsertBefore is not null, this function will duplicate (modified)
76 /// insertvalues when a part of a nested struct is extracted.
77 Value *FindInsertedValue(Value *V,
78 const unsigned *idx_begin,
79 const unsigned *idx_end,
81 Instruction *InsertBefore = 0);
83 /// This is a convenience wrapper for finding values indexed by a single index
85 inline Value *FindInsertedValue(Value *V, const unsigned Idx,
87 Instruction *InsertBefore = 0) {
88 const unsigned Idxs[1] = { Idx };
89 return FindInsertedValue(V, &Idxs[0], &Idxs[1], Context, InsertBefore);
92 /// GetConstantStringInfo - This function computes the length of a
93 /// null-terminated C string pointed to by V. If successful, it returns true
94 /// and returns the string in Str. If unsuccessful, it returns false. If
95 /// StopAtNul is set to true (the default), the returned string is truncated
96 /// by a nul character in the global. If StopAtNul is false, the nul
97 /// character is included in the result string.
98 bool GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset = 0,
99 bool StopAtNul = true);
100 } // end namespace llvm