[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:
@@ -184,34 +184,34 @@ def CIR_IntAttr : CIR_Attr<"Int", "int", [TypedAttrInterface]> {
|
|||||||
// FPAttr
|
// 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 summary = "An attribute containing a floating-point value";
|
||||||
let description = [{
|
let description = [{
|
||||||
An fp attribute is a literal attribute that represents a floating-point
|
An fp attribute is a literal attribute that represents a floating-point
|
||||||
value of the specified floating-point type. Supporting only CIR FP types.
|
value of the specified floating-point type. Supporting only CIR FP types.
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let parameters = (ins
|
let parameters = (ins
|
||||||
AttributeSelfTypeParameter<"", "::cir::FPTypeInterface">:$type,
|
AttributeSelfTypeParameter<"", "::cir::FPTypeInterface">:$type,
|
||||||
APFloatParameter<"">:$value
|
APFloatParameter<"">:$value
|
||||||
);
|
);
|
||||||
|
|
||||||
let builders = [
|
let builders = [
|
||||||
AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
|
AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
|
||||||
"const llvm::APFloat &":$value), [{
|
"const llvm::APFloat &":$value), [{
|
||||||
return $_get(type.getContext(), mlir::cast<FPTypeInterface>(type), 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 = [{
|
let extraClassDeclaration = [{
|
||||||
static FPAttr getZero(mlir::Type type);
|
static FPAttr getZero(mlir::Type type);
|
||||||
}];
|
}];
|
||||||
let genVerifyDecl = 1;
|
|
||||||
|
|
||||||
let assemblyFormat = [{
|
let assemblyFormat = [{
|
||||||
`<` custom<FloatLiteral>($value, ref($type)) `>`
|
`<` custom<FloatLiteral>($value, ref($type)) `>`
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
let genVerifyDecl = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ cir::ConstantOp
|
|||||||
clang::CIRGen::CIRGenBuilderTy::getConstFP(mlir::Location loc, mlir::Type t,
|
clang::CIRGen::CIRGenBuilderTy::getConstFP(mlir::Location loc, mlir::Type t,
|
||||||
llvm::APFloat fpVal) {
|
llvm::APFloat fpVal) {
|
||||||
assert(mlir::isa<cir::FPTypeInterface>(t) && "expected floating point type");
|
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
|
// This can't be defined in Address.h because that file is included by
|
||||||
|
|||||||
@@ -698,7 +698,7 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value,
|
|||||||
mlir::Type ty = cgm.convertType(destType);
|
mlir::Type ty = cgm.convertType(destType);
|
||||||
assert(mlir::isa<cir::FPTypeInterface>(ty) &&
|
assert(mlir::isa<cir::FPTypeInterface>(ty) &&
|
||||||
"expected floating-point type");
|
"expected floating-point type");
|
||||||
return cgm.getBuilder().getAttr<cir::FPAttr>(ty, init);
|
return cir::FPAttr::get(ty, init);
|
||||||
}
|
}
|
||||||
case APValue::Array: {
|
case APValue::Array: {
|
||||||
const ArrayType *arrayTy = cgm.getASTContext().getAsArrayType(destType);
|
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 real = value.getComplexFloatReal();
|
||||||
llvm::APFloat imag = value.getComplexFloatImag();
|
llvm::APFloat imag = value.getComplexFloatImag();
|
||||||
return builder.getAttr<cir::ConstComplexAttr>(
|
return builder.getAttr<cir::ConstComplexAttr>(
|
||||||
complexType, builder.getAttr<cir::FPAttr>(complexElemTy, real),
|
complexType, cir::FPAttr::get(complexElemTy, real),
|
||||||
builder.getAttr<cir::FPAttr>(complexElemTy, imag));
|
cir::FPAttr::get(complexElemTy, imag));
|
||||||
}
|
}
|
||||||
case APValue::FixedPoint:
|
case APValue::FixedPoint:
|
||||||
case APValue::AddrLabelDiff:
|
case APValue::AddrLabelDiff:
|
||||||
|
|||||||
@@ -165,8 +165,7 @@ public:
|
|||||||
assert(mlir::isa<cir::FPTypeInterface>(type) &&
|
assert(mlir::isa<cir::FPTypeInterface>(type) &&
|
||||||
"expect floating-point type");
|
"expect floating-point type");
|
||||||
return builder.create<cir::ConstantOp>(
|
return builder.create<cir::ConstantOp>(
|
||||||
cgf.getLoc(e->getExprLoc()),
|
cgf.getLoc(e->getExprLoc()), cir::FPAttr::get(type, e->getValue()));
|
||||||
builder.getAttr<cir::FPAttr>(type, e->getValue()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mlir::Value VisitCharacterLiteral(const CharacterLiteral *e) {
|
mlir::Value VisitCharacterLiteral(const CharacterLiteral *e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user