[LLVMdev] include files

Chandler Carruth chandlerc at google.com
Mon Jun 11 16:17:56 PDT 2012


On Mon, Jun 11, 2012 at 4:04 PM, Preston Briggs <preston.briggs at gmail.com>wrote:

> The LLVM Coding Standards discuss include files at some length.
> Suggests that the minimal list of includes be listed.
> Experimenting, I find the list is much shorter that used by most passes,
> perhaps only 3 or 4 files, probably because the necessary declarations
> are included indirectly. For example, I might get away with
> a .h file including only
>
> #include "llvm/Analysis/AliasAnalysis.h"
> #include "llvm/Analysis/LoopInfo.h"
> #include "llvm/ADT/SmallBitVector.h"
>
> and a .cpp file including only
>
> #include "myHeader.h"
> #include "llvm/Analysis/ScalarEvolutionExpressions.h"
> #include "llvm/Analysis/ValueTracking.h"
> #include "llvm/Support/InstIterator.h"
>
> Is it good style to cut the list down to the bare minimum like this?
>

Personally, I don't think so. But then personally, I don't like this bit of
the LLVM coding conventions.

I think that instead it should emphasize not trying to explicitly
include-what-you-use, or find the minimal number of include lines. Instead,
it should emphasize two things:

1) Include enough for your code to compile. If you're writing a header,
that should be enough for your header to be self sufficient.
2) Don't include more than you need to. If you don't use any part of a
header, don't include it.

Optimizing either above or below this seems like busy work and pointless
given the current scale and maintenance burden of the LLVM codebase.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120611/c295d6bd/attachment.html>


More information about the llvm-dev mailing list