summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/SCCP.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-11-02 02:20:32 +0000
committerChris Lattner <sabre@nondot.org>2009-11-02 02:20:32 +0000
commit7927220aef34e056c87b066d4bd87c81e6b0c225 (patch)
treeeb5ee3d661a0ca521e7ce61c5112fe49ddc6ff82 /lib/Transforms/Scalar/SCCP.cpp
parent7ebbabf5000cad682fcc2e4f58f2f83e1d38ef54 (diff)
downloadllvm-7927220aef34e056c87b066d4bd87c81e6b0c225.tar.gz
llvm-7927220aef34e056c87b066d4bd87c81e6b0c225.tar.bz2
llvm-7927220aef34e056c87b066d4bd87c81e6b0c225.tar.xz
change LatticeVal to use PointerIntPair to save some space.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85773 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/SCCP.cpp')
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp101
1 files changed, 52 insertions, 49 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index a348e20907..0451cb32ca 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/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);
}
};