[LLVMdev] local variable in Pattern definition?

kewuzhang kewu.zhang at amd.com
Wed Feb 18 08:44:12 PST 2015


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



More information about the llvm-dev mailing list