Fix some bugs, straighten stuff out, more work needs to be done.
[oota-llvm.git] / lib / Transforms / Scalar / SCCP.cpp
index 8d1547577b4142729d560d1ef05d0d09a29f1694..b936c6f2c89cb268fea91ca789d134182f9f3232 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Transforms/Scalar/ConstantProp.h"
+#include "llvm/Transforms/Scalar.h"
 #include "llvm/ConstantHandling.h"
 #include "llvm/Function.h"
+#include "llvm/BasicBlock.h"
 #include "llvm/iPHINode.h"
 #include "llvm/iMemory.h"
 #include "llvm/iTerminators.h"
@@ -92,7 +93,7 @@ class SCCP : public FunctionPass, public InstVisitor<SCCP> {
   std::set<BasicBlock*>     BBExecutable;// The basic blocks that are executable
   std::map<Value*, InstVal> ValueState;  // The state each value is in...
 
-  std::set<Instruction*>    InstWorkList;// The instruction work list
+  std::vector<Instruction*> InstWorkList;// The instruction work list
   std::vector<BasicBlock*>  BBWorkList;  // The BasicBlock work list
 public:
 
@@ -124,7 +125,7 @@ private:
     DEBUG_SCCP(cerr << "markConstant: " << V << " = " << I);
 
     if (ValueState[I].markConstant(V)) {
-      InstWorkList.insert(I);
+      InstWorkList.push_back(I);
       return true;
     }
     return false;
@@ -138,7 +139,7 @@ private:
     if (ValueState[V].markOverdefined()) {
       if (Instruction *I = dyn_cast<Instruction>(V)) {
        DEBUG_SCCP(cerr << "markOverdefined: " << V);
-       InstWorkList.insert(I);  // Only instructions go on the work list
+       InstWorkList.push_back(I);  // Only instructions go on the work list
       }
       return true;
     }
@@ -251,8 +252,8 @@ bool SCCP::runOnFunction(Function *F) {
   while (!BBWorkList.empty() || !InstWorkList.empty()) {
     // Process the instruction work list...
     while (!InstWorkList.empty()) {
-      Instruction *I = *InstWorkList.begin();
-      InstWorkList.erase(InstWorkList.begin());
+      Instruction *I = InstWorkList.back();
+      InstWorkList.pop_back();
 
       DEBUG_SCCP(cerr << "\nPopped off I-WL: " << I);
 
@@ -502,9 +503,15 @@ void SCCP::visitBinaryOperator(Instruction *I) {
   if (V1State.isOverdefined() || V2State.isOverdefined()) {
     markOverdefined(I);
   } else if (V1State.isConstant() && V2State.isConstant()) {
-    Constant *Result = ConstantFoldBinaryInstruction(I->getOpcode(),
-                                                     V1State.getConstant(),
-                                                     V2State.getConstant());
+    Constant *Result = 0;
+    if (isa<BinaryOperator>(I))
+      Result = ConstantFoldBinaryInstruction(I->getOpcode(),
+                                             V1State.getConstant(),
+                                             V2State.getConstant());
+    else if (isa<ShiftInst>(I))
+      Result = ConstantFoldShiftInstruction(I->getOpcode(),
+                                            V1State.getConstant(),
+                                            V2State.getConstant());
     if (Result)
       markConstant(I, Result);      // This instruction constant folds!
     else