-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[CIR] Upstream basic support for ArrayType #130502
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
Changes from 1 commit
0b00b1b
541da71
b5cf42b
6ceabd2
101f7a0
b386dc1
18163c0
9fb619f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,6 +280,25 @@ def CIR_BoolType : | |
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // ArrayType | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def CIR_ArrayType : CIR_Type<"Array", "array", | ||
| [DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> { | ||
|
|
||
| let summary = "CIR array type"; | ||
| let description = [{ | ||
| `CIR.array` represents C/C++ constant arrays. | ||
| }]; | ||
|
|
||
| let parameters = (ins "mlir::Type":$eltType, "uint64_t":$size); | ||
|
|
||
| let assemblyFormat = [{ | ||
| `<` $eltType `x` $size `>` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // FuncType | ||
| //===----------------------------------------------------------------------===// | ||
|
|
@@ -386,7 +405,7 @@ def VoidPtr : Type< | |
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def CIR_AnyType : AnyTypeOf<[ | ||
| CIR_VoidType, CIR_BoolType, CIR_IntType, CIR_AnyFloat, CIR_PointerType, | ||
| CIR_VoidType, CIR_BoolType, CIR_ArrayType, CIR_IntType, CIR_AnyFloat, CIR_PointerType, | ||
|
||
| CIR_FuncType | ||
| ]>; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -202,6 +202,18 @@ mlir::Type CIRGenTypes::convertType(QualType type) { | |
| break; | ||
| } | ||
|
|
||
| case Type::ConstantArray: { | ||
| const ConstantArrayType *arrTy = cast<ConstantArrayType>(ty); | ||
| mlir::Type elemTy = convertTypeForMem(arrTy->getElementType()); | ||
|
|
||
| // FIXME: In LLVM, "lower arrays of undefined struct type to arrays of | ||
| // i8 just to have a concrete type". Not sure this makes sense in CIR yet. | ||
| assert(builder.isSized(elemTy) && "not implemented"); | ||
|
||
| resultType = cir::ArrayType::get(builder.getContext(), elemTy, | ||
| arrTy->getSize().getZExtValue()); | ||
| break; | ||
| } | ||
|
|
||
| case Type::FunctionNoProto: | ||
| case Type::FunctionProto: | ||
| resultType = convertFunctionTypeInternal(type); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,6 +166,9 @@ static LogicalResult checkConstantTypes(mlir::Operation *op, mlir::Type opType, | |
| return success(); | ||
| } | ||
|
|
||
| if (mlir::isa<cir::ArrayType>(opType)) | ||
|
||
| return success(); | ||
|
|
||
| assert(isa<TypedAttr>(attrType) && "What else could we be looking at here?"); | ||
| return op->emitOpError("global with type ") | ||
| << cast<TypedAttr>(attrType).getType() << " not yet supported"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -369,6 +369,22 @@ BoolType::getABIAlignment(const ::mlir::DataLayout &dataLayout, | |
| return 1; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Definitions | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| llvm::TypeSize | ||
| ArrayType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these functions being called with any of the test cases? I don't see any checks that would be related to this.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My point was that if the code isn't being called, you should leave it out until it is needed.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but it's part of the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Thanks for the clarification. |
||
| ::mlir::DataLayoutEntryListRef params) const { | ||
| return getSize() * dataLayout.getTypeSizeInBits(getEltType()); | ||
| } | ||
|
|
||
| uint64_t | ||
| ArrayType::getABIAlignment(const ::mlir::DataLayout &dataLayout, | ||
| ::mlir::DataLayoutEntryListRef params) const { | ||
| return dataLayout.getTypeABIAlignment(getEltType()); | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // PointerType Definitions | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - 2>&1 | FileCheck %s | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will multidimensional arrays and array function arguments work at this point? If so, can you add tests for those? |
||
|
|
||
| int a[10]; | ||
| // CHECK: cir.global external @a : !cir.array<!cir.int<s, 32> x 10> | ||
|
|
||
| extern int b[10]; | ||
| // CHECK: cir.global external @b : !cir.array<!cir.int<s, 32> x 10> | ||
|
|
||
| void f() { | ||
| int c[10]; | ||
| // CHECK: %[[ARR:.*]] = cir.alloca !cir.array<!cir.int<s, 32> x 10>, !cir.ptr<!cir.array<!cir.int<s, 32> x 10>>, ["c"] | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.