Add attributes and affine expr/map to the Builder, switch the parser over to
use it.

This also removes "operand" from the affine expr classes: it is unnecessary
verbosity and "operand" will mean something very specific for SSA stuff (we
will have an Operand type).

PiperOrigin-RevId: 203976504
diff --git a/include/mlir/IR/AffineExpr.h b/include/mlir/IR/AffineExpr.h
index 699a4ea..b561257 100644
--- a/include/mlir/IR/AffineExpr.h
+++ b/include/mlir/IR/AffineExpr.h
@@ -86,43 +86,34 @@
 /// Binary affine expression.
 class AffineBinaryOpExpr : public AffineExpr {
  public:
-  AffineExpr *getLeftOperand() const { return lhsOperand; }
-  AffineExpr *getRightOperand() const { return rhsOperand; }
+   AffineExpr *getLHS() const { return lhs; }
+   AffineExpr *getRHS() const { return rhs; }
 
-  bool isSymbolic() const {
-    return lhsOperand->isSymbolic() && rhsOperand->isSymbolic();
-  }
-
-  /// Methods for support type inquiry through isa, cast, and dyn_cast.
-  static bool classof(const AffineExpr *expr) {
-    return expr->getKind() <= Kind::LAST_AFFINE_BINARY_OP;
+   /// Methods for support type inquiry through isa, cast, and dyn_cast.
+   static bool classof(const AffineExpr *expr) {
+     return expr->getKind() <= Kind::LAST_AFFINE_BINARY_OP;
   }
 
  protected:
-   static AffineBinaryOpExpr *get(Kind kind, AffineExpr *lhsOperand,
-                                  AffineExpr *rhsOperand, MLIRContext *context);
+   static AffineBinaryOpExpr *get(Kind kind, AffineExpr *lhs, AffineExpr *rhs,
+                                  MLIRContext *context);
 
-   explicit AffineBinaryOpExpr(Kind kind, AffineExpr *lhsOperand,
-                               AffineExpr *rhsOperand)
-       : AffineExpr(kind), lhsOperand(lhsOperand), rhsOperand(rhsOperand) {}
+   explicit AffineBinaryOpExpr(Kind kind, AffineExpr *lhs, AffineExpr *rhs)
+       : AffineExpr(kind), lhs(lhs), rhs(rhs) {}
 
-   AffineExpr *const lhsOperand;
-   AffineExpr *const rhsOperand;
+   AffineExpr *const lhs;
+   AffineExpr *const rhs;
 };
 
 /// Binary affine add expression.
 class AffineAddExpr : public AffineBinaryOpExpr {
  public:
-  static AffineExpr *get(AffineExpr *lhsOperand, AffineExpr *rhsOperand,
-                         MLIRContext *context);
+   static AffineExpr *get(AffineExpr *lhs, AffineExpr *rhs,
+                          MLIRContext *context);
 
-  bool isPureAffine() const {
-    return lhsOperand->isPureAffine() && rhsOperand->isPureAffine();
-  }
-
-  /// Methods for support type inquiry through isa, cast, and dyn_cast.
-  static bool classof(const AffineExpr *expr) {
-    return expr->getKind() == Kind::Add;
+   /// Methods for support type inquiry through isa, cast, and dyn_cast.
+   static bool classof(const AffineExpr *expr) {
+     return expr->getKind() == Kind::Add;
   }
   void print(raw_ostream &os) const;
 
@@ -131,20 +122,16 @@
   static AffineExpr *simplify(AffineExpr *lhs, AffineExpr *rhs,
                               MLIRContext *context);
 
-  explicit AffineAddExpr(AffineExpr *lhsOperand, AffineExpr *rhsOperand)
-      : AffineBinaryOpExpr(Kind::Add, lhsOperand, rhsOperand) {}
+  explicit AffineAddExpr(AffineExpr *lhs, AffineExpr *rhs)
+      : AffineBinaryOpExpr(Kind::Add, lhs, rhs) {}
 };
 
 /// Binary affine subtract expression.
 class AffineSubExpr : public AffineBinaryOpExpr {
 public:
-  static AffineSubExpr *get(AffineExpr *lhsOperand, AffineExpr *rhsOperand,
+  static AffineSubExpr *get(AffineExpr *lhs, AffineExpr *rhs,
                             MLIRContext *context);
 
-  bool isPureAffine() const {
-    return lhsOperand->isPureAffine() && rhsOperand->isPureAffine();
-  }
-
   /// Methods for support type inquiry through isa, cast, and dyn_cast.
   static bool classof(const AffineExpr *expr) {
     return expr->getKind() == Kind::Sub;
@@ -152,18 +139,16 @@
   void print(raw_ostream &os) const;
 
 private:
-  explicit AffineSubExpr(AffineExpr *lhsOperand, AffineExpr *rhsOperand)
-      : AffineBinaryOpExpr(Kind::Sub, lhsOperand, rhsOperand) {}
+  explicit AffineSubExpr(AffineExpr *lhs, AffineExpr *rhs)
+      : AffineBinaryOpExpr(Kind::Sub, lhs, rhs) {}
 };
 
 /// Binary affine multiplication expression.
 class AffineMulExpr : public AffineBinaryOpExpr {
 public:
-  static AffineMulExpr *get(AffineExpr *lhsOperand, AffineExpr *rhsOperand,
+  static AffineMulExpr *get(AffineExpr *lhs, AffineExpr *rhs,
                             MLIRContext *context);
 
-  bool isPureAffine() const;
-
   /// Methods for support type inquiry through isa, cast, and dyn_cast.
   static bool classof(const AffineExpr *expr) {
     return expr->getKind() == Kind::Mul;
@@ -171,18 +156,16 @@
   void print(raw_ostream &os) const;
 
 private:
-  explicit AffineMulExpr(AffineExpr *lhsOperand, AffineExpr *rhsOperand)
-      : AffineBinaryOpExpr(Kind::Mul, lhsOperand, rhsOperand) {}
+  explicit AffineMulExpr(AffineExpr *lhs, AffineExpr *rhs)
+      : AffineBinaryOpExpr(Kind::Mul, lhs, rhs) {}
 };
 
 /// Binary affine modulo operation expression.
 class AffineModExpr : public AffineBinaryOpExpr {
 public:
-  static AffineModExpr *get(AffineExpr *lhsOperand, AffineExpr *rhsOperand,
+  static AffineModExpr *get(AffineExpr *lhs, AffineExpr *rhs,
                             MLIRContext *context);
 
-  bool isPureAffine() const;
-
   /// Methods for support type inquiry through isa, cast, and dyn_cast.
   static bool classof(const AffineExpr *expr) {
     return expr->getKind() == Kind::Mod;
@@ -190,17 +173,15 @@
   void print(raw_ostream &os) const;
 
 private:
-  explicit AffineModExpr(AffineExpr *lhsOperand, AffineExpr *rhsOperand)
-      : AffineBinaryOpExpr(Kind::Mod, lhsOperand, rhsOperand) {}
+  explicit AffineModExpr(AffineExpr *lhs, AffineExpr *rhs)
+      : AffineBinaryOpExpr(Kind::Mod, lhs, rhs) {}
 };
 
 /// Binary affine floordiv expression.
 class AffineFloorDivExpr : public AffineBinaryOpExpr {
  public:
-   static AffineFloorDivExpr *get(AffineExpr *lhsOperand,
-                                  AffineExpr *rhsOperand, MLIRContext *context);
-
-   bool isPureAffine() const;
+   static AffineFloorDivExpr *get(AffineExpr *lhs, AffineExpr *rhs,
+                                  MLIRContext *context);
 
    /// Methods for support type inquiry through isa, cast, and dyn_cast.
    static bool classof(const AffineExpr *expr) {
@@ -209,18 +190,16 @@
   void print(raw_ostream &os) const;
 
 private:
-  explicit AffineFloorDivExpr(AffineExpr *lhsOperand, AffineExpr *rhsOperand)
-      : AffineBinaryOpExpr(Kind::FloorDiv, lhsOperand, rhsOperand) {}
+  explicit AffineFloorDivExpr(AffineExpr *lhs, AffineExpr *rhs)
+      : AffineBinaryOpExpr(Kind::FloorDiv, lhs, rhs) {}
 };
 
 /// Binary affine ceildiv expression.
 class AffineCeilDivExpr : public AffineBinaryOpExpr {
 public:
-  static AffineCeilDivExpr *get(AffineExpr *lhsOperand, AffineExpr *rhsOperand,
+  static AffineCeilDivExpr *get(AffineExpr *lhs, AffineExpr *rhs,
                                 MLIRContext *context);
 
-  bool isPureAffine() const;
-
   /// Methods for support type inquiry through isa, cast, and dyn_cast.
   static bool classof(const AffineExpr *expr) {
     return expr->getKind() == Kind::CeilDiv;
@@ -228,8 +207,8 @@
   void print(raw_ostream &os) const;
 
 private:
-  explicit AffineCeilDivExpr(AffineExpr *lhsOperand, AffineExpr *rhsOperand)
-      : AffineBinaryOpExpr(Kind::CeilDiv, lhsOperand, rhsOperand) {}
+  explicit AffineCeilDivExpr(AffineExpr *lhs, AffineExpr *rhs)
+      : AffineBinaryOpExpr(Kind::CeilDiv, lhs, rhs) {}
 };
 
 /// A dimensional identifier appearing in an affine expression.
@@ -243,8 +222,6 @@
 
   unsigned getPosition() const { return position; }
 
-  bool isPureAffine() const { return true; }
-
   /// Methods for support type inquiry through isa, cast, and dyn_cast.
   static bool classof(const AffineExpr *expr) {
     return expr->getKind() == Kind::DimId;
@@ -270,8 +247,6 @@
 
   unsigned getPosition() const { return position; }
 
-  bool isPureAffine() const { return true; }
-
   /// Methods for support type inquiry through isa, cast, and dyn_cast.
   static bool classof(const AffineExpr *expr) {
     return expr->getKind() == Kind::SymbolId;
@@ -293,8 +268,6 @@
 
   int64_t getValue() const { return constant; }
 
-  bool isPureAffine() const { return true; }
-
   /// Methods for support type inquiry through isa, cast, and dyn_cast.
   static bool classof(const AffineExpr *expr) {
     return expr->getKind() == Kind::Constant;
diff --git a/include/mlir/IR/Builders.h b/include/mlir/IR/Builders.h
index 644c812..730fe7d 100644
--- a/include/mlir/IR/Builders.h
+++ b/include/mlir/IR/Builders.h
@@ -30,6 +30,16 @@
 class VectorType;
 class RankedTensorType;
 class UnrankedTensorType;
+class BoolAttr;
+class IntegerAttr;
+class FloatAttr;
+class StringAttr;
+class ArrayAttr;
+class AffineMap;
+class AffineExpr;
+class AffineConstantExpr;
+class AffineDimExpr;
+class AffineSymbolExpr;
 
 /// This class is a general helper class for creating context-global objects
 /// like types, attributes, and affine expressions.
@@ -40,6 +50,9 @@
 
   MLIRContext *getContext() const { return context; }
 
+  Identifier getIdentifier(StringRef str);
+  Module *createModule();
+
   // Types.
   PrimitiveType *getAffineIntType();
   PrimitiveType *getBF16Type();
@@ -53,10 +66,27 @@
   RankedTensorType *getTensorType(ArrayRef<int> shape, Type *elementType);
   UnrankedTensorType *getTensorType(Type *elementType);
 
+  // Attributes.
+  BoolAttr *getBoolAttr(bool value);
+  IntegerAttr *getIntegerAttr(int64_t value);
+  FloatAttr *getFloatAttr(double value);
+  StringAttr *getStringAttr(StringRef bytes);
+  ArrayAttr *getArrayAttr(ArrayRef<Attribute *> value);
+
+  // Affine Expressions and Affine Map.
+  AffineMap *getAffineMap(unsigned dimCount, unsigned symbolCount,
+                          ArrayRef<AffineExpr *> results);
+  AffineDimExpr *getDimExpr(unsigned position);
+  AffineSymbolExpr *getSymbolExpr(unsigned position);
+  AffineConstantExpr *getConstantExpr(int64_t constant);
+  AffineExpr *getAddExpr(AffineExpr *lhs, AffineExpr *rhs);
+  AffineExpr *getSubExpr(AffineExpr *lhs, AffineExpr *rhs);
+  AffineExpr *getMulExpr(AffineExpr *lhs, AffineExpr *rhs);
+  AffineExpr *getModExpr(AffineExpr *lhs, AffineExpr *rhs);
+  AffineExpr *getFloorDivExpr(AffineExpr *lhs, AffineExpr *rhs);
+  AffineExpr *getCeilDivExpr(AffineExpr *lhs, AffineExpr *rhs);
+
   // TODO: Helpers for affine map/exprs, etc.
-  // TODO: Helpers for attributes.
-  // TODO: Identifier
-  // TODO: createModule()
 protected:
   MLIRContext *context;
 };