[LLVMdev] Regalloc Refactoring
Chris Lattner
sabre at nondot.org
Tue Apr 17 21:30:31 PDT 2007
On Tue, 17 Apr 2007, David Greene wrote:
> I'm actually fairly nervous about using inheritance this way. I know
> it's done like this all over LLVM but the Template Method pattern is
> often better. You don't _really_ need dynamic polymorphism for things
> like this. Static polymorphism is sufficient and it has the advantage
> of more flexibility for reuse (doesn't depend on a specific base class).
>
> For example, if I'm writing a register allocator, one way to do what
> you're saying without inheritance is to parameterize the allocator
> with a traits class and call into that for the custom routines:
This is a very detailed design point. I don't think it makes sense to
talk about this until we are further along :). I agree that there are
pros an cons, but I see these (static specialization vs dynamic dispatch)
as two equivalent ways to solve the same problem, just with two different
sets of trade-offs. With one you have code duplication (of an entire
register allocator??) on the other hand you have dynamic dispatch
overhead.
In practice, the only way to determine the worth of one approach over the
other is careful measurment, which you can't do until you have an
implementation :)
-Chris
--
http://nondot.org/sabre/
http://llvm.org/
More information about the llvm-dev
mailing list