Skip to content
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

Add align pragma for scalar data types (integer, logical, real, complex) #1427

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

GARRYHU
Copy link
Contributor

@GARRYHU GARRYHU commented Oct 24, 2023

Add support for aligning the first address of scalar data types (integer, logical, real, complex) with align pragma like "!dir$ align n".

For example:

!dir$ align 128
integer(kind=4) :: a

The align pragma enables the first address of variable "a" to be an integer multiple of 128.

The overall idea for this patch is as follows:

  • flang1:
    1. recognize the align pragma in the source code in do_sw()
    2. add a field to the ST_VAR symbol table to store the align value
    3. add ALIGN_PRAGMA *align_pragma_base to store all the align pragmas info parsed in the first pass
    4. match all the align pragmas and corresponding variables and set the variable's align value at the end of parse
    5. print the variable's align value in lower_symbol()
  • flang2:
    1. add a field to the ST_VAR symbol table to store the align value
    2. read and set the variable's align value in read_symbol()
    3. set the LL_Object::align_bytes field with the symbol's align field when creating an LLVM variable object
    4. adjust the size and align of common block according to the align value of variables in it, set the first address of a variable in the common block an integer multiple of the variable's align value.

This patch can be combined with #1360, which adds align pragma support for derived types and fixed shape array/character types. These two patches enable flang to support align pragma for most common data types.

I test locally through make check-flang-long, and also pass some custom tests and add them to the test folder.

@JiaweiHawk
Copy link
Contributor

Hi @GARRYHU,

It appears that our two pull requests(my pr link) contain a lot of code overlap.

I am of the opinion that we could work together to extract shared infrastructure and then continue with the subsequent tasks.

Are you interested in this?

@GARRYHU
Copy link
Contributor Author

GARRYHU commented Oct 24, 2023

Hi @GARRYHU,

It appears that our two pull requests(my pr link) contain a lot of code overlap.

I am of the opinion that we could work together to extract shared infrastructure and then continue with the subsequent tasks.

Are you interested in this?

Sure, I am glad to do that.

@bryanpkc
Copy link
Collaborator

@GARRYHU Thank you for your PR. As @JiaweiHawk already pointed out, there is probably an opportunity for you two to work together. We have already been reviewing #1360 for quite some time, so I suggest we get that one merged first, then you can submit a new version of this PR that's rebased on top of that one. How does that sound?

@GARRYHU
Copy link
Contributor Author

GARRYHU commented Nov 3, 2023

@GARRYHU Thank you for your PR. As @JiaweiHawk already pointed out, there is probably an opportunity for you two to work together. We have already been reviewing #1360 for quite some time, so I suggest we get that one merged first, then you can submit a new version of this PR that's rebased on top of that one. How does that sound?

OK, we will work together to make #1360 merged first!

@bryanpkc
Copy link
Collaborator

bryanpkc commented Jan 3, 2024

@GARRYHU @JiaweiHawk Now that #1360 has been merged, what is your plan for this PR? Will you rewrite it based on the latest master branch?

@GARRYHU
Copy link
Contributor Author

GARRYHU commented Jan 4, 2024

@GARRYHU @JiaweiHawk Now that #1360 has been merged, what is your plan for this PR? Will you rewrite it based on the latest master branch?

I'll try to rewrite my part based on the latest master branch next week (after my final exam)!

@GARRYHU
Copy link
Contributor Author

GARRYHU commented Jan 22, 2024

@bryanpkc After the refactoring work @JiaweiHawk and I did on #1360, the new version can support not only the alignment of data types like array, but also scalar data types (integer, logical, real, complex). Therefore, I just need to add some testcases for scalar data types on the basis of #1360. I have rebased this PR to add the testcases.

Copy link
Collaborator

@pawosm-arm pawosm-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the sole commit in this PR is only about adding the test cases, not the feature advertised by the PR topic. As the test case looks ok and the regexp used in it seem generic enough, I'm approving it anyway.

Copy link
Collaborator

@bryanpkc bryanpkc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too.

@pawosm-arm pawosm-arm merged commit 170c4f6 into flang-compiler:master Feb 7, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants