@@ -1237,6 +1237,92 @@ void ir_build_def_use_lists(ir_ctx *ctx)
1237
1237
}
1238
1238
#endif
1239
1239
1240
+ void ir_use_list_remove_all (ir_ctx * ctx , ir_ref from , ir_ref ref )
1241
+ {
1242
+ ir_ref j , n , * p , * q , use ;
1243
+ ir_use_list * use_list = & ctx -> use_lists [from ];
1244
+ ir_ref skip = 0 ;
1245
+
1246
+ n = use_list -> count ;
1247
+ for (j = 0 , p = q = & ctx -> use_edges [use_list -> refs ]; j < n ; j ++ , p ++ ) {
1248
+ use = * p ;
1249
+ if (use == ref ) {
1250
+ skip ++ ;
1251
+ } else {
1252
+ if (p != q ) {
1253
+ * q = use ;
1254
+ }
1255
+ q ++ ;
1256
+ }
1257
+ }
1258
+ if (skip ) {
1259
+ use_list -> count -= skip ;
1260
+ do {
1261
+ * q = IR_UNUSED ;
1262
+ q ++ ;
1263
+ } while (-- skip );
1264
+ }
1265
+ }
1266
+
1267
+ void ir_use_list_remove_one (ir_ctx * ctx , ir_ref from , ir_ref ref )
1268
+ {
1269
+ ir_ref j , n , * p ;
1270
+ ir_use_list * use_list = & ctx -> use_lists [from ];
1271
+
1272
+ n = use_list -> count ;
1273
+ j = 0 ;
1274
+ p = & ctx -> use_edges [use_list -> refs ];
1275
+ while (j < n ) {
1276
+ if (* p == ref ) {
1277
+ use_list -> count -- ;
1278
+ j ++ ;
1279
+ while (j < n ) {
1280
+ * p = * (p + 1 );
1281
+ p ++ ;
1282
+ j ++ ;
1283
+ }
1284
+ * p = IR_UNUSED ;
1285
+ break ;
1286
+ }
1287
+ j ++ ;
1288
+ }
1289
+ }
1290
+
1291
+ void ir_use_list_replace (ir_ctx * ctx , ir_ref ref , ir_ref use , ir_ref new_use )
1292
+ {
1293
+ ir_use_list * use_list = & ctx -> use_lists [ref ];
1294
+ ir_ref i , n , * p ;
1295
+
1296
+ n = use_list -> count ;
1297
+ for (i = 0 , p = & ctx -> use_edges [use_list -> refs ]; i < n ; i ++ , p ++ ) {
1298
+ if (* p == use ) {
1299
+ * p = new_use ;
1300
+ break ;
1301
+ }
1302
+ }
1303
+ }
1304
+
1305
+ bool ir_use_list_add (ir_ctx * ctx , ir_ref to , ir_ref ref )
1306
+ {
1307
+ ir_use_list * use_list = & ctx -> use_lists [to ];
1308
+ ir_ref n = use_list -> refs + use_list -> count ;
1309
+
1310
+ if (n < ctx -> use_edges_count && ctx -> use_edges [n ] == IR_UNUSED ) {
1311
+ ctx -> use_edges [n ] = ref ;
1312
+ use_list -> count ++ ;
1313
+ return 0 ;
1314
+ } else {
1315
+ /* Reallocate the whole edges buffer (this is inefficient) */
1316
+ ctx -> use_edges = ir_mem_realloc (ctx -> use_edges , (ctx -> use_edges_count + use_list -> count + 1 ) * sizeof (ir_ref ));
1317
+ memcpy (ctx -> use_edges + ctx -> use_edges_count , ctx -> use_edges + use_list -> refs , use_list -> count * sizeof (ir_ref ));
1318
+ use_list -> refs = ctx -> use_edges_count ;
1319
+ ctx -> use_edges [use_list -> refs + use_list -> count ] = ref ;
1320
+ use_list -> count ++ ;
1321
+ ctx -> use_edges_count += use_list -> count ;
1322
+ return 1 ;
1323
+ }
1324
+ }
1325
+
1240
1326
/* Helper Data Types */
1241
1327
void ir_array_grow (ir_array * a , uint32_t size )
1242
1328
{
0 commit comments