Fix array support (-Oarray optimization)#143
Open
alastairreid wants to merge 4 commits into
Open
Conversation
This change makes it easier to figure out the type of array literals which is required for the array wrapping transformation xform_array.
This transformation wraps arrays in records. The purpose of this is to simplify C code generation which was incorrectly generating 'x = y;' to copy an array.
nikolaykosarev
requested changes
May 19, 2026
| * This makes code generation easier because it allows | ||
| * us to copy arrays using assignment. | ||
| * | ||
| * Copyright (C) 2025-2025 Intel Corporation |
There was a problem hiding this comment.
Suggested change
| * Copyright (C) 2025-2025 Intel Corporation | |
| * Copyright (C) 2026-2026 Intel Corporation |
| (**************************************************************** | ||
| * ISA array wrapping transform | ||
| * | ||
| * Copyright (C) 2025-2025 Intel Corporation |
There was a problem hiding this comment.
Suggested change
| * Copyright (C) 2025-2025 Intel Corporation | |
| * Copyright (C) 2026-2026 Intel Corporation |
| if args.O0: | ||
| script = [] | ||
| script.append(":filter_unlisted_functions imports") | ||
| script.append(":filter_reachable_from --no-keep-builtins exports") |
| @@ -0,0 +1,37 @@ | |||
| // RUN: %aslrun -Oarrays %s | filecheck %s | |||
| // Copyright (C) 2023-2025 Intel Corporation | |||
| // Test returning a record containing an array | ||
| function Test(a : array [4] of Bits(32), i : Integer) -> R | ||
| begin | ||
| // var r := R{ x => a }; |
There was a problem hiding this comment.
Suggested change
| // var r := R{ x => a }; |
| ds' @ tuple_decls | ||
|
|
||
| (**************************************************************** | ||
| * Command: :xform_tuples |
There was a problem hiding this comment.
Suggested change
| * Command: :xform_tuples | |
| * Command: :xform_arrays |
| end | ||
|
|
||
| let xform_decls (ds : AST.declaration list) : AST.declaration list = | ||
| let replacer = new replaceArrayClass None in |
There was a problem hiding this comment.
Suggested change
| let replacer = new replaceArrayClass None in | |
| let replacer = new replaceArrayClass in |
tc not used.
| let xform_decls (ds : AST.declaration list) : AST.declaration list = | ||
| let replacer = new replaceArrayClass None in | ||
| let ds' = List.map (Isa_visitor.visit_decl (replacer :> Isa_visitor.isaVisitor)) ds in | ||
| let tuple_decls = replacer#mkTypeWrappers in |
There was a problem hiding this comment.
record_decls, or simply:
Suggested change
| let tuple_decls = replacer#mkTypeWrappers in | |
| let decls = replacer#mkTypeWrappers in |
| | Expr_ArrayInit (t, es) -> | ||
| let t' = Isa_visitor.visit_type (self :> Isa_visitor.isaVisitor) t in | ||
| let es' = Isa_visitor.visit_exprs (self :> Isa_visitor.isaVisitor) es in | ||
| let e' = AST.Expr_ArrayInit (t, es') in |
There was a problem hiding this comment.
Should be t' I believe:
Suggested change
| let e' = AST.Expr_ArrayInit (t, es') in | |
| let e' = AST.Expr_ArrayInit (t', es') in |
(looks like this is not covered by tests)
|
|
||
| // Copyright (C) 2025-2025 Intel Corporation | ||
|
|
||
| var R : array [16] of Bits(32); |
There was a problem hiding this comment.
Unused.
Suggested change
| var R : array [16] of Bits(32); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This transformation fixes array support by wrapping arrays in structs.
This works because C does not support array assignment (because arrays are promoted to pointers) but it does support struct assignment.
Fixes #41