@@ -567,6 +567,11 @@ void IRPrinter::print(const Stmt &ir) {
567
567
ir.accept (this );
568
568
}
569
569
570
+ void IRPrinter::print_summary (const Stmt &ir) {
571
+ ScopedValue<bool > old (is_summary, true );
572
+ ir.accept (this );
573
+ }
574
+
570
575
void IRPrinter::print_list (const std::vector<Expr> &exprs) {
571
576
for (size_t i = 0 ; i < exprs.size (); i++) {
572
577
print_no_parens (exprs[i]);
@@ -865,7 +870,9 @@ void IRPrinter::visit(const Let *op) {
865
870
stream << " let " << op->name << " = " ;
866
871
print (op->value );
867
872
stream << " in " ;
868
- print (op->body );
873
+ if (!is_summary) {
874
+ print (op->body );
875
+ }
869
876
close ();
870
877
}
871
878
@@ -875,7 +882,9 @@ void IRPrinter::visit(const LetStmt *op) {
875
882
print_no_parens (op->value );
876
883
stream << " \n " ;
877
884
878
- print (op->body );
885
+ if (!is_summary) {
886
+ print (op->body );
887
+ }
879
888
}
880
889
881
890
void IRPrinter::visit (const AssertStmt *op) {
@@ -905,25 +914,18 @@ void IRPrinter::visit(const For *op) {
905
914
print_no_parens (op->min );
906
915
stream << " , " ;
907
916
print_no_parens (op->extent );
908
- stream << " ) { \n " ;
917
+ stream << " ) " ;
909
918
910
- indent++;
911
- print (op->body );
912
- indent--;
913
-
914
- stream << get_indent () << " }\n " ;
919
+ print_braced_stmt (op->body , 1 );
915
920
}
916
921
917
922
void IRPrinter::visit (const Acquire *op) {
918
923
stream << get_indent () << " acquire (" ;
919
924
print_no_parens (op->semaphore );
920
925
stream << " , " ;
921
926
print_no_parens (op->count );
922
- stream << " ) {\n " ;
923
- indent++;
924
- print (op->body );
925
- indent--;
926
- stream << get_indent () << " }\n " ;
927
+ stream << " ) " ;
928
+ print_braced_stmt (op->body , 1 );
927
929
}
928
930
929
931
void IRPrinter::print_lets (const Let *let) {
@@ -932,7 +934,9 @@ void IRPrinter::print_lets(const Let *let) {
932
934
stream << " let " << let->name << " = " ;
933
935
print_no_parens (let->value );
934
936
stream << " in\n " ;
935
- if (const Let *next = let->body .as <Let>()) {
937
+ if (is_summary) {
938
+ stream << get_indent () << " ...\n " ;
939
+ } else if (const Let *next = let->body .as <Let>()) {
936
940
print_lets (next);
937
941
} else {
938
942
stream << get_indent ();
@@ -941,6 +945,19 @@ void IRPrinter::print_lets(const Let *let) {
941
945
}
942
946
}
943
947
948
+ void IRPrinter::print_braced_stmt (const Stmt &stmt, int extra_indent) {
949
+ if (is_summary) {
950
+ stream << " { ... }\n " ;
951
+ return ;
952
+ }
953
+
954
+ stream << " {\n " ;
955
+ indent += extra_indent;
956
+ print (stmt);
957
+ indent -= extra_indent;
958
+ stream << get_indent () << " }\n " ;
959
+ }
960
+
944
961
void IRPrinter::visit (const Store *op) {
945
962
stream << get_indent ();
946
963
const bool has_pred = !is_const_one (op->predicate );
@@ -1038,7 +1055,10 @@ void IRPrinter::visit(const Allocate *op) {
1038
1055
stream << get_indent () << " custom_delete { " << op->free_function << " (" << op->name << " ); }" ;
1039
1056
}
1040
1057
stream << " \n " ;
1041
- print (op->body );
1058
+
1059
+ if (!is_summary) {
1060
+ print (op->body );
1061
+ }
1042
1062
}
1043
1063
1044
1064
void IRPrinter::visit (const Free *op) {
@@ -1067,13 +1087,9 @@ void IRPrinter::visit(const Realize *op) {
1067
1087
stream << " if " ;
1068
1088
print (op->condition );
1069
1089
}
1070
- stream << " {\n " ;
1071
-
1072
- indent++;
1073
- print (op->body );
1074
- indent--;
1075
1090
1076
- stream << get_indent () << " }\n " ;
1091
+ stream << " " ;
1092
+ print_braced_stmt (op->body );
1077
1093
}
1078
1094
1079
1095
void IRPrinter::visit (const Prefetch *op) {
@@ -1102,12 +1118,16 @@ void IRPrinter::visit(const Prefetch *op) {
1102
1118
indent--;
1103
1119
stream << get_indent () << " }\n " ;
1104
1120
}
1105
- print (op->body );
1121
+ if (!is_summary) {
1122
+ print (op->body );
1123
+ }
1106
1124
}
1107
1125
1108
1126
void IRPrinter::visit (const Block *op) {
1109
- print (op->first );
1110
- print (op->rest );
1127
+ if (!is_summary) {
1128
+ print (op->first );
1129
+ print (op->rest );
1130
+ }
1111
1131
}
1112
1132
1113
1133
void IRPrinter::visit (const Fork *op) {
@@ -1121,14 +1141,23 @@ void IRPrinter::visit(const Fork *op) {
1121
1141
stmts.push_back (rest);
1122
1142
1123
1143
stream << get_indent () << " fork " ;
1124
- for (const Stmt &s : stmts) {
1125
- stream << " {\n " ;
1126
- indent++;
1127
- print (s);
1128
- indent--;
1129
- stream << get_indent () << " } " ;
1144
+ if (is_summary) {
1145
+ stream << " [" << stmts.size ();
1146
+ if (stmts.size () == 1 ) {
1147
+ stream << " child]" ;
1148
+ } else {
1149
+ stream << " children]" ;
1150
+ }
1151
+ } else {
1152
+ for (const Stmt &s : stmts) {
1153
+ stream << " {\n " ;
1154
+ indent++;
1155
+ print (s);
1156
+ indent--;
1157
+ stream << get_indent () << " } " ;
1158
+ }
1159
+ stream << " \n " ;
1130
1160
}
1131
- stream << " \n " ;
1132
1161
}
1133
1162
1134
1163
void IRPrinter::visit (const IfThenElse *op) {
@@ -1209,32 +1238,43 @@ void IRPrinter::visit(const VectorReduce *op) {
1209
1238
}
1210
1239
1211
1240
void IRPrinter::visit (const Atomic *op) {
1241
+ stream << get_indent ();
1242
+
1212
1243
if (op->mutex_name .empty ()) {
1213
- stream << get_indent () << " atomic ("
1214
- << op->producer_name << " ) {\n " ;
1244
+ stream << " atomic (" << op->producer_name << " ) " ;
1215
1245
} else {
1216
- stream << get_indent () << " atomic ("
1217
- << op->producer_name << " , "
1218
- << op->mutex_name << " ) {\n " ;
1246
+ stream << " atomic (" << op->producer_name << " , " << op->mutex_name << " ) " ;
1219
1247
}
1220
- indent += 2 ;
1221
- print (op->body );
1222
- indent -= 2 ;
1223
- stream << get_indent () << " }\n " ;
1248
+
1249
+ print_braced_stmt (op->body );
1224
1250
}
1225
1251
1226
1252
void IRPrinter::visit (const HoistedStorage *op) {
1227
1253
if (op->name .empty ()) {
1228
- stream << get_indent () << " hoisted_storage { \n " ;
1254
+ stream << get_indent () << " hoisted_storage " ;
1229
1255
} else {
1230
- stream << get_indent () << " hoisted_storage (" ;
1231
- stream << op->name ;
1232
- stream << " ) {\n " ;
1256
+ stream << get_indent () << " hoisted_storage (" << op->name << " ) " ;
1233
1257
}
1234
- indent += 2 ;
1235
- print (op->body );
1236
- indent -= 2 ;
1237
- stream << get_indent () << " }\n " ;
1258
+
1259
+ print_braced_stmt (op->body );
1260
+ }
1261
+
1262
+ std::string lldb_string (const Expr &ir) {
1263
+ std::stringstream s{};
1264
+ IRPrinter p (s);
1265
+ p.print_no_parens (ir);
1266
+ return s.str ();
1267
+ }
1268
+
1269
+ std::string lldb_string (const Internal::BaseExprNode *n) {
1270
+ return lldb_string (Expr (n));
1271
+ }
1272
+
1273
+ std::string lldb_string (const Stmt &ir) {
1274
+ std::stringstream s{};
1275
+ IRPrinter p (s);
1276
+ p.print_summary (ir);
1277
+ return s.str ();
1238
1278
}
1239
1279
1240
1280
} // namespace Internal
0 commit comments