Author: Henrich Lauko Date: 2025-04-19T08:40:11+02:00 New Revision: 9b6fbc06ad532e455960bbe6e4bffa5e72eb9e8c
URL: https://github.com/llvm/llvm-project/commit/9b6fbc06ad532e455960bbe6e4bffa5e72eb9e8c DIFF: https://github.com/llvm/llvm-project/commit/9b6fbc06ad532e455960bbe6e4bffa5e72eb9e8c.diff LOG: [CIR] Infer MLIR context in type builders when possible (#136362) This mirrors incubator changes from https://github.com/llvm/clangir/pull/1570 Added: Modified: clang/include/clang/CIR/Dialect/IR/CIRTypes.td clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp clang/lib/CIR/CodeGen/CIRGenTypes.cpp Removed: ################################################################################ diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td index b028bc7db4e59..a552b6081f5dc 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td @@ -294,6 +294,14 @@ def CIR_ArrayType : CIR_Type<"Array", "array", let parameters = (ins "mlir::Type":$eltType, "uint64_t":$size); + let builders = [ + TypeBuilderWithInferredContext<(ins + "mlir::Type":$eltType, "uint64_t":$size + ), [{ + return $_get(eltType.getContext(), eltType, size); + }]>, + ]; + let assemblyFormat = [{ `<` $eltType `x` $size `>` }]; diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp index 50fa029851f33..0caa8961ed0a6 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp @@ -206,8 +206,7 @@ emitArrayConstant(CIRGenModule &cgm, mlir::Type desiredType, eles.push_back(element); return cir::ConstArrayAttr::get( - cir::ArrayType::get(builder.getContext(), commonElementType, - arrayBound), + cir::ArrayType::get(commonElementType, arrayBound), mlir::ArrayAttr::get(builder.getContext(), eles)); } diff --git a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp index 5e209b5b92503..83aba256cd48e 100644 --- a/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp @@ -102,8 +102,7 @@ struct CIRRecordLowering final { mlir::Type type = getCharType(); return numberOfChars == CharUnits::One() ? type - : cir::ArrayType::get(type.getContext(), type, - numberOfChars.getQuantity()); + : cir::ArrayType::get(type, numberOfChars.getQuantity()); } mlir::Type getStorageType(const FieldDecl *fieldDecl) { diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp index 7bd86cf0c7bcd..c286aef360b01 100644 --- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp @@ -395,8 +395,7 @@ mlir::Type CIRGenTypes::convertType(QualType type) { case Type::ConstantArray: { const ConstantArrayType *arrTy = cast<ConstantArrayType>(ty); mlir::Type elemTy = convertTypeForMem(arrTy->getElementType()); - resultType = cir::ArrayType::get(builder.getContext(), elemTy, - arrTy->getSize().getZExtValue()); + resultType = cir::ArrayType::get(elemTy, arrTy->getSize().getZExtValue()); break; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits