[LLVMdev] RFC: variable names

Florian Merz florian.merz at kit.edu
Mon Oct 13 23:59:32 PDT 2014

Am 14.10.2014 um 02:31 schrieb Joshua Cranmer 🐧:
> On 10/13/2014 6:08 PM, Richard Smith wrote:
>> 1. Initialisms. It's common in Clang code (also in LLVM?) to use
>> initialisms as variable names. This doesn't really seem to work for
>> names that start with a lower case letter.
> In my local use of LLVM code, I tend to follow a lowercase variable
> naming convention. However, I have taking to using Module *M, Function
> *F, Instruction *I, etc. At longer abbreviations... well, I use gep,
> lhs, rhs, but BB, GV, SI, LI, CI. I suppose my convention ends up being
> that I use upper-case letters if it's referring to the current thing
> being processed (and there is no ambiguity as to what is meant). Either
> that, or I do it only for 1- or 2-character initialisms. :-)
> This does have the added benefit of making a distinction between i (the
> integer loop index count) and I (the current instruction being
> processed) exceptionally clear.
I always had the impression there is an implicit naming convention along 
the following lines:

In general, variable names are in lower case, even when abbreviated. 
But, if a variable's name refers to its type and the type is in the llvm 
or clang namespaces, then use the initials of the type in capitals. So 
it would be an llvm::BasicBlock called BB, an llvm::Instruction called 
I, and an llvm::GlobalValue called GV, but it would be rhs, because 
there is no class llvm::RightHandSide.

This way, there is an implicit list of terms to abbreviate in capitals 
in the code base, namely all types in the llvm namespace.

I can also imagine a short list of reserved variable names in the coding 
stype, e.g. I may only be used for Instructions, BB only for basic 
blocks, ...

More information about the llvm-dev mailing list