{"id":19664849,"url":"https://github.com/fluxml/irtools.jl","last_synced_at":"2025-02-27T03:43:26.824Z","repository":{"id":38845388,"uuid":"146080152","full_name":"FluxML/IRTools.jl","owner":"FluxML","description":"Mike's Little Intermediate Representation","archived":false,"fork":false,"pushed_at":"2024-11-20T05:02:05.000Z","size":552,"stargazers_count":111,"open_issues_count":40,"forks_count":36,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-02-23T02:03:01.494Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Julia","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/FluxML.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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}},"created_at":"2018-08-25T08:44:46.000Z","updated_at":"2024-07-29T16:31:33.000Z","dependencies_parsed_at":"2023-10-17T04:46:31.788Z","dependency_job_id":"c11b897a-3391-43d7-93e1-94a67cdfd4bd","html_url":"https://github.com/FluxML/IRTools.jl","commit_stats":{"total_commits":285,"total_committers":17,"mean_commits":"16.764705882352942","dds":0.2315789473684211,"last_synced_commit":"8a6971e4a594d540a491cafa059942472dc86a26"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FluxML%2FIRTools.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FluxML%2FIRTools.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FluxML%2FIRTools.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FluxML%2FIRTools.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FluxML","download_url":"https://codeload.github.com/FluxML/IRTools.jl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240974465,"owners_count":19887302,"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":[],"created_at":"2024-11-11T16:19:16.765Z","updated_at":"2025-02-27T03:43:26.805Z","avatar_url":"https://github.com/FluxML.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IRTools\n\n[![Build Status](https://travis-ci.org/FluxML/IRTools.jl.svg?branch=master)](https://travis-ci.org/FluxML/IRTools.jl)\n[![Dev Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://fluxml.github.io/IRTools.jl/latest/)\n[![Coverage](https://codecov.io/gh/FluxML/IRTools.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/FluxML/IRTools.jl)\n\nIRTools aims to provide a simple and flexible IR format, expressive enough to work with both lowered and typed Julia code, as well as external IRs. It can be used with Julia metaprogramming tools such as [Cassette](https://github.com/jrevels/Cassette.jl).\n\n```julia\njulia\u003e using IRTools\n\njulia\u003e function pow(x, n) # A simple Julia function\n         r = 1\n         while n \u003e 0\n           n -= 1\n           r *= x\n         end\n         return r\n       end\n\njulia\u003e ir = @code_ir pow(1, 1) # Get its IR\n1: (%1, %2, %3)\n  br 2 (%3, 1)\n2: (%4, %5)\n  %6 = %4 \u003e 0\n  br 4 unless %6\n  br 3\n3:\n  %7 = %4 - 1\n  %8 = %5 * %2\n  br 2 (%7, %8)\n4:\n  return %5\n\njulia\u003e using IRTools: var, xcall\n\njulia\u003e ir[var(8)] = xcall(:+, var(5), var(2)) # Tweak it\n:(%5 + %2)\n\njulia\u003e ir\n1: (%1, %2, %3)\n  br 2 (%3, 1)\n2: (%4, %5)\n  %6 = %4 \u003e 0\n  br 4 unless %6\n  br 3\n3:\n  %7 = %4 - 1\n  %8 = %5 + %2\n  br 2 (%7, %8)\n4:\n  return %5\n\njulia\u003e f = IRTools.func(ir); # Turn the new IR into a lambda\n\njulia\u003e f(nothing, 10, 5)\n51\n\njulia\u003e @code_llvm f(nothing, 10, 5)\ndefine i64 @\"julia_##399_17438\"(i64, i64) {\ntop:\n     %2 = icmp slt i64 %1, 1\n     %3 = mul i64 %1, %0\n     %4 = add i64 %3, 1\n     %value_phi1.lcssa = select i1 %2, i64 1, i64 %4\n    ret i64 %value_phi1.lcssa\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluxml%2Firtools.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffluxml%2Firtools.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluxml%2Firtools.jl/lists"}