Skip to content

Commit 801f2b9

Browse files
committed
Rename FloatAttr and remove old mlir::FloatType and mlir::FloatAttr
1 parent 49b7712 commit 801f2b9

25 files changed

+238
-279
lines changed

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ def IntAttr : CIR_Attr<"Int", "int", [TypedAttrInterface]> {
203203
}
204204

205205
//===----------------------------------------------------------------------===//
206-
// FloatAttr
206+
// FPAttr
207207
//===----------------------------------------------------------------------===//
208208

209-
def FloatAttr : CIR_Attr<"Float", "float", [TypedAttrInterface]> {
210-
let summary = "An Attribute containing a floating-point value";
209+
def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
210+
let summary = "An attribute containing a floating-point value";
211211
let description = [{
212-
A float attribute is a literal attribute that represents a floating-point
212+
An fp attribute is a literal attribute that represents a floating-point
213213
value of the specified floating-point type.
214214
}];
215215
let parameters = (ins AttributeSelfTypeParameter<"">:$type, "APFloat":$value);
@@ -220,7 +220,7 @@ def FloatAttr : CIR_Attr<"Float", "float", [TypedAttrInterface]> {
220220
}]>,
221221
];
222222
let extraClassDeclaration = [{
223-
static FloatAttr getZero(mlir::cir::FloatType type);
223+
static FPAttr getZero(mlir::cir::FloatType type);
224224
}];
225225
let genVerifyDecl = 1;
226226
let hasCustomAssemblyFormat = 1;

