Skip to content

[CIR] Let ConstantOp builder infer its type automatically #136606

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 22, 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
4 changes: 2 additions & 2 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ,
const llvm::APInt &val) {
return create<cir::ConstantOp>(loc, typ, getAttr<cir::IntAttr>(typ, val));
return create<cir::ConstantOp>(loc, getAttr<cir::IntAttr>(typ, val));
}

cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) {
return create<cir::ConstantOp>(loc, attr.getType(), attr);
return create<cir::ConstantOp>(loc, attr);
}

cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty,
Expand Down
9 changes: 0 additions & 9 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,9 @@ def ConstantOp : CIR_Op<"const",
```
}];

// The constant operation takes an attribute as the only input.
let arguments = (ins TypedAttrInterface:$value);

// The constant operation returns a single value of CIR_AnyType.
let results = (outs CIR_AnyType:$res);

let builders = [
OpBuilder<(ins "cir::BoolAttr":$value), [{
build($_builder, $_state, value.getType(), value);
}]>
];

let assemblyFormat = "attr-dict $value";

let hasVerifier = 1;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
// Creates constant nullptr for pointer type ty.
cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc) {
assert(!cir::MissingFeatures::targetCodeGenInfoGetNullPointer());
return create<cir::ConstantOp>(loc, ty, getConstPtrAttr(ty, 0));
return create<cir::ConstantOp>(loc, getConstPtrAttr(ty, 0));
}

mlir::Value createNeg(mlir::Value value) {
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
mlir::Value VisitIntegerLiteral(const IntegerLiteral *e) {
mlir::Type type = cgf.convertType(e->getType());
return builder.create<cir::ConstantOp>(
cgf.getLoc(e->getExprLoc()), type,
cgf.getLoc(e->getExprLoc()),
builder.getAttr<cir::IntAttr>(type, e->getValue()));
}

Expand All @@ -147,7 +147,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
assert(mlir::isa<cir::CIRFPTypeInterface>(type) &&
"expect floating-point type");
return builder.create<cir::ConstantOp>(
cgf.getLoc(e->getExprLoc()), type,
cgf.getLoc(e->getExprLoc()),
builder.getAttr<cir::FPAttr>(type, e->getValue()));
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/IR/CIRMemorySlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ llvm::SmallVector<MemorySlot> cir::AllocaOp::getPromotableSlots() {

Value cir::AllocaOp::getDefaultValue(const MemorySlot &slot,
OpBuilder &builder) {
return builder.create<cir::ConstantOp>(getLoc(), slot.elemType,
return builder.create<cir::ConstantOp>(getLoc(),
cir::UndefAttr::get(slot.elemType));
}

Expand Down
Loading