Skip to content

[CIR] Infer MLIRContext in attr builders when possible #136741

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 1 commit into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}]>
];

Expand Down Expand Up @@ -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; }
Expand Down
Loading