[LLVMdev] local variable in Pattern definition?

Adam Nemet anemet at apple.com
Thu Feb 19 15:04:31 PST 2015


> On Feb 18, 2015, at 9:46 AM, Tom Stellard <tom at stellard.net> wrote:
> 
> 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)> {
> 
> ...
> 
> }

Neat!

> 
> 
> 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
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu>         http://llvm.cs.uiuc.edu <http://llvm.cs.uiuc.edu/>
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev <http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150219/9e8f1f5c/attachment.html>


More information about the llvm-dev mailing list