Skip to content

Repository files navigation

IR-Regex


Image

Crates.io Deps GitHub issues GitHub GitHub release Image

A parallel regular expressions engine for LLVM IR that uses non-deterministic finite automaton (NFA). and LLVM Opcode as Symbol that match inputs in parallel on functions and instructions levels.

This project started with the question, Can't we replace the symbol in the finite automata transation with LLVM Opcode? 🤔

animated

Running on large input file (Around 16k LoC). animated


Install and run IR-Regex

  • Install:
    • cargo install ir-regex
  • Run:
    • ir-regex pattern file_path
      • Example: ir-regex "(add|sub)*" input.ll

The Regular Language

Symbols

  • alloca, load, store
  • add, sub, mul, sdiv, udiv, srem, urem
  • fadd, fsub, fmul, fdiv, fneg, frem
  • shl, ashr, lshr
  • icmp, fcmp
  • or, and, xor
  • call, callbr, invoke
  • select, switch, gep, phi
  • sext, zext, Trunc, FPTrunc
  • br, indirectbr
  • resume, return, unreachable

Operators

  • Choice: |
  • Grouping: (...)
  • Repetition: *

Example:

  • (add|sub)*
    • Will match a sequence of add or sub instructions.

License

MIT License

Copyright (c) 2026 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.

About

A parallel regular expressions engine for LLVM IR that uses non-deterministic finite automaton (NFA)

Topics

Resources

Code of conduct

Contributing

Stars

8 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages