[llvm-dev] [tablegen] anonymous def not fully instantiated

Nicolai Hähnle via llvm-dev llvm-dev at lists.llvm.org
Wed May 16 06:29:41 PDT 2018


On 15.05.2018 21:01, Davis, Alan via llvm-dev wrote:
> The following is an extraction from the Operand class hierarchy of 
> Target.td. I am trying to define a parameterized version of 
> AsmOperandClass with a passed-in bit size.
> 
> // from Target.td
> 
> class AsmOperandClass {
> 
>     string Name;
> 
> }
> 
> class Operand {
> 
>     AsmOperandClass ParserMatchClass;
> 
> }
> 
> // A parameterized AsmOperandClass
> 
> class myAsmOperandClass<int n> : AsmOperandClass {
> 
>    string Name = "Class" # n;
> 
> }
> 
> // A concrete instance
> 
> def myImm5Class: myAsmOperandClass<5>;
> 
> // Assign ParserMatchClass from the concrete instance: OK
> 
> def myImm5 : Operand {
> 
>    let ParserMatchClass = myImm5Class;
> 
> }
> 
> // Now try to abstract the above by parameterizing the size
> 
> class myImmClass<int n>: Operand {
> 
>    let ParserMatchClass = myAsmOperandClass<n>;
> 
> }
> 
> // Fails
> 
> def myImm6 : myImmClass<6>;
> 
> On the real .td file from which this was taken, tablegen complains that 
> the Name field of myImm6’s ParserMatchClass is not a string. The reason 
> is revealed by looking at the raw output from tablegen:
> 
> ------------- Defs -----------------
> 
> def myImm5Class {       // AsmOperandClass myAsmOperandClass
> 
>    string Name = "Class5";
> 
> }
> 
> def myImm5 {    // Operand
> 
>    AsmOperandClass ParserMatchClass = myImm5Class;
> 
> }
> 
> def anonymous_0 {       // AsmOperandClass myAsmOperandClass
> 
>    string Name = !strconcat("Class", !cast<string>(myImmClass:n));
> 
> }
> 
> def myImm6 {    // Operand myImmClass
> 
>    AsmOperandClass ParserMatchClass = anonymous_0;
> 
> }
> 
> In the myImm5Class def used by myImm5, the !strconcat operation has been 
> applied to compute the Name as “Class5”. But in the anonymous def used 
> by myImm6, the !strconcat operation has not been applied. Why not? How 
> is the anonymous definition any different than the explicit one?
> 
> Is this a known ‘feature’/deficiency? Or am I the first to ‘discover’ it 
> (seems unlikely).

You should update to the latest trunk. I've done a lot of cleanups and 
fixes in the TableGen frontend about two months ago, including a major 
rework of how anonymous instantiation works. The output for the example 
you showed above looks different (and correct) now.

Cheers,
Nicolai




> 
> -Alan
> 
> 
> 
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> 


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


More information about the llvm-dev mailing list