[tf][tfg] Remove CastOp's ODS definition

CastOp can not be marked as `NoSideEffect` and can not have a folder. Specifically, no operation inside a `GraphOp` can be assumed to have no uses because it could be specified as a `fetch`. In general, ops can only be folded/marked trivially dead inside functions.

Since CastOp has/will not have any further uses (the region ops will have relaxed type requirements). Remove the ODS definition altogether to cut the maintenance cost.

PiperOrigin-RevId: 427576456
Change-Id: I395fb8ba07277e8e8034f07dc445b3bfbf4dcaf7
diff --git a/tensorflow/core/ir/ops.cc b/tensorflow/core/ir/ops.cc
index 35373be..7e89c0e 100644
--- a/tensorflow/core/ir/ops.cc
+++ b/tensorflow/core/ir/ops.cc
@@ -909,26 +909,6 @@
 }
 
 //===----------------------------------------------------------------------===//
-// CastOp
-
-LogicalResult CastOp::fold(ArrayRef<Attribute> operands,
-                           SmallVectorImpl<OpFoldResult> &results) {
-  // If the op has control operands, we can't fold.
-  if (!ctls().empty()) return failure();
-  // GetResultOp gets the value from uninstantiated op and it can't be folded.
-  if (x().getDefiningOp<GetResultOp>()) return failure();
-
-  ShapedType x_shape = x().getType().dyn_cast<ShapedType>();
-  ShapedType y_shape = y().getType().dyn_cast<ShapedType>();
-  if (!x_shape || x_shape != y_shape || !x_shape.hasStaticShape())
-    return failure();
-
-  results.push_back(x());
-  results.push_back(LookupControlDependency(x()));
-  return success();
-}
-
-//===----------------------------------------------------------------------===//
 // If-Like Ops
 
 template <typename IfLikeOp>
diff --git a/tensorflow/core/ir/ops.td b/tensorflow/core/ir/ops.td
index e358621..52cd8da 100644
--- a/tensorflow/core/ir/ops.td
+++ b/tensorflow/core/ir/ops.td
@@ -239,24 +239,6 @@
 // op-specific cases.
 // TODO(jeffniu): Also, many of these should be derived attributes (e.g. types).
 
-// A cast operation.
-def TFGraph_CastOp : TFGraph_Op<"Cast", [NoSideEffect]> {
-  let summary = "Cast between two compatible tensor types.";
-
-  let arguments = (ins
-    // Op operands.
-    TFGraph_Tensor:$x,
-    Variadic<ControlType>:$ctls,
-    // Required attributes.
-    TFGraph_TypeOrPlaceholder:$SrcT,
-    TFGraph_TypeOrPlaceholder:$DstT,
-    DefaultValuedAttr<BoolAttr, "false">:$Truncate
-  );
-  let results = (outs AnyType:$y, ControlType:$ctl);
-
-  let hasFolder = 1;
-}
-
 // Base class for TFGraph concrete ops.
 class TFGraph_ConcreteOp<string mnemonic, list<Trait> traits = []> :
     TFGraph_Op<mnemonic, traits>;
diff --git a/tensorflow/core/ir/tests/canonicalize.mlir b/tensorflow/core/ir/tests/canonicalize.mlir
deleted file mode 100644
index 23f6121..0000000
--- a/tensorflow/core/ir/tests/canonicalize.mlir
+++ /dev/null
@@ -1,10 +0,0 @@
-// RUN: tfg-opt-no-passes %s --canonicalize | FileCheck %s
-
-tfg.graph #tf_type.version<producer = 42, min_consumer = 33> {
-  // CHECK: %[[A:.*]], %{{.*}} = A
-  %A, %ctl = A : () -> (tensor<1xi32>)
-  // CHECK-NOT: cast %[[A]]
-  %cast, %ctl_0 = Cast(%A) {SrcT = i32, DstT = i32} : (tensor<1xi32>) -> (tensor<1xi32>)
-  // CHECK: B(%[[A]])
-  %B, %ctl_1 = B(%cast) : (tensor<1xi32>) -> (tensor<1xf32>)
-}