Skip to content

Commit 348d477

Browse files
committed
Address code review comments
1 parent 6a83054 commit 348d477

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ def ConstComplexAttr : CIR_Attr<"ConstComplex", "const_complex",
307307
);
308308

309309
let builders = [
310-
AttrBuilderWithInferredContext<(ins "cir::ComplexType":$type,
311-
"mlir::TypedAttr":$real,
310+
AttrBuilderWithInferredContext<(ins "mlir::TypedAttr":$real,
312311
"mlir::TypedAttr":$imag), [{
312+
auto type = cir::ComplexType::get(real.getType());
313313
return $_get(type.getContext(), type, real, imag);
314314
}]>,
315315
];

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ void CIRGenFunction::emitExprAsInit(const Expr *init, const ValueDecl *d,
505505
"emitExprAsInit: complex type captured by init");
506506
mlir::Location loc = getLoc(init->getExprLoc());
507507
emitStoreOfComplex(loc, complex, lvalue,
508-
/*init*/ true);
508+
/*isInit*/ true);
509509
return;
510510
}
511511
case cir::TEK_Aggregate:

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ void ComplexExprEmitter::emitStoreOfComplex(mlir::Location loc, mlir::Value val,
4545
}
4646

4747
mlir::Value ComplexExprEmitter::VisitInitListExpr(InitListExpr *e) {
48+
mlir::Location loc = cgf.getLoc(e->getExprLoc());
4849
if (e->getNumInits() == 2) {
4950
mlir::Value real = cgf.emitScalarExpr(e->getInit(0));
5051
mlir::Value imag = cgf.emitScalarExpr(e->getInit(1));
51-
return builder.createComplexCreate(cgf.getLoc(e->getExprLoc()), real, imag);
52+
return builder.createComplexCreate(loc, real, imag);
5253
}
5354

5455
if (e->getNumInits() == 1) {
@@ -57,14 +58,11 @@ mlir::Value ComplexExprEmitter::VisitInitListExpr(InitListExpr *e) {
5758
}
5859

5960
assert(e->getNumInits() == 0 && "Unexpected number of inits");
60-
mlir::Location loc = cgf.getLoc(e->getExprLoc());
6161
QualType complexElemTy =
6262
e->getType()->castAs<clang::ComplexType>()->getElementType();
6363
mlir::Type complexElemLLVMTy = cgf.convertType(complexElemTy);
6464
mlir::TypedAttr defaultValue = builder.getZeroInitAttr(complexElemLLVMTy);
65-
auto complexTy = cir::ComplexType::get(complexElemLLVMTy);
66-
auto complexAttr =
67-
cir::ConstComplexAttr::get(complexTy, defaultValue, defaultValue);
65+
auto complexAttr = cir::ConstComplexAttr::get(defaultValue, defaultValue);
6866
return builder.create<cir::ConstantOp>(loc, complexAttr);
6967
}
7068

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,8 +1763,7 @@ OpFoldResult cir::ComplexCreateOp::fold(FoldAdaptor adaptor) {
17631763
// `#cir.const_complex` operation.
17641764
auto realAttr = mlir::cast<mlir::TypedAttr>(real);
17651765
auto imagAttr = mlir::cast<mlir::TypedAttr>(imag);
1766-
auto complexTy = cir::ComplexType::get(realAttr.getType());
1767-
return cir::ConstComplexAttr::get(complexTy, realAttr, imagAttr);
1766+
return cir::ConstComplexAttr::get(realAttr, imagAttr);
17681767
}
17691768

17701769
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)