[llvm-commits] [llvm] r137497	-	/llvm/trunk/docs/CodingStandards.html
    Jakob Stoklund Olesen 
    stoklund at 2pi.dk
       
    Fri Aug 12 13:59:34 PDT 2011
    
    
  
On Aug 12, 2011, at 1:19 PM, John McCall wrote:
> I would be willing to allow an exception for very short variable
> names which are obviously abbreviations, since those should
> never be non-local anyway.
It's an established convention in libCodeGen to use abbreviations for class members representing the current context:
class AsmPrinter : public MachineFunctionPass {
    TargetMachine &TM;
    const MCAsmInfo *MAI;
    const MachineFunction *MF;
    MachineModuleInfo *MMI;
    MachineLoopInfo *LI;
    DwarfDebug *DD;
    DwarfException *DE;
}
The common abbreviations are mostly standardized which helps a lot.  Terms like MF, MRI, TRI, and TII are instantly recognizable.  These objects are effectively singletons within a pass, so they don't need real names.  Sometimes they are locals, sometimes they are members, it doesn't matter - there is only one object.
This convention is very convenient and does not cause confusion once you are used to it.
For the less common analyses, I have started using longer names:
class RAGreedy {
  MachineDominatorTree *DomTree;
  MachineLoopInfo *Loops;
  EdgeBundles *Bundles;
  SpillPlacement *SpillPlacer;
  LiveDebugVariables *DebugVars;
}
Obviously, using LI for MachineLoopInfo is misguided ;-)
/jakob
    
    
More information about the llvm-commits
mailing list