2101 lines · plain
1================================================================================2Branching written with cf.br, cf.cond_br3================================================================================4func.func @simple(i64, i1) -> i64 {5^bb0(%a: i64, %cond: i1): // Code dominated by ^bb0 may refer to %a6 cf.cond_br %cond, ^bb1, ^bb27 8^bb1:9 cf.br ^bb3(%a: i64) // Branch passes %a as the argument10 11^bb2:12 %b = arith.addi %a, %a : i6413 cf.br ^bb3(%b: i64) // Branch passes %b as the argument14 15// ^bb3 receives an argument, named %c, from predecessors16// and passes it on to bb4 along with %a. %a is referenced17// directly from its defining operation and is not passed through18// an argument of ^bb3.19^bb3(%c: i64):20 cf.br ^bb4(%c, %a : i64, i64)21 22^bb4(%d : i64, %e : i64):23 %0 = arith.addi %d, %e : i6424 return %0 : i64 // Return is also a terminator.25}26--------------------------------------------------------------------------------27 28(toplevel29 (operation30 (custom_operation31 (func_dialect32 (symbol_ref_id)33 (func_arg_list34 (type35 (builtin_type36 (integer_type)))37 (type38 (builtin_type39 (integer_type))))40 (func_return41 (type_list_attr_parens42 (type43 (builtin_type44 (integer_type)))))45 (region46 (block47 (block_label48 (caret_id)49 (block_arg_list50 (value_use)51 (type52 (builtin_type53 (integer_type)))54 (value_use)55 (type56 (builtin_type57 (integer_type)))))58 (comment)59 (operation60 (custom_operation61 (cf_dialect62 (value_use)63 (successor64 (caret_id))65 (successor66 (caret_id))))))67 (block68 (block_label69 (caret_id))70 (operation71 (custom_operation72 (cf_dialect73 (successor74 (caret_id)75 (value_use)76 (type77 (builtin_type78 (integer_type))))))))79 (comment)80 (block81 (block_label82 (caret_id))83 (operation84 (op_result85 (value_use))86 (custom_operation87 (arith_dialect88 (value_use)89 (value_use)90 (type91 (builtin_type92 (integer_type))))))93 (operation94 (custom_operation95 (cf_dialect96 (successor97 (caret_id)98 (value_use)99 (type100 (builtin_type101 (integer_type))))))))102 (comment)103 (comment)104 (comment)105 (comment)106 (comment)107 (block108 (block_label109 (caret_id)110 (block_arg_list111 (value_use)112 (type113 (builtin_type114 (integer_type)))))115 (operation116 (custom_operation117 (cf_dialect118 (successor119 (caret_id)120 (value_use)121 (value_use)122 (type123 (builtin_type124 (integer_type)))125 (type126 (builtin_type127 (integer_type))))))))128 (block129 (block_label130 (caret_id)131 (block_arg_list132 (value_use)133 (type134 (builtin_type135 (integer_type)))136 (value_use)137 (type138 (builtin_type139 (integer_type)))))140 (operation141 (op_result142 (value_use))143 (custom_operation144 (arith_dialect145 (value_use)146 (value_use)147 (type148 (builtin_type149 (integer_type))))))150 (operation151 (custom_operation152 (func_dialect153 (value_use)154 (type155 (builtin_type156 (integer_type)))))))157 (comment))))))158 159================================================================================160Switch statement written with cf.switch161================================================================================162func.func @switch(%flag : i32, %caseOperand : i32) {163 cf.switch %flag : i32, [164 default: ^bb1(%caseOperand : i32),165 42: ^bb2(%caseOperand : i32),166 43: ^bb3(%caseOperand : i32)167 ]168 169 ^bb1(%bb1arg : i32):170 return171 ^bb2(%bb2arg : i32):172 return173 ^bb3(%bb3arg : i32):174 return175}176--------------------------------------------------------------------------------177 178(toplevel179 (operation180 (custom_operation181 (func_dialect182 (symbol_ref_id)183 (func_arg_list184 (value_use)185 (type186 (builtin_type187 (integer_type)))188 (value_use)189 (type190 (builtin_type191 (integer_type))))192 (region193 (entry_block194 (operation195 (custom_operation196 (cf_dialect197 (value_use)198 (type199 (builtin_type200 (integer_type)))201 (cf_case_label)202 (successor203 (caret_id)204 (value_use)205 (type206 (builtin_type207 (integer_type))))208 (cf_case_label209 (integer_literal))210 (successor211 (caret_id)212 (value_use)213 (type214 (builtin_type215 (integer_type))))216 (cf_case_label217 (integer_literal))218 (successor219 (caret_id)220 (value_use)221 (type222 (builtin_type223 (integer_type))))))))224 (block225 (block_label226 (caret_id)227 (block_arg_list228 (value_use)229 (type230 (builtin_type231 (integer_type)))))232 (operation233 (custom_operation234 (func_dialect))))235 (block236 (block_label237 (caret_id)238 (block_arg_list239 (value_use)240 (type241 (builtin_type242 (integer_type)))))243 (operation244 (custom_operation245 (func_dialect))))246 (block247 (block_label248 (caret_id)249 (block_arg_list250 (value_use)251 (type252 (builtin_type253 (integer_type)))))254 (operation255 (custom_operation256 (func_dialect)))))))))257 258================================================================================259Simple for-loop written with scf.for260================================================================================261func.func @for_loop_with_increasing_arg() -> i1 {262 %c0 = arith.constant 0 : index263 %c1 = arith.constant 1 : index264 %c4 = arith.constant 4 : index265 %c16 = arith.constant 16 : index266 %0 = scf.for %arg0 = %c0 to %c4 step %c1 iter_args(%arg1 = %c0) -> index {267 %10 = arith.addi %arg0, %arg1 : index268 scf.yield %10 : index269 }270 %1 = arith.cmpi ule, %0, %c16 : index271 func.return %1 : i1272}273--------------------------------------------------------------------------------274 275(toplevel276 (operation277 (custom_operation278 (func_dialect279 (symbol_ref_id)280 (func_arg_list)281 (func_return282 (type_list_attr_parens283 (type284 (builtin_type285 (integer_type)))))286 (region287 (entry_block288 (operation289 (op_result290 (value_use))291 (custom_operation292 (arith_dialect293 (integer_literal)294 (type295 (builtin_type296 (index_type))))))297 (operation298 (op_result299 (value_use))300 (custom_operation301 (arith_dialect302 (integer_literal)303 (type304 (builtin_type305 (index_type))))))306 (operation307 (op_result308 (value_use))309 (custom_operation310 (arith_dialect311 (integer_literal)312 (type313 (builtin_type314 (index_type))))))315 (operation316 (op_result317 (value_use))318 (custom_operation319 (arith_dialect320 (integer_literal)321 (type322 (builtin_type323 (index_type))))))324 (operation325 (op_result326 (value_use))327 (custom_operation328 (scf_dialect329 (value_use)330 (value_use)331 (value_use)332 (value_use)333 (value_use)334 (value_use)335 (type336 (builtin_type337 (index_type)))338 (region339 (entry_block340 (operation341 (op_result342 (value_use))343 (custom_operation344 (arith_dialect345 (value_use)346 (value_use)347 (type348 (builtin_type349 (index_type))))))350 (operation351 (custom_operation352 (scf_dialect353 (value_use)354 (type355 (builtin_type356 (index_type)))))))))))357 (operation358 (op_result359 (value_use))360 (custom_operation361 (arith_dialect362 (value_use)363 (value_use)364 (type365 (builtin_type366 (index_type))))))367 (operation368 (custom_operation369 (func_dialect370 (value_use)371 (type372 (builtin_type373 (integer_type))))))))))))374 375================================================================================376Nested for-loop written using scf.for377================================================================================378func.func @std_for(%arg0 : index, %arg1 : index, %arg2 : index) {379 scf.for %i0 = %arg0 to %arg1 step %arg2 {380 scf.for %i1 = %arg0 to %arg1 step %arg2 {381 %min_cmp = arith.cmpi slt, %i0, %i1 : index382 %min = arith.select %min_cmp, %i0, %i1 : index383 %max_cmp = arith.cmpi sge, %i0, %i1 : index384 %max = arith.select %max_cmp, %i0, %i1 : index385 scf.for %i2 = %min to %max step %i1 {386 }387 }388 }389 return390}391--------------------------------------------------------------------------------392 393(toplevel394 (operation395 (custom_operation396 (func_dialect397 (symbol_ref_id)398 (func_arg_list399 (value_use)400 (type401 (builtin_type402 (index_type)))403 (value_use)404 (type405 (builtin_type406 (index_type)))407 (value_use)408 (type409 (builtin_type410 (index_type))))411 (region412 (entry_block413 (operation414 (custom_operation415 (scf_dialect416 (value_use)417 (value_use)418 (value_use)419 (value_use)420 (region421 (entry_block422 (operation423 (custom_operation424 (scf_dialect425 (value_use)426 (value_use)427 (value_use)428 (value_use)429 (region430 (entry_block431 (operation432 (op_result433 (value_use))434 (custom_operation435 (arith_dialect436 (value_use)437 (value_use)438 (type439 (builtin_type440 (index_type))))))441 (operation442 (op_result443 (value_use))444 (custom_operation445 (arith_dialect446 (value_use)447 (value_use)448 (value_use)449 (type450 (builtin_type451 (index_type))))))452 (operation453 (op_result454 (value_use))455 (custom_operation456 (arith_dialect457 (value_use)458 (value_use)459 (type460 (builtin_type461 (index_type))))))462 (operation463 (op_result464 (value_use))465 (custom_operation466 (arith_dialect467 (value_use)468 (value_use)469 (value_use)470 (type471 (builtin_type472 (index_type))))))473 (operation474 (custom_operation475 (scf_dialect476 (value_use)477 (value_use)478 (value_use)479 (value_use)480 (region))))))))))))))481 (operation482 (custom_operation483 (func_dialect)))))))))484 485================================================================================486Conditional written with scf.if and scf.yield487================================================================================488func.func @std_if_yield(%arg0: i1, %arg1: f32)489{490 %x, %y = scf.if %arg0 -> (f32, f32) {491 %0 = arith.addf %arg1, %arg1 : f32492 %1 = arith.subf %arg1, %arg1 : f32493 scf.yield %0, %1 : f32, f32494 } else {495 %0 = arith.subf %arg1, %arg1 : f32496 %1 = arith.addf %arg1, %arg1 : f32497 scf.yield %0, %1 : f32, f32498 }499 return500}501--------------------------------------------------------------------------------502 503(toplevel504 (operation505 (custom_operation506 (func_dialect507 (symbol_ref_id)508 (func_arg_list509 (value_use)510 (type511 (builtin_type512 (integer_type)))513 (value_use)514 (type515 (builtin_type516 (float_type))))517 (region518 (entry_block519 (operation520 (op_result521 (value_use))522 (op_result523 (value_use))524 (custom_operation525 (scf_dialect526 (value_use)527 (type528 (builtin_type529 (float_type)))530 (type531 (builtin_type532 (float_type)))533 (region534 (entry_block535 (operation536 (op_result537 (value_use))538 (custom_operation539 (arith_dialect540 (value_use)541 (value_use)542 (type543 (builtin_type544 (float_type))))))545 (operation546 (op_result547 (value_use))548 (custom_operation549 (arith_dialect550 (value_use)551 (value_use)552 (type553 (builtin_type554 (float_type))))))555 (operation556 (custom_operation557 (scf_dialect558 (value_use)559 (value_use)560 (type561 (builtin_type562 (float_type)))563 (type564 (builtin_type565 (float_type))))))))566 (region567 (entry_block568 (operation569 (op_result570 (value_use))571 (custom_operation572 (arith_dialect573 (value_use)574 (value_use)575 (type576 (builtin_type577 (float_type))))))578 (operation579 (op_result580 (value_use))581 (custom_operation582 (arith_dialect583 (value_use)584 (value_use)585 (type586 (builtin_type587 (float_type))))))588 (operation589 (custom_operation590 (scf_dialect591 (value_use)592 (value_use)593 (type594 (builtin_type595 (float_type)))596 (type597 (builtin_type598 (float_type)))))))))))599 (operation600 (custom_operation601 (func_dialect)))))))))602 603================================================================================604Switch statement using scf.index_switch605================================================================================606func.func @switch(%arg0: index) -> i32 {607 %0 = scf.index_switch %arg0 -> i32608 case 2 {609 %c10_i32 = arith.constant 10 : i32610 scf.yield %c10_i32 : i32611 }612 case 5 {613 %c20_i32 = arith.constant 20 : i32614 scf.yield %c20_i32 : i32615 }616 default {617 %c30_i32 = arith.constant 30 : i32618 scf.yield %c30_i32 : i32619 }620 621 scf.index_switch %arg0622 default {623 scf.yield624 }625 626 return %0 : i32627}628--------------------------------------------------------------------------------629 630(toplevel631 (operation632 (custom_operation633 (func_dialect634 (symbol_ref_id)635 (func_arg_list636 (value_use)637 (type638 (builtin_type639 (index_type))))640 (func_return641 (type_list_attr_parens642 (type643 (builtin_type644 (integer_type)))))645 (region646 (entry_block647 (operation648 (op_result649 (value_use))650 (custom_operation651 (scf_dialect652 (value_use)653 (type654 (builtin_type655 (integer_type)))656 (scf_case_label657 (integer_literal))658 (region659 (entry_block660 (operation661 (op_result662 (value_use))663 (custom_operation664 (arith_dialect665 (integer_literal)666 (type667 (builtin_type668 (integer_type))))))669 (operation670 (custom_operation671 (scf_dialect672 (value_use)673 (type674 (builtin_type675 (integer_type))))))))676 (scf_case_label677 (integer_literal))678 (region679 (entry_block680 (operation681 (op_result682 (value_use))683 (custom_operation684 (arith_dialect685 (integer_literal)686 (type687 (builtin_type688 (integer_type))))))689 (operation690 (custom_operation691 (scf_dialect692 (value_use)693 (type694 (builtin_type695 (integer_type))))))))696 (scf_case_label)697 (region698 (entry_block699 (operation700 (op_result701 (value_use))702 (custom_operation703 (arith_dialect704 (integer_literal)705 (type706 (builtin_type707 (integer_type))))))708 (operation709 (custom_operation710 (scf_dialect711 (value_use)712 (type713 (builtin_type714 (integer_type)))))))))))715 (operation716 (custom_operation717 (scf_dialect718 (value_use)719 (scf_case_label)720 (region721 (entry_block722 (operation723 (custom_operation724 (scf_dialect))))))))725 (operation726 (custom_operation727 (func_dialect728 (value_use)729 (type730 (builtin_type731 (integer_type))))))))))))732 733================================================================================734Parallel for-loop and reduction using scf.parallel and scf.reduce735================================================================================736func.func @single_iteration_reduce(%A: index, %B: index) -> (index, index) {737 %c0 = arith.constant 0 : index738 %c1 = arith.constant 1 : index739 %c2 = arith.constant 2 : index740 %c3 = arith.constant 3 : index741 %c6 = arith.constant 6 : index742 %0:2 = scf.parallel (%i0, %i1) = (%c1, %c3) to (%c2, %c6) step (%c1, %c3) init(%A, %B) -> (index, index) {743 scf.reduce(%i0) : index {744 ^bb0(%lhs: index, %rhs: index):745 %1 = arith.addi %lhs, %rhs : index746 scf.reduce.return %1 : index747 }748 scf.reduce(%i1) : index {749 ^bb0(%lhs: index, %rhs: index):750 %2 = arith.muli %lhs, %rhs : index751 scf.reduce.return %2 : index752 }753 scf.yield754 }755 return %0#0, %0#1 : index, index756}757 758func.func @single_iteration_some(%A: memref<?x?x?xi32>) {759 %c0 = arith.constant 0 : index760 %c1 = arith.constant 1 : index761 %c2 = arith.constant 2 : index762 %c3 = arith.constant 3 : index763 %c6 = arith.constant 6 : index764 %c7 = arith.constant 7 : index765 %c10 = arith.constant 10 : index766 scf.parallel (%i0, %i1, %i2) = (%c0, %c3, %c7) to (%c1, %c6, %c10) step (%c1, %c2, %c3) {767 %c42 = arith.constant 42 : i32768 memref.store %c42, %A[%i0, %i1, %i2] : memref<?x?x?xi32>769 scf.yield770 }771 return772}773--------------------------------------------------------------------------------774 775(toplevel776 (operation777 (custom_operation778 (func_dialect779 (symbol_ref_id)780 (func_arg_list781 (value_use)782 (type783 (builtin_type784 (index_type)))785 (value_use)786 (type787 (builtin_type788 (index_type))))789 (func_return790 (type_list_attr_parens791 (type792 (builtin_type793 (index_type)))794 (type795 (builtin_type796 (index_type)))))797 (region798 (entry_block799 (operation800 (op_result801 (value_use))802 (custom_operation803 (arith_dialect804 (integer_literal)805 (type806 (builtin_type807 (index_type))))))808 (operation809 (op_result810 (value_use))811 (custom_operation812 (arith_dialect813 (integer_literal)814 (type815 (builtin_type816 (index_type))))))817 (operation818 (op_result819 (value_use))820 (custom_operation821 (arith_dialect822 (integer_literal)823 (type824 (builtin_type825 (index_type))))))826 (operation827 (op_result828 (value_use))829 (custom_operation830 (arith_dialect831 (integer_literal)832 (type833 (builtin_type834 (index_type))))))835 (operation836 (op_result837 (value_use))838 (custom_operation839 (arith_dialect840 (integer_literal)841 (type842 (builtin_type843 (index_type))))))844 (operation845 (op_result846 (value_use))847 (custom_operation848 (scf_dialect849 (value_use)850 (value_use)851 (value_use)852 (value_use)853 (value_use)854 (value_use)855 (value_use)856 (value_use)857 (value_use)858 (value_use)859 (type860 (builtin_type861 (index_type)))862 (type863 (builtin_type864 (index_type)))865 (region866 (entry_block867 (operation868 (custom_operation869 (scf_dialect870 (value_use)871 (type872 (builtin_type873 (index_type)))874 (region875 (block876 (block_label877 (caret_id)878 (block_arg_list879 (value_use)880 (type881 (builtin_type882 (index_type)))883 (value_use)884 (type885 (builtin_type886 (index_type)))))887 (operation888 (op_result889 (value_use))890 (custom_operation891 (arith_dialect892 (value_use)893 (value_use)894 (type895 (builtin_type896 (index_type))))))897 (operation898 (custom_operation899 (scf_dialect900 (value_use)901 (type902 (builtin_type903 (index_type)))))))))))904 (operation905 (custom_operation906 (scf_dialect907 (value_use)908 (type909 (builtin_type910 (index_type)))911 (region912 (block913 (block_label914 (caret_id)915 (block_arg_list916 (value_use)917 (type918 (builtin_type919 (index_type)))920 (value_use)921 (type922 (builtin_type923 (index_type)))))924 (operation925 (op_result926 (value_use))927 (custom_operation928 (arith_dialect929 (value_use)930 (value_use)931 (type932 (builtin_type933 (index_type))))))934 (operation935 (custom_operation936 (scf_dialect937 (value_use)938 (type939 (builtin_type940 (index_type)))))))))))941 (operation942 (custom_operation943 (scf_dialect))))))))944 (operation945 (custom_operation946 (func_dialect947 (value_use)948 (value_use)949 (type950 (builtin_type951 (index_type)))952 (type953 (builtin_type954 (index_type)))))))))))955 (operation956 (custom_operation957 (func_dialect958 (symbol_ref_id)959 (func_arg_list960 (value_use)961 (type962 (builtin_type963 (memref_type964 (dim_list965 (integer_type))))))966 (region967 (entry_block968 (operation969 (op_result970 (value_use))971 (custom_operation972 (arith_dialect973 (integer_literal)974 (type975 (builtin_type976 (index_type))))))977 (operation978 (op_result979 (value_use))980 (custom_operation981 (arith_dialect982 (integer_literal)983 (type984 (builtin_type985 (index_type))))))986 (operation987 (op_result988 (value_use))989 (custom_operation990 (arith_dialect991 (integer_literal)992 (type993 (builtin_type994 (index_type))))))995 (operation996 (op_result997 (value_use))998 (custom_operation999 (arith_dialect1000 (integer_literal)1001 (type1002 (builtin_type1003 (index_type))))))1004 (operation1005 (op_result1006 (value_use))1007 (custom_operation1008 (arith_dialect1009 (integer_literal)1010 (type1011 (builtin_type1012 (index_type))))))1013 (operation1014 (op_result1015 (value_use))1016 (custom_operation1017 (arith_dialect1018 (integer_literal)1019 (type1020 (builtin_type1021 (index_type))))))1022 (operation1023 (op_result1024 (value_use))1025 (custom_operation1026 (arith_dialect1027 (integer_literal)1028 (type1029 (builtin_type1030 (index_type))))))1031 (operation1032 (custom_operation1033 (scf_dialect1034 (value_use)1035 (value_use)1036 (value_use)1037 (value_use)1038 (value_use)1039 (value_use)1040 (value_use)1041 (value_use)1042 (value_use)1043 (value_use)1044 (value_use)1045 (value_use)1046 (region1047 (entry_block1048 (operation1049 (op_result1050 (value_use))1051 (custom_operation1052 (arith_dialect1053 (integer_literal)1054 (type1055 (builtin_type1056 (integer_type))))))1057 (operation1058 (custom_operation1059 (memref_dialect1060 (value_use)1061 (value_use)1062 (value_use)1063 (value_use)1064 (value_use)1065 (type1066 (builtin_type1067 (memref_type1068 (dim_list1069 (integer_type))))))))1070 (operation1071 (custom_operation1072 (scf_dialect))))))))1073 (operation1074 (custom_operation1075 (func_dialect)))))))))1076 1077================================================================================1078While loop written using scf.while and scf.condition1079================================================================================1080func.func @while_cond_true() -> i1 {1081 %0 = scf.while () : () -> i1 {1082 %condition = "test.condition"() : () -> i11083 scf.condition(%condition) %condition : i11084 } do {1085 ^bb0(%arg0: i1):1086 "test.use"(%arg0) : (i1) -> ()1087 scf.yield1088 }1089 return %0 : i11090}1091 1092func.func @while_unused_arg(%x : i32, %y : f64) -> i32 {1093 %0 = scf.while (%arg1 = %x, %arg2 = %y) : (i32, f64) -> (i32) {1094 %condition = "test.condition"(%arg1) : (i32) -> i11095 scf.condition(%condition) %arg1 : i321096 } do {1097 ^bb0(%arg1: i32):1098 %next = "test.use"(%arg1) : (i32) -> (i32)1099 scf.yield %next, %y : i32, f641100 }1101 return %0 : i321102}1103 1104func.func @infinite_while() {1105 %true = arith.constant true1106 scf.while : () -> () {1107 scf.condition(%true)1108 } do {1109 scf.yield1110 }1111 return1112}1113--------------------------------------------------------------------------------1114 1115(toplevel1116 (operation1117 (custom_operation1118 (func_dialect1119 (symbol_ref_id)1120 (func_arg_list)1121 (func_return1122 (type_list_attr_parens1123 (type1124 (builtin_type1125 (integer_type)))))1126 (region1127 (entry_block1128 (operation1129 (op_result1130 (value_use))1131 (custom_operation1132 (scf_dialect1133 (function_type1134 (type1135 (builtin_type1136 (integer_type))))1137 (region1138 (entry_block1139 (operation1140 (op_result1141 (value_use))1142 (generic_operation1143 (string_literal)1144 (function_type1145 (type1146 (builtin_type1147 (integer_type))))))1148 (operation1149 (custom_operation1150 (scf_dialect1151 (value_use)1152 (value_use)1153 (type1154 (builtin_type1155 (integer_type))))))))1156 (region1157 (block1158 (block_label1159 (caret_id)1160 (block_arg_list1161 (value_use)1162 (type1163 (builtin_type1164 (integer_type)))))1165 (operation1166 (generic_operation1167 (string_literal)1168 (value_use)1169 (function_type1170 (type1171 (builtin_type1172 (integer_type))))))1173 (operation1174 (custom_operation1175 (scf_dialect))))))))1176 (operation1177 (custom_operation1178 (func_dialect1179 (value_use)1180 (type1181 (builtin_type1182 (integer_type)))))))))))1183 (operation1184 (custom_operation1185 (func_dialect1186 (symbol_ref_id)1187 (func_arg_list1188 (value_use)1189 (type1190 (builtin_type1191 (integer_type)))1192 (value_use)1193 (type1194 (builtin_type1195 (float_type))))1196 (func_return1197 (type_list_attr_parens1198 (type1199 (builtin_type1200 (integer_type)))))1201 (region1202 (entry_block1203 (operation1204 (op_result1205 (value_use))1206 (custom_operation1207 (scf_dialect1208 (value_use)1209 (value_use)1210 (value_use)1211 (value_use)1212 (function_type1213 (type1214 (builtin_type1215 (integer_type)))1216 (type1217 (builtin_type1218 (float_type)))1219 (type1220 (builtin_type1221 (integer_type))))1222 (region1223 (entry_block1224 (operation1225 (op_result1226 (value_use))1227 (generic_operation1228 (string_literal)1229 (value_use)1230 (function_type1231 (type1232 (builtin_type1233 (integer_type)))1234 (type1235 (builtin_type1236 (integer_type))))))1237 (operation1238 (custom_operation1239 (scf_dialect1240 (value_use)1241 (value_use)1242 (type1243 (builtin_type1244 (integer_type))))))))1245 (region1246 (block1247 (block_label1248 (caret_id)1249 (block_arg_list1250 (value_use)1251 (type1252 (builtin_type1253 (integer_type)))))1254 (operation1255 (op_result1256 (value_use))1257 (generic_operation1258 (string_literal)1259 (value_use)1260 (function_type1261 (type1262 (builtin_type1263 (integer_type)))1264 (type1265 (builtin_type1266 (integer_type))))))1267 (operation1268 (custom_operation1269 (scf_dialect1270 (value_use)1271 (value_use)1272 (type1273 (builtin_type1274 (integer_type)))1275 (type1276 (builtin_type1277 (float_type)))))))))))1278 (operation1279 (custom_operation1280 (func_dialect1281 (value_use)1282 (type1283 (builtin_type1284 (integer_type)))))))))))1285 (operation1286 (custom_operation1287 (func_dialect1288 (symbol_ref_id)1289 (func_arg_list)1290 (region1291 (entry_block1292 (operation1293 (op_result1294 (value_use))1295 (custom_operation1296 (arith_dialect1297 (bool_literal))))1298 (operation1299 (custom_operation1300 (scf_dialect1301 (function_type)1302 (region1303 (entry_block1304 (operation1305 (custom_operation1306 (scf_dialect1307 (value_use))))))1308 (region1309 (entry_block1310 (operation1311 (custom_operation1312 (scf_dialect))))))))1313 (operation1314 (custom_operation1315 (func_dialect)))))))))1316 1317================================================================================1318affine.for with attribute aliseses1319================================================================================1320#map_simple0 = affine_map<()[] -> (10)>1321#map_simple1 = affine_map<()[s0] -> (s0)>1322#map_non_simple0 = affine_map<(d0)[] -> (d0)>1323#map_non_simple1 = affine_map<(d0)[s0] -> (d0 + s0)>1324#map_non_simple2 = affine_map<()[s0, s1] -> (s0 + s1)>1325#map_non_simple3 = affine_map<()[s0] -> (s0 + 3)>1326func.func @funcsimplemap(%arg0: index, %arg1: index) -> () {1327 affine.for %i0 = 0 to #map_simple0()[] {1328 affine.for %i1 = 0 to #map_simple1()[%arg1] {1329 affine.for %i2 = 0 to #map_non_simple0(%i0)[] {1330 affine.for %i3 = 0 to #map_non_simple1(%i0)[%arg1] {1331 affine.for %i4 = 0 to #map_non_simple2()[%arg1, %arg0] {1332 affine.for %i5 = 0 to #map_non_simple3()[%arg0] {1333 %c42_i32 = arith.constant 42 : i321334 }1335 }1336 }1337 }1338 }1339 }1340 return1341}1342--------------------------------------------------------------------------------1343 1344(toplevel1345 (attribute_alias_def1346 (attribute_value1347 (builtin_attribute1348 (affine_map1349 (integer_literal)))))1350 (attribute_alias_def1351 (attribute_value1352 (builtin_attribute1353 (affine_map1354 (bare_id)1355 (bare_id)))))1356 (attribute_alias_def1357 (attribute_value1358 (builtin_attribute1359 (affine_map1360 (bare_id)1361 (bare_id)))))1362 (attribute_alias_def1363 (attribute_value1364 (builtin_attribute1365 (affine_map1366 (bare_id)1367 (bare_id)1368 (bare_id)1369 (bare_id)))))1370 (attribute_alias_def1371 (attribute_value1372 (builtin_attribute1373 (affine_map1374 (bare_id)1375 (bare_id)1376 (bare_id)1377 (bare_id)))))1378 (attribute_alias_def1379 (attribute_value1380 (builtin_attribute1381 (affine_map1382 (bare_id)1383 (bare_id)1384 (integer_literal)))))1385 (operation1386 (custom_operation1387 (func_dialect1388 (symbol_ref_id)1389 (func_arg_list1390 (value_use)1391 (type1392 (builtin_type1393 (index_type)))1394 (value_use)1395 (type1396 (builtin_type1397 (index_type))))1398 (func_return1399 (type_list_attr_parens))1400 (region1401 (entry_block1402 (operation1403 (custom_operation1404 (affine_dialect1405 (value_use)1406 (integer_literal)1407 (attribute1408 (attribute_alias))1409 (region1410 (entry_block1411 (operation1412 (custom_operation1413 (affine_dialect1414 (value_use)1415 (integer_literal)1416 (attribute1417 (attribute_alias))1418 (value_use)1419 (region1420 (entry_block1421 (operation1422 (custom_operation1423 (affine_dialect1424 (value_use)1425 (integer_literal)1426 (attribute1427 (attribute_alias))1428 (value_use)1429 (region1430 (entry_block1431 (operation1432 (custom_operation1433 (affine_dialect1434 (value_use)1435 (integer_literal)1436 (attribute1437 (attribute_alias))1438 (value_use)1439 (value_use)1440 (region1441 (entry_block1442 (operation1443 (custom_operation1444 (affine_dialect1445 (value_use)1446 (integer_literal)1447 (attribute1448 (attribute_alias))1449 (value_use)1450 (value_use)1451 (region1452 (entry_block1453 (operation1454 (custom_operation1455 (affine_dialect1456 (value_use)1457 (integer_literal)1458 (attribute1459 (attribute_alias))1460 (value_use)1461 (region1462 (entry_block1463 (operation1464 (op_result1465 (value_use))1466 (custom_operation1467 (arith_dialect1468 (integer_literal)1469 (type1470 (builtin_type1471 (integer_type))))))))))))))))))))))))))))))))))))1472 (operation1473 (custom_operation1474 (func_dialect)))))))))1475 1476================================================================================1477affine.if and affine.yield1478================================================================================1479func.func @affine_if() -> f32 {1480 %zero = arith.constant 0.0 : f321481 %0 = affine.if affine_set<() : ()> () -> f32 {1482 affine.yield %zero : f321483 } else {1484 affine.yield %zero : f321485 }1486 return %0 : f321487}1488--------------------------------------------------------------------------------1489 1490(toplevel1491 (operation1492 (custom_operation1493 (func_dialect1494 (symbol_ref_id)1495 (func_arg_list)1496 (func_return1497 (type_list_attr_parens1498 (type1499 (builtin_type1500 (float_type)))))1501 (region1502 (entry_block1503 (operation1504 (op_result1505 (value_use))1506 (custom_operation1507 (arith_dialect1508 (float_literal)1509 (type1510 (builtin_type1511 (float_type))))))1512 (operation1513 (op_result1514 (value_use))1515 (custom_operation1516 (affine_dialect1517 (attribute1518 (builtin_attribute1519 (affine_set)))1520 (type1521 (builtin_type1522 (float_type)))1523 (region1524 (entry_block1525 (operation1526 (custom_operation1527 (affine_dialect1528 (value_use)1529 (type1530 (builtin_type1531 (float_type))))))))1532 (region1533 (entry_block1534 (operation1535 (custom_operation1536 (affine_dialect1537 (value_use)1538 (type1539 (builtin_type1540 (float_type)))))))))))1541 (operation1542 (custom_operation1543 (func_dialect1544 (value_use)1545 (type1546 (builtin_type1547 (float_type))))))))))))1548 1549================================================================================1550Parallel for loop written using affine.parallel1551================================================================================1552func.func @parallel(%A : memref<100x100xf32>, %N : index) {1553 affine.parallel (%i0, %j0) = (0, 0) to (symbol(%N), 100) step (10, 10) {1554 %0:2 = affine.parallel (%i1, %j1) = (%i0, %j0) to (%i0 + 10, %j0 + 10)1555 reduce ("minf", "maxf") -> (f32, f32) {1556 %2 = affine.load %A[%i0 + %i0, %j0 + %j1] : memref<100x100xf32>1557 affine.yield %2, %2 : f32, f321558 }1559 }1560 return1561}1562 1563func.func @parallel_min_max(%a: index, %b: index, %c: index, %d: index) {1564 affine.parallel (%i, %j, %k) = (max(%a, %b), %b, max(%a, %c))1565 to (%c, min(%c, %d), %b) {1566 affine.yield1567 }1568 return1569}1570--------------------------------------------------------------------------------1571 1572(toplevel1573 (operation1574 (custom_operation1575 (func_dialect1576 (symbol_ref_id)1577 (func_arg_list1578 (value_use)1579 (type1580 (builtin_type1581 (memref_type1582 (dim_list1583 (float_type)))))1584 (value_use)1585 (type1586 (builtin_type1587 (index_type))))1588 (region1589 (entry_block1590 (operation1591 (custom_operation1592 (affine_dialect1593 (value_use)1594 (value_use)1595 (integer_literal)1596 (integer_literal)1597 (value_use)1598 (integer_literal)1599 (integer_literal)1600 (integer_literal)1601 (region1602 (entry_block1603 (operation1604 (op_result1605 (value_use))1606 (custom_operation1607 (affine_dialect1608 (value_use)1609 (value_use)1610 (value_use)1611 (value_use)1612 (value_use)1613 (integer_literal)1614 (value_use)1615 (integer_literal)1616 (string_literal)1617 (string_literal)1618 (type1619 (builtin_type1620 (float_type)))1621 (type1622 (builtin_type1623 (float_type)))1624 (region1625 (entry_block1626 (operation1627 (op_result1628 (value_use))1629 (custom_operation1630 (affine_dialect1631 (value_use)1632 (value_use)1633 (value_use)1634 (value_use)1635 (value_use)1636 (type1637 (builtin_type1638 (memref_type1639 (dim_list1640 (float_type))))))))1641 (operation1642 (custom_operation1643 (affine_dialect1644 (value_use)1645 (value_use)1646 (type1647 (builtin_type1648 (float_type)))1649 (type1650 (builtin_type1651 (float_type))))))))))))))))1652 (operation1653 (custom_operation1654 (func_dialect))))))))1655 (operation1656 (custom_operation1657 (func_dialect1658 (symbol_ref_id)1659 (func_arg_list1660 (value_use)1661 (type1662 (builtin_type1663 (index_type)))1664 (value_use)1665 (type1666 (builtin_type1667 (index_type)))1668 (value_use)1669 (type1670 (builtin_type1671 (index_type)))1672 (value_use)1673 (type1674 (builtin_type1675 (index_type))))1676 (region1677 (entry_block1678 (operation1679 (custom_operation1680 (affine_dialect1681 (value_use)1682 (value_use)1683 (value_use)1684 (value_use)1685 (value_use)1686 (value_use)1687 (value_use)1688 (value_use)1689 (value_use)1690 (value_use)1691 (value_use)1692 (value_use)1693 (region1694 (entry_block1695 (operation1696 (custom_operation1697 (affine_dialect))))))))1698 (operation1699 (custom_operation1700 (func_dialect)))))))))1701 1702================================================================================1703Execution of a region using scf.execute_region1704================================================================================1705func.func @execute_region() -> i64 {1706 %res = scf.execute_region -> i64 {1707 %c1 = arith.constant 1 : i641708 scf.yield %c1 : i641709 }1710 1711 %res2:2 = scf.execute_region -> (i64, i64) {1712 %c1 = arith.constant 1 : i641713 scf.yield %c1, %c1 : i64, i641714 }1715 return %res : i641716}1717--------------------------------------------------------------------------------1718 1719(toplevel1720 (operation1721 (custom_operation1722 (func_dialect1723 (symbol_ref_id)1724 (func_arg_list)1725 (func_return1726 (type_list_attr_parens1727 (type1728 (builtin_type1729 (integer_type)))))1730 (region1731 (entry_block1732 (operation1733 (op_result1734 (value_use))1735 (custom_operation1736 (scf_dialect1737 (type1738 (builtin_type1739 (integer_type)))1740 (region1741 (entry_block1742 (operation1743 (op_result1744 (value_use))1745 (custom_operation1746 (arith_dialect1747 (integer_literal)1748 (type1749 (builtin_type1750 (integer_type))))))1751 (operation1752 (custom_operation1753 (scf_dialect1754 (value_use)1755 (type1756 (builtin_type1757 (integer_type)))))))))))1758 (operation1759 (op_result1760 (value_use))1761 (custom_operation1762 (scf_dialect1763 (type1764 (builtin_type1765 (integer_type)))1766 (type1767 (builtin_type1768 (integer_type)))1769 (region1770 (entry_block1771 (operation1772 (op_result1773 (value_use))1774 (custom_operation1775 (arith_dialect1776 (integer_literal)1777 (type1778 (builtin_type1779 (integer_type))))))1780 (operation1781 (custom_operation1782 (scf_dialect1783 (value_use)1784 (value_use)1785 (type1786 (builtin_type1787 (integer_type)))1788 (type1789 (builtin_type1790 (integer_type)))))))))))1791 (operation1792 (custom_operation1793 (func_dialect1794 (value_use)1795 (type1796 (builtin_type1797 (integer_type))))))))))))1798 1799================================================================================1800Parallel loop written using scf.forall and scf.forall.in_parallel1801================================================================================1802func.func @normalized_forall(%in: tensor<100xf32>, %out: tensor<100xf32>) {1803 %c1 = arith.constant 1 : index1804 %num_threads = arith.constant 100 : index1805 %result = scf.forall (%thread_idx) in (%num_threads) shared_outs(%o = %out) -> tensor<100xf32> {1806 %1 = tensor.extract_slice %in[%thread_idx][1][1] : tensor<100xf32> to tensor<1xf32>1807 scf.forall.in_parallel {1808 tensor.parallel_insert_slice %1 into %o[%thread_idx][1][1] :1809 tensor<1xf32> into tensor<100xf32>1810 }1811 }1812 return1813}1814 1815func.func @explicit_loop_bounds_forall(%in: tensor<100xf32>,1816 %out: tensor<100xf32>) {1817 %c0 = arith.constant 0 : index1818 %c1 = arith.constant 1 : index1819 %num_threads = arith.constant 100 : index1820 %result = scf.forall (%thread_idx) = (%c0) to (%num_threads) step (%c1) shared_outs(%o = %out) -> tensor<100xf32> {1821 %1 = tensor.extract_slice %in[%thread_idx][1][1] : tensor<100xf32> to tensor<1xf32>1822 scf.forall.in_parallel {1823 tensor.parallel_insert_slice %1 into %o[%thread_idx][1][1] :1824 tensor<1xf32> into tensor<100xf32>1825 } {mapping = [#gpu.thread<x>]}1826 }1827 return1828}1829 1830func.func @normalized_forall_elide_terminator() -> () {1831 %num_threads = arith.constant 100 : index1832 scf.forall (%thread_idx) in (%num_threads) {1833 scf.forall.in_parallel {1834 }1835 } {mapping = [#gpu.thread<x>]}1836 return1837 1838}1839--------------------------------------------------------------------------------1840 1841(toplevel1842 (operation1843 (custom_operation1844 (func_dialect1845 (symbol_ref_id)1846 (func_arg_list1847 (value_use)1848 (type1849 (builtin_type1850 (tensor_type1851 (dim_list1852 (float_type)))))1853 (value_use)1854 (type1855 (builtin_type1856 (tensor_type1857 (dim_list1858 (float_type))))))1859 (region1860 (entry_block1861 (operation1862 (op_result1863 (value_use))1864 (custom_operation1865 (arith_dialect1866 (integer_literal)1867 (type1868 (builtin_type1869 (index_type))))))1870 (operation1871 (op_result1872 (value_use))1873 (custom_operation1874 (arith_dialect1875 (integer_literal)1876 (type1877 (builtin_type1878 (index_type))))))1879 (operation1880 (op_result1881 (value_use))1882 (custom_operation1883 (scf_dialect1884 (value_use)1885 (value_use)1886 (value_use)1887 (value_use)1888 (type1889 (builtin_type1890 (tensor_type1891 (dim_list1892 (float_type)))))1893 (region1894 (entry_block1895 (operation1896 (op_result1897 (value_use))1898 (custom_operation1899 (tensor_dialect1900 (value_use)1901 (value_use)1902 (integer_literal)1903 (integer_literal)1904 (type1905 (builtin_type1906 (tensor_type1907 (dim_list1908 (float_type)))))1909 (type1910 (builtin_type1911 (tensor_type1912 (dim_list1913 (float_type))))))))1914 (operation1915 (custom_operation1916 (scf_dialect1917 (region1918 (entry_block1919 (operation1920 (custom_operation1921 (tensor_dialect1922 (value_use)1923 (value_use)1924 (value_use)1925 (integer_literal)1926 (integer_literal)1927 (type1928 (builtin_type1929 (tensor_type1930 (dim_list1931 (float_type)))))1932 (type1933 (builtin_type1934 (tensor_type1935 (dim_list1936 (float_type))))))))))))))))))1937 (operation1938 (custom_operation1939 (func_dialect))))))))1940 (operation1941 (custom_operation1942 (func_dialect1943 (symbol_ref_id)1944 (func_arg_list1945 (value_use)1946 (type1947 (builtin_type1948 (tensor_type1949 (dim_list1950 (float_type)))))1951 (value_use)1952 (type1953 (builtin_type1954 (tensor_type1955 (dim_list1956 (float_type))))))1957 (region1958 (entry_block1959 (operation1960 (op_result1961 (value_use))1962 (custom_operation1963 (arith_dialect1964 (integer_literal)1965 (type1966 (builtin_type1967 (index_type))))))1968 (operation1969 (op_result1970 (value_use))1971 (custom_operation1972 (arith_dialect1973 (integer_literal)1974 (type1975 (builtin_type1976 (index_type))))))1977 (operation1978 (op_result1979 (value_use))1980 (custom_operation1981 (arith_dialect1982 (integer_literal)1983 (type1984 (builtin_type1985 (index_type))))))1986 (operation1987 (op_result1988 (value_use))1989 (custom_operation1990 (scf_dialect1991 (value_use)1992 (value_use)1993 (value_use)1994 (value_use)1995 (value_use)1996 (value_use)1997 (type1998 (builtin_type1999 (tensor_type2000 (dim_list2001 (float_type)))))2002 (region2003 (entry_block2004 (operation2005 (op_result2006 (value_use))2007 (custom_operation2008 (tensor_dialect2009 (value_use)2010 (value_use)2011 (integer_literal)2012 (integer_literal)2013 (type2014 (builtin_type2015 (tensor_type2016 (dim_list2017 (float_type)))))2018 (type2019 (builtin_type2020 (tensor_type2021 (dim_list2022 (float_type))))))))2023 (operation2024 (custom_operation2025 (scf_dialect2026 (region2027 (entry_block2028 (operation2029 (custom_operation2030 (tensor_dialect2031 (value_use)2032 (value_use)2033 (value_use)2034 (integer_literal)2035 (integer_literal)2036 (type2037 (builtin_type2038 (tensor_type2039 (dim_list2040 (float_type)))))2041 (type2042 (builtin_type2043 (tensor_type2044 (dim_list2045 (float_type))))))))))2046 (attribute2047 (dictionary_attribute2048 (attribute_entry2049 (bare_id)2050 (attribute_value2051 (dialect_attribute2052 (pretty_dialect_item2053 (dialect_namespace)2054 (dialect_ident)2055 (pretty_dialect_item_body)))))))))))))))2056 (operation2057 (custom_operation2058 (func_dialect))))))))2059 (operation2060 (custom_operation2061 (func_dialect2062 (symbol_ref_id)2063 (func_arg_list)2064 (func_return2065 (type_list_attr_parens))2066 (region2067 (entry_block2068 (operation2069 (op_result2070 (value_use))2071 (custom_operation2072 (arith_dialect2073 (integer_literal)2074 (type2075 (builtin_type2076 (index_type))))))2077 (operation2078 (custom_operation2079 (scf_dialect2080 (value_use)2081 (value_use)2082 (region2083 (entry_block2084 (operation2085 (custom_operation2086 (scf_dialect2087 (region))))))2088 (attribute2089 (dictionary_attribute2090 (attribute_entry2091 (bare_id)2092 (attribute_value2093 (dialect_attribute2094 (pretty_dialect_item2095 (dialect_namespace)2096 (dialect_ident)2097 (pretty_dialect_item_body))))))))))2098 (operation2099 (custom_operation2100 (func_dialect)))))))))2101