Skip to content

[CIR] Make UndefAttr use AttrBuilderWithInferredContext #136605

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

Conversation

xlauko
Copy link
Contributor

@xlauko xlauko commented Apr 21, 2025

This mirrors incubator changes from llvm/clangir#1577

@xlauko
Copy link
Contributor Author

xlauko commented Apr 21, 2025

@xlauko xlauko marked this pull request as ready for review April 21, 2025 20:28
@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Apr 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 21, 2025

@llvm/pr-subscribers-clangir

Author: Henrich Lauko (xlauko)

Changes

This mirrors incubator changes from llvm/clangir#1577


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

2 Files Affected:

  • (modified) clang/include/clang/CIR/Dialect/IR/CIRAttrs.td (+7)
  • (modified) clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp (+2-2)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 214db1b1caeeb..dfe15a10fa54e 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -93,6 +93,13 @@ def UndefAttr : CIR_Attr<"Undef", "undef", [TypedAttrInterface]> {
   }];
 
   let parameters = (ins AttributeSelfTypeParameter<"">:$type);
+
+  let builders = [
+    AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{
+      return $_get(type.getContext(), type);
+    }]>
+  ];
+
   let assemblyFormat = [{}];
 }
 
diff --git a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
index 9cd5c54e6c19e..fe8a5e7428a81 100644
--- a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
@@ -34,8 +34,8 @@ llvm::SmallVector<MemorySlot> cir::AllocaOp::getPromotableSlots() {
 
 Value cir::AllocaOp::getDefaultValue(const MemorySlot &slot,
                                      OpBuilder &builder) {
-  return builder.create<cir::ConstantOp>(
-      getLoc(), slot.elemType, builder.getAttr<cir::UndefAttr>(slot.elemType));
+  return builder.create<cir::ConstantOp>(getLoc(), slot.elemType,
+                                         cir::UndefAttr::get(slot.elemType));
 }
 
 void cir::AllocaOp::handleBlockArgument(const MemorySlot &slot,

@llvmbot
Copy link
Member

llvmbot commented Apr 21, 2025

@llvm/pr-subscribers-clang

Author: Henrich Lauko (xlauko)

Changes

This mirrors incubator changes from llvm/clangir#1577


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

2 Files Affected:

  • (modified) clang/include/clang/CIR/Dialect/IR/CIRAttrs.td (+7)
  • (modified) clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp (+2-2)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 214db1b1caeeb..dfe15a10fa54e 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -93,6 +93,13 @@ def UndefAttr : CIR_Attr<"Undef", "undef", [TypedAttrInterface]> {
   }];
 
   let parameters = (ins AttributeSelfTypeParameter<"">:$type);
+
+  let builders = [
+    AttrBuilderWithInferredContext<(ins "mlir::Type":$type), [{
+      return $_get(type.getContext(), type);
+    }]>
+  ];
+
   let assemblyFormat = [{}];
 }
 
diff --git a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
index 9cd5c54e6c19e..fe8a5e7428a81 100644
--- a/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
@@ -34,8 +34,8 @@ llvm::SmallVector<MemorySlot> cir::AllocaOp::getPromotableSlots() {
 
 Value cir::AllocaOp::getDefaultValue(const MemorySlot &slot,
                                      OpBuilder &builder) {
-  return builder.create<cir::ConstantOp>(
-      getLoc(), slot.elemType, builder.getAttr<cir::UndefAttr>(slot.elemType));
+  return builder.create<cir::ConstantOp>(getLoc(), slot.elemType,
+                                         cir::UndefAttr::get(slot.elemType));
 }
 
 void cir::AllocaOp::handleBlockArgument(const MemorySlot &slot,

@xlauko xlauko requested a review from andykaylor April 21, 2025 20:29
Copy link
Contributor

@andykaylor andykaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@xlauko
Copy link
Contributor Author

xlauko commented Apr 22, 2025

Merge activity

@xlauko xlauko force-pushed the users/xlauko/cir-zero-attr-builder-with-inferred-context branch 2 times, most recently from 6f59c47 to 7790612 Compare April 22, 2025 06:34
@xlauko xlauko force-pushed the users/xlauko/cir-undef-attr-builder-with-inferred-context branch from 40e72dd to acad78f Compare April 22, 2025 06:57
@xlauko xlauko force-pushed the users/xlauko/cir-zero-attr-builder-with-inferred-context branch from 7790612 to a715e75 Compare April 22, 2025 06:57
Base automatically changed from users/xlauko/cir-zero-attr-builder-with-inferred-context to main April 22, 2025 06:59
@xlauko xlauko force-pushed the users/xlauko/cir-undef-attr-builder-with-inferred-context branch from acad78f to ab35526 Compare April 22, 2025 07:01
@xlauko xlauko force-pushed the users/xlauko/cir-undef-attr-builder-with-inferred-context branch from ab35526 to e31c61b Compare April 22, 2025 07:05
@xlauko xlauko merged commit 8639b36 into main Apr 22, 2025
6 of 10 checks passed
@xlauko xlauko deleted the users/xlauko/cir-undef-attr-builder-with-inferred-context branch April 22, 2025 07:08
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
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.

3 participants