+
+// handleAddition - Add two expressions together, creating a new expression that
+// represents the composite of the two...
+//
+static ExprType handleAddition(ExprType Left, ExprType Right, Value *V) {
+ const Type *Ty = V->getType();
+ if (Left.ExprTy > Right.ExprTy)
+ std::swap(Left, Right); // Make left be simpler than right
+
+ switch (Left.ExprTy) {
+ case ExprType::Constant:
+ return ExprType(Right.Scale, Right.Var,
+ DefZero(Right.Offset, Ty) + DefZero(Left.Offset, Ty));
+ case ExprType::Linear: // RHS side must be linear or scaled
+ case ExprType::ScaledLinear: // RHS must be scaled
+ if (Left.Var != Right.Var) // Are they the same variables?
+ return V; // if not, we don't know anything!
+
+ return ExprType(DefOne(Left.Scale , Ty) + DefOne(Right.Scale , Ty),
+ Right.Var,
+ DefZero(Left.Offset, Ty) + DefZero(Right.Offset, Ty));
+ default:
+ assert(0 && "Dont' know how to handle this case!");
+ return ExprType();
+ }