[flang-dev] (Strawman) Costed plan for LLVM-ification of F18

Johannes Doerfert via flang-dev flang-dev at lists.llvm.org
Sun Feb 2 21:42:10 PST 2020


Hi Rich,

Apologies for my delayed response.

On 01/30, Richard Barton via flang-dev wrote:
> Many thanks for the quick replies so far. Looking at the comments so
> far I clearly should have been more explicit in some of my items –
> sorry about that. 
> 
> Please find below an updated strawman for review. I notice no
> discussion on the dates I proposed. Are we happy to push for those?
> 
> First a few comments of my own:
>  
> > As long as "where appropriate" means there is tangible benefit to
> > changing from a standard type to a non-standard one. Not just change
> > for the sake of change.
>  
> I wonder if we are thinking about this the wrong way around. Our aim
> to become an LLVM project and we hope that will happen soon. When it
> does, and we are sitting in the monorepo as flang then all uses of
> standard C++ types instead of equivalent LLVM types without good
> technical grounds would look strange or to paraphrase, seem like
> "differences for the sake of difference".
>
> We need to be thinking of ourselves as an LLVM project. If we adopt
> that mindset, then rather than looking for a reason to adopt the LLVM
> types we should really be checking if there is a good reason _not_ to
> adopt them. I don’t doubt there will be some occasions where we have
> good justification to not adopt LLVM types and stay with the standard
> type and we certainly will back up our arguments not to chane. But I
> don’t think the default position should be not switch to LLVM types.

+1

I agree.

If we (want to) argue F18 is developed as an LLVM subproject and it is
supposed to be(come) an LLVM subproject, we have to deal with what that
means. Non-F18 folks raised a bunch of concerns during the first merge
attempt for reasons that a decent amount of LLVM developers considered
valid. Addressing these concerns is part of being in this community. I
am glad we started resolving them and it seems a lot of pain points are
almost gone.

No-one in the community is expected to blindly follow things like coding
rules if there is a good reason *not to*, however, the rules are there
for a reason too, even if it is just to settle disputes on how
semantically equivalent code should look like. If we feel they need to
change, we can propose such a change as we propose other changes. If we
feel there is a good reason to make a more widespread exception, maybe
we can do that too. What we cannot, or at least should not do, is to
blindly reject the rules with the argument that the LLVM way needs to
prove it is superior before we adopt it. This is a slippery slope that
starts here at merge time and will continue to cause discussions over
discussions every time a change is made that violates the LLVM rules or
the "F18" rules.

We need to remember, this is a *large community (project)* that would
not work without rules, even if we don't agree with all of them.


> > As with improving names, there is no reason to wait for any specific
> > date to make improvements to the code.
>  
> I fully agree with that and we should continue improving F18
> regardless of upstreaming. My intention with the statement in my mail
> is to make explicit to the LLVM community that we don’t intend to
> perform a line-by-line audit and make every change we could possibly
> do. We’re being asked to commit to a timeline and I want to make sure
> that the list of things we need to complete in that timeline is not
> open ended. I'd like to make explicit what we are not planning to do
> by some particular date and that we'll do later over time instead.
> 
> > No else-after-return ...
> > Here's an example from resolve-names.cpp:
> 
> I see where you are coming from here and we can discuss these sorts of
> details in depth on code review for the specific examples. In cases
> like these, perhaps there is some refactoring we could do to capture
> the three way condition in the type class such that the if/elif/else
> block is not needed at all, or in such a way that the rewrite to
> if/if/return seems more natural, or perhaps with enough comments it
> will look ok anyway. All we need to do at this stage is commit to
> looking at it seriously and state when we'll do that by.

At the end of the day these things are very much questions of style.

If you want to emphasize no case is special you could even put all in
conditionals and end with `llvm_unreachable` instead. I guess, because
LLVM strongly encourages early exists patterns like that, they are very
common to begin with and I would not necessarily think something is the
default. There is also always the comment option.



> Ta
> Rich
> 
> Updated Strawman
> =================
> Proposal:
> We will make the following style changes before merging to the monorepo
> 
> F18 changes to make it more LLVM-like in code style
> 	1. Rationalise headers to put public headers in /include and not /lib
> 	2. Examine F18's clang-format file and ensure we are comfortable with any deviations to the LLVM style
> 	3. Rename all .cc files to .cpp
> 	4. Capitalize the module directory names in /lib and /include (e.g. /lib/Parser)

1, 3, 4 seem to be easy to do. 2 might cause some discussion but
minimizing the difference would not only align us closer but also
benefit people that want to start working on Flang.


