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

Richard Barton via flang-dev flang-dev at lists.llvm.org
Thu Jan 30 08:37:08 PST 2020


Hi all
 
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.
 
> 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.

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)
	
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

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.

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

Increase use of LLVM APIs and utilities in F18
	a. std::string/std::string_view → StringRef where appropriate
	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.

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

> -----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


More information about the flang-dev mailing list