Implement support for branch instruction operands.

PiperOrigin-RevId: 205666777
diff --git a/include/mlir/IR/BasicBlock.h b/include/mlir/IR/BasicBlock.h
index be64e4f..d59a83b 100644
--- a/include/mlir/IR/BasicBlock.h
+++ b/include/mlir/IR/BasicBlock.h
@@ -59,9 +59,12 @@
   reverse_args_iterator args_rend() const { return getArguments().rend(); }
 
   bool args_empty() const { return arguments.empty(); }
+
+  /// Add one value to the operand list.
   BBArgument *addArgument(Type *type);
-  llvm::iterator_range<BBArgListType::iterator>
-  addArguments(ArrayRef<Type *> types);
+
+  /// Add one argument to the argument list for each type specified in the list.
+  llvm::iterator_range<args_iterator> addArguments(ArrayRef<Type *> types);
 
   unsigned getNumArguments() const { return arguments.size(); }
   BBArgument *getArgument(unsigned i) { return arguments[i]; }
diff --git a/include/mlir/IR/Builders.h b/include/mlir/IR/Builders.h
index 1a003b6..12b8aed 100644
--- a/include/mlir/IR/Builders.h
+++ b/include/mlir/IR/Builders.h
@@ -186,7 +186,7 @@
     return op;
   }
 
-  // Creates for statement. When step is not specified, it is set to 1. 
+  // Creates for statement. When step is not specified, it is set to 1.
   ForStmt *createFor(AffineConstantExpr *lowerBound,
                      AffineConstantExpr *upperBound,
                      AffineConstantExpr *step = nullptr);
diff --git a/include/mlir/IR/Instructions.h b/include/mlir/IR/Instructions.h
index 6f374bd..02b4ffc 100644
--- a/include/mlir/IR/Instructions.h
+++ b/include/mlir/IR/Instructions.h
@@ -260,7 +260,31 @@
     return dest;
   }
 
-  // TODO: need to take operands to specify BB arguments
+  unsigned getNumOperands() const { return operands.size(); }
+
+  // TODO: Add a getOperands() custom sequence that provides a value projection
+  // of the operand list.
+  CFGValue *getOperand(unsigned idx) { return getInstOperand(idx).get(); }
+  const CFGValue *getOperand(unsigned idx) const {
+    return getInstOperand(idx).get();
+  }
+
+  ArrayRef<InstOperand> getInstOperands() const { return operands; }
+  MutableArrayRef<InstOperand> getInstOperands() { return operands; }
+
+  InstOperand &getInstOperand(unsigned idx) { return operands[idx]; }
+  const InstOperand &getInstOperand(unsigned idx) const {
+    return operands[idx];
+  }
+
+  /// Add one value to the operand list.
+  void addOperand(CFGValue *value);
+
+  /// Add a list of values to the operand list.
+  void addOperands(ArrayRef<CFGValue *> values);
+
+  /// Erase a specific argument from the arg list.
+  // TODO: void eraseArgument(int Index);
 
   /// Methods for support type inquiry through isa, cast, and dyn_cast.
   static bool classof(const Instruction *inst) {
@@ -272,6 +296,7 @@
       : TerminatorInst(Kind::Branch), dest(dest) {}
 
   BasicBlock *dest;
+  std::vector<InstOperand> operands;
 };
 
 
diff --git a/include/mlir/IR/Module.h b/include/mlir/IR/Module.h
index 8401252..b0b9c96 100644
--- a/include/mlir/IR/Module.h
+++ b/include/mlir/IR/Module.h
@@ -37,6 +37,8 @@
 
   // FIXME: wrong representation and API.
   // TODO(someone): This should switch to llvm::iplist<Function>.
+  // TODO(someone): we also need a symbol table for function names +
+  // autorenaming like LLVM does.
   std::vector<Function*> functionList;
 
   /// Perform (potentially expensive) checks of invariants, used to detect
diff --git a/include/mlir/IR/SSAOperand.h b/include/mlir/IR/SSAOperand.h
index c8ab7d5..7685c31 100644
--- a/include/mlir/IR/SSAOperand.h
+++ b/include/mlir/IR/SSAOperand.h
@@ -61,6 +61,17 @@
   /// of the SSA machinery.
   SSAOperand *getNextOperandUsingThisValue() { return nextUse; }
 
+  /// We support a move constructor so SSAOperands can be in vectors, but this
+  /// shouldn't be used by general clients.
+  SSAOperand(SSAOperand &&other) {
+    other.removeFromCurrent();
+    value = other.value;
+    other.value = nullptr;
+    nextUse = nullptr;
+    back = nullptr;
+    insertIntoCurrent();
+  }
+
 private:
   /// The value used as this operand.  This can be null when in a
   /// "dropAllUses" state.
@@ -116,6 +127,11 @@
   /// Return which operand this is in the operand list of the User.
   // TODO:  unsigned getOperandNumber() const;
 
+  /// We support a move constructor so SSAOperands can be in vectors, but this
+  /// shouldn't be used by general clients.
+  SSAOperandImpl(SSAOperandImpl &&other)
+      : SSAOperand(std::move(other)), owner(other.owner) {}
+
 private:
   /// The owner of this operand.
   SSAOwnerTy *const owner;