[llvm] r188366 - Make more helper methods into static functions.

Craig Topper craig.topper at gmail.com
Wed Aug 14 18:26:58 PDT 2013


> Hi Craig,
>
> Whenever I write helper functions, I'm never sure whether to make them
> static or private member functions.  What criteria did you use when
> choosing to make these functions static?
>
> Thanks,
> Tom
>
>
Part of this answer is going to be very specific to the set of routines
that I was dealing with.

Some of these didn't access anything from the class they were in. That case
should be static at least in the class. If not outside the class in the
implementation file itself. I think LowerSDIV in this particular commit
fell into that class.

Another class of things I changed was ones that only needed the
X86Subtarget from the class they were in. This file is full of methods that
are were already static that fell into this type of function. So I was just
following along and passing them the one extra parameter they needed.

There were a few that needed some virtual methods from TargetLowering
(which is the parent class of X86TargetLowering). So they maybe should have
been in the class. But it turns out its easy to get a pointer to the
TargetLowering base from the DAG argument passed to all these functions.
Obviously this doesn't work if they are calling methods that only exist in
X86TargetLowering itself. And again there were already examples of
functions that were querying the TargetLowering from the DAG parameter.

So it comes down to a tradeoff of how much extra stuff you would need to
pass to make it a static function I guess. If you end up passing 'this' it
definitely should just be in the class.

~Craig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130814/9cb1358a/attachment.html>


More information about the llvm-commits mailing list