{"id":18106723,"url":"https://github.com/amrdeveloper/llql","last_synced_at":"2025-04-06T15:12:22.706Z","repository":{"id":260520650,"uuid":"876265794","full_name":"AmrDeveloper/LLQL","owner":"AmrDeveloper","description":"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","archived":false,"fork":false,"pushed_at":"2025-03-21T21:20:24.000Z","size":1673,"stargazers_count":50,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T15:12:16.016Z","etag":null,"topics":["bitcode","code-analysis","gitql","gitql-sdk","llvm","llvm-ir","pattern-matching"],"latest_commit_sha":null,"homepage":"https://amrdeveloper.github.io/LLQL/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AmrDeveloper.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"amrdeveloper"}},"created_at":"2024-10-21T17:15:51.000Z","updated_at":"2025-03-21T21:19:44.000Z","dependencies_parsed_at":"2024-10-31T19:56:14.995Z","dependency_job_id":"c8c9a265-c9c2-4fb6-8d07-c948769580b0","html_url":"https://github.com/AmrDeveloper/LLQL","commit_stats":{"total_commits":77,"total_committers":1,"mean_commits":77.0,"dds":0.0,"last_synced_commit":"103014d3c5fceb9a29022b78fdb79cfbf5e57bdd"},"previous_names":["amrdeveloper/llql"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmrDeveloper%2FLLQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmrDeveloper%2FLLQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmrDeveloper%2FLLQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmrDeveloper%2FLLQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AmrDeveloper","download_url":"https://codeload.github.com/AmrDeveloper/LLQL/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247500468,"owners_count":20948880,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcode","code-analysis","gitql","gitql-sdk","llvm","llvm-ir","pattern-matching"],"created_at":"2024-10-31T23:07:50.343Z","updated_at":"2025-04-06T15:12:22.678Z","avatar_url":"https://github.com/AmrDeveloper.png","language":"Rust","funding_links":["https://github.com/sponsors/amrdeveloper"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eLLQL - LLVM IR/BC Query Language\u003c/h1\u003e\u003c/br\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"media/llql_logo.svg\" width=\"20%\" height=\"20%\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"Crates.io\" src=\"https://img.shields.io/crates/v/llql?style=flat-square\"\u003e\n  \u003cimg alt=\"Deps\" src=\"https://deps.rs/repo/github/amrdeveloper/llql/status.svg\"\u003e\n  \u003cimg alt=\"Docs\" src=\"https://github.com/AmrDeveloper/GQL/actions/workflows/docs.yaml/badge.svg\"\u003e\n  \u003cimg alt=\"GitHub issues\" src=\"https://img.shields.io/github/issues/amrdeveloper/llql\"\u003e\n  \u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/amrdeveloper/llql\"\u003e\n  \u003cimg alt=\"GitHub release\" src=\"https://img.shields.io/github/v/release/amrdeveloper/llql\"\u003e\n  \u003cimg all=\"Crates.io\" src=\"https://img.shields.io/crates/d/llql?label=Crates.io%20Downloads\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\nLLQL 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.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"media/llql_demo.png\" alt=\"animated\" width=\"100%\"/\u003e\n\u003c/p\u003e\n\n---\n\n### Sample\n\nYou can search for missing optimizaitons patterns for example\n\n```SQL\n-- trunc (binop (Y, (ext X))) --\u003e binop ((trunc Y), X)\nSELECT instruction AS \"Missing Optimization: trunc (binop (Y, (ext X))) --\u003e binop ((trunc Y), X)\"\nFROM instructions WHERE m_inst(instruction, m_trunc(m_binop(m_any_inst(), m_zext() || m_sext())));\n\n-- trunc (binop (ext X), Y) --\u003e binop X, (trunc Y)\nSELECT instruction AS \"Missing Optimization: trunc (binop (ext X), Y) --\u003e binop X, (trunc Y)\"\nFROM instructions WHERE m_inst(instruction, m_trunc(m_binop(m_zext() || m_sext())));\n```\n\nIf 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.\n\n```llvm\ndefine i32 @function(i32 %a, i32 %b) {\n  %sub = sub i32 %a, %b\n  %mull = mul i32 %a, %b\n  %add = add i32 %sub, %mull\n  ret i32 %add\n}\n```\n\nWe can query to print the instruction with this query\n\n```sql\nSELECT instruction FROM instructions WHERE m_inst(instruction, m_add(m_sub(), m_mul()))\n```\n\nOr for example you can query how many times this pattern exists in each function\n\n```sql\nSELECT function_name, count() FROM instructions WHERE m_inst(instruction, m_add(m_sub(), m_mul())) GROUP BY function_name\n```\n\nYou can also filter by number of times the value is used for example for not used values\n\n```llvm\ndefine i32 @function(i32 %a, i32 %b) {\n  %unused_add = add i32 %a, 1\n\n  %used_twice = add i32 %a, %b\n  %add2 = add i32 %used_twice, %b\n  %add3 = add i32 %used_twice, %add2\n  ret i32 %add3\n}\n```\n\n```sql\nSELECT instruction FROM instructions WHERE m_inst(instruction, m_unused(m_add()))\n```\n\nand for value that used only time\n\n```sql\nSELECT instruction FROM instructions WHERE m_inst(instruction, m_has_one_use(m_add()))\n```\n\nand for value that used n times\n\n```sql\nSELECT instruction FROM instructions WHERE m_inst(instruction, m_has_n_uses(m_add(), 2))\n```\n\n---\n\n### Download or Install\n\nNote that Building from source or installing from Cargo.io requires LibClang 18.0 to be installed\n\n- Install from Cargo.io\n\n```\ncargo install llql\n```\n\n- Build from source code\n\n```\ngit clone https://github.com/AmrDeveloper/LLQL.git\ncd LLQL\ncargo build\n```\n\n### Run LLQL\n\n```\nLLQL is a SQL like query language to run on LLVM IR/BitCode files\nUsage: LLQL [OPTIONS]\n\nOptions:\n  -f,  --files \u003cpaths\u003e        Path for local files to run query on\n  -s,  --script \u003cfile\u003e        Script file contains one or more query\n  -q,  --query \u003cGQL Query\u003e    LLQL query to run on selected files\n  -p,  --pagination           Enable print result with pagination\n  -ps, --pagesize             Set pagination page size [default: 10]\n  -o,  --output               Set output format [render, json, csv]\n  -a,  --analysis             Print Query analysis\n  -e,  --editor               Enable GitQL LineEditor\n  -h,  --help                 Print LLQL help\n  -v,  --version              Print LLQL Current Version\n```\n\n### License\n\n```\nMIT License\n\nCopyright (c) 2024 - 2025 Amr Hesham\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famrdeveloper%2Fllql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famrdeveloper%2Fllql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famrdeveloper%2Fllql/lists"}