Commit 82f7d3c
authored
[RFC] [IR] Modules can make filtered range to iterate function definitions only (#167972)
We often wish to iterate over all function definitions in a module for
transformations.
Such API doesn't exists yet, so what people normally used is to iterate
over all functions and skip the declarations:
```cpp
for (auto& F: M) {
if (F.isDeclaration()) continue;
}
```
A regex search of the following pattern shows 100+ hits inside llvm, let
along other patterns, e.g. collect all definitions in a module into a
worklist.
```
for \(.*F.*\).*\n.*if \(F.isDeclaration\(\)\).*\n.*continue;
```
This pattern is verbose and hard to review in a long loop.
As an alternative, this patch provides a new API that iterates over
definitions only.
Tests:
1. Added unit test
2. Touching @svkeerthy 's tool (also to show the cleanness of the new
API).
Note: `function_definitions` seems a bit long, I'm open to suggestions
to other names.1 parent b360a78 commit 82f7d3c
File tree
3 files changed
+92
-9
lines changed- llvm
- include/llvm/IR
- tools/llvm-ir2vec
- unittests/IR
3 files changed
+92
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
710 | 710 | | |
711 | 711 | | |
712 | 712 | | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
713 | 724 | | |
714 | 725 | | |
715 | 726 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
398 | | - | |
399 | | - | |
400 | | - | |
| 398 | + | |
401 | 399 | | |
402 | 400 | | |
403 | 401 | | |
| |||
431 | 429 | | |
432 | 430 | | |
433 | 431 | | |
434 | | - | |
435 | | - | |
436 | | - | |
| 432 | + | |
437 | 433 | | |
438 | 434 | | |
439 | 435 | | |
| |||
532 | 528 | | |
533 | 529 | | |
534 | 530 | | |
535 | | - | |
536 | | - | |
537 | | - | |
| 531 | + | |
538 | 532 | | |
539 | 533 | | |
540 | 534 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
433 | 433 | | |
434 | 434 | | |
435 | 435 | | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
436 | 514 | | |
0 commit comments