3 Commits

Author SHA1 Message Date
Bertik23
fc6ad39044
[AsmParser] Track value references and function arguments (#174566)
This PR is part of the LLVM IR LSP server project:
https://discourse.llvm.org/t/rfc-ir-visualization-with-vs-code-extension-using-an-lsp-server/87773

To be able to implement goto definition in LSP. One must first have to
know what values are referenced on what positions.
This PR implements a Location -> Value* map that allows looking up
values referenced on queried locations.

For example
```llvm
%inst = add i32 1, %arg
```
Querying on 0:20 (the location of %arg) would return the Value* of the
`%arg`.

`getInstuctionLocation(%arg)` would still return the definition of that
value

Tracking for function arguments was also added in the same fashion a
function/instruction/basic block location tracking.

The tests were also updated to test the new features a bit.
2026-02-02 11:21:45 +00:00
Bertik23
251724c25d
[AsmParser] Faster location -> value lookups (#172702)
Uses IntervalMap to make location -> value lookups faster.

Adds some tests with this feature.
2025-12-22 16:26:45 +00:00
Bertik23
18d4ba593d
[LLVM][IR] Add location tracking to LLVM IR parser (#155797)
This PR is part of the LLVM IR LSP server project
([RFC](https://discourse.llvm.org/t/rfc-ir-visualization-with-vs-code-extension-using-an-lsp-server/87773))

To be able to make a LSP server, it's crucial to have location
information about the LLVM objects (Functions, BasicBlocks and
Instructions).

This PR adds:
 * Position tracking to the Lexer
 * A new AsmParserContext class, to hold the new position info
 * Tests to check if the location is correct

The AsmParserContext can be passed as an optional parameter into the
parser. Which populates it and it can be then used by other tools, such
as the LSP server.

The AsmParserContext idea was borrowed from MLIR. As we didn't want to
store data no one else uses inside the objects themselves. But the
implementation is different, this class holds several maps of Functions,
BasicBlocks and Instructions, to map them to their location.

And some utility methods were added to get the positions of the
processed tokens.
2025-10-22 16:46:12 +02:00