1# HLO Text Syntax 2 3```yacc 4hlo_module 5 : 'HloModule' name computations 6 ; 7 8/* If no computation is marked as ENTRY, the last computation will be the entry 9computation of the module.*/ 10computations 11 : computation 12 | computation computations 13 ; 14 15computation 16 : 'ENTRY' name param_list_to_shape instruction_list 17 | name param_list_to_shape instruction_list 18 | 'ENTRY' name instruction_list 19 | name instruction_list 20 ; 21 22/* If no instruction is marked as ROOT, the last instruction will be the root of 23its computation. */ 24instruction_list 25 : '{' instruction_list1 '}' 26 ; 27instruction_list1 28 : instruction 29 | instruction_list1 instruction 30 ; 31instruction 32 : 'ROOT' name '=' shape opcode operands extra_attributes 33 | name '=' shape opcode operands extra_attributes 34 ; 35 36operands 37 : '(' operands1 ')' 38 ; 39operands1 40 : /*empty*/ 41 | operand 42 | operands1 ',' operand 43 ; 44operand 45 : shape name 46 | name 47 ; 48 49attributes 50 : /*empty*/ 51 | ',' attribute 52 | ',' attribute attributes 53 ; 54attribute 55 : attribute_name attribute_value 56 ; 57attribute_value 58 : kInt 59 | kName 60 | [0-9bf]{2,}_[0-9io]{2,}->[0-9bf]{2,} /*dim_labels_pattern*/ 61 | [0-9]+(x[0-9]+)+ /*dxd_pattern*/ 62 | [0-9]+_[0-9]+(_[0-9]+)?(x[0-9]+_[0-9]+(_[0-9]+)?)* /*pad_pattern*/ 63 | '{' sub_attributes '}' 64 ; 65 66param_list_to_shape 67 : param_list '->' shape 68 ; 69 70param_list 71 : '(' param_list1 ')' 72 ; 73param_list1 74 : /*empty*/ 75 | param 76 | param_list1 ',' param 77 ; 78param 79 : name shape 80 ; 81 82shape 83 : shape_val_ 84 | '(' tuple_elements ')' 85 ; 86tuple_elements 87 : /*empty*/ 88 | shape (',' shape)* 89 ; 90 91name 92 : identifier ':' 93 | '%' identifier 94 | identifier 95 ; 96 97identifier 98 : [a-zA-Z_][a-zA-Z0-9_.-]* 99 ; 100 101/* literal is in the right hand side of a constant instruction. */ 102literal 103 : tuple 104 | non_tuple 105 ; 106tuple 107 : shape '(' literal_list ')' 108 ; 109literal_list 110 : /*empty*/ 111 : literal 112 | literal_list ',' literal 113 ; 114non_tuple 115 : rank01 116 | rank2345 117 ; 118rank2345 119 : shape sparse_or_nested_array 120 ; 121sparse_or_nested_array 122 : sparse_array 123 | nested_array 124 ; 125sparse_array 126 : '{' sparse_array1 '}' 127 ; 128sparse_array1 129 : sparse_array_item 130 | sparse_array1 ',' sparse_array_item 131 ; 132sparse_array_item 133 : multi_index ':' scalar 134 ; 135multi_index 136 : kInt 137 | '[' multi_index1 ']' 138 ; 139multi_index1 140 : kInt 141 | multi_index1 ',' kInt 142 ; 143 144``` 145