Skip to content

Commit 7b68015

Browse files
authored
[CIR] Infer MLIRContext in attr builders when possible (#136741)
Mirrors incubator changes from llvm/clangir#1582
1 parent 3ccfbc8 commit 7b68015

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
166166
mlir::TypedAttr getConstPtrAttr(mlir::Type type, int64_t value) {
167167
auto valueAttr = mlir::IntegerAttr::get(
168168
mlir::IntegerType::get(type.getContext(), 64), value);
169-
return cir::ConstPtrAttr::get(
170-
getContext(), mlir::cast<cir::PointerType>(type), valueAttr);
169+
return cir::ConstPtrAttr::get(type, valueAttr);
171170
}
172171

173172
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType,

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ def ConstArrayAttr : CIR_Attr<"ConstArray", "const_array", [TypedAttrInterface]>
202202
zeros = typeSize - mlir::cast<mlir::ArrayAttr>(elts).size();
203203

204204
return $_get(type.getContext(), type, elts, zeros);
205+
}]>,
206+
AttrBuilderWithInferredContext<(ins "cir::ArrayType":$type,
207+
"mlir::Attribute":$elts,
208+
"int":$trailingZerosNum), [{
209+
return $_get(type.getContext(), type, elts, trailingZerosNum);
205210
}]>
206211
];
207212

@@ -234,11 +239,7 @@ def ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", [TypedAttrInterface]> {
234239
"mlir::IntegerAttr":$value), [{
235240
return $_get(type.getContext(), mlir::cast<cir::PointerType>(type),
236241
value);
237-
}]>,
238-
AttrBuilder<(ins "mlir::Type":$type,
239-
"mlir::IntegerAttr":$value), [{
240-
return $_get($_ctxt, mlir::cast<cir::PointerType>(type), value);
241-
}]>,
242+
}]>
242243
];
243244
let extraClassDeclaration = [{
244245
bool isNullValue() const { return getValue().getInt() == 0; }

0 commit comments

Comments
 (0)