Skip to content

Conversation

xlauko
Copy link
Contributor

@xlauko xlauko commented Jul 2, 2025

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

This mirrors incubator changes from llvm/clangir#1726

@xlauko
Copy link
Contributor Author

xlauko commented Jul 2, 2025

@xlauko xlauko marked this pull request as ready for review July 2, 2025 10:18
@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Jul 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 2, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clangir

Author: Henrich Lauko (xlauko)

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

This mirrors incubator changes from llvm/clangir#1726


Full diff: https://github.com/llvm/llvm-project/pull/146662.diff

4 Files Affected:

  • (modified) clang/include/clang/CIR/Dialect/IR/CIRAttrs.td (+7-7)
  • (modified) clang/lib/CIR/CodeGen/CIRGenBuilder.cpp (+1-1)
  • (modified) clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp (+3-3)
  • (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+1-2)
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) {

@xlauko
Copy link
Contributor Author

xlauko commented Jul 2, 2025

Merge activity

  • Jul 2, 2:25 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 2, 2:37 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 2, 2:40 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 2, 2:43 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 2, 2:46 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 2, 2:49 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 2, 2:52 PM UTC: @xlauko merged this pull request with Graphite.

@xlauko xlauko force-pushed the users/xlauko/cir-int-attr-cleanup branch 2 times, most recently from 61e0a91 to aa2ee38 Compare July 2, 2025 14:32
Base automatically changed from users/xlauko/cir-int-attr-cleanup to main July 2, 2025 14:36
@xlauko xlauko force-pushed the users/xlauko/cir-fp-attr-refactor branch 4 times, most recently from a957afa to 842c9ca Compare July 2, 2025 14:45
- Adds CIR_ prefix to the definition
- Removes redundant builder and cleans up attribute creations

This mirrors incubator changes from llvm/clangir#1726
@xlauko xlauko force-pushed the users/xlauko/cir-fp-attr-refactor branch from 842c9ca to 5d8c805 Compare July 2, 2025 14:49
@xlauko xlauko merged commit e288561 into main Jul 2, 2025
5 of 7 checks passed
@xlauko xlauko deleted the users/xlauko/cir-fp-attr-refactor branch July 2, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants