[CIR] Clean up FPAttr (#146662)

- Adds CIR_ prefix to the definition
- Removes redundant builder and cleans up attribute creations

This mirrors incubator changes from https://github.com/llvm/clangir/pull/1726
This commit is contained in:
Henrich Lauko
2025-07-02 16:52:15 +02:00
committed by GitHub
parent 3dc09fbf29
commit e288561e6b
4 changed files with 12 additions and 13 deletions

View File

@@ -184,34 +184,34 @@ def CIR_IntAttr : CIR_Attr<"Int", "int", [TypedAttrInterface]> {
// FPAttr
//===----------------------------------------------------------------------===//
def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
def CIR_FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
let summary = "An attribute containing a floating-point value";
let description = [{
An fp attribute is a literal attribute that represents a floating-point
value of the specified floating-point type. Supporting only CIR FP types.
}];
let parameters = (ins
AttributeSelfTypeParameter<"", "::cir::FPTypeInterface">:$type,
APFloatParameter<"">:$value
);
let builders = [
AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
"const llvm::APFloat &":$value), [{
return $_get(type.getContext(), mlir::cast<FPTypeInterface>(type), value);
}]>,
AttrBuilder<(ins "mlir::Type":$type,
"const llvm::APFloat &":$value), [{
return $_get($_ctxt, mlir::cast<FPTypeInterface>(type), value);
}]>,
}]>
];
let extraClassDeclaration = [{
static FPAttr getZero(mlir::Type type);
}];
let genVerifyDecl = 1;
let assemblyFormat = [{
`<` custom<FloatLiteral>($value, ref($type)) `>`
}];
let genVerifyDecl = 1;
}

View File

@@ -63,7 +63,7 @@ cir::ConstantOp
clang::CIRGen::CIRGenBuilderTy::getConstFP(mlir::Location loc, mlir::Type t,
llvm::APFloat fpVal) {
assert(mlir::isa<cir::FPTypeInterface>(t) && "expected floating point type");
return create<cir::ConstantOp>(loc, getAttr<cir::FPAttr>(t, fpVal));
return create<cir::ConstantOp>(loc, cir::FPAttr::get(t, fpVal));
}
// This can't be defined in Address.h because that file is included by

View File

@@ -698,7 +698,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value,
mlir::Type ty = cgm.convertType(destType);
assert(mlir::isa<cir::FPTypeInterface>(ty) &&
"expected floating-point type");
return cgm.getBuilder().getAttr<cir::FPAttr>(ty, init);
return cir::FPAttr::get(ty, init);
}
case APValue::Array: {
const ArrayType *arrayTy = cgm.getASTContext().getAsArrayType(destType);
@@ -798,8 +798,8 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value,
llvm::APFloat real = value.getComplexFloatReal();
llvm::APFloat imag = value.getComplexFloatImag();
return builder.getAttr<cir::ConstComplexAttr>(
complexType, builder.getAttr<cir::FPAttr>(complexElemTy, real),
builder.getAttr<cir::FPAttr>(complexElemTy, imag));
complexType, cir::FPAttr::get(complexElemTy, real),
cir::FPAttr::get(complexElemTy, imag));
}
case APValue::FixedPoint:
case APValue::AddrLabelDiff:

View File

@@ -165,8 +165,7 @@ public:
assert(mlir::isa<cir::FPTypeInterface>(type) &&
"expect floating-point type");
return builder.create<cir::ConstantOp>(
cgf.getLoc(e->getExprLoc()),
builder.getAttr<cir::FPAttr>(type, e->getValue()));
cgf.getLoc(e->getExprLoc()), cir::FPAttr::get(type, e->getValue()));
}
mlir::Value VisitCharacterLiteral(const CharacterLiteral *e) {