123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748(*
Copyright 2013-2018 RIKEN
Copyright 2018-2025 Chiba Institude of Technology
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)(* Author: Masatomo Hashimoto <m.hashimoto@stair.center> *)moduleXlist=Diffast_misc.XlistopenLabel_commonletlevel_to_string(i,j)=Printf.sprintf"%d:%d"ijletlevel_list_to_string=Xlist.to_stringlevel_to_string","moduleDirective=structtypet=|Aliasofname*name|Assume|Assume_aligned|Attributes|Block_loop|Code_alignofint|Declare|Defineofname|DistributePoint|Else|Elseif|EndOptions|Endif|Fixedformlinesizeofstring|Fma|Forceinlineofbool|Freeform|Identofstring|If|IfDefinedofname|Init_dep_fwd|Inlineofbool|Integerofstring|Ivdepofstring|LoopCountofintlist|Messageofstring|Noblock_loop|Nodeclare|Nofma|Nofreeform|Nofusion|Noinline|Nooptimize|Noparallel|Noprefetch|Nostrict|Nounroll|Nounroll_and_jam|Novector|Objcommentofstring|Optimizeofstring|Optionsofstringlist|Packofstring|Parallel|Prefetch|Psectofname|Realofstring|Simd|Strict|Undefineofname|Unrollofintoption|Unroll_and_jamofintoption|Vectorletto_string=function|Alias(i,e)->"Alias:"^i^":"^e|Assume->"Assume"|Assume_aligned->"Assume_aligned"|Attributes->"Attributes"|Block_loop->"Block_loop"|Noblock_loop->"Noblock_loop"|Code_aligni->"Code_align:"^(string_of_inti)|Declare->"Declare"|Nodeclare->"Nodeclare"|Definen->"Define:"^n|Undefinen->"Undefine:"^n|DistributePoint->"DistributePoint"|Fixedformlinesizei->"Fixedformlinesize:"^i|Fma->"Fma"|Nofma->"Nofma"|Freeform->"Freeform"|Nofreeform->"Nofreeform"|Idents->"Ident:"^s|If->"If"|IfDefinedn->"IfDefined:"^n|Inlineb->"Inline:"^(string_of_boolb)|Forceinlineb->"Forceinline:"^(string_of_boolb)|Noinline->"Noinline"|Integeri->"Integer:"^i|Ivdepo->"Ivdep"^(ifo=""then""else":"^o)|Init_dep_fwd->"Init_dep_fwd"|LoopCountil->"LoopCount"^(int_list_to_string~prefix:":"","il)|Messages->"Message:"^s|Nofusion->"Nofusion"|Objcomments->"Objcomment:"^s|Optimizei->"Optimize"^(ifi=""then""else":"^i)|Nooptimize->"Nooptimize"|Optionsol->"Options:"^(string_list_to_string""ol)|Packi->"Pack"^(ifi=""then""else":"^i)|Parallel->"Parallel"|Noparallel->"Noparallel"|Prefetch->"Prefetch"|Noprefetch->"Noprefetch"|Psectn->"Psect:"^n|Reali->"Real:"^i|Simd->"Simd"|Strict->"Strict"|Nostrict->"Nostrict"|Unrolli_opt->"Unroll"^(int_opt_to_string~prefix:":"i_opt)|Nounroll->"Nounroll"|Unroll_and_jami_opt->"Unroll_and_jam"^(int_opt_to_string~prefix:":"i_opt)|Nounroll_and_jam->"Nounroll_and_jam"|Vector->"Vector"|Novector->"Novector"|Elseif->"Elseif"|Else->"Else"|Endif->"Endif"|EndOptions->"EndOptions"letto_simple_string=function|Alias(i,e)->"ALIAS "^i^", "^e|Assume->"ASSUME"|Assume_aligned->"ASSUME_ALIGNED"|Attributes->"ATTRIBUTES"|Block_loop->"BLOCK_LOOP"|Noblock_loop->"NOBLOCK_LOOP"|Code_aligni->"CODE_ALIGN:"^(string_of_inti)|Declare->"DECLARE"|Nodeclare->"NODECLARE"|Definen->"DEFINE "^n|Undefinen->"UNDEFINE "^n|DistributePoint->"DISTRIBUTE POINT"|Fixedformlinesizei->"FIXEDFORMLINESIZE:"^i|Fma->"FMA"|Nofma->"NOFMA"|Freeform->"FREEFORM"|Nofreeform->"NOFREEFORM"|Idents->"IDENT "^s|If->"IF"|IfDefinedn->"IF DEFINED "^n|Inlineb->"INLINE"^(ifbthen" RECURSIVE"else"")|Forceinlineb->"FORCEINLINE"^(ifbthen" RECURSIVE"else"")|Noinline->"NOINLINE"|Integeri->"INTEGER:"^i|Ivdepo->"IVDEP"^(ifo=""then""else":"^o)|Init_dep_fwd->"INIT_DEP_FWD"|LoopCountil->"LOOP COUNT"^(int_list_to_string~prefix:"="","il)|Messages->"MESSAGE:"^s|Nofusion->"NOFUSION"|Objcomments->"OBJCOMMENT LIB:"^s|Optimizei->"OPTIMIZE"^(ifi=""then""else":"^i)|Nooptimize->"NOOPTIMIZE"|Optionsol->"OPTIONS "^(string_list_to_string""ol)|Packi->"PACK"^(ifi=""then""else":"^i)|Parallel->"PARALLEL"|Noparallel->"NOPARALLEL"|Prefetch->"PREFETCH"|Noprefetch->"NOPREFETCH"|Psectn->"PSECT /"^n^"/"|Reali->"REAL:"^i|Simd->"SIMD"|Strict->"STRICT"|Nostrict->"NOSTRICT"|Unrolli_opt->"UNROLL"^(int_opt_to_string~prefix:"="i_opt)|Nounroll->"NOUNROLL"|Unroll_and_jami_opt->"UNROLL_AND_JAM"^(int_opt_to_string~prefix:"="i_opt)|Nounroll_and_jam->"NOUNROLL_AND_JAM"|Vector->"VECTOR"|Novector->"NOVECTOR"|Elseif->"ELSEIF"|Else->"ELSE"|Endif->"ENDIF"|EndOptions->"END OPTIONS"letto_tag=function|Alias(i,e)->"DecAlias",["internal",i;"external",e]|Assume->"DecAssume",[]|Assume_aligned->"DecAssume_aligned",[]|Attributes->"DecAttributes",[]|Block_loop->"DecBlock_loop",[]|Noblock_loop->"DecNoblock_loop",[]|Code_aligni->"DecCode_align",["value",string_of_inti]|Declare->"DecDeclare",[]|Nodeclare->"DecNodeclare",[]|Definen->"DecDefine",[name_attr_name,n]|Undefinen->"DecUndefine",[name_attr_name,n]|DistributePoint->"DecDistributePoint",[]|Fixedformlinesizei->"DecFixedformlinesize",["length",i]|Fma->"DecFma",[]|Nofma->"DecNofma",[]|Freeform->"DecFreeform",[]|Nofreeform->"DecNofreeform",[]|Idents->"DecIdent",["ident",s]|If->"DecIf",[]|IfDefinedn->"DecIfDefined",[name_attr_name,n]|Inlineb->"DecInline",["recursive",string_of_boolb]|Forceinlineb->"DecForceinline",["recursive",string_of_boolb]|Noinline->"DecNoinline",[]|Integeri->"DecInteger",["size",i]|Ivdepo->"DecIvdep",(ifo=""then[]else["option",o])|Init_dep_fwd->"DecInit_dep_fwd",[]|LoopCountil->"DecLoopCount",(list_to_attrstring_of_int"count"il)|Messages->"DecMessage",["message",s]|Nofusion->"DecNofusion",[]|Objcomments->"DecObjcomment",["library",s]|Optimizei->"DecOptimize",(ifi=""then[]else["level",i])|Nooptimize->"DecNooptimize",[]|Optionsol->"DecOptions",(list_to_attr(funx->x)"option"ol)|Packi->"DecPack",(ifi=""then[]else["align",i])|Parallel->"DecParallel",[]|Noparallel->"DecNoparallel",[]|Prefetch->"DecPrefetch",[]|Noprefetch->"DecNoprefetch",[]|Psectn->"DecPsect",[name_attr_name,n]|Reali->"DecReal",["size",i]|Simd->"DecSimd",[]|Strict->"DecStrict",[]|Nostrict->"DecNostrict",[]|Unrolli_opt->"DecUnroll",(int_opt_to_attr"n"i_opt)|Nounroll->"DecNounroll",[]|Unroll_and_jami_opt->"DecUnroll_and_jam",(int_opt_to_attr"n"i_opt)|Nounroll_and_jam->"DecNounroll_and_jam",[]|Vector->"DecVector",[]|Novector->"DecNovector",[]|Elseif->"DecElseif",[]|Else->"DecElse",[]|Endif->"DecEndif",[]|EndOptions->"DecEndOptions",[]letget_name=function|Definen|Undefinen|IfDefinedn|Psectn->n|_->raiseNot_foundletget_name_opt=function|Definen|Undefinen|IfDefinedn|Psectn->Somen|_->Noneletis_specification_part=function|Alias_|Assume|Assume_aligned|Attributes|Declare|Nodeclare|Define_|Undefine_|Fixedformlinesize_|Fma|Nofma|Freeform|Nofreeform|Ident_|If|IfDefined_|Elseif|Else|Endif|EndOptions|Message_|Objcomment_|Optimize_|Nooptimize|Options_|Integer_|Pack_|Psect_|Real_|Strict|Nostrict->true|_->falseletis_execution_part=function|Alias_|Assume|Assume_aligned|Attributes|Block_loop|Noblock_loop|Code_align_|Declare|Nodeclare|Define_|Undefine_|DistributePoint|Fixedformlinesize_|Fma|Nofma(*| Freeform*)(*| Nofreeform*)(*| Ident _*)|If|IfDefined_|Elseif|Else|Endif|Inline_|Forceinline_|Noinline(*| Integer _*)|Ivdep_|Init_dep_fwd|LoopCount_|Message_|Nofusion(*| Objcomment _*)|Optimize_|Nooptimize(*| Options _*)(*| EndOptions*)(*| Pack _*)|Parallel|Noparallel|Prefetch|Noprefetch|Psect_(*| Real _*)|Simd|Strict|Nostrict|Unroll_|Nounroll|Unroll_and_jam_|Nounroll_and_jam|Vector|Novector->true|_->falseletanonymize=function|Alias(_,_)->Alias("","")|Define_->Define""|Undefine_->Undefine""|Fixedformlinesize_->Fixedformlinesize""|Ident_->Ident""|IfDefined_->IfDefined""|Inline_->Inlinefalse|Forceinline_->Forceinlinefalse|Integer_->Integer""|Ivdep_->Ivdep""|LoopCount_->LoopCount[]|Message_->Message""|Objcomment_->Objcomment""|Optimize_->Optimize""|Options_->Options[]|Pack_->Pack""|Psect_->Psect""|Real_->Real""|Unroll_->UnrollNone|Unroll_and_jam_->Unroll_and_jamNone|l->lend(* module Directive *)moduleClause=structtypet=|Always|Assert|Aligned|Unaligned|Temporal|Nontemporal|Vecremainder|Novecremainder|Noassert|Firstprivate|Lastprivate|Linear|Private|Reduction|Vectorlengthofintlist|Vectorlengthfor|Num_threads|Mask|Nomask|Processorofstring|Uniform|Profitable|Cost|Factor|Levelof(int*int)listletto_string=function|Always->"Always"|Assert->"Assert"|Aligned->"Aligned"|Unaligned->"Unaligned"|Temporal->"Temporal"|Nontemporal->"Nontemporal"|Vecremainder->"Vecremainder"|Novecremainder->"Novecremainder"|Noassert->"Noassert"|Firstprivate->"Firstprivate"|Lastprivate->"Lastprivate"|Linear->"Linear"|Private->"Private"|Reduction->"Reduction"|Vectorlengthil->"Vectorlength"^(int_list_to_string~prefix:":"","il)|Vectorlengthfor->"Vectorlengthfor"|Num_threads->"Num_threads"|Mask->"Mask"|Nomask->"Nomask"|Processorp->"Processor:"^p|Uniform->"Uniform"|Profitable->"Profitable"|Cost->"Cost"|Factor->"Factor"|Levelll->"Level:"^(level_list_to_stringll)letto_simple_string=function|Always->"ALWAYS"|Assert->"ASSERT"|Aligned->"ALIGNED"|Unaligned->"UNALIGNED"|Temporal->"TEMPORAL"|Nontemporal->"NONTEMPORAL"|Vecremainder->"VECREMAINDER"|Novecremainder->"NOVECREMAINDER"|Noassert->"NOASSERT"|Firstprivate->"FIRSTPRIVATE"|Lastprivate->"LASTPRIVATE"|Linear->"LINEAR"|Private->"PRIVATE"|Reduction->"REDUCTION"|Vectorlengthil->"VECTORLENGTH ("^(int_list_to_string~prefix:""","il)|Vectorlengthfor->"VECTORLENGTHFOR"|Num_threads->"NUM_THREADS"|Mask->"MASK"|Nomask->"NOMASK"|Processorp->"PROCESSOR("^p^")"|Uniform->"UNIFORM"|Profitable->"PROFITABLE"|Cost->"COST"|Factor->"FACTOR"|Levelll->"LEVEL("^(level_list_to_stringll)^")"letto_tag=function|Always->"DecAlways",[]|Assert->"DecAssert",[]|Aligned->"DecAligned",[]|Unaligned->"DecUnaligned",[]|Temporal->"DecTemporal",[]|Nontemporal->"DecNontemporal",[]|Vecremainder->"DecVecremainder",[]|Novecremainder->"DecNovecremainder",[]|Noassert->"DecNoassert",[]|Firstprivate->"DecFirstprivate",[]|Lastprivate->"DecLastprivate",[]|Linear->"DecLinear",[]|Private->"DecPrivate",[]|Reduction->"DecReduction",[]|Vectorlengthil->"DecVectorlength",(list_to_attrstring_of_int"length"il)|Vectorlengthfor->"DecVectorlengthfor",[]|Num_threads->"DecNum_threads",[]|Mask->"DecMask",[]|Nomask->"DecNomask",[]|Processorp->"DecProcessor",["processor",p]|Uniform->"DecUniform",[]|Profitable->"DecProfitable",[]|Cost->"DecCost",[]|Factor->"Factor",[]|Levelll->"Level",(list_to_attrlevel_to_string"level"ll)letanonymize=function|Vectorlength_->Vectorlength[]|Processor_->Processor""|Level_->Level[]|l->lend(* module Clause *)moduleAttribute=structtypet=|Aliasofstring|Alignofint|Allocatable|Array_null|C|Code_alignofint|Concurrency_safe|Cvf|Decorate|Default|Dllexport|Dllimport|Extern|Fastmem|Forceinline|Ignore_loc|Inline|Mixed_str_len_arg|No_arg_check|Noclone|Noinline|Offloadofname|Optimization_parameterofstring|Reference|Stdcall|Value|Varying|Vectorletto_string=function|Aliass->"Alias:"^s|Aligni->"Align:"^(string_of_inti)|Allocatable->"Allocatable"|Array_null->"Array_null"|C->"C"|Code_aligni->"Code_align:"^(string_of_inti)|Concurrency_safe->"Concurrency_safe"|Cvf->"Cvf"|Decorate->"Decorate"|Default->"Default"|Dllexport->"Dllexport"|Dllimport->"Dllimport"|Extern->"Extern"|Fastmem->"Fastmem"|Forceinline->"Forceinline"|Ignore_loc->"Ignore_loc"|Inline->"Inline"|Mixed_str_len_arg->"Mixed_str_len_arg"|No_arg_check->"No_arg_check"|Noclone->"Noclone"|Noinline->"Noinline"|Offloadn->"Offload:"^n|Optimization_parameters->"Optimization_parameter:"^s|Reference->"Reference"|Stdcall->"Stdcall"|Value->"Value"|Varying->"Varying"|Vector->"Vector"letto_simple_string=function|Aliass->"ALIAS:"^s|Aligni->"ALIGN:"^(string_of_inti)|Allocatable->"ALLOCATABLE"|Array_null->"ARRAY_NULL"|C->"C"|Code_aligni->"CODE_ALIGN:"^(string_of_inti)|Concurrency_safe->"CONCURRENCY_SAFE"|Cvf->"CVF"|Decorate->"DECORATE"|Default->"DEFAULT"|Dllexport->"DLLEXPORT"|Dllimport->"DLLIMPORT"|Extern->"EXTERN"|Fastmem->"FASTMEM"|Forceinline->"FORCEINLINE"|Ignore_loc->"IGNORE_LOC"|Inline->"INLINE"|Mixed_str_len_arg->"MIXED_STR_LEN_ARG"|No_arg_check->"NO_ARG_CHECK"|Noclone->"NOCLONE"|Noinline->"NOINLINE"|Offloadn->"OFFLOAD:"^n|Optimization_parameters->"OPTIMIZATION_PARAMETER:"^s|Reference->"REFERENCE"|Stdcall->"STDCALL"|Value->"VALUE"|Varying->"VARYING"|Vector->"VECTOR"letto_tag=function|Aliass->"DecAttributeAlias",[name_attr_name,s]|Aligni->"DecAttributeAlign",["value",string_of_inti]|Allocatable->"DecAttributeAllocatable",[]|Array_null->"DecAttributeArray_null",[]|C->"DecAttributeC",[]|Code_aligni->"DecAttributeCode_align",["value",string_of_inti]|Concurrency_safe->"DecAttributeConcurrency_safe",[]|Cvf->"DecAttributeCvf",[]|Decorate->"DecAttributeDecorate",[]|Default->"DecAttributeDefault",[]|Dllexport->"DecAttributeDllexport",[]|Dllimport->"DecAttributeDllimport",[]|Extern->"DecAttributeExtern",[]|Fastmem->"DecAttributeFastmem",[]|Forceinline->"DecAttributeForceinline",[]|Ignore_loc->"DecAttributeIgnore_loc",[]|Inline->"DecAttributeInline",[]|Mixed_str_len_arg->"DecAttributeMixed_str_len_arg",[]|No_arg_check->"DecAttributeNo_arg_check",[]|Noclone->"DecAttributeNoclone",[]|Noinline->"DecAttributeNoinline",[]|Offloadn->"DecAttributeOffload",[name_attr_name,n]|Optimization_parameters->"DecAttributeOptimization_parameter",["parameter",s]|Reference->"DecAttributeReference",[]|Stdcall->"DecAttributeStdcall",[]|Value->"DecAttributeValue",[]|Varying->"DecAttributeVarying",[]|Vector->"DecAttributeVector",[]letget_name=function|Aliass->s|Offloadn->n|_->raiseNot_foundletget_name_opt=function|Aliass->Somes|Offloadn->Somen|_->Noneletanonymize=function|Alias_->Alias""|Align_->Align0|Code_align_->Code_align0|Offload_->Offload""|Optimization_parameter_->Optimization_parameter""|l->lletof_keywordkw=matchString.lowercase_asciikwwith|"allocatable"->Allocatable|"array_null"->Array_null|"c"->C|"concurrency_safe"->Concurrency_safe|"cvf"->Cvf|"decorate"->Decorate|"default"->Default|"dllexport"->Dllexport|"dllimport"->Dllimport|"extern"->Extern|"fastmem"->Fastmem|"forceinline"->Forceinline|"ignore_loc"->Ignore_loc|"mixed_str_len_arg"->Mixed_str_len_arg|"no_arg_check"->No_arg_check|"noclone"->Noclone|"reference"->Reference|"stdcall"->Stdcall|"value"->Value|"varying"->Varying|_->failwith"F_dec.Attribute.of_keyword"letof_keyword_intkw_=matchString.lowercase_asciikwwith|_->failwith"F_dec.Attribute.of_keyword_int"letof_keyword_namekwn=matchString.lowercase_asciikwwith|"offload"->Offloadn|_->failwith"F_dec.Attribute.of_keyword_name"letof_keyword_stringkws=matchString.lowercase_asciikwwith|"optimization_parameter"->Optimization_parameters|_->failwith"F_dec.Attribute.of_keyword_string"end(* module Attribute *)typet=|VarExpr|Alignofstring|Wrt|Nowrt|PrefetchHint|PrefetchHintAll|Maxofint|Minofint|Avgofintletto_string=function|VarExpr->"VarExpr"|Aligns->"Align:"^s|Wrt->"Wrt"|Nowrt->"Nowrt"|PrefetchHint->"PrefetchHint"|PrefetchHintAll->"PrefetchHintAll"|Maxi->"Max:"^(string_of_inti)|Mini->"Min:"^(string_of_inti)|Avgi->"Avg:"^(string_of_inti)letto_simple_string=function|VarExpr->"<var-expr>"|Aligns->"ALIGN="^s|Wrt->"WRT"|Nowrt->"NOWRT"|PrefetchHint->"<prefetch-hint>"|PrefetchHintAll->"<prefetch-hint-all>"|Maxi->"MAX="^(string_of_inti)|Mini->"MIN="^(string_of_inti)|Avgi->"AVG="^(string_of_inti)letto_tag=function|VarExpr->"DecVarExpr",[]|Aligns->"DecAlign",["align",s]|Wrt->"DecWrt",[]|Nowrt->"DecNowrt",[]|PrefetchHint->"DecPrefetchHint",[]|PrefetchHintAll->"DecPrefetchHintAll",[]|Maxi->"DecMax",[value_attr_name,string_of_inti]|Mini->"DecMin",[value_attr_name,string_of_inti]|Avgi->"DecAvg",[value_attr_name,string_of_inti]letanonymize=function|Align_->Align""|Max_->Max0|Min_->Min0|Avg_->Avg0|l->l