[clang] 7b68015 - [CIR] Infer MLIRContext in attr builders when possible (#136741)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 22 22:53:11 PDT 2025
Author: Henrich Lauko
Date: 2025-04-23T07:53:07+02:00
New Revision: 7b6801574d978ef418dd76257478cbbe5866b09f
URL: https://github.com/llvm/llvm-project/commit/7b6801574d978ef418dd76257478cbbe5866b09f
DIFF: https://github.com/llvm/llvm-project/commit/7b6801574d978ef418dd76257478cbbe5866b09f.diff
LOG: [CIR] Infer MLIRContext in attr builders when possible (#136741)
Mirrors incubator changes from https://github.com/llvm/clangir/pull/1582
Added:
Modified:
clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
Removed:
################################################################################
diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index 539268c6270f4..ef29791ed2783 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -166,8 +166,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
mlir::TypedAttr getConstPtrAttr(mlir::Type type, int64_t value) {
auto valueAttr = mlir::IntegerAttr::get(
mlir::IntegerType::get(type.getContext(), 64), value);
- return cir::ConstPtrAttr::get(
- getContext(), mlir::cast<cir::PointerType>(type), valueAttr);
+ return cir::ConstPtrAttr::get(type, valueAttr);
}
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType,
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index 293b83e70eff7..cce63c5cae608 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -202,6 +202,11 @@ def ConstArrayAttr : CIR_Attr<"ConstArray", "const_array", [TypedAttrInterface]>
zeros = typeSize - mlir::cast<mlir::ArrayAttr>(elts).size();
return $_get(type.getContext(), type, elts, zeros);
+ }]>,
+ AttrBuilderWithInferredContext<(ins "cir::ArrayType":$type,
+ "mlir::Attribute":$elts,
+ "int":$trailingZerosNum), [{
+ return $_get(type.getContext(), type, elts, trailingZerosNum);
}]>
];
@@ -234,11 +239,7 @@ def ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", [TypedAttrInterface]> {
"mlir::IntegerAttr":$value), [{
return $_get(type.getContext(), mlir::cast<cir::PointerType>(type),
value);
- }]>,
- AttrBuilder<(ins "mlir::Type":$type,
- "mlir::IntegerAttr":$value), [{
- return $_get($_ctxt, mlir::cast<cir::PointerType>(type), value);
- }]>,
+ }]>
];
let extraClassDeclaration = [{
bool isNullValue() const { return getValue().getInt() == 0; }
More information about the cfe-commits
mailing list