[llvm-dev] Pass a class as a parameter of a multidef

Nicolai Hähnle via llvm-dev llvm-dev at lists.llvm.org
Fri Oct 12 00:31:30 PDT 2018


On 11.10.2018 22:18, Roger Ferrer Ibáñez via llvm-dev wrote:
> I searched the mailing list but I couldn't find anything relevant so I 
> thought I'd ask.
> 
> I'm adding a few instructions of an ISA that is very regular and I find 
> myself writing repeatedly multidefs that are only different in the 
> classes used inside the multidef. However, to the best of my knowledge, 
> it is not possible to parameterise multidefs using classes, only values.
> 
> So I have something now that looks like this.
> 
> multidef foo<things> {
>    def A : ClassFoo<values_from_things>;
>    def : ClassFooAlias<more_values_from_things>;
> }
> 
> multidef bar<things> {
>    def A : ClassBar<values_from_things>;
>    def : ClassBarAlias<more_values_from_things>;
> }
> 
> multidef moo<things> {
>    defm FOO : foo<things>;
>    defm BAR : bar<things>
> }
> 
> defm QUUX : moo<things>;
> 
> And I would like to compact all the above as
> 
> multidef common<class C, class CAlias> {
>     def A : C<values_from_things>;
>     def  : CAlias<more_values_from_things>;
> }
> 
> multidef moo {
>     def FOO : common<ClassFoo, ClassFooAlias>;
>     def BAR : common<ClassBar, ClassBarAlias>;
> }
> 
> defm QUUX : moo<things>;
> 
> Perhaps I'm using tablegen suboptimally and there is a better approach 
> or a way to simulate a similar behaviour.
> 
> If not, has anyone in the past considered such generalisation? Maybe 
> we'd be hitting some limits of tablegen here?

It'd certainly be a non-trivial change that doesn't mesh particularly 
well with the existing feature set.

I'd ask you to first take a step back: if the ISA is as regular as you 
say it is, why do you have separate base classes in the first place?

Why not instead do something like:

   multidef common<variables> {
     def A : ClassBase<values>;
     def : ClassBaseAlias<values>;
   }

   multidef moo<variables> {
     let somevar = FooSpecificValue, ... in
     defm FOO : common<...>, FooSpecificClass<...>;

     let somevar = BarSpecificValue, ... in
     defm BAR : common<...>, BarSpecificClass<...>;
   }

   defm QUUX : moo<things>;

This is all very abstract of course, but maybe it gives you an 
alternative idea to solve your problem?

Cheers,
Nicolai
-- 
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.


More information about the llvm-dev mailing list