-
Notifications
You must be signed in to change notification settings - Fork 155
[CIR][CodeGen] Const structs with bitfields #412
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0e0c2bb
WIVP where V stands for very
gitoleg 2522d55
at least something works
gitoleg 7bd8ed8
commented dbg
gitoleg 8d43854
wip
gitoleg 0909c2e
wip, added zero init in CIRRecordLayoutBuilder
gitoleg ec4b430
removed debug info
gitoleg 24d89de
strane fix, but it works
gitoleg 7f12e3b
adds todo-comment
gitoleg 94e62e0
fix output struct type
gitoleg 32c03b1
wip
gitoleg ca4996a
removes padding
gitoleg 316de49
fixes todo-s
gitoleg 73f64e5
adds bitcast for the case of globals
gitoleg e5a8b56
fix one more unreachable case
gitoleg 6f881b5
updated comment in CIRGenModule
gitoleg f616b09
adds tests, fixes padding
gitoleg e298b59
clang-format applied
gitoleg c9e0238
minor fix
gitoleg aed5317
merged upstream/main
gitoleg 022c410
added a missed check and NYIed it
gitoleg 559a39f
Merge remote-tracking branch 'upstream/main' into const-struct-bitfields
gitoleg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir-enable -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare %s -o - 2>&1 | FileCheck %s | ||
|
||
struct T { | ||
int X : 5; | ||
int Y : 6; | ||
int Z : 9; | ||
int W; | ||
}; | ||
|
||
struct Inner { | ||
unsigned a : 1; | ||
unsigned b : 1; | ||
unsigned c : 1; | ||
unsigned d : 30; | ||
}; | ||
|
||
// CHECK: !ty_22T22 = !cir.struct<struct "T" {!cir.int<u, 32>, !cir.int<s, 32>} #cir.record.decl.ast> | ||
// CHECK: !ty_anon_struct = !cir.struct<struct {!cir.int<u, 8>, !cir.int<u, 8>, !cir.int<u, 8>, !cir.int<s, 32>}> | ||
// CHECK: #bfi_Z = #cir.bitfield_info<name = "Z", storage_type = !u32i, size = 9, offset = 11, is_signed = true> | ||
// CHECK: !ty_anon_struct1 = !cir.struct<struct {!cir.int<u, 8>, !cir.array<!cir.int<u, 8> x 3>, !cir.int<u, 8>, !cir.int<u, 8>, !cir.int<u, 8>, !cir.int<u, 8>}> | ||
|
||
struct T GV = { 1, 5, 256, 42 }; | ||
// CHECK: cir.global external @GV = #cir.const_struct<{#cir.int<161> : !u8i, #cir.int<0> : !u8i, #cir.int<8> : !u8i, #cir.int<42> : !s32i}> : !ty_anon_struct | ||
|
||
// check padding is used (const array of zeros) | ||
struct Inner var = { 1, 0, 1, 21}; | ||
// CHECK: cir.global external @var = #cir.const_struct<{#cir.int<5> : !u8i, #cir.const_array<[#cir.zero : !u8i, #cir.zero : !u8i, #cir.zero : !u8i]> : !cir.array<!u8i x 3>, #cir.int<21> : !u8i, #cir.int<0> : !u8i, #cir.int<0> : !u8i, #cir.int<0> : !u8i}> : !ty_anon_struct1 | ||
bcardosolopes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
// CHECK: cir.func {{.*@getZ()}} | ||
// CHECK: %1 = cir.get_global @GV : cir.ptr <!ty_anon_struct> | ||
// CHECK: %2 = cir.cast(bitcast, %1 : !cir.ptr<!ty_anon_struct>), !cir.ptr<!ty_22T22> | ||
// CHECK: %3 = cir.cast(bitcast, %2 : !cir.ptr<!ty_22T22>), !cir.ptr<!u32i> | ||
// CHECK: %4 = cir.get_bitfield(#bfi_Z, %3 : !cir.ptr<!u32i>) -> !s32i | ||
int getZ() { | ||
return GV.Z; | ||
} | ||
|
||
// check the type used is the type of T struct for plain field | ||
// CHECK: cir.func {{.*@getW()}} | ||
// CHECK: %1 = cir.get_global @GV : cir.ptr <!ty_anon_struct> | ||
// CHECK: %2 = cir.cast(bitcast, %1 : !cir.ptr<!ty_anon_struct>), !cir.ptr<!ty_22T22> | ||
// CHECK: %3 = cir.get_member %2[1] {name = "W"} : !cir.ptr<!ty_22T22> -> !cir.ptr<!s32i> | ||
int getW() { | ||
return GV.W; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.