[clang] [CIR] Infer MLIR context in type builders when possible (PR #136362)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 18 13:06:15 PDT 2025
https://github.com/xlauko created https://github.com/llvm/llvm-project/pull/136362
None
>From 2c711e7f5365c1fe6a34254f69c6480a469aebe7 Mon Sep 17 00:00:00 2001
From: xlauko <xlauko at mail.muni.cz>
Date: Fri, 18 Apr 2025 21:59:30 +0200
Subject: [PATCH] [CIR] Infer MLIR context in type builders when possible
---
clang/include/clang/CIR/Dialect/IR/CIRTypes.td | 8 ++++++++
clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp | 3 +--
clang/lib/CIR/CodeGen/CIRGenRecordLayoutBuilder.cpp | 3 +--
clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 3 +--
4 files changed, 11 insertions(+), 6 deletions(-)
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;
}
More information about the cfe-commits
mailing list