Changed the fundemental architecture of Operands for Instructions.  Now
Operands are maintained as a vector<Use> in the User class, and operator
iterators are provided as before.  Getting an operand no longer requires
a virtual function call.

WARNING: getOperand(x) where x >= getNumOperands() will now assert instead
of returning null!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp
index d85b33d..de76dcd 100644
--- a/lib/Transforms/IPO/InlineSimple.cpp
+++ b/lib/Transforms/IPO/InlineSimple.cpp
@@ -37,7 +37,8 @@
 static inline void RemapInstruction(Instruction *I, 
 				    map<const Value *, Value*> &ValueMap) {
 
-  for (unsigned op = 0; const Value *Op = I->getOperand(op); ++op) {
+  for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) {
+    const Value *Op = I->getOperand(op);
     Value *V = ValueMap[Op];
     if (!V && Op->isMethod()) 
       continue;  // Methods don't get relocated
@@ -115,11 +116,9 @@
   //
   Method::ArgumentListType::const_iterator PTI = 
     CalledMeth->getArgumentList().begin();
-  for (unsigned a = 1; Value *Operand = CI->getOperand(a); ++a, ++PTI) {
-    ValueMap[*PTI] = Operand;
-  }
+  for (unsigned a = 1, E = CI->getNumOperands(); a != E; ++a, ++PTI)
+    ValueMap[*PTI] = CI->getOperand(a);
   
-
   ValueMap[NewBB] = NewBB;  // Returns get converted to reference NewBB
 
   // Loop over all of the basic blocks in the method, inlining them as 
diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp
index 7a0254b..91a21c3 100644
--- a/lib/Transforms/Scalar/ConstantProp.cpp
+++ b/lib/Transforms/Scalar/ConstantProp.cpp
@@ -132,9 +132,9 @@
     BasicBlock *Dest1 = BI->getOperand(0)->castBasicBlockAsserting();
     BasicBlock *Dest2 = BI->getOperand(1)->castBasicBlockAsserting();
 
-    if (BI->getOperand(2)->isConstant()) {    // Are we branching on constant?
+    if (BI->getCondition()->isConstant()) {    // Are we branching on constant?
       // YES.  Change to unconditional branch...
-      ConstPoolBool *Cond = (ConstPoolBool*)BI->getOperand(2);
+      ConstPoolBool *Cond = (ConstPoolBool*)BI->getCondition();
       BasicBlock *Destination = Cond->getValue() ? Dest1 : Dest2;
       BasicBlock *OldDest     = Cond->getValue() ? Dest2 : Dest1;
 
@@ -147,9 +147,9 @@
       assert(BI->getParent() && "Terminator not inserted in block!");
       OldDest->removePredecessor(BI->getParent());
 
-      BI->setOperand(0, Destination);  // Set the unconditional destination
-      BI->setOperand(1, 0);            // Clear the conditional destination
-      BI->setOperand(2, 0);            // Clear the condition...
+      // Set the unconditional destination, and change the insn to be an
+      // unconditional branch.
+      BI->setUnconditionalDest(Destination);
       return true;
     } else if (Dest2 == Dest1) {       // Conditional branch to same location?
       // This branch matches something like this:  
@@ -160,9 +160,8 @@
       assert(BI->getParent() && "Terminator not inserted in block!");
       Dest1->removePredecessor(BI->getParent());
 
-      // Nuke the second destination, and the use of the condition variable
-      BI->setOperand(1, 0);            // Clear the conditional destination
-      BI->setOperand(2, 0);            // Clear the condition...
+      // Change a conditional branch to unconditional.
+      BI->setUnconditionalDest(Dest1);
       return true;
     }
   }
@@ -192,7 +191,7 @@
     PHINode *PN = (PHINode*)Inst; // If it's a PHI node and only has one operand
                                   // Then replace it directly with that operand.
     assert(PN->getOperand(0) && "PHI Node must have at least one operand!");
-    if (PN->getOperand(1) == 0) {       // If the PHI Node has exactly 1 operand
+    if (PN->getNumOperands() == 1) {    // If the PHI Node has exactly 1 operand
       Value *V = PN->getOperand(0);
       PN->replaceAllUsesWith(V);                 // Replace all uses of this PHI
                                                  // Unlink from basic block
diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp
index 8e37279..fa2c9c7 100644
--- a/lib/Transforms/Scalar/DCE.cpp
+++ b/lib/Transforms/Scalar/DCE.cpp
@@ -91,7 +91,7 @@
 
   do {
     PHINode *PN = (PHINode*)I;
-    assert(PN->getOperand(2) == 0 && "PHI node should only have one value!");
+    assert(PN->getNumOperands() == 2 && "PHI node should only have one value!");
     Value *V = PN->getOperand(0);
 
     PN->replaceAllUsesWith(V);      // Replace PHI node with its single value.
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 8b59e19..5bb75c7 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -408,10 +408,10 @@
 	markExecutable(Succ);
     } else if (SCValue.isConstant()) {
       ConstPoolVal *CPV = SCValue.getConstant();
-      for (SwitchInst::dest_iterator I = SI->dest_begin(), E = SI->dest_end();
-	   I != E; ++I) {
-	if (I->first->equals(CPV)) {   // Found the right branch...
-	  markExecutable(I->second);
+      // Make sure to skip the "default value" which isn't a value
+      for (unsigned i = 1, E = SI->getNumSuccessors(); i != E; ++i) {
+	if (SI->getSuccessorValue(i)->equals(CPV)) {// Found the right branch...
+	  markExecutable(SI->getSuccessor(i));
 	  return;
 	}
       }