-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[CIR] Clean up FPAttr #146662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[CIR] Clean up FPAttr #146662
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced Jul 2, 2025
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clangir Author: Henrich Lauko (xlauko) Changes
This mirrors incubator changes from llvm/clangir#1726 Full diff: https://github.com/llvm/llvm-project/pull/146662.diff 4 Files Affected:
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index a042f5cd0c19e..569e62ae11612 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -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;
}
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp b/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
index b94963c71f9c1..4a5a1dd53a05a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.cpp
@@ -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
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
index 5fc7a92cd00f9..5b3bf85cefbb0 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
@@ -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:
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 06827f84f34d4..6eeecca7e7c8f 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -165,8 +165,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
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) {
|
erichkeane
approved these changes
Jul 2, 2025
Merge activity
|
AmrDeveloper
approved these changes
Jul 2, 2025
61e0a91
to
aa2ee38
Compare
a957afa
to
842c9ca
Compare
- Adds CIR_ prefix to the definition - Removes redundant builder and cleans up attribute creations This mirrors incubator changes from llvm/clangir#1726
842c9ca
to
5d8c805
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This mirrors incubator changes from llvm/clangir#1726