2727#include " mlir/IR/BuiltinAttributes.h"
2828#include " mlir/IR/BuiltinOps.h"
2929#include " mlir/IR/MLIRContext.h"
30+ #include " mlir/Support/LLVM.h"
3031#include " mlir/Tools/mlir-translate/Translation.h"
3132#include " tfrt/bef/bef_encoding.h"
3233#include " tfrt/cpp_tests/test_util.h"
@@ -65,7 +66,7 @@ class BefAttrReaderTest : public ::testing::Test {
6566 auto mlir_attr = reader.ReadAttribute (attribute_type, offset);
6667 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (mlir_attr), attribute_type);
6768
68- EXPECT_EQ (static_cast <T>(mlir_attr. template cast <mlir::IntegerAttr>()
69+ EXPECT_EQ (static_cast <T>(mlir:: cast<mlir::IntegerAttr>(mlir_attr )
6970 .getValue ()
7071 .getLimitedValue ()),
7172 value);
@@ -109,9 +110,10 @@ TEST_F(BefAttrReaderTest, ReadF32Attribute) {
109110 auto mlir_attr = reader.ReadAttribute (attribute_type, offset);
110111 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (mlir_attr), attribute_type);
111112
112- EXPECT_EQ (static_cast <float >(
113- mlir_attr.cast <mlir::FloatAttr>().getValue ().convertToFloat ()),
114- kTestFloat );
113+ EXPECT_EQ (
114+ static_cast <float >(
115+ mlir::cast<mlir::FloatAttr>(mlir_attr).getValue ().convertToFloat ()),
116+ kTestFloat );
115117}
116118
117119constexpr double kTestDeouble = -3.141592 ;
@@ -126,9 +128,10 @@ TEST_F(BefAttrReaderTest, ReadF64Attribute) {
126128 auto mlir_attr = reader.ReadAttribute (attribute_type, offset);
127129 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (mlir_attr), attribute_type);
128130
129- EXPECT_EQ (static_cast <double >(
130- mlir_attr.cast <mlir::FloatAttr>().getValue ().convertToDouble ()),
131- kTestDeouble );
131+ EXPECT_EQ (
132+ static_cast <double >(
133+ mlir::cast<mlir::FloatAttr>(mlir_attr).getValue ().convertToDouble ()),
134+ kTestDeouble );
132135}
133136
134137constexpr char kTestString [] = " Hello, World" ;
@@ -143,7 +146,7 @@ TEST_F(BefAttrReaderTest, ReadStringAttribute) {
143146 auto mlir_attr = reader.ReadAttribute (attribute_type, offset);
144147 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (mlir_attr), attribute_type);
145148
146- EXPECT_EQ (mlir_attr. cast <mlir::StringAttr>().getValue (), kTestString );
149+ EXPECT_EQ (mlir:: cast<mlir::StringAttr>(mlir_attr ).getValue (), kTestString );
147150}
148151
149152TEST_F (BefAttrReaderTest, ReadI32TypeAttribute) {
@@ -160,7 +163,8 @@ TEST_F(BefAttrReaderTest, ReadI32TypeAttribute) {
160163 auto read_attr = reader.ReadAttribute (attribute_type, offset);
161164 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (mlir_attr), attribute_type);
162165
163- EXPECT_EQ (read_attr.cast <mlir::TypeAttr>().getValue (), mlir_attr.getValue ());
166+ EXPECT_EQ (mlir::cast<mlir::TypeAttr>(read_attr).getValue (),
167+ mlir_attr.getValue ());
164168}
165169
166170constexpr int64_t kTestShape [] = {1 , 2 , 3 };
@@ -176,7 +180,7 @@ TEST_F(BefAttrReaderTest, ReadRankedShapeAttribute) {
176180 auto mlir_attr = reader.ReadAttribute (attribute_type, offset);
177181 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (mlir_attr), attribute_type);
178182
179- auto shape_attr = mlir_attr. cast <tfrt::corert::ShapeAttr>();
183+ auto shape_attr = mlir:: cast<tfrt::corert::ShapeAttr>(mlir_attr );
180184 EXPECT_TRUE (shape_attr.hasRank ());
181185 EXPECT_EQ (shape_attr.getRank (), kTestShapeRank );
182186 for (int i = 0 ; i < kTestShapeRank ; ++i) {
@@ -195,7 +199,7 @@ TEST_F(BefAttrReaderTest, ReadUnrankedShapeAttribute) {
195199 auto mlir_attr = reader.ReadAttribute (attribute_type, offset);
196200 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (mlir_attr), attribute_type);
197201
198- auto shape_attr = mlir_attr. cast <tfrt::corert::ShapeAttr>();
202+ auto shape_attr = mlir:: cast<tfrt::corert::ShapeAttr>(mlir_attr );
199203 EXPECT_FALSE (shape_attr.hasRank ());
200204}
201205
@@ -211,13 +215,14 @@ TEST_F(BefAttrReaderTest, ReadI32ArrayAttribute) {
211215 auto mlir_attr = reader.ReadAttribute (attribute_type, offset);
212216 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (mlir_attr), attribute_type);
213217
214- auto array_attr = mlir_attr. cast <mlir::ArrayAttr>().getValue ();
218+ auto array_attr = mlir:: cast<mlir::ArrayAttr>(mlir_attr ).getValue ();
215219
216220 EXPECT_EQ (array_attr.size (), kTestI32ArraySize );
217221 for (int idx = 0 ; idx < kTestI32ArraySize ; ++idx) {
218- EXPECT_EQ (
219- array_attr[idx].cast <mlir::IntegerAttr>().getValue ().getLimitedValue (),
220- kTestI32Array [idx]);
222+ EXPECT_EQ (mlir::cast<mlir::IntegerAttr>(array_attr[idx])
223+ .getValue ()
224+ .getLimitedValue (),
225+ kTestI32Array [idx]);
221226 }
222227}
223228
@@ -233,13 +238,14 @@ TEST_F(BefAttrReaderTest, ReadF64ArrayAttribute) {
233238 auto mlir_attr = reader.ReadAttribute (attribute_type, offset);
234239 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (mlir_attr), attribute_type);
235240
236- auto array_attr = mlir_attr. cast <mlir::ArrayAttr>().getValue ();
241+ auto array_attr = mlir:: cast<mlir::ArrayAttr>(mlir_attr ).getValue ();
237242
238243 EXPECT_EQ (array_attr.size (), kTestF64ArraySize );
239244 for (int idx = 0 ; idx < kTestF64ArraySize ; ++idx) {
240- EXPECT_EQ (
241- array_attr[idx].cast <mlir::FloatAttr>().getValue ().convertToDouble (),
242- kTestF64Array [idx]);
245+ EXPECT_EQ (mlir::cast<mlir::FloatAttr>(array_attr[idx])
246+ .getValue ()
247+ .convertToDouble (),
248+ kTestF64Array [idx]);
243249 }
244250}
245251
@@ -272,7 +278,7 @@ TEST_F(BefAttrReaderTest, ReadDenseAttribute) {
272278 auto mlir_attr = reader.ReadAttribute (attribute_type, offset);
273279 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (mlir_attr), attribute_type);
274280
275- auto dense_attr = mlir_attr. cast <mlir::DenseElementsAttr>();
281+ auto dense_attr = mlir:: cast<mlir::DenseElementsAttr>(mlir_attr );
276282 const auto shaped_type = dense_attr.getType ();
277283
278284 EXPECT_EQ (
@@ -283,7 +289,7 @@ TEST_F(BefAttrReaderTest, ReadDenseAttribute) {
283289 EXPECT_EQ (shaped_type.getShape ()[1 ], 2 );
284290
285291 for (auto element : dense_attr.getValues <mlir::Attribute>()) {
286- EXPECT_EQ (element. cast <mlir::FloatAttr>().getValue ().convertToFloat (),
292+ EXPECT_EQ (mlir:: cast<mlir::FloatAttr>(element ).getValue ().convertToFloat (),
287293 1 .5f );
288294 }
289295}
@@ -316,26 +322,28 @@ TEST_F(BefAttrReaderTest, EmitAggregateAttribute) {
316322 auto read_attr = reader.ReadAttribute (attribute_type, offset);
317323 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (read_attr), attribute_type);
318324
319- auto aggregate_attr = read_attr. cast <mlir::ArrayAttr>();
325+ auto aggregate_attr = mlir:: cast<mlir::ArrayAttr>(read_attr );
320326 EXPECT_EQ (aggregate_attr.size (), 3 );
321327
322328 auto first = aggregate_attr[0 ];
323329 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (first),
324330 static_cast <BEFAttributeType>(DType::I32));
325- EXPECT_EQ (static_cast <int32_t >(
326- first.cast <mlir::IntegerAttr>().getValue ().getLimitedValue ()),
327- kTestAggregateAttr1 );
331+ EXPECT_EQ (
332+ static_cast <int32_t >(
333+ mlir::cast<mlir::IntegerAttr>(first).getValue ().getLimitedValue ()),
334+ kTestAggregateAttr1 );
328335
329336 auto second = aggregate_attr[1 ];
330337 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (second),
331338 static_cast <BEFAttributeType>(DType::String));
332- EXPECT_EQ (second.cast <mlir::StringAttr>().getValue (), kTestAggregateAttr2 );
339+ EXPECT_EQ (mlir::cast<mlir::StringAttr>(second).getValue (),
340+ kTestAggregateAttr2 );
333341
334342 auto third = aggregate_attr[2 ];
335343 EXPECT_EQ (BefAttrEmitter::GetBefAttributeType (third),
336344 static_cast <BEFAttributeType>(DType::F32));
337345 EXPECT_EQ (static_cast <float >(
338- third. cast <mlir::FloatAttr>().getValue ().convertToFloat ()),
346+ mlir:: cast<mlir::FloatAttr>(third ).getValue ().convertToFloat ()),
339347 kTestAggregateAttr3 );
340348}
341349
0 commit comments