Skip to content

Commit 4e600d4

Browse files
xlaukolanza
authored andcommitted
[CIR] Clean up FPAttr (llvm#1726)
- Adds CIR_ prefix to the definition - Removes redundant builder and cleans up attribute creations
1 parent 80473e8 commit 4e600d4

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,34 +477,34 @@ def CIR_IntAttr : CIR_Attr<"Int", "int", [TypedAttrInterface]> {
477477
// FPAttr
478478
//===----------------------------------------------------------------------===//
479479

480-
def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
480+
def CIR_FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
481481
let summary = "An attribute containing a floating-point value";
482482
let description = [{
483483
An fp attribute is a literal attribute that represents a floating-point
484484
value of the specified floating-point type. Supporting only CIR FP types.
485485
}];
486+
486487
let parameters = (ins
487488
AttributeSelfTypeParameter<"", "::cir::FPTypeInterface">:$type,
488489
APFloatParameter<"">:$value
489490
);
491+
490492
let builders = [
491493
AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
492494
"const llvm::APFloat &":$value), [{
493495
return $_get(type.getContext(), mlir::cast<FPTypeInterface>(type), value);
494-
}]>,
495-
AttrBuilder<(ins "mlir::Type":$type,
496-
"const llvm::APFloat &":$value), [{
497-
return $_get($_ctxt, mlir::cast<FPTypeInterface>(type), value);
498-
}]>,
496+
}]>
499497
];
498+
500499
let extraClassDeclaration = [{
501500
static FPAttr getZero(mlir::Type type);
502501
}];
503-
let genVerifyDecl = 1;
504502

505503
let assemblyFormat = [{
506504
`<` custom<FloatLiteral>($value, ref($type)) `>`
507505
}];
506+
507+
let genVerifyDecl = 1;
508508
}
509509

510510
//===----------------------------------------------------------------------===//

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
562562
llvm::APFloat fpVal) {
563563
assert((mlir::isa<cir::SingleType, cir::DoubleType>(t)) &&
564564
"expected cir::SingleType or cir::DoubleType");
565-
return create<cir::ConstantOp>(loc, getAttr<cir::FPAttr>(t, fpVal));
565+
return create<cir::ConstantOp>(loc, cir::FPAttr::get(t, fpVal));
566566
}
567567

568568
cir::IsFPClassOp createIsFPClass(mlir::Location loc, mlir::Value src,

clang/lib/CIR/CodeGen/CIRGenExprConst.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &Value,
19181918
mlir::Type ty = CGM.convertType(DestType);
19191919
assert(mlir::isa<cir::FPTypeInterface>(ty) &&
19201920
"expected floating-point type");
1921-
return CGM.getBuilder().getAttr<cir::FPAttr>(ty, Init);
1921+
return cir::FPAttr::get(ty, Init);
19221922
}
19231923
}
19241924
case APValue::Array: {
@@ -2026,8 +2026,8 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &Value,
20262026
llvm::APFloat real = Value.getComplexFloatReal();
20272027
llvm::APFloat imag = Value.getComplexFloatImag();
20282028
return builder.getAttr<cir::ComplexAttr>(
2029-
complexType, builder.getAttr<cir::FPAttr>(complexElemTy, real),
2030-
builder.getAttr<cir::FPAttr>(complexElemTy, imag));
2029+
complexType, cir::FPAttr::get(complexElemTy, real),
2030+
cir::FPAttr::get(complexElemTy, imag));
20312031
}
20322032
case APValue::FixedPoint:
20332033
case APValue::AddrLabelDiff:

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
188188
mlir::Value VisitFloatingLiteral(const FloatingLiteral *E) {
189189
mlir::Type Ty = CGF.convertType(E->getType());
190190
assert(mlir::isa<cir::FPTypeInterface>(Ty) && "expect floating-point type");
191-
return Builder.create<cir::ConstantOp>(
192-
CGF.getLoc(E->getExprLoc()),
193-
Builder.getAttr<cir::FPAttr>(Ty, E->getValue()));
191+
return Builder.create<cir::ConstantOp>(CGF.getLoc(E->getExprLoc()),
192+
cir::FPAttr::get(Ty, E->getValue()));
194193
}
195194
mlir::Value VisitCharacterLiteral(const CharacterLiteral *E) {
196195
mlir::Type Ty = CGF.convertType(E->getType());

0 commit comments

Comments
 (0)