> Increase use of LLVM APIs and utilities in F18
> 	a. Switch F18 custom File handling to LLVM's File handling (helps with non-POSIX platform support)
> 	b. Change uses of C++ standard stream IO library to LLVM's equivalent library
> 	c. Migrate use of std::list to a suitable alternative in LLVM's API
> 	d. Use llvm_unreachable with an error message for unreachable cases

LLVM has custom list data structures as well if we don't want to switch
to SmallVector or std::vector (if we really expect a lot of elements).


> We would like to aim for a merge date of Monday 24th Feb to merge to
> the monorepo with all of the above changes committed to F18 master.

That would be great!


> We then propose to make the following changes after merging to the monorepo. 
> 
> F18 changes to make it more LLVM-like in code style
> We will perform a one-off exercise where we audit the code to find these instances and bring them in line. We'll look at:
> 	1. Braces on all single-line if statements
> 	2. Uses of else-after-return.
> 	3. Add doxygen infrastructure so we can generate docs

I think 3 is in the short term one of the most important changes we need
to focus on. Basically every function/class/method/member that is
modified (post-merge) will need to have proper documentation.


> Increase use of LLVM APIs and utilities in F18
> 	a. std::string/std::string_view → StringRef where appropriate

Same for char* in some places.


> 	b. std::vector → llvm::SmallVector where appropriate
> 	c. std::set → llvm::SmallSet/llvm::StringSet/llvm::DenseSet where appropriate
> 	d. std::map → llvm::StringMap/llvm::DenseMap where appropriate
> 	e. Audit functions in include/flang/common and port to LLVM equivalents (e.g. builtin_popcount)
> 	f. Audit use of any error codes and switch to use llvm::Error instead
> 	
> Assuming we hit the above merge date, we think we can commit to making
> these changes before the LLVM11 branch is taken in June.
> 	
> After that date, we will continue to make progress towards LLVM style
> and API usage by fixing things as we find them during development and
> enforce the new style through code review.

Arguably, we should adapt LLVM style though code review now but for sure
post-merge.


> A few specific areas that have been mentioned before that we will tackle in this way are:
>    - Add doxygen style comments and file comments
>    - Classes, files, names, etc. where a more LLVM-standard naming can be used.
>    - Refactor code to use early exits

At some point we should also introduce unit tests where direct lit
testing is not possible, e.g., for F18 data structures.

Cheers,
  Johannes


> > -----Original Message-----
> > From: David Greene <greened at obbligato.org>
> > Sent: 29 January, 2020 21:16
> > To: Timothy Keith <tkeith at nvidia.com>; Richard Barton
> > <Richard.Barton at arm.com>; flang-dev at lists.llvm.org
> > Subject: Re: [flang-dev] (Strawman) Costed plan for LLVM-ification of F18
> > 
> > Timothy Keith via flang-dev <flang-dev at lists.llvm.org> writes:
> > 
> > >> 1. Eliminate braces from all single-line if statements
> > >
> > > This seems like a really bad idea and would like to see a reason for it.
> > 
> > FWIW this is one of the few things in LLVM's coding standards that I
> > strongly disagree with, but for whatever reason others strongly support
> > it.  I just live with it.  I would enthusiastically support an RFC to
> > llvm-dev to change it.
> > 
> > >> 2. Eliminate all uses of else-after-return
> > >
> > > Doing this blindly is also a bad idea.
> > 
> > I don't think anyone is saying to do anything "blindly."
> > 
> > >> b. std::vector → llvm::SmallVector where appropriate
> > >> c. std::set → llvm::SmallSet/llvm::StringSet/llvm::DenseSet where
> > appropriate
> > >> d. std::map → llvm::StringMap/llvm::DenseMap where appropriate
> > >
> > > As long as "where appropriate" means there is tangible benefit to
> > > changing from a standard type to a non-standard one. Not just change
> > > for the sake of change.
> > 
> > IME, LLVM's data structures are much faster/less resource intensive than
> > the standard library's.  That's natural as the standard library is
> > general-purpose code while LLVM's is tuned for specific use-cases.  In
> > my work I always use LLVM's data structures unless there's a good reason
> > not to.  f18 should follow the LLVM convention here.
> > 
> >                      -David
> _______________________________________________
> flang-dev mailing list
> flang-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/flang-dev

-- 

Johannes Doerfert
Researcher

Argonne National Laboratory
Lemont, IL 60439, USA

jdoerfert at anl.gov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-dev/attachments/20200202/0d5b480a/attachment.sig>


More information about the flang-dev mailing list