[all-commits] [llvm/llvm-project] 82f7d3: [RFC] [IR] Modules can make filtered range to iter...

Peter Rong via All-commits all-commits at lists.llvm.org
Fri Dec 5 09:42:33 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 82f7d3c7660c9edb871858e066a78b504a74404b
      https://github.com/llvm/llvm-project/commit/82f7d3c7660c9edb871858e066a78b504a74404b
  Author: Peter Rong <peterrong96 at gmail.com>
  Date:   2025-12-05 (Fri, 05 Dec 2025)

  Changed paths:
    M llvm/include/llvm/IR/Module.h
    M llvm/tools/llvm-ir2vec/llvm-ir2vec.cpp
    M llvm/unittests/IR/ModuleTest.cpp

  Log Message:
  -----------
  [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.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list