#llvm #llvm-ir #bitcode #language #git-ql

app llql

A tool to run SQL-like query on your LLVM IR or Bitcode files

1 unstable release

new 0.1.0 Oct 31, 2024

#243 in Command line utilities

Download history 78/week @ 2024-10-26

79 downloads per month

MIT license

135KB
3.5K SLoC

LLQL - LLVM IR/BC Query Language


Crates.io Deps GitHub issues GitHub

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.

animated


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.

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

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

SELECT function_name, count() FROM instructions WHERE m_inst(instruction, m_add(m_sub(), m_mul())) GROUP BY function_name

List of available functions


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 <paths>        Path for local files to run query on
  -q,  --query <GQL 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 License

Copyright (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.

Dependencies

~11–23MB
~317K SLoC