LLVM API Documentation

ValueTracking.h

Go to the documentation of this file.
00001 //===- llvm/Analysis/ValueTracking.h - Walk computations --------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains routines that help analyze properties that chains of
00011 // computations have.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_ANALYSIS_VALUETRACKING_H
00016 #define LLVM_ANALYSIS_VALUETRACKING_H
00017 
00018 #include "llvm/Support/DataTypes.h"
00019 #include <string>
00020 
00021 namespace llvm {
00022   class Value;
00023   class Instruction;
00024   class APInt;
00025   class TargetData;
00026   class LLVMContext;
00027   
00028   /// ComputeMaskedBits - Determine which of the bits specified in Mask are
00029   /// known to be either zero or one and return them in the KnownZero/KnownOne
00030   /// bit sets.  This code only analyzes bits in Mask, in order to short-circuit
00031   /// processing.
00032   void ComputeMaskedBits(Value *V, const APInt &Mask, APInt &KnownZero,
00033                          APInt &KnownOne, TargetData *TD = 0,
00034                          unsigned Depth = 0);
00035   
00036   /// MaskedValueIsZero - Return true if 'V & Mask' is known to be zero.  We use
00037   /// this predicate to simplify operations downstream.  Mask is known to be
00038   /// zero for bits that V cannot have.
00039   bool MaskedValueIsZero(Value *V, const APInt &Mask, 
00040                          TargetData *TD = 0, unsigned Depth = 0);
00041 
00042   
00043   /// ComputeNumSignBits - Return the number of times the sign bit of the
00044   /// register is replicated into the other bits.  We know that at least 1 bit
00045   /// is always equal to the sign bit (itself), but other cases can give us
00046   /// information.  For example, immediately after an "ashr X, 2", we know that
00047   /// the top 3 bits are all equal to each other, so we return 3.
00048   ///
00049   /// 'Op' must have a scalar integer type.
00050   ///
00051   unsigned ComputeNumSignBits(Value *Op, TargetData *TD = 0,
00052                               unsigned Depth = 0);
00053 
00054   /// CannotBeNegativeZero - Return true if we can prove that the specified FP 
00055   /// value is never equal to -0.0.
00056   ///
00057   bool CannotBeNegativeZero(const Value *V, unsigned Depth = 0);
00058 
00059   /// FindScalarValue - Given an aggregrate and an sequence of indices, see if
00060   /// the scalar value indexed is already around as a register, for example if
00061   /// it were inserted directly into the aggregrate.
00062   ///
00063   /// If InsertBefore is not null, this function will duplicate (modified)
00064   /// insertvalues when a part of a nested struct is extracted.
00065   Value *FindInsertedValue(Value *V,
00066                            const unsigned *idx_begin,
00067                            const unsigned *idx_end,
00068                            LLVMContext &Context,
00069                            Instruction *InsertBefore = 0);
00070 
00071   /// This is a convenience wrapper for finding values indexed by a single index
00072   /// only.
00073   inline Value *FindInsertedValue(Value *V, const unsigned Idx,
00074                                   LLVMContext &Context,
00075                                   Instruction *InsertBefore = 0) {
00076     const unsigned Idxs[1] = { Idx };
00077     return FindInsertedValue(V, &Idxs[0], &Idxs[1], Context, InsertBefore);
00078   }
00079   
00080   /// GetConstantStringInfo - This function computes the length of a
00081   /// null-terminated C string pointed to by V.  If successful, it returns true
00082   /// and returns the string in Str.  If unsuccessful, it returns false.  If
00083   /// StopAtNul is set to true (the default), the returned string is truncated
00084   /// by a nul character in the global.  If StopAtNul is false, the nul
00085   /// character is included in the result string.
00086   bool GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset = 0,
00087                              bool StopAtNul = true);
00088 } // end namespace llvm
00089 
00090 #endif