21 Commits

Author SHA1 Message Date
S. VenkataKeerthy
61a45d20cf
[IR2Vec][NFC] Add helper methods for numeric ID mapping in Vocabulary (#149212)
Add helper methods to IR2Vec's Vocabulary class for numeric ID mapping and vocabulary size calculation. These APIs will be useful in triplet generation for `llvm-ir2vec` tool (See #149214). 

(Tracking issue - #141817)
2025-07-17 13:40:51 -07:00
S. VenkataKeerthy
fad0fbc937
[NFC][IR2Vec] Fix warnings on MSVC compilation (#148911) 2025-07-15 10:54:00 -07:00
S. VenkataKeerthy
ec90786ad1
[NFC][IR2Vec] Exposing helpers in IR2Vec Vocabulary (#147841)
Minor refactoring IR2Vec vocabulary. This would help in upcoming PRs related to the IR2Vec tool.

(Tracking issue - #141817)
2025-07-14 16:38:50 -07:00
S. VenkataKeerthy
8ae8b50d36
[NFC][IR2Vec] Minor refactoring of opcode access in vocabulary (#147585)
Refactored IR2Vec vocabulary handling to improve code organization and error handling. This would help in upcoming PRs related to the IR2Vec tool.

(Tracking issue - #141817)
2025-07-14 16:35:24 -07:00
Kazu Hirata
a73aa721d6 [Analysis] Fix a warning
This patch fixes:

  llvm/lib/Analysis/IR2Vec.cpp:280:3: error: default label in switch
  which covers all enumeration values
  [-Werror,-Wcovered-switch-default]
2025-07-14 13:18:52 -07:00
S. VenkataKeerthy
e86bd05bdc
[IR2Vec] Restructuring Vocabulary (#145119)
This PR restructures the vocabulary. 

* String based look-ups are removed. Vocabulary is changed from a map to vector. (#141832)
* Grouped all the vocabulary related methods under a single class - `ir2vec::Vocabulary`. This replaces `IR2VecVocabResult`.
* `ir2vec::Vocabulary` effectively abstracts out the _layout_ and other internal details of the vector structure. Exposes necessary APIs for accessing the Vocabulary. 

These changes ensure that _all_ known opcodes and types are present in the vocabulary. We have retained the original operands. This can be extended going forward. 

(Tracking issue - #141817)
2025-07-14 11:07:29 -07:00
S. VenkataKeerthy
119292c40b
[IR2Vec] Add out-of-place arithmetic operators to Embedding class (#145118)
This PR adds out-of-place arithmetic operators (`+`, `-`, `*`) to the `Embedding` class in IR2Vec, complementing the existing in-place operators (`+=`, `-=`, `*=`). 

Tests have been added to verify the functionality of these new operators.

(Tracking issue - #141817)
2025-07-01 12:09:54 -07:00
S. VenkataKeerthy
0a69c83421
[NFC][IR2Vec] Remove unreachable code and simplify invalid mode test (#146459)
The code following `llvm_unreachable`  is optimized out in Release builds. In this case, `Embedder::create` do not seem to return `nullptr` causing `CreateInvalidMode` test to break. Hence removing `llvm_unreachable`.
2025-06-30 20:31:47 -07:00
S. VenkataKeerthy
9438048816
[IR2Vec] Simplifying creation of Embedder (#143999)
This change simplifies the API by removing the error handling complexity. 

- Changed `Embedder::create()` to return `std::unique_ptr<Embedder>` directly instead of `Expected<std::unique_ptr<Embedder>>`
- Updated documentation and tests to reflect the new API
- Added death test for invalid IR2Vec kind in debug mode
- In release mode, simply returns nullptr for invalid kinds instead of creating an error

(Tracking issue - #141817)
2025-06-30 18:24:08 -07:00
Kazu Hirata
56739f5866 [Analysis] Fix a warning
This patch fixes:

  llvm/lib/Analysis/IR2Vec.cpp:296:2: error: extra ';' outside of a
  function is incompatible with C++98
  [-Werror,-Wc++98-compat-extra-semi]
2025-06-30 14:18:03 -07:00
S. VenkataKeerthy
0745eb501d
[IR2Vec] Scale embeddings once in vocab analysis instead of repetitive scaling (#143986)
Changes to scale opcodes, types and args once in `IR2VecVocabAnalysis` so that we can avoid scaling each time while computing embeddings. This PR refactors the vocabulary to explicitly define 3 sections---Opcodes, Types, and Arguments---used for computing Embeddings. 

(Tracking issue - #141817 ; partly fixes - #141832)
2025-06-30 23:09:19 +02:00
S. VenkataKeerthy
e29bb9a038
[IR2Vec] Consider only reachable BBs and non-debug instructions (#143476)
Changes to consider BBs that are reachable from the entry block. Similarly we skip debug instruction while computing the embeddings.

(Tracking issue - #141817)
2025-06-17 10:57:52 -07:00
S. VenkataKeerthy
09c54c2e9e
[IR2Vec] Minor vocab changes and exposing weights (#143200)
This PR changes some asserts in Vocab to hard checks that emit error and exposes flags and constructor to help in unit tests.

(Tracking issue - #141817)
2025-06-13 10:43:22 -07:00
S. VenkataKeerthy
32649e017e
[IR2Vec] Exposing Embedding as an data type wrapped around std::vector<double> (#143197)
Currently `Embedding` is `std::vector<double>`. This PR makes it a data type wrapped around `std::vector<double>` to overload basic arithmetic operators and expose comparison operations. It _simplifies_ the usage here and in the passes where operations on `Embedding` would be performed.

(Tracking issue - #141817)
2025-06-10 15:12:16 -07:00
S. VenkataKeerthy
741136a8ac
[NFC][IR2Vec] Removing Dimension from Embedder::Create (#142486)
This PR removes the necessity to know the dimension of the embeddings while invoking `Embedder::Create`. Having the `Dimension` parameter introduces complexities in downstream consumers. 

(Tracking issue - #141817)
2025-06-02 15:05:11 -07:00
S. VenkataKeerthy
494c82e709
[IR2Vec] Support for lazy computation of BB Embeddings (#142033)
This PR exposes interfaces to compute embeddings at BB level. This would be necessary for delta patching the embeddings in MLInliner (#141836).

(Tracking issue - #141817)
2025-05-29 15:29:55 -07:00
S. VenkataKeerthy
e74b45e078
[IR2Vec] Adding unit tests (#141873)
This PR adds unit tests for IR2Vec

(Tracking issue - #141817)
2025-05-29 13:35:29 -07:00
S. VenkataKeerthy
3581e9bb4c
[NFC][IR2Vec] Refactoring for Stateless Embedding Computation (#141811)
Currently, users have to invoke two APIs: `computeEmbeddings()` followed
by getters to access the embeddings. This PR refactors the code to
reduce this *stateful* access of APIs. Users can now directly invoke
getters; Internally, getters would compute the embeddings.
2025-05-28 12:19:02 -07:00
Kazu Hirata
0918361d8b
[Analysis] Remove unused includes (NFC) (#141319)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-05-23 23:59:56 -07:00
Kazu Hirata
30a9d9d25b [Analysis] Fix warnings
This patch fixes:

  llvm/lib/Analysis/IR2Vec.cpp:76:3: error: default label in switch
  which covers all enumeration values
  [-Werror,-Wcovered-switch-default]

  llvm/lib/Analysis/IR2Vec.cpp:218:12: error: unused variable 'Dim'
  [-Werror,-Wunused-variable]
2025-05-22 10:12:25 -07:00
S. VenkataKeerthy
58ab005d8d
Adding IR2Vec as an analysis pass (#134004)
This PR introduces IR2Vec as an analysis pass. The changes include:
- Logic for generating Symbolic encodings.
- 75D learned vocabulary.
- lit tests.

Here is the link to the RFC -
https://discourse.llvm.org/t/rfc-enhancing-mlgo-inlining-with-ir2vec-embeddings

Acknowledgements: contributors -
https://github.com/IITH-Compilers/IR2Vec/graphs/contributors

---------

Co-authored-by: svkeerthy <venkatakeerthy@google.com>
Co-authored-by: Mircea Trofin <mtrofin@google.com>
2025-05-22 09:50:21 -07:00