[flang-commits] [flang] Add support for assume_aligned directive (PR #81747)

Mats Petersson via flang-commits flang-commits at lists.llvm.org
Tue Feb 20 12:29:22 PST 2024


Leporacanthicus wrote:

> why is a general designator allowed instead of a simple base object name? why would subscripts be needed to set alignment of the base object?

Because that's what's allowed by the original implementation, and in some source code that we're trying to compile. The test-case with the three array index variant I added is a simplified version of that original source. Would have been MUCH easier if it was just the name of the base object. That already works [it produces a warning that it's ignored - fine by me].

Here's the Intel blurb about this directive: 
https://www.intel.com/content/www/us/en/developer/articles/technical/alignment-of-fortran-allocatable-arrays-pointers-in-intel-fortran-compiler.html
https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-0/assume-aligned.html#GUID-99FB2C09-35C8-4486-9C32-009F22847E0D

By the way this directive doesn't set the alignment, it is telling the compiler what the actual alignment is, however that may have been achieved. 

At present, my main concern is to get the compiler to accept this at all - in the form it is in the original source, which I don't think is available on the internet, I'm sorry about that. I was originally just accepting  a name and `maybe(parenthesis(many(chars)))` [from memory]  but Kiran suggested I use a designator - I'm expecting that will make it a little easier to implement something that sets the alignment in the generated code so that the lower levels can use it to select vector instructions or similar, which require a certain alignment. 

Because there are parenthesis involved, the current version of the compiler says "expected end of statement" when it hits the parenthesis. 

Here's a some nonsense-code to show the difference between "already works" and "causes compilation error".  It will fail on line 4, pointing at the parenthesis. 

```
SUBROUTINE aa()
!DIR$ assume_aligned A:16
!DIR$ assume_aligned B:16
!DIR$ assume_aligned C(1):16
END SUBROUTINE aa
```


https://github.com/llvm/llvm-project/pull/81747


More information about the flang-commits mailing list