[LLVMdev] Regalloc Refactoring
David Greene
greened at obbligato.org
Tue Apr 17 13:59:32 PDT 2007
Evan Cheng wrote:
> While I agree spill cost computation does not belong in coalescer, I
> am not sure if it should go into a separate pass. To me, spill cost
> formulas should be register allocator specific. Perhaps it ought to
> belong to a generic register allocator class. Each derivative
> allocator is responsible for overriding it and calling it if it deems
> necessary.
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:
template<class RegallocTraits>
class GCRegAlloc {
void doAlloc() {
...
RegallocTraits::computeSpillCost(someValue);
...
};
};
An alternative to think about during these discussions.
-Dave
More information about the llvm-dev
mailing list