[LLVMdev] PassManager and dependencies

Bill? Wendling wendling at isanbard.org
Sun Oct 20 23:22:01 PDT 2002

Also sprach Casey Carter:
} > 2. Don't optimize things that don't have to be optimized.  In general
} >    these methods aren't called enough, or only during debugging, so it
} >    is better to be clear than it is to save a few cycles.  As a general
} >    rule, optimize for clarity, not performance.  Often performance comes
} >    for free with clarity.
} > 
} What could be more clear than "static X x; return x;"?
Well...actually, the above takes knowing that the "static" in a function
will preserve the variable between calls and only initialize once.
Depending upon the use, "return x" is clearer IMNSHO, especially in the
case you had (where it's a string) or, even better, simply to return the
const char *, as mentioned below.


} > 3. If you REALLY want to be efficient, think about other short-cuts.  In
} >    this case, a constant string is always returned.  You could change
} >    the virtual method to always return a const char*, therefore avoiding
} >    a copy constructor call that may be unneccesary:
} > 
} >
} A good reference-counted string implementation should efficiently handle 
} returning a const& as in this case.  Of course, this is example code 
} that I hacked out in about ten minutes just to illustrate the problem, 
} so I would say that the goal is to optimize for speed of coding: I wrote 
} it as it came to  me.

|| Bill? Wendling			wendling at isanbard.org

More information about the llvm-dev mailing list