-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[CIR] Infer MLIR context in type builders when possible #136362
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
[CIR] Infer MLIR context in type builders when possible #136362
Conversation
@llvm/pr-subscribers-clangir Author: Henrich Lauko (xlauko) ChangesThis mirrors incubator changes from llvm/clangir#1570 Full diff: https://github.com/llvm/llvm-project/pull/136362.diff 4 Files Affected:
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;
}
|
@llvm/pr-subscribers-clang Author: Henrich Lauko (xlauko) ChangesThis mirrors incubator changes from llvm/clangir#1570 Full diff: https://github.com/llvm/llvm-project/pull/136362.diff 4 Files Affected:
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;
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This mirrors incubator changes from llvm/clangir#1570