tablegen question

Trying to resolve some general tablegen questions.

Consider the test case for Tablegen called eq.td

class Base<int V> {
   int Value = V;
}

class Derived<string Truth> :
   Base<!if(!eq(Truth, "true"), 1, 0)>;

def TRUE : Derived<"true">;
def FALSE : Derived<"false">;

If I process this through tablegen I get:

------------- Classes -----------------
class Base<int Base:V = ?> {
   int Value = Base:V;
   string NAME = ?;
}
class Derived<string Derived:Truth = ?> { // Base
   int Value = !if(!eq(Derived:Truth, "true"), 1, 0);
   string NAME = ?;
}
------------- Defs -----------------
def FALSE { // Base Derived
   int Value = 0;
   string NAME = ?;
}
def TRUE { // Base Derived
   int Value = 1;
   string NAME = ?;
}

Why is NAME=? in FALSE and TRUE.

Shouldn't it be FALSE and TRUE ??

From my understanding, NAME is a special builtin entry and dedicated for

things related multiclass,

So, is the following rewrite what you want?

class Base<int V> {
   int Value = V;
}

class Derived<string Truth> :
   Base<!if(!eq(Truth, "true"), 1, 0)>;

multiclass Derived_m<string T> {
  def #NAME# : Derived<T>;
}

defm TRUE : Derived_m<"true">;
defm FALSE : Derived_m<"false">;

tablegen result:

------------- Classes -----------------
class Base<int Base:V = ?> {
  int Value = Base:V;
  string NAME = ?;
}
class Derived<string Derived:Truth = ?> { // Base
  int Value = !if(!eq(Derived:Truth, "true"), 1, 0);
  string NAME = ?;
}
------------- Defs -----------------
def FALSE { // Base Derived !strconcat(NAME, "")
  int Value = 0;
  string NAME = "FALSE";
}
def TRUE { // Base Derived !strconcat(NAME, "")
  int Value = 1;
  string NAME = "TRUE";
}

According to the TableGen manual:

“Each def record has a special entry called “NAME.” This is the name of the def (“ADD32rr” above). In the general case def names can be formed from various kinds of string processing expressions and NAME resolves to the final value obtained after resolving all of those expressions. The user may refer to NAME anywhere she desires to use the ultimate name of the def. NAME should not be defined anywhere else in user code to avoid conflict problems.”

I agree that for multiclass it works more how you would expect it to.

So, I don’t think that NAME should be ? as in the example I gave.

Reed Kotler <rkotler@mips.com> writes:

I agree that for multiclass it works more how you would expect it to.

So, I don't think that NAME should be ? as in the example I gave.

I think you are right. I never tested it with regular classes because I
hadn't come across a use case. But it should work. I'll see if I can
fix it.

                                -Dave

If you run tablegen on almost anything (just the front end), you will see NAME=? for all the
records.

thanks.

Reed

Reed Kotler<rkotler@mips.com> writes:

I agree that for multiclass it works more how you would expect it to.

So, I don't think that NAME should be ? as in the example I gave.

I think you are right. I never tested it with regular classes because I
hadn't come across a use case. But it should work. I'll see if I can
fix it.

                              -Dave

If you run tablegen on almost anything (just the front end), you will
see NAME=? for all the
records.

  Hi Reed,

    I filed a bug to track this issue

              http://www.llvm.org/bugs/show_bug.cgi?id=12365