local variable in Pattern definition?

Hi guys,

When I am trying to define pattern in a multi class, I got something like this:

multi class P_PAT<string sty, SDNode tNode>
{
  def : Pat<( !cast<ValueType>(“v2” # sty) (tNode !cast<ValueType>(“v2” # sty):$src1, !cast<ValueType>(“v2” # sty):$src2) ),
                    ( add !cast<ValueType>(“v2” # sty):$src1, !cast<ValueType>(“v2” # sty):$src2) >;
}

noticed that in the above pattern, the "!cast<ValueType>(“v2” # sty)” is used several times, make the pattern looks so complicated.
Is there anyway to define a “local variable” so I can define it only once and use it?

like to make the above definition to something like:
"multi class P_PAT<string sty, SDNode tNode>
{
  ValueType tt = !cast<ValueType>(“v2” # sty);
  def : Pat<( tt (tNode tt:$src1, tt:$src2) ),
          ( add tt:$src1, tt:$src2) >;
}

where the "ValueType tt = !cast<ValueType>(“v2” # sty); “ is the local variable definition, but is sure generate compiling errors.
how to fix it?

Best

kevin

Hi guys,

When I am trying to define pattern in a multi class, I got something like this:

multi class P_PAT<string sty, SDNode tNode>
{
  def : Pat<( !cast<ValueType>(“v2” # sty) (tNode !cast<ValueType>(“v2” # sty):$src1, !cast<ValueType>(“v2” # sty):$src2) ),
                    ( add !cast<ValueType>(“v2” # sty):$src1, !cast<ValueType>(“v2” # sty):$src2) >;
}

noticed that in the above pattern, the "!cast<ValueType>(“v2” # sty)” is used several times, make the pattern looks so complicated.
Is there anyway to define a “local variable” so I can define it only once and use it?

Try something like this:

multi class P_PAT<string sty, SDNode tNode, ValueType vt = !cast<ValueType>(“v2” # sty)> {

...

}

Alternatively, you could create a class that wraps the pattern to simplify it. For example:

class MyPat <ValueType vt, SDNode tNode> : Pat <
  ...

;

multiclass P_PAT<string sty, SDNode tNode> {
  def : MyPat<!Cast<ValueType>("v2" # sty), sty>;
}

-Tom

Hi guys,

When I am trying to define pattern in a multi class, I got something like this:

multi class P_PAT<string sty, SDNode tNode>
{
def : Pat<( !cast(“v2” # sty) (tNode !cast(“v2” # sty):$src1, !cast(“v2” # sty):$src2) ),
( add !cast(“v2” # sty):$src1, !cast(“v2” # sty):$src2) >;
}

noticed that in the above pattern, the "!cast(“v2” # sty)” is used several times, make the pattern looks so complicated.
Is there anyway to define a “local variable” so I can define it only once and use it?

Try something like this:

multi class P_PAT<string sty, SDNode tNode, ValueType vt = !cast(“v2” # sty)> {

}

Neat!