Skip to content

Commit e288561

Browse files
authored
[CIR] Clean up FPAttr (llvm#146662)
- Adds CIR_ prefix to the definition - Removes redundant builder and cleans up attribute creations This mirrors incubator changes from llvm/clangir#1726
1 parent 3dc09fb commit e288561

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

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

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

187-
def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
187+
def CIR_FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> {
188188
let summary = "An attribute containing a floating-point value";
189189
let description = [{
190190
An fp attribute is a literal attribute that represents a floating-point
191191
value of the specified floating-point type. Supporting only CIR FP types.
192192
}];
193+
193194
let parameters = (ins
194195
AttributeSelfTypeParameter<"", "::cir::FPTypeInterface">:$type,
195196
APFloatParameter<"">:$value
196197
);
198+
197199
let builders = [
198200
AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
199201
"const llvm::APFloat &":$value), [{
200202
return $_get(type.getContext(), mlir::cast<FPTypeInterface>(type), value);
201-
}]>,
202-
AttrBuilder<(ins "mlir::Type":$type,
203-
"const llvm::APFloat &":$value), [{
204-
return $_get($_ctxt, mlir::cast<FPTypeInterface>(type), value);
205-
}]>,
203+
}]>
206204
];
205+
207206
let extraClassDeclaration = [{
208207
static FPAttr getZero(mlir::Type type);
209208
}];
210-
let genVerifyDecl = 1;
211209

212210
let assemblyFormat = [{
213211
`<` custom<FloatLiteral>($value, ref($type)) `>`
214212
}];
213+
214+
let genVerifyDecl = 1;
215215
}
216216

217217

clang/lib/CIR/CodeGen/CIRGenBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ cir::ConstantOp
6363
clang::CIRGen::CIRGenBuilderTy::getConstFP(mlir::Location loc, mlir::Type t,
6464
llvm::APFloat fpVal) {
6565
assert(mlir::isa<cir::FPTypeInterface>(t) && "expected floating point type");
66-
return create<cir::ConstantOp>(loc, getAttr<cir::FPAttr>(t, fpVal));
66+
return create<cir::ConstantOp>(loc, cir::FPAttr::get(t, fpVal));
6767
}
6868

6969
// This can't be defined in Address.h because that file is included by

clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value,
698698
mlir::Type ty = cgm.convertType(destType);
699699
assert(mlir::isa<cir::FPTypeInterface>(ty) &&
700700
"expected floating-point type");
701-
return cgm.getBuilder().getAttr<cir::FPAttr>(ty, init);
701+
return cir::FPAttr::get(ty, init);
702702
}
703703
case APValue::Array: {
704704
const ArrayType *arrayTy = cgm.getASTContext().getAsArrayType(destType);
@@ -798,8 +798,8 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value,
798798
llvm::APFloat real = value.getComplexFloatReal();
799799
llvm::APFloat imag = value.getComplexFloatImag();
800800
return builder.getAttr<cir::ConstComplexAttr>(
801-
complexType, builder.getAttr<cir::FPAttr>(complexElemTy, real),
802-
builder.getAttr<cir::FPAttr>(complexElemTy, imag));
801+
complexType, cir::FPAttr::get(complexElemTy, real),
802+
cir::FPAttr::get(complexElemTy, imag));
803803
}
804804
case APValue::FixedPoint:
805805
case APValue::AddrLabelDiff:

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
165165
assert(mlir::isa<cir::FPTypeInterface>(type) &&
166166
"expect floating-point type");
167167
return builder.create<cir::ConstantOp>(
168-
cgf.getLoc(e->getExprLoc()),
169-
builder.getAttr<cir::FPAttr>(type, e->getValue()));
168+
cgf.getLoc(e->getExprLoc()), cir::FPAttr::get(type, e->getValue()));
170169
}
171170

172171
mlir::Value VisitCharacterLiteral(const CharacterLiteral *e) {

0 commit comments

Comments
 (0)