[LLVMdev] local variable in Pattern definition?

Tom Stellard tom at stellard.net
Wed Feb 18 09:46:56 PST 2015


On Wed, Feb 18, 2015 at 11:44:12AM -0500, kewuzhang wrote:
> 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

> 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
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list