diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-11-02 02:20:32 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-11-02 02:20:32 +0000 | 
| commit | efdd2bbce6bb87339952a8f6b73ca51b624886ea (patch) | |
| tree | b6f0be771b7607d6b68699bda4577290b27f0eb6 /llvm/lib/Transforms/Scalar | |
| parent | 3cd6a61b275f49df4f2aaa273efbf4cf8e0a6511 (diff) | |
| download | bcm5719-llvm-efdd2bbce6bb87339952a8f6b73ca51b624886ea.tar.gz bcm5719-llvm-efdd2bbce6bb87339952a8f6b73ca51b624886ea.zip | |
change LatticeVal to use PointerIntPair to save some space.
llvm-svn: 85773
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/SCCP.cpp | 101 | 
1 files changed, 52 insertions, 49 deletions
| diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp index a348e20907e..0451cb32cae 100644 --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -15,10 +15,6 @@  //   * Proves values to be constant, and replaces them with constants  //   * Proves conditional branches to be unconditional  // -// Notice that: -//   * This pass has a habit of making definitions be dead.  It is a good idea -//     to to run a DCE pass sometime after running this pass. -//  //===----------------------------------------------------------------------===//  #define DEBUG_TYPE "sccp" @@ -40,7 +36,7 @@  #include "llvm/Support/raw_ostream.h"  #include "llvm/ADT/DenseMap.h"  #include "llvm/ADT/DenseSet.h" -#include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/PointerIntPair.h"  #include "llvm/ADT/SmallVector.h"  #include "llvm/ADT/Statistic.h"  #include "llvm/ADT/STLExtras.h" @@ -61,7 +57,7 @@ namespace {  /// an LLVM value may occupy.  It is a simple class with value semantics.  ///  class LatticeVal { -  enum { +  enum LatticeValueTy {      /// undefined - This LLVM Value has no known value yet.      undefined, @@ -77,61 +73,68 @@ class LatticeVal {      /// overdefined - This instruction is not known to be constant, and we know      /// it has a value.      overdefined -  } LatticeValue;    // The current lattice position +  }; + +  /// Val: This stores the current lattice value along with the Constant* for +  /// the constant if this is a 'constant' or 'forcedconstant' value. +  PointerIntPair<Constant *, 2, LatticeValueTy> Val; +   +  LatticeValueTy getLatticeValue() const { +    return Val.getInt(); +  } -  Constant *ConstantVal; // If Constant value, the current value  public: -  inline LatticeVal() : LatticeValue(undefined), ConstantVal(0) {} +  inline LatticeVal() : Val(0, undefined) {} -  // markOverdefined - Return true if this is a new status to be in... +  inline bool isUndefined() const { return getLatticeValue() == undefined; } +  inline bool isConstant() const { +    return getLatticeValue() == constant || getLatticeValue() == forcedconstant; +  } +  inline bool isOverdefined() const { return getLatticeValue() == overdefined; } +   +  inline Constant *getConstant() const { +    assert(isConstant() && "Cannot get the constant of a non-constant!"); +    return Val.getPointer(); +  } +   +  /// markOverdefined - Return true if this is a change in status.    inline bool markOverdefined() { -    if (LatticeValue != overdefined) { -      LatticeValue = overdefined; -      return true; -    } -    return false; +    if (isOverdefined()) +      return false; +     +    Val.setInt(overdefined); +    return true;    } -  // markConstant - Return true if this is a new status for us. +  /// markConstant - Return true if this is a change in status.    inline bool markConstant(Constant *V) { -    if (LatticeValue != constant) { -      if (LatticeValue == undefined) { -        LatticeValue = constant; -        assert(V && "Marking constant with NULL"); -        ConstantVal = V; -      } else { -        assert(LatticeValue == forcedconstant &&  -               "Cannot move from overdefined to constant!"); -        // Stay at forcedconstant if the constant is the same. -        if (V == ConstantVal) return false; -         -        // Otherwise, we go to overdefined.  Assumptions made based on the -        // forced value are possibly wrong.  Assuming this is another constant -        // could expose a contradiction. -        LatticeValue = overdefined; -      } -      return true; +    if (isConstant()) { +      assert(getConstant() == V && "Marking constant with different value"); +      return false; +    } +     +    if (isUndefined()) { +      Val.setInt(constant); +      assert(V && "Marking constant with NULL"); +      Val.setPointer(V);      } else { -      assert(ConstantVal == V && "Marking constant with different value"); +      assert(getLatticeValue() == forcedconstant &&  +             "Cannot move from overdefined to constant!"); +      // Stay at forcedconstant if the constant is the same. +      if (V == getConstant()) return false; +       +      // Otherwise, we go to overdefined.  Assumptions made based on the +      // forced value are possibly wrong.  Assuming this is another constant +      // could expose a contradiction. +      Val.setInt(overdefined);      } -    return false; +    return true;    }    inline void markForcedConstant(Constant *V) { -    assert(LatticeValue == undefined && "Can't force a defined value!"); -    LatticeValue = forcedconstant; -    ConstantVal = V; -  } -   -  inline bool isUndefined() const { return LatticeValue == undefined; } -  inline bool isConstant() const { -    return LatticeValue == constant || LatticeValue == forcedconstant; -  } -  inline bool isOverdefined() const { return LatticeValue == overdefined; } - -  inline Constant *getConstant() const { -    assert(isConstant() && "Cannot get the constant of a non-constant!"); -    return ConstantVal; +    assert(isUndefined() && "Can't force a defined value!"); +    Val.setInt(forcedconstant); +    Val.setPointer(V);    }  }; | 

