-
Notifications
You must be signed in to change notification settings - Fork 14.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 all commits
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 |
---|---|---|
|
@@ -369,6 +369,22 @@ BoolType::getABIAlignment(const ::mlir::DataLayout &dataLayout, | |
return 1; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Definitions | ||
//===----------------------------------------------------------------------===// | ||
|
||
llvm::TypeSize | ||
ArrayType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout, | ||
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. 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 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. 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 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,26 @@ | ||
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - 2>&1 | FileCheck %s | ||
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> | ||
|
||
int aa[10][5]; | ||
// CHECK: cir.global external @aa : !cir.array<!cir.array<!cir.int<s, 32> x 5> x 10> | ||
|
||
extern int b[10]; | ||
// CHECK: cir.global external @b : !cir.array<!cir.int<s, 32> x 10> | ||
|
||
extern int bb[10][5]; | ||
// CHECK: cir.global external @bb : !cir.array<!cir.array<!cir.int<s, 32> x 5> x 10> | ||
|
||
void f() { | ||
int l[10]; | ||
// CHECK: %[[ARR:.*]] = cir.alloca !cir.array<!cir.int<s, 32> x 10>, !cir.ptr<!cir.array<!cir.int<s, 32> x 10>>, ["l"] | ||
} | ||
|
||
void f2(int p[10]) {} | ||
// CHECK: cir.func @f2(%arg0: !cir.ptr<!cir.int<s, 32>> | ||
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. Can you also check the |
||
// CHECK: cir.alloca !cir.ptr<!cir.int<s, 32>>, !cir.ptr<!cir.ptr<!cir.int<s, 32>>>, ["p", init] | ||
|
||
void f3(int pp[10][5]) {} | ||
// CHECK: cir.func @f3(%arg0: !cir.ptr<!cir.array<!cir.int<s, 32> x 5>> | ||
// CHECK: cir.alloca !cir.ptr<!cir.array<!cir.int<s, 32> x 5>>, !cir.ptr<!cir.ptr<!cir.array<!cir.int<s, 32> x 5>>> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// RUN: cir-opt %s | FileCheck %s | ||
|
||
module { | ||
|
||
cir.global external @a : !cir.array<!cir.int<s, 32> x 10> | ||
// CHECK: cir.global external @a : !cir.array<!cir.int<s, 32> x 10> | ||
|
||
cir.global external @aa : !cir.array<!cir.array<!cir.int<s, 32> x 10> x 10> | ||
// CHECK: cir.global external @aa : !cir.array<!cir.array<!cir.int<s, 32> x 10> x 10> | ||
|
||
cir.global external @b : !cir.array<!cir.int<s, 32> x 10> | ||
// CHECK: cir.global external @b : !cir.array<!cir.int<s, 32> x 10> | ||
|
||
cir.global external @bb : !cir.array<!cir.array<!cir.int<s, 32> x 10> x 10> | ||
// CHECK: cir.global external @bb : !cir.array<!cir.array<!cir.int<s, 32> x 10> x 10> | ||
|
||
cir.func @f() { | ||
%0 = cir.alloca !cir.array<!cir.int<s, 32> x 10>, !cir.ptr<!cir.array<!cir.int<s, 32> x 10>>, ["l"] {alignment = 4 : i64} | ||
cir.return | ||
} | ||
|
||
// CHECK: cir.func @f() { | ||
// CHECK: %0 = cir.alloca !cir.array<!cir.int<s, 32> x 10>, !cir.ptr<!cir.array<!cir.int<s, 32> x 10>>, ["l"] {alignment = 4 : i64} | ||
// CHECK: cir.return | ||
// CHECK: } | ||
|
||
cir.func @f2(%arg0: !cir.ptr<!cir.int<s, 32>>) { | ||
%0 = cir.alloca !cir.ptr<!cir.int<s, 32>>, !cir.ptr<!cir.ptr<!cir.int<s, 32>>>, ["p", init] {alignment = 8 : i64} | ||
cir.store %arg0, %0 : !cir.ptr<!cir.int<s, 32>>, !cir.ptr<!cir.ptr<!cir.int<s, 32>>> | ||
cir.return | ||
} | ||
|
||
// CHECK: cir.func @f2(%arg0: !cir.ptr<!cir.int<s, 32>>) { | ||
// CHECK: %0 = cir.alloca !cir.ptr<!cir.int<s, 32>>, !cir.ptr<!cir.ptr<!cir.int<s, 32>>>, ["p", init] {alignment = 8 : i64} | ||
// CHECK: cir.store %arg0, %0 : !cir.ptr<!cir.int<s, 32>>, !cir.ptr<!cir.ptr<!cir.int<s, 32>>> | ||
// CHECK: cir.return | ||
// CHECK: } | ||
|
||
cir.func @f3(%arg0: !cir.ptr<!cir.array<!cir.int<s, 32> x 10>>) { | ||
%0 = cir.alloca !cir.ptr<!cir.array<!cir.int<s, 32> x 10>>, !cir.ptr<!cir.ptr<!cir.array<!cir.int<s, 32> x 10>>>, ["pp", init] {alignment = 8 : i64} | ||
cir.store %arg0, %0 : !cir.ptr<!cir.array<!cir.int<s, 32> x 10>>, !cir.ptr<!cir.ptr<!cir.array<!cir.int<s, 32> x 10>>> | ||
cir.return | ||
} | ||
|
||
// CHECK: cir.func @f3(%arg0: !cir.ptr<!cir.array<!cir.int<s, 32> x 10>>) { | ||
// CHECK: %0 = cir.alloca !cir.ptr<!cir.array<!cir.int<s, 32> x 10>>, !cir.ptr<!cir.ptr<!cir.array<!cir.int<s, 32> x 10>>>, ["pp", init] {alignment = 8 : i64} | ||
// CHECK: cir.store %arg0, %0 : !cir.ptr<!cir.array<!cir.int<s, 32> x 10>>, !cir.ptr<!cir.ptr<!cir.array<!cir.int<s, 32> x 10>>> | ||
// CHECK: cir.return | ||
// CHECK: } | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o - 2>&1 | FileCheck %s | ||
|
||
int a[10]; | ||
// CHECK: @a = external dso_local global [10 x i32] | ||
|
||
int aa[10][5]; | ||
// CHECK: @aa = external dso_local global [10 x [5 x i32]] | ||
|
||
extern int b[10]; | ||
// CHECK: @b = external dso_local global [10 x i32] | ||
|
||
extern int bb[10][5]; | ||
// CHECK: @bb = external dso_local global [10 x [5 x i32]] | ||
|
||
void f() { | ||
int l[10]; | ||
} | ||
// CHECK: define void @f() | ||
// CHECK-NEXT: alloca [10 x i32], i64 1, align 16 | ||
|
||
void f2(int p[10]) {} | ||
// CHECK: define void @f2(ptr {{%.*}}) | ||
// CHECK-NEXT: alloca ptr, i64 1, align 8 | ||
|
||
void f3(int pp[10][5]) {} | ||
// CHECK: define void @f3(ptr {{%.*}}) | ||
// CHECK-NEXT: alloca ptr, i64 1, align 8 |
Uh oh!
There was an error while loading. Please reload this page.