clang/include/clang/CIR/Dialect/IR/CIRTypes.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ def CIR_Double : CIR_FloatType<"Double", "double"> {
123123

124124
// Constraints
125125

126-
def CIR_AnyFloat: Type<
127-
CPred<"$_self.isa<::mlir::FloatType, ::mlir::cir::FloatType>()">>;
126+
def CIR_AnyFloat: Type<CPred<"$_self.isa<::mlir::cir::FloatType>()">>;
128127

129128
//===----------------------------------------------------------------------===//
130129
// PointerType

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,8 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
224224
mlir::TypedAttr getZeroInitAttr(mlir::Type ty) {
225225
if (ty.isa<mlir::cir::IntType>())
226226
return mlir::cir::IntAttr::get(ty, 0);
227-
if (ty.isa<mlir::FloatType>())
228-
return mlir::FloatAttr::get(ty, 0.0);
229227
if (auto fltType = ty.dyn_cast<mlir::cir::FloatType>())
230-
return mlir::cir::FloatAttr::getZero(fltType);
228+
return mlir::cir::FPAttr::getZero(fltType);
231229
if (auto arrTy = ty.dyn_cast<mlir::cir::ArrayType>())
232230
return getZeroAttr(arrTy);
233231
if (auto ptrTy = ty.dyn_cast<mlir::cir::PointerType>())
@@ -252,13 +250,8 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
252250
if (const auto intVal = attr.dyn_cast<mlir::cir::IntAttr>())
253251
return intVal.isNullValue();
254252

255-
if (attr.isa<mlir::FloatAttr, mlir::cir::FloatAttr>()) {
256-
auto fpVal = [&attr] {
257-
if (auto fpAttr = attr.dyn_cast<mlir::cir::FloatAttr>())
258-
return fpAttr.getValue();
259-
return attr.cast<mlir::FloatAttr>().getValue();
260-
}();
261-
253+
if (auto fpAttr = attr.dyn_cast<mlir::cir::FPAttr>()) {
254+
auto fpVal = fpAttr.getValue();
262255
bool ignored;
263256
llvm::APFloat FV(+0.0);
264257
FV.convert(fpVal.getSemantics(), llvm::APFloat::rmNearestTiesToEven,
@@ -350,23 +343,23 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
350343
}
351344
bool isInt(mlir::Type i) { return i.isa<mlir::cir::IntType>(); }
352345

353-
mlir::FloatType getLongDouble80BitsTy() const {
354-
return typeCache.LongDouble80BitsTy;
346+
mlir::cir::FloatType getLongDouble80BitsTy() const {
347+
llvm_unreachable("NYI");
355348
}
356349

357350
/// Get the proper floating point type for the given semantics.
358-
mlir::FloatType getFloatTyForFormat(const llvm::fltSemantics &format,
359-
bool useNativeHalf) const {
351+
mlir::cir::FloatType getFloatTyForFormat(const llvm::fltSemantics &format,
352+
bool useNativeHalf) const {
360353
if (&format == &llvm::APFloat::IEEEhalf()) {
361354
llvm_unreachable("IEEEhalf float format is NYI");
362355
}
363356

364357
if (&format == &llvm::APFloat::BFloat())
365358
llvm_unreachable("BFloat float format is NYI");
366359
if (&format == &llvm::APFloat::IEEEsingle())
367-
llvm_unreachable("IEEEsingle float format is NYI");
360+
return typeCache.FloatTy;
368361
if (&format == &llvm::APFloat::IEEEdouble())
369-
llvm_unreachable("IEEEdouble float format is NYI");
362+
return typeCache.DoubleTy;
370363
if (&format == &llvm::APFloat::IEEEquad())
371364
llvm_unreachable("IEEEquad float format is NYI");
372365
if (&format == &llvm::APFloat::PPCDoubleDouble())
@@ -477,8 +470,7 @@ class CIRGenBuilderTy : public CIRBaseBuilderTy {
477470
}
478471

479472
bool isSized(mlir::Type ty) {
480-
if (ty.isIntOrFloat() ||
481-
ty.isa<mlir::cir::PointerType, mlir::cir::StructType,
473+
if (ty.isa<mlir::cir::PointerType, mlir::cir::StructType,
482474
mlir::cir::ArrayType, mlir::cir::BoolType, mlir::cir::IntType,
483475
mlir::cir::FloatType>())
484476
return true;

clang/lib/CIR/CodeGen/CIRGenExprConst.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,9 +1479,8 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &Value,
14791479
assert(0 && "not implemented");
14801480
else {
14811481
mlir::Type ty = CGM.getCIRType(DestType);
1482-
if (ty.isa<mlir::cir::FloatType>())
1483-
return CGM.getBuilder().getAttr<mlir::cir::FloatAttr>(ty, Init);
1484-
return builder.getFloatAttr(ty, Init);
1482+
assert(ty.isa<mlir::cir::FloatType>() && "expected floating-point type");
1483+
return CGM.getBuilder().getAttr<mlir::cir::FPAttr>(ty, Init);
14851484
}
14861485
}
14871486
case APValue::Array: {

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,10 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
165165
}
166166
mlir::Value VisitFloatingLiteral(const FloatingLiteral *E) {
167167
mlir::Type Ty = CGF.getCIRType(E->getType());
168-
if (Ty.isa<mlir::cir::FloatType>())
169-
return Builder.create<mlir::cir::ConstantOp>(
170-
CGF.getLoc(E->getExprLoc()), Ty,
171-
Builder.getAttr<mlir::cir::FloatAttr>(Ty, E->getValue()));
168+
assert(Ty.isa<mlir::cir::FloatType>() && "expect floating-point type");
172169
return Builder.create<mlir::cir::ConstantOp>(
173170
CGF.getLoc(E->getExprLoc()), Ty,
174-
Builder.getFloatAttr(Ty, E->getValue()));
171+
Builder.getAttr<mlir::cir::FPAttr>(Ty, E->getValue()));
175172
}
176173
mlir::Value VisitCharacterLiteral(const CharacterLiteral *E) {
177174
mlir::Type Ty = CGF.getCIRType(E->getType());
@@ -1205,7 +1202,7 @@ mlir::Value ScalarExprEmitter::buildSub(const BinOpInfo &Ops) {
12051202
llvm_unreachable("NYI");
12061203

12071204
assert(!UnimplementedFeature::cirVectorType());
1208-
if (Ops.LHS.getType().isa<mlir::FloatType, mlir::cir::FloatType>()) {
1205+
if (Ops.LHS.getType().isa<mlir::cir::FloatType>()) {
12091206
CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(CGF, Ops.FPFeatures);
12101207
return Builder.createFSub(Ops.LHS, Ops.RHS);
12111208
}
@@ -1673,20 +1670,20 @@ mlir::Value ScalarExprEmitter::buildScalarCast(
16731670
llvm_unreachable("NYI: signed bool");
16741671
if (CGF.getBuilder().isInt(DstTy)) {
16751672
CastKind = mlir::cir::CastKind::bool_to_int;
1676-
} else if (DstTy.isa<mlir::FloatType, mlir::cir::FloatType>()) {
1673+
} else if (DstTy.isa<mlir::cir::FloatType>()) {
16771674
CastKind = mlir::cir::CastKind::bool_to_float;
16781675
} else {
16791676
llvm_unreachable("Internal error: Cast to unexpected type");
16801677
}
16811678
} else if (CGF.getBuilder().isInt(SrcTy)) {
16821679
if (CGF.getBuilder().isInt(DstTy)) {
16831680
CastKind = mlir::cir::CastKind::integral;
1684-
} else if (DstTy.isa<mlir::FloatType, mlir::cir::FloatType>()) {
1681+
} else if (DstTy.isa<mlir::cir::FloatType>()) {
16851682
CastKind = mlir::cir::CastKind::int_to_float;
16861683
} else {
16871684
llvm_unreachable("Internal error: Cast to unexpected type");
16881685
}
1689-
} else if (SrcTy.isa<mlir::FloatType, mlir::cir::FloatType>()) {
1686+
} else if (SrcTy.isa<mlir::cir::FloatType>()) {
16901687
if (CGF.getBuilder().isInt(DstTy)) {
16911688
// If we can't recognize overflow as undefined behavior, assume that
16921689
// overflow saturates. This protects against normal optimizations if we
@@ -1696,7 +1693,7 @@ mlir::Value ScalarExprEmitter::buildScalarCast(
16961693
if (Builder.getIsFPConstrained())
16971694
llvm_unreachable("NYI");
16981695
CastKind = mlir::cir::CastKind::float_to_int;
1699-
} else if (DstTy.isa<mlir::FloatType, mlir::cir::FloatType>()) {
1696+
} else if (DstTy.isa<mlir::cir::FloatType>()) {
17001697
// TODO: split this to createFPExt/createFPTrunc
17011698
return Builder.createFloatingCast(Src, DstTy);
17021699
} else {

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
137137
DoubleTy = ::mlir::cir::FloatType::getDouble(builder.getContext());
138138
// TODO(cir): perhaps we should abstract long double variations into a custom
139139
// cir.long_double type. Said type would also hold the semantics for lowering.
140-
LongDouble80BitsTy = ::mlir::FloatType::getF80(builder.getContext());
141140

142141
// TODO: PointerWidthInBits
143142
PointerAlignInBytes =

clang/lib/CIR/CodeGen/CIRGenTypeCache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ struct CIRGenTypeCache {
3939
// cir.long_double type. Said type would also hold the semantics for lowering.
4040
mlir::cir::SingleType FloatTy;
4141
mlir::cir::DoubleType DoubleTy;
42-
mlir::FloatType LongDouble80BitsTy;
4342

4443
/// int
4544
mlir::Type UIntTy;

clang/lib/CIR/Dialect/IR/CIRAttrs.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,10 @@ LogicalResult IntAttr::verify(function_ref<InFlightDiagnostic()> emitError,
296296
}
297297

298298
//===----------------------------------------------------------------------===//
299-
// FloatAttr definitions
299+
// FPAttr definitions
300300
//===----------------------------------------------------------------------===//
301301

302-
Attribute cir::FloatAttr::parse(AsmParser &parser, Type odsType) {
302+
Attribute cir::FPAttr::parse(AsmParser &parser, Type odsType) {
303303
double value;
304304

305305
if (!odsType.isa<cir::FloatType>())
@@ -321,20 +321,19 @@ Attribute cir::FloatAttr::parse(AsmParser &parser, Type odsType) {
321321
convertedValue.convert(ty.getFloatSemantics(), llvm::RoundingMode::TowardZero,
322322
&losesInfo);
323323

324-
return cir::FloatAttr::get(ty, convertedValue);
324+
return cir::FPAttr::get(ty, convertedValue);
325325
}
326326

327-
void cir::FloatAttr::print(AsmPrinter &printer) const {
327+
void cir::FPAttr::print(AsmPrinter &printer) const {
328328
printer << '<' << getValue() << '>';
329329
}
330330

331-
cir::FloatAttr cir::FloatAttr::getZero(mlir::cir::FloatType type) {
331+
cir::FPAttr cir::FPAttr::getZero(mlir::cir::FloatType type) {
332332
return get(type, APFloat::getZero(type.getFloatSemantics()));
333333
}
334334

335-
LogicalResult
336-
cir::FloatAttr::verify(function_ref<InFlightDiagnostic()> emitError, Type type,
337-
APFloat value) {
335+
LogicalResult cir::FPAttr::verify(function_ref<InFlightDiagnostic()> emitError,
336+
Type type, APFloat value) {
338337
auto fltType = type.dyn_cast<cir::FloatType>();
339338
if (!fltType) {
340339
emitError() << "expected floating-point type";

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,7 @@ static LogicalResult checkConstantTypes(mlir::Operation *op, mlir::Type opType,
300300
return success();
301301
}
302302

303-
if (attrType
304-
.isa<mlir::cir::IntAttr, mlir::FloatAttr, mlir::cir::FloatAttr>()) {
303+
if (attrType.isa<mlir::cir::IntAttr, mlir::cir::FPAttr>()) {
305304
auto at = attrType.cast<TypedAttr>();
306305
if (at.getType() != opType) {
307306
return op->emitOpError("result type (")
@@ -424,13 +423,13 @@ LogicalResult CastOp::verify() {
424423
return success();
425424
}
426425
case cir::CastKind::floating: {
427-
if (!srcType.isa<mlir::FloatType, mlir::cir::FloatType>() ||
428-
!resType.isa<mlir::FloatType, mlir::cir::FloatType>())
426+
if (!srcType.isa<mlir::cir::FloatType>() ||
427+
!resType.isa<mlir::cir::FloatType>())
429428
return emitOpError() << "requries floating for source and result";
430429
return success();
431430
}
432431
case cir::CastKind::float_to_int: {
433-
if (!srcType.isa<mlir::FloatType, mlir::cir::FloatType>())
432+
if (!srcType.isa<mlir::cir::FloatType>())
434433
return emitOpError() << "requires floating for source";
435434
if (!resType.dyn_cast<mlir::cir::IntType>())
436435
return emitOpError() << "requires !IntegerType for result";
@@ -451,7 +450,7 @@ LogicalResult CastOp::verify() {
451450
return success();
452451
}
453452
case cir::CastKind::float_to_bool: {
454-
if (!srcType.isa<mlir::FloatType, mlir::cir::FloatType>())
453+
if (!srcType.isa<mlir::cir::FloatType>())
455454
return emitOpError() << "requires float for source";
456455
if (!resType.isa<mlir::cir::BoolType>())
457456
return emitOpError() << "requires !cir.bool for result";
@@ -467,14 +466,14 @@ LogicalResult CastOp::verify() {
467466
case cir::CastKind::int_to_float: {
468467
if (!srcType.isa<mlir::cir::IntType>())
469468
return emitOpError() << "requires !cir.int for source";
470-
if (!resType.isa<mlir::FloatType, mlir::cir::FloatType>())
469+
if (!resType.isa<mlir::cir::FloatType>())
471470
return emitOpError() << "requires !cir.float for result";
472471
return success();
473472
}
474473
case cir::CastKind::bool_to_float: {
475474
if (!srcType.isa<mlir::cir::BoolType>())
476475
return emitOpError() << "requires !cir.bool for source";
477-
if (!resType.isa<mlir::FloatType, mlir::cir::FloatType>())
476+
if (!resType.isa<mlir::cir::FloatType>())
478477
return emitOpError() << "requires !cir.float for result";
479478
return success();
480479
}

0 commit comments

Comments
 (0)