diff --git a/.github/actions/install-linux-deps/action.yml b/.github/actions/install-linux-deps/action.yml index e827acdaaa..cc2ab179ee 100644 --- a/.github/actions/install-linux-deps/action.yml +++ b/.github/actions/install-linux-deps/action.yml @@ -25,7 +25,7 @@ runs: - name: Add LLVM Debian repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Update and upgrade APT @@ -33,4 +33,4 @@ runs: run: sudo apt-get update && sudo apt-get upgrade -y - name: Install LLVM shell: bash - run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools + run: sudo apt-get install llvm-20 llvm-20-dev llvm-20-runtime clang-20 clang-tools-20 lld-20 libpolly-20-dev libmlir-20-dev mlir-20-tools diff --git a/.github/workflows/bench-hyperfine.yml b/.github/workflows/bench-hyperfine.yml index b4dbd4a960..e975b30d8d 100644 --- a/.github/workflows/bench-hyperfine.yml +++ b/.github/workflows/bench-hyperfine.yml @@ -19,9 +19,9 @@ jobs: runs-on: ubuntu-24.04 env: CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse - MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ - TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ - LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ + MLIR_SYS_200_PREFIX: /usr/lib/llvm-20/ + TABLEGEN_200_PREFIX: /usr/lib/llvm-20/ + LLVM_SYS_201_PREFIX: /usr/lib/llvm-20/ steps: - uses: actions/checkout@v4 - name: check and free hdd space left @@ -50,11 +50,11 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM - run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools + run: sudo apt-get install llvm-20 llvm-20-dev llvm-20-runtime clang-20 clang-tools-20 lld-20 libpolly-20-dev libmlir-20-dev mlir-20-tools - name: Install hyperfine uses: taiki-e/install-action@v2 with: @@ -85,9 +85,9 @@ jobs: build-binaries: env: - MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ - LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ - TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ + MLIR_SYS_200_PREFIX: /usr/lib/llvm-20/ + LLVM_SYS_201_PREFIX: /usr/lib/llvm-20/ + TABLEGEN_200_PREFIX: /usr/lib/llvm-20/ RUST_LOG: cairo_native=debug,cairo_native_test=debug strategy: matrix: @@ -129,12 +129,12 @@ jobs: if: ${{ steps.cache-binary.outputs.cache-hit != 'true' || steps.cache-library.outputs.cache-hit != 'true' }} uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM if: ${{ steps.cache-binary.outputs.cache-hit != 'true' || steps.cache-library.outputs.cache-hit != 'true' }} - run: sudo apt-get update && sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools + run: sudo apt-get update && sudo apt-get install llvm-20 llvm-20-dev llvm-20-runtime clang-20 clang-tools-20 lld-20 libpolly-20-dev libmlir-20-dev mlir-20-tools - name: Checkout base commit if: ${{ steps.cache-binary.outputs.cache-hit != 'true' || steps.cache-library.outputs.cache-hit != 'true' }} @@ -155,9 +155,9 @@ jobs: run-bench: env: - MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ - LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ - TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ + MLIR_SYS_200_PREFIX: /usr/lib/llvm-20/ + LLVM_SYS_201_PREFIX: /usr/lib/llvm-20/ + TABLEGEN_200_PREFIX: /usr/lib/llvm-20/ RUST_LOG: cairo_native=debug,cairo_native_test=debug strategy: matrix: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c7ab266fe3..e6186bd16f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,9 +16,9 @@ jobs: name: clippy runs-on: ubuntu-24.04 env: - MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ - LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ - TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ + MLIR_SYS_200_PREFIX: /usr/lib/llvm-20/ + LLVM_SYS_201_PREFIX: /usr/lib/llvm-20/ + TABLEGEN_200_PREFIX: /usr/lib/llvm-20/ steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@1.84.1 @@ -28,11 +28,11 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM - run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools + run: sudo apt-get install llvm-20 llvm-20-dev llvm-20-runtime clang-20 clang-tools-20 lld-20 libpolly-20-dev libmlir-20-dev mlir-20-tools - name: Clippy run: make check @@ -83,9 +83,9 @@ jobs: udeps: runs-on: ubuntu-24.04 env: - MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ - LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ - TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ + MLIR_SYS_200_PREFIX: /usr/lib/llvm-20/ + LLVM_SYS_201_PREFIX: /usr/lib/llvm-20/ + TABLEGEN_200_PREFIX: /usr/lib/llvm-20/ steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master @@ -96,11 +96,11 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM - run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools + run: sudo apt-get install llvm-20 llvm-20-dev llvm-20-runtime clang-20 clang-tools-20 lld-20 libpolly-20-dev libmlir-20-dev mlir-20-tools - name: Machete uses: bnjbvr/cargo-machete@main @@ -108,9 +108,9 @@ jobs: name: test (linux, amd64) runs-on: ubuntu-24.04 env: - MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ - LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ - TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ + MLIR_SYS_200_PREFIX: /usr/lib/llvm-20/ + LLVM_SYS_201_PREFIX: /usr/lib/llvm-20/ + TABLEGEN_200_PREFIX: /usr/lib/llvm-20/ RUST_LOG: cairo_native=debug,cairo_native_test=debug steps: - uses: actions/checkout@v4 @@ -140,12 +140,12 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - run: sudo apt-get update && sudo apt-get upgrade -y - name: Install LLVM - run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools + run: sudo apt-get install llvm-20 llvm-20-dev llvm-20-runtime clang-20 clang-tools-20 lld-20 libpolly-20-dev libmlir-20-dev mlir-20-tools - name: Install deps run: make deps - name: test @@ -159,9 +159,9 @@ jobs: env: CARGO_TERM_COLOR: always LIBRARY_PATH: /opt/homebrew/lib - MLIR_SYS_190_PREFIX: /opt/homebrew/opt/llvm@19 - LLVM_SYS_191_PREFIX: /opt/homebrew/opt/llvm@19 - TABLEGEN_190_PREFIX: /opt/homebrew/opt/llvm@19 + MLIR_SYS_200_PREFIX: /opt/homebrew/opt/llvm@20 + LLVM_SYS_201_PREFIX: /opt/homebrew/opt/llvm@20 + TABLEGEN_200_PREFIX: /opt/homebrew/opt/llvm@20 RUST_LOG: cairo_native=debug,cairo_native_test=debug steps: - uses: actions/checkout@v4 @@ -199,9 +199,9 @@ jobs: - partition: 4 output: lcov-4.info env: - MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ - LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ - TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ + MLIR_SYS_200_PREFIX: /usr/lib/llvm-20/ + LLVM_SYS_201_PREFIX: /usr/lib/llvm-20/ + TABLEGEN_200_PREFIX: /usr/lib/llvm-20/ RUST_LOG: cairo_native=debug steps: - uses: actions/checkout@v4 @@ -231,11 +231,11 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM - run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools + run: sudo apt-get install llvm-20 llvm-20-dev llvm-20-runtime clang-20 clang-tools-20 lld-20 libpolly-20-dev libmlir-20-dev mlir-20-tools - name: Install testing tools uses: taiki-e/install-action@v2 with: diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 301a69b253..ad34263252 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -12,9 +12,9 @@ jobs: run: runs-on: ubuntu-latest env: - LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ - MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ - TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ + LLVM_SYS_201_PREFIX: /usr/lib/llvm-20/ + MLIR_SYS_200_PREFIX: /usr/lib/llvm-20/ + TABLEGEN_200_PREFIX: /usr/lib/llvm-20/ RPC_ENDPOINT_TESTNET: ${{ secrets.RPC_ENDPOINT_TESTNET }} RPC_ENDPOINT_MAINNET: ${{ secrets.RPC_ENDPOINT_MAINNET }} strategy: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cb8d100e50..8395334e45 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,9 +13,9 @@ jobs: release: runs-on: ubuntu-24.04 env: - MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ - LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ - TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ + MLIR_SYS_200_PREFIX: /usr/lib/llvm-20/ + LLVM_SYS_201_PREFIX: /usr/lib/llvm-20/ + TABLEGEN_200_PREFIX: /usr/lib/llvm-20/ CRATES_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} steps: - name: Checkout @@ -32,11 +32,11 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM - run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools + run: sudo apt-get install llvm-20 llvm-20-dev llvm-20-runtime clang-20 clang-tools-20 lld-20 libpolly-20-dev libmlir-20-dev mlir-20-tools - name: publish sierra emu run: cargo publish --token ${CRATES_TOKEN} --all-features -p sierra-emu - name: publish cairo native diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a92cb2bee2..a0e88e4b23 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,18 +27,18 @@ jobs: include: - target: x86_64-unknown-linux-gnu os: ubuntu-24.04 - dep_base_dir: /usr/lib/llvm-19 + dep_base_dir: /usr/lib/llvm-20 - target: x86_64-apple-darwin os: macos-14 - dep_base_dir: /opt/homebrew/opt/llvm@19 + dep_base_dir: /opt/homebrew/opt/llvm@20 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Set env run: | - echo "MLIR_SYS_190_PREFIX=${{ matrix.dep_base_dir }}" >> $GITHUB_ENV - echo "LLVM_SYS_191_PREFIX=${{ matrix.dep_base_dir }}" >> $GITHUB_ENV - echo "TABLEGEN_190_PREFIX=${{ matrix.dep_base_dir }}" >> $GITHUB_ENV + echo "MLIR_SYS_200_PREFIX=${{ matrix.dep_base_dir }}" >> $GITHUB_ENV + echo "LLVM_SYS_201_PREFIX=${{ matrix.dep_base_dir }}" >> $GITHUB_ENV + echo "TABLEGEN_200_PREFIX=${{ matrix.dep_base_dir }}" >> $GITHUB_ENV - name: Install deps # deps-ci-linux does nothing on macos so it works run: make deps && make deps-ci-linux diff --git a/.github/workflows/rustdoc.yml b/.github/workflows/rustdoc.yml index bef3d3ebf6..0e4516817f 100644 --- a/.github/workflows/rustdoc.yml +++ b/.github/workflows/rustdoc.yml @@ -13,9 +13,9 @@ jobs: name: GitHub Pages runs-on: ubuntu-24.04 env: - MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ - LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ - TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ + MLIR_SYS_200_PREFIX: /usr/lib/llvm-20/ + LLVM_SYS_201_PREFIX: /usr/lib/llvm-20/ + TABLEGEN_200_PREFIX: /usr/lib/llvm-20/ steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@1.84.1 @@ -23,11 +23,11 @@ jobs: - name: add llvm deb repository uses: myci-actions/add-deb-repo@11 with: - repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-19 main + repo: deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-20 main repo-name: llvm-repo keys-asc: https://apt.llvm.org/llvm-snapshot.gpg.key - name: Install LLVM - run: sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools + run: sudo apt-get install llvm-20 llvm-20-dev llvm-20-runtime clang-20 clang-tools-20 lld-20 libpolly-20-dev libmlir-20-dev mlir-20-tools - name: Build docs run: make doc - name: Deploy Documentation diff --git a/.github/workflows/starknet-blocks.yml b/.github/workflows/starknet-blocks.yml index 8d18fddc57..da7a54ee05 100644 --- a/.github/workflows/starknet-blocks.yml +++ b/.github/workflows/starknet-blocks.yml @@ -11,9 +11,9 @@ jobs: name: Run Blocks runs-on: ubuntu-latest env: - MLIR_SYS_190_PREFIX: /usr/lib/llvm-19/ - LLVM_SYS_191_PREFIX: /usr/lib/llvm-19/ - TABLEGEN_190_PREFIX: /usr/lib/llvm-19/ + MLIR_SYS_200_PREFIX: /usr/lib/llvm-20/ + LLVM_SYS_201_PREFIX: /usr/lib/llvm-20/ + TABLEGEN_200_PREFIX: /usr/lib/llvm-20/ RPC_ENDPOINT_TESTNET: ${{ secrets.RPC_ENDPOINT_TESTNET }} RPC_ENDPOINT_MAINNET: ${{ secrets.RPC_ENDPOINT_MAINNET }} strategy: @@ -32,8 +32,8 @@ jobs: with: repository: lambdaclass/starknet-replay path: starknet-replay - # https://github.com/lambdaclass/starknet-replay/pull/185 - ref: 9b9d486bdf9173a2bfd90d78f43ffb0ca2d27fcc + # https://github.com/lambdaclass/starknet-replay/pull/189 + ref: 01d3161c40379764c19e7dbcdfe01fb683b7edf6 # We need native to use the linux deps ci action - name: Checkout Native uses: actions/checkout@v4 @@ -44,8 +44,8 @@ jobs: with: repository: lambdaclass/sequencer path: sequencer - # https://github.com/lambdaclass/sequencer/pull/73 - ref: fe5d445ad6da8bbbd82b044e9115add4aea910af + # https://github.com/lambdaclass/sequencer/pull/75 + ref: 976f19b8304350290b761ed3448b8fdb8a620b0c - name: Cache RPC Calls uses: actions/cache@v4.2.0 with: diff --git a/Cargo.lock b/Cargo.lock index cced9cb579..6ed2628ad5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -777,7 +777,7 @@ dependencies = [ "anyhow", "cairo-lang-utils", "const-fnv1a-hash", - "convert_case 0.8.0", + "convert_case", "derivative", "itertools 0.14.0", "lalrpop", @@ -924,7 +924,7 @@ dependencies = [ "cairo-lang-sierra", "cairo-lang-sierra-to-casm", "cairo-lang-utils", - "convert_case 0.8.0", + "convert_case", "itertools 0.14.0", "num-bigint", "num-integer", @@ -1365,9 +1365,9 @@ dependencies = [ [[package]] name = "comrak" -version = "0.33.0" +version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39bff2cbb80102771ca62bd2375bc6f6611dc1493373440b23aa08a155538708" +checksum = "2a4f05e73ca9a30af27bebc13600f91fd1651b2ec7d139ca82a89df7ca583af1" dependencies = [ "caseless", "entities", @@ -1435,15 +1435,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "convert_case" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb402b8d4c85569410425650ce3eddc7d698ed96d39a73f941b08fb63082f1e7" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "convert_case" version = "0.8.0" @@ -2330,9 +2321,9 @@ checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" [[package]] name = "llvm-sys" -version = "191.0.0" +version = "201.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "893cddf1adf0354b93411e413553dd4daf5c43195d73f1acfa1e394bdd371456" +checksum = "9bb947e8b79254ca10d496d0798a9ba1287dcf68e50a92b016fec1cc45bef447" dependencies = [ "anyhow", "cc", @@ -2388,9 +2379,9 @@ dependencies = [ [[package]] name = "melior" -version = "0.21.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2af6454b7bcd7edc8c2060a3726a18ceaed60e25c34d9f8de9c6b44e82eb647" +checksum = "8a965d90213b0759491eeff1a94a3daf3c87918b13d2411227c1be8c26df6293" dependencies = [ "melior-macro", "mlir-sys", @@ -2398,12 +2389,12 @@ dependencies = [ [[package]] name = "melior-macro" -version = "0.14.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a99671327250df8e24e56d8304474a970e7a2c6bb8f6dc71382d188136fe4d1b" +checksum = "49d9020b35c25d0f40d125e660386b6a374a9f79285d58f67eb8301b9509e6ef" dependencies = [ "comrak", - "convert_case 0.7.1", + "convert_case", "proc-macro2", "quote", "regex", @@ -2445,9 +2436,9 @@ dependencies = [ [[package]] name = "mlir-sys" -version = "0.4.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee4047ffefa7e9853412025a98b38a66968584543918cf084a6e4df9144b71b" +checksum = "8e9348dd263d2680d657635d9dd084cdcd785d7486a41332ffa4c926d5882b54" dependencies = [ "bindgen", ] @@ -3624,9 +3615,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tblgen" -version = "0.5.2" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c155c9310c9e11e6f642b4c8a30ae572ea0cad013d5c9e28bb264b52fa8163bb" +checksum = "836472eafcc544aa0167f880c0998d4a77b422d22100186e67fc6daf35cab94c" dependencies = [ "bindgen", "cc", diff --git a/Cargo.toml b/Cargo.toml index b6d861708d..ca374c359e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,9 +83,9 @@ educe = "0.5.11" # can't update until https://github.com/magiclen/educe/issues/2 itertools = "0.14.0" lazy_static = "1.5" libc = "0.2" -llvm-sys = "191.0.0" -melior = { version = "0.21.0", features = ["ods-dialects", "helpers"] } -mlir-sys = { version = "0.4.1" } +llvm-sys = "201.0.1" +melior = { version = "0.23.0", features = ["ods-dialects", "helpers"] } +mlir-sys = { version = "0.5.0" } num-bigint.workspace = true num-traits.workspace = true starknet-types-core = { workspace = true, default-features = false, features = [ diff --git a/Dockerfile b/Dockerfile index 24c5c73a98..9e6b006f9e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,15 +10,15 @@ RUN apt update -y && apt install -y lsb-release \ libz-dev \ libzstd-dev -# Install LLVM 19 -RUN echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-19 main" > /etc/apt/sources.list.d/llvm-19.list -RUN echo "deb-src http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-19 main" >> /etc/apt/sources.list.d/llvm-19.list +# Install LLVM 20 +RUN echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-20 main" > /etc/apt/sources.list.d/llvm-20.list +RUN echo "deb-src http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-20 main" >> /etc/apt/sources.list.d/llvm-20.list RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - RUN apt update -y && apt install -y \ - libmlir-19-dev \ - libpolly-19-dev \ - llvm-19-dev \ - mlir-19-tools + libmlir-20-dev \ + libpolly-20-dev \ + llvm-20-dev \ + mlir-20-tools # Install rust RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y @@ -29,8 +29,8 @@ COPY . /cairo_native/ # Compile cairo_native WORKDIR /cairo_native/ -ENV MLIR_SYS_190_PREFIX=/usr/lib/llvm-19 -ENV LLVM_SYS_191_PREFIX=/usr/lib/llvm-19 -ENV TABLEGEN_190_PREFIX=/usr/lib/llvm-19 +ENV MLIR_SYS_200_PREFIX=/usr/lib/llvm-20 +ENV LLVM_SYS_201_PREFIX=/usr/lib/llvm-20 +ENV TABLEGEN_200_PREFIX=/usr/lib/llvm-20 RUN make deps RUN make build diff --git a/Makefile b/Makefile index 2ce7ae9309..364efb7ee6 100644 --- a/Makefile +++ b/Makefile @@ -28,13 +28,13 @@ usage: check-llvm needs-cairo2 .PHONY: check-llvm check-llvm: -ifndef MLIR_SYS_190_PREFIX - $(error Could not find a suitable LLVM 19 toolchain (mlir), please set MLIR_SYS_190_PREFIX env pointing to the LLVM 19 dir) +ifndef MLIR_SYS_200_PREFIX + $(error Could not find a suitable LLVM 20 toolchain (mlir), please set MLIR_SYS_200_PREFIX env pointing to the LLVM 20 dir) endif -ifndef TABLEGEN_190_PREFIX - $(error Could not find a suitable LLVM 19 toolchain (tablegen), please set TABLEGEN_190_PREFIX env pointing to the LLVM 19 dir) +ifndef TABLEGEN_200_PREFIX + $(error Could not find a suitable LLVM 20 toolchain (tablegen), please set TABLEGEN_200_PREFIX env pointing to the LLVM 20 dir) endif - @echo "LLVM is correctly set at $(MLIR_SYS_190_PREFIX)." + @echo "LLVM is correctly set at $(MLIR_SYS_200_PREFIX)." .PHONY: needs-cairo2 needs-cairo2: @@ -137,14 +137,14 @@ endif .PHONY: deps-macos deps-macos: build-cairo-2-compiler-macos install-scarb-macos - -brew install llvm@19 --quiet + -brew install llvm@20 --quiet @echo "You can execute the env-macos.sh script to setup the needed env variables." # CI use only .PHONY: deps-ci-linux build-cairo-2-compiler install-scarb deps-ci-linux: ifeq ($(UNAME), Linux) - -wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 19 + -wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 20 endif cairo-repo-2-dir = cairo2 diff --git a/README.md b/README.md index 2459370da7..55ebc5a68c 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ use. This can be done by adding `cairo-native = "0.6.0"` to your Cargo.toml ### Dependencies - Linux or macOS (aarch64 included) only for now -- LLVM 19 with MLIR: On debian you can use [apt.llvm.org](https://apt.llvm.org/), +- LLVM 20 with MLIR: On debian you can use [apt.llvm.org](https://apt.llvm.org/), on macOS you can use brew - Rust 1.78.0 or later, since we make use of the u128 [abi change](https://blog.rust-lang.org/2024/03/30/i128-layout-update.html). @@ -64,14 +64,14 @@ make deps ``` #### Linux -Since Linux distributions change widely, you need to install LLVM 19 via your +Since Linux distributions change widely, you need to install LLVM 20 via your package manager, compile it or check if the current release has a Linux binary. If you are on Debian/Ubuntu, check out the repository https://apt.llvm.org/ Then you can install with: ```bash -sudo apt-get install llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools +sudo apt-get install llvm-20 llvm-20-dev llvm-20-runtime clang-20 clang-tools-20 lld-20 libpolly-20-dev libmlir-20-dev mlir-20-tools ``` If you decide to build from source, here are some indications: @@ -80,23 +80,23 @@ If you decide to build from source, here are some indications: ```bash # Go to https://github.com/llvm/llvm-project/releases -# Download the latest LLVM 19 release: -# The blob to download is called llvm-project-19.x.x.src.tar.xz +# Download the latest LLVM 20 release: +# The blob to download is called llvm-project-20.x.x.src.tar.xz # For example -wget https://github.com/llvm/llvm-project/releases/download/llvmorg-19.1.7/llvm-project-19.1.7.src.tar.xz -tar xf llvm-project-19.1.5.src.tar.xz +wget https://github.com/llvm/llvm-project/releases/download/llvmorg-20.1.8/llvm-project-20.1.8.src.tar.xz +tar xf llvm-project-20.1.8.src.tar.xz -cd llvm-project-19.1.5.src.tar +cd llvm-project-20.1.8.src.tar mkdir build cd build -# The following cmake command configures the build to be installed to /opt/llvm-19 +# The following cmake command configures the build to be installed to /opt/llvm-20 cmake -G Ninja ../llvm \ -DLLVM_ENABLE_PROJECTS="mlir;clang;clang-tools-extra;lld;polly" \ -DLLVM_BUILD_EXAMPLES=OFF \ -DLLVM_TARGETS_TO_BUILD="Native" \ - -DCMAKE_INSTALL_PREFIX=/opt/llvm-19 \ + -DCMAKE_INSTALL_PREFIX=/opt/llvm-20 \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DLLVM_PARALLEL_LINK_JOBS=4 \ -DLLVM_ENABLE_BINDINGS=OFF \ @@ -108,14 +108,14 @@ ninja install -Setup a environment variable called `MLIR_SYS_190_PREFIX`, `LLVM_SYS_191_PREFIX` -and `TABLEGEN_190_PREFIX` pointing to the llvm directory: +Setup a environment variable called `MLIR_SYS_200_PREFIX`, `LLVM_SYS_201_PREFIX` +and `TABLEGEN_200_PREFIX` pointing to the llvm directory: ```bash -# For Debian/Ubuntu using the repository, the path will be /usr/lib/llvm-19 -export MLIR_SYS_190_PREFIX=/usr/lib/llvm-19 -export LLVM_SYS_191_PREFIX=/usr/lib/llvm-19 -export TABLEGEN_190_PREFIX=/usr/lib/llvm-19 +# For Debian/Ubuntu using the repository, the path will be /usr/lib/llvm-20 +export MLIR_SYS_200_PREFIX=/usr/lib/llvm-20 +export LLVM_SYS_201_PREFIX=/usr/lib/llvm-20 +export TABLEGEN_200_PREFIX=/usr/lib/llvm-20 ``` Alternatively, if installed from Debian/Ubuntu repository, then you can use @@ -126,7 +126,7 @@ source env.sh ``` #### MacOS -The makefile `deps` target (which you should have ran before) installs LLVM 19 +The makefile `deps` target (which you should have ran before) installs LLVM 20 with brew for you, afterwards you need to execute the `env.sh` script to setup the needed environment variables. @@ -138,9 +138,9 @@ source env.sh If you are using vscode as your code editor, you'll need to add this to you settings.json: ```json "rust-analyzer.cargo.extraEnv": { - "MLIR_SYS_190_PREFIX": "", - "LLVM_SYS_191_PREFIX": "", - "TABLEGEN_190_PREFIX": "", + "MLIR_SYS_200_PREFIX": "", + "LLVM_SYS_201_PREFIX": "", + "TABLEGEN_200_PREFIX": "", } ``` if you are on MacOs, you'll need to add this extra line: @@ -367,14 +367,14 @@ Options: - [hyperfine](https://github.com/sharkdp/hyperfine): `cargo install hyperfine` - [cairo 2.12.0-dev.0](https://github.com/starkware-libs/cairo) - Cairo Corelibs -- LLVM 19 with MLIR +- LLVM 20 with MLIR You need to setup some environment variables: ```bash -$MLIR_SYS_190_PREFIX=/path/to/llvm19 # Required for non-standard LLVM install locations. -$LLVM_SYS_191_PREFIX=/path/to/llvm19 # Required for non-standard LLVM install locations. -$TABLEGEN_190_PREFIX=/path/to/llvm19 # Required for non-standard LLVM install locations. +$MLIR_SYS_200_PREFIX=/path/to/llvm20 # Required for non-standard LLVM install locations. +$LLVM_SYS_201_PREFIX=/path/to/llvm20 # Required for non-standard LLVM install locations. +$TABLEGEN_200_PREFIX=/path/to/llvm20 # Required for non-standard LLVM install locations. ``` You can then run the `bench` makefile target: diff --git a/env.sh b/env.sh index c4f022162f..29c6294c89 100644 --- a/env.sh +++ b/env.sh @@ -12,23 +12,23 @@ case $(uname) in Darwin) # If installed with brew LIBRARY_PATH=/opt/homebrew/lib - MLIR_SYS_190_PREFIX="$(brew --prefix llvm@19)" - LLVM_SYS_191_PREFIX="$(brew --prefix llvm@19)" - TABLEGEN_190_PREFIX="$(brew --prefix llvm@19)" + MLIR_SYS_200_PREFIX="$(brew --prefix llvm@20)" + LLVM_SYS_201_PREFIX="$(brew --prefix llvm@20)" + TABLEGEN_200_PREFIX="$(brew --prefix llvm@20)" export LIBRARY_PATH - export MLIR_SYS_190_PREFIX - export LLVM_SYS_191_PREFIX - export TABLEGEN_190_PREFIX + export MLIR_SYS_200_PREFIX + export LLVM_SYS_201_PREFIX + export TABLEGEN_200_PREFIX ;; Linux) # If installed from Debian/Ubuntu repository: - MLIR_SYS_190_PREFIX=/usr/lib/llvm-19 - LLVM_SYS_191_PREFIX=/usr/lib/llvm-19 - TABLEGEN_190_PREFIX=/usr/lib/llvm-19 + MLIR_SYS_200_PREFIX=/usr/lib/llvm-20 + LLVM_SYS_201_PREFIX=/usr/lib/llvm-20 + TABLEGEN_200_PREFIX=/usr/lib/llvm-20 - export MLIR_SYS_190_PREFIX - export LLVM_SYS_191_PREFIX - export TABLEGEN_190_PREFIX + export MLIR_SYS_200_PREFIX + export LLVM_SYS_201_PREFIX + export TABLEGEN_200_PREFIX ;; esac diff --git a/scripts/bench-hyperfine.sh b/scripts/bench-hyperfine.sh index e802ba0dab..231a4ee02c 100755 --- a/scripts/bench-hyperfine.sh +++ b/scripts/bench-hyperfine.sh @@ -2,7 +2,7 @@ # Configuration. ROOT_DIR="$(dirname "$(readlink -f "${0%/*}")")" -MLIR_DIR="$MLIR_SYS_190_PREFIX" +MLIR_DIR="$MLIR_SYS_200_PREFIX" CAIRO_SRCS=$(find \ "$ROOT_DIR/programs/benches" \ @@ -25,7 +25,7 @@ then fi if [[ -z "$MLIR_DIR" ]] then - echo "${bold}MLIR_DIR is empty. Did you forget to set MLIR_SYS_190_PREFIX?${normal}" + echo "${bold}MLIR_DIR is empty. Did you forget to set MLIR_SYS_200_PREFIX?${normal}" exit 1 fi diff --git a/src/compiler.rs b/src/compiler.rs index 21a5d822da..ac13a9e0f6 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -57,7 +57,11 @@ use crate::{ native_assert, native_panic, statistics::Statistics, types::TypeBuilder, - utils::{generate_function_name, walk_ir::walk_mlir_block}, + utils::{ + generate_function_name, + operations_ext::{llvm_call, LLVMCalleType}, + walk_ir::walk_mlir_block, + }, }; use bumpalo::Bump; use cairo_lang_sierra::{ @@ -81,21 +85,18 @@ use melior::{ }, helpers::{ArithBlockExt, BuiltinBlockExt, LlvmBlockExt}, ir::{ - attribute::{ - DenseI64ArrayAttribute, FlatSymbolRefAttribute, IntegerAttribute, StringAttribute, - TypeAttribute, - }, - operation::OperationBuilder, + attribute::{DenseI64ArrayAttribute, IntegerAttribute, StringAttribute, TypeAttribute}, r#type::{FunctionType, IntegerType, MemRefType}, Attribute, AttributeLike, Block, BlockLike, BlockRef, Identifier, Location, Module, Region, - Type, Value, + RegionLike, Type, Value, }, Context, }; use mlir_sys::{ - mlirDisctinctAttrCreate, mlirLLVMDICompileUnitAttrGet, mlirLLVMDIFileAttrGet, - mlirLLVMDIModuleAttrGet, mlirLLVMDIModuleAttrGetScope, mlirLLVMDISubprogramAttrGet, - mlirLLVMDISubroutineTypeAttrGet, MlirLLVMDIEmissionKind_MlirLLVMDIEmissionKindFull, + mlirAttributeGetNull, mlirDisctinctAttrCreate, mlirLLVMDICompileUnitAttrGet, + mlirLLVMDIFileAttrGet, mlirLLVMDIModuleAttrGet, mlirLLVMDIModuleAttrGetScope, + mlirLLVMDISubprogramAttrGet, mlirLLVMDISubroutineTypeAttrGet, + MlirLLVMDIEmissionKind_MlirLLVMDIEmissionKindFull, MlirLLVMDINameTableKind_MlirLLVMDINameTableKindDefault, }; use std::{ @@ -350,6 +351,8 @@ fn compile_func( mlirLLVMDISubprogramAttrGet( context.to_raw(), + mlirAttributeGetNull(), + false, id, module_scope, file_attr.to_raw(), @@ -360,6 +363,10 @@ fn compile_func( (sierra_stmt_start_offset + function.entry_point.0) as u32, 0x8, // dwarf subprogram flag: definition ty, + 0, + std::ptr::null(), // subprogram's retained nodes, we don't need any + 0, + std::ptr::null(), // subprogram's annotations, we don't need any ) }) }; @@ -1417,24 +1424,20 @@ fn generate_entry_point_wrapper<'c>( args.push(block.argument(i)?.into()); } - let result = block.append_op_result( - OperationBuilder::new("llvm.call", location) - .add_attributes(&[ - ( - Identifier::new(context, "callee"), - FlatSymbolRefAttribute::new(context, private_symbol).into(), - ), - ( - Identifier::new(context, "CConv"), - Attribute::parse(context, "#llvm.cconv") - .ok_or(Error::ParseAttributeError)?, - ), - ]) - .add_operands(&args) - .add_results(&[llvm::r#type::r#struct(context, ret_types, false)]) - .build()?, + let func_call = llvm_call( + context, + LLVMCalleType::Symbol(private_symbol), + &args, + &[( + Identifier::new(context, "CConv"), + Attribute::parse(context, "#llvm.cconv").ok_or(Error::ParseAttributeError)?, + )], + &[llvm::r#type::r#struct(context, ret_types, false)], + location, )?; + let result = block.append_op_result(func_call)?; + let mut returns = Vec::with_capacity(ret_types.len()); for (i, ty) in ret_types.iter().enumerate() { returns.push(block.extract_value(context, location, result, *ty, i)?); diff --git a/src/context.rs b/src/context.rs index 00717c3f50..96ba1b343e 100644 --- a/src/context.rs +++ b/src/context.rs @@ -23,7 +23,7 @@ use melior::{ ir::{ attribute::StringAttribute, operation::{OperationBuilder, OperationPrintingFlags}, - Attribute, AttributeLike, Block, Identifier, Location, Module, Region, + Attribute, AttributeLike, Block, Identifier, Location, Module, Region, RegionLike, }, utility::{register_all_dialects, register_all_llvm_translations, register_all_passes}, Context, diff --git a/src/libfuncs.rs b/src/libfuncs.rs index 970e1eb93d..927bd8ed3a 100644 --- a/src/libfuncs.rs +++ b/src/libfuncs.rs @@ -7,7 +7,10 @@ use crate::{ metadata::MetadataStorage, native_panic, types::TypeBuilder, - utils::ProgramRegistryExt, + utils::{ + operations_ext::{llvm_call, LLVMCalleType}, + ProgramRegistryExt, + }, }; use bumpalo::Bump; use cairo_lang_sierra::{ @@ -30,9 +33,8 @@ use melior::{ helpers::{ArithBlockExt, BuiltinBlockExt, LlvmBlockExt}, ir::{ attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute}, - operation::OperationBuilder, r#type::IntegerType, - Attribute, Block, BlockLike, BlockRef, Location, Module, Region, Value, + Attribute, Block, BlockLike, BlockRef, Location, Module, Region, RegionLike, Value, }, Context, }; @@ -719,13 +721,14 @@ pub fn build_mock_runtime_call<'c, 'a>( // Load the function pointer, and call the function let function_ptr = block.load(context, location, function_ptr_ptr, ptr_type)?; - let result = block.append_op_result( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function_ptr]) - .add_operands(args) - .add_results(&[llvm::r#type::pointer(context, 0)]) - .build()?, + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function_ptr), + args, + &[], + &[llvm::r#type::pointer(context, 0)], + location, )?; - Ok(result) + Ok(block.append_op_result(func_call)?) } diff --git a/src/libfuncs/array.rs b/src/libfuncs/array.rs index 54662fbbf5..1c20f30f53 100644 --- a/src/libfuncs/array.rs +++ b/src/libfuncs/array.rs @@ -27,7 +27,8 @@ use melior::{ }, helpers::{ArithBlockExt, BuiltinBlockExt, GepIndex, LlvmBlockExt}, ir::{ - attribute::IntegerAttribute, r#type::IntegerType, Block, BlockLike, Location, Region, Value, + attribute::IntegerAttribute, r#type::IntegerType, Block, BlockLike, Location, Region, + RegionLike, Value, }, Context, }; diff --git a/src/libfuncs/felt252_dict_entry.rs b/src/libfuncs/felt252_dict_entry.rs index 6ba5be091f..04fff0d145 100644 --- a/src/libfuncs/felt252_dict_entry.rs +++ b/src/libfuncs/felt252_dict_entry.rs @@ -19,7 +19,7 @@ use cairo_lang_sierra::{ use melior::{ dialect::{llvm, scf}, helpers::{ArithBlockExt, BuiltinBlockExt, LlvmBlockExt}, - ir::{r#type::IntegerType, Block, BlockLike, Location, Region}, + ir::{r#type::IntegerType, Block, BlockLike, Location, Region, RegionLike}, Context, }; use std::cell::Cell; diff --git a/src/libfuncs/function_call.rs b/src/libfuncs/function_call.rs index a7513f77eb..3b2cbd364d 100644 --- a/src/libfuncs/function_call.rs +++ b/src/libfuncs/function_call.rs @@ -6,10 +6,11 @@ use super::LibfuncHelper; use crate::{ error::{Error, Result}, + libfuncs::LLVMCalleType, metadata::{tail_recursion::TailRecursionMeta, MetadataStorage}, native_assert, types::TypeBuilder, - utils::generate_function_name, + utils::{generate_function_name, operations_ext::llvm_call}, }; use cairo_lang_sierra::{ extensions::{ @@ -22,10 +23,8 @@ use melior::{ dialect::{cf, index, llvm, memref}, helpers::{ArithBlockExt, BuiltinBlockExt, LlvmBlockExt}, ir::{ - attribute::{DenseI32ArrayAttribute, FlatSymbolRefAttribute}, - operation::OperationBuilder, - r#type::IntegerType, - Attribute, Block, BlockLike, Identifier, Location, Type, Value, + attribute::DenseI32ArrayAttribute, r#type::IntegerType, Attribute, Block, BlockLike, + Identifier, Location, Type, Value, }, Context, }; @@ -186,27 +185,20 @@ pub fn build<'ctx, 'this>( None }; - let function_call_result = entry.append_op_result( - OperationBuilder::new("llvm.call", location) - .add_attributes(&[ - ( - Identifier::new(context, "callee"), - FlatSymbolRefAttribute::new( - context, - &format!("impl${}", generate_function_name(&info.function.id, false)), - ) - .into(), - ), - ( - Identifier::new(context, "CConv"), - Attribute::parse(context, "#llvm.cconv") - .ok_or(Error::ParseAttributeError)?, - ), - ]) - .add_operands(&arguments) - .add_results(&[llvm::r#type::r#struct(context, &result_types, false)]) - .build()?, + let function_sym = format!("impl${}", generate_function_name(&info.function.id, false)); + let func_call = llvm_call( + context, + LLVMCalleType::Symbol(&function_sym), + &arguments, + &[( + Identifier::new(context, "CConv"), + Attribute::parse(context, "#llvm.cconv") + .ok_or(Error::ParseAttributeError)?, + )], + &[llvm::r#type::r#struct(context, &result_types, false)], + location, )?; + let function_call_result = entry.append_op_result(func_call)?; let mut results = Vec::new(); match has_return_ptr { diff --git a/src/libfuncs/int.rs b/src/libfuncs/int.rs index c8f1e5e478..1201281316 100644 --- a/src/libfuncs/int.rs +++ b/src/libfuncs/int.rs @@ -36,7 +36,7 @@ use melior::{ helpers::{ArithBlockExt, BuiltinBlockExt, LlvmBlockExt}, ir::{ attribute::IntegerAttribute, operation::OperationBuilder, r#type::IntegerType, Block, - BlockLike, Location, Region, ValueLike, + BlockLike, Location, Region, RegionLike, ValueLike, }, Context, }; diff --git a/src/libfuncs/starknet.rs b/src/libfuncs/starknet.rs index daf8aa2274..4e03d349a3 100644 --- a/src/libfuncs/starknet.rs +++ b/src/libfuncs/starknet.rs @@ -4,9 +4,10 @@ use super::LibfuncHelper; use crate::{ error::{Error, Result}, ffi::get_struct_field_type_at, + libfuncs::LLVMCalleType, metadata::{drop_overrides::DropOverridesMeta, MetadataStorage}, starknet::handler::StarknetSyscallHandlerCallbacks, - utils::{get_integer_layout, ProgramRegistryExt, PRIME}, + utils::{get_integer_layout, operations_ext::llvm_call, ProgramRegistryExt, PRIME}, }; use cairo_lang_sierra::{ extensions::{ @@ -25,8 +26,8 @@ use melior::{ }, helpers::{ArithBlockExt, BuiltinBlockExt, GepIndex, LlvmBlockExt}, ir::{ - attribute::DenseI64ArrayAttribute, operation::OperationBuilder, r#type::IntegerType, - Attribute, Block, BlockLike, Location, Type, ValueLike, + attribute::DenseI64ArrayAttribute, r#type::IntegerType, Attribute, Block, BlockLike, + Location, Type, ValueLike, }, Context, }; @@ -283,19 +284,21 @@ pub fn build_call_contract<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - address_arg_ptr, - entry_point_selector_arg_ptr, - calldata_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[ + result_ptr, + ptr, + gas_builtin_ptr, + address_arg_ptr, + entry_point_selector_arg_ptr, + calldata_arg_ptr, + ], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -563,18 +566,20 @@ pub fn build_storage_read<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - entry.arg(2)?, - address_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[ + result_ptr, + ptr, + gas_builtin_ptr, + entry.arg(2)?, + address_arg_ptr, + ], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -729,19 +734,21 @@ pub fn build_storage_write<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - entry.arg(2)?, - address_arg_ptr, - value_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[ + result_ptr, + ptr, + gas_builtin_ptr, + entry.arg(2)?, + address_arg_ptr, + value_arg_ptr, + ], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -1049,18 +1056,14 @@ pub fn build_emit_event<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - keys_arg_ptr, - data_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr, keys_arg_ptr, data_arg_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -1204,11 +1207,14 @@ pub fn build_get_block_hash<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[fn_ptr, result_ptr, ptr, gas_builtin_ptr, entry.arg(2)?]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr, entry.arg(2)?], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -1346,11 +1352,14 @@ pub fn build_get_execution_info<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[fn_ptr, result_ptr, ptr, gas_builtin_ptr]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -1488,11 +1497,14 @@ pub fn build_get_execution_info_v2<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[fn_ptr, result_ptr, ptr, gas_builtin_ptr]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -1710,29 +1722,31 @@ pub fn build_deploy<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - class_hash_arg_ptr, - contract_address_salt_arg_ptr, - calldata_arg_ptr, - entry - .append_operation(llvm::extract_value( - context, - entry.arg(5)?, - DenseI64ArrayAttribute::new(context, &[0]), - IntegerType::new(context, 1).into(), - location, - )) - .result(0)? - .into(), - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[ + result_ptr, + ptr, + gas_builtin_ptr, + class_hash_arg_ptr, + contract_address_salt_arg_ptr, + calldata_arg_ptr, + entry + .append_operation(llvm::extract_value( + context, + entry.arg(5)?, + DenseI64ArrayAttribute::new(context, &[0]), + IntegerType::new(context, 1).into(), + location, + )) + .result(0)? + .into(), + ], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -1904,11 +1918,14 @@ pub fn build_keccak<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[fn_ptr, result_ptr, ptr, gas_builtin_ptr, input_arg_ptr]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr, input_arg_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -2080,19 +2097,21 @@ pub fn build_library_call<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - class_hash_arg_ptr, - function_selector_arg_ptr, - calldata_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[ + result_ptr, + ptr, + gas_builtin_ptr, + class_hash_arg_ptr, + function_selector_arg_ptr, + calldata_arg_ptr, + ], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -2295,20 +2314,22 @@ pub fn build_meta_tx_v0<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - address_arg_ptr, - entry_point_selector_arg_ptr, - calldata_arg_ptr, - signature_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[ + result_ptr, + ptr, + gas_builtin_ptr, + address_arg_ptr, + entry_point_selector_arg_ptr, + calldata_arg_ptr, + signature_arg_ptr, + ], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -2461,11 +2482,14 @@ pub fn build_replace_class<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[fn_ptr, result_ptr, ptr, gas_builtin_ptr, class_hash_arg_ptr]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr, class_hash_arg_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -2631,18 +2655,20 @@ pub fn build_send_message_to_l1<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - to_address_arg_ptr, - payload_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[ + result_ptr, + ptr, + gas_builtin_ptr, + to_address_arg_ptr, + payload_arg_ptr, + ], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -2792,18 +2818,20 @@ pub fn build_sha256_process_block_syscall<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - sha256_prev_state_ptr, - sha256_current_block_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[ + result_ptr, + ptr, + gas_builtin_ptr, + sha256_prev_state_ptr, + sha256_current_block_ptr, + ], + &[], + &[], + location, + )?); registry.build_type( context, @@ -2943,17 +2971,14 @@ pub fn build_get_class_hash_at<'ctx, 'this>( )?; let fn_ptr = entry.load(context, location, fn_ptr, llvm::r#type::pointer(context, 0))?; - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - contract_address_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr, contract_address_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, diff --git a/src/libfuncs/starknet/secp256.rs b/src/libfuncs/starknet/secp256.rs index 0ff3d1633b..c9f6679905 100644 --- a/src/libfuncs/starknet/secp256.rs +++ b/src/libfuncs/starknet/secp256.rs @@ -1,9 +1,9 @@ use crate::{ error::Result, - libfuncs::LibfuncHelper, + libfuncs::{LLVMCalleType, LibfuncHelper}, metadata::MetadataStorage, starknet::handler::StarknetSyscallHandlerCallbacks, - utils::{get_integer_layout, ProgramRegistryExt}, + utils::{get_integer_layout, operations_ext::llvm_call, ProgramRegistryExt}, }; use cairo_lang_sierra::{ extensions::{ @@ -17,10 +17,7 @@ use cairo_lang_sierra::{ use melior::{ dialect::llvm::{self, LoadStoreOptions}, helpers::{GepIndex, LlvmBlockExt}, - ir::{ - attribute::DenseI32ArrayAttribute, operation::OperationBuilder, r#type::IntegerType, Block, - BlockLike, Location, - }, + ir::{attribute::DenseI32ArrayAttribute, r#type::IntegerType, Block, BlockLike, Location}, Context, }; use std::alloc::Layout; @@ -205,18 +202,14 @@ pub fn build_k1_new<'ctx, 'this>( .result(0)? .into(); - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - x_arg_ptr, - y_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr, x_arg_ptr, y_arg_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -415,18 +408,14 @@ pub fn build_k1_add<'ctx, 'this>( .result(0)? .into(); - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - p0_arg_ptr, - p1_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr, p0_arg_ptr, p1_arg_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -625,18 +614,14 @@ pub fn build_k1_mul<'ctx, 'this>( .result(0)? .into(); - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - p_arg_ptr, - scalar_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr, p_arg_ptr, scalar_arg_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -830,18 +815,20 @@ pub fn build_k1_get_point_from_x<'ctx, 'this>( .result(0)? .into(); - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - x_arg_ptr, - y_parity_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[ + result_ptr, + ptr, + gas_builtin_ptr, + x_arg_ptr, + y_parity_arg_ptr, + ], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -1050,11 +1037,14 @@ pub fn build_k1_get_xy<'ctx, 'this>( .result(0)? .into(); - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[fn_ptr, result_ptr, ptr, gas_builtin_ptr, p_arg_ptr]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr, p_arg_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -1289,18 +1279,14 @@ pub fn build_r1_new<'ctx, 'this>( .result(0)? .into(); - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - x_arg_ptr, - y_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr, x_arg_ptr, y_arg_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -1500,18 +1486,14 @@ pub fn build_r1_add<'ctx, 'this>( .result(0)? .into(); - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - p0_arg_ptr, - p1_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr, p0_arg_ptr, p1_arg_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -1713,18 +1695,14 @@ pub fn build_r1_mul<'ctx, 'this>( .result(0)? .into(); - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - p_arg_ptr, - scalar_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr, p_arg_ptr, scalar_arg_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -1921,18 +1899,20 @@ pub fn build_r1_get_point_from_x<'ctx, 'this>( .result(0)? .into(); - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[ - fn_ptr, - result_ptr, - ptr, - gas_builtin_ptr, - x_arg_ptr, - y_parity_arg_ptr, - ]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[ + result_ptr, + ptr, + gas_builtin_ptr, + x_arg_ptr, + y_parity_arg_ptr, + ], + &[], + &[], + location, + )?); let result = entry.load( context, @@ -2142,11 +2122,14 @@ pub fn build_r1_get_xy<'ctx, 'this>( .result(0)? .into(); - entry.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[fn_ptr, result_ptr, ptr, gas_builtin_ptr, p_arg_ptr]) - .build()?, - ); + entry.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(fn_ptr), + &[result_ptr, ptr, gas_builtin_ptr, p_arg_ptr], + &[], + &[], + location, + )?); let result = entry.load( context, diff --git a/src/libfuncs/uint256.rs b/src/libfuncs/uint256.rs index 291c2e0809..332bc510b5 100644 --- a/src/libfuncs/uint256.rs +++ b/src/libfuncs/uint256.rs @@ -21,7 +21,7 @@ use melior::{ attribute::{DenseI64ArrayAttribute, IntegerAttribute}, operation::OperationBuilder, r#type::IntegerType, - Block, BlockLike, Location, Region, Value, + Block, BlockLike, Location, Region, RegionLike, Value, }, Context, }; diff --git a/src/metadata/debug_utils.rs b/src/metadata/debug_utils.rs index 8afca095f7..b82cb00e95 100644 --- a/src/metadata/debug_utils.rs +++ b/src/metadata/debug_utils.rs @@ -85,7 +85,10 @@ use crate::{ error::{Error, Result}, - utils::get_integer_layout, + utils::{ + get_integer_layout, + operations_ext::{llvm_call, LLVMCalleType}, + }, }; use melior::{ dialect::{ @@ -216,11 +219,16 @@ impl DebugUtils { DebugBinding::BreakpointMarker, )?; - block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .build()?, - ); + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[], + &[], + &[], + location, + )?; + + block.append_operation(func_call); Ok(()) } @@ -287,12 +295,16 @@ impl DebugUtils { .result(0)? .into(); - block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[ptr, len]) - .build()?, - ); + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[ptr, len], + &[], + &[], + location, + )?; + + block.append_operation(func_call); Ok(()) } @@ -308,12 +320,16 @@ impl DebugUtils { let function = self.build_function(context, module, block, location, DebugBinding::PrintPointer)?; - block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[value]) - .build()?, - ); + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[value], + &[], + &[], + location, + )?; + + block.append_operation(func_call); Ok(()) } @@ -329,12 +345,16 @@ impl DebugUtils { let function = self.build_function(context, module, block, location, DebugBinding::PrintI1)?; - block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[value]) - .build()?, - ); + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[value], + &[], + &[], + location, + )?; + + block.append_operation(func_call); Ok(()) } @@ -404,12 +424,16 @@ impl DebugUtils { .result(0)? .into(); - block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[l0, l1, l2, l3]) - .build()?, - ); + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[l0, l1, l2, l3], + &[], + &[], + location, + )?; + + block.append_operation(func_call); Ok(()) } @@ -425,12 +449,16 @@ impl DebugUtils { let function = self.build_function(context, module, block, location, DebugBinding::PrintI8)?; - block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[value]) - .build()?, - ); + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[value], + &[], + &[], + location, + )?; + + block.append_operation(func_call); Ok(()) } @@ -446,12 +474,16 @@ impl DebugUtils { let function = self.build_function(context, module, block, location, DebugBinding::PrintI32)?; - block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[value]) - .build()?, - ); + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[value], + &[], + &[], + location, + )?; + + block.append_operation(func_call); Ok(()) } @@ -467,12 +499,16 @@ impl DebugUtils { let function = self.build_function(context, module, block, location, DebugBinding::PrintI64)?; - block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[value]) - .build()?, - ); + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[value], + &[], + &[], + location, + )?; + + block.append_operation(func_call); Ok(()) } @@ -511,12 +547,16 @@ impl DebugUtils { .result(0)? .into(); - block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[value_lo, value_hi]) - .build()?, - ); + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[value_lo, value_hi], + &[], + &[], + location, + )?; + + block.append_operation(func_call); Ok(()) } @@ -543,12 +583,16 @@ impl DebugUtils { let len = block.const_int(context, location, len, 64)?; - block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[ptr, len]) - .build()?, - ); + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[ptr, len], + &[], + &[], + location, + )?; + + block.append_operation(func_call); Ok(()) } diff --git a/src/metadata/felt252_dict.rs b/src/metadata/felt252_dict.rs index 381d35652d..87434d00e0 100644 --- a/src/metadata/felt252_dict.rs +++ b/src/metadata/felt252_dict.rs @@ -13,7 +13,7 @@ use melior::{ helpers::{BuiltinBlockExt, LlvmBlockExt}, ir::{ attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute}, - Attribute, Block, BlockLike, Identifier, Location, Module, Region, + Attribute, Block, BlockLike, Identifier, Location, Module, Region, RegionLike, }, Context, }; diff --git a/src/metadata/profiler.rs b/src/metadata/profiler.rs index feb96daa31..8936f6f68f 100644 --- a/src/metadata/profiler.rs +++ b/src/metadata/profiler.rs @@ -37,7 +37,9 @@ use melior::{ }, helpers::{ArithBlockExt, BuiltinBlockExt, LlvmBlockExt}, ir::{ - attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute}, + attribute::{ + DenseI32ArrayAttribute, FlatSymbolRefAttribute, StringAttribute, TypeAttribute, + }, operation::OperationBuilder, r#type::{IntegerType, MemRefType}, Attribute, Block, BlockLike, Identifier, Location, Module, Region, Value, @@ -318,6 +320,8 @@ impl ProfilerMeta { ods::llvm::call( context, &[callback_ptr, trace_id, statement_idx, delta_value], + &[], + DenseI32ArrayAttribute::new(context, &[]), location, ) .into(), diff --git a/src/metadata/realloc_bindings.rs b/src/metadata/realloc_bindings.rs index 1019940a33..c55b0f25c8 100644 --- a/src/metadata/realloc_bindings.rs +++ b/src/metadata/realloc_bindings.rs @@ -6,7 +6,9 @@ use melior::{ dialect::llvm, ir::{ - attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute}, + attribute::{ + DenseI32ArrayAttribute, FlatSymbolRefAttribute, StringAttribute, TypeAttribute, + }, operation::OperationBuilder, r#type::IntegerType, BlockLike, Identifier, Location, Module, Operation, Region, Value, @@ -66,11 +68,21 @@ impl ReallocBindingsMeta { location: Location<'c>, ) -> Result, Error> { OperationBuilder::new("llvm.call", location) - .add_attributes(&[( - Identifier::new(context, "callee"), - FlatSymbolRefAttribute::new(context, "realloc").into(), - )]) .add_operands(&[ptr, len]) + .add_attributes(&[ + ( + Identifier::new(context, "callee"), + FlatSymbolRefAttribute::new(context, "realloc").into(), + ), + ( + Identifier::new(context, "operandSegmentSizes"), + DenseI32ArrayAttribute::new(context, &[2, 0]).into(), + ), + ( + Identifier::new(context, "op_bundle_sizes"), + DenseI32ArrayAttribute::new(context, &[]).into(), + ), + ]) .add_results(&[llvm::r#type::pointer(context, 0)]) .build() } @@ -82,11 +94,22 @@ impl ReallocBindingsMeta { location: Location<'c>, ) -> Result, Error> { OperationBuilder::new("llvm.call", location) - .add_attributes(&[( - Identifier::new(context, "callee"), - FlatSymbolRefAttribute::new(context, "free").into(), - )]) .add_operands(&[ptr]) + .add_operands(&[]) + .add_attributes(&[ + ( + Identifier::new(context, "callee"), + FlatSymbolRefAttribute::new(context, "free").into(), + ), + ( + Identifier::new(context, "operandSegmentSizes"), + DenseI32ArrayAttribute::new(context, &[1, 0]).into(), + ), + ( + Identifier::new(context, "op_bundle_sizes"), + DenseI32ArrayAttribute::new(context, &[]).into(), + ), + ]) .build() } } diff --git a/src/metadata/runtime_bindings.rs b/src/metadata/runtime_bindings.rs index 82a08458ae..d9b1da9f4f 100644 --- a/src/metadata/runtime_bindings.rs +++ b/src/metadata/runtime_bindings.rs @@ -6,13 +6,13 @@ use crate::{ error::{Error, Result}, libfuncs::LibfuncHelper, + utils::operations_ext::{llvm_call, LLVMCalleType}, }; use melior::{ dialect::{llvm, ods}, helpers::{ArithBlockExt, BuiltinBlockExt, LlvmBlockExt}, ir::{ attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute}, - operation::OperationBuilder, r#type::IntegerType, Attribute, Block, BlockLike, Location, Module, OperationRef, Region, Value, }, @@ -184,17 +184,16 @@ impl RuntimeBindingsMeta { { let function = self.build_function(context, module, block, location, RuntimeBinding::DebugPrint)?; + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[target_fd, values_ptr, values_len], + &[], + &[IntegerType::new(context, 32).into()], + location, + )?; - Ok(block - .append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[target_fd, values_ptr, values_len]) - .add_results(&[IntegerType::new(context, 32).into()]) - .build()?, - ) - .result(0)? - .into()) + Ok(block.append_op_result(func_call)?) } /// Register if necessary, then invoke the `pedersen()` function. @@ -215,12 +214,14 @@ impl RuntimeBindingsMeta { let function = self.build_function(context, module, block, location, RuntimeBinding::Pedersen)?; - Ok(block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[dst_ptr, lhs_ptr, rhs_ptr]) - .build()?, - )) + Ok(block.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[dst_ptr, lhs_ptr, rhs_ptr], + &[], + &[], + location, + )?)) } /// Register if necessary, then invoke the `poseidon()` function. @@ -247,12 +248,14 @@ impl RuntimeBindingsMeta { RuntimeBinding::HadesPermutation, )?; - Ok(block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[op0_ptr, op1_ptr, op2_ptr]) - .build()?, - )) + Ok(block.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[op0_ptr, op1_ptr, op2_ptr], + &[], + &[], + location, + )?)) } /// Register if necessary, then invoke the `ec_point_from_x_nz()` function. @@ -275,13 +278,14 @@ impl RuntimeBindingsMeta { RuntimeBinding::EcPointFromXNz, )?; - Ok(block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[point_ptr]) - .add_results(&[IntegerType::new(context, 1).into()]) - .build()?, - )) + Ok(block.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[point_ptr], + &[], + &[IntegerType::new(context, 1).into()], + location, + )?)) } /// Register if necessary, then invoke the `ec_point_try_new_nz()` function. @@ -304,13 +308,14 @@ impl RuntimeBindingsMeta { RuntimeBinding::EcPointTryNewNz, )?; - Ok(block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[point_ptr]) - .add_results(&[IntegerType::new(context, 1).into()]) - .build()?, - )) + Ok(block.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[point_ptr], + &[], + &[IntegerType::new(context, 1).into()], + location, + )?)) } /// Register if necessary, then invoke the `ec_state_init()` function. @@ -333,12 +338,14 @@ impl RuntimeBindingsMeta { RuntimeBinding::EcStateInit, )?; - Ok(block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[state_ptr]) - .build()?, - )) + Ok(block.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[state_ptr], + &[], + &[], + location, + )?)) } /// Register if necessary, then invoke the `ec_state_add()` function. @@ -357,12 +364,14 @@ impl RuntimeBindingsMeta { let function = self.build_function(context, module, block, location, RuntimeBinding::EcStateAdd)?; - Ok(block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[state_ptr, point_ptr]) - .build()?, - )) + Ok(block.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[state_ptr, point_ptr], + &[], + &[], + location, + )?)) } /// Register if necessary, then invoke the `ec_state_add_mul()` function. @@ -388,12 +397,14 @@ impl RuntimeBindingsMeta { RuntimeBinding::EcStateAddMul, )?; - Ok(block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[state_ptr, scalar_ptr, point_ptr]) - .build()?, - )) + Ok(block.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[state_ptr, scalar_ptr, point_ptr], + &[], + &[], + location, + )?)) } pub fn libfunc_ec_state_try_finalize_nz<'c, 'a>( @@ -416,13 +427,14 @@ impl RuntimeBindingsMeta { RuntimeBinding::EcStateTryFinalizeNz, )?; - Ok(block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[point_ptr, state_ptr]) - .add_results(&[IntegerType::new(context, 1).into()]) - .build()?, - )) + Ok(block.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[point_ptr, state_ptr], + &[], + &[IntegerType::new(context, 1).into()], + location, + )?)) } /// Register if necessary, then invoke the `dict_alloc_new()` function. @@ -455,13 +467,16 @@ impl RuntimeBindingsMeta { } }; - Ok(block.append_op_result( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[size, align, drop_fn]) - .add_results(&[llvm::r#type::pointer(context, 0)]) - .build()?, - )?) + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[size, align, drop_fn], + &[], + &[llvm::r#type::pointer(context, 0)], + location, + )?; + + Ok(block.append_op_result(func_call)?) } /// Register if necessary, then invoke the `dict_alloc_new()` function. @@ -482,12 +497,14 @@ impl RuntimeBindingsMeta { let function = self.build_function(context, module, block, location, RuntimeBinding::DictDrop)?; - Ok(block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[ptr]) - .build()?, - )) + Ok(block.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[ptr], + &[], + &[], + location, + )?)) } /// Register if necessary, then invoke the `dict_alloc_new()` function. @@ -508,13 +525,16 @@ impl RuntimeBindingsMeta { let function = self.build_function(context, module, block, location, RuntimeBinding::DictDup)?; - Ok(block.append_op_result( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[ptr]) - .add_results(&[llvm::r#type::pointer(context, 0)]) - .build()?, - )?) + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[ptr], + &[], + &[llvm::r#type::pointer(context, 0)], + location, + )?; + + Ok(block.append_op_result(func_call)?) } /// Register if necessary, then invoke the `dict_get()` function. @@ -545,14 +565,17 @@ impl RuntimeBindingsMeta { align_of::<*mut ()>(), )?; - let is_present = block.append_op_result( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[dict_ptr, key_ptr, value_ptr]) - .add_results(&[IntegerType::new(context, c_int::BITS).into()]) - .build()?, + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[dict_ptr, key_ptr, value_ptr], + &[], + &[IntegerType::new(context, c_int::BITS).into()], + location, )?; + let is_present = block.append_op_result(func_call)?; + let value_ptr = block.load( context, location, @@ -585,13 +608,14 @@ impl RuntimeBindingsMeta { let function = self.build_function(context, module, block, location, RuntimeBinding::DictSquash)?; - Ok(block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[dict_ptr, range_check_ptr, gas_ptr]) - .add_results(&[IntegerType::new(context, 64).into()]) - .build()?, - )) + Ok(block.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[dict_ptr, range_check_ptr, gas_ptr], + &[], + &[IntegerType::new(context, 64).into()], + location, + )?)) } // Register if necessary, then invoke the `get_costs_builtin()` function. @@ -614,12 +638,14 @@ impl RuntimeBindingsMeta { RuntimeBinding::GetCostsBuiltin, )?; - Ok(block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_results(&[llvm::r#type::pointer(context, 0)]) - .build()?, - )) + Ok(block.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[], + &[], + &[llvm::r#type::pointer(context, 0)], + location, + )?)) } /// Register if necessary, then invoke the `vtable_cheatcode()` runtime function. @@ -642,6 +668,8 @@ impl RuntimeBindingsMeta { where 'c: 'a, { + use crate::utils::operations_ext::{llvm_call, LLVMCalleType}; + let function = self.build_function( context, module, @@ -650,12 +678,14 @@ impl RuntimeBindingsMeta { RuntimeBinding::VtableCheatcode, )?; - Ok(block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[result_ptr, selector_ptr, args]) - .build()?, - )) + Ok(block.append_operation(llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[result_ptr, selector_ptr, args], + &[], + &[], + location, + )?)) } } diff --git a/src/metadata/trace_dump.rs b/src/metadata/trace_dump.rs index 6742d5683f..203fe635f2 100644 --- a/src/metadata/trace_dump.rs +++ b/src/metadata/trace_dump.rs @@ -1,6 +1,9 @@ #![cfg(feature = "with-trace-dump")] -use crate::error::{Error, Result}; +use crate::{ + error::{Error, Result}, + utils::operations_ext::{llvm_call, LLVMCalleType}, +}; use cairo_lang_sierra::{ ids::{ConcreteTypeId, VarId}, program::StatementIdx, @@ -10,7 +13,6 @@ use melior::{ helpers::{ArithBlockExt, BuiltinBlockExt, LlvmBlockExt}, ir::{ attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute}, - operation::OperationBuilder, r#type::{IntegerType, MemRefType}, Attribute, Block, BlockLike, Location, Module, Region, Value, }, @@ -113,12 +115,17 @@ impl TraceDumpMeta { let function = self.build_function(context, module, block, location, TraceBinding::State)?; - block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[trace_id, var_id, value_ty, value_ptr]) - .build()?, - ); + + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[trace_id, var_id, value_ty, value_ptr], + &[], + &[], + location, + )?; + + block.append_operation(func_call); Ok(()) } @@ -136,12 +143,16 @@ impl TraceDumpMeta { let function = self.build_function(context, module, block, location, TraceBinding::Push)?; - block.append_operation( - OperationBuilder::new("llvm.call", location) - .add_operands(&[function]) - .add_operands(&[trace_id, statement_idx]) - .build()?, - ); + let func_call = llvm_call( + context, + LLVMCalleType::FuncPtr(function), + &[trace_id, statement_idx], + &[], + &[], + location, + )?; + + block.append_operation(func_call); Ok(()) } diff --git a/src/types/array.rs b/src/types/array.rs index c2c1cac13b..f083a5dd27 100644 --- a/src/types/array.rs +++ b/src/types/array.rs @@ -40,7 +40,7 @@ use cairo_lang_sierra::{ }; use melior::{ dialect::{arith, llvm}, - ir::{r#type::IntegerType, Block, Location, Module, Type}, + ir::{r#type::IntegerType, Block, Location, Module, RegionLike, Type}, Context, }; use melior::{ diff --git a/src/types/box.rs b/src/types/box.rs index 331fd92bc6..566ffed067 100644 --- a/src/types/box.rs +++ b/src/types/box.rs @@ -34,7 +34,7 @@ use melior::{ helpers::{ArithBlockExt, BuiltinBlockExt, LlvmBlockExt}, ir::{ attribute::IntegerAttribute, r#type::IntegerType, Block, BlockLike, Location, Module, - Region, Type, + Region, RegionLike, Type, }, Context, }; diff --git a/src/types/circuit.rs b/src/types/circuit.rs index 5cb6163349..76da0575c6 100644 --- a/src/types/circuit.rs +++ b/src/types/circuit.rs @@ -23,7 +23,9 @@ use cairo_lang_sierra::{ use melior::{ dialect::{func, llvm}, helpers::{ArithBlockExt, BuiltinBlockExt, LlvmBlockExt}, - ir::{r#type::IntegerType, Block, BlockLike, Location, Module, Region, Type, Value}, + ir::{ + r#type::IntegerType, Block, BlockLike, Location, Module, Region, RegionLike, Type, Value, + }, Context, }; diff --git a/src/types/enum.rs b/src/types/enum.rs index 52cd8fa7cc..603fd625c8 100644 --- a/src/types/enum.rs +++ b/src/types/enum.rs @@ -421,7 +421,9 @@ use cairo_lang_sierra::{ use melior::{ dialect::{cf, func, llvm}, helpers::{BuiltinBlockExt, LlvmBlockExt}, - ir::{r#type::IntegerType, Block, BlockLike, Location, Module, Region, Type, Value}, + ir::{ + r#type::IntegerType, Block, BlockLike, Location, Module, Region, RegionLike, Type, Value, + }, Context, }; use std::{ diff --git a/src/types/felt252_dict.rs b/src/types/felt252_dict.rs index 58f036eecb..50a93af897 100644 --- a/src/types/felt252_dict.rs +++ b/src/types/felt252_dict.rs @@ -26,7 +26,7 @@ use cairo_lang_sierra::{ use melior::{ dialect::{func, llvm}, helpers::BuiltinBlockExt, - ir::{Block, BlockLike, Location, Module, Region, Type}, + ir::{Block, BlockLike, Location, Module, Region, RegionLike, Type}, Context, }; diff --git a/src/types/nullable.rs b/src/types/nullable.rs index f126fcb178..c4f9524fb5 100644 --- a/src/types/nullable.rs +++ b/src/types/nullable.rs @@ -24,7 +24,7 @@ use cairo_lang_sierra::{ use melior::{ dialect::{cf, func}, helpers::{ArithBlockExt, BuiltinBlockExt, LlvmBlockExt}, - ir::{BlockLike, Region}, + ir::{BlockLike, Region, RegionLike}, }; use melior::{ dialect::{llvm, ods}, diff --git a/src/types/snapshot.rs b/src/types/snapshot.rs index aa52bd5e09..68eb570c9b 100644 --- a/src/types/snapshot.rs +++ b/src/types/snapshot.rs @@ -31,7 +31,7 @@ use cairo_lang_sierra::{ use melior::{ dialect::func, helpers::BuiltinBlockExt, - ir::{Block, BlockLike, Location, Module, Region, Type}, + ir::{Block, BlockLike, Location, Module, Region, RegionLike, Type}, Context, }; diff --git a/src/types/starknet.rs b/src/types/starknet.rs index e97daafe5a..fe3e83aae7 100644 --- a/src/types/starknet.rs +++ b/src/types/starknet.rs @@ -42,7 +42,7 @@ use melior::{ helpers::{ArithBlockExt, BuiltinBlockExt}, ir::{ attribute::IntegerAttribute, r#type::IntegerType, Block, BlockLike, Location, Module, - Region, Type, + Region, RegionLike, Type, }, Context, }; diff --git a/src/types/struct.rs b/src/types/struct.rs index f253db376b..5bea81aedd 100644 --- a/src/types/struct.rs +++ b/src/types/struct.rs @@ -50,7 +50,7 @@ use cairo_lang_sierra::{ use melior::{ dialect::{func, llvm}, helpers::{BuiltinBlockExt, LlvmBlockExt}, - ir::{Block, BlockLike, Location, Module, Region, Type}, + ir::{Block, BlockLike, Location, Module, Region, RegionLike, Type}, Context, }; diff --git a/src/utils.rs b/src/utils.rs index 51ded2715f..1101842bad 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -34,6 +34,7 @@ use std::{ use thiserror::Error; pub mod mem_tracing; +pub mod operations_ext; mod program_registry_ext; mod range_ext; #[cfg(feature = "with-segfault-catcher")] diff --git a/src/utils/operations_ext.rs b/src/utils/operations_ext.rs new file mode 100644 index 0000000000..ae6e52c62c --- /dev/null +++ b/src/utils/operations_ext.rs @@ -0,0 +1,82 @@ +use melior::{ + ir::{ + attribute::{DenseI32ArrayAttribute, FlatSymbolRefAttribute}, + operation::{Operation, OperationBuilder}, + Attribute, Identifier, Location, Type, Value, + }, + Context, +}; + +use crate::error::Result; + +pub enum LLVMCalleType<'c, 'a> { + Symbol(&'a str), + FuncPtr(Value<'c, 'a>), +} + +/// Helper function to perform an `llvm.call` operation. +/// +/// The function allows to use either the function pointer or it's symbol. It will also calculate +/// the `operandSegmentSizes` attribute, needed by the operation, from `calle_type` and the +/// arguments' size. This is to avoid having to calculate this attribute by hand. +/// +/// # Safety +/// +/// The `attrs` argument should no contain the calle or the operandSegmentSizes attributes as specified +/// by the function itself. Adding them result in an error for attribute duplication. +/// +/// If the call was to be performed with the function pointer, the latter should not be included in `args` +/// as part of the call operands since that is already handled by the function itself. +pub fn llvm_call<'c, 'a>( + context: &'c Context, + calle_type: LLVMCalleType<'c, 'a>, + args: &[Value<'c, 'a>], + attrs: &[(Identifier<'c>, Attribute<'c>)], + ret_types: &[Type<'c>], + location: Location<'c>, +) -> Result> { + let op = { + // llvm.call is an operation that takes two groups of variadic operands (calle-operands and "op-bundle-operands"). + // + // * The calle-operans are the operands we are used to: + // 1. function-pointer (if it was an indirect call). + // 2. function-args (if any). + // + // * The op-bundle-operands are a way to specify operands without changing the function's firm. + // + // Since we have 2 groups of variadic operands, we are expected to tell the amount of operands for each group. We + // do this by specifying the attribute "operandSegmentSizes". If we were to call the function from a pointer, we would + // have 1 + for the "calle-operands" group and 0 from the op-bundle-operands group. + let op = match calle_type { + LLVMCalleType::Symbol(sym) => OperationBuilder::new("llvm.call", location) + .add_attributes(&[ + ( + Identifier::new(context, "callee"), + FlatSymbolRefAttribute::new(context, sym).into(), + ), + ( + Identifier::new(context, "operandSegmentSizes"), + DenseI32ArrayAttribute::new(context, &[args.len() as i32, 0]).into(), + ), + ]), + LLVMCalleType::FuncPtr(ptr) => OperationBuilder::new("llvm.call", location) + .add_attributes(&[( + Identifier::new(context, "operandSegmentSizes"), + DenseI32ArrayAttribute::new(context, &[args.len() as i32 + 1, 0]).into(), + )]) + .add_operands(&[ptr]), + }; + + // We don't use op-bundle-operands in the call, so "op_bundle_sizes" should be empty. + op.add_attributes(&[( + Identifier::new(context, "op_bundle_sizes"), + DenseI32ArrayAttribute::new(context, &[]).into(), + )]) + }; + + Ok(op + .add_operands(args) + .add_attributes(attrs) + .add_results(ret_types) + .build()?) +} diff --git a/src/utils/walk_ir.rs b/src/utils/walk_ir.rs index 363542aad0..7d3a99102f 100644 --- a/src/utils/walk_ir.rs +++ b/src/utils/walk_ir.rs @@ -6,7 +6,7 @@ use llvm_sys::{ prelude::{LLVMModuleRef, LLVMValueRef}, LLVMBasicBlock, LLVMValue, }; -use melior::ir::{BlockLike, BlockRef, OperationRef}; +use melior::ir::{BlockLike, BlockRef, OperationRef, RegionLike}; /// Traverses the given operation tree in preorder. ///