Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amrdeveloper/llql
LLQL is a tool that allow you to run SQL-like query with Pattern matching functions inspired by LLVM InstCombine Pattern Matchers on LLVM IR/Bitcode files
https://github.com/amrdeveloper/llql
bitcode code-analysis gitql gitql-sdk llvm llvm-ir pattern-matching
Last synced: 3 days ago
JSON representation
LLQL is a tool that allow you to run SQL-like query with Pattern matching functions inspired by LLVM InstCombine Pattern Matchers on LLVM IR/Bitcode files
- Host: GitHub
- URL: https://github.com/amrdeveloper/llql
- Owner: AmrDeveloper
- License: mit
- Created: 2024-10-21T17:15:51.000Z (2 months ago)
- Default Branch: master
- Last Pushed: 2024-10-31T19:15:00.000Z (about 2 months ago)
- Last Synced: 2024-10-31T19:56:12.379Z (about 2 months ago)
- Topics: bitcode, code-analysis, gitql, gitql-sdk, llvm, llvm-ir, pattern-matching
- Language: Rust
- Homepage: https://crates.io/crates/llql
- Size: 903 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
LLQL - LLVM IR/BC Query Language
LLQL is a tool that allow you to run SQL-like query with Pattern matching functions inspired by LLVM InstCombine Pattern Matchers on LLVM IR/BitCode files instead of database files using the GitQL SDK.
---
### Sample
If we have LLVM IR function like this, and we want to match `add` instruction that has result of sub instruction as Left hand side and result of mul instruction as Right hand side.
```ir
define i32 @function(i32 %a, i32 %b) {
%sub = sub i32 %a, %b
%mull = mul i32 %a, %b
%add = add i32 %sub, %mull
ret i32 %add
}
```We can query to print the instruction with this query
```sql
SELECT instruction FROM instructions WHERE m_inst(instruction, m_add(m_sub(), m_mul()))
```Or for example you can query how many times this pattern exists in each function
```sql
SELECT function_name, count() FROM instructions WHERE m_inst(instruction, m_add(m_sub(), m_mul())) GROUP BY function_name
```You can also filter by number of times the value is used for example for not used values
```IR
define i32 @function(i32 %a, i32 %b) {
%unused_add = add i32 %a, 1%used_twice = add i32 %a, %b
%add2 = add i32 %used_twice, %b
%add3 = add i32 %used_twice, %add2
ret i32 %add3
}
``````sql
SELECT instruction FROM instructions WHERE m_inst(instruction, m_unused(m_add()))
```and for value that used only time
```sql
SELECT instruction FROM instructions WHERE m_inst(instruction, m_has_one_use(m_add()))
```and for value that used n times
```sql
SELECT instruction FROM instructions WHERE m_inst(instruction, m_has_n_uses(m_add(), 2))
```---
### List of available functions
- [Instructions Matchers Functions](docs/InstructionMatcher.md)
- [Types Matchers functions](docs/TypeMatcher.md)---
### Tables structures
#### Instructions table
| Name | Type | Description |
| ---------------- | --------- | ------------------------------- |
| function_name | Text | Instruction function name |
| basic_block_name | Text | Basic block of this instruction |
| instruction | LLVMValue | LLVM Instruction |---
### Download or Install
Note that Building from source or installing from Cargo.io requires LibClang 16 to be installed
- Install from Cargo.io
```
cargo install llql
```- Build from source code
```
git clone https://github.com/AmrDeveloper/LLQL.git
cd LLQL
cargo build
```### Run LLQL
```
LLQL is a SQL like query language to run on LLVM IR/BitCode files
Usage: LLQL [OPTIONS]Options:
-f, --files Path for local files to run query on
-s, --script Script file contains one or more query
-q, --query LLQL query to run on selected files
-p, --pagination Enable print result with pagination
-ps, --pagesize Set pagination page size [default: 10]
-o, --output Set output format [render, json, csv]
-a, --analysis Print Query analysis
-e, --editor Enable GitQL LineEditor
-h, --help Print LLQL help
-v, --version Print LLQL Current Version
```### License
```
MIT LicenseCopyright (c) 2024 Amr Hesham
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```