11
11
// ===----------------------------------------------------------------------===//
12
12
13
13
#include " clang/CIR/Dialect/IR/CIRAttrs.h"
14
+ #include " clang/CIR/Dialect/Builder/CIRBaseBuilder.h"
14
15
#include " clang/CIR/Dialect/IR/CIRDialect.h"
15
16
#include " clang/CIR/Dialect/IR/CIROpsEnums.h"
16
17
#include " clang/CIR/Dialect/IR/CIRTypes.h"
@@ -322,7 +323,7 @@ parseFloatLiteral(mlir::AsmParser &parser,
322
323
auto losesInfo = false ;
323
324
value.emplace (rawValue);
324
325
325
- auto tyFpInterface = ty.dyn_cast <cir::CIRFPTypeInterface>();
326
+ auto tyFpInterface = ty.dyn_cast <mlir:: cir::CIRFPTypeInterface>();
326
327
if (!tyFpInterface) {
327
328
// Parsing of the current floating-point literal has succeeded, but the
328
329
// given attribute type is invalid. This error will be reported later when
@@ -335,14 +336,16 @@ parseFloatLiteral(mlir::AsmParser &parser,
335
336
return success ();
336
337
}
337
338
338
- cir::FPAttr cir::FPAttr::getZero (mlir::Type type) {
339
- return get (type,
340
- APFloat::getZero (
341
- type.cast <cir::CIRFPTypeInterface>().getFloatSemantics ()));
339
+ mlir::cir::FPAttr mlir::cir::FPAttr::getZero (mlir::Type type) {
340
+ return get (
341
+ type,
342
+ APFloat::getZero (
343
+ type.cast <mlir::cir::CIRFPTypeInterface>().getFloatSemantics ()));
342
344
}
343
345
344
- LogicalResult cir::FPAttr::verify (function_ref<InFlightDiagnostic()> emitError,
345
- Type type, APFloat value) {
346
+ LogicalResult
347
+ mlir::cir::FPAttr::verify (function_ref<InFlightDiagnostic()> emitError,
348
+ Type type, APFloat value) {
346
349
auto fltTypeInterface = type.dyn_cast <cir::CIRFPTypeInterface>();
347
350
if (!fltTypeInterface) {
348
351
emitError () << " expected floating-point type" ;
@@ -362,8 +365,8 @@ LogicalResult cir::FPAttr::verify(function_ref<InFlightDiagnostic()> emitError,
362
365
// ===----------------------------------------------------------------------===//
363
366
364
367
LogicalResult
365
- cir::ComplexAttr::verify (function_ref<InFlightDiagnostic()> emitError,
366
- Type type, TypedAttr real, TypedAttr imag) {
368
+ mlir:: cir::ComplexAttr::verify (function_ref<InFlightDiagnostic()> emitError,
369
+ Type type, TypedAttr real, TypedAttr imag) {
367
370
auto complexTy = type.dyn_cast <mlir::cir::ComplexType>();
368
371
if (!complexTy) {
369
372
emitError () << " expected complex type" ;
@@ -383,21 +386,14 @@ cir::ComplexAttr::verify(function_ref<InFlightDiagnostic()> emitError,
383
386
return success ();
384
387
}
385
388
386
- cir::ComplexAttr cir::ComplexAttr::getZero (Type type) {
389
+ mlir:: cir::ComplexAttr mlir:: cir::ComplexAttr::getZero (Type type) {
387
390
auto complexTy = type.cast <mlir::cir::ComplexType>();
388
391
auto elementTy = complexTy.getElementTy ();
389
392
390
- mlir::TypedAttr real;
391
- mlir::TypedAttr imag;
392
-
393
- if (elementTy.isa <mlir::cir::IntType>()) {
394
- real = mlir::cir::IntAttr::get (elementTy, 0 );
395
- imag = mlir::cir::IntAttr::get (elementTy, 0 );
396
- } else {
397
- real = mlir::cir::FPAttr::getZero (elementTy);
398
- imag = mlir::cir::FPAttr::getZero (elementTy);
399
- }
393
+ ::cir::CIRBaseBuilderTy builder (*type.getContext ());
400
394
395
+ auto real = builder.getZeroInitAttr (elementTy);
396
+ auto imag = builder.getZeroInitAttr (elementTy);
401
397
return get (type, real, imag);
402
398
}
403
399
0 commit comments